blob: 22563468dd2bae57da2fa56fef83aeea6671decd [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
Steven Valdezc4aa7272016-10-03 12:25:56 -0400362 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
363 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400364 // expectMessageDropped, if true, means the test message is expected to
365 // be dropped by the client rather than echoed back.
366 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700367}
368
Adam Langley7c803a62015-06-15 15:35:05 -0700369var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700370
David Benjaminc07afb72016-09-22 10:18:58 -0400371func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500372 if len(data) == 0 {
373 return
374 }
375
376 protocol := "tls"
377 if test.protocol == dtls {
378 protocol = "dtls"
379 }
380
381 side := "client"
382 if test.testType == serverTest {
383 side = "server"
384 }
385
386 dir := path.Join(*transcriptDir, protocol, side)
387 if err := os.MkdirAll(dir, 0755); err != nil {
388 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
389 return
390 }
391
David Benjaminc07afb72016-09-22 10:18:58 -0400392 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500393 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
394 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
395 }
396}
397
David Benjamin3ed59772016-03-08 12:50:21 -0500398// A timeoutConn implements an idle timeout on each Read and Write operation.
399type timeoutConn struct {
400 net.Conn
401 timeout time.Duration
402}
403
404func (t *timeoutConn) Read(b []byte) (int, error) {
405 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
406 return 0, err
407 }
408 return t.Conn.Read(b)
409}
410
411func (t *timeoutConn) Write(b []byte) (int, error) {
412 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
413 return 0, err
414 }
415 return t.Conn.Write(b)
416}
417
David Benjaminc07afb72016-09-22 10:18:58 -0400418func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400419 if !test.noSessionCache {
420 if config.ClientSessionCache == nil {
421 config.ClientSessionCache = NewLRUClientSessionCache(1)
422 }
423 if config.ServerSessionCache == nil {
424 config.ServerSessionCache = NewLRUServerSessionCache(1)
425 }
426 }
427 if test.testType == clientTest {
428 if len(config.Certificates) == 0 {
429 config.Certificates = []Certificate{rsaCertificate}
430 }
431 } else {
432 // Supply a ServerName to ensure a constant session cache key,
433 // rather than falling back to net.Conn.RemoteAddr.
434 if len(config.ServerName) == 0 {
435 config.ServerName = "test"
436 }
437 }
438 if *fuzzer {
439 config.Bugs.NullAllCiphers = true
440 }
David Benjamin01a90572016-09-22 00:11:43 -0400441 if *deterministic {
442 config.Time = func() time.Time { return time.Unix(1234, 1234) }
443 }
David Benjamine54af062016-08-08 19:21:18 -0400444
David Benjamin01784b42016-06-07 18:00:52 -0400445 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500446
David Benjamin6fd297b2014-08-11 18:43:38 -0400447 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500448 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
449 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500450 }
451
David Benjamin9867b7d2016-03-01 23:25:48 -0500452 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500453 local, peer := "client", "server"
454 if test.testType == clientTest {
455 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500456 }
David Benjaminebda9b32015-11-02 15:33:18 -0500457 connDebug := &recordingConn{
458 Conn: conn,
459 isDatagram: test.protocol == dtls,
460 local: local,
461 peer: peer,
462 }
463 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500464 if *flagDebug {
465 defer connDebug.WriteTo(os.Stdout)
466 }
467 if len(*transcriptDir) != 0 {
468 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400469 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500470 }()
471 }
David Benjaminebda9b32015-11-02 15:33:18 -0500472
473 if config.Bugs.PacketAdaptor != nil {
474 config.Bugs.PacketAdaptor.debug = connDebug
475 }
476 }
477
478 if test.replayWrites {
479 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400480 }
481
David Benjamin3ed59772016-03-08 12:50:21 -0500482 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500483 if test.damageFirstWrite {
484 connDamage = newDamageAdaptor(conn)
485 conn = connDamage
486 }
487
David Benjamin6fd297b2014-08-11 18:43:38 -0400488 if test.sendPrefix != "" {
489 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
490 return err
491 }
David Benjamin98e882e2014-08-08 13:24:34 -0400492 }
493
David Benjamin1d5c83e2014-07-22 19:20:02 -0400494 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400495 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400496 if test.protocol == dtls {
497 tlsConn = DTLSServer(conn, config)
498 } else {
499 tlsConn = Server(conn, config)
500 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400501 } else {
502 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400503 if test.protocol == dtls {
504 tlsConn = DTLSClient(conn, config)
505 } else {
506 tlsConn = Client(conn, config)
507 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400508 }
David Benjamin30789da2015-08-29 22:56:45 -0400509 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400510
Adam Langley95c29f32014-06-20 12:00:00 -0700511 if err := tlsConn.Handshake(); err != nil {
512 return err
513 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700514
David Benjamin01fe8202014-09-24 15:21:44 -0400515 // TODO(davidben): move all per-connection expectations into a dedicated
516 // expectations struct that can be specified separately for the two
517 // legs.
518 expectedVersion := test.expectedVersion
519 if isResume && test.expectedResumeVersion != 0 {
520 expectedVersion = test.expectedResumeVersion
521 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700522 connState := tlsConn.ConnectionState()
523 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400524 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400525 }
526
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700527 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400528 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
529 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700530 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
531 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
532 }
David Benjamin90da8c82015-04-20 14:57:57 -0400533
David Benjamina08e49d2014-08-24 01:46:07 -0400534 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700535 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400536 if channelID == nil {
537 return fmt.Errorf("no channel ID negotiated")
538 }
539 if channelID.Curve != channelIDKey.Curve ||
540 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
541 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
542 return fmt.Errorf("incorrect channel ID")
543 }
544 }
545
David Benjaminae2888f2014-09-06 12:58:58 -0400546 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700547 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400548 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
549 }
550 }
551
David Benjaminc7ce9772015-10-09 19:32:41 -0400552 if test.expectNoNextProto {
553 if actual := connState.NegotiatedProtocol; actual != "" {
554 return fmt.Errorf("got unexpected next proto %s", actual)
555 }
556 }
557
David Benjaminfc7b0862014-09-06 13:21:53 -0400558 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700559 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400560 return fmt.Errorf("next proto type mismatch")
561 }
562 }
563
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700564 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500565 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
566 }
567
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100568 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300569 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100570 }
571
Paul Lietar4fac72e2015-09-09 13:44:55 +0100572 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
573 return fmt.Errorf("SCT list mismatch")
574 }
575
Nick Harper60edffd2016-06-21 15:19:24 -0700576 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
577 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400578 }
579
Steven Valdez5440fe02016-07-18 12:40:30 -0400580 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
581 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
582 }
583
David Benjaminc565ebb2015-04-03 04:06:36 -0400584 if test.exportKeyingMaterial > 0 {
585 actual := make([]byte, test.exportKeyingMaterial)
586 if _, err := io.ReadFull(tlsConn, actual); err != nil {
587 return err
588 }
589 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
590 if err != nil {
591 return err
592 }
593 if !bytes.Equal(actual, expected) {
594 return fmt.Errorf("keying material mismatch")
595 }
596 }
597
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700598 if test.testTLSUnique {
599 var peersValue [12]byte
600 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
601 return err
602 }
603 expected := tlsConn.ConnectionState().TLSUnique
604 if !bytes.Equal(peersValue[:], expected) {
605 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
606 }
607 }
608
David Benjamine58c4f52014-08-24 03:47:07 -0400609 if test.shimWritesFirst {
610 var buf [5]byte
611 _, err := io.ReadFull(tlsConn, buf[:])
612 if err != nil {
613 return err
614 }
615 if string(buf[:]) != "hello" {
616 return fmt.Errorf("bad initial message")
617 }
618 }
619
Steven Valdez32635b82016-08-16 11:25:03 -0400620 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400621 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400622 return err
623 }
Steven Valdez32635b82016-08-16 11:25:03 -0400624 }
625
David Benjamina8ebe222015-06-06 03:04:39 -0400626 for i := 0; i < test.sendEmptyRecords; i++ {
627 tlsConn.Write(nil)
628 }
629
David Benjamin24f346d2015-06-06 03:28:08 -0400630 for i := 0; i < test.sendWarningAlerts; i++ {
631 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
632 }
633
David Benjamin47921102016-07-28 11:29:18 -0400634 if test.sendHalfHelloRequest {
635 tlsConn.SendHalfHelloRequest()
636 }
637
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400638 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700639 if test.renegotiateCiphers != nil {
640 config.CipherSuites = test.renegotiateCiphers
641 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400642 for i := 0; i < test.renegotiate; i++ {
643 if err := tlsConn.Renegotiate(); err != nil {
644 return err
645 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700646 }
647 } else if test.renegotiateCiphers != nil {
648 panic("renegotiateCiphers without renegotiate")
649 }
650
David Benjamin5fa3eba2015-01-22 16:35:40 -0500651 if test.damageFirstWrite {
652 connDamage.setDamage(true)
653 tlsConn.Write([]byte("DAMAGED WRITE"))
654 connDamage.setDamage(false)
655 }
656
David Benjamin8e6db492015-07-25 18:29:23 -0400657 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700658 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400659 if test.protocol == dtls {
660 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
661 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700662 // Read until EOF.
663 _, err := io.Copy(ioutil.Discard, tlsConn)
664 return err
665 }
David Benjamin4417d052015-04-05 04:17:25 -0400666 if messageLen == 0 {
667 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700668 }
Adam Langley95c29f32014-06-20 12:00:00 -0700669
David Benjamin8e6db492015-07-25 18:29:23 -0400670 messageCount := test.messageCount
671 if messageCount == 0 {
672 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400673 }
674
David Benjamin8e6db492015-07-25 18:29:23 -0400675 for j := 0; j < messageCount; j++ {
676 testMessage := make([]byte, messageLen)
677 for i := range testMessage {
678 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400679 }
David Benjamin8e6db492015-07-25 18:29:23 -0400680 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700681
Steven Valdez32635b82016-08-16 11:25:03 -0400682 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400683 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400684 }
685
David Benjamin8e6db492015-07-25 18:29:23 -0400686 for i := 0; i < test.sendEmptyRecords; i++ {
687 tlsConn.Write(nil)
688 }
689
690 for i := 0; i < test.sendWarningAlerts; i++ {
691 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
692 }
693
David Benjamin4f75aaf2015-09-01 16:53:10 -0400694 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400695 // The shim will not respond.
696 continue
697 }
698
David Benjamin8e6db492015-07-25 18:29:23 -0400699 buf := make([]byte, len(testMessage))
700 if test.protocol == dtls {
701 bufTmp := make([]byte, len(buf)+1)
702 n, err := tlsConn.Read(bufTmp)
703 if err != nil {
704 return err
705 }
706 if n != len(buf) {
707 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
708 }
709 copy(buf, bufTmp)
710 } else {
711 _, err := io.ReadFull(tlsConn, buf)
712 if err != nil {
713 return err
714 }
715 }
716
717 for i, v := range buf {
718 if v != testMessage[i]^0xff {
719 return fmt.Errorf("bad reply contents at byte %d", i)
720 }
Adam Langley95c29f32014-06-20 12:00:00 -0700721 }
722 }
723
724 return nil
725}
726
David Benjamin325b5c32014-07-01 19:40:31 -0400727func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400728 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700729 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400730 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700731 }
David Benjamin325b5c32014-07-01 19:40:31 -0400732 valgrindArgs = append(valgrindArgs, path)
733 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700734
David Benjamin325b5c32014-07-01 19:40:31 -0400735 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700736}
737
David Benjamin325b5c32014-07-01 19:40:31 -0400738func gdbOf(path string, args ...string) *exec.Cmd {
739 xtermArgs := []string{"-e", "gdb", "--args"}
740 xtermArgs = append(xtermArgs, path)
741 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700742
David Benjamin325b5c32014-07-01 19:40:31 -0400743 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700744}
745
David Benjamind16bf342015-12-18 00:53:12 -0500746func lldbOf(path string, args ...string) *exec.Cmd {
747 xtermArgs := []string{"-e", "lldb", "--"}
748 xtermArgs = append(xtermArgs, path)
749 xtermArgs = append(xtermArgs, args...)
750
751 return exec.Command("xterm", xtermArgs...)
752}
753
EKR842ae6c2016-07-27 09:22:05 +0200754var (
755 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
756 errUnimplemented = errors.New("child process does not implement needed flags")
757)
Adam Langley69a01602014-11-17 17:26:55 -0800758
David Benjamin87c8a642015-02-21 01:54:29 -0500759// accept accepts a connection from listener, unless waitChan signals a process
760// exit first.
761func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
762 type connOrError struct {
763 conn net.Conn
764 err error
765 }
766 connChan := make(chan connOrError, 1)
767 go func() {
768 conn, err := listener.Accept()
769 connChan <- connOrError{conn, err}
770 close(connChan)
771 }()
772 select {
773 case result := <-connChan:
774 return result.conn, result.err
775 case childErr := <-waitChan:
776 waitChan <- childErr
777 return nil, fmt.Errorf("child exited early: %s", childErr)
778 }
779}
780
EKRf71d7ed2016-08-06 13:25:12 -0700781func translateExpectedError(errorStr string) string {
782 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
783 return translated
784 }
785
786 if *looseErrors {
787 return ""
788 }
789
790 return errorStr
791}
792
Adam Langley7c803a62015-06-15 15:35:05 -0700793func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400794 // Help debugging panics on the Go side.
795 defer func() {
796 if r := recover(); r != nil {
797 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
798 panic(r)
799 }
800 }()
801
Adam Langley38311732014-10-16 19:04:35 -0700802 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
803 panic("Error expected without shouldFail in " + test.name)
804 }
805
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700806 if test.expectResumeRejected && !test.resumeSession {
807 panic("expectResumeRejected without resumeSession in " + test.name)
808 }
809
David Benjamin87c8a642015-02-21 01:54:29 -0500810 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
811 if err != nil {
812 panic(err)
813 }
814 defer func() {
815 if listener != nil {
816 listener.Close()
817 }
818 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700819
David Benjamin87c8a642015-02-21 01:54:29 -0500820 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400821 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400822 flags = append(flags, "-server")
823
David Benjamin025b3d32014-07-01 19:53:04 -0400824 flags = append(flags, "-key-file")
825 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700826 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400827 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700828 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400829 }
830
831 flags = append(flags, "-cert-file")
832 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700833 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400834 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700835 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400836 }
837 }
David Benjamin5a593af2014-08-11 19:51:50 -0400838
David Benjamin6fd297b2014-08-11 18:43:38 -0400839 if test.protocol == dtls {
840 flags = append(flags, "-dtls")
841 }
842
David Benjamin46662482016-08-17 00:51:00 -0400843 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400844 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400845 resumeCount++
846 if test.resumeRenewedSession {
847 resumeCount++
848 }
849 }
850
851 if resumeCount > 0 {
852 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400853 }
854
David Benjamine58c4f52014-08-24 03:47:07 -0400855 if test.shimWritesFirst {
856 flags = append(flags, "-shim-writes-first")
857 }
858
David Benjamin30789da2015-08-29 22:56:45 -0400859 if test.shimShutsDown {
860 flags = append(flags, "-shim-shuts-down")
861 }
862
David Benjaminc565ebb2015-04-03 04:06:36 -0400863 if test.exportKeyingMaterial > 0 {
864 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
865 flags = append(flags, "-export-label", test.exportLabel)
866 flags = append(flags, "-export-context", test.exportContext)
867 if test.useExportContext {
868 flags = append(flags, "-use-export-context")
869 }
870 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700871 if test.expectResumeRejected {
872 flags = append(flags, "-expect-session-miss")
873 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400874
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700875 if test.testTLSUnique {
876 flags = append(flags, "-tls-unique")
877 }
878
David Benjamin025b3d32014-07-01 19:53:04 -0400879 flags = append(flags, test.flags...)
880
881 var shim *exec.Cmd
882 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700883 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700884 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700885 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500886 } else if *useLLDB {
887 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400888 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700889 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400890 }
David Benjamin025b3d32014-07-01 19:53:04 -0400891 shim.Stdin = os.Stdin
892 var stdoutBuf, stderrBuf bytes.Buffer
893 shim.Stdout = &stdoutBuf
894 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800895 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500896 shim.Env = os.Environ()
897 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800898 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400899 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800900 }
901 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
902 }
David Benjamin025b3d32014-07-01 19:53:04 -0400903
904 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700905 panic(err)
906 }
David Benjamin87c8a642015-02-21 01:54:29 -0500907 waitChan := make(chan error, 1)
908 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700909
910 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700911
David Benjamin7a4aaa42016-09-20 17:58:14 -0400912 if *deterministic {
913 config.Rand = &deterministicRand{}
914 }
915
David Benjamin87c8a642015-02-21 01:54:29 -0500916 conn, err := acceptOrWait(listener, waitChan)
917 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400918 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500919 conn.Close()
920 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500921
David Benjamin46662482016-08-17 00:51:00 -0400922 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400923 var resumeConfig Config
924 if test.resumeConfig != nil {
925 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400926 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500927 resumeConfig.SessionTicketKey = config.SessionTicketKey
928 resumeConfig.ClientSessionCache = config.ClientSessionCache
929 resumeConfig.ServerSessionCache = config.ServerSessionCache
930 }
David Benjamin2e045a92016-06-08 13:09:56 -0400931 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400932 } else {
933 resumeConfig = config
934 }
David Benjamin87c8a642015-02-21 01:54:29 -0500935 var connResume net.Conn
936 connResume, err = acceptOrWait(listener, waitChan)
937 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400938 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500939 connResume.Close()
940 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400941 }
942
David Benjamin87c8a642015-02-21 01:54:29 -0500943 // Close the listener now. This is to avoid hangs should the shim try to
944 // open more connections than expected.
945 listener.Close()
946 listener = nil
947
948 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400949 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800950 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200951 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
952 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800953 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200954 case 89:
955 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400956 case 99:
957 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800958 }
959 }
Adam Langley95c29f32014-06-20 12:00:00 -0700960
David Benjamin9bea3492016-03-02 10:59:16 -0500961 // Account for Windows line endings.
962 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
963 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500964
965 // Separate the errors from the shim and those from tools like
966 // AddressSanitizer.
967 var extraStderr string
968 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
969 stderr = stderrParts[0]
970 extraStderr = stderrParts[1]
971 }
972
Adam Langley95c29f32014-06-20 12:00:00 -0700973 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700974 expectedError := translateExpectedError(test.expectedError)
975 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200976
Adam Langleyac61fa32014-06-23 12:03:11 -0700977 localError := "none"
978 if err != nil {
979 localError = err.Error()
980 }
981 if len(test.expectedLocalError) != 0 {
982 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
983 }
Adam Langley95c29f32014-06-20 12:00:00 -0700984
985 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700986 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700987 if childErr != nil {
988 childError = childErr.Error()
989 }
990
991 var msg string
992 switch {
993 case failed && !test.shouldFail:
994 msg = "unexpected failure"
995 case !failed && test.shouldFail:
996 msg = "unexpected success"
997 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700998 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700999 default:
1000 panic("internal error")
1001 }
1002
David Benjamin9aafb642016-09-20 19:36:53 -04001003 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 -07001004 }
1005
David Benjamind2ba8892016-09-20 19:41:04 -04001006 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001007 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001008 }
1009
David Benjamind2ba8892016-09-20 19:41:04 -04001010 if *useValgrind && isValgrindError {
1011 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1012 }
1013
Adam Langley95c29f32014-06-20 12:00:00 -07001014 return nil
1015}
1016
1017var tlsVersions = []struct {
1018 name string
1019 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001020 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001021 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001022}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001023 {"SSL3", VersionSSL30, "-no-ssl3", false},
1024 {"TLS1", VersionTLS10, "-no-tls1", true},
1025 {"TLS11", VersionTLS11, "-no-tls11", false},
1026 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001027 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001028}
1029
1030var testCipherSuites = []struct {
1031 name string
1032 id uint16
1033}{
1034 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001035 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001036 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001037 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001038 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001039 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001040 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001041 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1042 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001043 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001044 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1045 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001046 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001047 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1048 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001049 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1050 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001051 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001052 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001053 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001054 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001055 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001056 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001057 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001058 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001059 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001060 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001061 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001062 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001063 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1064 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1065 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1066 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001067 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1068 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001069 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1070 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001071 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001072 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1073 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1074 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001075 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001076}
1077
David Benjamin8b8c0062014-11-23 02:47:52 -05001078func hasComponent(suiteName, component string) bool {
1079 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1080}
1081
David Benjaminf7768e42014-08-31 02:06:47 -04001082func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001083 return hasComponent(suiteName, "GCM") ||
1084 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001085 hasComponent(suiteName, "SHA384") ||
1086 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001087}
1088
Nick Harper1fd39d82016-06-14 18:14:35 -07001089func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001090 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001091}
1092
David Benjamin8b8c0062014-11-23 02:47:52 -05001093func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001094 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001095}
1096
Adam Langleya7997f12015-05-14 17:38:50 -07001097func bigFromHex(hex string) *big.Int {
1098 ret, ok := new(big.Int).SetString(hex, 16)
1099 if !ok {
1100 panic("failed to parse hex number 0x" + hex)
1101 }
1102 return ret
1103}
1104
Adam Langley7c803a62015-06-15 15:35:05 -07001105func addBasicTests() {
1106 basicTests := []testCase{
1107 {
Adam Langley7c803a62015-06-15 15:35:05 -07001108 name: "NoFallbackSCSV",
1109 config: Config{
1110 Bugs: ProtocolBugs{
1111 FailIfNotFallbackSCSV: true,
1112 },
1113 },
1114 shouldFail: true,
1115 expectedLocalError: "no fallback SCSV found",
1116 },
1117 {
1118 name: "SendFallbackSCSV",
1119 config: Config{
1120 Bugs: ProtocolBugs{
1121 FailIfNotFallbackSCSV: true,
1122 },
1123 },
1124 flags: []string{"-fallback-scsv"},
1125 },
1126 {
1127 name: "ClientCertificateTypes",
1128 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001129 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001130 ClientAuth: RequestClientCert,
1131 ClientCertificateTypes: []byte{
1132 CertTypeDSSSign,
1133 CertTypeRSASign,
1134 CertTypeECDSASign,
1135 },
1136 },
1137 flags: []string{
1138 "-expect-certificate-types",
1139 base64.StdEncoding.EncodeToString([]byte{
1140 CertTypeDSSSign,
1141 CertTypeRSASign,
1142 CertTypeECDSASign,
1143 }),
1144 },
1145 },
1146 {
Adam Langley7c803a62015-06-15 15:35:05 -07001147 name: "UnauthenticatedECDH",
1148 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001149 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001150 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1151 Bugs: ProtocolBugs{
1152 UnauthenticatedECDH: true,
1153 },
1154 },
1155 shouldFail: true,
1156 expectedError: ":UNEXPECTED_MESSAGE:",
1157 },
1158 {
1159 name: "SkipCertificateStatus",
1160 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001161 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001162 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1163 Bugs: ProtocolBugs{
1164 SkipCertificateStatus: true,
1165 },
1166 },
1167 flags: []string{
1168 "-enable-ocsp-stapling",
1169 },
1170 },
1171 {
1172 name: "SkipServerKeyExchange",
1173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001174 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1176 Bugs: ProtocolBugs{
1177 SkipServerKeyExchange: true,
1178 },
1179 },
1180 shouldFail: true,
1181 expectedError: ":UNEXPECTED_MESSAGE:",
1182 },
1183 {
Adam Langley7c803a62015-06-15 15:35:05 -07001184 testType: serverTest,
1185 name: "Alert",
1186 config: Config{
1187 Bugs: ProtocolBugs{
1188 SendSpuriousAlert: alertRecordOverflow,
1189 },
1190 },
1191 shouldFail: true,
1192 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1193 },
1194 {
1195 protocol: dtls,
1196 testType: serverTest,
1197 name: "Alert-DTLS",
1198 config: Config{
1199 Bugs: ProtocolBugs{
1200 SendSpuriousAlert: alertRecordOverflow,
1201 },
1202 },
1203 shouldFail: true,
1204 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1205 },
1206 {
1207 testType: serverTest,
1208 name: "FragmentAlert",
1209 config: Config{
1210 Bugs: ProtocolBugs{
1211 FragmentAlert: true,
1212 SendSpuriousAlert: alertRecordOverflow,
1213 },
1214 },
1215 shouldFail: true,
1216 expectedError: ":BAD_ALERT:",
1217 },
1218 {
1219 protocol: dtls,
1220 testType: serverTest,
1221 name: "FragmentAlert-DTLS",
1222 config: Config{
1223 Bugs: ProtocolBugs{
1224 FragmentAlert: true,
1225 SendSpuriousAlert: alertRecordOverflow,
1226 },
1227 },
1228 shouldFail: true,
1229 expectedError: ":BAD_ALERT:",
1230 },
1231 {
1232 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001233 name: "DoubleAlert",
1234 config: Config{
1235 Bugs: ProtocolBugs{
1236 DoubleAlert: true,
1237 SendSpuriousAlert: alertRecordOverflow,
1238 },
1239 },
1240 shouldFail: true,
1241 expectedError: ":BAD_ALERT:",
1242 },
1243 {
1244 protocol: dtls,
1245 testType: serverTest,
1246 name: "DoubleAlert-DTLS",
1247 config: Config{
1248 Bugs: ProtocolBugs{
1249 DoubleAlert: true,
1250 SendSpuriousAlert: alertRecordOverflow,
1251 },
1252 },
1253 shouldFail: true,
1254 expectedError: ":BAD_ALERT:",
1255 },
1256 {
Adam Langley7c803a62015-06-15 15:35:05 -07001257 name: "SkipNewSessionTicket",
1258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001259 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001260 Bugs: ProtocolBugs{
1261 SkipNewSessionTicket: true,
1262 },
1263 },
1264 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001265 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001266 },
1267 {
1268 testType: serverTest,
1269 name: "FallbackSCSV",
1270 config: Config{
1271 MaxVersion: VersionTLS11,
1272 Bugs: ProtocolBugs{
1273 SendFallbackSCSV: true,
1274 },
1275 },
1276 shouldFail: true,
1277 expectedError: ":INAPPROPRIATE_FALLBACK:",
1278 },
1279 {
1280 testType: serverTest,
1281 name: "FallbackSCSV-VersionMatch",
1282 config: Config{
1283 Bugs: ProtocolBugs{
1284 SendFallbackSCSV: true,
1285 },
1286 },
1287 },
1288 {
1289 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001290 name: "FallbackSCSV-VersionMatch-TLS12",
1291 config: Config{
1292 MaxVersion: VersionTLS12,
1293 Bugs: ProtocolBugs{
1294 SendFallbackSCSV: true,
1295 },
1296 },
1297 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1298 },
1299 {
1300 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001301 name: "FragmentedClientVersion",
1302 config: Config{
1303 Bugs: ProtocolBugs{
1304 MaxHandshakeRecordLength: 1,
1305 FragmentClientVersion: true,
1306 },
1307 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001308 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001309 },
1310 {
Adam Langley7c803a62015-06-15 15:35:05 -07001311 testType: serverTest,
1312 name: "HttpGET",
1313 sendPrefix: "GET / HTTP/1.0\n",
1314 shouldFail: true,
1315 expectedError: ":HTTP_REQUEST:",
1316 },
1317 {
1318 testType: serverTest,
1319 name: "HttpPOST",
1320 sendPrefix: "POST / HTTP/1.0\n",
1321 shouldFail: true,
1322 expectedError: ":HTTP_REQUEST:",
1323 },
1324 {
1325 testType: serverTest,
1326 name: "HttpHEAD",
1327 sendPrefix: "HEAD / HTTP/1.0\n",
1328 shouldFail: true,
1329 expectedError: ":HTTP_REQUEST:",
1330 },
1331 {
1332 testType: serverTest,
1333 name: "HttpPUT",
1334 sendPrefix: "PUT / HTTP/1.0\n",
1335 shouldFail: true,
1336 expectedError: ":HTTP_REQUEST:",
1337 },
1338 {
1339 testType: serverTest,
1340 name: "HttpCONNECT",
1341 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1342 shouldFail: true,
1343 expectedError: ":HTTPS_PROXY_REQUEST:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "Garbage",
1348 sendPrefix: "blah",
1349 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001350 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001351 },
1352 {
Adam Langley7c803a62015-06-15 15:35:05 -07001353 name: "RSAEphemeralKey",
1354 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001355 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001356 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1357 Bugs: ProtocolBugs{
1358 RSAEphemeralKey: true,
1359 },
1360 },
1361 shouldFail: true,
1362 expectedError: ":UNEXPECTED_MESSAGE:",
1363 },
1364 {
1365 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001366 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001367 shouldFail: true,
1368 expectedError: ":WRONG_SSL_VERSION:",
1369 },
1370 {
1371 protocol: dtls,
1372 name: "DisableEverything-DTLS",
1373 flags: []string{"-no-tls12", "-no-tls1"},
1374 shouldFail: true,
1375 expectedError: ":WRONG_SSL_VERSION:",
1376 },
1377 {
Adam Langley7c803a62015-06-15 15:35:05 -07001378 protocol: dtls,
1379 testType: serverTest,
1380 name: "MTU",
1381 config: Config{
1382 Bugs: ProtocolBugs{
1383 MaxPacketLength: 256,
1384 },
1385 },
1386 flags: []string{"-mtu", "256"},
1387 },
1388 {
1389 protocol: dtls,
1390 testType: serverTest,
1391 name: "MTUExceeded",
1392 config: Config{
1393 Bugs: ProtocolBugs{
1394 MaxPacketLength: 255,
1395 },
1396 },
1397 flags: []string{"-mtu", "256"},
1398 shouldFail: true,
1399 expectedLocalError: "dtls: exceeded maximum packet length",
1400 },
1401 {
1402 name: "CertMismatchRSA",
1403 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001404 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001405 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001406 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001407 Bugs: ProtocolBugs{
1408 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1409 },
1410 },
1411 shouldFail: true,
1412 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1413 },
1414 {
1415 name: "CertMismatchECDSA",
1416 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001417 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001418 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001419 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001420 Bugs: ProtocolBugs{
1421 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1422 },
1423 },
1424 shouldFail: true,
1425 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1426 },
1427 {
1428 name: "EmptyCertificateList",
1429 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001430 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001431 Bugs: ProtocolBugs{
1432 EmptyCertificateList: true,
1433 },
1434 },
1435 shouldFail: true,
1436 expectedError: ":DECODE_ERROR:",
1437 },
1438 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001439 name: "EmptyCertificateList-TLS13",
1440 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001441 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001442 Bugs: ProtocolBugs{
1443 EmptyCertificateList: true,
1444 },
1445 },
1446 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001447 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001448 },
1449 {
Adam Langley7c803a62015-06-15 15:35:05 -07001450 name: "TLSFatalBadPackets",
1451 damageFirstWrite: true,
1452 shouldFail: true,
1453 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1454 },
1455 {
1456 protocol: dtls,
1457 name: "DTLSIgnoreBadPackets",
1458 damageFirstWrite: true,
1459 },
1460 {
1461 protocol: dtls,
1462 name: "DTLSIgnoreBadPackets-Async",
1463 damageFirstWrite: true,
1464 flags: []string{"-async"},
1465 },
1466 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001467 name: "AppDataBeforeHandshake",
1468 config: Config{
1469 Bugs: ProtocolBugs{
1470 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1471 },
1472 },
1473 shouldFail: true,
1474 expectedError: ":UNEXPECTED_RECORD:",
1475 },
1476 {
1477 name: "AppDataBeforeHandshake-Empty",
1478 config: Config{
1479 Bugs: ProtocolBugs{
1480 AppDataBeforeHandshake: []byte{},
1481 },
1482 },
1483 shouldFail: true,
1484 expectedError: ":UNEXPECTED_RECORD:",
1485 },
1486 {
1487 protocol: dtls,
1488 name: "AppDataBeforeHandshake-DTLS",
1489 config: Config{
1490 Bugs: ProtocolBugs{
1491 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1492 },
1493 },
1494 shouldFail: true,
1495 expectedError: ":UNEXPECTED_RECORD:",
1496 },
1497 {
1498 protocol: dtls,
1499 name: "AppDataBeforeHandshake-DTLS-Empty",
1500 config: Config{
1501 Bugs: ProtocolBugs{
1502 AppDataBeforeHandshake: []byte{},
1503 },
1504 },
1505 shouldFail: true,
1506 expectedError: ":UNEXPECTED_RECORD:",
1507 },
1508 {
Adam Langley7c803a62015-06-15 15:35:05 -07001509 name: "AppDataAfterChangeCipherSpec",
1510 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001511 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001512 Bugs: ProtocolBugs{
1513 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1514 },
1515 },
1516 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001517 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001518 },
1519 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001520 name: "AppDataAfterChangeCipherSpec-Empty",
1521 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001522 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001523 Bugs: ProtocolBugs{
1524 AppDataAfterChangeCipherSpec: []byte{},
1525 },
1526 },
1527 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001528 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001529 },
1530 {
Adam Langley7c803a62015-06-15 15:35:05 -07001531 protocol: dtls,
1532 name: "AppDataAfterChangeCipherSpec-DTLS",
1533 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001534 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001535 Bugs: ProtocolBugs{
1536 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1537 },
1538 },
1539 // BoringSSL's DTLS implementation will drop the out-of-order
1540 // application data.
1541 },
1542 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001543 protocol: dtls,
1544 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1545 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001546 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001547 Bugs: ProtocolBugs{
1548 AppDataAfterChangeCipherSpec: []byte{},
1549 },
1550 },
1551 // BoringSSL's DTLS implementation will drop the out-of-order
1552 // application data.
1553 },
1554 {
Adam Langley7c803a62015-06-15 15:35:05 -07001555 name: "AlertAfterChangeCipherSpec",
1556 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001557 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001558 Bugs: ProtocolBugs{
1559 AlertAfterChangeCipherSpec: alertRecordOverflow,
1560 },
1561 },
1562 shouldFail: true,
1563 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1564 },
1565 {
1566 protocol: dtls,
1567 name: "AlertAfterChangeCipherSpec-DTLS",
1568 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001569 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001570 Bugs: ProtocolBugs{
1571 AlertAfterChangeCipherSpec: alertRecordOverflow,
1572 },
1573 },
1574 shouldFail: true,
1575 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1576 },
1577 {
1578 protocol: dtls,
1579 name: "ReorderHandshakeFragments-Small-DTLS",
1580 config: Config{
1581 Bugs: ProtocolBugs{
1582 ReorderHandshakeFragments: true,
1583 // Small enough that every handshake message is
1584 // fragmented.
1585 MaxHandshakeRecordLength: 2,
1586 },
1587 },
1588 },
1589 {
1590 protocol: dtls,
1591 name: "ReorderHandshakeFragments-Large-DTLS",
1592 config: Config{
1593 Bugs: ProtocolBugs{
1594 ReorderHandshakeFragments: true,
1595 // Large enough that no handshake message is
1596 // fragmented.
1597 MaxHandshakeRecordLength: 2048,
1598 },
1599 },
1600 },
1601 {
1602 protocol: dtls,
1603 name: "MixCompleteMessageWithFragments-DTLS",
1604 config: Config{
1605 Bugs: ProtocolBugs{
1606 ReorderHandshakeFragments: true,
1607 MixCompleteMessageWithFragments: true,
1608 MaxHandshakeRecordLength: 2,
1609 },
1610 },
1611 },
1612 {
1613 name: "SendInvalidRecordType",
1614 config: Config{
1615 Bugs: ProtocolBugs{
1616 SendInvalidRecordType: true,
1617 },
1618 },
1619 shouldFail: true,
1620 expectedError: ":UNEXPECTED_RECORD:",
1621 },
1622 {
1623 protocol: dtls,
1624 name: "SendInvalidRecordType-DTLS",
1625 config: Config{
1626 Bugs: ProtocolBugs{
1627 SendInvalidRecordType: true,
1628 },
1629 },
1630 shouldFail: true,
1631 expectedError: ":UNEXPECTED_RECORD:",
1632 },
1633 {
1634 name: "FalseStart-SkipServerSecondLeg",
1635 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001636 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001637 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1638 NextProtos: []string{"foo"},
1639 Bugs: ProtocolBugs{
1640 SkipNewSessionTicket: true,
1641 SkipChangeCipherSpec: true,
1642 SkipFinished: true,
1643 ExpectFalseStart: true,
1644 },
1645 },
1646 flags: []string{
1647 "-false-start",
1648 "-handshake-never-done",
1649 "-advertise-alpn", "\x03foo",
1650 },
1651 shimWritesFirst: true,
1652 shouldFail: true,
1653 expectedError: ":UNEXPECTED_RECORD:",
1654 },
1655 {
1656 name: "FalseStart-SkipServerSecondLeg-Implicit",
1657 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001658 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001659 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1660 NextProtos: []string{"foo"},
1661 Bugs: ProtocolBugs{
1662 SkipNewSessionTicket: true,
1663 SkipChangeCipherSpec: true,
1664 SkipFinished: true,
1665 },
1666 },
1667 flags: []string{
1668 "-implicit-handshake",
1669 "-false-start",
1670 "-handshake-never-done",
1671 "-advertise-alpn", "\x03foo",
1672 },
1673 shouldFail: true,
1674 expectedError: ":UNEXPECTED_RECORD:",
1675 },
1676 {
1677 testType: serverTest,
1678 name: "FailEarlyCallback",
1679 flags: []string{"-fail-early-callback"},
1680 shouldFail: true,
1681 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001682 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001683 },
1684 {
Adam Langley7c803a62015-06-15 15:35:05 -07001685 protocol: dtls,
1686 name: "FragmentMessageTypeMismatch-DTLS",
1687 config: Config{
1688 Bugs: ProtocolBugs{
1689 MaxHandshakeRecordLength: 2,
1690 FragmentMessageTypeMismatch: true,
1691 },
1692 },
1693 shouldFail: true,
1694 expectedError: ":FRAGMENT_MISMATCH:",
1695 },
1696 {
1697 protocol: dtls,
1698 name: "FragmentMessageLengthMismatch-DTLS",
1699 config: Config{
1700 Bugs: ProtocolBugs{
1701 MaxHandshakeRecordLength: 2,
1702 FragmentMessageLengthMismatch: true,
1703 },
1704 },
1705 shouldFail: true,
1706 expectedError: ":FRAGMENT_MISMATCH:",
1707 },
1708 {
1709 protocol: dtls,
1710 name: "SplitFragments-Header-DTLS",
1711 config: Config{
1712 Bugs: ProtocolBugs{
1713 SplitFragments: 2,
1714 },
1715 },
1716 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001717 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001718 },
1719 {
1720 protocol: dtls,
1721 name: "SplitFragments-Boundary-DTLS",
1722 config: Config{
1723 Bugs: ProtocolBugs{
1724 SplitFragments: dtlsRecordHeaderLen,
1725 },
1726 },
1727 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001728 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001729 },
1730 {
1731 protocol: dtls,
1732 name: "SplitFragments-Body-DTLS",
1733 config: Config{
1734 Bugs: ProtocolBugs{
1735 SplitFragments: dtlsRecordHeaderLen + 1,
1736 },
1737 },
1738 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001739 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001740 },
1741 {
1742 protocol: dtls,
1743 name: "SendEmptyFragments-DTLS",
1744 config: Config{
1745 Bugs: ProtocolBugs{
1746 SendEmptyFragments: true,
1747 },
1748 },
1749 },
1750 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001751 name: "BadFinished-Client",
1752 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001753 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001754 Bugs: ProtocolBugs{
1755 BadFinished: true,
1756 },
1757 },
1758 shouldFail: true,
1759 expectedError: ":DIGEST_CHECK_FAILED:",
1760 },
1761 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001762 name: "BadFinished-Client-TLS13",
1763 config: Config{
1764 MaxVersion: VersionTLS13,
1765 Bugs: ProtocolBugs{
1766 BadFinished: true,
1767 },
1768 },
1769 shouldFail: true,
1770 expectedError: ":DIGEST_CHECK_FAILED:",
1771 },
1772 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001773 testType: serverTest,
1774 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001775 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001776 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001777 Bugs: ProtocolBugs{
1778 BadFinished: true,
1779 },
1780 },
1781 shouldFail: true,
1782 expectedError: ":DIGEST_CHECK_FAILED:",
1783 },
1784 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001785 testType: serverTest,
1786 name: "BadFinished-Server-TLS13",
1787 config: Config{
1788 MaxVersion: VersionTLS13,
1789 Bugs: ProtocolBugs{
1790 BadFinished: true,
1791 },
1792 },
1793 shouldFail: true,
1794 expectedError: ":DIGEST_CHECK_FAILED:",
1795 },
1796 {
Adam Langley7c803a62015-06-15 15:35:05 -07001797 name: "FalseStart-BadFinished",
1798 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001799 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001800 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1801 NextProtos: []string{"foo"},
1802 Bugs: ProtocolBugs{
1803 BadFinished: true,
1804 ExpectFalseStart: true,
1805 },
1806 },
1807 flags: []string{
1808 "-false-start",
1809 "-handshake-never-done",
1810 "-advertise-alpn", "\x03foo",
1811 },
1812 shimWritesFirst: true,
1813 shouldFail: true,
1814 expectedError: ":DIGEST_CHECK_FAILED:",
1815 },
1816 {
1817 name: "NoFalseStart-NoALPN",
1818 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001819 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001820 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1821 Bugs: ProtocolBugs{
1822 ExpectFalseStart: true,
1823 AlertBeforeFalseStartTest: alertAccessDenied,
1824 },
1825 },
1826 flags: []string{
1827 "-false-start",
1828 },
1829 shimWritesFirst: true,
1830 shouldFail: true,
1831 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1832 expectedLocalError: "tls: peer did not false start: EOF",
1833 },
1834 {
1835 name: "NoFalseStart-NoAEAD",
1836 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001837 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1839 NextProtos: []string{"foo"},
1840 Bugs: ProtocolBugs{
1841 ExpectFalseStart: true,
1842 AlertBeforeFalseStartTest: alertAccessDenied,
1843 },
1844 },
1845 flags: []string{
1846 "-false-start",
1847 "-advertise-alpn", "\x03foo",
1848 },
1849 shimWritesFirst: true,
1850 shouldFail: true,
1851 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1852 expectedLocalError: "tls: peer did not false start: EOF",
1853 },
1854 {
1855 name: "NoFalseStart-RSA",
1856 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001857 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001858 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1859 NextProtos: []string{"foo"},
1860 Bugs: ProtocolBugs{
1861 ExpectFalseStart: true,
1862 AlertBeforeFalseStartTest: alertAccessDenied,
1863 },
1864 },
1865 flags: []string{
1866 "-false-start",
1867 "-advertise-alpn", "\x03foo",
1868 },
1869 shimWritesFirst: true,
1870 shouldFail: true,
1871 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1872 expectedLocalError: "tls: peer did not false start: EOF",
1873 },
1874 {
1875 name: "NoFalseStart-DHE_RSA",
1876 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001877 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001878 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1879 NextProtos: []string{"foo"},
1880 Bugs: ProtocolBugs{
1881 ExpectFalseStart: true,
1882 AlertBeforeFalseStartTest: alertAccessDenied,
1883 },
1884 },
1885 flags: []string{
1886 "-false-start",
1887 "-advertise-alpn", "\x03foo",
1888 },
1889 shimWritesFirst: true,
1890 shouldFail: true,
1891 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1892 expectedLocalError: "tls: peer did not false start: EOF",
1893 },
1894 {
Adam Langley7c803a62015-06-15 15:35:05 -07001895 protocol: dtls,
1896 name: "SendSplitAlert-Sync",
1897 config: Config{
1898 Bugs: ProtocolBugs{
1899 SendSplitAlert: true,
1900 },
1901 },
1902 },
1903 {
1904 protocol: dtls,
1905 name: "SendSplitAlert-Async",
1906 config: Config{
1907 Bugs: ProtocolBugs{
1908 SendSplitAlert: true,
1909 },
1910 },
1911 flags: []string{"-async"},
1912 },
1913 {
1914 protocol: dtls,
1915 name: "PackDTLSHandshake",
1916 config: Config{
1917 Bugs: ProtocolBugs{
1918 MaxHandshakeRecordLength: 2,
1919 PackHandshakeFragments: 20,
1920 PackHandshakeRecords: 200,
1921 },
1922 },
1923 },
1924 {
Adam Langley7c803a62015-06-15 15:35:05 -07001925 name: "SendEmptyRecords-Pass",
1926 sendEmptyRecords: 32,
1927 },
1928 {
1929 name: "SendEmptyRecords",
1930 sendEmptyRecords: 33,
1931 shouldFail: true,
1932 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1933 },
1934 {
1935 name: "SendEmptyRecords-Async",
1936 sendEmptyRecords: 33,
1937 flags: []string{"-async"},
1938 shouldFail: true,
1939 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1940 },
1941 {
David Benjamine8e84b92016-08-03 15:39:47 -04001942 name: "SendWarningAlerts-Pass",
1943 config: Config{
1944 MaxVersion: VersionTLS12,
1945 },
Adam Langley7c803a62015-06-15 15:35:05 -07001946 sendWarningAlerts: 4,
1947 },
1948 {
David Benjamine8e84b92016-08-03 15:39:47 -04001949 protocol: dtls,
1950 name: "SendWarningAlerts-DTLS-Pass",
1951 config: Config{
1952 MaxVersion: VersionTLS12,
1953 },
Adam Langley7c803a62015-06-15 15:35:05 -07001954 sendWarningAlerts: 4,
1955 },
1956 {
David Benjamine8e84b92016-08-03 15:39:47 -04001957 name: "SendWarningAlerts-TLS13",
1958 config: Config{
1959 MaxVersion: VersionTLS13,
1960 },
1961 sendWarningAlerts: 4,
1962 shouldFail: true,
1963 expectedError: ":BAD_ALERT:",
1964 expectedLocalError: "remote error: error decoding message",
1965 },
1966 {
1967 name: "SendWarningAlerts",
1968 config: Config{
1969 MaxVersion: VersionTLS12,
1970 },
Adam Langley7c803a62015-06-15 15:35:05 -07001971 sendWarningAlerts: 5,
1972 shouldFail: true,
1973 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1974 },
1975 {
David Benjamine8e84b92016-08-03 15:39:47 -04001976 name: "SendWarningAlerts-Async",
1977 config: Config{
1978 MaxVersion: VersionTLS12,
1979 },
Adam Langley7c803a62015-06-15 15:35:05 -07001980 sendWarningAlerts: 5,
1981 flags: []string{"-async"},
1982 shouldFail: true,
1983 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1984 },
David Benjaminba4594a2015-06-18 18:36:15 -04001985 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04001986 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04001987 config: Config{
1988 MaxVersion: VersionTLS13,
1989 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04001990 sendKeyUpdates: 33,
1991 keyUpdateRequest: keyUpdateNotRequested,
1992 shouldFail: true,
1993 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04001994 },
1995 {
David Benjaminba4594a2015-06-18 18:36:15 -04001996 name: "EmptySessionID",
1997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001998 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001999 SessionTicketsDisabled: true,
2000 },
2001 noSessionCache: true,
2002 flags: []string{"-expect-no-session"},
2003 },
David Benjamin30789da2015-08-29 22:56:45 -04002004 {
2005 name: "Unclean-Shutdown",
2006 config: Config{
2007 Bugs: ProtocolBugs{
2008 NoCloseNotify: true,
2009 ExpectCloseNotify: true,
2010 },
2011 },
2012 shimShutsDown: true,
2013 flags: []string{"-check-close-notify"},
2014 shouldFail: true,
2015 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2016 },
2017 {
2018 name: "Unclean-Shutdown-Ignored",
2019 config: Config{
2020 Bugs: ProtocolBugs{
2021 NoCloseNotify: true,
2022 },
2023 },
2024 shimShutsDown: true,
2025 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002026 {
David Benjaminfa214e42016-05-10 17:03:10 -04002027 name: "Unclean-Shutdown-Alert",
2028 config: Config{
2029 Bugs: ProtocolBugs{
2030 SendAlertOnShutdown: alertDecompressionFailure,
2031 ExpectCloseNotify: true,
2032 },
2033 },
2034 shimShutsDown: true,
2035 flags: []string{"-check-close-notify"},
2036 shouldFail: true,
2037 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2038 },
2039 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002040 name: "LargePlaintext",
2041 config: Config{
2042 Bugs: ProtocolBugs{
2043 SendLargeRecords: true,
2044 },
2045 },
2046 messageLen: maxPlaintext + 1,
2047 shouldFail: true,
2048 expectedError: ":DATA_LENGTH_TOO_LONG:",
2049 },
2050 {
2051 protocol: dtls,
2052 name: "LargePlaintext-DTLS",
2053 config: Config{
2054 Bugs: ProtocolBugs{
2055 SendLargeRecords: true,
2056 },
2057 },
2058 messageLen: maxPlaintext + 1,
2059 shouldFail: true,
2060 expectedError: ":DATA_LENGTH_TOO_LONG:",
2061 },
2062 {
2063 name: "LargeCiphertext",
2064 config: Config{
2065 Bugs: ProtocolBugs{
2066 SendLargeRecords: true,
2067 },
2068 },
2069 messageLen: maxPlaintext * 2,
2070 shouldFail: true,
2071 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2072 },
2073 {
2074 protocol: dtls,
2075 name: "LargeCiphertext-DTLS",
2076 config: Config{
2077 Bugs: ProtocolBugs{
2078 SendLargeRecords: true,
2079 },
2080 },
2081 messageLen: maxPlaintext * 2,
2082 // Unlike the other four cases, DTLS drops records which
2083 // are invalid before authentication, so the connection
2084 // does not fail.
2085 expectMessageDropped: true,
2086 },
David Benjamindd6fed92015-10-23 17:41:12 -04002087 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002088 name: "BadHelloRequest-1",
2089 renegotiate: 1,
2090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002091 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002092 Bugs: ProtocolBugs{
2093 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2094 },
2095 },
2096 flags: []string{
2097 "-renegotiate-freely",
2098 "-expect-total-renegotiations", "1",
2099 },
2100 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002101 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002102 },
2103 {
2104 name: "BadHelloRequest-2",
2105 renegotiate: 1,
2106 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002107 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002108 Bugs: ProtocolBugs{
2109 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2110 },
2111 },
2112 flags: []string{
2113 "-renegotiate-freely",
2114 "-expect-total-renegotiations", "1",
2115 },
2116 shouldFail: true,
2117 expectedError: ":BAD_HELLO_REQUEST:",
2118 },
David Benjaminef1b0092015-11-21 14:05:44 -05002119 {
2120 testType: serverTest,
2121 name: "SupportTicketsWithSessionID",
2122 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002123 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002124 SessionTicketsDisabled: true,
2125 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002126 resumeConfig: &Config{
2127 MaxVersion: VersionTLS12,
2128 },
David Benjaminef1b0092015-11-21 14:05:44 -05002129 resumeSession: true,
2130 },
David Benjamin02edcd02016-07-27 17:40:37 -04002131 {
2132 protocol: dtls,
2133 name: "DTLS-SendExtraFinished",
2134 config: Config{
2135 Bugs: ProtocolBugs{
2136 SendExtraFinished: true,
2137 },
2138 },
2139 shouldFail: true,
2140 expectedError: ":UNEXPECTED_RECORD:",
2141 },
2142 {
2143 protocol: dtls,
2144 name: "DTLS-SendExtraFinished-Reordered",
2145 config: Config{
2146 Bugs: ProtocolBugs{
2147 MaxHandshakeRecordLength: 2,
2148 ReorderHandshakeFragments: true,
2149 SendExtraFinished: true,
2150 },
2151 },
2152 shouldFail: true,
2153 expectedError: ":UNEXPECTED_RECORD:",
2154 },
David Benjamine97fb482016-07-29 09:23:07 -04002155 {
2156 testType: serverTest,
2157 name: "V2ClientHello-EmptyRecordPrefix",
2158 config: Config{
2159 // Choose a cipher suite that does not involve
2160 // elliptic curves, so no extensions are
2161 // involved.
2162 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002163 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002164 Bugs: ProtocolBugs{
2165 SendV2ClientHello: true,
2166 },
2167 },
2168 sendPrefix: string([]byte{
2169 byte(recordTypeHandshake),
2170 3, 1, // version
2171 0, 0, // length
2172 }),
2173 // A no-op empty record may not be sent before V2ClientHello.
2174 shouldFail: true,
2175 expectedError: ":WRONG_VERSION_NUMBER:",
2176 },
2177 {
2178 testType: serverTest,
2179 name: "V2ClientHello-WarningAlertPrefix",
2180 config: Config{
2181 // Choose a cipher suite that does not involve
2182 // elliptic curves, so no extensions are
2183 // involved.
2184 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002185 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002186 Bugs: ProtocolBugs{
2187 SendV2ClientHello: true,
2188 },
2189 },
2190 sendPrefix: string([]byte{
2191 byte(recordTypeAlert),
2192 3, 1, // version
2193 0, 2, // length
2194 alertLevelWarning, byte(alertDecompressionFailure),
2195 }),
2196 // A no-op warning alert may not be sent before V2ClientHello.
2197 shouldFail: true,
2198 expectedError: ":WRONG_VERSION_NUMBER:",
2199 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002200 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002201 name: "KeyUpdate",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002202 config: Config{
2203 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002204 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002205 sendKeyUpdates: 1,
2206 keyUpdateRequest: keyUpdateNotRequested,
2207 },
2208 {
2209 name: "KeyUpdate-InvalidRequestMode",
2210 config: Config{
2211 MaxVersion: VersionTLS13,
2212 },
2213 sendKeyUpdates: 1,
2214 keyUpdateRequest: 42,
2215 shouldFail: true,
2216 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002217 },
David Benjaminabe94e32016-09-04 14:18:58 -04002218 {
2219 name: "SendSNIWarningAlert",
2220 config: Config{
2221 MaxVersion: VersionTLS12,
2222 Bugs: ProtocolBugs{
2223 SendSNIWarningAlert: true,
2224 },
2225 },
2226 },
David Benjaminc241d792016-09-09 10:34:20 -04002227 {
2228 testType: serverTest,
2229 name: "ExtraCompressionMethods-TLS12",
2230 config: Config{
2231 MaxVersion: VersionTLS12,
2232 Bugs: ProtocolBugs{
2233 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2234 },
2235 },
2236 },
2237 {
2238 testType: serverTest,
2239 name: "ExtraCompressionMethods-TLS13",
2240 config: Config{
2241 MaxVersion: VersionTLS13,
2242 Bugs: ProtocolBugs{
2243 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2244 },
2245 },
2246 shouldFail: true,
2247 expectedError: ":INVALID_COMPRESSION_LIST:",
2248 expectedLocalError: "remote error: illegal parameter",
2249 },
2250 {
2251 testType: serverTest,
2252 name: "NoNullCompression-TLS12",
2253 config: Config{
2254 MaxVersion: VersionTLS12,
2255 Bugs: ProtocolBugs{
2256 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2257 },
2258 },
2259 shouldFail: true,
2260 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2261 expectedLocalError: "remote error: illegal parameter",
2262 },
2263 {
2264 testType: serverTest,
2265 name: "NoNullCompression-TLS13",
2266 config: Config{
2267 MaxVersion: VersionTLS13,
2268 Bugs: ProtocolBugs{
2269 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2270 },
2271 },
2272 shouldFail: true,
2273 expectedError: ":INVALID_COMPRESSION_LIST:",
2274 expectedLocalError: "remote error: illegal parameter",
2275 },
David Benjamin65ac9972016-09-02 21:35:25 -04002276 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002277 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002278 config: Config{
2279 MaxVersion: VersionTLS12,
2280 Bugs: ProtocolBugs{
2281 ExpectGREASE: true,
2282 },
2283 },
2284 flags: []string{"-enable-grease"},
2285 },
2286 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002287 name: "GREASE-Client-TLS13",
2288 config: Config{
2289 MaxVersion: VersionTLS13,
2290 Bugs: ProtocolBugs{
2291 ExpectGREASE: true,
2292 },
2293 },
2294 flags: []string{"-enable-grease"},
2295 },
2296 {
2297 testType: serverTest,
2298 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002299 config: Config{
2300 MaxVersion: VersionTLS13,
2301 Bugs: ProtocolBugs{
2302 ExpectGREASE: true,
2303 },
2304 },
2305 flags: []string{"-enable-grease"},
2306 },
Adam Langley7c803a62015-06-15 15:35:05 -07002307 }
Adam Langley7c803a62015-06-15 15:35:05 -07002308 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002309
2310 // Test that very large messages can be received.
2311 cert := rsaCertificate
2312 for i := 0; i < 50; i++ {
2313 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2314 }
2315 testCases = append(testCases, testCase{
2316 name: "LargeMessage",
2317 config: Config{
2318 Certificates: []Certificate{cert},
2319 },
2320 })
2321 testCases = append(testCases, testCase{
2322 protocol: dtls,
2323 name: "LargeMessage-DTLS",
2324 config: Config{
2325 Certificates: []Certificate{cert},
2326 },
2327 })
2328
2329 // They are rejected if the maximum certificate chain length is capped.
2330 testCases = append(testCases, testCase{
2331 name: "LargeMessage-Reject",
2332 config: Config{
2333 Certificates: []Certificate{cert},
2334 },
2335 flags: []string{"-max-cert-list", "16384"},
2336 shouldFail: true,
2337 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2338 })
2339 testCases = append(testCases, testCase{
2340 protocol: dtls,
2341 name: "LargeMessage-Reject-DTLS",
2342 config: Config{
2343 Certificates: []Certificate{cert},
2344 },
2345 flags: []string{"-max-cert-list", "16384"},
2346 shouldFail: true,
2347 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2348 })
Adam Langley7c803a62015-06-15 15:35:05 -07002349}
2350
Adam Langley95c29f32014-06-20 12:00:00 -07002351func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002352 const bogusCipher = 0xfe00
2353
Adam Langley95c29f32014-06-20 12:00:00 -07002354 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002355 const psk = "12345"
2356 const pskIdentity = "luggage combo"
2357
Adam Langley95c29f32014-06-20 12:00:00 -07002358 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002359 var certFile string
2360 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002361 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002362 cert = ecdsaP256Certificate
2363 certFile = ecdsaP256CertificateFile
2364 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002365 } else {
David Benjamin33863262016-07-08 17:20:12 -07002366 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002367 certFile = rsaCertificateFile
2368 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002369 }
2370
David Benjamin48cae082014-10-27 01:06:24 -04002371 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002372 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002373 flags = append(flags,
2374 "-psk", psk,
2375 "-psk-identity", pskIdentity)
2376 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002377 if hasComponent(suite.name, "NULL") {
2378 // NULL ciphers must be explicitly enabled.
2379 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2380 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002381 if hasComponent(suite.name, "CECPQ1") {
2382 // CECPQ1 ciphers must be explicitly enabled.
2383 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2384 }
David Benjamin881f1962016-08-10 18:29:12 -04002385 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2386 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2387 // for now.
2388 flags = append(flags, "-cipher", suite.name)
2389 }
David Benjamin48cae082014-10-27 01:06:24 -04002390
Adam Langley95c29f32014-06-20 12:00:00 -07002391 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002392 for _, protocol := range []protocol{tls, dtls} {
2393 var prefix string
2394 if protocol == dtls {
2395 if !ver.hasDTLS {
2396 continue
2397 }
2398 prefix = "D"
2399 }
Adam Langley95c29f32014-06-20 12:00:00 -07002400
David Benjamin0407e762016-06-17 16:41:18 -04002401 var shouldServerFail, shouldClientFail bool
2402 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2403 // BoringSSL clients accept ECDHE on SSLv3, but
2404 // a BoringSSL server will never select it
2405 // because the extension is missing.
2406 shouldServerFail = true
2407 }
2408 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2409 shouldClientFail = true
2410 shouldServerFail = true
2411 }
David Benjamin54c217c2016-07-13 12:35:25 -04002412 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002413 shouldClientFail = true
2414 shouldServerFail = true
2415 }
Steven Valdez803c77a2016-09-06 14:13:43 -04002416 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2417 shouldClientFail = true
2418 shouldServerFail = true
2419 }
David Benjamin0407e762016-06-17 16:41:18 -04002420 if !isDTLSCipher(suite.name) && protocol == dtls {
2421 shouldClientFail = true
2422 shouldServerFail = true
2423 }
David Benjamin4298d772015-12-19 00:18:25 -05002424
David Benjamin5ecb88b2016-10-04 17:51:35 -04002425 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002426 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002427 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002428 if shouldServerFail {
2429 expectedServerError = ":NO_SHARED_CIPHER:"
2430 }
2431 if shouldClientFail {
2432 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002433 // Configure the server to select ciphers as normal but
2434 // select an incompatible cipher in ServerHello.
2435 serverCipherSuites = nil
2436 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002437 }
David Benjamin025b3d32014-07-01 19:53:04 -04002438
David Benjamin6fd297b2014-08-11 18:43:38 -04002439 testCases = append(testCases, testCase{
2440 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002441 protocol: protocol,
2442
2443 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002444 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002445 MinVersion: ver.version,
2446 MaxVersion: ver.version,
2447 CipherSuites: []uint16{suite.id},
2448 Certificates: []Certificate{cert},
2449 PreSharedKey: []byte(psk),
2450 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002451 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002452 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002453 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002454 },
2455 certFile: certFile,
2456 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002457 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002458 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002459 shouldFail: shouldServerFail,
2460 expectedError: expectedServerError,
2461 })
2462
2463 testCases = append(testCases, testCase{
2464 testType: clientTest,
2465 protocol: protocol,
2466 name: prefix + ver.name + "-" + suite.name + "-client",
2467 config: Config{
2468 MinVersion: ver.version,
2469 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002470 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002471 Certificates: []Certificate{cert},
2472 PreSharedKey: []byte(psk),
2473 PreSharedKeyIdentity: pskIdentity,
2474 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002475 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002476 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002477 },
2478 },
2479 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002480 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002481 shouldFail: shouldClientFail,
2482 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002483 })
David Benjamin2c99d282015-09-01 10:23:00 -04002484
Nick Harper1fd39d82016-06-14 18:14:35 -07002485 if !shouldClientFail {
2486 // Ensure the maximum record size is accepted.
2487 testCases = append(testCases, testCase{
2488 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2489 config: Config{
2490 MinVersion: ver.version,
2491 MaxVersion: ver.version,
2492 CipherSuites: []uint16{suite.id},
2493 Certificates: []Certificate{cert},
2494 PreSharedKey: []byte(psk),
2495 PreSharedKeyIdentity: pskIdentity,
2496 },
2497 flags: flags,
2498 messageLen: maxPlaintext,
2499 })
2500 }
2501 }
David Benjamin2c99d282015-09-01 10:23:00 -04002502 }
Adam Langley95c29f32014-06-20 12:00:00 -07002503 }
Adam Langleya7997f12015-05-14 17:38:50 -07002504
2505 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002506 name: "NoSharedCipher",
2507 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002508 MaxVersion: VersionTLS12,
2509 CipherSuites: []uint16{},
2510 },
2511 shouldFail: true,
2512 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2513 })
2514
2515 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002516 name: "NoSharedCipher-TLS13",
2517 config: Config{
2518 MaxVersion: VersionTLS13,
2519 CipherSuites: []uint16{},
2520 },
2521 shouldFail: true,
2522 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2523 })
2524
2525 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002526 name: "UnsupportedCipherSuite",
2527 config: Config{
2528 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002529 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002530 Bugs: ProtocolBugs{
2531 IgnorePeerCipherPreferences: true,
2532 },
2533 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002534 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002535 shouldFail: true,
2536 expectedError: ":WRONG_CIPHER_RETURNED:",
2537 })
2538
2539 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002540 name: "ServerHelloBogusCipher",
2541 config: Config{
2542 MaxVersion: VersionTLS12,
2543 Bugs: ProtocolBugs{
2544 SendCipherSuite: bogusCipher,
2545 },
2546 },
2547 shouldFail: true,
2548 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2549 })
2550 testCases = append(testCases, testCase{
2551 name: "ServerHelloBogusCipher-TLS13",
2552 config: Config{
2553 MaxVersion: VersionTLS13,
2554 Bugs: ProtocolBugs{
2555 SendCipherSuite: bogusCipher,
2556 },
2557 },
2558 shouldFail: true,
2559 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2560 })
2561
2562 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002563 name: "WeakDH",
2564 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002565 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002566 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2567 Bugs: ProtocolBugs{
2568 // This is a 1023-bit prime number, generated
2569 // with:
2570 // openssl gendh 1023 | openssl asn1parse -i
2571 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2572 },
2573 },
2574 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002575 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002576 })
Adam Langleycef75832015-09-03 14:51:12 -07002577
David Benjamincd24a392015-11-11 13:23:05 -08002578 testCases = append(testCases, testCase{
2579 name: "SillyDH",
2580 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002581 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002582 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2583 Bugs: ProtocolBugs{
2584 // This is a 4097-bit prime number, generated
2585 // with:
2586 // openssl gendh 4097 | openssl asn1parse -i
2587 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2588 },
2589 },
2590 shouldFail: true,
2591 expectedError: ":DH_P_TOO_LONG:",
2592 })
2593
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002594 // This test ensures that Diffie-Hellman public values are padded with
2595 // zeros so that they're the same length as the prime. This is to avoid
2596 // hitting a bug in yaSSL.
2597 testCases = append(testCases, testCase{
2598 testType: serverTest,
2599 name: "DHPublicValuePadded",
2600 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002601 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002602 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2603 Bugs: ProtocolBugs{
2604 RequireDHPublicValueLen: (1025 + 7) / 8,
2605 },
2606 },
2607 flags: []string{"-use-sparse-dh-prime"},
2608 })
David Benjamincd24a392015-11-11 13:23:05 -08002609
David Benjamin241ae832016-01-15 03:04:54 -05002610 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002611 testCases = append(testCases, testCase{
2612 testType: serverTest,
2613 name: "UnknownCipher",
2614 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002615 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002616 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002617 Bugs: ProtocolBugs{
2618 AdvertiseAllConfiguredCiphers: true,
2619 },
2620 },
2621 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002622
2623 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002624 testCases = append(testCases, testCase{
2625 testType: serverTest,
2626 name: "UnknownCipher-TLS13",
2627 config: Config{
2628 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002629 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002630 Bugs: ProtocolBugs{
2631 AdvertiseAllConfiguredCiphers: true,
2632 },
David Benjamin241ae832016-01-15 03:04:54 -05002633 },
2634 })
2635
David Benjamin78679342016-09-16 19:42:05 -04002636 // Test empty ECDHE_PSK identity hints work as expected.
2637 testCases = append(testCases, testCase{
2638 name: "EmptyECDHEPSKHint",
2639 config: Config{
2640 MaxVersion: VersionTLS12,
2641 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2642 PreSharedKey: []byte("secret"),
2643 },
2644 flags: []string{"-psk", "secret"},
2645 })
2646
2647 // Test empty PSK identity hints work as expected, even if an explicit
2648 // ServerKeyExchange is sent.
2649 testCases = append(testCases, testCase{
2650 name: "ExplicitEmptyPSKHint",
2651 config: Config{
2652 MaxVersion: VersionTLS12,
2653 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2654 PreSharedKey: []byte("secret"),
2655 Bugs: ProtocolBugs{
2656 AlwaysSendPreSharedKeyIdentityHint: true,
2657 },
2658 },
2659 flags: []string{"-psk", "secret"},
2660 })
2661
Adam Langleycef75832015-09-03 14:51:12 -07002662 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2663 // 1.1 specific cipher suite settings. A server is setup with the given
2664 // cipher lists and then a connection is made for each member of
2665 // expectations. The cipher suite that the server selects must match
2666 // the specified one.
2667 var versionSpecificCiphersTest = []struct {
2668 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2669 // expectations is a map from TLS version to cipher suite id.
2670 expectations map[uint16]uint16
2671 }{
2672 {
2673 // Test that the null case (where no version-specific ciphers are set)
2674 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002675 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2676 "", // no ciphers specifically for TLS ≥ 1.0
2677 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002678 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002679 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2680 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2681 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2682 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002683 },
2684 },
2685 {
2686 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2687 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002688 "DES-CBC3-SHA:AES128-SHA", // default
2689 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2690 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002691 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002692 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002693 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2694 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2695 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2696 },
2697 },
2698 {
2699 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2700 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002701 "DES-CBC3-SHA:AES128-SHA", // default
2702 "", // no ciphers specifically for TLS ≥ 1.0
2703 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002704 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002705 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2706 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002707 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2708 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2709 },
2710 },
2711 {
2712 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2713 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002714 "DES-CBC3-SHA:AES128-SHA", // default
2715 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2716 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002717 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002718 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002719 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2720 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2721 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2722 },
2723 },
2724 }
2725
2726 for i, test := range versionSpecificCiphersTest {
2727 for version, expectedCipherSuite := range test.expectations {
2728 flags := []string{"-cipher", test.ciphersDefault}
2729 if len(test.ciphersTLS10) > 0 {
2730 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2731 }
2732 if len(test.ciphersTLS11) > 0 {
2733 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2734 }
2735
2736 testCases = append(testCases, testCase{
2737 testType: serverTest,
2738 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2739 config: Config{
2740 MaxVersion: version,
2741 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002742 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 -07002743 },
2744 flags: flags,
2745 expectedCipher: expectedCipherSuite,
2746 })
2747 }
2748 }
Adam Langley95c29f32014-06-20 12:00:00 -07002749}
2750
2751func addBadECDSASignatureTests() {
2752 for badR := BadValue(1); badR < NumBadValues; badR++ {
2753 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002754 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002755 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2756 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002757 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002758 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002759 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002760 Bugs: ProtocolBugs{
2761 BadECDSAR: badR,
2762 BadECDSAS: badS,
2763 },
2764 },
2765 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002766 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002767 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002768 testCases = append(testCases, testCase{
2769 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2770 config: Config{
2771 MaxVersion: VersionTLS13,
2772 Certificates: []Certificate{ecdsaP256Certificate},
2773 Bugs: ProtocolBugs{
2774 BadECDSAR: badR,
2775 BadECDSAS: badS,
2776 },
2777 },
2778 shouldFail: true,
2779 expectedError: ":BAD_SIGNATURE:",
2780 })
Adam Langley95c29f32014-06-20 12:00:00 -07002781 }
2782 }
2783}
2784
Adam Langley80842bd2014-06-20 12:00:00 -07002785func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002786 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002787 name: "MaxCBCPadding",
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 MaxPadding: true,
2793 },
2794 },
2795 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2796 })
David Benjamin025b3d32014-07-01 19:53:04 -04002797 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002798 name: "BadCBCPadding",
2799 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002800 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002801 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2802 Bugs: ProtocolBugs{
2803 PaddingFirstByteBad: true,
2804 },
2805 },
2806 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002807 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002808 })
2809 // OpenSSL previously had an issue where the first byte of padding in
2810 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002811 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002812 name: "BadCBCPadding255",
2813 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002814 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002815 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2816 Bugs: ProtocolBugs{
2817 MaxPadding: true,
2818 PaddingFirstByteBadIf255: true,
2819 },
2820 },
2821 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2822 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002823 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002824 })
2825}
2826
Kenny Root7fdeaf12014-08-05 15:23:37 -07002827func addCBCSplittingTests() {
2828 testCases = append(testCases, testCase{
2829 name: "CBCRecordSplitting",
2830 config: Config{
2831 MaxVersion: VersionTLS10,
2832 MinVersion: VersionTLS10,
2833 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2834 },
David Benjaminac8302a2015-09-01 17:18:15 -04002835 messageLen: -1, // read until EOF
2836 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002837 flags: []string{
2838 "-async",
2839 "-write-different-record-sizes",
2840 "-cbc-record-splitting",
2841 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002842 })
2843 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002844 name: "CBCRecordSplittingPartialWrite",
2845 config: Config{
2846 MaxVersion: VersionTLS10,
2847 MinVersion: VersionTLS10,
2848 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2849 },
2850 messageLen: -1, // read until EOF
2851 flags: []string{
2852 "-async",
2853 "-write-different-record-sizes",
2854 "-cbc-record-splitting",
2855 "-partial-write",
2856 },
2857 })
2858}
2859
David Benjamin636293b2014-07-08 17:59:18 -04002860func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002861 // Add a dummy cert pool to stress certificate authority parsing.
2862 // TODO(davidben): Add tests that those values parse out correctly.
2863 certPool := x509.NewCertPool()
2864 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2865 if err != nil {
2866 panic(err)
2867 }
2868 certPool.AddCert(cert)
2869
David Benjamin636293b2014-07-08 17:59:18 -04002870 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002871 testCases = append(testCases, testCase{
2872 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002873 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002874 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002875 MinVersion: ver.version,
2876 MaxVersion: ver.version,
2877 ClientAuth: RequireAnyClientCert,
2878 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002879 },
2880 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002881 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2882 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002883 },
2884 })
2885 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002886 testType: serverTest,
2887 name: ver.name + "-Server-ClientAuth-RSA",
2888 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002889 MinVersion: ver.version,
2890 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002891 Certificates: []Certificate{rsaCertificate},
2892 },
2893 flags: []string{"-require-any-client-certificate"},
2894 })
David Benjamine098ec22014-08-27 23:13:20 -04002895 if ver.version != VersionSSL30 {
2896 testCases = append(testCases, testCase{
2897 testType: serverTest,
2898 name: ver.name + "-Server-ClientAuth-ECDSA",
2899 config: Config{
2900 MinVersion: ver.version,
2901 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002902 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002903 },
2904 flags: []string{"-require-any-client-certificate"},
2905 })
2906 testCases = append(testCases, testCase{
2907 testType: clientTest,
2908 name: ver.name + "-Client-ClientAuth-ECDSA",
2909 config: Config{
2910 MinVersion: ver.version,
2911 MaxVersion: ver.version,
2912 ClientAuth: RequireAnyClientCert,
2913 ClientCAs: certPool,
2914 },
2915 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002916 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2917 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002918 },
2919 })
2920 }
Adam Langley37646832016-08-01 16:16:46 -07002921
2922 testCases = append(testCases, testCase{
2923 name: "NoClientCertificate-" + ver.name,
2924 config: Config{
2925 MinVersion: ver.version,
2926 MaxVersion: ver.version,
2927 ClientAuth: RequireAnyClientCert,
2928 },
2929 shouldFail: true,
2930 expectedLocalError: "client didn't provide a certificate",
2931 })
2932
2933 testCases = append(testCases, testCase{
2934 // Even if not configured to expect a certificate, OpenSSL will
2935 // return X509_V_OK as the verify_result.
2936 testType: serverTest,
2937 name: "NoClientCertificateRequested-Server-" + ver.name,
2938 config: Config{
2939 MinVersion: ver.version,
2940 MaxVersion: ver.version,
2941 },
2942 flags: []string{
2943 "-expect-verify-result",
2944 },
David Benjamin5d9ba812016-10-07 20:51:20 -04002945 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07002946 })
2947
2948 testCases = append(testCases, testCase{
2949 // If a client certificate is not provided, OpenSSL will still
2950 // return X509_V_OK as the verify_result.
2951 testType: serverTest,
2952 name: "NoClientCertificate-Server-" + ver.name,
2953 config: Config{
2954 MinVersion: ver.version,
2955 MaxVersion: ver.version,
2956 },
2957 flags: []string{
2958 "-expect-verify-result",
2959 "-verify-peer",
2960 },
David Benjamin5d9ba812016-10-07 20:51:20 -04002961 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07002962 })
2963
David Benjamin1db9e1b2016-10-07 20:51:43 -04002964 certificateRequired := "remote error: certificate required"
2965 if ver.version < VersionTLS13 {
2966 // Prior to TLS 1.3, the generic handshake_failure alert
2967 // was used.
2968 certificateRequired = "remote error: handshake failure"
2969 }
Adam Langley37646832016-08-01 16:16:46 -07002970 testCases = append(testCases, testCase{
2971 testType: serverTest,
2972 name: "RequireAnyClientCertificate-" + ver.name,
2973 config: Config{
2974 MinVersion: ver.version,
2975 MaxVersion: ver.version,
2976 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04002977 flags: []string{"-require-any-client-certificate"},
2978 shouldFail: true,
2979 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2980 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07002981 })
2982
2983 if ver.version != VersionSSL30 {
2984 testCases = append(testCases, testCase{
2985 testType: serverTest,
2986 name: "SkipClientCertificate-" + ver.name,
2987 config: Config{
2988 MinVersion: ver.version,
2989 MaxVersion: ver.version,
2990 Bugs: ProtocolBugs{
2991 SkipClientCertificate: true,
2992 },
2993 },
2994 // Setting SSL_VERIFY_PEER allows anonymous clients.
2995 flags: []string{"-verify-peer"},
2996 shouldFail: true,
2997 expectedError: ":UNEXPECTED_MESSAGE:",
2998 })
2999 }
David Benjamin636293b2014-07-08 17:59:18 -04003000 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003001
David Benjaminc032dfa2016-05-12 14:54:57 -04003002 // Client auth is only legal in certificate-based ciphers.
3003 testCases = append(testCases, testCase{
3004 testType: clientTest,
3005 name: "ClientAuth-PSK",
3006 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003007 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003008 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3009 PreSharedKey: []byte("secret"),
3010 ClientAuth: RequireAnyClientCert,
3011 },
3012 flags: []string{
3013 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3014 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3015 "-psk", "secret",
3016 },
3017 shouldFail: true,
3018 expectedError: ":UNEXPECTED_MESSAGE:",
3019 })
3020 testCases = append(testCases, testCase{
3021 testType: clientTest,
3022 name: "ClientAuth-ECDHE_PSK",
3023 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003024 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003025 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3026 PreSharedKey: []byte("secret"),
3027 ClientAuth: RequireAnyClientCert,
3028 },
3029 flags: []string{
3030 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3031 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3032 "-psk", "secret",
3033 },
3034 shouldFail: true,
3035 expectedError: ":UNEXPECTED_MESSAGE:",
3036 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003037
3038 // Regression test for a bug where the client CA list, if explicitly
3039 // set to NULL, was mis-encoded.
3040 testCases = append(testCases, testCase{
3041 testType: serverTest,
3042 name: "Null-Client-CA-List",
3043 config: Config{
3044 MaxVersion: VersionTLS12,
3045 Certificates: []Certificate{rsaCertificate},
3046 },
3047 flags: []string{
3048 "-require-any-client-certificate",
3049 "-use-null-client-ca-list",
3050 },
3051 })
David Benjamin636293b2014-07-08 17:59:18 -04003052}
3053
Adam Langley75712922014-10-10 16:23:43 -07003054func addExtendedMasterSecretTests() {
3055 const expectEMSFlag = "-expect-extended-master-secret"
3056
3057 for _, with := range []bool{false, true} {
3058 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003059 if with {
3060 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003061 }
3062
3063 for _, isClient := range []bool{false, true} {
3064 suffix := "-Server"
3065 testType := serverTest
3066 if isClient {
3067 suffix = "-Client"
3068 testType = clientTest
3069 }
3070
3071 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003072 // In TLS 1.3, the extension is irrelevant and
3073 // always reports as enabled.
3074 var flags []string
3075 if with || ver.version >= VersionTLS13 {
3076 flags = []string{expectEMSFlag}
3077 }
3078
Adam Langley75712922014-10-10 16:23:43 -07003079 test := testCase{
3080 testType: testType,
3081 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3082 config: Config{
3083 MinVersion: ver.version,
3084 MaxVersion: ver.version,
3085 Bugs: ProtocolBugs{
3086 NoExtendedMasterSecret: !with,
3087 RequireExtendedMasterSecret: with,
3088 },
3089 },
David Benjamin48cae082014-10-27 01:06:24 -04003090 flags: flags,
3091 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003092 }
3093 if test.shouldFail {
3094 test.expectedLocalError = "extended master secret required but not supported by peer"
3095 }
3096 testCases = append(testCases, test)
3097 }
3098 }
3099 }
3100
Adam Langleyba5934b2015-06-02 10:50:35 -07003101 for _, isClient := range []bool{false, true} {
3102 for _, supportedInFirstConnection := range []bool{false, true} {
3103 for _, supportedInResumeConnection := range []bool{false, true} {
3104 boolToWord := func(b bool) string {
3105 if b {
3106 return "Yes"
3107 }
3108 return "No"
3109 }
3110 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3111 if isClient {
3112 suffix += "Client"
3113 } else {
3114 suffix += "Server"
3115 }
3116
3117 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003118 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003119 Bugs: ProtocolBugs{
3120 RequireExtendedMasterSecret: true,
3121 },
3122 }
3123
3124 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003125 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003126 Bugs: ProtocolBugs{
3127 NoExtendedMasterSecret: true,
3128 },
3129 }
3130
3131 test := testCase{
3132 name: "ExtendedMasterSecret-" + suffix,
3133 resumeSession: true,
3134 }
3135
3136 if !isClient {
3137 test.testType = serverTest
3138 }
3139
3140 if supportedInFirstConnection {
3141 test.config = supportedConfig
3142 } else {
3143 test.config = noSupportConfig
3144 }
3145
3146 if supportedInResumeConnection {
3147 test.resumeConfig = &supportedConfig
3148 } else {
3149 test.resumeConfig = &noSupportConfig
3150 }
3151
3152 switch suffix {
3153 case "YesToYes-Client", "YesToYes-Server":
3154 // When a session is resumed, it should
3155 // still be aware that its master
3156 // secret was generated via EMS and
3157 // thus it's safe to use tls-unique.
3158 test.flags = []string{expectEMSFlag}
3159 case "NoToYes-Server":
3160 // If an original connection did not
3161 // contain EMS, but a resumption
3162 // handshake does, then a server should
3163 // not resume the session.
3164 test.expectResumeRejected = true
3165 case "YesToNo-Server":
3166 // Resuming an EMS session without the
3167 // EMS extension should cause the
3168 // server to abort the connection.
3169 test.shouldFail = true
3170 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3171 case "NoToYes-Client":
3172 // A client should abort a connection
3173 // where the server resumed a non-EMS
3174 // session but echoed the EMS
3175 // extension.
3176 test.shouldFail = true
3177 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3178 case "YesToNo-Client":
3179 // A client should abort a connection
3180 // where the server didn't echo EMS
3181 // when the session used it.
3182 test.shouldFail = true
3183 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3184 }
3185
3186 testCases = append(testCases, test)
3187 }
3188 }
3189 }
David Benjamin163c9562016-08-29 23:14:17 -04003190
3191 // Switching EMS on renegotiation is forbidden.
3192 testCases = append(testCases, testCase{
3193 name: "ExtendedMasterSecret-Renego-NoEMS",
3194 config: Config{
3195 MaxVersion: VersionTLS12,
3196 Bugs: ProtocolBugs{
3197 NoExtendedMasterSecret: true,
3198 NoExtendedMasterSecretOnRenegotiation: true,
3199 },
3200 },
3201 renegotiate: 1,
3202 flags: []string{
3203 "-renegotiate-freely",
3204 "-expect-total-renegotiations", "1",
3205 },
3206 })
3207
3208 testCases = append(testCases, testCase{
3209 name: "ExtendedMasterSecret-Renego-Upgrade",
3210 config: Config{
3211 MaxVersion: VersionTLS12,
3212 Bugs: ProtocolBugs{
3213 NoExtendedMasterSecret: true,
3214 },
3215 },
3216 renegotiate: 1,
3217 flags: []string{
3218 "-renegotiate-freely",
3219 "-expect-total-renegotiations", "1",
3220 },
3221 shouldFail: true,
3222 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3223 })
3224
3225 testCases = append(testCases, testCase{
3226 name: "ExtendedMasterSecret-Renego-Downgrade",
3227 config: Config{
3228 MaxVersion: VersionTLS12,
3229 Bugs: ProtocolBugs{
3230 NoExtendedMasterSecretOnRenegotiation: true,
3231 },
3232 },
3233 renegotiate: 1,
3234 flags: []string{
3235 "-renegotiate-freely",
3236 "-expect-total-renegotiations", "1",
3237 },
3238 shouldFail: true,
3239 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3240 })
Adam Langley75712922014-10-10 16:23:43 -07003241}
3242
David Benjamin582ba042016-07-07 12:33:25 -07003243type stateMachineTestConfig struct {
3244 protocol protocol
3245 async bool
3246 splitHandshake, packHandshakeFlight bool
3247}
3248
David Benjamin43ec06f2014-08-05 02:28:57 -04003249// Adds tests that try to cover the range of the handshake state machine, under
3250// various conditions. Some of these are redundant with other tests, but they
3251// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003252func addAllStateMachineCoverageTests() {
3253 for _, async := range []bool{false, true} {
3254 for _, protocol := range []protocol{tls, dtls} {
3255 addStateMachineCoverageTests(stateMachineTestConfig{
3256 protocol: protocol,
3257 async: async,
3258 })
3259 addStateMachineCoverageTests(stateMachineTestConfig{
3260 protocol: protocol,
3261 async: async,
3262 splitHandshake: true,
3263 })
3264 if protocol == tls {
3265 addStateMachineCoverageTests(stateMachineTestConfig{
3266 protocol: protocol,
3267 async: async,
3268 packHandshakeFlight: true,
3269 })
3270 }
3271 }
3272 }
3273}
3274
3275func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003276 var tests []testCase
3277
3278 // Basic handshake, with resumption. Client and server,
3279 // session ID and session ticket.
3280 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003281 name: "Basic-Client",
3282 config: Config{
3283 MaxVersion: VersionTLS12,
3284 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003285 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003286 // Ensure session tickets are used, not session IDs.
3287 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003288 })
3289 tests = append(tests, testCase{
3290 name: "Basic-Client-RenewTicket",
3291 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003292 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003293 Bugs: ProtocolBugs{
3294 RenewTicketOnResume: true,
3295 },
3296 },
David Benjamin46662482016-08-17 00:51:00 -04003297 flags: []string{"-expect-ticket-renewal"},
3298 resumeSession: true,
3299 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003300 })
3301 tests = append(tests, testCase{
3302 name: "Basic-Client-NoTicket",
3303 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003304 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003305 SessionTicketsDisabled: true,
3306 },
3307 resumeSession: true,
3308 })
3309 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003310 name: "Basic-Client-Implicit",
3311 config: Config{
3312 MaxVersion: VersionTLS12,
3313 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003314 flags: []string{"-implicit-handshake"},
3315 resumeSession: true,
3316 })
3317 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003318 testType: serverTest,
3319 name: "Basic-Server",
3320 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003321 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003322 Bugs: ProtocolBugs{
3323 RequireSessionTickets: true,
3324 },
3325 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003326 resumeSession: true,
3327 })
3328 tests = append(tests, testCase{
3329 testType: serverTest,
3330 name: "Basic-Server-NoTickets",
3331 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003332 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003333 SessionTicketsDisabled: true,
3334 },
3335 resumeSession: true,
3336 })
3337 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003338 testType: serverTest,
3339 name: "Basic-Server-Implicit",
3340 config: Config{
3341 MaxVersion: VersionTLS12,
3342 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003343 flags: []string{"-implicit-handshake"},
3344 resumeSession: true,
3345 })
3346 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003347 testType: serverTest,
3348 name: "Basic-Server-EarlyCallback",
3349 config: Config{
3350 MaxVersion: VersionTLS12,
3351 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003352 flags: []string{"-use-early-callback"},
3353 resumeSession: true,
3354 })
3355
Steven Valdez143e8b32016-07-11 13:19:03 -04003356 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003357 if config.protocol == tls {
3358 tests = append(tests, testCase{
3359 name: "TLS13-1RTT-Client",
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 testType: serverTest,
3370 name: "TLS13-1RTT-Server",
3371 config: Config{
3372 MaxVersion: VersionTLS13,
3373 MinVersion: VersionTLS13,
3374 },
David Benjamin46662482016-08-17 00:51:00 -04003375 resumeSession: true,
3376 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003377 })
3378
3379 tests = append(tests, testCase{
3380 name: "TLS13-HelloRetryRequest-Client",
3381 config: Config{
3382 MaxVersion: VersionTLS13,
3383 MinVersion: VersionTLS13,
3384 // P-384 requires a HelloRetryRequest against
3385 // BoringSSL's default configuration. Assert
3386 // that we do indeed test this with
3387 // ExpectMissingKeyShare.
3388 CurvePreferences: []CurveID{CurveP384},
3389 Bugs: ProtocolBugs{
3390 ExpectMissingKeyShare: true,
3391 },
3392 },
3393 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3394 resumeSession: true,
3395 })
3396
3397 tests = append(tests, testCase{
3398 testType: serverTest,
3399 name: "TLS13-HelloRetryRequest-Server",
3400 config: Config{
3401 MaxVersion: VersionTLS13,
3402 MinVersion: VersionTLS13,
3403 // Require a HelloRetryRequest for every curve.
3404 DefaultCurves: []CurveID{},
3405 },
3406 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3407 resumeSession: true,
3408 })
3409 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003410
David Benjamin760b1dd2015-05-15 23:33:48 -04003411 // TLS client auth.
3412 tests = append(tests, testCase{
3413 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003414 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003415 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003416 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003417 ClientAuth: RequestClientCert,
3418 },
3419 })
3420 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003421 testType: serverTest,
3422 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003423 config: Config{
3424 MaxVersion: VersionTLS12,
3425 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003426 // Setting SSL_VERIFY_PEER allows anonymous clients.
3427 flags: []string{"-verify-peer"},
3428 })
David Benjamin582ba042016-07-07 12:33:25 -07003429 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003430 tests = append(tests, testCase{
3431 testType: clientTest,
3432 name: "ClientAuth-NoCertificate-Client-SSL3",
3433 config: Config{
3434 MaxVersion: VersionSSL30,
3435 ClientAuth: RequestClientCert,
3436 },
3437 })
3438 tests = append(tests, testCase{
3439 testType: serverTest,
3440 name: "ClientAuth-NoCertificate-Server-SSL3",
3441 config: Config{
3442 MaxVersion: VersionSSL30,
3443 },
3444 // Setting SSL_VERIFY_PEER allows anonymous clients.
3445 flags: []string{"-verify-peer"},
3446 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003447 tests = append(tests, testCase{
3448 testType: clientTest,
3449 name: "ClientAuth-NoCertificate-Client-TLS13",
3450 config: Config{
3451 MaxVersion: VersionTLS13,
3452 ClientAuth: RequestClientCert,
3453 },
3454 })
3455 tests = append(tests, testCase{
3456 testType: serverTest,
3457 name: "ClientAuth-NoCertificate-Server-TLS13",
3458 config: Config{
3459 MaxVersion: VersionTLS13,
3460 },
3461 // Setting SSL_VERIFY_PEER allows anonymous clients.
3462 flags: []string{"-verify-peer"},
3463 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003464 }
3465 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003466 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003467 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003468 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003469 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003470 ClientAuth: RequireAnyClientCert,
3471 },
3472 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003473 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3474 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003475 },
3476 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003477 tests = append(tests, testCase{
3478 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003479 name: "ClientAuth-RSA-Client-TLS13",
3480 config: Config{
3481 MaxVersion: VersionTLS13,
3482 ClientAuth: RequireAnyClientCert,
3483 },
3484 flags: []string{
3485 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3486 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3487 },
3488 })
3489 tests = append(tests, testCase{
3490 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003491 name: "ClientAuth-ECDSA-Client",
3492 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003493 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003494 ClientAuth: RequireAnyClientCert,
3495 },
3496 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003497 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3498 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003499 },
3500 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003501 tests = append(tests, testCase{
3502 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003503 name: "ClientAuth-ECDSA-Client-TLS13",
3504 config: Config{
3505 MaxVersion: VersionTLS13,
3506 ClientAuth: RequireAnyClientCert,
3507 },
3508 flags: []string{
3509 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3510 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3511 },
3512 })
3513 tests = append(tests, testCase{
3514 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003515 name: "ClientAuth-NoCertificate-OldCallback",
3516 config: Config{
3517 MaxVersion: VersionTLS12,
3518 ClientAuth: RequestClientCert,
3519 },
3520 flags: []string{"-use-old-client-cert-callback"},
3521 })
3522 tests = append(tests, testCase{
3523 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003524 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3525 config: Config{
3526 MaxVersion: VersionTLS13,
3527 ClientAuth: RequestClientCert,
3528 },
3529 flags: []string{"-use-old-client-cert-callback"},
3530 })
3531 tests = append(tests, testCase{
3532 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003533 name: "ClientAuth-OldCallback",
3534 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003535 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003536 ClientAuth: RequireAnyClientCert,
3537 },
3538 flags: []string{
3539 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3540 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3541 "-use-old-client-cert-callback",
3542 },
3543 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003544 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003545 testType: clientTest,
3546 name: "ClientAuth-OldCallback-TLS13",
3547 config: Config{
3548 MaxVersion: VersionTLS13,
3549 ClientAuth: RequireAnyClientCert,
3550 },
3551 flags: []string{
3552 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3553 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3554 "-use-old-client-cert-callback",
3555 },
3556 })
3557 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003558 testType: serverTest,
3559 name: "ClientAuth-Server",
3560 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003561 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003562 Certificates: []Certificate{rsaCertificate},
3563 },
3564 flags: []string{"-require-any-client-certificate"},
3565 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003566 tests = append(tests, testCase{
3567 testType: serverTest,
3568 name: "ClientAuth-Server-TLS13",
3569 config: Config{
3570 MaxVersion: VersionTLS13,
3571 Certificates: []Certificate{rsaCertificate},
3572 },
3573 flags: []string{"-require-any-client-certificate"},
3574 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003575
David Benjamin4c3ddf72016-06-29 18:13:53 -04003576 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003577 tests = append(tests, testCase{
3578 testType: serverTest,
3579 name: "Basic-Server-RSA",
3580 config: Config{
3581 MaxVersion: VersionTLS12,
3582 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3583 },
3584 flags: []string{
3585 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3586 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3587 },
3588 })
3589 tests = append(tests, testCase{
3590 testType: serverTest,
3591 name: "Basic-Server-ECDHE-RSA",
3592 config: Config{
3593 MaxVersion: VersionTLS12,
3594 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3595 },
3596 flags: []string{
3597 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3598 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3599 },
3600 })
3601 tests = append(tests, testCase{
3602 testType: serverTest,
3603 name: "Basic-Server-ECDHE-ECDSA",
3604 config: Config{
3605 MaxVersion: VersionTLS12,
3606 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3607 },
3608 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003609 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3610 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003611 },
3612 })
3613
David Benjamin760b1dd2015-05-15 23:33:48 -04003614 // No session ticket support; server doesn't send NewSessionTicket.
3615 tests = append(tests, testCase{
3616 name: "SessionTicketsDisabled-Client",
3617 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003618 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003619 SessionTicketsDisabled: true,
3620 },
3621 })
3622 tests = append(tests, testCase{
3623 testType: serverTest,
3624 name: "SessionTicketsDisabled-Server",
3625 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003626 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003627 SessionTicketsDisabled: true,
3628 },
3629 })
3630
3631 // Skip ServerKeyExchange in PSK key exchange if there's no
3632 // identity hint.
3633 tests = append(tests, testCase{
3634 name: "EmptyPSKHint-Client",
3635 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003636 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003637 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3638 PreSharedKey: []byte("secret"),
3639 },
3640 flags: []string{"-psk", "secret"},
3641 })
3642 tests = append(tests, testCase{
3643 testType: serverTest,
3644 name: "EmptyPSKHint-Server",
3645 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003646 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003647 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3648 PreSharedKey: []byte("secret"),
3649 },
3650 flags: []string{"-psk", "secret"},
3651 })
3652
David Benjamin4c3ddf72016-06-29 18:13:53 -04003653 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003654 tests = append(tests, testCase{
3655 testType: clientTest,
3656 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003657 config: Config{
3658 MaxVersion: VersionTLS12,
3659 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003660 flags: []string{
3661 "-enable-ocsp-stapling",
3662 "-expect-ocsp-response",
3663 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003664 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003665 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003666 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003667 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003668 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003669 testType: serverTest,
3670 name: "OCSPStapling-Server",
3671 config: Config{
3672 MaxVersion: VersionTLS12,
3673 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003674 expectedOCSPResponse: testOCSPResponse,
3675 flags: []string{
3676 "-ocsp-response",
3677 base64.StdEncoding.EncodeToString(testOCSPResponse),
3678 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003679 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003680 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003681 tests = append(tests, testCase{
3682 testType: clientTest,
3683 name: "OCSPStapling-Client-TLS13",
3684 config: Config{
3685 MaxVersion: VersionTLS13,
3686 },
3687 flags: []string{
3688 "-enable-ocsp-stapling",
3689 "-expect-ocsp-response",
3690 base64.StdEncoding.EncodeToString(testOCSPResponse),
3691 "-verify-peer",
3692 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003693 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003694 })
3695 tests = append(tests, testCase{
3696 testType: serverTest,
3697 name: "OCSPStapling-Server-TLS13",
3698 config: Config{
3699 MaxVersion: VersionTLS13,
3700 },
3701 expectedOCSPResponse: testOCSPResponse,
3702 flags: []string{
3703 "-ocsp-response",
3704 base64.StdEncoding.EncodeToString(testOCSPResponse),
3705 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003706 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003707 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003708
David Benjamin4c3ddf72016-06-29 18:13:53 -04003709 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003710 for _, vers := range tlsVersions {
3711 if config.protocol == dtls && !vers.hasDTLS {
3712 continue
3713 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003714 for _, testType := range []testType{clientTest, serverTest} {
3715 suffix := "-Client"
3716 if testType == serverTest {
3717 suffix = "-Server"
3718 }
3719 suffix += "-" + vers.name
3720
3721 flag := "-verify-peer"
3722 if testType == serverTest {
3723 flag = "-require-any-client-certificate"
3724 }
3725
3726 tests = append(tests, testCase{
3727 testType: testType,
3728 name: "CertificateVerificationSucceed" + suffix,
3729 config: Config{
3730 MaxVersion: vers.version,
3731 Certificates: []Certificate{rsaCertificate},
3732 },
3733 flags: []string{
3734 flag,
3735 "-expect-verify-result",
3736 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003737 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003738 })
3739 tests = append(tests, testCase{
3740 testType: testType,
3741 name: "CertificateVerificationFail" + suffix,
3742 config: Config{
3743 MaxVersion: vers.version,
3744 Certificates: []Certificate{rsaCertificate},
3745 },
3746 flags: []string{
3747 flag,
3748 "-verify-fail",
3749 },
3750 shouldFail: true,
3751 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3752 })
3753 }
3754
3755 // By default, the client is in a soft fail mode where the peer
3756 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003757 tests = append(tests, testCase{
3758 testType: clientTest,
3759 name: "CertificateVerificationSoftFail-" + vers.name,
3760 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003761 MaxVersion: vers.version,
3762 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003763 },
3764 flags: []string{
3765 "-verify-fail",
3766 "-expect-verify-result",
3767 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003768 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003769 })
3770 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003771
David Benjamin1d4f4c02016-07-26 18:03:08 -04003772 tests = append(tests, testCase{
3773 name: "ShimSendAlert",
3774 flags: []string{"-send-alert"},
3775 shimWritesFirst: true,
3776 shouldFail: true,
3777 expectedLocalError: "remote error: decompression failure",
3778 })
3779
David Benjamin582ba042016-07-07 12:33:25 -07003780 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003781 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003782 name: "Renegotiate-Client",
3783 config: Config{
3784 MaxVersion: VersionTLS12,
3785 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003786 renegotiate: 1,
3787 flags: []string{
3788 "-renegotiate-freely",
3789 "-expect-total-renegotiations", "1",
3790 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003791 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003792
David Benjamin47921102016-07-28 11:29:18 -04003793 tests = append(tests, testCase{
3794 name: "SendHalfHelloRequest",
3795 config: Config{
3796 MaxVersion: VersionTLS12,
3797 Bugs: ProtocolBugs{
3798 PackHelloRequestWithFinished: config.packHandshakeFlight,
3799 },
3800 },
3801 sendHalfHelloRequest: true,
3802 flags: []string{"-renegotiate-ignore"},
3803 shouldFail: true,
3804 expectedError: ":UNEXPECTED_RECORD:",
3805 })
3806
David Benjamin760b1dd2015-05-15 23:33:48 -04003807 // NPN on client and server; results in post-handshake message.
3808 tests = append(tests, testCase{
3809 name: "NPN-Client",
3810 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003811 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003812 NextProtos: []string{"foo"},
3813 },
3814 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003815 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003816 expectedNextProto: "foo",
3817 expectedNextProtoType: npn,
3818 })
3819 tests = append(tests, testCase{
3820 testType: serverTest,
3821 name: "NPN-Server",
3822 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003823 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003824 NextProtos: []string{"bar"},
3825 },
3826 flags: []string{
3827 "-advertise-npn", "\x03foo\x03bar\x03baz",
3828 "-expect-next-proto", "bar",
3829 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003830 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003831 expectedNextProto: "bar",
3832 expectedNextProtoType: npn,
3833 })
3834
3835 // TODO(davidben): Add tests for when False Start doesn't trigger.
3836
3837 // Client does False Start and negotiates NPN.
3838 tests = append(tests, testCase{
3839 name: "FalseStart",
3840 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003841 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003842 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3843 NextProtos: []string{"foo"},
3844 Bugs: ProtocolBugs{
3845 ExpectFalseStart: true,
3846 },
3847 },
3848 flags: []string{
3849 "-false-start",
3850 "-select-next-proto", "foo",
3851 },
3852 shimWritesFirst: true,
3853 resumeSession: true,
3854 })
3855
3856 // Client does False Start and negotiates ALPN.
3857 tests = append(tests, testCase{
3858 name: "FalseStart-ALPN",
3859 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003860 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003861 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3862 NextProtos: []string{"foo"},
3863 Bugs: ProtocolBugs{
3864 ExpectFalseStart: true,
3865 },
3866 },
3867 flags: []string{
3868 "-false-start",
3869 "-advertise-alpn", "\x03foo",
3870 },
3871 shimWritesFirst: true,
3872 resumeSession: true,
3873 })
3874
3875 // Client does False Start but doesn't explicitly call
3876 // SSL_connect.
3877 tests = append(tests, testCase{
3878 name: "FalseStart-Implicit",
3879 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003880 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003881 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3882 NextProtos: []string{"foo"},
3883 },
3884 flags: []string{
3885 "-implicit-handshake",
3886 "-false-start",
3887 "-advertise-alpn", "\x03foo",
3888 },
3889 })
3890
3891 // False Start without session tickets.
3892 tests = append(tests, testCase{
3893 name: "FalseStart-SessionTicketsDisabled",
3894 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003895 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003896 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3897 NextProtos: []string{"foo"},
3898 SessionTicketsDisabled: true,
3899 Bugs: ProtocolBugs{
3900 ExpectFalseStart: true,
3901 },
3902 },
3903 flags: []string{
3904 "-false-start",
3905 "-select-next-proto", "foo",
3906 },
3907 shimWritesFirst: true,
3908 })
3909
Adam Langleydf759b52016-07-11 15:24:37 -07003910 tests = append(tests, testCase{
3911 name: "FalseStart-CECPQ1",
3912 config: Config{
3913 MaxVersion: VersionTLS12,
3914 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3915 NextProtos: []string{"foo"},
3916 Bugs: ProtocolBugs{
3917 ExpectFalseStart: true,
3918 },
3919 },
3920 flags: []string{
3921 "-false-start",
3922 "-cipher", "DEFAULT:kCECPQ1",
3923 "-select-next-proto", "foo",
3924 },
3925 shimWritesFirst: true,
3926 resumeSession: true,
3927 })
3928
David Benjamin760b1dd2015-05-15 23:33:48 -04003929 // Server parses a V2ClientHello.
3930 tests = append(tests, testCase{
3931 testType: serverTest,
3932 name: "SendV2ClientHello",
3933 config: Config{
3934 // Choose a cipher suite that does not involve
3935 // elliptic curves, so no extensions are
3936 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003937 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003938 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003939 Bugs: ProtocolBugs{
3940 SendV2ClientHello: true,
3941 },
3942 },
3943 })
3944
3945 // Client sends a Channel ID.
3946 tests = append(tests, testCase{
3947 name: "ChannelID-Client",
3948 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003949 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003950 RequestChannelID: true,
3951 },
Adam Langley7c803a62015-06-15 15:35:05 -07003952 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003953 resumeSession: true,
3954 expectChannelID: true,
3955 })
3956
3957 // Server accepts a Channel ID.
3958 tests = append(tests, testCase{
3959 testType: serverTest,
3960 name: "ChannelID-Server",
3961 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003962 MaxVersion: VersionTLS12,
3963 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003964 },
3965 flags: []string{
3966 "-expect-channel-id",
3967 base64.StdEncoding.EncodeToString(channelIDBytes),
3968 },
3969 resumeSession: true,
3970 expectChannelID: true,
3971 })
David Benjamin30789da2015-08-29 22:56:45 -04003972
David Benjaminf8fcdf32016-06-08 15:56:13 -04003973 // Channel ID and NPN at the same time, to ensure their relative
3974 // ordering is correct.
3975 tests = append(tests, testCase{
3976 name: "ChannelID-NPN-Client",
3977 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003978 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003979 RequestChannelID: true,
3980 NextProtos: []string{"foo"},
3981 },
3982 flags: []string{
3983 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3984 "-select-next-proto", "foo",
3985 },
3986 resumeSession: true,
3987 expectChannelID: true,
3988 expectedNextProto: "foo",
3989 expectedNextProtoType: npn,
3990 })
3991 tests = append(tests, testCase{
3992 testType: serverTest,
3993 name: "ChannelID-NPN-Server",
3994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003995 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003996 ChannelID: channelIDKey,
3997 NextProtos: []string{"bar"},
3998 },
3999 flags: []string{
4000 "-expect-channel-id",
4001 base64.StdEncoding.EncodeToString(channelIDBytes),
4002 "-advertise-npn", "\x03foo\x03bar\x03baz",
4003 "-expect-next-proto", "bar",
4004 },
4005 resumeSession: true,
4006 expectChannelID: true,
4007 expectedNextProto: "bar",
4008 expectedNextProtoType: npn,
4009 })
4010
David Benjamin30789da2015-08-29 22:56:45 -04004011 // Bidirectional shutdown with the runner initiating.
4012 tests = append(tests, testCase{
4013 name: "Shutdown-Runner",
4014 config: Config{
4015 Bugs: ProtocolBugs{
4016 ExpectCloseNotify: true,
4017 },
4018 },
4019 flags: []string{"-check-close-notify"},
4020 })
4021
4022 // Bidirectional shutdown with the shim initiating. The runner,
4023 // in the meantime, sends garbage before the close_notify which
4024 // the shim must ignore.
4025 tests = append(tests, testCase{
4026 name: "Shutdown-Shim",
4027 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004028 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004029 Bugs: ProtocolBugs{
4030 ExpectCloseNotify: true,
4031 },
4032 },
4033 shimShutsDown: true,
4034 sendEmptyRecords: 1,
4035 sendWarningAlerts: 1,
4036 flags: []string{"-check-close-notify"},
4037 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004038 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004039 // TODO(davidben): DTLS 1.3 will want a similar thing for
4040 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004041 tests = append(tests, testCase{
4042 name: "SkipHelloVerifyRequest",
4043 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004044 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004045 Bugs: ProtocolBugs{
4046 SkipHelloVerifyRequest: true,
4047 },
4048 },
4049 })
4050 }
4051
David Benjamin760b1dd2015-05-15 23:33:48 -04004052 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004053 test.protocol = config.protocol
4054 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004055 test.name += "-DTLS"
4056 }
David Benjamin582ba042016-07-07 12:33:25 -07004057 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004058 test.name += "-Async"
4059 test.flags = append(test.flags, "-async")
4060 } else {
4061 test.name += "-Sync"
4062 }
David Benjamin582ba042016-07-07 12:33:25 -07004063 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004064 test.name += "-SplitHandshakeRecords"
4065 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004066 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004067 test.config.Bugs.MaxPacketLength = 256
4068 test.flags = append(test.flags, "-mtu", "256")
4069 }
4070 }
David Benjamin582ba042016-07-07 12:33:25 -07004071 if config.packHandshakeFlight {
4072 test.name += "-PackHandshakeFlight"
4073 test.config.Bugs.PackHandshakeFlight = true
4074 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004075 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004076 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004077}
4078
Adam Langley524e7172015-02-20 16:04:00 -08004079func addDDoSCallbackTests() {
4080 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004081 for _, resume := range []bool{false, true} {
4082 suffix := "Resume"
4083 if resume {
4084 suffix = "No" + suffix
4085 }
4086
4087 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004088 testType: serverTest,
4089 name: "Server-DDoS-OK-" + suffix,
4090 config: Config{
4091 MaxVersion: VersionTLS12,
4092 },
Adam Langley524e7172015-02-20 16:04:00 -08004093 flags: []string{"-install-ddos-callback"},
4094 resumeSession: resume,
4095 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004096 testCases = append(testCases, testCase{
4097 testType: serverTest,
4098 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4099 config: Config{
4100 MaxVersion: VersionTLS13,
4101 },
4102 flags: []string{"-install-ddos-callback"},
4103 resumeSession: resume,
4104 })
Adam Langley524e7172015-02-20 16:04:00 -08004105
4106 failFlag := "-fail-ddos-callback"
4107 if resume {
4108 failFlag = "-fail-second-ddos-callback"
4109 }
4110 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004111 testType: serverTest,
4112 name: "Server-DDoS-Reject-" + suffix,
4113 config: Config{
4114 MaxVersion: VersionTLS12,
4115 },
David Benjamin2c66e072016-09-16 15:58:00 -04004116 flags: []string{"-install-ddos-callback", failFlag},
4117 resumeSession: resume,
4118 shouldFail: true,
4119 expectedError: ":CONNECTION_REJECTED:",
4120 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004121 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004122 testCases = append(testCases, testCase{
4123 testType: serverTest,
4124 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4125 config: Config{
4126 MaxVersion: VersionTLS13,
4127 },
David Benjamin2c66e072016-09-16 15:58:00 -04004128 flags: []string{"-install-ddos-callback", failFlag},
4129 resumeSession: resume,
4130 shouldFail: true,
4131 expectedError: ":CONNECTION_REJECTED:",
4132 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004133 })
Adam Langley524e7172015-02-20 16:04:00 -08004134 }
4135}
4136
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004137func addVersionNegotiationTests() {
4138 for i, shimVers := range tlsVersions {
4139 // Assemble flags to disable all newer versions on the shim.
4140 var flags []string
4141 for _, vers := range tlsVersions[i+1:] {
4142 flags = append(flags, vers.flag)
4143 }
4144
Steven Valdezfdd10992016-09-15 16:27:05 -04004145 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004146 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004147 protocols := []protocol{tls}
4148 if runnerVers.hasDTLS && shimVers.hasDTLS {
4149 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004150 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004151 for _, protocol := range protocols {
4152 expectedVersion := shimVers.version
4153 if runnerVers.version < shimVers.version {
4154 expectedVersion = runnerVers.version
4155 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004156
David Benjamin8b8c0062014-11-23 02:47:52 -05004157 suffix := shimVers.name + "-" + runnerVers.name
4158 if protocol == dtls {
4159 suffix += "-DTLS"
4160 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004161
David Benjamin1eb367c2014-12-12 18:17:51 -05004162 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4163
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004164 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004165 clientVers := shimVers.version
4166 if clientVers > VersionTLS10 {
4167 clientVers = VersionTLS10
4168 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004169 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004170 serverVers := expectedVersion
4171 if expectedVersion >= VersionTLS13 {
4172 serverVers = VersionTLS10
4173 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004174 serverVers = versionToWire(serverVers, protocol == dtls)
4175
David Benjamin8b8c0062014-11-23 02:47:52 -05004176 testCases = append(testCases, testCase{
4177 protocol: protocol,
4178 testType: clientTest,
4179 name: "VersionNegotiation-Client-" + suffix,
4180 config: Config{
4181 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004182 Bugs: ProtocolBugs{
4183 ExpectInitialRecordVersion: clientVers,
4184 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004185 },
4186 flags: flags,
4187 expectedVersion: expectedVersion,
4188 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004189 testCases = append(testCases, testCase{
4190 protocol: protocol,
4191 testType: clientTest,
4192 name: "VersionNegotiation-Client2-" + suffix,
4193 config: Config{
4194 MaxVersion: runnerVers.version,
4195 Bugs: ProtocolBugs{
4196 ExpectInitialRecordVersion: clientVers,
4197 },
4198 },
4199 flags: []string{"-max-version", shimVersFlag},
4200 expectedVersion: expectedVersion,
4201 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004202
4203 testCases = append(testCases, testCase{
4204 protocol: protocol,
4205 testType: serverTest,
4206 name: "VersionNegotiation-Server-" + suffix,
4207 config: Config{
4208 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004209 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004210 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004211 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004212 },
4213 flags: flags,
4214 expectedVersion: expectedVersion,
4215 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004216 testCases = append(testCases, testCase{
4217 protocol: protocol,
4218 testType: serverTest,
4219 name: "VersionNegotiation-Server2-" + suffix,
4220 config: Config{
4221 MaxVersion: runnerVers.version,
4222 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004223 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004224 },
4225 },
4226 flags: []string{"-max-version", shimVersFlag},
4227 expectedVersion: expectedVersion,
4228 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004229 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004230 }
4231 }
David Benjamin95c69562016-06-29 18:15:03 -04004232
Steven Valdezfdd10992016-09-15 16:27:05 -04004233 // Test the version extension at all versions.
4234 for _, vers := range tlsVersions {
4235 protocols := []protocol{tls}
4236 if vers.hasDTLS {
4237 protocols = append(protocols, dtls)
4238 }
4239 for _, protocol := range protocols {
4240 suffix := vers.name
4241 if protocol == dtls {
4242 suffix += "-DTLS"
4243 }
4244
4245 wireVersion := versionToWire(vers.version, protocol == dtls)
4246 testCases = append(testCases, testCase{
4247 protocol: protocol,
4248 testType: serverTest,
4249 name: "VersionNegotiationExtension-" + suffix,
4250 config: Config{
4251 Bugs: ProtocolBugs{
4252 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4253 },
4254 },
4255 expectedVersion: vers.version,
4256 })
4257 }
4258
4259 }
4260
4261 // If all versions are unknown, negotiation fails.
4262 testCases = append(testCases, testCase{
4263 testType: serverTest,
4264 name: "NoSupportedVersions",
4265 config: Config{
4266 Bugs: ProtocolBugs{
4267 SendSupportedVersions: []uint16{0x1111},
4268 },
4269 },
4270 shouldFail: true,
4271 expectedError: ":UNSUPPORTED_PROTOCOL:",
4272 })
4273 testCases = append(testCases, testCase{
4274 protocol: dtls,
4275 testType: serverTest,
4276 name: "NoSupportedVersions-DTLS",
4277 config: Config{
4278 Bugs: ProtocolBugs{
4279 SendSupportedVersions: []uint16{0x1111},
4280 },
4281 },
4282 shouldFail: true,
4283 expectedError: ":UNSUPPORTED_PROTOCOL:",
4284 })
4285
4286 testCases = append(testCases, testCase{
4287 testType: serverTest,
4288 name: "ClientHelloVersionTooHigh",
4289 config: Config{
4290 MaxVersion: VersionTLS13,
4291 Bugs: ProtocolBugs{
4292 SendClientVersion: 0x0304,
4293 OmitSupportedVersions: true,
4294 },
4295 },
4296 expectedVersion: VersionTLS12,
4297 })
4298
4299 testCases = append(testCases, testCase{
4300 testType: serverTest,
4301 name: "ConflictingVersionNegotiation",
4302 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004303 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004304 SendClientVersion: VersionTLS12,
4305 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004306 },
4307 },
David Benjaminad75a662016-09-30 15:42:59 -04004308 // The extension takes precedence over the ClientHello version.
4309 expectedVersion: VersionTLS11,
4310 })
4311
4312 testCases = append(testCases, testCase{
4313 testType: serverTest,
4314 name: "ConflictingVersionNegotiation-2",
4315 config: Config{
4316 Bugs: ProtocolBugs{
4317 SendClientVersion: VersionTLS11,
4318 SendSupportedVersions: []uint16{VersionTLS12},
4319 },
4320 },
4321 // The extension takes precedence over the ClientHello version.
4322 expectedVersion: VersionTLS12,
4323 })
4324
4325 testCases = append(testCases, testCase{
4326 testType: serverTest,
4327 name: "RejectFinalTLS13",
4328 config: Config{
4329 Bugs: ProtocolBugs{
4330 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4331 },
4332 },
4333 // We currently implement a draft TLS 1.3 version. Ensure that
4334 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004335 expectedVersion: VersionTLS12,
4336 })
4337
David Benjamin95c69562016-06-29 18:15:03 -04004338 // Test for version tolerance.
4339 testCases = append(testCases, testCase{
4340 testType: serverTest,
4341 name: "MinorVersionTolerance",
4342 config: Config{
4343 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004344 SendClientVersion: 0x03ff,
4345 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004346 },
4347 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004348 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004349 })
4350 testCases = append(testCases, testCase{
4351 testType: serverTest,
4352 name: "MajorVersionTolerance",
4353 config: Config{
4354 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004355 SendClientVersion: 0x0400,
4356 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004357 },
4358 },
David Benjaminad75a662016-09-30 15:42:59 -04004359 // TLS 1.3 must be negotiated with the supported_versions
4360 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004361 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004362 })
David Benjaminad75a662016-09-30 15:42:59 -04004363 testCases = append(testCases, testCase{
4364 testType: serverTest,
4365 name: "VersionTolerance-TLS13",
4366 config: Config{
4367 Bugs: ProtocolBugs{
4368 // Although TLS 1.3 does not use
4369 // ClientHello.version, it still tolerates high
4370 // values there.
4371 SendClientVersion: 0x0400,
4372 },
4373 },
4374 expectedVersion: VersionTLS13,
4375 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004376
David Benjamin95c69562016-06-29 18:15:03 -04004377 testCases = append(testCases, testCase{
4378 protocol: dtls,
4379 testType: serverTest,
4380 name: "MinorVersionTolerance-DTLS",
4381 config: Config{
4382 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004383 SendClientVersion: 0xfe00,
4384 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004385 },
4386 },
4387 expectedVersion: VersionTLS12,
4388 })
4389 testCases = append(testCases, testCase{
4390 protocol: dtls,
4391 testType: serverTest,
4392 name: "MajorVersionTolerance-DTLS",
4393 config: Config{
4394 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004395 SendClientVersion: 0xfdff,
4396 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004397 },
4398 },
4399 expectedVersion: VersionTLS12,
4400 })
4401
4402 // Test that versions below 3.0 are rejected.
4403 testCases = append(testCases, testCase{
4404 testType: serverTest,
4405 name: "VersionTooLow",
4406 config: Config{
4407 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004408 SendClientVersion: 0x0200,
4409 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004410 },
4411 },
4412 shouldFail: true,
4413 expectedError: ":UNSUPPORTED_PROTOCOL:",
4414 })
4415 testCases = append(testCases, testCase{
4416 protocol: dtls,
4417 testType: serverTest,
4418 name: "VersionTooLow-DTLS",
4419 config: Config{
4420 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004421 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004422 },
4423 },
4424 shouldFail: true,
4425 expectedError: ":UNSUPPORTED_PROTOCOL:",
4426 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004427
David Benjamin2dc02042016-09-19 19:57:37 -04004428 testCases = append(testCases, testCase{
4429 name: "ServerBogusVersion",
4430 config: Config{
4431 Bugs: ProtocolBugs{
4432 SendServerHelloVersion: 0x1234,
4433 },
4434 },
4435 shouldFail: true,
4436 expectedError: ":UNSUPPORTED_PROTOCOL:",
4437 })
4438
David Benjamin1f61f0d2016-07-10 12:20:35 -04004439 // Test TLS 1.3's downgrade signal.
4440 testCases = append(testCases, testCase{
4441 name: "Downgrade-TLS12-Client",
4442 config: Config{
4443 Bugs: ProtocolBugs{
4444 NegotiateVersion: VersionTLS12,
4445 },
4446 },
David Benjamin592b5322016-09-30 15:15:01 -04004447 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004448 // TODO(davidben): This test should fail once TLS 1.3 is final
4449 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004450 })
4451 testCases = append(testCases, testCase{
4452 testType: serverTest,
4453 name: "Downgrade-TLS12-Server",
4454 config: Config{
4455 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004456 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004457 },
4458 },
David Benjamin592b5322016-09-30 15:15:01 -04004459 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004460 // TODO(davidben): This test should fail once TLS 1.3 is final
4461 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004462 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004463}
4464
David Benjaminaccb4542014-12-12 23:44:33 -05004465func addMinimumVersionTests() {
4466 for i, shimVers := range tlsVersions {
4467 // Assemble flags to disable all older versions on the shim.
4468 var flags []string
4469 for _, vers := range tlsVersions[:i] {
4470 flags = append(flags, vers.flag)
4471 }
4472
4473 for _, runnerVers := range tlsVersions {
4474 protocols := []protocol{tls}
4475 if runnerVers.hasDTLS && shimVers.hasDTLS {
4476 protocols = append(protocols, dtls)
4477 }
4478 for _, protocol := range protocols {
4479 suffix := shimVers.name + "-" + runnerVers.name
4480 if protocol == dtls {
4481 suffix += "-DTLS"
4482 }
4483 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4484
David Benjaminaccb4542014-12-12 23:44:33 -05004485 var expectedVersion uint16
4486 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004487 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004488 if runnerVers.version >= shimVers.version {
4489 expectedVersion = runnerVers.version
4490 } else {
4491 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004492 expectedError = ":UNSUPPORTED_PROTOCOL:"
4493 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004494 }
4495
4496 testCases = append(testCases, testCase{
4497 protocol: protocol,
4498 testType: clientTest,
4499 name: "MinimumVersion-Client-" + suffix,
4500 config: Config{
4501 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004502 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004503 // Ensure the server does not decline to
4504 // select a version (versions extension) or
4505 // cipher (some ciphers depend on versions).
4506 NegotiateVersion: runnerVers.version,
4507 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004508 },
David Benjaminaccb4542014-12-12 23:44:33 -05004509 },
David Benjamin87909c02014-12-13 01:55:01 -05004510 flags: flags,
4511 expectedVersion: expectedVersion,
4512 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004513 expectedError: expectedError,
4514 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004515 })
4516 testCases = append(testCases, testCase{
4517 protocol: protocol,
4518 testType: clientTest,
4519 name: "MinimumVersion-Client2-" + suffix,
4520 config: Config{
4521 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004522 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004523 // Ensure the server does not decline to
4524 // select a version (versions extension) or
4525 // cipher (some ciphers depend on versions).
4526 NegotiateVersion: runnerVers.version,
4527 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004528 },
David Benjaminaccb4542014-12-12 23:44:33 -05004529 },
David Benjamin87909c02014-12-13 01:55:01 -05004530 flags: []string{"-min-version", shimVersFlag},
4531 expectedVersion: expectedVersion,
4532 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004533 expectedError: expectedError,
4534 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004535 })
4536
4537 testCases = append(testCases, testCase{
4538 protocol: protocol,
4539 testType: serverTest,
4540 name: "MinimumVersion-Server-" + suffix,
4541 config: Config{
4542 MaxVersion: runnerVers.version,
4543 },
David Benjamin87909c02014-12-13 01:55:01 -05004544 flags: flags,
4545 expectedVersion: expectedVersion,
4546 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004547 expectedError: expectedError,
4548 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004549 })
4550 testCases = append(testCases, testCase{
4551 protocol: protocol,
4552 testType: serverTest,
4553 name: "MinimumVersion-Server2-" + suffix,
4554 config: Config{
4555 MaxVersion: runnerVers.version,
4556 },
David Benjamin87909c02014-12-13 01:55:01 -05004557 flags: []string{"-min-version", shimVersFlag},
4558 expectedVersion: expectedVersion,
4559 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004560 expectedError: expectedError,
4561 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004562 })
4563 }
4564 }
4565 }
4566}
4567
David Benjamine78bfde2014-09-06 12:45:15 -04004568func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004569 // TODO(davidben): Extensions, where applicable, all move their server
4570 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4571 // tests for both. Also test interaction with 0-RTT when implemented.
4572
David Benjamin97d17d92016-07-14 16:12:00 -04004573 // Repeat extensions tests all versions except SSL 3.0.
4574 for _, ver := range tlsVersions {
4575 if ver.version == VersionSSL30 {
4576 continue
4577 }
4578
David Benjamin97d17d92016-07-14 16:12:00 -04004579 // Test that duplicate extensions are rejected.
4580 testCases = append(testCases, testCase{
4581 testType: clientTest,
4582 name: "DuplicateExtensionClient-" + ver.name,
4583 config: Config{
4584 MaxVersion: ver.version,
4585 Bugs: ProtocolBugs{
4586 DuplicateExtension: true,
4587 },
David Benjamine78bfde2014-09-06 12:45:15 -04004588 },
David Benjamin97d17d92016-07-14 16:12:00 -04004589 shouldFail: true,
4590 expectedLocalError: "remote error: error decoding message",
4591 })
4592 testCases = append(testCases, testCase{
4593 testType: serverTest,
4594 name: "DuplicateExtensionServer-" + ver.name,
4595 config: Config{
4596 MaxVersion: ver.version,
4597 Bugs: ProtocolBugs{
4598 DuplicateExtension: true,
4599 },
David Benjamine78bfde2014-09-06 12:45:15 -04004600 },
David Benjamin97d17d92016-07-14 16:12:00 -04004601 shouldFail: true,
4602 expectedLocalError: "remote error: error decoding message",
4603 })
4604
4605 // Test SNI.
4606 testCases = append(testCases, testCase{
4607 testType: clientTest,
4608 name: "ServerNameExtensionClient-" + ver.name,
4609 config: Config{
4610 MaxVersion: ver.version,
4611 Bugs: ProtocolBugs{
4612 ExpectServerName: "example.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 })
4617 testCases = append(testCases, testCase{
4618 testType: clientTest,
4619 name: "ServerNameExtensionClientMismatch-" + ver.name,
4620 config: Config{
4621 MaxVersion: ver.version,
4622 Bugs: ProtocolBugs{
4623 ExpectServerName: "mismatch.com",
4624 },
David Benjamine78bfde2014-09-06 12:45:15 -04004625 },
David Benjamin97d17d92016-07-14 16:12:00 -04004626 flags: []string{"-host-name", "example.com"},
4627 shouldFail: true,
4628 expectedLocalError: "tls: unexpected server name",
4629 })
4630 testCases = append(testCases, testCase{
4631 testType: clientTest,
4632 name: "ServerNameExtensionClientMissing-" + ver.name,
4633 config: Config{
4634 MaxVersion: ver.version,
4635 Bugs: ProtocolBugs{
4636 ExpectServerName: "missing.com",
4637 },
David Benjamine78bfde2014-09-06 12:45:15 -04004638 },
David Benjamin97d17d92016-07-14 16:12:00 -04004639 shouldFail: true,
4640 expectedLocalError: "tls: unexpected server name",
4641 })
4642 testCases = append(testCases, testCase{
4643 testType: serverTest,
4644 name: "ServerNameExtensionServer-" + ver.name,
4645 config: Config{
4646 MaxVersion: ver.version,
4647 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004648 },
David Benjamin97d17d92016-07-14 16:12:00 -04004649 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004650 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004651 })
4652
4653 // Test ALPN.
4654 testCases = append(testCases, testCase{
4655 testType: clientTest,
4656 name: "ALPNClient-" + ver.name,
4657 config: Config{
4658 MaxVersion: ver.version,
4659 NextProtos: []string{"foo"},
4660 },
4661 flags: []string{
4662 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4663 "-expect-alpn", "foo",
4664 },
4665 expectedNextProto: "foo",
4666 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004667 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004668 })
4669 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004670 testType: clientTest,
4671 name: "ALPNClient-Mismatch-" + ver.name,
4672 config: Config{
4673 MaxVersion: ver.version,
4674 Bugs: ProtocolBugs{
4675 SendALPN: "baz",
4676 },
4677 },
4678 flags: []string{
4679 "-advertise-alpn", "\x03foo\x03bar",
4680 },
4681 shouldFail: true,
4682 expectedError: ":INVALID_ALPN_PROTOCOL:",
4683 expectedLocalError: "remote error: illegal parameter",
4684 })
4685 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004686 testType: serverTest,
4687 name: "ALPNServer-" + ver.name,
4688 config: Config{
4689 MaxVersion: ver.version,
4690 NextProtos: []string{"foo", "bar", "baz"},
4691 },
4692 flags: []string{
4693 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4694 "-select-alpn", "foo",
4695 },
4696 expectedNextProto: "foo",
4697 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004698 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004699 })
4700 testCases = append(testCases, testCase{
4701 testType: serverTest,
4702 name: "ALPNServer-Decline-" + ver.name,
4703 config: Config{
4704 MaxVersion: ver.version,
4705 NextProtos: []string{"foo", "bar", "baz"},
4706 },
4707 flags: []string{"-decline-alpn"},
4708 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004709 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004710 })
4711
David Benjamin25fe85b2016-08-09 20:00:32 -04004712 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4713 // called once.
4714 testCases = append(testCases, testCase{
4715 testType: serverTest,
4716 name: "ALPNServer-Async-" + ver.name,
4717 config: Config{
4718 MaxVersion: ver.version,
4719 NextProtos: []string{"foo", "bar", "baz"},
4720 },
4721 flags: []string{
4722 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4723 "-select-alpn", "foo",
4724 "-async",
4725 },
4726 expectedNextProto: "foo",
4727 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004728 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004729 })
4730
David Benjamin97d17d92016-07-14 16:12:00 -04004731 var emptyString string
4732 testCases = append(testCases, testCase{
4733 testType: clientTest,
4734 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4735 config: Config{
4736 MaxVersion: ver.version,
4737 NextProtos: []string{""},
4738 Bugs: ProtocolBugs{
4739 // A server returning an empty ALPN protocol
4740 // should be rejected.
4741 ALPNProtocol: &emptyString,
4742 },
4743 },
4744 flags: []string{
4745 "-advertise-alpn", "\x03foo",
4746 },
4747 shouldFail: true,
4748 expectedError: ":PARSE_TLSEXT:",
4749 })
4750 testCases = append(testCases, testCase{
4751 testType: serverTest,
4752 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4753 config: Config{
4754 MaxVersion: ver.version,
4755 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004756 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004757 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004758 },
David Benjamin97d17d92016-07-14 16:12:00 -04004759 flags: []string{
4760 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004761 },
David Benjamin97d17d92016-07-14 16:12:00 -04004762 shouldFail: true,
4763 expectedError: ":PARSE_TLSEXT:",
4764 })
4765
4766 // Test NPN and the interaction with ALPN.
4767 if ver.version < VersionTLS13 {
4768 // Test that the server prefers ALPN over NPN.
4769 testCases = append(testCases, testCase{
4770 testType: serverTest,
4771 name: "ALPNServer-Preferred-" + ver.name,
4772 config: Config{
4773 MaxVersion: ver.version,
4774 NextProtos: []string{"foo", "bar", "baz"},
4775 },
4776 flags: []string{
4777 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4778 "-select-alpn", "foo",
4779 "-advertise-npn", "\x03foo\x03bar\x03baz",
4780 },
4781 expectedNextProto: "foo",
4782 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004783 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004784 })
4785 testCases = append(testCases, testCase{
4786 testType: serverTest,
4787 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4788 config: Config{
4789 MaxVersion: ver.version,
4790 NextProtos: []string{"foo", "bar", "baz"},
4791 Bugs: ProtocolBugs{
4792 SwapNPNAndALPN: true,
4793 },
4794 },
4795 flags: []string{
4796 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4797 "-select-alpn", "foo",
4798 "-advertise-npn", "\x03foo\x03bar\x03baz",
4799 },
4800 expectedNextProto: "foo",
4801 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004802 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004803 })
4804
4805 // Test that negotiating both NPN and ALPN is forbidden.
4806 testCases = append(testCases, testCase{
4807 name: "NegotiateALPNAndNPN-" + ver.name,
4808 config: Config{
4809 MaxVersion: ver.version,
4810 NextProtos: []string{"foo", "bar", "baz"},
4811 Bugs: ProtocolBugs{
4812 NegotiateALPNAndNPN: true,
4813 },
4814 },
4815 flags: []string{
4816 "-advertise-alpn", "\x03foo",
4817 "-select-next-proto", "foo",
4818 },
4819 shouldFail: true,
4820 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4821 })
4822 testCases = append(testCases, testCase{
4823 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4824 config: Config{
4825 MaxVersion: ver.version,
4826 NextProtos: []string{"foo", "bar", "baz"},
4827 Bugs: ProtocolBugs{
4828 NegotiateALPNAndNPN: true,
4829 SwapNPNAndALPN: true,
4830 },
4831 },
4832 flags: []string{
4833 "-advertise-alpn", "\x03foo",
4834 "-select-next-proto", "foo",
4835 },
4836 shouldFail: true,
4837 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4838 })
4839
4840 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4841 testCases = append(testCases, testCase{
4842 name: "DisableNPN-" + ver.name,
4843 config: Config{
4844 MaxVersion: ver.version,
4845 NextProtos: []string{"foo"},
4846 },
4847 flags: []string{
4848 "-select-next-proto", "foo",
4849 "-disable-npn",
4850 },
4851 expectNoNextProto: true,
4852 })
4853 }
4854
4855 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004856
4857 // Resume with a corrupt ticket.
4858 testCases = append(testCases, testCase{
4859 testType: serverTest,
4860 name: "CorruptTicket-" + ver.name,
4861 config: Config{
4862 MaxVersion: ver.version,
4863 Bugs: ProtocolBugs{
4864 CorruptTicket: true,
4865 },
4866 },
4867 resumeSession: true,
4868 expectResumeRejected: true,
4869 })
4870 // Test the ticket callback, with and without renewal.
4871 testCases = append(testCases, testCase{
4872 testType: serverTest,
4873 name: "TicketCallback-" + ver.name,
4874 config: Config{
4875 MaxVersion: ver.version,
4876 },
4877 resumeSession: true,
4878 flags: []string{"-use-ticket-callback"},
4879 })
4880 testCases = append(testCases, testCase{
4881 testType: serverTest,
4882 name: "TicketCallback-Renew-" + ver.name,
4883 config: Config{
4884 MaxVersion: ver.version,
4885 Bugs: ProtocolBugs{
4886 ExpectNewTicket: true,
4887 },
4888 },
4889 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4890 resumeSession: true,
4891 })
4892
4893 // Test that the ticket callback is only called once when everything before
4894 // it in the ClientHello is asynchronous. This corrupts the ticket so
4895 // certificate selection callbacks run.
4896 testCases = append(testCases, testCase{
4897 testType: serverTest,
4898 name: "TicketCallback-SingleCall-" + ver.name,
4899 config: Config{
4900 MaxVersion: ver.version,
4901 Bugs: ProtocolBugs{
4902 CorruptTicket: true,
4903 },
4904 },
4905 resumeSession: true,
4906 expectResumeRejected: true,
4907 flags: []string{
4908 "-use-ticket-callback",
4909 "-async",
4910 },
4911 })
4912
4913 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004914 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004915 testCases = append(testCases, testCase{
4916 testType: serverTest,
4917 name: "OversizedSessionId-" + ver.name,
4918 config: Config{
4919 MaxVersion: ver.version,
4920 Bugs: ProtocolBugs{
4921 OversizedSessionId: true,
4922 },
4923 },
4924 resumeSession: true,
4925 shouldFail: true,
4926 expectedError: ":DECODE_ERROR:",
4927 })
4928 }
4929
4930 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4931 // are ignored.
4932 if ver.hasDTLS {
4933 testCases = append(testCases, testCase{
4934 protocol: dtls,
4935 name: "SRTP-Client-" + ver.name,
4936 config: Config{
4937 MaxVersion: ver.version,
4938 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4939 },
4940 flags: []string{
4941 "-srtp-profiles",
4942 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4943 },
4944 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4945 })
4946 testCases = append(testCases, testCase{
4947 protocol: dtls,
4948 testType: serverTest,
4949 name: "SRTP-Server-" + ver.name,
4950 config: Config{
4951 MaxVersion: ver.version,
4952 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4953 },
4954 flags: []string{
4955 "-srtp-profiles",
4956 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4957 },
4958 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4959 })
4960 // Test that the MKI is ignored.
4961 testCases = append(testCases, testCase{
4962 protocol: dtls,
4963 testType: serverTest,
4964 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4965 config: Config{
4966 MaxVersion: ver.version,
4967 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4968 Bugs: ProtocolBugs{
4969 SRTPMasterKeyIdentifer: "bogus",
4970 },
4971 },
4972 flags: []string{
4973 "-srtp-profiles",
4974 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4975 },
4976 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4977 })
4978 // Test that SRTP isn't negotiated on the server if there were
4979 // no matching profiles.
4980 testCases = append(testCases, testCase{
4981 protocol: dtls,
4982 testType: serverTest,
4983 name: "SRTP-Server-NoMatch-" + ver.name,
4984 config: Config{
4985 MaxVersion: ver.version,
4986 SRTPProtectionProfiles: []uint16{100, 101, 102},
4987 },
4988 flags: []string{
4989 "-srtp-profiles",
4990 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4991 },
4992 expectedSRTPProtectionProfile: 0,
4993 })
4994 // Test that the server returning an invalid SRTP profile is
4995 // flagged as an error by the client.
4996 testCases = append(testCases, testCase{
4997 protocol: dtls,
4998 name: "SRTP-Client-NoMatch-" + ver.name,
4999 config: Config{
5000 MaxVersion: ver.version,
5001 Bugs: ProtocolBugs{
5002 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5003 },
5004 },
5005 flags: []string{
5006 "-srtp-profiles",
5007 "SRTP_AES128_CM_SHA1_80",
5008 },
5009 shouldFail: true,
5010 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5011 })
5012 }
5013
5014 // Test SCT list.
5015 testCases = append(testCases, testCase{
5016 name: "SignedCertificateTimestampList-Client-" + ver.name,
5017 testType: clientTest,
5018 config: Config{
5019 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005020 },
David Benjamin97d17d92016-07-14 16:12:00 -04005021 flags: []string{
5022 "-enable-signed-cert-timestamps",
5023 "-expect-signed-cert-timestamps",
5024 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005025 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005026 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005027 })
David Benjamindaa88502016-10-04 16:32:16 -04005028
5029 // The SCT extension did not specify that it must only be sent on resumption as it
5030 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005031 testCases = append(testCases, testCase{
5032 name: "SendSCTListOnResume-" + ver.name,
5033 config: Config{
5034 MaxVersion: ver.version,
5035 Bugs: ProtocolBugs{
5036 SendSCTListOnResume: []byte("bogus"),
5037 },
David Benjamind98452d2015-06-16 14:16:23 -04005038 },
David Benjamin97d17d92016-07-14 16:12:00 -04005039 flags: []string{
5040 "-enable-signed-cert-timestamps",
5041 "-expect-signed-cert-timestamps",
5042 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005043 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005044 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005045 })
David Benjamindaa88502016-10-04 16:32:16 -04005046
David Benjamin97d17d92016-07-14 16:12:00 -04005047 testCases = append(testCases, testCase{
5048 name: "SignedCertificateTimestampList-Server-" + ver.name,
5049 testType: serverTest,
5050 config: Config{
5051 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005052 },
David Benjamin97d17d92016-07-14 16:12:00 -04005053 flags: []string{
5054 "-signed-cert-timestamps",
5055 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005056 },
David Benjamin97d17d92016-07-14 16:12:00 -04005057 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005058 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005059 })
5060 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005061
Paul Lietar4fac72e2015-09-09 13:44:55 +01005062 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005063 testType: clientTest,
5064 name: "ClientHelloPadding",
5065 config: Config{
5066 Bugs: ProtocolBugs{
5067 RequireClientHelloSize: 512,
5068 },
5069 },
5070 // This hostname just needs to be long enough to push the
5071 // ClientHello into F5's danger zone between 256 and 511 bytes
5072 // long.
5073 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5074 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005075
5076 // Extensions should not function in SSL 3.0.
5077 testCases = append(testCases, testCase{
5078 testType: serverTest,
5079 name: "SSLv3Extensions-NoALPN",
5080 config: Config{
5081 MaxVersion: VersionSSL30,
5082 NextProtos: []string{"foo", "bar", "baz"},
5083 },
5084 flags: []string{
5085 "-select-alpn", "foo",
5086 },
5087 expectNoNextProto: true,
5088 })
5089
5090 // Test session tickets separately as they follow a different codepath.
5091 testCases = append(testCases, testCase{
5092 testType: serverTest,
5093 name: "SSLv3Extensions-NoTickets",
5094 config: Config{
5095 MaxVersion: VersionSSL30,
5096 Bugs: ProtocolBugs{
5097 // Historically, session tickets in SSL 3.0
5098 // failed in different ways depending on whether
5099 // the client supported renegotiation_info.
5100 NoRenegotiationInfo: true,
5101 },
5102 },
5103 resumeSession: true,
5104 })
5105 testCases = append(testCases, testCase{
5106 testType: serverTest,
5107 name: "SSLv3Extensions-NoTickets2",
5108 config: Config{
5109 MaxVersion: VersionSSL30,
5110 },
5111 resumeSession: true,
5112 })
5113
5114 // But SSL 3.0 does send and process renegotiation_info.
5115 testCases = append(testCases, testCase{
5116 testType: serverTest,
5117 name: "SSLv3Extensions-RenegotiationInfo",
5118 config: Config{
5119 MaxVersion: VersionSSL30,
5120 Bugs: ProtocolBugs{
5121 RequireRenegotiationInfo: true,
5122 },
5123 },
5124 })
5125 testCases = append(testCases, testCase{
5126 testType: serverTest,
5127 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5128 config: Config{
5129 MaxVersion: VersionSSL30,
5130 Bugs: ProtocolBugs{
5131 NoRenegotiationInfo: true,
5132 SendRenegotiationSCSV: true,
5133 RequireRenegotiationInfo: true,
5134 },
5135 },
5136 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005137
5138 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5139 // in ServerHello.
5140 testCases = append(testCases, testCase{
5141 name: "NPN-Forbidden-TLS13",
5142 config: Config{
5143 MaxVersion: VersionTLS13,
5144 NextProtos: []string{"foo"},
5145 Bugs: ProtocolBugs{
5146 NegotiateNPNAtAllVersions: true,
5147 },
5148 },
5149 flags: []string{"-select-next-proto", "foo"},
5150 shouldFail: true,
5151 expectedError: ":ERROR_PARSING_EXTENSION:",
5152 })
5153 testCases = append(testCases, testCase{
5154 name: "EMS-Forbidden-TLS13",
5155 config: Config{
5156 MaxVersion: VersionTLS13,
5157 Bugs: ProtocolBugs{
5158 NegotiateEMSAtAllVersions: true,
5159 },
5160 },
5161 shouldFail: true,
5162 expectedError: ":ERROR_PARSING_EXTENSION:",
5163 })
5164 testCases = append(testCases, testCase{
5165 name: "RenegotiationInfo-Forbidden-TLS13",
5166 config: Config{
5167 MaxVersion: VersionTLS13,
5168 Bugs: ProtocolBugs{
5169 NegotiateRenegotiationInfoAtAllVersions: true,
5170 },
5171 },
5172 shouldFail: true,
5173 expectedError: ":ERROR_PARSING_EXTENSION:",
5174 })
5175 testCases = append(testCases, testCase{
5176 name: "ChannelID-Forbidden-TLS13",
5177 config: Config{
5178 MaxVersion: VersionTLS13,
5179 RequestChannelID: true,
5180 Bugs: ProtocolBugs{
5181 NegotiateChannelIDAtAllVersions: true,
5182 },
5183 },
5184 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
5185 shouldFail: true,
5186 expectedError: ":ERROR_PARSING_EXTENSION:",
5187 })
5188 testCases = append(testCases, testCase{
5189 name: "Ticket-Forbidden-TLS13",
5190 config: Config{
5191 MaxVersion: VersionTLS12,
5192 },
5193 resumeConfig: &Config{
5194 MaxVersion: VersionTLS13,
5195 Bugs: ProtocolBugs{
5196 AdvertiseTicketExtension: true,
5197 },
5198 },
5199 resumeSession: true,
5200 shouldFail: true,
5201 expectedError: ":ERROR_PARSING_EXTENSION:",
5202 })
5203
5204 // Test that illegal extensions in TLS 1.3 are declined by the server if
5205 // offered in ClientHello. The runner's server will fail if this occurs,
5206 // so we exercise the offering path. (EMS and Renegotiation Info are
5207 // implicit in every test.)
5208 testCases = append(testCases, testCase{
5209 testType: serverTest,
5210 name: "ChannelID-Declined-TLS13",
5211 config: Config{
5212 MaxVersion: VersionTLS13,
5213 ChannelID: channelIDKey,
5214 },
5215 flags: []string{"-enable-channel-id"},
5216 })
5217 testCases = append(testCases, testCase{
5218 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005219 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005220 config: Config{
5221 MaxVersion: VersionTLS13,
5222 NextProtos: []string{"bar"},
5223 },
5224 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5225 })
David Benjamin196df5b2016-09-21 16:23:27 -04005226
5227 testCases = append(testCases, testCase{
5228 testType: serverTest,
5229 name: "InvalidChannelIDSignature",
5230 config: Config{
5231 MaxVersion: VersionTLS12,
5232 ChannelID: channelIDKey,
5233 Bugs: ProtocolBugs{
5234 InvalidChannelIDSignature: true,
5235 },
5236 },
5237 flags: []string{"-enable-channel-id"},
5238 shouldFail: true,
5239 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5240 expectedLocalError: "remote error: error decrypting message",
5241 })
David Benjamindaa88502016-10-04 16:32:16 -04005242
5243 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5244 // tolerated.
5245 testCases = append(testCases, testCase{
5246 name: "SendOCSPResponseOnResume-TLS12",
5247 config: Config{
5248 MaxVersion: VersionTLS12,
5249 Bugs: ProtocolBugs{
5250 SendOCSPResponseOnResume: []byte("bogus"),
5251 },
5252 },
5253 flags: []string{
5254 "-enable-ocsp-stapling",
5255 "-expect-ocsp-response",
5256 base64.StdEncoding.EncodeToString(testOCSPResponse),
5257 },
5258 resumeSession: true,
5259 })
5260
5261 // Beginning TLS 1.3, enforce this does not happen.
5262 testCases = append(testCases, testCase{
5263 name: "SendOCSPResponseOnResume-TLS13",
5264 config: Config{
5265 MaxVersion: VersionTLS13,
5266 Bugs: ProtocolBugs{
5267 SendOCSPResponseOnResume: []byte("bogus"),
5268 },
5269 },
5270 flags: []string{
5271 "-enable-ocsp-stapling",
5272 "-expect-ocsp-response",
5273 base64.StdEncoding.EncodeToString(testOCSPResponse),
5274 },
5275 resumeSession: true,
5276 shouldFail: true,
5277 expectedError: ":ERROR_PARSING_EXTENSION:",
5278 })
David Benjamine78bfde2014-09-06 12:45:15 -04005279}
5280
David Benjamin01fe8202014-09-24 15:21:44 -04005281func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005282 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005283 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005284 // SSL 3.0 does not have tickets and TLS 1.3 does not
5285 // have session IDs, so skip their cross-resumption
5286 // tests.
5287 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5288 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5289 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005290 }
5291
David Benjamin8b8c0062014-11-23 02:47:52 -05005292 protocols := []protocol{tls}
5293 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5294 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005295 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005296 for _, protocol := range protocols {
5297 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5298 if protocol == dtls {
5299 suffix += "-DTLS"
5300 }
5301
David Benjaminece3de92015-03-16 18:02:20 -04005302 if sessionVers.version == resumeVers.version {
5303 testCases = append(testCases, testCase{
5304 protocol: protocol,
5305 name: "Resume-Client" + suffix,
5306 resumeSession: true,
5307 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005308 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005309 Bugs: ProtocolBugs{
5310 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5311 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5312 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005313 },
David Benjaminece3de92015-03-16 18:02:20 -04005314 expectedVersion: sessionVers.version,
5315 expectedResumeVersion: resumeVers.version,
5316 })
5317 } else {
David Benjamin405da482016-08-08 17:25:07 -04005318 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5319
5320 // Offering a TLS 1.3 session sends an empty session ID, so
5321 // there is no way to convince a non-lookahead client the
5322 // session was resumed. It will appear to the client that a
5323 // stray ChangeCipherSpec was sent.
5324 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5325 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005326 }
5327
David Benjaminece3de92015-03-16 18:02:20 -04005328 testCases = append(testCases, testCase{
5329 protocol: protocol,
5330 name: "Resume-Client-Mismatch" + suffix,
5331 resumeSession: true,
5332 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005333 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005334 },
David Benjaminece3de92015-03-16 18:02:20 -04005335 expectedVersion: sessionVers.version,
5336 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005337 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005338 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005339 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005340 },
5341 },
5342 expectedResumeVersion: resumeVers.version,
5343 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005344 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005345 })
5346 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005347
5348 testCases = append(testCases, testCase{
5349 protocol: protocol,
5350 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005351 resumeSession: true,
5352 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005353 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005354 },
5355 expectedVersion: sessionVers.version,
5356 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005357 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005358 },
5359 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005360 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005361 expectedResumeVersion: resumeVers.version,
5362 })
5363
David Benjamin8b8c0062014-11-23 02:47:52 -05005364 testCases = append(testCases, testCase{
5365 protocol: protocol,
5366 testType: serverTest,
5367 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005368 resumeSession: true,
5369 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005370 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005371 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005372 expectedVersion: sessionVers.version,
5373 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005374 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005375 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005376 Bugs: ProtocolBugs{
5377 SendBothTickets: true,
5378 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005379 },
5380 expectedResumeVersion: resumeVers.version,
5381 })
5382 }
David Benjamin01fe8202014-09-24 15:21:44 -04005383 }
5384 }
David Benjaminece3de92015-03-16 18:02:20 -04005385
5386 testCases = append(testCases, testCase{
5387 name: "Resume-Client-CipherMismatch",
5388 resumeSession: true,
5389 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005390 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005391 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5392 },
5393 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005394 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005395 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5396 Bugs: ProtocolBugs{
5397 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5398 },
5399 },
5400 shouldFail: true,
5401 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5402 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005403
5404 testCases = append(testCases, testCase{
5405 name: "Resume-Client-CipherMismatch-TLS13",
5406 resumeSession: true,
5407 config: Config{
5408 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005409 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005410 },
5411 resumeConfig: &Config{
5412 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005413 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005414 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005415 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005416 },
5417 },
5418 shouldFail: true,
5419 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5420 })
David Benjamin01fe8202014-09-24 15:21:44 -04005421}
5422
Adam Langley2ae77d22014-10-28 17:29:33 -07005423func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005424 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005425 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005426 testType: serverTest,
5427 name: "Renegotiate-Server-Forbidden",
5428 config: Config{
5429 MaxVersion: VersionTLS12,
5430 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005431 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005432 shouldFail: true,
5433 expectedError: ":NO_RENEGOTIATION:",
5434 expectedLocalError: "remote error: no renegotiation",
5435 })
Adam Langley5021b222015-06-12 18:27:58 -07005436 // The server shouldn't echo the renegotiation extension unless
5437 // requested by the client.
5438 testCases = append(testCases, testCase{
5439 testType: serverTest,
5440 name: "Renegotiate-Server-NoExt",
5441 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005442 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005443 Bugs: ProtocolBugs{
5444 NoRenegotiationInfo: true,
5445 RequireRenegotiationInfo: true,
5446 },
5447 },
5448 shouldFail: true,
5449 expectedLocalError: "renegotiation extension missing",
5450 })
5451 // The renegotiation SCSV should be sufficient for the server to echo
5452 // the extension.
5453 testCases = append(testCases, testCase{
5454 testType: serverTest,
5455 name: "Renegotiate-Server-NoExt-SCSV",
5456 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005457 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005458 Bugs: ProtocolBugs{
5459 NoRenegotiationInfo: true,
5460 SendRenegotiationSCSV: true,
5461 RequireRenegotiationInfo: true,
5462 },
5463 },
5464 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005465 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005466 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005467 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005468 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005469 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005470 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005471 },
5472 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005473 renegotiate: 1,
5474 flags: []string{
5475 "-renegotiate-freely",
5476 "-expect-total-renegotiations", "1",
5477 },
David Benjamincdea40c2015-03-19 14:09:43 -04005478 })
5479 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005480 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005481 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005482 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005483 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005484 Bugs: ProtocolBugs{
5485 EmptyRenegotiationInfo: true,
5486 },
5487 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005488 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005489 shouldFail: true,
5490 expectedError: ":RENEGOTIATION_MISMATCH:",
5491 })
5492 testCases = append(testCases, testCase{
5493 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005494 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005495 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005496 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005497 Bugs: ProtocolBugs{
5498 BadRenegotiationInfo: true,
5499 },
5500 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005501 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005502 shouldFail: true,
5503 expectedError: ":RENEGOTIATION_MISMATCH:",
5504 })
5505 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005506 name: "Renegotiate-Client-Downgrade",
5507 renegotiate: 1,
5508 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005509 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005510 Bugs: ProtocolBugs{
5511 NoRenegotiationInfoAfterInitial: true,
5512 },
5513 },
5514 flags: []string{"-renegotiate-freely"},
5515 shouldFail: true,
5516 expectedError: ":RENEGOTIATION_MISMATCH:",
5517 })
5518 testCases = append(testCases, testCase{
5519 name: "Renegotiate-Client-Upgrade",
5520 renegotiate: 1,
5521 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005522 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005523 Bugs: ProtocolBugs{
5524 NoRenegotiationInfoInInitial: true,
5525 },
5526 },
5527 flags: []string{"-renegotiate-freely"},
5528 shouldFail: true,
5529 expectedError: ":RENEGOTIATION_MISMATCH:",
5530 })
5531 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005532 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005533 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005534 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005535 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005536 Bugs: ProtocolBugs{
5537 NoRenegotiationInfo: true,
5538 },
5539 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005540 flags: []string{
5541 "-renegotiate-freely",
5542 "-expect-total-renegotiations", "1",
5543 },
David Benjamincff0b902015-05-15 23:09:47 -04005544 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005545
5546 // Test that the server may switch ciphers on renegotiation without
5547 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005548 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005549 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005550 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005551 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005552 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005553 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005554 },
5555 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005556 flags: []string{
5557 "-renegotiate-freely",
5558 "-expect-total-renegotiations", "1",
5559 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005560 })
5561 testCases = append(testCases, testCase{
5562 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005563 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005564 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005565 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005566 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5567 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005568 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005569 flags: []string{
5570 "-renegotiate-freely",
5571 "-expect-total-renegotiations", "1",
5572 },
David Benjaminb16346b2015-04-08 19:16:58 -04005573 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005574
5575 // Test that the server may not switch versions on renegotiation.
5576 testCases = append(testCases, testCase{
5577 name: "Renegotiate-Client-SwitchVersion",
5578 config: Config{
5579 MaxVersion: VersionTLS12,
5580 // Pick a cipher which exists at both versions.
5581 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5582 Bugs: ProtocolBugs{
5583 NegotiateVersionOnRenego: VersionTLS11,
5584 },
5585 },
5586 renegotiate: 1,
5587 flags: []string{
5588 "-renegotiate-freely",
5589 "-expect-total-renegotiations", "1",
5590 },
5591 shouldFail: true,
5592 expectedError: ":WRONG_SSL_VERSION:",
5593 })
5594
David Benjaminb16346b2015-04-08 19:16:58 -04005595 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005596 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005597 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005598 config: Config{
5599 MaxVersion: VersionTLS10,
5600 Bugs: ProtocolBugs{
5601 RequireSameRenegoClientVersion: true,
5602 },
5603 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005604 flags: []string{
5605 "-renegotiate-freely",
5606 "-expect-total-renegotiations", "1",
5607 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005608 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005609 testCases = append(testCases, testCase{
5610 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005611 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005612 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005613 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005614 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5615 NextProtos: []string{"foo"},
5616 },
5617 flags: []string{
5618 "-false-start",
5619 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005620 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005621 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005622 },
5623 shimWritesFirst: true,
5624 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005625
5626 // Client-side renegotiation controls.
5627 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005628 name: "Renegotiate-Client-Forbidden-1",
5629 config: Config{
5630 MaxVersion: VersionTLS12,
5631 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005632 renegotiate: 1,
5633 shouldFail: true,
5634 expectedError: ":NO_RENEGOTIATION:",
5635 expectedLocalError: "remote error: no renegotiation",
5636 })
5637 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005638 name: "Renegotiate-Client-Once-1",
5639 config: Config{
5640 MaxVersion: VersionTLS12,
5641 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005642 renegotiate: 1,
5643 flags: []string{
5644 "-renegotiate-once",
5645 "-expect-total-renegotiations", "1",
5646 },
5647 })
5648 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005649 name: "Renegotiate-Client-Freely-1",
5650 config: Config{
5651 MaxVersion: VersionTLS12,
5652 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005653 renegotiate: 1,
5654 flags: []string{
5655 "-renegotiate-freely",
5656 "-expect-total-renegotiations", "1",
5657 },
5658 })
5659 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005660 name: "Renegotiate-Client-Once-2",
5661 config: Config{
5662 MaxVersion: VersionTLS12,
5663 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005664 renegotiate: 2,
5665 flags: []string{"-renegotiate-once"},
5666 shouldFail: true,
5667 expectedError: ":NO_RENEGOTIATION:",
5668 expectedLocalError: "remote error: no renegotiation",
5669 })
5670 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005671 name: "Renegotiate-Client-Freely-2",
5672 config: Config{
5673 MaxVersion: VersionTLS12,
5674 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005675 renegotiate: 2,
5676 flags: []string{
5677 "-renegotiate-freely",
5678 "-expect-total-renegotiations", "2",
5679 },
5680 })
Adam Langley27a0d082015-11-03 13:34:10 -08005681 testCases = append(testCases, testCase{
5682 name: "Renegotiate-Client-NoIgnore",
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 shouldFail: true,
5690 expectedError: ":NO_RENEGOTIATION:",
5691 })
5692 testCases = append(testCases, testCase{
5693 name: "Renegotiate-Client-Ignore",
5694 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005695 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005696 Bugs: ProtocolBugs{
5697 SendHelloRequestBeforeEveryAppDataRecord: true,
5698 },
5699 },
5700 flags: []string{
5701 "-renegotiate-ignore",
5702 "-expect-total-renegotiations", "0",
5703 },
5704 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005705
David Benjamin34941c02016-10-08 11:45:31 -04005706 // Renegotiation is not allowed at SSL 3.0.
5707 testCases = append(testCases, testCase{
5708 name: "Renegotiate-Client-SSL3",
5709 config: Config{
5710 MaxVersion: VersionSSL30,
5711 },
5712 renegotiate: 1,
5713 flags: []string{
5714 "-renegotiate-freely",
5715 "-expect-total-renegotiations", "1",
5716 },
5717 shouldFail: true,
5718 expectedError: ":NO_RENEGOTIATION:",
5719 expectedLocalError: "remote error: no renegotiation",
5720 })
5721
David Benjamin397c8e62016-07-08 14:14:36 -07005722 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005723 testCases = append(testCases, testCase{
5724 name: "StrayHelloRequest",
5725 config: Config{
5726 MaxVersion: VersionTLS12,
5727 Bugs: ProtocolBugs{
5728 SendHelloRequestBeforeEveryHandshakeMessage: true,
5729 },
5730 },
5731 })
5732 testCases = append(testCases, testCase{
5733 name: "StrayHelloRequest-Packed",
5734 config: Config{
5735 MaxVersion: VersionTLS12,
5736 Bugs: ProtocolBugs{
5737 PackHandshakeFlight: true,
5738 SendHelloRequestBeforeEveryHandshakeMessage: true,
5739 },
5740 },
5741 })
5742
David Benjamin12d2c482016-07-24 10:56:51 -04005743 // Test renegotiation works if HelloRequest and server Finished come in
5744 // the same record.
5745 testCases = append(testCases, testCase{
5746 name: "Renegotiate-Client-Packed",
5747 config: Config{
5748 MaxVersion: VersionTLS12,
5749 Bugs: ProtocolBugs{
5750 PackHandshakeFlight: true,
5751 PackHelloRequestWithFinished: true,
5752 },
5753 },
5754 renegotiate: 1,
5755 flags: []string{
5756 "-renegotiate-freely",
5757 "-expect-total-renegotiations", "1",
5758 },
5759 })
5760
David Benjamin397c8e62016-07-08 14:14:36 -07005761 // Renegotiation is forbidden in TLS 1.3.
5762 testCases = append(testCases, testCase{
5763 name: "Renegotiate-Client-TLS13",
5764 config: Config{
5765 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005766 Bugs: ProtocolBugs{
5767 SendHelloRequestBeforeEveryAppDataRecord: true,
5768 },
David Benjamin397c8e62016-07-08 14:14:36 -07005769 },
David Benjamin397c8e62016-07-08 14:14:36 -07005770 flags: []string{
5771 "-renegotiate-freely",
5772 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005773 shouldFail: true,
5774 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005775 })
5776
5777 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5778 testCases = append(testCases, testCase{
5779 name: "StrayHelloRequest-TLS13",
5780 config: Config{
5781 MaxVersion: VersionTLS13,
5782 Bugs: ProtocolBugs{
5783 SendHelloRequestBeforeEveryHandshakeMessage: true,
5784 },
5785 },
5786 shouldFail: true,
5787 expectedError: ":UNEXPECTED_MESSAGE:",
5788 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005789}
5790
David Benjamin5e961c12014-11-07 01:48:35 -05005791func addDTLSReplayTests() {
5792 // Test that sequence number replays are detected.
5793 testCases = append(testCases, testCase{
5794 protocol: dtls,
5795 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005796 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005797 replayWrites: true,
5798 })
5799
David Benjamin8e6db492015-07-25 18:29:23 -04005800 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005801 // than the retransmit window.
5802 testCases = append(testCases, testCase{
5803 protocol: dtls,
5804 name: "DTLS-Replay-LargeGaps",
5805 config: Config{
5806 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005807 SequenceNumberMapping: func(in uint64) uint64 {
5808 return in * 127
5809 },
David Benjamin5e961c12014-11-07 01:48:35 -05005810 },
5811 },
David Benjamin8e6db492015-07-25 18:29:23 -04005812 messageCount: 200,
5813 replayWrites: true,
5814 })
5815
5816 // Test the incoming sequence number changing non-monotonically.
5817 testCases = append(testCases, testCase{
5818 protocol: dtls,
5819 name: "DTLS-Replay-NonMonotonic",
5820 config: Config{
5821 Bugs: ProtocolBugs{
5822 SequenceNumberMapping: func(in uint64) uint64 {
5823 return in ^ 31
5824 },
5825 },
5826 },
5827 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005828 replayWrites: true,
5829 })
5830}
5831
Nick Harper60edffd2016-06-21 15:19:24 -07005832var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005833 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005834 id signatureAlgorithm
5835 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005836}{
Nick Harper60edffd2016-06-21 15:19:24 -07005837 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5838 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5839 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5840 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005841 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005842 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5843 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5844 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005845 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5846 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5847 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005848 // Tests for key types prior to TLS 1.2.
5849 {"RSA", 0, testCertRSA},
5850 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005851}
5852
Nick Harper60edffd2016-06-21 15:19:24 -07005853const fakeSigAlg1 signatureAlgorithm = 0x2a01
5854const fakeSigAlg2 signatureAlgorithm = 0xff01
5855
5856func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005857 // Not all ciphers involve a signature. Advertise a list which gives all
5858 // versions a signing cipher.
5859 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04005860 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04005861 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5862 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5863 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5864 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5865 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5866 }
5867
David Benjaminca3d5452016-07-14 12:51:01 -04005868 var allAlgorithms []signatureAlgorithm
5869 for _, alg := range testSignatureAlgorithms {
5870 if alg.id != 0 {
5871 allAlgorithms = append(allAlgorithms, alg.id)
5872 }
5873 }
5874
Nick Harper60edffd2016-06-21 15:19:24 -07005875 // Make sure each signature algorithm works. Include some fake values in
5876 // the list and ensure they're ignored.
5877 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005878 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005879 if (ver.version < VersionTLS12) != (alg.id == 0) {
5880 continue
5881 }
5882
5883 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5884 // or remove it in C.
5885 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005886 continue
5887 }
Nick Harper60edffd2016-06-21 15:19:24 -07005888
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005889 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005890 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005891 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5892 shouldFail = true
5893 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005894 // RSA-PKCS1 does not exist in TLS 1.3.
5895 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5896 shouldFail = true
5897 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005898
5899 var signError, verifyError string
5900 if shouldFail {
5901 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5902 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005903 }
David Benjamin000800a2014-11-14 01:43:59 -05005904
David Benjamin1fb125c2016-07-08 18:52:12 -07005905 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005906
David Benjamin7a41d372016-07-09 11:21:54 -07005907 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005908 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005909 config: Config{
5910 MaxVersion: ver.version,
5911 ClientAuth: RequireAnyClientCert,
5912 VerifySignatureAlgorithms: []signatureAlgorithm{
5913 fakeSigAlg1,
5914 alg.id,
5915 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005916 },
David Benjamin7a41d372016-07-09 11:21:54 -07005917 },
5918 flags: []string{
5919 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5920 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5921 "-enable-all-curves",
5922 },
5923 shouldFail: shouldFail,
5924 expectedError: signError,
5925 expectedPeerSignatureAlgorithm: alg.id,
5926 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005927
David Benjamin7a41d372016-07-09 11:21:54 -07005928 testCases = append(testCases, testCase{
5929 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005930 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005931 config: Config{
5932 MaxVersion: ver.version,
5933 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5934 SignSignatureAlgorithms: []signatureAlgorithm{
5935 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005936 },
David Benjamin7a41d372016-07-09 11:21:54 -07005937 Bugs: ProtocolBugs{
5938 SkipECDSACurveCheck: shouldFail,
5939 IgnoreSignatureVersionChecks: shouldFail,
5940 // The client won't advertise 1.3-only algorithms after
5941 // version negotiation.
5942 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005943 },
David Benjamin7a41d372016-07-09 11:21:54 -07005944 },
5945 flags: []string{
5946 "-require-any-client-certificate",
5947 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5948 "-enable-all-curves",
5949 },
5950 shouldFail: shouldFail,
5951 expectedError: verifyError,
5952 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005953
5954 testCases = append(testCases, testCase{
5955 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005956 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005957 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005958 MaxVersion: ver.version,
5959 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005960 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005961 fakeSigAlg1,
5962 alg.id,
5963 fakeSigAlg2,
5964 },
5965 },
5966 flags: []string{
5967 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5968 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5969 "-enable-all-curves",
5970 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005971 shouldFail: shouldFail,
5972 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005973 expectedPeerSignatureAlgorithm: alg.id,
5974 })
5975
5976 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005977 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005978 config: Config{
5979 MaxVersion: ver.version,
5980 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005981 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005982 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005983 alg.id,
5984 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005985 Bugs: ProtocolBugs{
5986 SkipECDSACurveCheck: shouldFail,
5987 IgnoreSignatureVersionChecks: shouldFail,
5988 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005989 },
5990 flags: []string{
5991 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5992 "-enable-all-curves",
5993 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005994 shouldFail: shouldFail,
5995 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005996 })
David Benjamin5208fd42016-07-13 21:43:25 -04005997
5998 if !shouldFail {
5999 testCases = append(testCases, testCase{
6000 testType: serverTest,
6001 name: "ClientAuth-InvalidSignature" + suffix,
6002 config: Config{
6003 MaxVersion: ver.version,
6004 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6005 SignSignatureAlgorithms: []signatureAlgorithm{
6006 alg.id,
6007 },
6008 Bugs: ProtocolBugs{
6009 InvalidSignature: true,
6010 },
6011 },
6012 flags: []string{
6013 "-require-any-client-certificate",
6014 "-enable-all-curves",
6015 },
6016 shouldFail: true,
6017 expectedError: ":BAD_SIGNATURE:",
6018 })
6019
6020 testCases = append(testCases, testCase{
6021 name: "ServerAuth-InvalidSignature" + suffix,
6022 config: Config{
6023 MaxVersion: ver.version,
6024 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6025 CipherSuites: signingCiphers,
6026 SignSignatureAlgorithms: []signatureAlgorithm{
6027 alg.id,
6028 },
6029 Bugs: ProtocolBugs{
6030 InvalidSignature: true,
6031 },
6032 },
6033 flags: []string{"-enable-all-curves"},
6034 shouldFail: true,
6035 expectedError: ":BAD_SIGNATURE:",
6036 })
6037 }
David Benjaminca3d5452016-07-14 12:51:01 -04006038
6039 if ver.version >= VersionTLS12 && !shouldFail {
6040 testCases = append(testCases, testCase{
6041 name: "ClientAuth-Sign-Negotiate" + suffix,
6042 config: Config{
6043 MaxVersion: ver.version,
6044 ClientAuth: RequireAnyClientCert,
6045 VerifySignatureAlgorithms: allAlgorithms,
6046 },
6047 flags: []string{
6048 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6049 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6050 "-enable-all-curves",
6051 "-signing-prefs", strconv.Itoa(int(alg.id)),
6052 },
6053 expectedPeerSignatureAlgorithm: alg.id,
6054 })
6055
6056 testCases = append(testCases, testCase{
6057 testType: serverTest,
6058 name: "ServerAuth-Sign-Negotiate" + suffix,
6059 config: Config{
6060 MaxVersion: ver.version,
6061 CipherSuites: signingCiphers,
6062 VerifySignatureAlgorithms: allAlgorithms,
6063 },
6064 flags: []string{
6065 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6066 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6067 "-enable-all-curves",
6068 "-signing-prefs", strconv.Itoa(int(alg.id)),
6069 },
6070 expectedPeerSignatureAlgorithm: alg.id,
6071 })
6072 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006073 }
David Benjamin000800a2014-11-14 01:43:59 -05006074 }
6075
Nick Harper60edffd2016-06-21 15:19:24 -07006076 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006077 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006078 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006079 config: Config{
6080 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006081 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006082 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006083 signatureECDSAWithP521AndSHA512,
6084 signatureRSAPKCS1WithSHA384,
6085 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006086 },
6087 },
6088 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006089 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6090 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006091 },
Nick Harper60edffd2016-06-21 15:19:24 -07006092 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006093 })
6094
6095 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006096 name: "ClientAuth-SignatureType-TLS13",
6097 config: Config{
6098 ClientAuth: RequireAnyClientCert,
6099 MaxVersion: VersionTLS13,
6100 VerifySignatureAlgorithms: []signatureAlgorithm{
6101 signatureECDSAWithP521AndSHA512,
6102 signatureRSAPKCS1WithSHA384,
6103 signatureRSAPSSWithSHA384,
6104 signatureECDSAWithSHA1,
6105 },
6106 },
6107 flags: []string{
6108 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6109 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6110 },
6111 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6112 })
6113
6114 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006115 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006116 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006117 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006118 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006119 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006120 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006121 signatureECDSAWithP521AndSHA512,
6122 signatureRSAPKCS1WithSHA384,
6123 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006124 },
6125 },
Nick Harper60edffd2016-06-21 15:19:24 -07006126 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006127 })
6128
Steven Valdez143e8b32016-07-11 13:19:03 -04006129 testCases = append(testCases, testCase{
6130 testType: serverTest,
6131 name: "ServerAuth-SignatureType-TLS13",
6132 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006133 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006134 VerifySignatureAlgorithms: []signatureAlgorithm{
6135 signatureECDSAWithP521AndSHA512,
6136 signatureRSAPKCS1WithSHA384,
6137 signatureRSAPSSWithSHA384,
6138 signatureECDSAWithSHA1,
6139 },
6140 },
6141 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6142 })
6143
David Benjamina95e9f32016-07-08 16:28:04 -07006144 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006145 testCases = append(testCases, testCase{
6146 testType: serverTest,
6147 name: "Verify-ClientAuth-SignatureType",
6148 config: Config{
6149 MaxVersion: VersionTLS12,
6150 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006151 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006152 signatureRSAPKCS1WithSHA256,
6153 },
6154 Bugs: ProtocolBugs{
6155 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6156 },
6157 },
6158 flags: []string{
6159 "-require-any-client-certificate",
6160 },
6161 shouldFail: true,
6162 expectedError: ":WRONG_SIGNATURE_TYPE:",
6163 })
6164
6165 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006166 testType: serverTest,
6167 name: "Verify-ClientAuth-SignatureType-TLS13",
6168 config: Config{
6169 MaxVersion: VersionTLS13,
6170 Certificates: []Certificate{rsaCertificate},
6171 SignSignatureAlgorithms: []signatureAlgorithm{
6172 signatureRSAPSSWithSHA256,
6173 },
6174 Bugs: ProtocolBugs{
6175 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6176 },
6177 },
6178 flags: []string{
6179 "-require-any-client-certificate",
6180 },
6181 shouldFail: true,
6182 expectedError: ":WRONG_SIGNATURE_TYPE:",
6183 })
6184
6185 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006186 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006187 config: Config{
6188 MaxVersion: VersionTLS12,
6189 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006190 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006191 signatureRSAPKCS1WithSHA256,
6192 },
6193 Bugs: ProtocolBugs{
6194 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6195 },
6196 },
6197 shouldFail: true,
6198 expectedError: ":WRONG_SIGNATURE_TYPE:",
6199 })
6200
Steven Valdez143e8b32016-07-11 13:19:03 -04006201 testCases = append(testCases, testCase{
6202 name: "Verify-ServerAuth-SignatureType-TLS13",
6203 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006204 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006205 SignSignatureAlgorithms: []signatureAlgorithm{
6206 signatureRSAPSSWithSHA256,
6207 },
6208 Bugs: ProtocolBugs{
6209 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6210 },
6211 },
6212 shouldFail: true,
6213 expectedError: ":WRONG_SIGNATURE_TYPE:",
6214 })
6215
David Benjamin51dd7d62016-07-08 16:07:01 -07006216 // Test that, if the list is missing, the peer falls back to SHA-1 in
6217 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006218 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006219 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006220 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006221 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006222 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006223 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006224 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006225 },
6226 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006227 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006228 },
6229 },
6230 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006231 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6232 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006233 },
6234 })
6235
6236 testCases = append(testCases, testCase{
6237 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006238 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006239 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006240 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006241 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006242 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006243 },
6244 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006245 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006246 },
6247 },
David Benjaminee32bea2016-08-17 13:36:44 -04006248 flags: []string{
6249 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6250 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6251 },
6252 })
6253
6254 testCases = append(testCases, testCase{
6255 name: "ClientAuth-SHA1-Fallback-ECDSA",
6256 config: Config{
6257 MaxVersion: VersionTLS12,
6258 ClientAuth: RequireAnyClientCert,
6259 VerifySignatureAlgorithms: []signatureAlgorithm{
6260 signatureECDSAWithSHA1,
6261 },
6262 Bugs: ProtocolBugs{
6263 NoSignatureAlgorithms: true,
6264 },
6265 },
6266 flags: []string{
6267 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6268 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6269 },
6270 })
6271
6272 testCases = append(testCases, testCase{
6273 testType: serverTest,
6274 name: "ServerAuth-SHA1-Fallback-ECDSA",
6275 config: Config{
6276 MaxVersion: VersionTLS12,
6277 VerifySignatureAlgorithms: []signatureAlgorithm{
6278 signatureECDSAWithSHA1,
6279 },
6280 Bugs: ProtocolBugs{
6281 NoSignatureAlgorithms: true,
6282 },
6283 },
6284 flags: []string{
6285 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6286 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6287 },
David Benjamin000800a2014-11-14 01:43:59 -05006288 })
David Benjamin72dc7832015-03-16 17:49:43 -04006289
David Benjamin51dd7d62016-07-08 16:07:01 -07006290 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006291 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006292 config: Config{
6293 MaxVersion: VersionTLS13,
6294 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006295 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006296 signatureRSAPKCS1WithSHA1,
6297 },
6298 Bugs: ProtocolBugs{
6299 NoSignatureAlgorithms: true,
6300 },
6301 },
6302 flags: []string{
6303 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6304 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6305 },
David Benjamin48901652016-08-01 12:12:47 -04006306 shouldFail: true,
6307 // An empty CertificateRequest signature algorithm list is a
6308 // syntax error in TLS 1.3.
6309 expectedError: ":DECODE_ERROR:",
6310 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006311 })
6312
6313 testCases = append(testCases, testCase{
6314 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006315 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006316 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006317 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006318 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006319 signatureRSAPKCS1WithSHA1,
6320 },
6321 Bugs: ProtocolBugs{
6322 NoSignatureAlgorithms: true,
6323 },
6324 },
6325 shouldFail: true,
6326 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6327 })
6328
David Benjaminb62d2872016-07-18 14:55:02 +02006329 // Test that hash preferences are enforced. BoringSSL does not implement
6330 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006331 testCases = append(testCases, testCase{
6332 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006333 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006334 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006335 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006336 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006337 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006338 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006339 },
6340 Bugs: ProtocolBugs{
6341 IgnorePeerSignatureAlgorithmPreferences: true,
6342 },
6343 },
6344 flags: []string{"-require-any-client-certificate"},
6345 shouldFail: true,
6346 expectedError: ":WRONG_SIGNATURE_TYPE:",
6347 })
6348
6349 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006350 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006351 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006352 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006353 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006354 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006355 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006356 },
6357 Bugs: ProtocolBugs{
6358 IgnorePeerSignatureAlgorithmPreferences: true,
6359 },
6360 },
6361 shouldFail: true,
6362 expectedError: ":WRONG_SIGNATURE_TYPE:",
6363 })
David Benjaminb62d2872016-07-18 14:55:02 +02006364 testCases = append(testCases, testCase{
6365 testType: serverTest,
6366 name: "ClientAuth-Enforced-TLS13",
6367 config: Config{
6368 MaxVersion: VersionTLS13,
6369 Certificates: []Certificate{rsaCertificate},
6370 SignSignatureAlgorithms: []signatureAlgorithm{
6371 signatureRSAPKCS1WithMD5,
6372 },
6373 Bugs: ProtocolBugs{
6374 IgnorePeerSignatureAlgorithmPreferences: true,
6375 IgnoreSignatureVersionChecks: true,
6376 },
6377 },
6378 flags: []string{"-require-any-client-certificate"},
6379 shouldFail: true,
6380 expectedError: ":WRONG_SIGNATURE_TYPE:",
6381 })
6382
6383 testCases = append(testCases, testCase{
6384 name: "ServerAuth-Enforced-TLS13",
6385 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006386 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006387 SignSignatureAlgorithms: []signatureAlgorithm{
6388 signatureRSAPKCS1WithMD5,
6389 },
6390 Bugs: ProtocolBugs{
6391 IgnorePeerSignatureAlgorithmPreferences: true,
6392 IgnoreSignatureVersionChecks: true,
6393 },
6394 },
6395 shouldFail: true,
6396 expectedError: ":WRONG_SIGNATURE_TYPE:",
6397 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006398
6399 // Test that the agreed upon digest respects the client preferences and
6400 // the server digests.
6401 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006402 name: "NoCommonAlgorithms-Digests",
6403 config: Config{
6404 MaxVersion: VersionTLS12,
6405 ClientAuth: RequireAnyClientCert,
6406 VerifySignatureAlgorithms: []signatureAlgorithm{
6407 signatureRSAPKCS1WithSHA512,
6408 signatureRSAPKCS1WithSHA1,
6409 },
6410 },
6411 flags: []string{
6412 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6413 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6414 "-digest-prefs", "SHA256",
6415 },
6416 shouldFail: true,
6417 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6418 })
6419 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006420 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006421 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006422 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006423 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006424 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006425 signatureRSAPKCS1WithSHA512,
6426 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006427 },
6428 },
6429 flags: []string{
6430 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6431 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006432 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006433 },
David Benjaminca3d5452016-07-14 12:51:01 -04006434 shouldFail: true,
6435 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6436 })
6437 testCases = append(testCases, testCase{
6438 name: "NoCommonAlgorithms-TLS13",
6439 config: Config{
6440 MaxVersion: VersionTLS13,
6441 ClientAuth: RequireAnyClientCert,
6442 VerifySignatureAlgorithms: []signatureAlgorithm{
6443 signatureRSAPSSWithSHA512,
6444 signatureRSAPSSWithSHA384,
6445 },
6446 },
6447 flags: []string{
6448 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6449 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6450 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6451 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006452 shouldFail: true,
6453 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006454 })
6455 testCases = append(testCases, testCase{
6456 name: "Agree-Digest-SHA256",
6457 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006458 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006459 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006460 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006461 signatureRSAPKCS1WithSHA1,
6462 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006463 },
6464 },
6465 flags: []string{
6466 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6467 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006468 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006469 },
Nick Harper60edffd2016-06-21 15:19:24 -07006470 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006471 })
6472 testCases = append(testCases, testCase{
6473 name: "Agree-Digest-SHA1",
6474 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006475 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006476 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006477 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006478 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006479 },
6480 },
6481 flags: []string{
6482 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6483 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006484 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006485 },
Nick Harper60edffd2016-06-21 15:19:24 -07006486 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006487 })
6488 testCases = append(testCases, testCase{
6489 name: "Agree-Digest-Default",
6490 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006491 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006492 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006493 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006494 signatureRSAPKCS1WithSHA256,
6495 signatureECDSAWithP256AndSHA256,
6496 signatureRSAPKCS1WithSHA1,
6497 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006498 },
6499 },
6500 flags: []string{
6501 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6502 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6503 },
Nick Harper60edffd2016-06-21 15:19:24 -07006504 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006505 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006506
David Benjaminca3d5452016-07-14 12:51:01 -04006507 // Test that the signing preference list may include extra algorithms
6508 // without negotiation problems.
6509 testCases = append(testCases, testCase{
6510 testType: serverTest,
6511 name: "FilterExtraAlgorithms",
6512 config: Config{
6513 MaxVersion: VersionTLS12,
6514 VerifySignatureAlgorithms: []signatureAlgorithm{
6515 signatureRSAPKCS1WithSHA256,
6516 },
6517 },
6518 flags: []string{
6519 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6520 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6521 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6522 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6523 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6524 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6525 },
6526 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6527 })
6528
David Benjamin4c3ddf72016-06-29 18:13:53 -04006529 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6530 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006531 testCases = append(testCases, testCase{
6532 name: "CheckLeafCurve",
6533 config: Config{
6534 MaxVersion: VersionTLS12,
6535 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006536 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006537 },
6538 flags: []string{"-p384-only"},
6539 shouldFail: true,
6540 expectedError: ":BAD_ECC_CERT:",
6541 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006542
6543 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6544 testCases = append(testCases, testCase{
6545 name: "CheckLeafCurve-TLS13",
6546 config: Config{
6547 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07006548 Certificates: []Certificate{ecdsaP256Certificate},
6549 },
6550 flags: []string{"-p384-only"},
6551 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006552
6553 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6554 testCases = append(testCases, testCase{
6555 name: "ECDSACurveMismatch-Verify-TLS12",
6556 config: Config{
6557 MaxVersion: VersionTLS12,
6558 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6559 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006560 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006561 signatureECDSAWithP384AndSHA384,
6562 },
6563 },
6564 })
6565
6566 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6567 testCases = append(testCases, testCase{
6568 name: "ECDSACurveMismatch-Verify-TLS13",
6569 config: Config{
6570 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07006571 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006572 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006573 signatureECDSAWithP384AndSHA384,
6574 },
6575 Bugs: ProtocolBugs{
6576 SkipECDSACurveCheck: true,
6577 },
6578 },
6579 shouldFail: true,
6580 expectedError: ":WRONG_SIGNATURE_TYPE:",
6581 })
6582
6583 // Signature algorithm selection in TLS 1.3 should take the curve into
6584 // account.
6585 testCases = append(testCases, testCase{
6586 testType: serverTest,
6587 name: "ECDSACurveMismatch-Sign-TLS13",
6588 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006589 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006590 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006591 signatureECDSAWithP384AndSHA384,
6592 signatureECDSAWithP256AndSHA256,
6593 },
6594 },
6595 flags: []string{
6596 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6597 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6598 },
6599 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6600 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006601
6602 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6603 // server does not attempt to sign in that case.
6604 testCases = append(testCases, testCase{
6605 testType: serverTest,
6606 name: "RSA-PSS-Large",
6607 config: Config{
6608 MaxVersion: VersionTLS13,
6609 VerifySignatureAlgorithms: []signatureAlgorithm{
6610 signatureRSAPSSWithSHA512,
6611 },
6612 },
6613 flags: []string{
6614 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6615 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6616 },
6617 shouldFail: true,
6618 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6619 })
David Benjamin57e929f2016-08-30 00:30:38 -04006620
6621 // Test that RSA-PSS is enabled by default for TLS 1.2.
6622 testCases = append(testCases, testCase{
6623 testType: clientTest,
6624 name: "RSA-PSS-Default-Verify",
6625 config: Config{
6626 MaxVersion: VersionTLS12,
6627 SignSignatureAlgorithms: []signatureAlgorithm{
6628 signatureRSAPSSWithSHA256,
6629 },
6630 },
6631 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6632 })
6633
6634 testCases = append(testCases, testCase{
6635 testType: serverTest,
6636 name: "RSA-PSS-Default-Sign",
6637 config: Config{
6638 MaxVersion: VersionTLS12,
6639 VerifySignatureAlgorithms: []signatureAlgorithm{
6640 signatureRSAPSSWithSHA256,
6641 },
6642 },
6643 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6644 })
David Benjamin000800a2014-11-14 01:43:59 -05006645}
6646
David Benjamin83f90402015-01-27 01:09:43 -05006647// timeouts is the retransmit schedule for BoringSSL. It doubles and
6648// caps at 60 seconds. On the 13th timeout, it gives up.
6649var timeouts = []time.Duration{
6650 1 * time.Second,
6651 2 * time.Second,
6652 4 * time.Second,
6653 8 * time.Second,
6654 16 * time.Second,
6655 32 * time.Second,
6656 60 * time.Second,
6657 60 * time.Second,
6658 60 * time.Second,
6659 60 * time.Second,
6660 60 * time.Second,
6661 60 * time.Second,
6662 60 * time.Second,
6663}
6664
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006665// shortTimeouts is an alternate set of timeouts which would occur if the
6666// initial timeout duration was set to 250ms.
6667var shortTimeouts = []time.Duration{
6668 250 * time.Millisecond,
6669 500 * time.Millisecond,
6670 1 * time.Second,
6671 2 * time.Second,
6672 4 * time.Second,
6673 8 * time.Second,
6674 16 * time.Second,
6675 32 * time.Second,
6676 60 * time.Second,
6677 60 * time.Second,
6678 60 * time.Second,
6679 60 * time.Second,
6680 60 * time.Second,
6681}
6682
David Benjamin83f90402015-01-27 01:09:43 -05006683func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006684 // These tests work by coordinating some behavior on both the shim and
6685 // the runner.
6686 //
6687 // TimeoutSchedule configures the runner to send a series of timeout
6688 // opcodes to the shim (see packetAdaptor) immediately before reading
6689 // each peer handshake flight N. The timeout opcode both simulates a
6690 // timeout in the shim and acts as a synchronization point to help the
6691 // runner bracket each handshake flight.
6692 //
6693 // We assume the shim does not read from the channel eagerly. It must
6694 // first wait until it has sent flight N and is ready to receive
6695 // handshake flight N+1. At this point, it will process the timeout
6696 // opcode. It must then immediately respond with a timeout ACK and act
6697 // as if the shim was idle for the specified amount of time.
6698 //
6699 // The runner then drops all packets received before the ACK and
6700 // continues waiting for flight N. This ordering results in one attempt
6701 // at sending flight N to be dropped. For the test to complete, the
6702 // shim must send flight N again, testing that the shim implements DTLS
6703 // retransmit on a timeout.
6704
Steven Valdez143e8b32016-07-11 13:19:03 -04006705 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006706 // likely be more epochs to cross and the final message's retransmit may
6707 // be more complex.
6708
David Benjamin585d7a42016-06-02 14:58:00 -04006709 for _, async := range []bool{true, false} {
6710 var tests []testCase
6711
6712 // Test that this is indeed the timeout schedule. Stress all
6713 // four patterns of handshake.
6714 for i := 1; i < len(timeouts); i++ {
6715 number := strconv.Itoa(i)
6716 tests = append(tests, testCase{
6717 protocol: dtls,
6718 name: "DTLS-Retransmit-Client-" + number,
6719 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006720 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006721 Bugs: ProtocolBugs{
6722 TimeoutSchedule: timeouts[:i],
6723 },
6724 },
6725 resumeSession: true,
6726 })
6727 tests = append(tests, testCase{
6728 protocol: dtls,
6729 testType: serverTest,
6730 name: "DTLS-Retransmit-Server-" + number,
6731 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006732 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006733 Bugs: ProtocolBugs{
6734 TimeoutSchedule: timeouts[:i],
6735 },
6736 },
6737 resumeSession: true,
6738 })
6739 }
6740
6741 // Test that exceeding the timeout schedule hits a read
6742 // timeout.
6743 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006744 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006745 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006746 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006747 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006748 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006749 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006750 },
6751 },
6752 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006753 shouldFail: true,
6754 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006755 })
David Benjamin585d7a42016-06-02 14:58:00 -04006756
6757 if async {
6758 // Test that timeout handling has a fudge factor, due to API
6759 // problems.
6760 tests = append(tests, testCase{
6761 protocol: dtls,
6762 name: "DTLS-Retransmit-Fudge",
6763 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006764 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006765 Bugs: ProtocolBugs{
6766 TimeoutSchedule: []time.Duration{
6767 timeouts[0] - 10*time.Millisecond,
6768 },
6769 },
6770 },
6771 resumeSession: true,
6772 })
6773 }
6774
6775 // Test that the final Finished retransmitting isn't
6776 // duplicated if the peer badly fragments everything.
6777 tests = append(tests, testCase{
6778 testType: serverTest,
6779 protocol: dtls,
6780 name: "DTLS-Retransmit-Fragmented",
6781 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006782 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006783 Bugs: ProtocolBugs{
6784 TimeoutSchedule: []time.Duration{timeouts[0]},
6785 MaxHandshakeRecordLength: 2,
6786 },
6787 },
6788 })
6789
6790 // Test the timeout schedule when a shorter initial timeout duration is set.
6791 tests = append(tests, testCase{
6792 protocol: dtls,
6793 name: "DTLS-Retransmit-Short-Client",
6794 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006795 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006796 Bugs: ProtocolBugs{
6797 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6798 },
6799 },
6800 resumeSession: true,
6801 flags: []string{"-initial-timeout-duration-ms", "250"},
6802 })
6803 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006804 protocol: dtls,
6805 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006806 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006807 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006808 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006809 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006810 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006811 },
6812 },
6813 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006814 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006815 })
David Benjamin585d7a42016-06-02 14:58:00 -04006816
6817 for _, test := range tests {
6818 if async {
6819 test.name += "-Async"
6820 test.flags = append(test.flags, "-async")
6821 }
6822
6823 testCases = append(testCases, test)
6824 }
David Benjamin83f90402015-01-27 01:09:43 -05006825 }
David Benjamin83f90402015-01-27 01:09:43 -05006826}
6827
David Benjaminc565ebb2015-04-03 04:06:36 -04006828func addExportKeyingMaterialTests() {
6829 for _, vers := range tlsVersions {
6830 if vers.version == VersionSSL30 {
6831 continue
6832 }
6833 testCases = append(testCases, testCase{
6834 name: "ExportKeyingMaterial-" + vers.name,
6835 config: Config{
6836 MaxVersion: vers.version,
6837 },
6838 exportKeyingMaterial: 1024,
6839 exportLabel: "label",
6840 exportContext: "context",
6841 useExportContext: true,
6842 })
6843 testCases = append(testCases, testCase{
6844 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6845 config: Config{
6846 MaxVersion: vers.version,
6847 },
6848 exportKeyingMaterial: 1024,
6849 })
6850 testCases = append(testCases, testCase{
6851 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6852 config: Config{
6853 MaxVersion: vers.version,
6854 },
6855 exportKeyingMaterial: 1024,
6856 useExportContext: true,
6857 })
6858 testCases = append(testCases, testCase{
6859 name: "ExportKeyingMaterial-Small-" + vers.name,
6860 config: Config{
6861 MaxVersion: vers.version,
6862 },
6863 exportKeyingMaterial: 1,
6864 exportLabel: "label",
6865 exportContext: "context",
6866 useExportContext: true,
6867 })
6868 }
6869 testCases = append(testCases, testCase{
6870 name: "ExportKeyingMaterial-SSL3",
6871 config: Config{
6872 MaxVersion: VersionSSL30,
6873 },
6874 exportKeyingMaterial: 1024,
6875 exportLabel: "label",
6876 exportContext: "context",
6877 useExportContext: true,
6878 shouldFail: true,
6879 expectedError: "failed to export keying material",
6880 })
6881}
6882
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006883func addTLSUniqueTests() {
6884 for _, isClient := range []bool{false, true} {
6885 for _, isResumption := range []bool{false, true} {
6886 for _, hasEMS := range []bool{false, true} {
6887 var suffix string
6888 if isResumption {
6889 suffix = "Resume-"
6890 } else {
6891 suffix = "Full-"
6892 }
6893
6894 if hasEMS {
6895 suffix += "EMS-"
6896 } else {
6897 suffix += "NoEMS-"
6898 }
6899
6900 if isClient {
6901 suffix += "Client"
6902 } else {
6903 suffix += "Server"
6904 }
6905
6906 test := testCase{
6907 name: "TLSUnique-" + suffix,
6908 testTLSUnique: true,
6909 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006910 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006911 Bugs: ProtocolBugs{
6912 NoExtendedMasterSecret: !hasEMS,
6913 },
6914 },
6915 }
6916
6917 if isResumption {
6918 test.resumeSession = true
6919 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006920 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006921 Bugs: ProtocolBugs{
6922 NoExtendedMasterSecret: !hasEMS,
6923 },
6924 }
6925 }
6926
6927 if isResumption && !hasEMS {
6928 test.shouldFail = true
6929 test.expectedError = "failed to get tls-unique"
6930 }
6931
6932 testCases = append(testCases, test)
6933 }
6934 }
6935 }
6936}
6937
Adam Langley09505632015-07-30 18:10:13 -07006938func addCustomExtensionTests() {
6939 expectedContents := "custom extension"
6940 emptyString := ""
6941
6942 for _, isClient := range []bool{false, true} {
6943 suffix := "Server"
6944 flag := "-enable-server-custom-extension"
6945 testType := serverTest
6946 if isClient {
6947 suffix = "Client"
6948 flag = "-enable-client-custom-extension"
6949 testType = clientTest
6950 }
6951
6952 testCases = append(testCases, testCase{
6953 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006954 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006955 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006956 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006957 Bugs: ProtocolBugs{
6958 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006959 ExpectedCustomExtension: &expectedContents,
6960 },
6961 },
6962 flags: []string{flag},
6963 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006964 testCases = append(testCases, testCase{
6965 testType: testType,
6966 name: "CustomExtensions-" + suffix + "-TLS13",
6967 config: Config{
6968 MaxVersion: VersionTLS13,
6969 Bugs: ProtocolBugs{
6970 CustomExtension: expectedContents,
6971 ExpectedCustomExtension: &expectedContents,
6972 },
6973 },
6974 flags: []string{flag},
6975 })
Adam Langley09505632015-07-30 18:10:13 -07006976
6977 // If the parse callback fails, the handshake should also fail.
6978 testCases = append(testCases, testCase{
6979 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006980 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006981 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006982 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006983 Bugs: ProtocolBugs{
6984 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006985 ExpectedCustomExtension: &expectedContents,
6986 },
6987 },
David Benjamin399e7c92015-07-30 23:01:27 -04006988 flags: []string{flag},
6989 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006990 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6991 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006992 testCases = append(testCases, testCase{
6993 testType: testType,
6994 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6995 config: Config{
6996 MaxVersion: VersionTLS13,
6997 Bugs: ProtocolBugs{
6998 CustomExtension: expectedContents + "foo",
6999 ExpectedCustomExtension: &expectedContents,
7000 },
7001 },
7002 flags: []string{flag},
7003 shouldFail: true,
7004 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7005 })
Adam Langley09505632015-07-30 18:10:13 -07007006
7007 // If the add callback fails, the handshake should also fail.
7008 testCases = append(testCases, testCase{
7009 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007010 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007011 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007012 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007013 Bugs: ProtocolBugs{
7014 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007015 ExpectedCustomExtension: &expectedContents,
7016 },
7017 },
David Benjamin399e7c92015-07-30 23:01:27 -04007018 flags: []string{flag, "-custom-extension-fail-add"},
7019 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007020 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7021 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007022 testCases = append(testCases, testCase{
7023 testType: testType,
7024 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7025 config: Config{
7026 MaxVersion: VersionTLS13,
7027 Bugs: ProtocolBugs{
7028 CustomExtension: expectedContents,
7029 ExpectedCustomExtension: &expectedContents,
7030 },
7031 },
7032 flags: []string{flag, "-custom-extension-fail-add"},
7033 shouldFail: true,
7034 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7035 })
Adam Langley09505632015-07-30 18:10:13 -07007036
7037 // If the add callback returns zero, no extension should be
7038 // added.
7039 skipCustomExtension := expectedContents
7040 if isClient {
7041 // For the case where the client skips sending the
7042 // custom extension, the server must not “echo” it.
7043 skipCustomExtension = ""
7044 }
7045 testCases = append(testCases, testCase{
7046 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007047 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007048 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007049 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007050 Bugs: ProtocolBugs{
7051 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007052 ExpectedCustomExtension: &emptyString,
7053 },
7054 },
7055 flags: []string{flag, "-custom-extension-skip"},
7056 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007057 testCases = append(testCases, testCase{
7058 testType: testType,
7059 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7060 config: Config{
7061 MaxVersion: VersionTLS13,
7062 Bugs: ProtocolBugs{
7063 CustomExtension: skipCustomExtension,
7064 ExpectedCustomExtension: &emptyString,
7065 },
7066 },
7067 flags: []string{flag, "-custom-extension-skip"},
7068 })
Adam Langley09505632015-07-30 18:10:13 -07007069 }
7070
7071 // The custom extension add callback should not be called if the client
7072 // doesn't send the extension.
7073 testCases = append(testCases, testCase{
7074 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007075 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007076 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007077 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007078 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007079 ExpectedCustomExtension: &emptyString,
7080 },
7081 },
7082 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7083 })
Adam Langley2deb9842015-08-07 11:15:37 -07007084
Steven Valdez143e8b32016-07-11 13:19:03 -04007085 testCases = append(testCases, testCase{
7086 testType: serverTest,
7087 name: "CustomExtensions-NotCalled-Server-TLS13",
7088 config: Config{
7089 MaxVersion: VersionTLS13,
7090 Bugs: ProtocolBugs{
7091 ExpectedCustomExtension: &emptyString,
7092 },
7093 },
7094 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7095 })
7096
Adam Langley2deb9842015-08-07 11:15:37 -07007097 // Test an unknown extension from the server.
7098 testCases = append(testCases, testCase{
7099 testType: clientTest,
7100 name: "UnknownExtension-Client",
7101 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007102 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007103 Bugs: ProtocolBugs{
7104 CustomExtension: expectedContents,
7105 },
7106 },
David Benjamin0c40a962016-08-01 12:05:50 -04007107 shouldFail: true,
7108 expectedError: ":UNEXPECTED_EXTENSION:",
7109 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007110 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007111 testCases = append(testCases, testCase{
7112 testType: clientTest,
7113 name: "UnknownExtension-Client-TLS13",
7114 config: Config{
7115 MaxVersion: VersionTLS13,
7116 Bugs: ProtocolBugs{
7117 CustomExtension: expectedContents,
7118 },
7119 },
David Benjamin0c40a962016-08-01 12:05:50 -04007120 shouldFail: true,
7121 expectedError: ":UNEXPECTED_EXTENSION:",
7122 expectedLocalError: "remote error: unsupported extension",
7123 })
David Benjamin490469f2016-10-05 22:44:38 -04007124 testCases = append(testCases, testCase{
7125 testType: clientTest,
7126 name: "UnknownUnencryptedExtension-Client-TLS13",
7127 config: Config{
7128 MaxVersion: VersionTLS13,
7129 Bugs: ProtocolBugs{
7130 CustomUnencryptedExtension: expectedContents,
7131 },
7132 },
7133 shouldFail: true,
7134 expectedError: ":UNEXPECTED_EXTENSION:",
7135 // The shim must send an alert, but alerts at this point do not
7136 // get successfully decrypted by the runner.
7137 expectedLocalError: "local error: bad record MAC",
7138 })
7139 testCases = append(testCases, testCase{
7140 testType: clientTest,
7141 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7142 config: Config{
7143 MaxVersion: VersionTLS13,
7144 Bugs: ProtocolBugs{
7145 SendUnencryptedALPN: "foo",
7146 },
7147 },
7148 flags: []string{
7149 "-advertise-alpn", "\x03foo\x03bar",
7150 },
7151 shouldFail: true,
7152 expectedError: ":UNEXPECTED_EXTENSION:",
7153 // The shim must send an alert, but alerts at this point do not
7154 // get successfully decrypted by the runner.
7155 expectedLocalError: "local error: bad record MAC",
7156 })
David Benjamin0c40a962016-08-01 12:05:50 -04007157
7158 // Test a known but unoffered extension from the server.
7159 testCases = append(testCases, testCase{
7160 testType: clientTest,
7161 name: "UnofferedExtension-Client",
7162 config: Config{
7163 MaxVersion: VersionTLS12,
7164 Bugs: ProtocolBugs{
7165 SendALPN: "alpn",
7166 },
7167 },
7168 shouldFail: true,
7169 expectedError: ":UNEXPECTED_EXTENSION:",
7170 expectedLocalError: "remote error: unsupported extension",
7171 })
7172 testCases = append(testCases, testCase{
7173 testType: clientTest,
7174 name: "UnofferedExtension-Client-TLS13",
7175 config: Config{
7176 MaxVersion: VersionTLS13,
7177 Bugs: ProtocolBugs{
7178 SendALPN: "alpn",
7179 },
7180 },
7181 shouldFail: true,
7182 expectedError: ":UNEXPECTED_EXTENSION:",
7183 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007184 })
Adam Langley09505632015-07-30 18:10:13 -07007185}
7186
David Benjaminb36a3952015-12-01 18:53:13 -05007187func addRSAClientKeyExchangeTests() {
7188 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7189 testCases = append(testCases, testCase{
7190 testType: serverTest,
7191 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7192 config: Config{
7193 // Ensure the ClientHello version and final
7194 // version are different, to detect if the
7195 // server uses the wrong one.
7196 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007197 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007198 Bugs: ProtocolBugs{
7199 BadRSAClientKeyExchange: bad,
7200 },
7201 },
7202 shouldFail: true,
7203 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7204 })
7205 }
David Benjamine63d9d72016-09-19 18:27:34 -04007206
7207 // The server must compare whatever was in ClientHello.version for the
7208 // RSA premaster.
7209 testCases = append(testCases, testCase{
7210 testType: serverTest,
7211 name: "SendClientVersion-RSA",
7212 config: Config{
7213 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7214 Bugs: ProtocolBugs{
7215 SendClientVersion: 0x1234,
7216 },
7217 },
7218 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7219 })
David Benjaminb36a3952015-12-01 18:53:13 -05007220}
7221
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007222var testCurves = []struct {
7223 name string
7224 id CurveID
7225}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007226 {"P-256", CurveP256},
7227 {"P-384", CurveP384},
7228 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007229 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007230}
7231
Steven Valdez5440fe02016-07-18 12:40:30 -04007232const bogusCurve = 0x1234
7233
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007234func addCurveTests() {
7235 for _, curve := range testCurves {
7236 testCases = append(testCases, testCase{
7237 name: "CurveTest-Client-" + curve.name,
7238 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007239 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007240 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7241 CurvePreferences: []CurveID{curve.id},
7242 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007243 flags: []string{
7244 "-enable-all-curves",
7245 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7246 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007247 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007248 })
7249 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007250 name: "CurveTest-Client-" + curve.name + "-TLS13",
7251 config: Config{
7252 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007253 CurvePreferences: []CurveID{curve.id},
7254 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007255 flags: []string{
7256 "-enable-all-curves",
7257 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7258 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007259 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007260 })
7261 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007262 testType: serverTest,
7263 name: "CurveTest-Server-" + curve.name,
7264 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007265 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007266 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7267 CurvePreferences: []CurveID{curve.id},
7268 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007269 flags: []string{
7270 "-enable-all-curves",
7271 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7272 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007273 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007274 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007275 testCases = append(testCases, testCase{
7276 testType: serverTest,
7277 name: "CurveTest-Server-" + curve.name + "-TLS13",
7278 config: Config{
7279 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007280 CurvePreferences: []CurveID{curve.id},
7281 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007282 flags: []string{
7283 "-enable-all-curves",
7284 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7285 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007286 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007287 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007288 }
David Benjamin241ae832016-01-15 03:04:54 -05007289
7290 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007291 testCases = append(testCases, testCase{
7292 testType: serverTest,
7293 name: "UnknownCurve",
7294 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007295 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007296 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7297 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7298 },
7299 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007300
Steven Valdez803c77a2016-09-06 14:13:43 -04007301 // The server must be tolerant to bogus curves.
7302 testCases = append(testCases, testCase{
7303 testType: serverTest,
7304 name: "UnknownCurve-TLS13",
7305 config: Config{
7306 MaxVersion: VersionTLS13,
7307 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7308 },
7309 })
7310
David Benjamin4c3ddf72016-06-29 18:13:53 -04007311 // The server must not consider ECDHE ciphers when there are no
7312 // supported curves.
7313 testCases = append(testCases, testCase{
7314 testType: serverTest,
7315 name: "NoSupportedCurves",
7316 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007317 MaxVersion: VersionTLS12,
7318 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7319 Bugs: ProtocolBugs{
7320 NoSupportedCurves: true,
7321 },
7322 },
7323 shouldFail: true,
7324 expectedError: ":NO_SHARED_CIPHER:",
7325 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007326 testCases = append(testCases, testCase{
7327 testType: serverTest,
7328 name: "NoSupportedCurves-TLS13",
7329 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007330 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007331 Bugs: ProtocolBugs{
7332 NoSupportedCurves: true,
7333 },
7334 },
7335 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007336 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007337 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007338
7339 // The server must fall back to another cipher when there are no
7340 // supported curves.
7341 testCases = append(testCases, testCase{
7342 testType: serverTest,
7343 name: "NoCommonCurves",
7344 config: Config{
7345 MaxVersion: VersionTLS12,
7346 CipherSuites: []uint16{
7347 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7348 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7349 },
7350 CurvePreferences: []CurveID{CurveP224},
7351 },
7352 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7353 })
7354
7355 // The client must reject bogus curves and disabled curves.
7356 testCases = append(testCases, testCase{
7357 name: "BadECDHECurve",
7358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007359 MaxVersion: VersionTLS12,
7360 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7361 Bugs: ProtocolBugs{
7362 SendCurve: bogusCurve,
7363 },
7364 },
7365 shouldFail: true,
7366 expectedError: ":WRONG_CURVE:",
7367 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007368 testCases = append(testCases, testCase{
7369 name: "BadECDHECurve-TLS13",
7370 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007371 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007372 Bugs: ProtocolBugs{
7373 SendCurve: bogusCurve,
7374 },
7375 },
7376 shouldFail: true,
7377 expectedError: ":WRONG_CURVE:",
7378 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007379
7380 testCases = append(testCases, testCase{
7381 name: "UnsupportedCurve",
7382 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007383 MaxVersion: VersionTLS12,
7384 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7385 CurvePreferences: []CurveID{CurveP256},
7386 Bugs: ProtocolBugs{
7387 IgnorePeerCurvePreferences: true,
7388 },
7389 },
7390 flags: []string{"-p384-only"},
7391 shouldFail: true,
7392 expectedError: ":WRONG_CURVE:",
7393 })
7394
David Benjamin4f921572016-07-17 14:20:10 +02007395 testCases = append(testCases, testCase{
7396 // TODO(davidben): Add a TLS 1.3 version where
7397 // HelloRetryRequest requests an unsupported curve.
7398 name: "UnsupportedCurve-ServerHello-TLS13",
7399 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007400 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02007401 CurvePreferences: []CurveID{CurveP384},
7402 Bugs: ProtocolBugs{
7403 SendCurve: CurveP256,
7404 },
7405 },
7406 flags: []string{"-p384-only"},
7407 shouldFail: true,
7408 expectedError: ":WRONG_CURVE:",
7409 })
7410
David Benjamin4c3ddf72016-06-29 18:13:53 -04007411 // Test invalid curve points.
7412 testCases = append(testCases, testCase{
7413 name: "InvalidECDHPoint-Client",
7414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007415 MaxVersion: VersionTLS12,
7416 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7417 CurvePreferences: []CurveID{CurveP256},
7418 Bugs: ProtocolBugs{
7419 InvalidECDHPoint: true,
7420 },
7421 },
7422 shouldFail: true,
7423 expectedError: ":INVALID_ENCODING:",
7424 })
7425 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007426 name: "InvalidECDHPoint-Client-TLS13",
7427 config: Config{
7428 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007429 CurvePreferences: []CurveID{CurveP256},
7430 Bugs: ProtocolBugs{
7431 InvalidECDHPoint: true,
7432 },
7433 },
7434 shouldFail: true,
7435 expectedError: ":INVALID_ENCODING:",
7436 })
7437 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007438 testType: serverTest,
7439 name: "InvalidECDHPoint-Server",
7440 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007441 MaxVersion: VersionTLS12,
7442 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7443 CurvePreferences: []CurveID{CurveP256},
7444 Bugs: ProtocolBugs{
7445 InvalidECDHPoint: true,
7446 },
7447 },
7448 shouldFail: true,
7449 expectedError: ":INVALID_ENCODING:",
7450 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007451 testCases = append(testCases, testCase{
7452 testType: serverTest,
7453 name: "InvalidECDHPoint-Server-TLS13",
7454 config: Config{
7455 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007456 CurvePreferences: []CurveID{CurveP256},
7457 Bugs: ProtocolBugs{
7458 InvalidECDHPoint: true,
7459 },
7460 },
7461 shouldFail: true,
7462 expectedError: ":INVALID_ENCODING:",
7463 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007464}
7465
Matt Braithwaite54217e42016-06-13 13:03:47 -07007466func addCECPQ1Tests() {
7467 testCases = append(testCases, testCase{
7468 testType: clientTest,
7469 name: "CECPQ1-Client-BadX25519Part",
7470 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007471 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007472 MinVersion: VersionTLS12,
7473 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7474 Bugs: ProtocolBugs{
7475 CECPQ1BadX25519Part: true,
7476 },
7477 },
7478 flags: []string{"-cipher", "kCECPQ1"},
7479 shouldFail: true,
7480 expectedLocalError: "local error: bad record MAC",
7481 })
7482 testCases = append(testCases, testCase{
7483 testType: clientTest,
7484 name: "CECPQ1-Client-BadNewhopePart",
7485 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007486 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007487 MinVersion: VersionTLS12,
7488 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7489 Bugs: ProtocolBugs{
7490 CECPQ1BadNewhopePart: true,
7491 },
7492 },
7493 flags: []string{"-cipher", "kCECPQ1"},
7494 shouldFail: true,
7495 expectedLocalError: "local error: bad record MAC",
7496 })
7497 testCases = append(testCases, testCase{
7498 testType: serverTest,
7499 name: "CECPQ1-Server-BadX25519Part",
7500 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007501 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007502 MinVersion: VersionTLS12,
7503 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7504 Bugs: ProtocolBugs{
7505 CECPQ1BadX25519Part: true,
7506 },
7507 },
7508 flags: []string{"-cipher", "kCECPQ1"},
7509 shouldFail: true,
7510 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7511 })
7512 testCases = append(testCases, testCase{
7513 testType: serverTest,
7514 name: "CECPQ1-Server-BadNewhopePart",
7515 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007516 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007517 MinVersion: VersionTLS12,
7518 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7519 Bugs: ProtocolBugs{
7520 CECPQ1BadNewhopePart: true,
7521 },
7522 },
7523 flags: []string{"-cipher", "kCECPQ1"},
7524 shouldFail: true,
7525 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7526 })
7527}
7528
David Benjamin5c4e8572016-08-19 17:44:53 -04007529func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007530 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007531 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007532 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007533 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007534 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7535 Bugs: ProtocolBugs{
7536 // This is a 1234-bit prime number, generated
7537 // with:
7538 // openssl gendh 1234 | openssl asn1parse -i
7539 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7540 },
7541 },
David Benjamin9e68f192016-06-30 14:55:33 -04007542 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007543 })
7544 testCases = append(testCases, testCase{
7545 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007546 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007547 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007548 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007549 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7550 },
7551 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007552 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007553 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007554}
7555
David Benjaminc9ae27c2016-06-24 22:56:37 -04007556func addTLS13RecordTests() {
7557 testCases = append(testCases, testCase{
7558 name: "TLS13-RecordPadding",
7559 config: Config{
7560 MaxVersion: VersionTLS13,
7561 MinVersion: VersionTLS13,
7562 Bugs: ProtocolBugs{
7563 RecordPadding: 10,
7564 },
7565 },
7566 })
7567
7568 testCases = append(testCases, testCase{
7569 name: "TLS13-EmptyRecords",
7570 config: Config{
7571 MaxVersion: VersionTLS13,
7572 MinVersion: VersionTLS13,
7573 Bugs: ProtocolBugs{
7574 OmitRecordContents: true,
7575 },
7576 },
7577 shouldFail: true,
7578 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7579 })
7580
7581 testCases = append(testCases, testCase{
7582 name: "TLS13-OnlyPadding",
7583 config: Config{
7584 MaxVersion: VersionTLS13,
7585 MinVersion: VersionTLS13,
7586 Bugs: ProtocolBugs{
7587 OmitRecordContents: true,
7588 RecordPadding: 10,
7589 },
7590 },
7591 shouldFail: true,
7592 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7593 })
7594
7595 testCases = append(testCases, testCase{
7596 name: "TLS13-WrongOuterRecord",
7597 config: Config{
7598 MaxVersion: VersionTLS13,
7599 MinVersion: VersionTLS13,
7600 Bugs: ProtocolBugs{
7601 OuterRecordType: recordTypeHandshake,
7602 },
7603 },
7604 shouldFail: true,
7605 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7606 })
7607}
7608
Steven Valdez5b986082016-09-01 12:29:49 -04007609func addSessionTicketTests() {
7610 testCases = append(testCases, testCase{
7611 // In TLS 1.2 and below, empty NewSessionTicket messages
7612 // mean the server changed its mind on sending a ticket.
7613 name: "SendEmptySessionTicket",
7614 config: Config{
7615 MaxVersion: VersionTLS12,
7616 Bugs: ProtocolBugs{
7617 SendEmptySessionTicket: true,
7618 },
7619 },
7620 flags: []string{"-expect-no-session"},
7621 })
7622
7623 // Test that the server ignores unknown PSK modes.
7624 testCases = append(testCases, testCase{
7625 testType: serverTest,
7626 name: "TLS13-SendUnknownModeSessionTicket-Server",
7627 config: Config{
7628 MaxVersion: VersionTLS13,
7629 Bugs: ProtocolBugs{
7630 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7631 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7632 },
7633 },
7634 resumeSession: true,
7635 expectedResumeVersion: VersionTLS13,
7636 })
7637
7638 // Test that the server declines sessions with no matching key exchange mode.
7639 testCases = append(testCases, testCase{
7640 testType: serverTest,
7641 name: "TLS13-SendBadKEModeSessionTicket-Server",
7642 config: Config{
7643 MaxVersion: VersionTLS13,
7644 Bugs: ProtocolBugs{
7645 SendPSKKeyExchangeModes: []byte{0x1a},
7646 },
7647 },
7648 resumeSession: true,
7649 expectResumeRejected: true,
7650 })
7651
7652 // Test that the server declines sessions with no matching auth mode.
7653 testCases = append(testCases, testCase{
7654 testType: serverTest,
7655 name: "TLS13-SendBadAuthModeSessionTicket-Server",
7656 config: Config{
7657 MaxVersion: VersionTLS13,
7658 Bugs: ProtocolBugs{
7659 SendPSKAuthModes: []byte{0x1a},
7660 },
7661 },
7662 resumeSession: true,
7663 expectResumeRejected: true,
7664 })
7665
7666 // Test that the client ignores unknown PSK modes.
7667 testCases = append(testCases, testCase{
7668 testType: clientTest,
7669 name: "TLS13-SendUnknownModeSessionTicket-Client",
7670 config: Config{
7671 MaxVersion: VersionTLS13,
7672 Bugs: ProtocolBugs{
7673 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7674 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7675 },
7676 },
7677 resumeSession: true,
7678 expectedResumeVersion: VersionTLS13,
7679 })
7680
7681 // Test that the client ignores tickets with no matching key exchange mode.
7682 testCases = append(testCases, testCase{
7683 testType: clientTest,
7684 name: "TLS13-SendBadKEModeSessionTicket-Client",
7685 config: Config{
7686 MaxVersion: VersionTLS13,
7687 Bugs: ProtocolBugs{
7688 SendPSKKeyExchangeModes: []byte{0x1a},
7689 },
7690 },
7691 flags: []string{"-expect-no-session"},
7692 })
7693
7694 // Test that the client ignores tickets with no matching auth mode.
7695 testCases = append(testCases, testCase{
7696 testType: clientTest,
7697 name: "TLS13-SendBadAuthModeSessionTicket-Client",
7698 config: Config{
7699 MaxVersion: VersionTLS13,
7700 Bugs: ProtocolBugs{
7701 SendPSKAuthModes: []byte{0x1a},
7702 },
7703 },
7704 flags: []string{"-expect-no-session"},
7705 })
7706}
7707
David Benjamin82261be2016-07-07 14:32:50 -07007708func addChangeCipherSpecTests() {
7709 // Test missing ChangeCipherSpecs.
7710 testCases = append(testCases, testCase{
7711 name: "SkipChangeCipherSpec-Client",
7712 config: Config{
7713 MaxVersion: VersionTLS12,
7714 Bugs: ProtocolBugs{
7715 SkipChangeCipherSpec: true,
7716 },
7717 },
7718 shouldFail: true,
7719 expectedError: ":UNEXPECTED_RECORD:",
7720 })
7721 testCases = append(testCases, testCase{
7722 testType: serverTest,
7723 name: "SkipChangeCipherSpec-Server",
7724 config: Config{
7725 MaxVersion: VersionTLS12,
7726 Bugs: ProtocolBugs{
7727 SkipChangeCipherSpec: true,
7728 },
7729 },
7730 shouldFail: true,
7731 expectedError: ":UNEXPECTED_RECORD:",
7732 })
7733 testCases = append(testCases, testCase{
7734 testType: serverTest,
7735 name: "SkipChangeCipherSpec-Server-NPN",
7736 config: Config{
7737 MaxVersion: VersionTLS12,
7738 NextProtos: []string{"bar"},
7739 Bugs: ProtocolBugs{
7740 SkipChangeCipherSpec: true,
7741 },
7742 },
7743 flags: []string{
7744 "-advertise-npn", "\x03foo\x03bar\x03baz",
7745 },
7746 shouldFail: true,
7747 expectedError: ":UNEXPECTED_RECORD:",
7748 })
7749
7750 // Test synchronization between the handshake and ChangeCipherSpec.
7751 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7752 // rejected. Test both with and without handshake packing to handle both
7753 // when the partial post-CCS message is in its own record and when it is
7754 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007755 for _, packed := range []bool{false, true} {
7756 var suffix string
7757 if packed {
7758 suffix = "-Packed"
7759 }
7760
7761 testCases = append(testCases, testCase{
7762 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7763 config: Config{
7764 MaxVersion: VersionTLS12,
7765 Bugs: ProtocolBugs{
7766 FragmentAcrossChangeCipherSpec: true,
7767 PackHandshakeFlight: packed,
7768 },
7769 },
7770 shouldFail: true,
7771 expectedError: ":UNEXPECTED_RECORD:",
7772 })
7773 testCases = append(testCases, testCase{
7774 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7775 config: Config{
7776 MaxVersion: VersionTLS12,
7777 },
7778 resumeSession: true,
7779 resumeConfig: &Config{
7780 MaxVersion: VersionTLS12,
7781 Bugs: ProtocolBugs{
7782 FragmentAcrossChangeCipherSpec: true,
7783 PackHandshakeFlight: packed,
7784 },
7785 },
7786 shouldFail: true,
7787 expectedError: ":UNEXPECTED_RECORD:",
7788 })
7789 testCases = append(testCases, testCase{
7790 testType: serverTest,
7791 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7792 config: Config{
7793 MaxVersion: VersionTLS12,
7794 Bugs: ProtocolBugs{
7795 FragmentAcrossChangeCipherSpec: true,
7796 PackHandshakeFlight: packed,
7797 },
7798 },
7799 shouldFail: true,
7800 expectedError: ":UNEXPECTED_RECORD:",
7801 })
7802 testCases = append(testCases, testCase{
7803 testType: serverTest,
7804 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7805 config: Config{
7806 MaxVersion: VersionTLS12,
7807 },
7808 resumeSession: true,
7809 resumeConfig: &Config{
7810 MaxVersion: VersionTLS12,
7811 Bugs: ProtocolBugs{
7812 FragmentAcrossChangeCipherSpec: true,
7813 PackHandshakeFlight: packed,
7814 },
7815 },
7816 shouldFail: true,
7817 expectedError: ":UNEXPECTED_RECORD:",
7818 })
7819 testCases = append(testCases, testCase{
7820 testType: serverTest,
7821 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7822 config: Config{
7823 MaxVersion: VersionTLS12,
7824 NextProtos: []string{"bar"},
7825 Bugs: ProtocolBugs{
7826 FragmentAcrossChangeCipherSpec: true,
7827 PackHandshakeFlight: packed,
7828 },
7829 },
7830 flags: []string{
7831 "-advertise-npn", "\x03foo\x03bar\x03baz",
7832 },
7833 shouldFail: true,
7834 expectedError: ":UNEXPECTED_RECORD:",
7835 })
7836 }
7837
David Benjamin61672812016-07-14 23:10:43 -04007838 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7839 // messages in the handshake queue. Do this by testing the server
7840 // reading the client Finished, reversing the flight so Finished comes
7841 // first.
7842 testCases = append(testCases, testCase{
7843 protocol: dtls,
7844 testType: serverTest,
7845 name: "SendUnencryptedFinished-DTLS",
7846 config: Config{
7847 MaxVersion: VersionTLS12,
7848 Bugs: ProtocolBugs{
7849 SendUnencryptedFinished: true,
7850 ReverseHandshakeFragments: true,
7851 },
7852 },
7853 shouldFail: true,
7854 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7855 })
7856
Steven Valdez143e8b32016-07-11 13:19:03 -04007857 // Test synchronization between encryption changes and the handshake in
7858 // TLS 1.3, where ChangeCipherSpec is implicit.
7859 testCases = append(testCases, testCase{
7860 name: "PartialEncryptedExtensionsWithServerHello",
7861 config: Config{
7862 MaxVersion: VersionTLS13,
7863 Bugs: ProtocolBugs{
7864 PartialEncryptedExtensionsWithServerHello: true,
7865 },
7866 },
7867 shouldFail: true,
7868 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7869 })
7870 testCases = append(testCases, testCase{
7871 testType: serverTest,
7872 name: "PartialClientFinishedWithClientHello",
7873 config: Config{
7874 MaxVersion: VersionTLS13,
7875 Bugs: ProtocolBugs{
7876 PartialClientFinishedWithClientHello: true,
7877 },
7878 },
7879 shouldFail: true,
7880 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7881 })
7882
David Benjamin82261be2016-07-07 14:32:50 -07007883 // Test that early ChangeCipherSpecs are handled correctly.
7884 testCases = append(testCases, testCase{
7885 testType: serverTest,
7886 name: "EarlyChangeCipherSpec-server-1",
7887 config: Config{
7888 MaxVersion: VersionTLS12,
7889 Bugs: ProtocolBugs{
7890 EarlyChangeCipherSpec: 1,
7891 },
7892 },
7893 shouldFail: true,
7894 expectedError: ":UNEXPECTED_RECORD:",
7895 })
7896 testCases = append(testCases, testCase{
7897 testType: serverTest,
7898 name: "EarlyChangeCipherSpec-server-2",
7899 config: Config{
7900 MaxVersion: VersionTLS12,
7901 Bugs: ProtocolBugs{
7902 EarlyChangeCipherSpec: 2,
7903 },
7904 },
7905 shouldFail: true,
7906 expectedError: ":UNEXPECTED_RECORD:",
7907 })
7908 testCases = append(testCases, testCase{
7909 protocol: dtls,
7910 name: "StrayChangeCipherSpec",
7911 config: Config{
7912 // TODO(davidben): Once DTLS 1.3 exists, test
7913 // that stray ChangeCipherSpec messages are
7914 // rejected.
7915 MaxVersion: VersionTLS12,
7916 Bugs: ProtocolBugs{
7917 StrayChangeCipherSpec: true,
7918 },
7919 },
7920 })
7921
7922 // Test that the contents of ChangeCipherSpec are checked.
7923 testCases = append(testCases, testCase{
7924 name: "BadChangeCipherSpec-1",
7925 config: Config{
7926 MaxVersion: VersionTLS12,
7927 Bugs: ProtocolBugs{
7928 BadChangeCipherSpec: []byte{2},
7929 },
7930 },
7931 shouldFail: true,
7932 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7933 })
7934 testCases = append(testCases, testCase{
7935 name: "BadChangeCipherSpec-2",
7936 config: Config{
7937 MaxVersion: VersionTLS12,
7938 Bugs: ProtocolBugs{
7939 BadChangeCipherSpec: []byte{1, 1},
7940 },
7941 },
7942 shouldFail: true,
7943 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7944 })
7945 testCases = append(testCases, testCase{
7946 protocol: dtls,
7947 name: "BadChangeCipherSpec-DTLS-1",
7948 config: Config{
7949 MaxVersion: VersionTLS12,
7950 Bugs: ProtocolBugs{
7951 BadChangeCipherSpec: []byte{2},
7952 },
7953 },
7954 shouldFail: true,
7955 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7956 })
7957 testCases = append(testCases, testCase{
7958 protocol: dtls,
7959 name: "BadChangeCipherSpec-DTLS-2",
7960 config: Config{
7961 MaxVersion: VersionTLS12,
7962 Bugs: ProtocolBugs{
7963 BadChangeCipherSpec: []byte{1, 1},
7964 },
7965 },
7966 shouldFail: true,
7967 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7968 })
7969}
7970
David Benjamincd2c8062016-09-09 11:28:16 -04007971type perMessageTest struct {
7972 messageType uint8
7973 test testCase
7974}
7975
7976// makePerMessageTests returns a series of test templates which cover each
7977// message in the TLS handshake. These may be used with bugs like
7978// WrongMessageType to fully test a per-message bug.
7979func makePerMessageTests() []perMessageTest {
7980 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007981 for _, protocol := range []protocol{tls, dtls} {
7982 var suffix string
7983 if protocol == dtls {
7984 suffix = "-DTLS"
7985 }
7986
David Benjamincd2c8062016-09-09 11:28:16 -04007987 ret = append(ret, perMessageTest{
7988 messageType: typeClientHello,
7989 test: testCase{
7990 protocol: protocol,
7991 testType: serverTest,
7992 name: "ClientHello" + suffix,
7993 config: Config{
7994 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007995 },
7996 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007997 })
7998
7999 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008000 ret = append(ret, perMessageTest{
8001 messageType: typeHelloVerifyRequest,
8002 test: testCase{
8003 protocol: protocol,
8004 name: "HelloVerifyRequest" + suffix,
8005 config: Config{
8006 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008007 },
8008 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008009 })
8010 }
8011
David Benjamincd2c8062016-09-09 11:28:16 -04008012 ret = append(ret, perMessageTest{
8013 messageType: typeServerHello,
8014 test: testCase{
8015 protocol: protocol,
8016 name: "ServerHello" + 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: typeCertificate,
8025 test: testCase{
8026 protocol: protocol,
8027 name: "ServerCertificate" + suffix,
8028 config: Config{
8029 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008030 },
8031 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008032 })
8033
David Benjamincd2c8062016-09-09 11:28:16 -04008034 ret = append(ret, perMessageTest{
8035 messageType: typeCertificateStatus,
8036 test: testCase{
8037 protocol: protocol,
8038 name: "CertificateStatus" + suffix,
8039 config: Config{
8040 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008041 },
David Benjamincd2c8062016-09-09 11:28:16 -04008042 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008043 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008044 })
8045
David Benjamincd2c8062016-09-09 11:28:16 -04008046 ret = append(ret, perMessageTest{
8047 messageType: typeServerKeyExchange,
8048 test: testCase{
8049 protocol: protocol,
8050 name: "ServerKeyExchange" + suffix,
8051 config: Config{
8052 MaxVersion: VersionTLS12,
8053 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008054 },
8055 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008056 })
8057
David Benjamincd2c8062016-09-09 11:28:16 -04008058 ret = append(ret, perMessageTest{
8059 messageType: typeCertificateRequest,
8060 test: testCase{
8061 protocol: protocol,
8062 name: "CertificateRequest" + suffix,
8063 config: Config{
8064 MaxVersion: VersionTLS12,
8065 ClientAuth: RequireAnyClientCert,
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: typeServerHelloDone,
8072 test: testCase{
8073 protocol: protocol,
8074 name: "ServerHelloDone" + suffix,
8075 config: Config{
8076 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008077 },
8078 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008079 })
8080
David Benjamincd2c8062016-09-09 11:28:16 -04008081 ret = append(ret, perMessageTest{
8082 messageType: typeCertificate,
8083 test: testCase{
8084 testType: serverTest,
8085 protocol: protocol,
8086 name: "ClientCertificate" + suffix,
8087 config: Config{
8088 Certificates: []Certificate{rsaCertificate},
8089 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008090 },
David Benjamincd2c8062016-09-09 11:28:16 -04008091 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008092 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008093 })
8094
David Benjamincd2c8062016-09-09 11:28:16 -04008095 ret = append(ret, perMessageTest{
8096 messageType: typeCertificateVerify,
8097 test: testCase{
8098 testType: serverTest,
8099 protocol: protocol,
8100 name: "CertificateVerify" + suffix,
8101 config: Config{
8102 Certificates: []Certificate{rsaCertificate},
8103 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008104 },
David Benjamincd2c8062016-09-09 11:28:16 -04008105 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008106 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008107 })
8108
David Benjamincd2c8062016-09-09 11:28:16 -04008109 ret = append(ret, perMessageTest{
8110 messageType: typeClientKeyExchange,
8111 test: testCase{
8112 testType: serverTest,
8113 protocol: protocol,
8114 name: "ClientKeyExchange" + suffix,
8115 config: Config{
8116 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008117 },
8118 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008119 })
8120
8121 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008122 ret = append(ret, perMessageTest{
8123 messageType: typeNextProtocol,
8124 test: testCase{
8125 testType: serverTest,
8126 protocol: protocol,
8127 name: "NextProtocol" + suffix,
8128 config: Config{
8129 MaxVersion: VersionTLS12,
8130 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008131 },
David Benjamincd2c8062016-09-09 11:28:16 -04008132 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008133 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008134 })
8135
David Benjamincd2c8062016-09-09 11:28:16 -04008136 ret = append(ret, perMessageTest{
8137 messageType: typeChannelID,
8138 test: testCase{
8139 testType: serverTest,
8140 protocol: protocol,
8141 name: "ChannelID" + suffix,
8142 config: Config{
8143 MaxVersion: VersionTLS12,
8144 ChannelID: channelIDKey,
8145 },
8146 flags: []string{
8147 "-expect-channel-id",
8148 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008149 },
8150 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008151 })
8152 }
8153
David Benjamincd2c8062016-09-09 11:28:16 -04008154 ret = append(ret, perMessageTest{
8155 messageType: typeFinished,
8156 test: testCase{
8157 testType: serverTest,
8158 protocol: protocol,
8159 name: "ClientFinished" + 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: typeNewSessionTicket,
8168 test: testCase{
8169 protocol: protocol,
8170 name: "NewSessionTicket" + 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
David Benjamincd2c8062016-09-09 11:28:16 -04008177 ret = append(ret, perMessageTest{
8178 messageType: typeFinished,
8179 test: testCase{
8180 protocol: protocol,
8181 name: "ServerFinished" + suffix,
8182 config: Config{
8183 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008184 },
8185 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008186 })
8187
8188 }
David Benjamincd2c8062016-09-09 11:28:16 -04008189
8190 ret = append(ret, perMessageTest{
8191 messageType: typeClientHello,
8192 test: testCase{
8193 testType: serverTest,
8194 name: "TLS13-ClientHello",
8195 config: Config{
8196 MaxVersion: VersionTLS13,
8197 },
8198 },
8199 })
8200
8201 ret = append(ret, perMessageTest{
8202 messageType: typeServerHello,
8203 test: testCase{
8204 name: "TLS13-ServerHello",
8205 config: Config{
8206 MaxVersion: VersionTLS13,
8207 },
8208 },
8209 })
8210
8211 ret = append(ret, perMessageTest{
8212 messageType: typeEncryptedExtensions,
8213 test: testCase{
8214 name: "TLS13-EncryptedExtensions",
8215 config: Config{
8216 MaxVersion: VersionTLS13,
8217 },
8218 },
8219 })
8220
8221 ret = append(ret, perMessageTest{
8222 messageType: typeCertificateRequest,
8223 test: testCase{
8224 name: "TLS13-CertificateRequest",
8225 config: Config{
8226 MaxVersion: VersionTLS13,
8227 ClientAuth: RequireAnyClientCert,
8228 },
8229 },
8230 })
8231
8232 ret = append(ret, perMessageTest{
8233 messageType: typeCertificate,
8234 test: testCase{
8235 name: "TLS13-ServerCertificate",
8236 config: Config{
8237 MaxVersion: VersionTLS13,
8238 },
8239 },
8240 })
8241
8242 ret = append(ret, perMessageTest{
8243 messageType: typeCertificateVerify,
8244 test: testCase{
8245 name: "TLS13-ServerCertificateVerify",
8246 config: Config{
8247 MaxVersion: VersionTLS13,
8248 },
8249 },
8250 })
8251
8252 ret = append(ret, perMessageTest{
8253 messageType: typeFinished,
8254 test: testCase{
8255 name: "TLS13-ServerFinished",
8256 config: Config{
8257 MaxVersion: VersionTLS13,
8258 },
8259 },
8260 })
8261
8262 ret = append(ret, perMessageTest{
8263 messageType: typeCertificate,
8264 test: testCase{
8265 testType: serverTest,
8266 name: "TLS13-ClientCertificate",
8267 config: Config{
8268 Certificates: []Certificate{rsaCertificate},
8269 MaxVersion: VersionTLS13,
8270 },
8271 flags: []string{"-require-any-client-certificate"},
8272 },
8273 })
8274
8275 ret = append(ret, perMessageTest{
8276 messageType: typeCertificateVerify,
8277 test: testCase{
8278 testType: serverTest,
8279 name: "TLS13-ClientCertificateVerify",
8280 config: Config{
8281 Certificates: []Certificate{rsaCertificate},
8282 MaxVersion: VersionTLS13,
8283 },
8284 flags: []string{"-require-any-client-certificate"},
8285 },
8286 })
8287
8288 ret = append(ret, perMessageTest{
8289 messageType: typeFinished,
8290 test: testCase{
8291 testType: serverTest,
8292 name: "TLS13-ClientFinished",
8293 config: Config{
8294 MaxVersion: VersionTLS13,
8295 },
8296 },
8297 })
8298
8299 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008300}
8301
David Benjamincd2c8062016-09-09 11:28:16 -04008302func addWrongMessageTypeTests() {
8303 for _, t := range makePerMessageTests() {
8304 t.test.name = "WrongMessageType-" + t.test.name
8305 t.test.config.Bugs.SendWrongMessageType = t.messageType
8306 t.test.shouldFail = true
8307 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8308 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008309
David Benjamincd2c8062016-09-09 11:28:16 -04008310 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8311 // In TLS 1.3, a bad ServerHello means the client sends
8312 // an unencrypted alert while the server expects
8313 // encryption, so the alert is not readable by runner.
8314 t.test.expectedLocalError = "local error: bad record MAC"
8315 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008316
David Benjamincd2c8062016-09-09 11:28:16 -04008317 testCases = append(testCases, t.test)
8318 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008319}
8320
David Benjamin639846e2016-09-09 11:41:18 -04008321func addTrailingMessageDataTests() {
8322 for _, t := range makePerMessageTests() {
8323 t.test.name = "TrailingMessageData-" + t.test.name
8324 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8325 t.test.shouldFail = true
8326 t.test.expectedError = ":DECODE_ERROR:"
8327 t.test.expectedLocalError = "remote error: error decoding message"
8328
8329 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8330 // In TLS 1.3, a bad ServerHello means the client sends
8331 // an unencrypted alert while the server expects
8332 // encryption, so the alert is not readable by runner.
8333 t.test.expectedLocalError = "local error: bad record MAC"
8334 }
8335
8336 if t.messageType == typeFinished {
8337 // Bad Finished messages read as the verify data having
8338 // the wrong length.
8339 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8340 t.test.expectedLocalError = "remote error: error decrypting message"
8341 }
8342
8343 testCases = append(testCases, t.test)
8344 }
8345}
8346
Steven Valdez143e8b32016-07-11 13:19:03 -04008347func addTLS13HandshakeTests() {
8348 testCases = append(testCases, testCase{
8349 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008350 name: "NegotiatePSKResumption-TLS13",
8351 config: Config{
8352 MaxVersion: VersionTLS13,
8353 Bugs: ProtocolBugs{
8354 NegotiatePSKResumption: true,
8355 },
8356 },
8357 resumeSession: true,
8358 shouldFail: true,
8359 expectedError: ":UNEXPECTED_EXTENSION:",
8360 })
8361
8362 testCases = append(testCases, testCase{
8363 testType: clientTest,
8364 name: "OmitServerHelloSignatureAlgorithms",
8365 config: Config{
8366 MaxVersion: VersionTLS13,
8367 Bugs: ProtocolBugs{
8368 OmitServerHelloSignatureAlgorithms: true,
8369 },
8370 },
8371 shouldFail: true,
8372 expectedError: ":UNEXPECTED_EXTENSION:",
8373 })
8374
8375 testCases = append(testCases, testCase{
8376 testType: clientTest,
8377 name: "IncludeServerHelloSignatureAlgorithms",
8378 config: Config{
8379 MaxVersion: VersionTLS13,
8380 Bugs: ProtocolBugs{
8381 IncludeServerHelloSignatureAlgorithms: true,
8382 },
8383 },
8384 resumeSession: true,
8385 shouldFail: true,
8386 expectedError: ":UNEXPECTED_EXTENSION:",
8387 })
8388
8389 testCases = append(testCases, testCase{
8390 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008391 name: "MissingKeyShare-Client",
8392 config: Config{
8393 MaxVersion: VersionTLS13,
8394 Bugs: ProtocolBugs{
8395 MissingKeyShare: true,
8396 },
8397 },
8398 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008399 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008400 })
8401
8402 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008403 testType: serverTest,
8404 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008405 config: Config{
8406 MaxVersion: VersionTLS13,
8407 Bugs: ProtocolBugs{
8408 MissingKeyShare: true,
8409 },
8410 },
8411 shouldFail: true,
8412 expectedError: ":MISSING_KEY_SHARE:",
8413 })
8414
8415 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008416 testType: serverTest,
8417 name: "DuplicateKeyShares",
8418 config: Config{
8419 MaxVersion: VersionTLS13,
8420 Bugs: ProtocolBugs{
8421 DuplicateKeyShares: true,
8422 },
8423 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008424 shouldFail: true,
8425 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008426 })
8427
8428 testCases = append(testCases, testCase{
8429 testType: clientTest,
8430 name: "EmptyEncryptedExtensions",
8431 config: Config{
8432 MaxVersion: VersionTLS13,
8433 Bugs: ProtocolBugs{
8434 EmptyEncryptedExtensions: true,
8435 },
8436 },
8437 shouldFail: true,
8438 expectedLocalError: "remote error: error decoding message",
8439 })
8440
8441 testCases = append(testCases, testCase{
8442 testType: clientTest,
8443 name: "EncryptedExtensionsWithKeyShare",
8444 config: Config{
8445 MaxVersion: VersionTLS13,
8446 Bugs: ProtocolBugs{
8447 EncryptedExtensionsWithKeyShare: true,
8448 },
8449 },
8450 shouldFail: true,
8451 expectedLocalError: "remote error: unsupported extension",
8452 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008453
8454 testCases = append(testCases, testCase{
8455 testType: serverTest,
8456 name: "SendHelloRetryRequest",
8457 config: Config{
8458 MaxVersion: VersionTLS13,
8459 // Require a HelloRetryRequest for every curve.
8460 DefaultCurves: []CurveID{},
8461 },
8462 expectedCurveID: CurveX25519,
8463 })
8464
8465 testCases = append(testCases, testCase{
8466 testType: serverTest,
8467 name: "SendHelloRetryRequest-2",
8468 config: Config{
8469 MaxVersion: VersionTLS13,
8470 DefaultCurves: []CurveID{CurveP384},
8471 },
8472 // Although the ClientHello did not predict our preferred curve,
8473 // we always select it whether it is predicted or not.
8474 expectedCurveID: CurveX25519,
8475 })
8476
8477 testCases = append(testCases, testCase{
8478 name: "UnknownCurve-HelloRetryRequest",
8479 config: Config{
8480 MaxVersion: VersionTLS13,
8481 // P-384 requires HelloRetryRequest in BoringSSL.
8482 CurvePreferences: []CurveID{CurveP384},
8483 Bugs: ProtocolBugs{
8484 SendHelloRetryRequestCurve: bogusCurve,
8485 },
8486 },
8487 shouldFail: true,
8488 expectedError: ":WRONG_CURVE:",
8489 })
8490
8491 testCases = append(testCases, testCase{
8492 name: "DisabledCurve-HelloRetryRequest",
8493 config: Config{
8494 MaxVersion: VersionTLS13,
8495 CurvePreferences: []CurveID{CurveP256},
8496 Bugs: ProtocolBugs{
8497 IgnorePeerCurvePreferences: true,
8498 },
8499 },
8500 flags: []string{"-p384-only"},
8501 shouldFail: true,
8502 expectedError: ":WRONG_CURVE:",
8503 })
8504
8505 testCases = append(testCases, testCase{
8506 name: "UnnecessaryHelloRetryRequest",
8507 config: Config{
8508 MaxVersion: VersionTLS13,
8509 Bugs: ProtocolBugs{
8510 UnnecessaryHelloRetryRequest: true,
8511 },
8512 },
8513 shouldFail: true,
8514 expectedError: ":WRONG_CURVE:",
8515 })
8516
8517 testCases = append(testCases, testCase{
8518 name: "SecondHelloRetryRequest",
8519 config: Config{
8520 MaxVersion: VersionTLS13,
8521 // P-384 requires HelloRetryRequest in BoringSSL.
8522 CurvePreferences: []CurveID{CurveP384},
8523 Bugs: ProtocolBugs{
8524 SecondHelloRetryRequest: true,
8525 },
8526 },
8527 shouldFail: true,
8528 expectedError: ":UNEXPECTED_MESSAGE:",
8529 })
8530
8531 testCases = append(testCases, testCase{
8532 testType: serverTest,
8533 name: "SecondClientHelloMissingKeyShare",
8534 config: Config{
8535 MaxVersion: VersionTLS13,
8536 DefaultCurves: []CurveID{},
8537 Bugs: ProtocolBugs{
8538 SecondClientHelloMissingKeyShare: true,
8539 },
8540 },
8541 shouldFail: true,
8542 expectedError: ":MISSING_KEY_SHARE:",
8543 })
8544
8545 testCases = append(testCases, testCase{
8546 testType: serverTest,
8547 name: "SecondClientHelloWrongCurve",
8548 config: Config{
8549 MaxVersion: VersionTLS13,
8550 DefaultCurves: []CurveID{},
8551 Bugs: ProtocolBugs{
8552 MisinterpretHelloRetryRequestCurve: CurveP521,
8553 },
8554 },
8555 shouldFail: true,
8556 expectedError: ":WRONG_CURVE:",
8557 })
8558
8559 testCases = append(testCases, testCase{
8560 name: "HelloRetryRequestVersionMismatch",
8561 config: Config{
8562 MaxVersion: VersionTLS13,
8563 // P-384 requires HelloRetryRequest in BoringSSL.
8564 CurvePreferences: []CurveID{CurveP384},
8565 Bugs: ProtocolBugs{
8566 SendServerHelloVersion: 0x0305,
8567 },
8568 },
8569 shouldFail: true,
8570 expectedError: ":WRONG_VERSION_NUMBER:",
8571 })
8572
8573 testCases = append(testCases, testCase{
8574 name: "HelloRetryRequestCurveMismatch",
8575 config: Config{
8576 MaxVersion: VersionTLS13,
8577 // P-384 requires HelloRetryRequest in BoringSSL.
8578 CurvePreferences: []CurveID{CurveP384},
8579 Bugs: ProtocolBugs{
8580 // Send P-384 (correct) in the HelloRetryRequest.
8581 SendHelloRetryRequestCurve: CurveP384,
8582 // But send P-256 in the ServerHello.
8583 SendCurve: CurveP256,
8584 },
8585 },
8586 shouldFail: true,
8587 expectedError: ":WRONG_CURVE:",
8588 })
8589
8590 // Test the server selecting a curve that requires a HelloRetryRequest
8591 // without sending it.
8592 testCases = append(testCases, testCase{
8593 name: "SkipHelloRetryRequest",
8594 config: Config{
8595 MaxVersion: VersionTLS13,
8596 // P-384 requires HelloRetryRequest in BoringSSL.
8597 CurvePreferences: []CurveID{CurveP384},
8598 Bugs: ProtocolBugs{
8599 SkipHelloRetryRequest: true,
8600 },
8601 },
8602 shouldFail: true,
8603 expectedError: ":WRONG_CURVE:",
8604 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008605
8606 testCases = append(testCases, testCase{
8607 name: "TLS13-RequestContextInHandshake",
8608 config: Config{
8609 MaxVersion: VersionTLS13,
8610 MinVersion: VersionTLS13,
8611 ClientAuth: RequireAnyClientCert,
8612 Bugs: ProtocolBugs{
8613 SendRequestContext: []byte("request context"),
8614 },
8615 },
8616 flags: []string{
8617 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8618 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8619 },
8620 shouldFail: true,
8621 expectedError: ":DECODE_ERROR:",
8622 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008623
8624 testCases = append(testCases, testCase{
8625 testType: serverTest,
8626 name: "TLS13-TrailingKeyShareData",
8627 config: Config{
8628 MaxVersion: VersionTLS13,
8629 Bugs: ProtocolBugs{
8630 TrailingKeyShareData: true,
8631 },
8632 },
8633 shouldFail: true,
8634 expectedError: ":DECODE_ERROR:",
8635 })
David Benjamin7f78df42016-10-05 22:33:19 -04008636
8637 testCases = append(testCases, testCase{
8638 name: "TLS13-AlwaysSelectPSKIdentity",
8639 config: Config{
8640 MaxVersion: VersionTLS13,
8641 Bugs: ProtocolBugs{
8642 AlwaysSelectPSKIdentity: true,
8643 },
8644 },
8645 shouldFail: true,
8646 expectedError: ":UNEXPECTED_EXTENSION:",
8647 })
8648
8649 testCases = append(testCases, testCase{
8650 name: "TLS13-InvalidPSKIdentity",
8651 config: Config{
8652 MaxVersion: VersionTLS13,
8653 Bugs: ProtocolBugs{
8654 SelectPSKIdentityOnResume: 1,
8655 },
8656 },
8657 resumeSession: true,
8658 shouldFail: true,
8659 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
8660 })
David Benjamin1286bee2016-10-07 15:25:06 -04008661
8662 // Test that unknown NewSessionTicket extensions are tolerated.
8663 testCases = append(testCases, testCase{
8664 name: "TLS13-CustomTicketExtension",
8665 config: Config{
8666 MaxVersion: VersionTLS13,
8667 Bugs: ProtocolBugs{
8668 CustomTicketExtension: "1234",
8669 },
8670 },
8671 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008672}
8673
David Benjaminf3fbade2016-09-19 13:08:16 -04008674func addPeekTests() {
8675 // Test SSL_peek works, including on empty records.
8676 testCases = append(testCases, testCase{
8677 name: "Peek-Basic",
8678 sendEmptyRecords: 1,
8679 flags: []string{"-peek-then-read"},
8680 })
8681
8682 // Test SSL_peek can drive the initial handshake.
8683 testCases = append(testCases, testCase{
8684 name: "Peek-ImplicitHandshake",
8685 flags: []string{
8686 "-peek-then-read",
8687 "-implicit-handshake",
8688 },
8689 })
8690
8691 // Test SSL_peek can discover and drive a renegotiation.
8692 testCases = append(testCases, testCase{
8693 name: "Peek-Renegotiate",
8694 config: Config{
8695 MaxVersion: VersionTLS12,
8696 },
8697 renegotiate: 1,
8698 flags: []string{
8699 "-peek-then-read",
8700 "-renegotiate-freely",
8701 "-expect-total-renegotiations", "1",
8702 },
8703 })
8704
8705 // Test SSL_peek can discover a close_notify.
8706 testCases = append(testCases, testCase{
8707 name: "Peek-Shutdown",
8708 config: Config{
8709 Bugs: ProtocolBugs{
8710 ExpectCloseNotify: true,
8711 },
8712 },
8713 flags: []string{
8714 "-peek-then-read",
8715 "-check-close-notify",
8716 },
8717 })
8718
8719 // Test SSL_peek can discover an alert.
8720 testCases = append(testCases, testCase{
8721 name: "Peek-Alert",
8722 config: Config{
8723 Bugs: ProtocolBugs{
8724 SendSpuriousAlert: alertRecordOverflow,
8725 },
8726 },
8727 flags: []string{"-peek-then-read"},
8728 shouldFail: true,
8729 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8730 })
8731
8732 // Test SSL_peek can handle KeyUpdate.
8733 testCases = append(testCases, testCase{
8734 name: "Peek-KeyUpdate",
8735 config: Config{
8736 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04008737 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04008738 sendKeyUpdates: 1,
8739 keyUpdateRequest: keyUpdateNotRequested,
8740 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04008741 })
8742}
8743
Adam Langley7c803a62015-06-15 15:35:05 -07008744func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008745 defer wg.Done()
8746
8747 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008748 var err error
8749
8750 if *mallocTest < 0 {
8751 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008752 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008753 } else {
8754 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8755 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008756 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008757 if err != nil {
8758 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8759 }
8760 break
8761 }
8762 }
8763 }
Adam Langley95c29f32014-06-20 12:00:00 -07008764 statusChan <- statusMsg{test: test, err: err}
8765 }
8766}
8767
8768type statusMsg struct {
8769 test *testCase
8770 started bool
8771 err error
8772}
8773
David Benjamin5f237bc2015-02-11 17:14:15 -05008774func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008775 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008776
David Benjamin5f237bc2015-02-11 17:14:15 -05008777 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008778 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008779 if !*pipe {
8780 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008781 var erase string
8782 for i := 0; i < lineLen; i++ {
8783 erase += "\b \b"
8784 }
8785 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008786 }
8787
Adam Langley95c29f32014-06-20 12:00:00 -07008788 if msg.started {
8789 started++
8790 } else {
8791 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008792
8793 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008794 if msg.err == errUnimplemented {
8795 if *pipe {
8796 // Print each test instead of a status line.
8797 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8798 }
8799 unimplemented++
8800 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8801 } else {
8802 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8803 failed++
8804 testOutput.addResult(msg.test.name, "FAIL")
8805 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008806 } else {
8807 if *pipe {
8808 // Print each test instead of a status line.
8809 fmt.Printf("PASSED (%s)\n", msg.test.name)
8810 }
8811 testOutput.addResult(msg.test.name, "PASS")
8812 }
Adam Langley95c29f32014-06-20 12:00:00 -07008813 }
8814
David Benjamin5f237bc2015-02-11 17:14:15 -05008815 if !*pipe {
8816 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008817 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008818 lineLen = len(line)
8819 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008820 }
Adam Langley95c29f32014-06-20 12:00:00 -07008821 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008822
8823 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008824}
8825
8826func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008827 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008828 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008829 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008830
Adam Langley7c803a62015-06-15 15:35:05 -07008831 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008832 addCipherSuiteTests()
8833 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008834 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008835 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008836 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008837 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008838 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008839 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008840 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008841 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008842 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008843 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008844 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008845 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008846 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008847 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008848 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008849 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008850 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008851 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008852 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008853 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04008854 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008855 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008856 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008857 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008858 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008859 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008860 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008861 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008862
8863 var wg sync.WaitGroup
8864
Adam Langley7c803a62015-06-15 15:35:05 -07008865 statusChan := make(chan statusMsg, *numWorkers)
8866 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008867 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008868
EKRf71d7ed2016-08-06 13:25:12 -07008869 if len(*shimConfigFile) != 0 {
8870 encoded, err := ioutil.ReadFile(*shimConfigFile)
8871 if err != nil {
8872 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8873 os.Exit(1)
8874 }
8875
8876 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8877 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8878 os.Exit(1)
8879 }
8880 }
8881
David Benjamin025b3d32014-07-01 19:53:04 -04008882 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008883
Adam Langley7c803a62015-06-15 15:35:05 -07008884 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008885 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008886 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008887 }
8888
David Benjamin270f0a72016-03-17 14:41:36 -04008889 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008890 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008891 matched := true
8892 if len(*testToRun) != 0 {
8893 var err error
8894 matched, err = filepath.Match(*testToRun, testCases[i].name)
8895 if err != nil {
8896 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8897 os.Exit(1)
8898 }
8899 }
8900
EKRf71d7ed2016-08-06 13:25:12 -07008901 if !*includeDisabled {
8902 for pattern := range shimConfig.DisabledTests {
8903 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8904 if err != nil {
8905 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8906 os.Exit(1)
8907 }
8908
8909 if isDisabled {
8910 matched = false
8911 break
8912 }
8913 }
8914 }
8915
David Benjamin17e12922016-07-28 18:04:43 -04008916 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008917 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008918 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008919 }
8920 }
David Benjamin17e12922016-07-28 18:04:43 -04008921
David Benjamin270f0a72016-03-17 14:41:36 -04008922 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008923 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008924 os.Exit(1)
8925 }
Adam Langley95c29f32014-06-20 12:00:00 -07008926
8927 close(testChan)
8928 wg.Wait()
8929 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008930 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008931
8932 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008933
8934 if *jsonOutput != "" {
8935 if err := testOutput.writeTo(*jsonOutput); err != nil {
8936 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8937 }
8938 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008939
EKR842ae6c2016-07-27 09:22:05 +02008940 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8941 os.Exit(1)
8942 }
8943
8944 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008945 os.Exit(1)
8946 }
Adam Langley95c29f32014-06-20 12:00:00 -07008947}