blob: 8743d4988fea60b2ef4d880d82a92cb21b09c4df [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{
David Benjamin079b3942016-10-20 13:19:20 -04002302 // TLS 1.3 servers are expected to
2303 // always enable GREASE. TLS 1.3 is new,
2304 // so there is no existing ecosystem to
2305 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002306 ExpectGREASE: true,
2307 },
2308 },
David Benjamin65ac9972016-09-02 21:35:25 -04002309 },
Adam Langley7c803a62015-06-15 15:35:05 -07002310 }
Adam Langley7c803a62015-06-15 15:35:05 -07002311 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002312
2313 // Test that very large messages can be received.
2314 cert := rsaCertificate
2315 for i := 0; i < 50; i++ {
2316 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2317 }
2318 testCases = append(testCases, testCase{
2319 name: "LargeMessage",
2320 config: Config{
2321 Certificates: []Certificate{cert},
2322 },
2323 })
2324 testCases = append(testCases, testCase{
2325 protocol: dtls,
2326 name: "LargeMessage-DTLS",
2327 config: Config{
2328 Certificates: []Certificate{cert},
2329 },
2330 })
2331
2332 // They are rejected if the maximum certificate chain length is capped.
2333 testCases = append(testCases, testCase{
2334 name: "LargeMessage-Reject",
2335 config: Config{
2336 Certificates: []Certificate{cert},
2337 },
2338 flags: []string{"-max-cert-list", "16384"},
2339 shouldFail: true,
2340 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2341 })
2342 testCases = append(testCases, testCase{
2343 protocol: dtls,
2344 name: "LargeMessage-Reject-DTLS",
2345 config: Config{
2346 Certificates: []Certificate{cert},
2347 },
2348 flags: []string{"-max-cert-list", "16384"},
2349 shouldFail: true,
2350 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2351 })
Adam Langley7c803a62015-06-15 15:35:05 -07002352}
2353
Adam Langley95c29f32014-06-20 12:00:00 -07002354func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002355 const bogusCipher = 0xfe00
2356
Adam Langley95c29f32014-06-20 12:00:00 -07002357 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002358 const psk = "12345"
2359 const pskIdentity = "luggage combo"
2360
Adam Langley95c29f32014-06-20 12:00:00 -07002361 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002362 var certFile string
2363 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002364 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002365 cert = ecdsaP256Certificate
2366 certFile = ecdsaP256CertificateFile
2367 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002368 } else {
David Benjamin33863262016-07-08 17:20:12 -07002369 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002370 certFile = rsaCertificateFile
2371 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002372 }
2373
David Benjamin48cae082014-10-27 01:06:24 -04002374 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002375 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002376 flags = append(flags,
2377 "-psk", psk,
2378 "-psk-identity", pskIdentity)
2379 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002380 if hasComponent(suite.name, "NULL") {
2381 // NULL ciphers must be explicitly enabled.
2382 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2383 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002384 if hasComponent(suite.name, "CECPQ1") {
2385 // CECPQ1 ciphers must be explicitly enabled.
2386 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2387 }
David Benjamin881f1962016-08-10 18:29:12 -04002388 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2389 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2390 // for now.
2391 flags = append(flags, "-cipher", suite.name)
2392 }
David Benjamin48cae082014-10-27 01:06:24 -04002393
Adam Langley95c29f32014-06-20 12:00:00 -07002394 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002395 for _, protocol := range []protocol{tls, dtls} {
2396 var prefix string
2397 if protocol == dtls {
2398 if !ver.hasDTLS {
2399 continue
2400 }
2401 prefix = "D"
2402 }
Adam Langley95c29f32014-06-20 12:00:00 -07002403
David Benjamin0407e762016-06-17 16:41:18 -04002404 var shouldServerFail, shouldClientFail bool
2405 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2406 // BoringSSL clients accept ECDHE on SSLv3, but
2407 // a BoringSSL server will never select it
2408 // because the extension is missing.
2409 shouldServerFail = true
2410 }
2411 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2412 shouldClientFail = true
2413 shouldServerFail = true
2414 }
David Benjamin54c217c2016-07-13 12:35:25 -04002415 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002416 shouldClientFail = true
2417 shouldServerFail = true
2418 }
Steven Valdez803c77a2016-09-06 14:13:43 -04002419 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2420 shouldClientFail = true
2421 shouldServerFail = true
2422 }
David Benjamin0407e762016-06-17 16:41:18 -04002423 if !isDTLSCipher(suite.name) && protocol == dtls {
2424 shouldClientFail = true
2425 shouldServerFail = true
2426 }
David Benjamin4298d772015-12-19 00:18:25 -05002427
David Benjamin5ecb88b2016-10-04 17:51:35 -04002428 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002429 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002430 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002431 if shouldServerFail {
2432 expectedServerError = ":NO_SHARED_CIPHER:"
2433 }
2434 if shouldClientFail {
2435 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002436 // Configure the server to select ciphers as normal but
2437 // select an incompatible cipher in ServerHello.
2438 serverCipherSuites = nil
2439 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002440 }
David Benjamin025b3d32014-07-01 19:53:04 -04002441
David Benjamin6fd297b2014-08-11 18:43:38 -04002442 testCases = append(testCases, testCase{
2443 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002444 protocol: protocol,
2445
2446 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002447 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002448 MinVersion: ver.version,
2449 MaxVersion: ver.version,
2450 CipherSuites: []uint16{suite.id},
2451 Certificates: []Certificate{cert},
2452 PreSharedKey: []byte(psk),
2453 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002454 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002455 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002456 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002457 },
2458 certFile: certFile,
2459 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002460 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002461 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002462 shouldFail: shouldServerFail,
2463 expectedError: expectedServerError,
2464 })
2465
2466 testCases = append(testCases, testCase{
2467 testType: clientTest,
2468 protocol: protocol,
2469 name: prefix + ver.name + "-" + suite.name + "-client",
2470 config: Config{
2471 MinVersion: ver.version,
2472 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002473 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002474 Certificates: []Certificate{cert},
2475 PreSharedKey: []byte(psk),
2476 PreSharedKeyIdentity: pskIdentity,
2477 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002478 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002479 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002480 },
2481 },
2482 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002483 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002484 shouldFail: shouldClientFail,
2485 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002486 })
David Benjamin2c99d282015-09-01 10:23:00 -04002487
Nick Harper1fd39d82016-06-14 18:14:35 -07002488 if !shouldClientFail {
2489 // Ensure the maximum record size is accepted.
2490 testCases = append(testCases, testCase{
David Benjamin231a4752016-11-10 10:46:00 -05002491 protocol: protocol,
2492 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
Nick Harper1fd39d82016-06-14 18:14:35 -07002493 config: Config{
2494 MinVersion: ver.version,
2495 MaxVersion: ver.version,
2496 CipherSuites: []uint16{suite.id},
2497 Certificates: []Certificate{cert},
2498 PreSharedKey: []byte(psk),
2499 PreSharedKeyIdentity: pskIdentity,
2500 },
2501 flags: flags,
2502 messageLen: maxPlaintext,
2503 })
David Benjamin231a4752016-11-10 10:46:00 -05002504
2505 // Test bad records for all ciphers. Bad records are fatal in TLS
2506 // and ignored in DTLS.
2507 var shouldFail bool
2508 var expectedError string
2509 if protocol == tls {
2510 shouldFail = true
2511 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2512 }
2513
2514 testCases = append(testCases, testCase{
2515 protocol: protocol,
2516 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2517 config: Config{
2518 MinVersion: ver.version,
2519 MaxVersion: ver.version,
2520 CipherSuites: []uint16{suite.id},
2521 Certificates: []Certificate{cert},
2522 PreSharedKey: []byte(psk),
2523 PreSharedKeyIdentity: pskIdentity,
2524 },
2525 flags: flags,
2526 damageFirstWrite: true,
2527 messageLen: maxPlaintext,
2528 shouldFail: shouldFail,
2529 expectedError: expectedError,
2530 })
Nick Harper1fd39d82016-06-14 18:14:35 -07002531 }
2532 }
David Benjamin2c99d282015-09-01 10:23:00 -04002533 }
Adam Langley95c29f32014-06-20 12:00:00 -07002534 }
Adam Langleya7997f12015-05-14 17:38:50 -07002535
2536 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002537 name: "NoSharedCipher",
2538 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002539 MaxVersion: VersionTLS12,
2540 CipherSuites: []uint16{},
2541 },
2542 shouldFail: true,
2543 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2544 })
2545
2546 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002547 name: "NoSharedCipher-TLS13",
2548 config: Config{
2549 MaxVersion: VersionTLS13,
2550 CipherSuites: []uint16{},
2551 },
2552 shouldFail: true,
2553 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2554 })
2555
2556 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002557 name: "UnsupportedCipherSuite",
2558 config: Config{
2559 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002560 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002561 Bugs: ProtocolBugs{
2562 IgnorePeerCipherPreferences: true,
2563 },
2564 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002565 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002566 shouldFail: true,
2567 expectedError: ":WRONG_CIPHER_RETURNED:",
2568 })
2569
2570 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002571 name: "ServerHelloBogusCipher",
2572 config: Config{
2573 MaxVersion: VersionTLS12,
2574 Bugs: ProtocolBugs{
2575 SendCipherSuite: bogusCipher,
2576 },
2577 },
2578 shouldFail: true,
2579 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2580 })
2581 testCases = append(testCases, testCase{
2582 name: "ServerHelloBogusCipher-TLS13",
2583 config: Config{
2584 MaxVersion: VersionTLS13,
2585 Bugs: ProtocolBugs{
2586 SendCipherSuite: bogusCipher,
2587 },
2588 },
2589 shouldFail: true,
2590 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2591 })
2592
2593 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002594 name: "WeakDH",
2595 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002596 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002597 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2598 Bugs: ProtocolBugs{
2599 // This is a 1023-bit prime number, generated
2600 // with:
2601 // openssl gendh 1023 | openssl asn1parse -i
2602 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2603 },
2604 },
2605 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002606 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002607 })
Adam Langleycef75832015-09-03 14:51:12 -07002608
David Benjamincd24a392015-11-11 13:23:05 -08002609 testCases = append(testCases, testCase{
2610 name: "SillyDH",
2611 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002612 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002613 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2614 Bugs: ProtocolBugs{
2615 // This is a 4097-bit prime number, generated
2616 // with:
2617 // openssl gendh 4097 | openssl asn1parse -i
2618 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2619 },
2620 },
2621 shouldFail: true,
2622 expectedError: ":DH_P_TOO_LONG:",
2623 })
2624
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002625 // This test ensures that Diffie-Hellman public values are padded with
2626 // zeros so that they're the same length as the prime. This is to avoid
2627 // hitting a bug in yaSSL.
2628 testCases = append(testCases, testCase{
2629 testType: serverTest,
2630 name: "DHPublicValuePadded",
2631 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002632 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002633 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2634 Bugs: ProtocolBugs{
2635 RequireDHPublicValueLen: (1025 + 7) / 8,
2636 },
2637 },
2638 flags: []string{"-use-sparse-dh-prime"},
2639 })
David Benjamincd24a392015-11-11 13:23:05 -08002640
David Benjamin241ae832016-01-15 03:04:54 -05002641 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002642 testCases = append(testCases, testCase{
2643 testType: serverTest,
2644 name: "UnknownCipher",
2645 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002646 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002647 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002648 Bugs: ProtocolBugs{
2649 AdvertiseAllConfiguredCiphers: true,
2650 },
2651 },
2652 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002653
2654 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002655 testCases = append(testCases, testCase{
2656 testType: serverTest,
2657 name: "UnknownCipher-TLS13",
2658 config: Config{
2659 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002660 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002661 Bugs: ProtocolBugs{
2662 AdvertiseAllConfiguredCiphers: true,
2663 },
David Benjamin241ae832016-01-15 03:04:54 -05002664 },
2665 })
2666
David Benjamin78679342016-09-16 19:42:05 -04002667 // Test empty ECDHE_PSK identity hints work as expected.
2668 testCases = append(testCases, testCase{
2669 name: "EmptyECDHEPSKHint",
2670 config: Config{
2671 MaxVersion: VersionTLS12,
2672 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2673 PreSharedKey: []byte("secret"),
2674 },
2675 flags: []string{"-psk", "secret"},
2676 })
2677
2678 // Test empty PSK identity hints work as expected, even if an explicit
2679 // ServerKeyExchange is sent.
2680 testCases = append(testCases, testCase{
2681 name: "ExplicitEmptyPSKHint",
2682 config: Config{
2683 MaxVersion: VersionTLS12,
2684 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2685 PreSharedKey: []byte("secret"),
2686 Bugs: ProtocolBugs{
2687 AlwaysSendPreSharedKeyIdentityHint: true,
2688 },
2689 },
2690 flags: []string{"-psk", "secret"},
2691 })
2692
Adam Langleycef75832015-09-03 14:51:12 -07002693 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2694 // 1.1 specific cipher suite settings. A server is setup with the given
2695 // cipher lists and then a connection is made for each member of
2696 // expectations. The cipher suite that the server selects must match
2697 // the specified one.
2698 var versionSpecificCiphersTest = []struct {
2699 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2700 // expectations is a map from TLS version to cipher suite id.
2701 expectations map[uint16]uint16
2702 }{
2703 {
2704 // Test that the null case (where no version-specific ciphers are set)
2705 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002706 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2707 "", // no ciphers specifically for TLS ≥ 1.0
2708 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002709 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002710 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2711 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2712 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2713 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002714 },
2715 },
2716 {
2717 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2718 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002719 "DES-CBC3-SHA:AES128-SHA", // default
2720 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2721 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002722 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002723 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002724 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2725 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2726 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2727 },
2728 },
2729 {
2730 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2731 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002732 "DES-CBC3-SHA:AES128-SHA", // default
2733 "", // no ciphers specifically for TLS ≥ 1.0
2734 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002735 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002736 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2737 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002738 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2739 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2740 },
2741 },
2742 {
2743 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2744 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002745 "DES-CBC3-SHA:AES128-SHA", // default
2746 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2747 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002748 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002749 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002750 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2751 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2752 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2753 },
2754 },
2755 }
2756
2757 for i, test := range versionSpecificCiphersTest {
2758 for version, expectedCipherSuite := range test.expectations {
2759 flags := []string{"-cipher", test.ciphersDefault}
2760 if len(test.ciphersTLS10) > 0 {
2761 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2762 }
2763 if len(test.ciphersTLS11) > 0 {
2764 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2765 }
2766
2767 testCases = append(testCases, testCase{
2768 testType: serverTest,
2769 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2770 config: Config{
2771 MaxVersion: version,
2772 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002773 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 -07002774 },
2775 flags: flags,
2776 expectedCipher: expectedCipherSuite,
2777 })
2778 }
2779 }
Adam Langley95c29f32014-06-20 12:00:00 -07002780}
2781
2782func addBadECDSASignatureTests() {
2783 for badR := BadValue(1); badR < NumBadValues; badR++ {
2784 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002785 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002786 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2787 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002788 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002789 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002790 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002791 Bugs: ProtocolBugs{
2792 BadECDSAR: badR,
2793 BadECDSAS: badS,
2794 },
2795 },
2796 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002797 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002798 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002799 testCases = append(testCases, testCase{
2800 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2801 config: Config{
2802 MaxVersion: VersionTLS13,
2803 Certificates: []Certificate{ecdsaP256Certificate},
2804 Bugs: ProtocolBugs{
2805 BadECDSAR: badR,
2806 BadECDSAS: badS,
2807 },
2808 },
2809 shouldFail: true,
2810 expectedError: ":BAD_SIGNATURE:",
2811 })
Adam Langley95c29f32014-06-20 12:00:00 -07002812 }
2813 }
2814}
2815
Adam Langley80842bd2014-06-20 12:00:00 -07002816func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002817 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002818 name: "MaxCBCPadding",
2819 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002820 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002821 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2822 Bugs: ProtocolBugs{
2823 MaxPadding: true,
2824 },
2825 },
2826 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2827 })
David Benjamin025b3d32014-07-01 19:53:04 -04002828 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002829 name: "BadCBCPadding",
2830 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002831 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2833 Bugs: ProtocolBugs{
2834 PaddingFirstByteBad: true,
2835 },
2836 },
2837 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002838 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002839 })
2840 // OpenSSL previously had an issue where the first byte of padding in
2841 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002842 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002843 name: "BadCBCPadding255",
2844 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002845 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002846 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2847 Bugs: ProtocolBugs{
2848 MaxPadding: true,
2849 PaddingFirstByteBadIf255: true,
2850 },
2851 },
2852 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2853 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002854 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002855 })
2856}
2857
Kenny Root7fdeaf12014-08-05 15:23:37 -07002858func addCBCSplittingTests() {
2859 testCases = append(testCases, testCase{
2860 name: "CBCRecordSplitting",
2861 config: Config{
2862 MaxVersion: VersionTLS10,
2863 MinVersion: VersionTLS10,
2864 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2865 },
David Benjaminac8302a2015-09-01 17:18:15 -04002866 messageLen: -1, // read until EOF
2867 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002868 flags: []string{
2869 "-async",
2870 "-write-different-record-sizes",
2871 "-cbc-record-splitting",
2872 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002873 })
2874 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002875 name: "CBCRecordSplittingPartialWrite",
2876 config: Config{
2877 MaxVersion: VersionTLS10,
2878 MinVersion: VersionTLS10,
2879 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2880 },
2881 messageLen: -1, // read until EOF
2882 flags: []string{
2883 "-async",
2884 "-write-different-record-sizes",
2885 "-cbc-record-splitting",
2886 "-partial-write",
2887 },
2888 })
2889}
2890
David Benjamin636293b2014-07-08 17:59:18 -04002891func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002892 // Add a dummy cert pool to stress certificate authority parsing.
2893 // TODO(davidben): Add tests that those values parse out correctly.
2894 certPool := x509.NewCertPool()
2895 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2896 if err != nil {
2897 panic(err)
2898 }
2899 certPool.AddCert(cert)
2900
David Benjamin636293b2014-07-08 17:59:18 -04002901 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002902 testCases = append(testCases, testCase{
2903 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002904 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002905 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002906 MinVersion: ver.version,
2907 MaxVersion: ver.version,
2908 ClientAuth: RequireAnyClientCert,
2909 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002910 },
2911 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002912 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2913 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002914 },
2915 })
2916 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002917 testType: serverTest,
2918 name: ver.name + "-Server-ClientAuth-RSA",
2919 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002920 MinVersion: ver.version,
2921 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002922 Certificates: []Certificate{rsaCertificate},
2923 },
2924 flags: []string{"-require-any-client-certificate"},
2925 })
David Benjamine098ec22014-08-27 23:13:20 -04002926 if ver.version != VersionSSL30 {
2927 testCases = append(testCases, testCase{
2928 testType: serverTest,
2929 name: ver.name + "-Server-ClientAuth-ECDSA",
2930 config: Config{
2931 MinVersion: ver.version,
2932 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002933 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002934 },
2935 flags: []string{"-require-any-client-certificate"},
2936 })
2937 testCases = append(testCases, testCase{
2938 testType: clientTest,
2939 name: ver.name + "-Client-ClientAuth-ECDSA",
2940 config: Config{
2941 MinVersion: ver.version,
2942 MaxVersion: ver.version,
2943 ClientAuth: RequireAnyClientCert,
2944 ClientCAs: certPool,
2945 },
2946 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002947 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2948 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002949 },
2950 })
2951 }
Adam Langley37646832016-08-01 16:16:46 -07002952
2953 testCases = append(testCases, testCase{
2954 name: "NoClientCertificate-" + ver.name,
2955 config: Config{
2956 MinVersion: ver.version,
2957 MaxVersion: ver.version,
2958 ClientAuth: RequireAnyClientCert,
2959 },
2960 shouldFail: true,
2961 expectedLocalError: "client didn't provide a certificate",
2962 })
2963
2964 testCases = append(testCases, testCase{
2965 // Even if not configured to expect a certificate, OpenSSL will
2966 // return X509_V_OK as the verify_result.
2967 testType: serverTest,
2968 name: "NoClientCertificateRequested-Server-" + ver.name,
2969 config: Config{
2970 MinVersion: ver.version,
2971 MaxVersion: ver.version,
2972 },
2973 flags: []string{
2974 "-expect-verify-result",
2975 },
David Benjamin5d9ba812016-10-07 20:51:20 -04002976 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07002977 })
2978
2979 testCases = append(testCases, testCase{
2980 // If a client certificate is not provided, OpenSSL will still
2981 // return X509_V_OK as the verify_result.
2982 testType: serverTest,
2983 name: "NoClientCertificate-Server-" + ver.name,
2984 config: Config{
2985 MinVersion: ver.version,
2986 MaxVersion: ver.version,
2987 },
2988 flags: []string{
2989 "-expect-verify-result",
2990 "-verify-peer",
2991 },
David Benjamin5d9ba812016-10-07 20:51:20 -04002992 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07002993 })
2994
David Benjamin1db9e1b2016-10-07 20:51:43 -04002995 certificateRequired := "remote error: certificate required"
2996 if ver.version < VersionTLS13 {
2997 // Prior to TLS 1.3, the generic handshake_failure alert
2998 // was used.
2999 certificateRequired = "remote error: handshake failure"
3000 }
Adam Langley37646832016-08-01 16:16:46 -07003001 testCases = append(testCases, testCase{
3002 testType: serverTest,
3003 name: "RequireAnyClientCertificate-" + ver.name,
3004 config: Config{
3005 MinVersion: ver.version,
3006 MaxVersion: ver.version,
3007 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003008 flags: []string{"-require-any-client-certificate"},
3009 shouldFail: true,
3010 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3011 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003012 })
3013
3014 if ver.version != VersionSSL30 {
3015 testCases = append(testCases, testCase{
3016 testType: serverTest,
3017 name: "SkipClientCertificate-" + ver.name,
3018 config: Config{
3019 MinVersion: ver.version,
3020 MaxVersion: ver.version,
3021 Bugs: ProtocolBugs{
3022 SkipClientCertificate: true,
3023 },
3024 },
3025 // Setting SSL_VERIFY_PEER allows anonymous clients.
3026 flags: []string{"-verify-peer"},
3027 shouldFail: true,
3028 expectedError: ":UNEXPECTED_MESSAGE:",
3029 })
3030 }
David Benjamin636293b2014-07-08 17:59:18 -04003031 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003032
David Benjaminc032dfa2016-05-12 14:54:57 -04003033 // Client auth is only legal in certificate-based ciphers.
3034 testCases = append(testCases, testCase{
3035 testType: clientTest,
3036 name: "ClientAuth-PSK",
3037 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003038 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003039 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3040 PreSharedKey: []byte("secret"),
3041 ClientAuth: RequireAnyClientCert,
3042 },
3043 flags: []string{
3044 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3045 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3046 "-psk", "secret",
3047 },
3048 shouldFail: true,
3049 expectedError: ":UNEXPECTED_MESSAGE:",
3050 })
3051 testCases = append(testCases, testCase{
3052 testType: clientTest,
3053 name: "ClientAuth-ECDHE_PSK",
3054 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003055 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003056 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3057 PreSharedKey: []byte("secret"),
3058 ClientAuth: RequireAnyClientCert,
3059 },
3060 flags: []string{
3061 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3062 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3063 "-psk", "secret",
3064 },
3065 shouldFail: true,
3066 expectedError: ":UNEXPECTED_MESSAGE:",
3067 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003068
3069 // Regression test for a bug where the client CA list, if explicitly
3070 // set to NULL, was mis-encoded.
3071 testCases = append(testCases, testCase{
3072 testType: serverTest,
3073 name: "Null-Client-CA-List",
3074 config: Config{
3075 MaxVersion: VersionTLS12,
3076 Certificates: []Certificate{rsaCertificate},
3077 },
3078 flags: []string{
3079 "-require-any-client-certificate",
3080 "-use-null-client-ca-list",
3081 },
3082 })
David Benjamin636293b2014-07-08 17:59:18 -04003083}
3084
Adam Langley75712922014-10-10 16:23:43 -07003085func addExtendedMasterSecretTests() {
3086 const expectEMSFlag = "-expect-extended-master-secret"
3087
3088 for _, with := range []bool{false, true} {
3089 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003090 if with {
3091 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003092 }
3093
3094 for _, isClient := range []bool{false, true} {
3095 suffix := "-Server"
3096 testType := serverTest
3097 if isClient {
3098 suffix = "-Client"
3099 testType = clientTest
3100 }
3101
3102 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003103 // In TLS 1.3, the extension is irrelevant and
3104 // always reports as enabled.
3105 var flags []string
3106 if with || ver.version >= VersionTLS13 {
3107 flags = []string{expectEMSFlag}
3108 }
3109
Adam Langley75712922014-10-10 16:23:43 -07003110 test := testCase{
3111 testType: testType,
3112 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3113 config: Config{
3114 MinVersion: ver.version,
3115 MaxVersion: ver.version,
3116 Bugs: ProtocolBugs{
3117 NoExtendedMasterSecret: !with,
3118 RequireExtendedMasterSecret: with,
3119 },
3120 },
David Benjamin48cae082014-10-27 01:06:24 -04003121 flags: flags,
3122 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003123 }
3124 if test.shouldFail {
3125 test.expectedLocalError = "extended master secret required but not supported by peer"
3126 }
3127 testCases = append(testCases, test)
3128 }
3129 }
3130 }
3131
Adam Langleyba5934b2015-06-02 10:50:35 -07003132 for _, isClient := range []bool{false, true} {
3133 for _, supportedInFirstConnection := range []bool{false, true} {
3134 for _, supportedInResumeConnection := range []bool{false, true} {
3135 boolToWord := func(b bool) string {
3136 if b {
3137 return "Yes"
3138 }
3139 return "No"
3140 }
3141 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3142 if isClient {
3143 suffix += "Client"
3144 } else {
3145 suffix += "Server"
3146 }
3147
3148 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003149 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003150 Bugs: ProtocolBugs{
3151 RequireExtendedMasterSecret: true,
3152 },
3153 }
3154
3155 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003156 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003157 Bugs: ProtocolBugs{
3158 NoExtendedMasterSecret: true,
3159 },
3160 }
3161
3162 test := testCase{
3163 name: "ExtendedMasterSecret-" + suffix,
3164 resumeSession: true,
3165 }
3166
3167 if !isClient {
3168 test.testType = serverTest
3169 }
3170
3171 if supportedInFirstConnection {
3172 test.config = supportedConfig
3173 } else {
3174 test.config = noSupportConfig
3175 }
3176
3177 if supportedInResumeConnection {
3178 test.resumeConfig = &supportedConfig
3179 } else {
3180 test.resumeConfig = &noSupportConfig
3181 }
3182
3183 switch suffix {
3184 case "YesToYes-Client", "YesToYes-Server":
3185 // When a session is resumed, it should
3186 // still be aware that its master
3187 // secret was generated via EMS and
3188 // thus it's safe to use tls-unique.
3189 test.flags = []string{expectEMSFlag}
3190 case "NoToYes-Server":
3191 // If an original connection did not
3192 // contain EMS, but a resumption
3193 // handshake does, then a server should
3194 // not resume the session.
3195 test.expectResumeRejected = true
3196 case "YesToNo-Server":
3197 // Resuming an EMS session without the
3198 // EMS extension should cause the
3199 // server to abort the connection.
3200 test.shouldFail = true
3201 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3202 case "NoToYes-Client":
3203 // A client should abort a connection
3204 // where the server resumed a non-EMS
3205 // session but echoed the EMS
3206 // extension.
3207 test.shouldFail = true
3208 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3209 case "YesToNo-Client":
3210 // A client should abort a connection
3211 // where the server didn't echo EMS
3212 // when the session used it.
3213 test.shouldFail = true
3214 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3215 }
3216
3217 testCases = append(testCases, test)
3218 }
3219 }
3220 }
David Benjamin163c9562016-08-29 23:14:17 -04003221
3222 // Switching EMS on renegotiation is forbidden.
3223 testCases = append(testCases, testCase{
3224 name: "ExtendedMasterSecret-Renego-NoEMS",
3225 config: Config{
3226 MaxVersion: VersionTLS12,
3227 Bugs: ProtocolBugs{
3228 NoExtendedMasterSecret: true,
3229 NoExtendedMasterSecretOnRenegotiation: true,
3230 },
3231 },
3232 renegotiate: 1,
3233 flags: []string{
3234 "-renegotiate-freely",
3235 "-expect-total-renegotiations", "1",
3236 },
3237 })
3238
3239 testCases = append(testCases, testCase{
3240 name: "ExtendedMasterSecret-Renego-Upgrade",
3241 config: Config{
3242 MaxVersion: VersionTLS12,
3243 Bugs: ProtocolBugs{
3244 NoExtendedMasterSecret: true,
3245 },
3246 },
3247 renegotiate: 1,
3248 flags: []string{
3249 "-renegotiate-freely",
3250 "-expect-total-renegotiations", "1",
3251 },
3252 shouldFail: true,
3253 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3254 })
3255
3256 testCases = append(testCases, testCase{
3257 name: "ExtendedMasterSecret-Renego-Downgrade",
3258 config: Config{
3259 MaxVersion: VersionTLS12,
3260 Bugs: ProtocolBugs{
3261 NoExtendedMasterSecretOnRenegotiation: true,
3262 },
3263 },
3264 renegotiate: 1,
3265 flags: []string{
3266 "-renegotiate-freely",
3267 "-expect-total-renegotiations", "1",
3268 },
3269 shouldFail: true,
3270 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3271 })
Adam Langley75712922014-10-10 16:23:43 -07003272}
3273
David Benjamin582ba042016-07-07 12:33:25 -07003274type stateMachineTestConfig struct {
3275 protocol protocol
3276 async bool
3277 splitHandshake, packHandshakeFlight bool
3278}
3279
David Benjamin43ec06f2014-08-05 02:28:57 -04003280// Adds tests that try to cover the range of the handshake state machine, under
3281// various conditions. Some of these are redundant with other tests, but they
3282// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003283func addAllStateMachineCoverageTests() {
3284 for _, async := range []bool{false, true} {
3285 for _, protocol := range []protocol{tls, dtls} {
3286 addStateMachineCoverageTests(stateMachineTestConfig{
3287 protocol: protocol,
3288 async: async,
3289 })
3290 addStateMachineCoverageTests(stateMachineTestConfig{
3291 protocol: protocol,
3292 async: async,
3293 splitHandshake: true,
3294 })
3295 if protocol == tls {
3296 addStateMachineCoverageTests(stateMachineTestConfig{
3297 protocol: protocol,
3298 async: async,
3299 packHandshakeFlight: true,
3300 })
3301 }
3302 }
3303 }
3304}
3305
3306func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003307 var tests []testCase
3308
3309 // Basic handshake, with resumption. Client and server,
3310 // session ID and session ticket.
3311 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003312 name: "Basic-Client",
3313 config: Config{
3314 MaxVersion: VersionTLS12,
3315 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003316 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003317 // Ensure session tickets are used, not session IDs.
3318 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003319 })
3320 tests = append(tests, testCase{
3321 name: "Basic-Client-RenewTicket",
3322 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003323 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003324 Bugs: ProtocolBugs{
3325 RenewTicketOnResume: true,
3326 },
3327 },
David Benjamin46662482016-08-17 00:51:00 -04003328 flags: []string{"-expect-ticket-renewal"},
3329 resumeSession: true,
3330 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003331 })
3332 tests = append(tests, testCase{
3333 name: "Basic-Client-NoTicket",
3334 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003335 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003336 SessionTicketsDisabled: true,
3337 },
3338 resumeSession: true,
3339 })
3340 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003341 name: "Basic-Client-Implicit",
3342 config: Config{
3343 MaxVersion: VersionTLS12,
3344 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003345 flags: []string{"-implicit-handshake"},
3346 resumeSession: true,
3347 })
3348 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003349 testType: serverTest,
3350 name: "Basic-Server",
3351 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003352 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003353 Bugs: ProtocolBugs{
3354 RequireSessionTickets: true,
3355 },
3356 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003357 resumeSession: true,
3358 })
3359 tests = append(tests, testCase{
3360 testType: serverTest,
3361 name: "Basic-Server-NoTickets",
3362 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003363 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003364 SessionTicketsDisabled: true,
3365 },
3366 resumeSession: true,
3367 })
3368 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003369 testType: serverTest,
3370 name: "Basic-Server-Implicit",
3371 config: Config{
3372 MaxVersion: VersionTLS12,
3373 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003374 flags: []string{"-implicit-handshake"},
3375 resumeSession: true,
3376 })
3377 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003378 testType: serverTest,
3379 name: "Basic-Server-EarlyCallback",
3380 config: Config{
3381 MaxVersion: VersionTLS12,
3382 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003383 flags: []string{"-use-early-callback"},
3384 resumeSession: true,
3385 })
3386
Steven Valdez143e8b32016-07-11 13:19:03 -04003387 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003388 if config.protocol == tls {
3389 tests = append(tests, testCase{
3390 name: "TLS13-1RTT-Client",
3391 config: Config{
3392 MaxVersion: VersionTLS13,
3393 MinVersion: VersionTLS13,
3394 },
David Benjamin46662482016-08-17 00:51:00 -04003395 resumeSession: true,
3396 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003397 })
3398
3399 tests = append(tests, testCase{
3400 testType: serverTest,
3401 name: "TLS13-1RTT-Server",
3402 config: Config{
3403 MaxVersion: VersionTLS13,
3404 MinVersion: VersionTLS13,
3405 },
David Benjamin46662482016-08-17 00:51:00 -04003406 resumeSession: true,
3407 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003408 })
3409
3410 tests = append(tests, testCase{
3411 name: "TLS13-HelloRetryRequest-Client",
3412 config: Config{
3413 MaxVersion: VersionTLS13,
3414 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003415 // P-384 requires a HelloRetryRequest against BoringSSL's default
3416 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003417 CurvePreferences: []CurveID{CurveP384},
3418 Bugs: ProtocolBugs{
3419 ExpectMissingKeyShare: true,
3420 },
3421 },
3422 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3423 resumeSession: true,
3424 })
3425
3426 tests = append(tests, testCase{
3427 testType: serverTest,
3428 name: "TLS13-HelloRetryRequest-Server",
3429 config: Config{
3430 MaxVersion: VersionTLS13,
3431 MinVersion: VersionTLS13,
3432 // Require a HelloRetryRequest for every curve.
3433 DefaultCurves: []CurveID{},
3434 },
3435 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3436 resumeSession: true,
3437 })
3438 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003439
David Benjamin760b1dd2015-05-15 23:33:48 -04003440 // TLS client auth.
3441 tests = append(tests, testCase{
3442 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003443 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003444 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003445 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003446 ClientAuth: RequestClientCert,
3447 },
3448 })
3449 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003450 testType: serverTest,
3451 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003452 config: Config{
3453 MaxVersion: VersionTLS12,
3454 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003455 // Setting SSL_VERIFY_PEER allows anonymous clients.
3456 flags: []string{"-verify-peer"},
3457 })
David Benjamin582ba042016-07-07 12:33:25 -07003458 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003459 tests = append(tests, testCase{
3460 testType: clientTest,
3461 name: "ClientAuth-NoCertificate-Client-SSL3",
3462 config: Config{
3463 MaxVersion: VersionSSL30,
3464 ClientAuth: RequestClientCert,
3465 },
3466 })
3467 tests = append(tests, testCase{
3468 testType: serverTest,
3469 name: "ClientAuth-NoCertificate-Server-SSL3",
3470 config: Config{
3471 MaxVersion: VersionSSL30,
3472 },
3473 // Setting SSL_VERIFY_PEER allows anonymous clients.
3474 flags: []string{"-verify-peer"},
3475 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003476 tests = append(tests, testCase{
3477 testType: clientTest,
3478 name: "ClientAuth-NoCertificate-Client-TLS13",
3479 config: Config{
3480 MaxVersion: VersionTLS13,
3481 ClientAuth: RequestClientCert,
3482 },
3483 })
3484 tests = append(tests, testCase{
3485 testType: serverTest,
3486 name: "ClientAuth-NoCertificate-Server-TLS13",
3487 config: Config{
3488 MaxVersion: VersionTLS13,
3489 },
3490 // Setting SSL_VERIFY_PEER allows anonymous clients.
3491 flags: []string{"-verify-peer"},
3492 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003493 }
3494 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003495 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003496 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003497 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003498 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003499 ClientAuth: RequireAnyClientCert,
3500 },
3501 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003502 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3503 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003504 },
3505 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003506 tests = append(tests, testCase{
3507 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003508 name: "ClientAuth-RSA-Client-TLS13",
3509 config: Config{
3510 MaxVersion: VersionTLS13,
3511 ClientAuth: RequireAnyClientCert,
3512 },
3513 flags: []string{
3514 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3515 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3516 },
3517 })
3518 tests = append(tests, testCase{
3519 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003520 name: "ClientAuth-ECDSA-Client",
3521 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003522 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003523 ClientAuth: RequireAnyClientCert,
3524 },
3525 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003526 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3527 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003528 },
3529 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003530 tests = append(tests, testCase{
3531 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003532 name: "ClientAuth-ECDSA-Client-TLS13",
3533 config: Config{
3534 MaxVersion: VersionTLS13,
3535 ClientAuth: RequireAnyClientCert,
3536 },
3537 flags: []string{
3538 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3539 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3540 },
3541 })
3542 tests = append(tests, testCase{
3543 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003544 name: "ClientAuth-NoCertificate-OldCallback",
3545 config: Config{
3546 MaxVersion: VersionTLS12,
3547 ClientAuth: RequestClientCert,
3548 },
3549 flags: []string{"-use-old-client-cert-callback"},
3550 })
3551 tests = append(tests, testCase{
3552 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003553 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3554 config: Config{
3555 MaxVersion: VersionTLS13,
3556 ClientAuth: RequestClientCert,
3557 },
3558 flags: []string{"-use-old-client-cert-callback"},
3559 })
3560 tests = append(tests, testCase{
3561 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003562 name: "ClientAuth-OldCallback",
3563 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003564 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003565 ClientAuth: RequireAnyClientCert,
3566 },
3567 flags: []string{
3568 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3569 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3570 "-use-old-client-cert-callback",
3571 },
3572 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003573 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003574 testType: clientTest,
3575 name: "ClientAuth-OldCallback-TLS13",
3576 config: Config{
3577 MaxVersion: VersionTLS13,
3578 ClientAuth: RequireAnyClientCert,
3579 },
3580 flags: []string{
3581 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3582 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3583 "-use-old-client-cert-callback",
3584 },
3585 })
3586 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003587 testType: serverTest,
3588 name: "ClientAuth-Server",
3589 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003590 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003591 Certificates: []Certificate{rsaCertificate},
3592 },
3593 flags: []string{"-require-any-client-certificate"},
3594 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003595 tests = append(tests, testCase{
3596 testType: serverTest,
3597 name: "ClientAuth-Server-TLS13",
3598 config: Config{
3599 MaxVersion: VersionTLS13,
3600 Certificates: []Certificate{rsaCertificate},
3601 },
3602 flags: []string{"-require-any-client-certificate"},
3603 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003604
David Benjamin4c3ddf72016-06-29 18:13:53 -04003605 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003606 tests = append(tests, testCase{
3607 testType: serverTest,
3608 name: "Basic-Server-RSA",
3609 config: Config{
3610 MaxVersion: VersionTLS12,
3611 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3612 },
3613 flags: []string{
3614 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3615 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3616 },
3617 })
3618 tests = append(tests, testCase{
3619 testType: serverTest,
3620 name: "Basic-Server-ECDHE-RSA",
3621 config: Config{
3622 MaxVersion: VersionTLS12,
3623 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3624 },
3625 flags: []string{
3626 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3627 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3628 },
3629 })
3630 tests = append(tests, testCase{
3631 testType: serverTest,
3632 name: "Basic-Server-ECDHE-ECDSA",
3633 config: Config{
3634 MaxVersion: VersionTLS12,
3635 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3636 },
3637 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003638 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3639 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003640 },
3641 })
3642
David Benjamin760b1dd2015-05-15 23:33:48 -04003643 // No session ticket support; server doesn't send NewSessionTicket.
3644 tests = append(tests, testCase{
3645 name: "SessionTicketsDisabled-Client",
3646 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003647 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003648 SessionTicketsDisabled: true,
3649 },
3650 })
3651 tests = append(tests, testCase{
3652 testType: serverTest,
3653 name: "SessionTicketsDisabled-Server",
3654 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003655 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003656 SessionTicketsDisabled: true,
3657 },
3658 })
3659
3660 // Skip ServerKeyExchange in PSK key exchange if there's no
3661 // identity hint.
3662 tests = append(tests, testCase{
3663 name: "EmptyPSKHint-Client",
3664 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003665 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003666 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3667 PreSharedKey: []byte("secret"),
3668 },
3669 flags: []string{"-psk", "secret"},
3670 })
3671 tests = append(tests, testCase{
3672 testType: serverTest,
3673 name: "EmptyPSKHint-Server",
3674 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003675 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003676 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3677 PreSharedKey: []byte("secret"),
3678 },
3679 flags: []string{"-psk", "secret"},
3680 })
3681
David Benjamin4c3ddf72016-06-29 18:13:53 -04003682 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003683 tests = append(tests, testCase{
3684 testType: clientTest,
3685 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003686 config: Config{
3687 MaxVersion: VersionTLS12,
3688 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003689 flags: []string{
3690 "-enable-ocsp-stapling",
3691 "-expect-ocsp-response",
3692 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003693 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003694 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003695 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003696 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003697 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003698 testType: serverTest,
3699 name: "OCSPStapling-Server",
3700 config: Config{
3701 MaxVersion: VersionTLS12,
3702 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003703 expectedOCSPResponse: testOCSPResponse,
3704 flags: []string{
3705 "-ocsp-response",
3706 base64.StdEncoding.EncodeToString(testOCSPResponse),
3707 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003708 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003709 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003710 tests = append(tests, testCase{
3711 testType: clientTest,
3712 name: "OCSPStapling-Client-TLS13",
3713 config: Config{
3714 MaxVersion: VersionTLS13,
3715 },
3716 flags: []string{
3717 "-enable-ocsp-stapling",
3718 "-expect-ocsp-response",
3719 base64.StdEncoding.EncodeToString(testOCSPResponse),
3720 "-verify-peer",
3721 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003722 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003723 })
3724 tests = append(tests, testCase{
3725 testType: serverTest,
3726 name: "OCSPStapling-Server-TLS13",
3727 config: Config{
3728 MaxVersion: VersionTLS13,
3729 },
3730 expectedOCSPResponse: testOCSPResponse,
3731 flags: []string{
3732 "-ocsp-response",
3733 base64.StdEncoding.EncodeToString(testOCSPResponse),
3734 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003735 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003736 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003737
David Benjamin4c3ddf72016-06-29 18:13:53 -04003738 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003739 for _, vers := range tlsVersions {
3740 if config.protocol == dtls && !vers.hasDTLS {
3741 continue
3742 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003743 for _, testType := range []testType{clientTest, serverTest} {
3744 suffix := "-Client"
3745 if testType == serverTest {
3746 suffix = "-Server"
3747 }
3748 suffix += "-" + vers.name
3749
3750 flag := "-verify-peer"
3751 if testType == serverTest {
3752 flag = "-require-any-client-certificate"
3753 }
3754
3755 tests = append(tests, testCase{
3756 testType: testType,
3757 name: "CertificateVerificationSucceed" + suffix,
3758 config: Config{
3759 MaxVersion: vers.version,
3760 Certificates: []Certificate{rsaCertificate},
3761 },
3762 flags: []string{
3763 flag,
3764 "-expect-verify-result",
3765 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003766 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003767 })
3768 tests = append(tests, testCase{
3769 testType: testType,
3770 name: "CertificateVerificationFail" + suffix,
3771 config: Config{
3772 MaxVersion: vers.version,
3773 Certificates: []Certificate{rsaCertificate},
3774 },
3775 flags: []string{
3776 flag,
3777 "-verify-fail",
3778 },
3779 shouldFail: true,
3780 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3781 })
3782 }
3783
3784 // By default, the client is in a soft fail mode where the peer
3785 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003786 tests = append(tests, testCase{
3787 testType: clientTest,
3788 name: "CertificateVerificationSoftFail-" + vers.name,
3789 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003790 MaxVersion: vers.version,
3791 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003792 },
3793 flags: []string{
3794 "-verify-fail",
3795 "-expect-verify-result",
3796 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003797 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003798 })
3799 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003800
David Benjamin1d4f4c02016-07-26 18:03:08 -04003801 tests = append(tests, testCase{
3802 name: "ShimSendAlert",
3803 flags: []string{"-send-alert"},
3804 shimWritesFirst: true,
3805 shouldFail: true,
3806 expectedLocalError: "remote error: decompression failure",
3807 })
3808
David Benjamin582ba042016-07-07 12:33:25 -07003809 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003810 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003811 name: "Renegotiate-Client",
3812 config: Config{
3813 MaxVersion: VersionTLS12,
3814 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003815 renegotiate: 1,
3816 flags: []string{
3817 "-renegotiate-freely",
3818 "-expect-total-renegotiations", "1",
3819 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003820 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003821
David Benjamin47921102016-07-28 11:29:18 -04003822 tests = append(tests, testCase{
3823 name: "SendHalfHelloRequest",
3824 config: Config{
3825 MaxVersion: VersionTLS12,
3826 Bugs: ProtocolBugs{
3827 PackHelloRequestWithFinished: config.packHandshakeFlight,
3828 },
3829 },
3830 sendHalfHelloRequest: true,
3831 flags: []string{"-renegotiate-ignore"},
3832 shouldFail: true,
3833 expectedError: ":UNEXPECTED_RECORD:",
3834 })
3835
David Benjamin760b1dd2015-05-15 23:33:48 -04003836 // NPN on client and server; results in post-handshake message.
3837 tests = append(tests, testCase{
3838 name: "NPN-Client",
3839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003840 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003841 NextProtos: []string{"foo"},
3842 },
3843 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003844 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003845 expectedNextProto: "foo",
3846 expectedNextProtoType: npn,
3847 })
3848 tests = append(tests, testCase{
3849 testType: serverTest,
3850 name: "NPN-Server",
3851 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003852 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003853 NextProtos: []string{"bar"},
3854 },
3855 flags: []string{
3856 "-advertise-npn", "\x03foo\x03bar\x03baz",
3857 "-expect-next-proto", "bar",
3858 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003859 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003860 expectedNextProto: "bar",
3861 expectedNextProtoType: npn,
3862 })
3863
3864 // TODO(davidben): Add tests for when False Start doesn't trigger.
3865
3866 // Client does False Start and negotiates NPN.
3867 tests = append(tests, testCase{
3868 name: "FalseStart",
3869 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003870 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003871 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3872 NextProtos: []string{"foo"},
3873 Bugs: ProtocolBugs{
3874 ExpectFalseStart: true,
3875 },
3876 },
3877 flags: []string{
3878 "-false-start",
3879 "-select-next-proto", "foo",
3880 },
3881 shimWritesFirst: true,
3882 resumeSession: true,
3883 })
3884
3885 // Client does False Start and negotiates ALPN.
3886 tests = append(tests, testCase{
3887 name: "FalseStart-ALPN",
3888 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003889 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003890 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3891 NextProtos: []string{"foo"},
3892 Bugs: ProtocolBugs{
3893 ExpectFalseStart: true,
3894 },
3895 },
3896 flags: []string{
3897 "-false-start",
3898 "-advertise-alpn", "\x03foo",
3899 },
3900 shimWritesFirst: true,
3901 resumeSession: true,
3902 })
3903
3904 // Client does False Start but doesn't explicitly call
3905 // SSL_connect.
3906 tests = append(tests, testCase{
3907 name: "FalseStart-Implicit",
3908 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003909 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003910 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3911 NextProtos: []string{"foo"},
3912 },
3913 flags: []string{
3914 "-implicit-handshake",
3915 "-false-start",
3916 "-advertise-alpn", "\x03foo",
3917 },
3918 })
3919
3920 // False Start without session tickets.
3921 tests = append(tests, testCase{
3922 name: "FalseStart-SessionTicketsDisabled",
3923 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003924 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003925 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3926 NextProtos: []string{"foo"},
3927 SessionTicketsDisabled: true,
3928 Bugs: ProtocolBugs{
3929 ExpectFalseStart: true,
3930 },
3931 },
3932 flags: []string{
3933 "-false-start",
3934 "-select-next-proto", "foo",
3935 },
3936 shimWritesFirst: true,
3937 })
3938
Adam Langleydf759b52016-07-11 15:24:37 -07003939 tests = append(tests, testCase{
3940 name: "FalseStart-CECPQ1",
3941 config: Config{
3942 MaxVersion: VersionTLS12,
3943 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3944 NextProtos: []string{"foo"},
3945 Bugs: ProtocolBugs{
3946 ExpectFalseStart: true,
3947 },
3948 },
3949 flags: []string{
3950 "-false-start",
3951 "-cipher", "DEFAULT:kCECPQ1",
3952 "-select-next-proto", "foo",
3953 },
3954 shimWritesFirst: true,
3955 resumeSession: true,
3956 })
3957
David Benjamin760b1dd2015-05-15 23:33:48 -04003958 // Server parses a V2ClientHello.
3959 tests = append(tests, testCase{
3960 testType: serverTest,
3961 name: "SendV2ClientHello",
3962 config: Config{
3963 // Choose a cipher suite that does not involve
3964 // elliptic curves, so no extensions are
3965 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003966 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003967 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003968 Bugs: ProtocolBugs{
3969 SendV2ClientHello: true,
3970 },
3971 },
3972 })
3973
Nick Harper60a85cb2016-09-23 16:25:11 -07003974 // Test Channel ID
3975 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07003976 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07003977 continue
3978 }
3979 // Client sends a Channel ID.
3980 tests = append(tests, testCase{
3981 name: "ChannelID-Client-" + ver.name,
3982 config: Config{
3983 MaxVersion: ver.version,
3984 RequestChannelID: true,
3985 },
3986 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
3987 resumeSession: true,
3988 expectChannelID: true,
3989 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003990
Nick Harper60a85cb2016-09-23 16:25:11 -07003991 // Server accepts a Channel ID.
3992 tests = append(tests, testCase{
3993 testType: serverTest,
3994 name: "ChannelID-Server-" + ver.name,
3995 config: Config{
3996 MaxVersion: ver.version,
3997 ChannelID: channelIDKey,
3998 },
3999 flags: []string{
4000 "-expect-channel-id",
4001 base64.StdEncoding.EncodeToString(channelIDBytes),
4002 },
4003 resumeSession: true,
4004 expectChannelID: true,
4005 })
4006
4007 tests = append(tests, testCase{
4008 testType: serverTest,
4009 name: "InvalidChannelIDSignature-" + ver.name,
4010 config: Config{
4011 MaxVersion: ver.version,
4012 ChannelID: channelIDKey,
4013 Bugs: ProtocolBugs{
4014 InvalidChannelIDSignature: true,
4015 },
4016 },
4017 flags: []string{"-enable-channel-id"},
4018 shouldFail: true,
4019 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4020 })
4021 }
David Benjamin30789da2015-08-29 22:56:45 -04004022
David Benjaminf8fcdf32016-06-08 15:56:13 -04004023 // Channel ID and NPN at the same time, to ensure their relative
4024 // ordering is correct.
4025 tests = append(tests, testCase{
4026 name: "ChannelID-NPN-Client",
4027 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004028 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004029 RequestChannelID: true,
4030 NextProtos: []string{"foo"},
4031 },
4032 flags: []string{
4033 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4034 "-select-next-proto", "foo",
4035 },
4036 resumeSession: true,
4037 expectChannelID: true,
4038 expectedNextProto: "foo",
4039 expectedNextProtoType: npn,
4040 })
4041 tests = append(tests, testCase{
4042 testType: serverTest,
4043 name: "ChannelID-NPN-Server",
4044 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004045 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004046 ChannelID: channelIDKey,
4047 NextProtos: []string{"bar"},
4048 },
4049 flags: []string{
4050 "-expect-channel-id",
4051 base64.StdEncoding.EncodeToString(channelIDBytes),
4052 "-advertise-npn", "\x03foo\x03bar\x03baz",
4053 "-expect-next-proto", "bar",
4054 },
4055 resumeSession: true,
4056 expectChannelID: true,
4057 expectedNextProto: "bar",
4058 expectedNextProtoType: npn,
4059 })
4060
David Benjamin30789da2015-08-29 22:56:45 -04004061 // Bidirectional shutdown with the runner initiating.
4062 tests = append(tests, testCase{
4063 name: "Shutdown-Runner",
4064 config: Config{
4065 Bugs: ProtocolBugs{
4066 ExpectCloseNotify: true,
4067 },
4068 },
4069 flags: []string{"-check-close-notify"},
4070 })
4071
4072 // Bidirectional shutdown with the shim initiating. The runner,
4073 // in the meantime, sends garbage before the close_notify which
4074 // the shim must ignore.
4075 tests = append(tests, testCase{
4076 name: "Shutdown-Shim",
4077 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004078 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004079 Bugs: ProtocolBugs{
4080 ExpectCloseNotify: true,
4081 },
4082 },
4083 shimShutsDown: true,
4084 sendEmptyRecords: 1,
4085 sendWarningAlerts: 1,
4086 flags: []string{"-check-close-notify"},
4087 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004088 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004089 // TODO(davidben): DTLS 1.3 will want a similar thing for
4090 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004091 tests = append(tests, testCase{
4092 name: "SkipHelloVerifyRequest",
4093 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004094 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004095 Bugs: ProtocolBugs{
4096 SkipHelloVerifyRequest: true,
4097 },
4098 },
4099 })
4100 }
4101
David Benjamin760b1dd2015-05-15 23:33:48 -04004102 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004103 test.protocol = config.protocol
4104 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004105 test.name += "-DTLS"
4106 }
David Benjamin582ba042016-07-07 12:33:25 -07004107 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004108 test.name += "-Async"
4109 test.flags = append(test.flags, "-async")
4110 } else {
4111 test.name += "-Sync"
4112 }
David Benjamin582ba042016-07-07 12:33:25 -07004113 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004114 test.name += "-SplitHandshakeRecords"
4115 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004116 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004117 test.config.Bugs.MaxPacketLength = 256
4118 test.flags = append(test.flags, "-mtu", "256")
4119 }
4120 }
David Benjamin582ba042016-07-07 12:33:25 -07004121 if config.packHandshakeFlight {
4122 test.name += "-PackHandshakeFlight"
4123 test.config.Bugs.PackHandshakeFlight = true
4124 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004125 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004126 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004127}
4128
Adam Langley524e7172015-02-20 16:04:00 -08004129func addDDoSCallbackTests() {
4130 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004131 for _, resume := range []bool{false, true} {
4132 suffix := "Resume"
4133 if resume {
4134 suffix = "No" + suffix
4135 }
4136
4137 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004138 testType: serverTest,
4139 name: "Server-DDoS-OK-" + suffix,
4140 config: Config{
4141 MaxVersion: VersionTLS12,
4142 },
Adam Langley524e7172015-02-20 16:04:00 -08004143 flags: []string{"-install-ddos-callback"},
4144 resumeSession: resume,
4145 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004146 testCases = append(testCases, testCase{
4147 testType: serverTest,
4148 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4149 config: Config{
4150 MaxVersion: VersionTLS13,
4151 },
4152 flags: []string{"-install-ddos-callback"},
4153 resumeSession: resume,
4154 })
Adam Langley524e7172015-02-20 16:04:00 -08004155
4156 failFlag := "-fail-ddos-callback"
4157 if resume {
4158 failFlag = "-fail-second-ddos-callback"
4159 }
4160 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004161 testType: serverTest,
4162 name: "Server-DDoS-Reject-" + suffix,
4163 config: Config{
4164 MaxVersion: VersionTLS12,
4165 },
David Benjamin2c66e072016-09-16 15:58:00 -04004166 flags: []string{"-install-ddos-callback", failFlag},
4167 resumeSession: resume,
4168 shouldFail: true,
4169 expectedError: ":CONNECTION_REJECTED:",
4170 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004171 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004172 testCases = append(testCases, testCase{
4173 testType: serverTest,
4174 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4175 config: Config{
4176 MaxVersion: VersionTLS13,
4177 },
David Benjamin2c66e072016-09-16 15:58:00 -04004178 flags: []string{"-install-ddos-callback", failFlag},
4179 resumeSession: resume,
4180 shouldFail: true,
4181 expectedError: ":CONNECTION_REJECTED:",
4182 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004183 })
Adam Langley524e7172015-02-20 16:04:00 -08004184 }
4185}
4186
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004187func addVersionNegotiationTests() {
4188 for i, shimVers := range tlsVersions {
4189 // Assemble flags to disable all newer versions on the shim.
4190 var flags []string
4191 for _, vers := range tlsVersions[i+1:] {
4192 flags = append(flags, vers.flag)
4193 }
4194
Steven Valdezfdd10992016-09-15 16:27:05 -04004195 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004196 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004197 protocols := []protocol{tls}
4198 if runnerVers.hasDTLS && shimVers.hasDTLS {
4199 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004200 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004201 for _, protocol := range protocols {
4202 expectedVersion := shimVers.version
4203 if runnerVers.version < shimVers.version {
4204 expectedVersion = runnerVers.version
4205 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004206
David Benjamin8b8c0062014-11-23 02:47:52 -05004207 suffix := shimVers.name + "-" + runnerVers.name
4208 if protocol == dtls {
4209 suffix += "-DTLS"
4210 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004211
David Benjamin1eb367c2014-12-12 18:17:51 -05004212 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4213
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004214 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004215 clientVers := shimVers.version
4216 if clientVers > VersionTLS10 {
4217 clientVers = VersionTLS10
4218 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004219 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004220 serverVers := expectedVersion
4221 if expectedVersion >= VersionTLS13 {
4222 serverVers = VersionTLS10
4223 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004224 serverVers = versionToWire(serverVers, protocol == dtls)
4225
David Benjamin8b8c0062014-11-23 02:47:52 -05004226 testCases = append(testCases, testCase{
4227 protocol: protocol,
4228 testType: clientTest,
4229 name: "VersionNegotiation-Client-" + suffix,
4230 config: Config{
4231 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004232 Bugs: ProtocolBugs{
4233 ExpectInitialRecordVersion: clientVers,
4234 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004235 },
4236 flags: flags,
4237 expectedVersion: expectedVersion,
4238 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004239 testCases = append(testCases, testCase{
4240 protocol: protocol,
4241 testType: clientTest,
4242 name: "VersionNegotiation-Client2-" + suffix,
4243 config: Config{
4244 MaxVersion: runnerVers.version,
4245 Bugs: ProtocolBugs{
4246 ExpectInitialRecordVersion: clientVers,
4247 },
4248 },
4249 flags: []string{"-max-version", shimVersFlag},
4250 expectedVersion: expectedVersion,
4251 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004252
4253 testCases = append(testCases, testCase{
4254 protocol: protocol,
4255 testType: serverTest,
4256 name: "VersionNegotiation-Server-" + suffix,
4257 config: Config{
4258 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004259 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004260 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004261 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004262 },
4263 flags: flags,
4264 expectedVersion: expectedVersion,
4265 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004266 testCases = append(testCases, testCase{
4267 protocol: protocol,
4268 testType: serverTest,
4269 name: "VersionNegotiation-Server2-" + suffix,
4270 config: Config{
4271 MaxVersion: runnerVers.version,
4272 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004273 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004274 },
4275 },
4276 flags: []string{"-max-version", shimVersFlag},
4277 expectedVersion: expectedVersion,
4278 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004279 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004280 }
4281 }
David Benjamin95c69562016-06-29 18:15:03 -04004282
Steven Valdezfdd10992016-09-15 16:27:05 -04004283 // Test the version extension at all versions.
4284 for _, vers := range tlsVersions {
4285 protocols := []protocol{tls}
4286 if vers.hasDTLS {
4287 protocols = append(protocols, dtls)
4288 }
4289 for _, protocol := range protocols {
4290 suffix := vers.name
4291 if protocol == dtls {
4292 suffix += "-DTLS"
4293 }
4294
4295 wireVersion := versionToWire(vers.version, protocol == dtls)
4296 testCases = append(testCases, testCase{
4297 protocol: protocol,
4298 testType: serverTest,
4299 name: "VersionNegotiationExtension-" + suffix,
4300 config: Config{
4301 Bugs: ProtocolBugs{
4302 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4303 },
4304 },
4305 expectedVersion: vers.version,
4306 })
4307 }
4308
4309 }
4310
4311 // If all versions are unknown, negotiation fails.
4312 testCases = append(testCases, testCase{
4313 testType: serverTest,
4314 name: "NoSupportedVersions",
4315 config: Config{
4316 Bugs: ProtocolBugs{
4317 SendSupportedVersions: []uint16{0x1111},
4318 },
4319 },
4320 shouldFail: true,
4321 expectedError: ":UNSUPPORTED_PROTOCOL:",
4322 })
4323 testCases = append(testCases, testCase{
4324 protocol: dtls,
4325 testType: serverTest,
4326 name: "NoSupportedVersions-DTLS",
4327 config: Config{
4328 Bugs: ProtocolBugs{
4329 SendSupportedVersions: []uint16{0x1111},
4330 },
4331 },
4332 shouldFail: true,
4333 expectedError: ":UNSUPPORTED_PROTOCOL:",
4334 })
4335
4336 testCases = append(testCases, testCase{
4337 testType: serverTest,
4338 name: "ClientHelloVersionTooHigh",
4339 config: Config{
4340 MaxVersion: VersionTLS13,
4341 Bugs: ProtocolBugs{
4342 SendClientVersion: 0x0304,
4343 OmitSupportedVersions: true,
4344 },
4345 },
4346 expectedVersion: VersionTLS12,
4347 })
4348
4349 testCases = append(testCases, testCase{
4350 testType: serverTest,
4351 name: "ConflictingVersionNegotiation",
4352 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004353 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004354 SendClientVersion: VersionTLS12,
4355 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004356 },
4357 },
David Benjaminad75a662016-09-30 15:42:59 -04004358 // The extension takes precedence over the ClientHello version.
4359 expectedVersion: VersionTLS11,
4360 })
4361
4362 testCases = append(testCases, testCase{
4363 testType: serverTest,
4364 name: "ConflictingVersionNegotiation-2",
4365 config: Config{
4366 Bugs: ProtocolBugs{
4367 SendClientVersion: VersionTLS11,
4368 SendSupportedVersions: []uint16{VersionTLS12},
4369 },
4370 },
4371 // The extension takes precedence over the ClientHello version.
4372 expectedVersion: VersionTLS12,
4373 })
4374
4375 testCases = append(testCases, testCase{
4376 testType: serverTest,
4377 name: "RejectFinalTLS13",
4378 config: Config{
4379 Bugs: ProtocolBugs{
4380 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4381 },
4382 },
4383 // We currently implement a draft TLS 1.3 version. Ensure that
4384 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004385 expectedVersion: VersionTLS12,
4386 })
4387
Brian Smithf85d3232016-10-28 10:34:06 -10004388 // Test that the maximum version is selected regardless of the
4389 // client-sent order.
4390 testCases = append(testCases, testCase{
4391 testType: serverTest,
4392 name: "IgnoreClientVersionOrder",
4393 config: Config{
4394 Bugs: ProtocolBugs{
4395 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4396 },
4397 },
4398 expectedVersion: VersionTLS13,
4399 })
4400
David Benjamin95c69562016-06-29 18:15:03 -04004401 // Test for version tolerance.
4402 testCases = append(testCases, testCase{
4403 testType: serverTest,
4404 name: "MinorVersionTolerance",
4405 config: Config{
4406 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004407 SendClientVersion: 0x03ff,
4408 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004409 },
4410 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004411 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004412 })
4413 testCases = append(testCases, testCase{
4414 testType: serverTest,
4415 name: "MajorVersionTolerance",
4416 config: Config{
4417 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004418 SendClientVersion: 0x0400,
4419 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004420 },
4421 },
David Benjaminad75a662016-09-30 15:42:59 -04004422 // TLS 1.3 must be negotiated with the supported_versions
4423 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004424 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004425 })
David Benjaminad75a662016-09-30 15:42:59 -04004426 testCases = append(testCases, testCase{
4427 testType: serverTest,
4428 name: "VersionTolerance-TLS13",
4429 config: Config{
4430 Bugs: ProtocolBugs{
4431 // Although TLS 1.3 does not use
4432 // ClientHello.version, it still tolerates high
4433 // values there.
4434 SendClientVersion: 0x0400,
4435 },
4436 },
4437 expectedVersion: VersionTLS13,
4438 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004439
David Benjamin95c69562016-06-29 18:15:03 -04004440 testCases = append(testCases, testCase{
4441 protocol: dtls,
4442 testType: serverTest,
4443 name: "MinorVersionTolerance-DTLS",
4444 config: Config{
4445 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004446 SendClientVersion: 0xfe00,
4447 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004448 },
4449 },
4450 expectedVersion: VersionTLS12,
4451 })
4452 testCases = append(testCases, testCase{
4453 protocol: dtls,
4454 testType: serverTest,
4455 name: "MajorVersionTolerance-DTLS",
4456 config: Config{
4457 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004458 SendClientVersion: 0xfdff,
4459 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004460 },
4461 },
4462 expectedVersion: VersionTLS12,
4463 })
4464
4465 // Test that versions below 3.0 are rejected.
4466 testCases = append(testCases, testCase{
4467 testType: serverTest,
4468 name: "VersionTooLow",
4469 config: Config{
4470 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004471 SendClientVersion: 0x0200,
4472 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004473 },
4474 },
4475 shouldFail: true,
4476 expectedError: ":UNSUPPORTED_PROTOCOL:",
4477 })
4478 testCases = append(testCases, testCase{
4479 protocol: dtls,
4480 testType: serverTest,
4481 name: "VersionTooLow-DTLS",
4482 config: Config{
4483 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004484 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004485 },
4486 },
4487 shouldFail: true,
4488 expectedError: ":UNSUPPORTED_PROTOCOL:",
4489 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004490
David Benjamin2dc02042016-09-19 19:57:37 -04004491 testCases = append(testCases, testCase{
4492 name: "ServerBogusVersion",
4493 config: Config{
4494 Bugs: ProtocolBugs{
4495 SendServerHelloVersion: 0x1234,
4496 },
4497 },
4498 shouldFail: true,
4499 expectedError: ":UNSUPPORTED_PROTOCOL:",
4500 })
4501
David Benjamin1f61f0d2016-07-10 12:20:35 -04004502 // Test TLS 1.3's downgrade signal.
4503 testCases = append(testCases, testCase{
4504 name: "Downgrade-TLS12-Client",
4505 config: Config{
4506 Bugs: ProtocolBugs{
4507 NegotiateVersion: VersionTLS12,
4508 },
4509 },
David Benjamin592b5322016-09-30 15:15:01 -04004510 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004511 // TODO(davidben): This test should fail once TLS 1.3 is final
4512 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004513 })
4514 testCases = append(testCases, testCase{
4515 testType: serverTest,
4516 name: "Downgrade-TLS12-Server",
4517 config: Config{
4518 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004519 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004520 },
4521 },
David Benjamin592b5322016-09-30 15:15:01 -04004522 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004523 // TODO(davidben): This test should fail once TLS 1.3 is final
4524 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004525 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004526}
4527
David Benjaminaccb4542014-12-12 23:44:33 -05004528func addMinimumVersionTests() {
4529 for i, shimVers := range tlsVersions {
4530 // Assemble flags to disable all older versions on the shim.
4531 var flags []string
4532 for _, vers := range tlsVersions[:i] {
4533 flags = append(flags, vers.flag)
4534 }
4535
4536 for _, runnerVers := range tlsVersions {
4537 protocols := []protocol{tls}
4538 if runnerVers.hasDTLS && shimVers.hasDTLS {
4539 protocols = append(protocols, dtls)
4540 }
4541 for _, protocol := range protocols {
4542 suffix := shimVers.name + "-" + runnerVers.name
4543 if protocol == dtls {
4544 suffix += "-DTLS"
4545 }
4546 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4547
David Benjaminaccb4542014-12-12 23:44:33 -05004548 var expectedVersion uint16
4549 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004550 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004551 if runnerVers.version >= shimVers.version {
4552 expectedVersion = runnerVers.version
4553 } else {
4554 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004555 expectedError = ":UNSUPPORTED_PROTOCOL:"
4556 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004557 }
4558
4559 testCases = append(testCases, testCase{
4560 protocol: protocol,
4561 testType: clientTest,
4562 name: "MinimumVersion-Client-" + suffix,
4563 config: Config{
4564 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004565 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004566 // Ensure the server does not decline to
4567 // select a version (versions extension) or
4568 // cipher (some ciphers depend on versions).
4569 NegotiateVersion: runnerVers.version,
4570 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004571 },
David Benjaminaccb4542014-12-12 23:44:33 -05004572 },
David Benjamin87909c02014-12-13 01:55:01 -05004573 flags: flags,
4574 expectedVersion: expectedVersion,
4575 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004576 expectedError: expectedError,
4577 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004578 })
4579 testCases = append(testCases, testCase{
4580 protocol: protocol,
4581 testType: clientTest,
4582 name: "MinimumVersion-Client2-" + suffix,
4583 config: Config{
4584 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004585 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004586 // Ensure the server does not decline to
4587 // select a version (versions extension) or
4588 // cipher (some ciphers depend on versions).
4589 NegotiateVersion: runnerVers.version,
4590 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004591 },
David Benjaminaccb4542014-12-12 23:44:33 -05004592 },
David Benjamin87909c02014-12-13 01:55:01 -05004593 flags: []string{"-min-version", shimVersFlag},
4594 expectedVersion: expectedVersion,
4595 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004596 expectedError: expectedError,
4597 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004598 })
4599
4600 testCases = append(testCases, testCase{
4601 protocol: protocol,
4602 testType: serverTest,
4603 name: "MinimumVersion-Server-" + suffix,
4604 config: Config{
4605 MaxVersion: runnerVers.version,
4606 },
David Benjamin87909c02014-12-13 01:55:01 -05004607 flags: flags,
4608 expectedVersion: expectedVersion,
4609 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004610 expectedError: expectedError,
4611 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004612 })
4613 testCases = append(testCases, testCase{
4614 protocol: protocol,
4615 testType: serverTest,
4616 name: "MinimumVersion-Server2-" + suffix,
4617 config: Config{
4618 MaxVersion: runnerVers.version,
4619 },
David Benjamin87909c02014-12-13 01:55:01 -05004620 flags: []string{"-min-version", shimVersFlag},
4621 expectedVersion: expectedVersion,
4622 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004623 expectedError: expectedError,
4624 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004625 })
4626 }
4627 }
4628 }
4629}
4630
David Benjamine78bfde2014-09-06 12:45:15 -04004631func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004632 // TODO(davidben): Extensions, where applicable, all move their server
4633 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4634 // tests for both. Also test interaction with 0-RTT when implemented.
4635
David Benjamin97d17d92016-07-14 16:12:00 -04004636 // Repeat extensions tests all versions except SSL 3.0.
4637 for _, ver := range tlsVersions {
4638 if ver.version == VersionSSL30 {
4639 continue
4640 }
4641
David Benjamin97d17d92016-07-14 16:12:00 -04004642 // Test that duplicate extensions are rejected.
4643 testCases = append(testCases, testCase{
4644 testType: clientTest,
4645 name: "DuplicateExtensionClient-" + ver.name,
4646 config: Config{
4647 MaxVersion: ver.version,
4648 Bugs: ProtocolBugs{
4649 DuplicateExtension: true,
4650 },
David Benjamine78bfde2014-09-06 12:45:15 -04004651 },
David Benjamin97d17d92016-07-14 16:12:00 -04004652 shouldFail: true,
4653 expectedLocalError: "remote error: error decoding message",
4654 })
4655 testCases = append(testCases, testCase{
4656 testType: serverTest,
4657 name: "DuplicateExtensionServer-" + ver.name,
4658 config: Config{
4659 MaxVersion: ver.version,
4660 Bugs: ProtocolBugs{
4661 DuplicateExtension: true,
4662 },
David Benjamine78bfde2014-09-06 12:45:15 -04004663 },
David Benjamin97d17d92016-07-14 16:12:00 -04004664 shouldFail: true,
4665 expectedLocalError: "remote error: error decoding message",
4666 })
4667
4668 // Test SNI.
4669 testCases = append(testCases, testCase{
4670 testType: clientTest,
4671 name: "ServerNameExtensionClient-" + ver.name,
4672 config: Config{
4673 MaxVersion: ver.version,
4674 Bugs: ProtocolBugs{
4675 ExpectServerName: "example.com",
4676 },
David Benjamine78bfde2014-09-06 12:45:15 -04004677 },
David Benjamin97d17d92016-07-14 16:12:00 -04004678 flags: []string{"-host-name", "example.com"},
4679 })
4680 testCases = append(testCases, testCase{
4681 testType: clientTest,
4682 name: "ServerNameExtensionClientMismatch-" + ver.name,
4683 config: Config{
4684 MaxVersion: ver.version,
4685 Bugs: ProtocolBugs{
4686 ExpectServerName: "mismatch.com",
4687 },
David Benjamine78bfde2014-09-06 12:45:15 -04004688 },
David Benjamin97d17d92016-07-14 16:12:00 -04004689 flags: []string{"-host-name", "example.com"},
4690 shouldFail: true,
4691 expectedLocalError: "tls: unexpected server name",
4692 })
4693 testCases = append(testCases, testCase{
4694 testType: clientTest,
4695 name: "ServerNameExtensionClientMissing-" + ver.name,
4696 config: Config{
4697 MaxVersion: ver.version,
4698 Bugs: ProtocolBugs{
4699 ExpectServerName: "missing.com",
4700 },
David Benjamine78bfde2014-09-06 12:45:15 -04004701 },
David Benjamin97d17d92016-07-14 16:12:00 -04004702 shouldFail: true,
4703 expectedLocalError: "tls: unexpected server name",
4704 })
4705 testCases = append(testCases, testCase{
4706 testType: serverTest,
4707 name: "ServerNameExtensionServer-" + ver.name,
4708 config: Config{
4709 MaxVersion: ver.version,
4710 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004711 },
David Benjamin97d17d92016-07-14 16:12:00 -04004712 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004713 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004714 })
4715
4716 // Test ALPN.
4717 testCases = append(testCases, testCase{
4718 testType: clientTest,
4719 name: "ALPNClient-" + ver.name,
4720 config: Config{
4721 MaxVersion: ver.version,
4722 NextProtos: []string{"foo"},
4723 },
4724 flags: []string{
4725 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4726 "-expect-alpn", "foo",
4727 },
4728 expectedNextProto: "foo",
4729 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004730 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004731 })
4732 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004733 testType: clientTest,
4734 name: "ALPNClient-Mismatch-" + ver.name,
4735 config: Config{
4736 MaxVersion: ver.version,
4737 Bugs: ProtocolBugs{
4738 SendALPN: "baz",
4739 },
4740 },
4741 flags: []string{
4742 "-advertise-alpn", "\x03foo\x03bar",
4743 },
4744 shouldFail: true,
4745 expectedError: ":INVALID_ALPN_PROTOCOL:",
4746 expectedLocalError: "remote error: illegal parameter",
4747 })
4748 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004749 testType: serverTest,
4750 name: "ALPNServer-" + ver.name,
4751 config: Config{
4752 MaxVersion: ver.version,
4753 NextProtos: []string{"foo", "bar", "baz"},
4754 },
4755 flags: []string{
4756 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4757 "-select-alpn", "foo",
4758 },
4759 expectedNextProto: "foo",
4760 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004761 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004762 })
4763 testCases = append(testCases, testCase{
4764 testType: serverTest,
4765 name: "ALPNServer-Decline-" + ver.name,
4766 config: Config{
4767 MaxVersion: ver.version,
4768 NextProtos: []string{"foo", "bar", "baz"},
4769 },
4770 flags: []string{"-decline-alpn"},
4771 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004772 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004773 })
4774
David Benjamin25fe85b2016-08-09 20:00:32 -04004775 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4776 // called once.
4777 testCases = append(testCases, testCase{
4778 testType: serverTest,
4779 name: "ALPNServer-Async-" + ver.name,
4780 config: Config{
4781 MaxVersion: ver.version,
4782 NextProtos: []string{"foo", "bar", "baz"},
4783 },
4784 flags: []string{
4785 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4786 "-select-alpn", "foo",
4787 "-async",
4788 },
4789 expectedNextProto: "foo",
4790 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004791 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004792 })
4793
David Benjamin97d17d92016-07-14 16:12:00 -04004794 var emptyString string
4795 testCases = append(testCases, testCase{
4796 testType: clientTest,
4797 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4798 config: Config{
4799 MaxVersion: ver.version,
4800 NextProtos: []string{""},
4801 Bugs: ProtocolBugs{
4802 // A server returning an empty ALPN protocol
4803 // should be rejected.
4804 ALPNProtocol: &emptyString,
4805 },
4806 },
4807 flags: []string{
4808 "-advertise-alpn", "\x03foo",
4809 },
4810 shouldFail: true,
4811 expectedError: ":PARSE_TLSEXT:",
4812 })
4813 testCases = append(testCases, testCase{
4814 testType: serverTest,
4815 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4816 config: Config{
4817 MaxVersion: ver.version,
4818 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004819 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004820 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004821 },
David Benjamin97d17d92016-07-14 16:12:00 -04004822 flags: []string{
4823 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004824 },
David Benjamin97d17d92016-07-14 16:12:00 -04004825 shouldFail: true,
4826 expectedError: ":PARSE_TLSEXT:",
4827 })
4828
4829 // Test NPN and the interaction with ALPN.
4830 if ver.version < VersionTLS13 {
4831 // Test that the server prefers ALPN over NPN.
4832 testCases = append(testCases, testCase{
4833 testType: serverTest,
4834 name: "ALPNServer-Preferred-" + ver.name,
4835 config: Config{
4836 MaxVersion: ver.version,
4837 NextProtos: []string{"foo", "bar", "baz"},
4838 },
4839 flags: []string{
4840 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4841 "-select-alpn", "foo",
4842 "-advertise-npn", "\x03foo\x03bar\x03baz",
4843 },
4844 expectedNextProto: "foo",
4845 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004846 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004847 })
4848 testCases = append(testCases, testCase{
4849 testType: serverTest,
4850 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4851 config: Config{
4852 MaxVersion: ver.version,
4853 NextProtos: []string{"foo", "bar", "baz"},
4854 Bugs: ProtocolBugs{
4855 SwapNPNAndALPN: true,
4856 },
4857 },
4858 flags: []string{
4859 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4860 "-select-alpn", "foo",
4861 "-advertise-npn", "\x03foo\x03bar\x03baz",
4862 },
4863 expectedNextProto: "foo",
4864 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004865 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004866 })
4867
4868 // Test that negotiating both NPN and ALPN is forbidden.
4869 testCases = append(testCases, testCase{
4870 name: "NegotiateALPNAndNPN-" + ver.name,
4871 config: Config{
4872 MaxVersion: ver.version,
4873 NextProtos: []string{"foo", "bar", "baz"},
4874 Bugs: ProtocolBugs{
4875 NegotiateALPNAndNPN: true,
4876 },
4877 },
4878 flags: []string{
4879 "-advertise-alpn", "\x03foo",
4880 "-select-next-proto", "foo",
4881 },
4882 shouldFail: true,
4883 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4884 })
4885 testCases = append(testCases, testCase{
4886 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4887 config: Config{
4888 MaxVersion: ver.version,
4889 NextProtos: []string{"foo", "bar", "baz"},
4890 Bugs: ProtocolBugs{
4891 NegotiateALPNAndNPN: true,
4892 SwapNPNAndALPN: true,
4893 },
4894 },
4895 flags: []string{
4896 "-advertise-alpn", "\x03foo",
4897 "-select-next-proto", "foo",
4898 },
4899 shouldFail: true,
4900 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4901 })
4902
4903 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4904 testCases = append(testCases, testCase{
4905 name: "DisableNPN-" + ver.name,
4906 config: Config{
4907 MaxVersion: ver.version,
4908 NextProtos: []string{"foo"},
4909 },
4910 flags: []string{
4911 "-select-next-proto", "foo",
4912 "-disable-npn",
4913 },
4914 expectNoNextProto: true,
4915 })
4916 }
4917
4918 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004919
4920 // Resume with a corrupt ticket.
4921 testCases = append(testCases, testCase{
4922 testType: serverTest,
4923 name: "CorruptTicket-" + ver.name,
4924 config: Config{
4925 MaxVersion: ver.version,
4926 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004927 FilterTicket: func(in []byte) ([]byte, error) {
4928 in[len(in)-1] ^= 1
4929 return in, nil
4930 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004931 },
4932 },
4933 resumeSession: true,
4934 expectResumeRejected: true,
4935 })
4936 // Test the ticket callback, with and without renewal.
4937 testCases = append(testCases, testCase{
4938 testType: serverTest,
4939 name: "TicketCallback-" + ver.name,
4940 config: Config{
4941 MaxVersion: ver.version,
4942 },
4943 resumeSession: true,
4944 flags: []string{"-use-ticket-callback"},
4945 })
4946 testCases = append(testCases, testCase{
4947 testType: serverTest,
4948 name: "TicketCallback-Renew-" + ver.name,
4949 config: Config{
4950 MaxVersion: ver.version,
4951 Bugs: ProtocolBugs{
4952 ExpectNewTicket: true,
4953 },
4954 },
4955 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4956 resumeSession: true,
4957 })
4958
4959 // Test that the ticket callback is only called once when everything before
4960 // it in the ClientHello is asynchronous. This corrupts the ticket so
4961 // certificate selection callbacks run.
4962 testCases = append(testCases, testCase{
4963 testType: serverTest,
4964 name: "TicketCallback-SingleCall-" + ver.name,
4965 config: Config{
4966 MaxVersion: ver.version,
4967 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004968 FilterTicket: func(in []byte) ([]byte, error) {
4969 in[len(in)-1] ^= 1
4970 return in, nil
4971 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004972 },
4973 },
4974 resumeSession: true,
4975 expectResumeRejected: true,
4976 flags: []string{
4977 "-use-ticket-callback",
4978 "-async",
4979 },
4980 })
4981
4982 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004983 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004984 testCases = append(testCases, testCase{
4985 testType: serverTest,
4986 name: "OversizedSessionId-" + ver.name,
4987 config: Config{
4988 MaxVersion: ver.version,
4989 Bugs: ProtocolBugs{
4990 OversizedSessionId: true,
4991 },
4992 },
4993 resumeSession: true,
4994 shouldFail: true,
4995 expectedError: ":DECODE_ERROR:",
4996 })
4997 }
4998
4999 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5000 // are ignored.
5001 if ver.hasDTLS {
5002 testCases = append(testCases, testCase{
5003 protocol: dtls,
5004 name: "SRTP-Client-" + ver.name,
5005 config: Config{
5006 MaxVersion: ver.version,
5007 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5008 },
5009 flags: []string{
5010 "-srtp-profiles",
5011 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5012 },
5013 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5014 })
5015 testCases = append(testCases, testCase{
5016 protocol: dtls,
5017 testType: serverTest,
5018 name: "SRTP-Server-" + ver.name,
5019 config: Config{
5020 MaxVersion: ver.version,
5021 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5022 },
5023 flags: []string{
5024 "-srtp-profiles",
5025 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5026 },
5027 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5028 })
5029 // Test that the MKI is ignored.
5030 testCases = append(testCases, testCase{
5031 protocol: dtls,
5032 testType: serverTest,
5033 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5034 config: Config{
5035 MaxVersion: ver.version,
5036 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5037 Bugs: ProtocolBugs{
5038 SRTPMasterKeyIdentifer: "bogus",
5039 },
5040 },
5041 flags: []string{
5042 "-srtp-profiles",
5043 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5044 },
5045 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5046 })
5047 // Test that SRTP isn't negotiated on the server if there were
5048 // no matching profiles.
5049 testCases = append(testCases, testCase{
5050 protocol: dtls,
5051 testType: serverTest,
5052 name: "SRTP-Server-NoMatch-" + ver.name,
5053 config: Config{
5054 MaxVersion: ver.version,
5055 SRTPProtectionProfiles: []uint16{100, 101, 102},
5056 },
5057 flags: []string{
5058 "-srtp-profiles",
5059 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5060 },
5061 expectedSRTPProtectionProfile: 0,
5062 })
5063 // Test that the server returning an invalid SRTP profile is
5064 // flagged as an error by the client.
5065 testCases = append(testCases, testCase{
5066 protocol: dtls,
5067 name: "SRTP-Client-NoMatch-" + ver.name,
5068 config: Config{
5069 MaxVersion: ver.version,
5070 Bugs: ProtocolBugs{
5071 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5072 },
5073 },
5074 flags: []string{
5075 "-srtp-profiles",
5076 "SRTP_AES128_CM_SHA1_80",
5077 },
5078 shouldFail: true,
5079 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5080 })
5081 }
5082
5083 // Test SCT list.
5084 testCases = append(testCases, testCase{
5085 name: "SignedCertificateTimestampList-Client-" + ver.name,
5086 testType: clientTest,
5087 config: Config{
5088 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005089 },
David Benjamin97d17d92016-07-14 16:12:00 -04005090 flags: []string{
5091 "-enable-signed-cert-timestamps",
5092 "-expect-signed-cert-timestamps",
5093 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005094 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005095 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005096 })
David Benjamindaa88502016-10-04 16:32:16 -04005097
5098 // The SCT extension did not specify that it must only be sent on resumption as it
5099 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005100 testCases = append(testCases, testCase{
5101 name: "SendSCTListOnResume-" + ver.name,
5102 config: Config{
5103 MaxVersion: ver.version,
5104 Bugs: ProtocolBugs{
5105 SendSCTListOnResume: []byte("bogus"),
5106 },
David Benjamind98452d2015-06-16 14:16:23 -04005107 },
David Benjamin97d17d92016-07-14 16:12:00 -04005108 flags: []string{
5109 "-enable-signed-cert-timestamps",
5110 "-expect-signed-cert-timestamps",
5111 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005112 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005113 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005114 })
David Benjamindaa88502016-10-04 16:32:16 -04005115
David Benjamin97d17d92016-07-14 16:12:00 -04005116 testCases = append(testCases, testCase{
5117 name: "SignedCertificateTimestampList-Server-" + ver.name,
5118 testType: serverTest,
5119 config: Config{
5120 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005121 },
David Benjamin97d17d92016-07-14 16:12:00 -04005122 flags: []string{
5123 "-signed-cert-timestamps",
5124 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005125 },
David Benjamin97d17d92016-07-14 16:12:00 -04005126 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005127 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005128 })
5129 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005130
Paul Lietar4fac72e2015-09-09 13:44:55 +01005131 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005132 testType: clientTest,
5133 name: "ClientHelloPadding",
5134 config: Config{
5135 Bugs: ProtocolBugs{
5136 RequireClientHelloSize: 512,
5137 },
5138 },
5139 // This hostname just needs to be long enough to push the
5140 // ClientHello into F5's danger zone between 256 and 511 bytes
5141 // long.
5142 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5143 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005144
5145 // Extensions should not function in SSL 3.0.
5146 testCases = append(testCases, testCase{
5147 testType: serverTest,
5148 name: "SSLv3Extensions-NoALPN",
5149 config: Config{
5150 MaxVersion: VersionSSL30,
5151 NextProtos: []string{"foo", "bar", "baz"},
5152 },
5153 flags: []string{
5154 "-select-alpn", "foo",
5155 },
5156 expectNoNextProto: true,
5157 })
5158
5159 // Test session tickets separately as they follow a different codepath.
5160 testCases = append(testCases, testCase{
5161 testType: serverTest,
5162 name: "SSLv3Extensions-NoTickets",
5163 config: Config{
5164 MaxVersion: VersionSSL30,
5165 Bugs: ProtocolBugs{
5166 // Historically, session tickets in SSL 3.0
5167 // failed in different ways depending on whether
5168 // the client supported renegotiation_info.
5169 NoRenegotiationInfo: true,
5170 },
5171 },
5172 resumeSession: true,
5173 })
5174 testCases = append(testCases, testCase{
5175 testType: serverTest,
5176 name: "SSLv3Extensions-NoTickets2",
5177 config: Config{
5178 MaxVersion: VersionSSL30,
5179 },
5180 resumeSession: true,
5181 })
5182
5183 // But SSL 3.0 does send and process renegotiation_info.
5184 testCases = append(testCases, testCase{
5185 testType: serverTest,
5186 name: "SSLv3Extensions-RenegotiationInfo",
5187 config: Config{
5188 MaxVersion: VersionSSL30,
5189 Bugs: ProtocolBugs{
5190 RequireRenegotiationInfo: true,
5191 },
5192 },
5193 })
5194 testCases = append(testCases, testCase{
5195 testType: serverTest,
5196 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5197 config: Config{
5198 MaxVersion: VersionSSL30,
5199 Bugs: ProtocolBugs{
5200 NoRenegotiationInfo: true,
5201 SendRenegotiationSCSV: true,
5202 RequireRenegotiationInfo: true,
5203 },
5204 },
5205 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005206
5207 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5208 // in ServerHello.
5209 testCases = append(testCases, testCase{
5210 name: "NPN-Forbidden-TLS13",
5211 config: Config{
5212 MaxVersion: VersionTLS13,
5213 NextProtos: []string{"foo"},
5214 Bugs: ProtocolBugs{
5215 NegotiateNPNAtAllVersions: true,
5216 },
5217 },
5218 flags: []string{"-select-next-proto", "foo"},
5219 shouldFail: true,
5220 expectedError: ":ERROR_PARSING_EXTENSION:",
5221 })
5222 testCases = append(testCases, testCase{
5223 name: "EMS-Forbidden-TLS13",
5224 config: Config{
5225 MaxVersion: VersionTLS13,
5226 Bugs: ProtocolBugs{
5227 NegotiateEMSAtAllVersions: true,
5228 },
5229 },
5230 shouldFail: true,
5231 expectedError: ":ERROR_PARSING_EXTENSION:",
5232 })
5233 testCases = append(testCases, testCase{
5234 name: "RenegotiationInfo-Forbidden-TLS13",
5235 config: Config{
5236 MaxVersion: VersionTLS13,
5237 Bugs: ProtocolBugs{
5238 NegotiateRenegotiationInfoAtAllVersions: true,
5239 },
5240 },
5241 shouldFail: true,
5242 expectedError: ":ERROR_PARSING_EXTENSION:",
5243 })
5244 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005245 name: "Ticket-Forbidden-TLS13",
5246 config: Config{
5247 MaxVersion: VersionTLS12,
5248 },
5249 resumeConfig: &Config{
5250 MaxVersion: VersionTLS13,
5251 Bugs: ProtocolBugs{
5252 AdvertiseTicketExtension: true,
5253 },
5254 },
5255 resumeSession: true,
5256 shouldFail: true,
5257 expectedError: ":ERROR_PARSING_EXTENSION:",
5258 })
5259
5260 // Test that illegal extensions in TLS 1.3 are declined by the server if
5261 // offered in ClientHello. The runner's server will fail if this occurs,
5262 // so we exercise the offering path. (EMS and Renegotiation Info are
5263 // implicit in every test.)
5264 testCases = append(testCases, testCase{
5265 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005266 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005267 config: Config{
5268 MaxVersion: VersionTLS13,
5269 NextProtos: []string{"bar"},
5270 },
5271 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5272 })
David Benjamin196df5b2016-09-21 16:23:27 -04005273
David Benjamindaa88502016-10-04 16:32:16 -04005274 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5275 // tolerated.
5276 testCases = append(testCases, testCase{
5277 name: "SendOCSPResponseOnResume-TLS12",
5278 config: Config{
5279 MaxVersion: VersionTLS12,
5280 Bugs: ProtocolBugs{
5281 SendOCSPResponseOnResume: []byte("bogus"),
5282 },
5283 },
5284 flags: []string{
5285 "-enable-ocsp-stapling",
5286 "-expect-ocsp-response",
5287 base64.StdEncoding.EncodeToString(testOCSPResponse),
5288 },
5289 resumeSession: true,
5290 })
5291
5292 // Beginning TLS 1.3, enforce this does not happen.
5293 testCases = append(testCases, testCase{
5294 name: "SendOCSPResponseOnResume-TLS13",
5295 config: Config{
5296 MaxVersion: VersionTLS13,
5297 Bugs: ProtocolBugs{
5298 SendOCSPResponseOnResume: []byte("bogus"),
5299 },
5300 },
5301 flags: []string{
5302 "-enable-ocsp-stapling",
5303 "-expect-ocsp-response",
5304 base64.StdEncoding.EncodeToString(testOCSPResponse),
5305 },
5306 resumeSession: true,
5307 shouldFail: true,
5308 expectedError: ":ERROR_PARSING_EXTENSION:",
5309 })
David Benjamine78bfde2014-09-06 12:45:15 -04005310}
5311
David Benjamin01fe8202014-09-24 15:21:44 -04005312func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005313 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005314 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005315 // SSL 3.0 does not have tickets and TLS 1.3 does not
5316 // have session IDs, so skip their cross-resumption
5317 // tests.
5318 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5319 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5320 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005321 }
5322
David Benjamin8b8c0062014-11-23 02:47:52 -05005323 protocols := []protocol{tls}
5324 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5325 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005326 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005327 for _, protocol := range protocols {
5328 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5329 if protocol == dtls {
5330 suffix += "-DTLS"
5331 }
5332
David Benjaminece3de92015-03-16 18:02:20 -04005333 if sessionVers.version == resumeVers.version {
5334 testCases = append(testCases, testCase{
5335 protocol: protocol,
5336 name: "Resume-Client" + suffix,
5337 resumeSession: true,
5338 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005339 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005340 Bugs: ProtocolBugs{
5341 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5342 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5343 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005344 },
David Benjaminece3de92015-03-16 18:02:20 -04005345 expectedVersion: sessionVers.version,
5346 expectedResumeVersion: resumeVers.version,
5347 })
5348 } else {
David Benjamin405da482016-08-08 17:25:07 -04005349 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5350
5351 // Offering a TLS 1.3 session sends an empty session ID, so
5352 // there is no way to convince a non-lookahead client the
5353 // session was resumed. It will appear to the client that a
5354 // stray ChangeCipherSpec was sent.
5355 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5356 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005357 }
5358
David Benjaminece3de92015-03-16 18:02:20 -04005359 testCases = append(testCases, testCase{
5360 protocol: protocol,
5361 name: "Resume-Client-Mismatch" + suffix,
5362 resumeSession: true,
5363 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005364 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005365 },
David Benjaminece3de92015-03-16 18:02:20 -04005366 expectedVersion: sessionVers.version,
5367 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005368 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005369 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005370 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005371 },
5372 },
5373 expectedResumeVersion: resumeVers.version,
5374 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005375 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005376 })
5377 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005378
5379 testCases = append(testCases, testCase{
5380 protocol: protocol,
5381 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005382 resumeSession: true,
5383 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005384 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005385 },
5386 expectedVersion: sessionVers.version,
5387 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005388 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005389 },
5390 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005391 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005392 expectedResumeVersion: resumeVers.version,
5393 })
5394
David Benjamin8b8c0062014-11-23 02:47:52 -05005395 testCases = append(testCases, testCase{
5396 protocol: protocol,
5397 testType: serverTest,
5398 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005399 resumeSession: true,
5400 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005401 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005402 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005403 expectedVersion: sessionVers.version,
5404 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005405 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005406 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005407 Bugs: ProtocolBugs{
5408 SendBothTickets: true,
5409 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005410 },
5411 expectedResumeVersion: resumeVers.version,
5412 })
5413 }
David Benjamin01fe8202014-09-24 15:21:44 -04005414 }
5415 }
David Benjaminece3de92015-03-16 18:02:20 -04005416
David Benjamin4199b0d2016-11-01 13:58:25 -04005417 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005418 testCases = append(testCases, testCase{
5419 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005420 name: "ShimTicketRewritable",
5421 resumeSession: true,
5422 config: Config{
5423 MaxVersion: VersionTLS12,
5424 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5425 Bugs: ProtocolBugs{
5426 FilterTicket: func(in []byte) ([]byte, error) {
5427 in, err := SetShimTicketVersion(in, VersionTLS12)
5428 if err != nil {
5429 return nil, err
5430 }
5431 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5432 },
5433 },
5434 },
5435 flags: []string{
5436 "-ticket-key",
5437 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5438 },
5439 })
5440
5441 // Resumptions are declined if the version does not match.
5442 testCases = append(testCases, testCase{
5443 testType: serverTest,
5444 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005445 resumeSession: true,
5446 config: Config{
5447 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005448 Bugs: ProtocolBugs{
5449 FilterTicket: func(in []byte) ([]byte, error) {
5450 return SetShimTicketVersion(in, VersionTLS13)
5451 },
5452 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005453 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005454 flags: []string{
5455 "-ticket-key",
5456 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5457 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005458 expectResumeRejected: true,
5459 })
5460
5461 testCases = append(testCases, testCase{
5462 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005463 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005464 resumeSession: true,
5465 config: Config{
5466 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005467 Bugs: ProtocolBugs{
5468 FilterTicket: func(in []byte) ([]byte, error) {
5469 return SetShimTicketVersion(in, VersionTLS12)
5470 },
5471 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005472 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005473 flags: []string{
5474 "-ticket-key",
5475 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5476 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005477 expectResumeRejected: true,
5478 })
5479
David Benjamin4199b0d2016-11-01 13:58:25 -04005480 // Resumptions are declined if the cipher is invalid or disabled.
5481 testCases = append(testCases, testCase{
5482 testType: serverTest,
5483 name: "Resume-Server-DeclineBadCipher",
5484 resumeSession: true,
5485 config: Config{
5486 MaxVersion: VersionTLS12,
5487 Bugs: ProtocolBugs{
5488 FilterTicket: func(in []byte) ([]byte, error) {
5489 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5490 },
5491 },
5492 },
5493 flags: []string{
5494 "-ticket-key",
5495 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5496 },
5497 expectResumeRejected: true,
5498 })
5499
5500 testCases = append(testCases, testCase{
5501 testType: serverTest,
5502 name: "Resume-Server-DeclineBadCipher-2",
5503 resumeSession: true,
5504 config: Config{
5505 MaxVersion: VersionTLS12,
5506 Bugs: ProtocolBugs{
5507 FilterTicket: func(in []byte) ([]byte, error) {
5508 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5509 },
5510 },
5511 },
5512 flags: []string{
5513 "-cipher", "AES128",
5514 "-ticket-key",
5515 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5516 },
5517 expectResumeRejected: true,
5518 })
5519
5520 testCases = append(testCases, testCase{
5521 testType: serverTest,
5522 name: "Resume-Server-DeclineBadCipher-TLS13",
5523 resumeSession: true,
5524 config: Config{
5525 MaxVersion: VersionTLS13,
5526 Bugs: ProtocolBugs{
5527 FilterTicket: func(in []byte) ([]byte, error) {
5528 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5529 },
5530 },
5531 },
5532 flags: []string{
5533 "-ticket-key",
5534 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5535 },
5536 expectResumeRejected: true,
5537 })
5538
David Benjamin4199b0d2016-11-01 13:58:25 -04005539 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005540 testCases = append(testCases, testCase{
5541 name: "Resume-Client-CipherMismatch",
5542 resumeSession: true,
5543 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005544 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005545 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5546 },
5547 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005548 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005549 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5550 Bugs: ProtocolBugs{
5551 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5552 },
5553 },
5554 shouldFail: true,
5555 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5556 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005557
5558 testCases = append(testCases, testCase{
5559 name: "Resume-Client-CipherMismatch-TLS13",
5560 resumeSession: true,
5561 config: Config{
5562 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005563 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005564 },
5565 resumeConfig: &Config{
5566 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005567 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005568 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005569 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005570 },
5571 },
5572 shouldFail: true,
5573 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5574 })
David Benjamin01fe8202014-09-24 15:21:44 -04005575}
5576
Adam Langley2ae77d22014-10-28 17:29:33 -07005577func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005578 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005579 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005580 testType: serverTest,
5581 name: "Renegotiate-Server-Forbidden",
5582 config: Config{
5583 MaxVersion: VersionTLS12,
5584 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005585 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005586 shouldFail: true,
5587 expectedError: ":NO_RENEGOTIATION:",
5588 expectedLocalError: "remote error: no renegotiation",
5589 })
Adam Langley5021b222015-06-12 18:27:58 -07005590 // The server shouldn't echo the renegotiation extension unless
5591 // requested by the client.
5592 testCases = append(testCases, testCase{
5593 testType: serverTest,
5594 name: "Renegotiate-Server-NoExt",
5595 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005596 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005597 Bugs: ProtocolBugs{
5598 NoRenegotiationInfo: true,
5599 RequireRenegotiationInfo: true,
5600 },
5601 },
5602 shouldFail: true,
5603 expectedLocalError: "renegotiation extension missing",
5604 })
5605 // The renegotiation SCSV should be sufficient for the server to echo
5606 // the extension.
5607 testCases = append(testCases, testCase{
5608 testType: serverTest,
5609 name: "Renegotiate-Server-NoExt-SCSV",
5610 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005611 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005612 Bugs: ProtocolBugs{
5613 NoRenegotiationInfo: true,
5614 SendRenegotiationSCSV: true,
5615 RequireRenegotiationInfo: true,
5616 },
5617 },
5618 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005619 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005620 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005621 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005622 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005623 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005624 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005625 },
5626 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005627 renegotiate: 1,
5628 flags: []string{
5629 "-renegotiate-freely",
5630 "-expect-total-renegotiations", "1",
5631 },
David Benjamincdea40c2015-03-19 14:09:43 -04005632 })
5633 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005634 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005635 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005636 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005637 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005638 Bugs: ProtocolBugs{
5639 EmptyRenegotiationInfo: true,
5640 },
5641 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005642 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005643 shouldFail: true,
5644 expectedError: ":RENEGOTIATION_MISMATCH:",
5645 })
5646 testCases = append(testCases, testCase{
5647 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005648 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005649 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005650 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005651 Bugs: ProtocolBugs{
5652 BadRenegotiationInfo: true,
5653 },
5654 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005655 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005656 shouldFail: true,
5657 expectedError: ":RENEGOTIATION_MISMATCH:",
5658 })
5659 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005660 name: "Renegotiate-Client-Downgrade",
5661 renegotiate: 1,
5662 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005663 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005664 Bugs: ProtocolBugs{
5665 NoRenegotiationInfoAfterInitial: true,
5666 },
5667 },
5668 flags: []string{"-renegotiate-freely"},
5669 shouldFail: true,
5670 expectedError: ":RENEGOTIATION_MISMATCH:",
5671 })
5672 testCases = append(testCases, testCase{
5673 name: "Renegotiate-Client-Upgrade",
5674 renegotiate: 1,
5675 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005676 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005677 Bugs: ProtocolBugs{
5678 NoRenegotiationInfoInInitial: true,
5679 },
5680 },
5681 flags: []string{"-renegotiate-freely"},
5682 shouldFail: true,
5683 expectedError: ":RENEGOTIATION_MISMATCH:",
5684 })
5685 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005686 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005687 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005688 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005689 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005690 Bugs: ProtocolBugs{
5691 NoRenegotiationInfo: true,
5692 },
5693 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005694 flags: []string{
5695 "-renegotiate-freely",
5696 "-expect-total-renegotiations", "1",
5697 },
David Benjamincff0b902015-05-15 23:09:47 -04005698 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005699
5700 // Test that the server may switch ciphers on renegotiation without
5701 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005702 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005703 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005704 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005705 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005706 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005707 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005708 },
5709 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005710 flags: []string{
5711 "-renegotiate-freely",
5712 "-expect-total-renegotiations", "1",
5713 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005714 })
5715 testCases = append(testCases, testCase{
5716 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005717 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005718 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005719 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005720 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5721 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005722 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005723 flags: []string{
5724 "-renegotiate-freely",
5725 "-expect-total-renegotiations", "1",
5726 },
David Benjaminb16346b2015-04-08 19:16:58 -04005727 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005728
5729 // Test that the server may not switch versions on renegotiation.
5730 testCases = append(testCases, testCase{
5731 name: "Renegotiate-Client-SwitchVersion",
5732 config: Config{
5733 MaxVersion: VersionTLS12,
5734 // Pick a cipher which exists at both versions.
5735 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5736 Bugs: ProtocolBugs{
5737 NegotiateVersionOnRenego: VersionTLS11,
5738 },
5739 },
5740 renegotiate: 1,
5741 flags: []string{
5742 "-renegotiate-freely",
5743 "-expect-total-renegotiations", "1",
5744 },
5745 shouldFail: true,
5746 expectedError: ":WRONG_SSL_VERSION:",
5747 })
5748
David Benjaminb16346b2015-04-08 19:16:58 -04005749 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005750 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005751 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005752 config: Config{
5753 MaxVersion: VersionTLS10,
5754 Bugs: ProtocolBugs{
5755 RequireSameRenegoClientVersion: true,
5756 },
5757 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005758 flags: []string{
5759 "-renegotiate-freely",
5760 "-expect-total-renegotiations", "1",
5761 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005762 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005763 testCases = append(testCases, testCase{
5764 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005765 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005766 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005767 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005768 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5769 NextProtos: []string{"foo"},
5770 },
5771 flags: []string{
5772 "-false-start",
5773 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005774 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005775 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005776 },
5777 shimWritesFirst: true,
5778 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005779
5780 // Client-side renegotiation controls.
5781 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005782 name: "Renegotiate-Client-Forbidden-1",
5783 config: Config{
5784 MaxVersion: VersionTLS12,
5785 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005786 renegotiate: 1,
5787 shouldFail: true,
5788 expectedError: ":NO_RENEGOTIATION:",
5789 expectedLocalError: "remote error: no renegotiation",
5790 })
5791 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005792 name: "Renegotiate-Client-Once-1",
5793 config: Config{
5794 MaxVersion: VersionTLS12,
5795 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005796 renegotiate: 1,
5797 flags: []string{
5798 "-renegotiate-once",
5799 "-expect-total-renegotiations", "1",
5800 },
5801 })
5802 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005803 name: "Renegotiate-Client-Freely-1",
5804 config: Config{
5805 MaxVersion: VersionTLS12,
5806 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005807 renegotiate: 1,
5808 flags: []string{
5809 "-renegotiate-freely",
5810 "-expect-total-renegotiations", "1",
5811 },
5812 })
5813 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005814 name: "Renegotiate-Client-Once-2",
5815 config: Config{
5816 MaxVersion: VersionTLS12,
5817 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005818 renegotiate: 2,
5819 flags: []string{"-renegotiate-once"},
5820 shouldFail: true,
5821 expectedError: ":NO_RENEGOTIATION:",
5822 expectedLocalError: "remote error: no renegotiation",
5823 })
5824 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005825 name: "Renegotiate-Client-Freely-2",
5826 config: Config{
5827 MaxVersion: VersionTLS12,
5828 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005829 renegotiate: 2,
5830 flags: []string{
5831 "-renegotiate-freely",
5832 "-expect-total-renegotiations", "2",
5833 },
5834 })
Adam Langley27a0d082015-11-03 13:34:10 -08005835 testCases = append(testCases, testCase{
5836 name: "Renegotiate-Client-NoIgnore",
5837 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005838 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005839 Bugs: ProtocolBugs{
5840 SendHelloRequestBeforeEveryAppDataRecord: true,
5841 },
5842 },
5843 shouldFail: true,
5844 expectedError: ":NO_RENEGOTIATION:",
5845 })
5846 testCases = append(testCases, testCase{
5847 name: "Renegotiate-Client-Ignore",
5848 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005849 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005850 Bugs: ProtocolBugs{
5851 SendHelloRequestBeforeEveryAppDataRecord: true,
5852 },
5853 },
5854 flags: []string{
5855 "-renegotiate-ignore",
5856 "-expect-total-renegotiations", "0",
5857 },
5858 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005859
David Benjamin34941c02016-10-08 11:45:31 -04005860 // Renegotiation is not allowed at SSL 3.0.
5861 testCases = append(testCases, testCase{
5862 name: "Renegotiate-Client-SSL3",
5863 config: Config{
5864 MaxVersion: VersionSSL30,
5865 },
5866 renegotiate: 1,
5867 flags: []string{
5868 "-renegotiate-freely",
5869 "-expect-total-renegotiations", "1",
5870 },
5871 shouldFail: true,
5872 expectedError: ":NO_RENEGOTIATION:",
5873 expectedLocalError: "remote error: no renegotiation",
5874 })
5875
David Benjamin397c8e62016-07-08 14:14:36 -07005876 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005877 testCases = append(testCases, testCase{
5878 name: "StrayHelloRequest",
5879 config: Config{
5880 MaxVersion: VersionTLS12,
5881 Bugs: ProtocolBugs{
5882 SendHelloRequestBeforeEveryHandshakeMessage: true,
5883 },
5884 },
5885 })
5886 testCases = append(testCases, testCase{
5887 name: "StrayHelloRequest-Packed",
5888 config: Config{
5889 MaxVersion: VersionTLS12,
5890 Bugs: ProtocolBugs{
5891 PackHandshakeFlight: true,
5892 SendHelloRequestBeforeEveryHandshakeMessage: true,
5893 },
5894 },
5895 })
5896
David Benjamin12d2c482016-07-24 10:56:51 -04005897 // Test renegotiation works if HelloRequest and server Finished come in
5898 // the same record.
5899 testCases = append(testCases, testCase{
5900 name: "Renegotiate-Client-Packed",
5901 config: Config{
5902 MaxVersion: VersionTLS12,
5903 Bugs: ProtocolBugs{
5904 PackHandshakeFlight: true,
5905 PackHelloRequestWithFinished: true,
5906 },
5907 },
5908 renegotiate: 1,
5909 flags: []string{
5910 "-renegotiate-freely",
5911 "-expect-total-renegotiations", "1",
5912 },
5913 })
5914
David Benjamin397c8e62016-07-08 14:14:36 -07005915 // Renegotiation is forbidden in TLS 1.3.
5916 testCases = append(testCases, testCase{
5917 name: "Renegotiate-Client-TLS13",
5918 config: Config{
5919 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005920 Bugs: ProtocolBugs{
5921 SendHelloRequestBeforeEveryAppDataRecord: true,
5922 },
David Benjamin397c8e62016-07-08 14:14:36 -07005923 },
David Benjamin397c8e62016-07-08 14:14:36 -07005924 flags: []string{
5925 "-renegotiate-freely",
5926 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005927 shouldFail: true,
5928 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005929 })
5930
5931 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5932 testCases = append(testCases, testCase{
5933 name: "StrayHelloRequest-TLS13",
5934 config: Config{
5935 MaxVersion: VersionTLS13,
5936 Bugs: ProtocolBugs{
5937 SendHelloRequestBeforeEveryHandshakeMessage: true,
5938 },
5939 },
5940 shouldFail: true,
5941 expectedError: ":UNEXPECTED_MESSAGE:",
5942 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005943}
5944
David Benjamin5e961c12014-11-07 01:48:35 -05005945func addDTLSReplayTests() {
5946 // Test that sequence number replays are detected.
5947 testCases = append(testCases, testCase{
5948 protocol: dtls,
5949 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005950 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005951 replayWrites: true,
5952 })
5953
David Benjamin8e6db492015-07-25 18:29:23 -04005954 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005955 // than the retransmit window.
5956 testCases = append(testCases, testCase{
5957 protocol: dtls,
5958 name: "DTLS-Replay-LargeGaps",
5959 config: Config{
5960 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005961 SequenceNumberMapping: func(in uint64) uint64 {
5962 return in * 127
5963 },
David Benjamin5e961c12014-11-07 01:48:35 -05005964 },
5965 },
David Benjamin8e6db492015-07-25 18:29:23 -04005966 messageCount: 200,
5967 replayWrites: true,
5968 })
5969
5970 // Test the incoming sequence number changing non-monotonically.
5971 testCases = append(testCases, testCase{
5972 protocol: dtls,
5973 name: "DTLS-Replay-NonMonotonic",
5974 config: Config{
5975 Bugs: ProtocolBugs{
5976 SequenceNumberMapping: func(in uint64) uint64 {
5977 return in ^ 31
5978 },
5979 },
5980 },
5981 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005982 replayWrites: true,
5983 })
5984}
5985
Nick Harper60edffd2016-06-21 15:19:24 -07005986var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005987 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005988 id signatureAlgorithm
5989 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005990}{
Nick Harper60edffd2016-06-21 15:19:24 -07005991 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5992 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5993 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5994 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005995 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005996 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5997 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5998 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005999 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6000 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6001 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006002 // Tests for key types prior to TLS 1.2.
6003 {"RSA", 0, testCertRSA},
6004 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006005}
6006
Nick Harper60edffd2016-06-21 15:19:24 -07006007const fakeSigAlg1 signatureAlgorithm = 0x2a01
6008const fakeSigAlg2 signatureAlgorithm = 0xff01
6009
6010func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006011 // Not all ciphers involve a signature. Advertise a list which gives all
6012 // versions a signing cipher.
6013 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006014 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006015 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6016 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6017 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6018 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6019 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6020 }
6021
David Benjaminca3d5452016-07-14 12:51:01 -04006022 var allAlgorithms []signatureAlgorithm
6023 for _, alg := range testSignatureAlgorithms {
6024 if alg.id != 0 {
6025 allAlgorithms = append(allAlgorithms, alg.id)
6026 }
6027 }
6028
Nick Harper60edffd2016-06-21 15:19:24 -07006029 // Make sure each signature algorithm works. Include some fake values in
6030 // the list and ensure they're ignored.
6031 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006032 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006033 if (ver.version < VersionTLS12) != (alg.id == 0) {
6034 continue
6035 }
6036
6037 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6038 // or remove it in C.
6039 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006040 continue
6041 }
Nick Harper60edffd2016-06-21 15:19:24 -07006042
David Benjamin3ef76972016-10-17 17:59:54 -04006043 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006044 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006045 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006046 shouldSignFail = true
6047 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006048 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006049 // RSA-PKCS1 does not exist in TLS 1.3.
6050 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006051 shouldSignFail = true
6052 shouldVerifyFail = true
6053 }
6054
6055 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6056 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6057 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006058 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006059
6060 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006061 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006062 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006063 }
6064 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006065 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006066 }
David Benjamin000800a2014-11-14 01:43:59 -05006067
David Benjamin1fb125c2016-07-08 18:52:12 -07006068 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006069
David Benjamin7a41d372016-07-09 11:21:54 -07006070 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006071 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006072 config: Config{
6073 MaxVersion: ver.version,
6074 ClientAuth: RequireAnyClientCert,
6075 VerifySignatureAlgorithms: []signatureAlgorithm{
6076 fakeSigAlg1,
6077 alg.id,
6078 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006079 },
David Benjamin7a41d372016-07-09 11:21:54 -07006080 },
6081 flags: []string{
6082 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6083 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6084 "-enable-all-curves",
6085 },
David Benjamin3ef76972016-10-17 17:59:54 -04006086 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006087 expectedError: signError,
6088 expectedPeerSignatureAlgorithm: alg.id,
6089 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006090
David Benjamin7a41d372016-07-09 11:21:54 -07006091 testCases = append(testCases, testCase{
6092 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006093 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006094 config: Config{
6095 MaxVersion: ver.version,
6096 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6097 SignSignatureAlgorithms: []signatureAlgorithm{
6098 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006099 },
David Benjamin7a41d372016-07-09 11:21:54 -07006100 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006101 SkipECDSACurveCheck: shouldVerifyFail,
6102 IgnoreSignatureVersionChecks: shouldVerifyFail,
6103 // Some signature algorithms may not be advertised.
6104 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006105 },
David Benjamin7a41d372016-07-09 11:21:54 -07006106 },
6107 flags: []string{
6108 "-require-any-client-certificate",
6109 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6110 "-enable-all-curves",
6111 },
David Benjamin3ef76972016-10-17 17:59:54 -04006112 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006113 expectedError: verifyError,
6114 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006115
6116 testCases = append(testCases, testCase{
6117 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006118 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006119 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006120 MaxVersion: ver.version,
6121 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006122 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006123 fakeSigAlg1,
6124 alg.id,
6125 fakeSigAlg2,
6126 },
6127 },
6128 flags: []string{
6129 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6130 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6131 "-enable-all-curves",
6132 },
David Benjamin3ef76972016-10-17 17:59:54 -04006133 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006134 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006135 expectedPeerSignatureAlgorithm: alg.id,
6136 })
6137
6138 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006139 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006140 config: Config{
6141 MaxVersion: ver.version,
6142 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006143 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006144 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006145 alg.id,
6146 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006147 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006148 SkipECDSACurveCheck: shouldVerifyFail,
6149 IgnoreSignatureVersionChecks: shouldVerifyFail,
6150 // Some signature algorithms may not be advertised.
6151 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006152 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006153 },
6154 flags: []string{
6155 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6156 "-enable-all-curves",
6157 },
David Benjamin3ef76972016-10-17 17:59:54 -04006158 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006159 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006160 })
David Benjamin5208fd42016-07-13 21:43:25 -04006161
David Benjamin3ef76972016-10-17 17:59:54 -04006162 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006163 testCases = append(testCases, testCase{
6164 testType: serverTest,
6165 name: "ClientAuth-InvalidSignature" + suffix,
6166 config: Config{
6167 MaxVersion: ver.version,
6168 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6169 SignSignatureAlgorithms: []signatureAlgorithm{
6170 alg.id,
6171 },
6172 Bugs: ProtocolBugs{
6173 InvalidSignature: true,
6174 },
6175 },
6176 flags: []string{
6177 "-require-any-client-certificate",
6178 "-enable-all-curves",
6179 },
6180 shouldFail: true,
6181 expectedError: ":BAD_SIGNATURE:",
6182 })
6183
6184 testCases = append(testCases, testCase{
6185 name: "ServerAuth-InvalidSignature" + suffix,
6186 config: Config{
6187 MaxVersion: ver.version,
6188 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6189 CipherSuites: signingCiphers,
6190 SignSignatureAlgorithms: []signatureAlgorithm{
6191 alg.id,
6192 },
6193 Bugs: ProtocolBugs{
6194 InvalidSignature: true,
6195 },
6196 },
6197 flags: []string{"-enable-all-curves"},
6198 shouldFail: true,
6199 expectedError: ":BAD_SIGNATURE:",
6200 })
6201 }
David Benjaminca3d5452016-07-14 12:51:01 -04006202
David Benjamin3ef76972016-10-17 17:59:54 -04006203 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006204 testCases = append(testCases, testCase{
6205 name: "ClientAuth-Sign-Negotiate" + suffix,
6206 config: Config{
6207 MaxVersion: ver.version,
6208 ClientAuth: RequireAnyClientCert,
6209 VerifySignatureAlgorithms: allAlgorithms,
6210 },
6211 flags: []string{
6212 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6213 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6214 "-enable-all-curves",
6215 "-signing-prefs", strconv.Itoa(int(alg.id)),
6216 },
6217 expectedPeerSignatureAlgorithm: alg.id,
6218 })
6219
6220 testCases = append(testCases, testCase{
6221 testType: serverTest,
6222 name: "ServerAuth-Sign-Negotiate" + suffix,
6223 config: Config{
6224 MaxVersion: ver.version,
6225 CipherSuites: signingCiphers,
6226 VerifySignatureAlgorithms: allAlgorithms,
6227 },
6228 flags: []string{
6229 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6230 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6231 "-enable-all-curves",
6232 "-signing-prefs", strconv.Itoa(int(alg.id)),
6233 },
6234 expectedPeerSignatureAlgorithm: alg.id,
6235 })
6236 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006237 }
David Benjamin000800a2014-11-14 01:43:59 -05006238 }
6239
Nick Harper60edffd2016-06-21 15:19:24 -07006240 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006241 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006242 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006243 config: Config{
6244 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006245 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006246 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006247 signatureECDSAWithP521AndSHA512,
6248 signatureRSAPKCS1WithSHA384,
6249 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006250 },
6251 },
6252 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006253 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6254 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006255 },
Nick Harper60edffd2016-06-21 15:19:24 -07006256 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006257 })
6258
6259 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006260 name: "ClientAuth-SignatureType-TLS13",
6261 config: Config{
6262 ClientAuth: RequireAnyClientCert,
6263 MaxVersion: VersionTLS13,
6264 VerifySignatureAlgorithms: []signatureAlgorithm{
6265 signatureECDSAWithP521AndSHA512,
6266 signatureRSAPKCS1WithSHA384,
6267 signatureRSAPSSWithSHA384,
6268 signatureECDSAWithSHA1,
6269 },
6270 },
6271 flags: []string{
6272 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6273 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6274 },
6275 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6276 })
6277
6278 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006279 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006280 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006281 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006282 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006283 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006284 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006285 signatureECDSAWithP521AndSHA512,
6286 signatureRSAPKCS1WithSHA384,
6287 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006288 },
6289 },
Nick Harper60edffd2016-06-21 15:19:24 -07006290 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006291 })
6292
Steven Valdez143e8b32016-07-11 13:19:03 -04006293 testCases = append(testCases, testCase{
6294 testType: serverTest,
6295 name: "ServerAuth-SignatureType-TLS13",
6296 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006297 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006298 VerifySignatureAlgorithms: []signatureAlgorithm{
6299 signatureECDSAWithP521AndSHA512,
6300 signatureRSAPKCS1WithSHA384,
6301 signatureRSAPSSWithSHA384,
6302 signatureECDSAWithSHA1,
6303 },
6304 },
6305 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6306 })
6307
David Benjamina95e9f32016-07-08 16:28:04 -07006308 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006309 testCases = append(testCases, testCase{
6310 testType: serverTest,
6311 name: "Verify-ClientAuth-SignatureType",
6312 config: Config{
6313 MaxVersion: VersionTLS12,
6314 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006315 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006316 signatureRSAPKCS1WithSHA256,
6317 },
6318 Bugs: ProtocolBugs{
6319 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6320 },
6321 },
6322 flags: []string{
6323 "-require-any-client-certificate",
6324 },
6325 shouldFail: true,
6326 expectedError: ":WRONG_SIGNATURE_TYPE:",
6327 })
6328
6329 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006330 testType: serverTest,
6331 name: "Verify-ClientAuth-SignatureType-TLS13",
6332 config: Config{
6333 MaxVersion: VersionTLS13,
6334 Certificates: []Certificate{rsaCertificate},
6335 SignSignatureAlgorithms: []signatureAlgorithm{
6336 signatureRSAPSSWithSHA256,
6337 },
6338 Bugs: ProtocolBugs{
6339 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6340 },
6341 },
6342 flags: []string{
6343 "-require-any-client-certificate",
6344 },
6345 shouldFail: true,
6346 expectedError: ":WRONG_SIGNATURE_TYPE:",
6347 })
6348
6349 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006350 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006351 config: Config{
6352 MaxVersion: VersionTLS12,
6353 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006354 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006355 signatureRSAPKCS1WithSHA256,
6356 },
6357 Bugs: ProtocolBugs{
6358 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6359 },
6360 },
6361 shouldFail: true,
6362 expectedError: ":WRONG_SIGNATURE_TYPE:",
6363 })
6364
Steven Valdez143e8b32016-07-11 13:19:03 -04006365 testCases = append(testCases, testCase{
6366 name: "Verify-ServerAuth-SignatureType-TLS13",
6367 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006368 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006369 SignSignatureAlgorithms: []signatureAlgorithm{
6370 signatureRSAPSSWithSHA256,
6371 },
6372 Bugs: ProtocolBugs{
6373 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6374 },
6375 },
6376 shouldFail: true,
6377 expectedError: ":WRONG_SIGNATURE_TYPE:",
6378 })
6379
David Benjamin51dd7d62016-07-08 16:07:01 -07006380 // Test that, if the list is missing, the peer falls back to SHA-1 in
6381 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006382 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006383 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006384 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006385 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006386 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006387 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006388 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006389 },
6390 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006391 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006392 },
6393 },
6394 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006395 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6396 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006397 },
6398 })
6399
6400 testCases = append(testCases, testCase{
6401 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006402 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006403 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006404 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006405 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006406 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006407 },
6408 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006409 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006410 },
6411 },
David Benjaminee32bea2016-08-17 13:36:44 -04006412 flags: []string{
6413 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6414 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6415 },
6416 })
6417
6418 testCases = append(testCases, testCase{
6419 name: "ClientAuth-SHA1-Fallback-ECDSA",
6420 config: Config{
6421 MaxVersion: VersionTLS12,
6422 ClientAuth: RequireAnyClientCert,
6423 VerifySignatureAlgorithms: []signatureAlgorithm{
6424 signatureECDSAWithSHA1,
6425 },
6426 Bugs: ProtocolBugs{
6427 NoSignatureAlgorithms: true,
6428 },
6429 },
6430 flags: []string{
6431 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6432 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6433 },
6434 })
6435
6436 testCases = append(testCases, testCase{
6437 testType: serverTest,
6438 name: "ServerAuth-SHA1-Fallback-ECDSA",
6439 config: Config{
6440 MaxVersion: VersionTLS12,
6441 VerifySignatureAlgorithms: []signatureAlgorithm{
6442 signatureECDSAWithSHA1,
6443 },
6444 Bugs: ProtocolBugs{
6445 NoSignatureAlgorithms: true,
6446 },
6447 },
6448 flags: []string{
6449 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6450 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6451 },
David Benjamin000800a2014-11-14 01:43:59 -05006452 })
David Benjamin72dc7832015-03-16 17:49:43 -04006453
David Benjamin51dd7d62016-07-08 16:07:01 -07006454 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006455 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006456 config: Config{
6457 MaxVersion: VersionTLS13,
6458 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006459 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006460 signatureRSAPKCS1WithSHA1,
6461 },
6462 Bugs: ProtocolBugs{
6463 NoSignatureAlgorithms: true,
6464 },
6465 },
6466 flags: []string{
6467 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6468 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6469 },
David Benjamin48901652016-08-01 12:12:47 -04006470 shouldFail: true,
6471 // An empty CertificateRequest signature algorithm list is a
6472 // syntax error in TLS 1.3.
6473 expectedError: ":DECODE_ERROR:",
6474 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006475 })
6476
6477 testCases = append(testCases, testCase{
6478 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006479 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006480 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006481 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006482 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006483 signatureRSAPKCS1WithSHA1,
6484 },
6485 Bugs: ProtocolBugs{
6486 NoSignatureAlgorithms: true,
6487 },
6488 },
6489 shouldFail: true,
6490 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6491 })
6492
David Benjaminb62d2872016-07-18 14:55:02 +02006493 // Test that hash preferences are enforced. BoringSSL does not implement
6494 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006495 testCases = append(testCases, testCase{
6496 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006497 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006498 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006499 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006500 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006501 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006502 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006503 },
6504 Bugs: ProtocolBugs{
6505 IgnorePeerSignatureAlgorithmPreferences: true,
6506 },
6507 },
6508 flags: []string{"-require-any-client-certificate"},
6509 shouldFail: true,
6510 expectedError: ":WRONG_SIGNATURE_TYPE:",
6511 })
6512
6513 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006514 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006516 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006517 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006518 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006519 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006520 },
6521 Bugs: ProtocolBugs{
6522 IgnorePeerSignatureAlgorithmPreferences: true,
6523 },
6524 },
6525 shouldFail: true,
6526 expectedError: ":WRONG_SIGNATURE_TYPE:",
6527 })
David Benjaminb62d2872016-07-18 14:55:02 +02006528 testCases = append(testCases, testCase{
6529 testType: serverTest,
6530 name: "ClientAuth-Enforced-TLS13",
6531 config: Config{
6532 MaxVersion: VersionTLS13,
6533 Certificates: []Certificate{rsaCertificate},
6534 SignSignatureAlgorithms: []signatureAlgorithm{
6535 signatureRSAPKCS1WithMD5,
6536 },
6537 Bugs: ProtocolBugs{
6538 IgnorePeerSignatureAlgorithmPreferences: true,
6539 IgnoreSignatureVersionChecks: true,
6540 },
6541 },
6542 flags: []string{"-require-any-client-certificate"},
6543 shouldFail: true,
6544 expectedError: ":WRONG_SIGNATURE_TYPE:",
6545 })
6546
6547 testCases = append(testCases, testCase{
6548 name: "ServerAuth-Enforced-TLS13",
6549 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006550 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006551 SignSignatureAlgorithms: []signatureAlgorithm{
6552 signatureRSAPKCS1WithMD5,
6553 },
6554 Bugs: ProtocolBugs{
6555 IgnorePeerSignatureAlgorithmPreferences: true,
6556 IgnoreSignatureVersionChecks: true,
6557 },
6558 },
6559 shouldFail: true,
6560 expectedError: ":WRONG_SIGNATURE_TYPE:",
6561 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006562
6563 // Test that the agreed upon digest respects the client preferences and
6564 // the server digests.
6565 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006566 name: "NoCommonAlgorithms-Digests",
6567 config: Config{
6568 MaxVersion: VersionTLS12,
6569 ClientAuth: RequireAnyClientCert,
6570 VerifySignatureAlgorithms: []signatureAlgorithm{
6571 signatureRSAPKCS1WithSHA512,
6572 signatureRSAPKCS1WithSHA1,
6573 },
6574 },
6575 flags: []string{
6576 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6577 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6578 "-digest-prefs", "SHA256",
6579 },
6580 shouldFail: true,
6581 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6582 })
6583 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006584 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006585 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006586 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006587 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006588 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006589 signatureRSAPKCS1WithSHA512,
6590 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006591 },
6592 },
6593 flags: []string{
6594 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6595 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006596 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006597 },
David Benjaminca3d5452016-07-14 12:51:01 -04006598 shouldFail: true,
6599 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6600 })
6601 testCases = append(testCases, testCase{
6602 name: "NoCommonAlgorithms-TLS13",
6603 config: Config{
6604 MaxVersion: VersionTLS13,
6605 ClientAuth: RequireAnyClientCert,
6606 VerifySignatureAlgorithms: []signatureAlgorithm{
6607 signatureRSAPSSWithSHA512,
6608 signatureRSAPSSWithSHA384,
6609 },
6610 },
6611 flags: []string{
6612 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6613 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6614 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6615 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006616 shouldFail: true,
6617 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006618 })
6619 testCases = append(testCases, testCase{
6620 name: "Agree-Digest-SHA256",
6621 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006622 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006623 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006624 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006625 signatureRSAPKCS1WithSHA1,
6626 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006627 },
6628 },
6629 flags: []string{
6630 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6631 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006632 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006633 },
Nick Harper60edffd2016-06-21 15:19:24 -07006634 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006635 })
6636 testCases = append(testCases, testCase{
6637 name: "Agree-Digest-SHA1",
6638 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006639 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006640 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006641 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006642 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006643 },
6644 },
6645 flags: []string{
6646 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6647 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006648 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006649 },
Nick Harper60edffd2016-06-21 15:19:24 -07006650 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006651 })
6652 testCases = append(testCases, testCase{
6653 name: "Agree-Digest-Default",
6654 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006655 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006656 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006657 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006658 signatureRSAPKCS1WithSHA256,
6659 signatureECDSAWithP256AndSHA256,
6660 signatureRSAPKCS1WithSHA1,
6661 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006662 },
6663 },
6664 flags: []string{
6665 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6666 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6667 },
Nick Harper60edffd2016-06-21 15:19:24 -07006668 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006669 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006670
David Benjaminca3d5452016-07-14 12:51:01 -04006671 // Test that the signing preference list may include extra algorithms
6672 // without negotiation problems.
6673 testCases = append(testCases, testCase{
6674 testType: serverTest,
6675 name: "FilterExtraAlgorithms",
6676 config: Config{
6677 MaxVersion: VersionTLS12,
6678 VerifySignatureAlgorithms: []signatureAlgorithm{
6679 signatureRSAPKCS1WithSHA256,
6680 },
6681 },
6682 flags: []string{
6683 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6684 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6685 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6686 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6687 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6688 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6689 },
6690 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6691 })
6692
David Benjamin4c3ddf72016-06-29 18:13:53 -04006693 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6694 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006695 testCases = append(testCases, testCase{
6696 name: "CheckLeafCurve",
6697 config: Config{
6698 MaxVersion: VersionTLS12,
6699 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006700 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006701 },
6702 flags: []string{"-p384-only"},
6703 shouldFail: true,
6704 expectedError: ":BAD_ECC_CERT:",
6705 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006706
6707 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6708 testCases = append(testCases, testCase{
6709 name: "CheckLeafCurve-TLS13",
6710 config: Config{
6711 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07006712 Certificates: []Certificate{ecdsaP256Certificate},
6713 },
6714 flags: []string{"-p384-only"},
6715 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006716
6717 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6718 testCases = append(testCases, testCase{
6719 name: "ECDSACurveMismatch-Verify-TLS12",
6720 config: Config{
6721 MaxVersion: VersionTLS12,
6722 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6723 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006724 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006725 signatureECDSAWithP384AndSHA384,
6726 },
6727 },
6728 })
6729
6730 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6731 testCases = append(testCases, testCase{
6732 name: "ECDSACurveMismatch-Verify-TLS13",
6733 config: Config{
6734 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07006735 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006736 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006737 signatureECDSAWithP384AndSHA384,
6738 },
6739 Bugs: ProtocolBugs{
6740 SkipECDSACurveCheck: true,
6741 },
6742 },
6743 shouldFail: true,
6744 expectedError: ":WRONG_SIGNATURE_TYPE:",
6745 })
6746
6747 // Signature algorithm selection in TLS 1.3 should take the curve into
6748 // account.
6749 testCases = append(testCases, testCase{
6750 testType: serverTest,
6751 name: "ECDSACurveMismatch-Sign-TLS13",
6752 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006753 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006754 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006755 signatureECDSAWithP384AndSHA384,
6756 signatureECDSAWithP256AndSHA256,
6757 },
6758 },
6759 flags: []string{
6760 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6761 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6762 },
6763 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6764 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006765
6766 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6767 // server does not attempt to sign in that case.
6768 testCases = append(testCases, testCase{
6769 testType: serverTest,
6770 name: "RSA-PSS-Large",
6771 config: Config{
6772 MaxVersion: VersionTLS13,
6773 VerifySignatureAlgorithms: []signatureAlgorithm{
6774 signatureRSAPSSWithSHA512,
6775 },
6776 },
6777 flags: []string{
6778 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6779 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6780 },
6781 shouldFail: true,
6782 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6783 })
David Benjamin57e929f2016-08-30 00:30:38 -04006784
6785 // Test that RSA-PSS is enabled by default for TLS 1.2.
6786 testCases = append(testCases, testCase{
6787 testType: clientTest,
6788 name: "RSA-PSS-Default-Verify",
6789 config: Config{
6790 MaxVersion: VersionTLS12,
6791 SignSignatureAlgorithms: []signatureAlgorithm{
6792 signatureRSAPSSWithSHA256,
6793 },
6794 },
6795 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6796 })
6797
6798 testCases = append(testCases, testCase{
6799 testType: serverTest,
6800 name: "RSA-PSS-Default-Sign",
6801 config: Config{
6802 MaxVersion: VersionTLS12,
6803 VerifySignatureAlgorithms: []signatureAlgorithm{
6804 signatureRSAPSSWithSHA256,
6805 },
6806 },
6807 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6808 })
David Benjamin000800a2014-11-14 01:43:59 -05006809}
6810
David Benjamin83f90402015-01-27 01:09:43 -05006811// timeouts is the retransmit schedule for BoringSSL. It doubles and
6812// caps at 60 seconds. On the 13th timeout, it gives up.
6813var timeouts = []time.Duration{
6814 1 * time.Second,
6815 2 * time.Second,
6816 4 * time.Second,
6817 8 * time.Second,
6818 16 * time.Second,
6819 32 * time.Second,
6820 60 * time.Second,
6821 60 * time.Second,
6822 60 * time.Second,
6823 60 * time.Second,
6824 60 * time.Second,
6825 60 * time.Second,
6826 60 * time.Second,
6827}
6828
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006829// shortTimeouts is an alternate set of timeouts which would occur if the
6830// initial timeout duration was set to 250ms.
6831var shortTimeouts = []time.Duration{
6832 250 * time.Millisecond,
6833 500 * time.Millisecond,
6834 1 * time.Second,
6835 2 * time.Second,
6836 4 * time.Second,
6837 8 * time.Second,
6838 16 * time.Second,
6839 32 * time.Second,
6840 60 * time.Second,
6841 60 * time.Second,
6842 60 * time.Second,
6843 60 * time.Second,
6844 60 * time.Second,
6845}
6846
David Benjamin83f90402015-01-27 01:09:43 -05006847func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006848 // These tests work by coordinating some behavior on both the shim and
6849 // the runner.
6850 //
6851 // TimeoutSchedule configures the runner to send a series of timeout
6852 // opcodes to the shim (see packetAdaptor) immediately before reading
6853 // each peer handshake flight N. The timeout opcode both simulates a
6854 // timeout in the shim and acts as a synchronization point to help the
6855 // runner bracket each handshake flight.
6856 //
6857 // We assume the shim does not read from the channel eagerly. It must
6858 // first wait until it has sent flight N and is ready to receive
6859 // handshake flight N+1. At this point, it will process the timeout
6860 // opcode. It must then immediately respond with a timeout ACK and act
6861 // as if the shim was idle for the specified amount of time.
6862 //
6863 // The runner then drops all packets received before the ACK and
6864 // continues waiting for flight N. This ordering results in one attempt
6865 // at sending flight N to be dropped. For the test to complete, the
6866 // shim must send flight N again, testing that the shim implements DTLS
6867 // retransmit on a timeout.
6868
Steven Valdez143e8b32016-07-11 13:19:03 -04006869 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006870 // likely be more epochs to cross and the final message's retransmit may
6871 // be more complex.
6872
David Benjamin585d7a42016-06-02 14:58:00 -04006873 for _, async := range []bool{true, false} {
6874 var tests []testCase
6875
6876 // Test that this is indeed the timeout schedule. Stress all
6877 // four patterns of handshake.
6878 for i := 1; i < len(timeouts); i++ {
6879 number := strconv.Itoa(i)
6880 tests = append(tests, testCase{
6881 protocol: dtls,
6882 name: "DTLS-Retransmit-Client-" + number,
6883 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006884 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006885 Bugs: ProtocolBugs{
6886 TimeoutSchedule: timeouts[:i],
6887 },
6888 },
6889 resumeSession: true,
6890 })
6891 tests = append(tests, testCase{
6892 protocol: dtls,
6893 testType: serverTest,
6894 name: "DTLS-Retransmit-Server-" + number,
6895 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006896 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006897 Bugs: ProtocolBugs{
6898 TimeoutSchedule: timeouts[:i],
6899 },
6900 },
6901 resumeSession: true,
6902 })
6903 }
6904
6905 // Test that exceeding the timeout schedule hits a read
6906 // timeout.
6907 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006908 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006909 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006910 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006911 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006912 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006913 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006914 },
6915 },
6916 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006917 shouldFail: true,
6918 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006919 })
David Benjamin585d7a42016-06-02 14:58:00 -04006920
6921 if async {
6922 // Test that timeout handling has a fudge factor, due to API
6923 // problems.
6924 tests = append(tests, testCase{
6925 protocol: dtls,
6926 name: "DTLS-Retransmit-Fudge",
6927 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006928 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006929 Bugs: ProtocolBugs{
6930 TimeoutSchedule: []time.Duration{
6931 timeouts[0] - 10*time.Millisecond,
6932 },
6933 },
6934 },
6935 resumeSession: true,
6936 })
6937 }
6938
6939 // Test that the final Finished retransmitting isn't
6940 // duplicated if the peer badly fragments everything.
6941 tests = append(tests, testCase{
6942 testType: serverTest,
6943 protocol: dtls,
6944 name: "DTLS-Retransmit-Fragmented",
6945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006946 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006947 Bugs: ProtocolBugs{
6948 TimeoutSchedule: []time.Duration{timeouts[0]},
6949 MaxHandshakeRecordLength: 2,
6950 },
6951 },
6952 })
6953
6954 // Test the timeout schedule when a shorter initial timeout duration is set.
6955 tests = append(tests, testCase{
6956 protocol: dtls,
6957 name: "DTLS-Retransmit-Short-Client",
6958 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006959 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006960 Bugs: ProtocolBugs{
6961 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6962 },
6963 },
6964 resumeSession: true,
6965 flags: []string{"-initial-timeout-duration-ms", "250"},
6966 })
6967 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006968 protocol: dtls,
6969 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006970 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006972 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006973 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006974 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006975 },
6976 },
6977 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006978 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006979 })
David Benjamin585d7a42016-06-02 14:58:00 -04006980
6981 for _, test := range tests {
6982 if async {
6983 test.name += "-Async"
6984 test.flags = append(test.flags, "-async")
6985 }
6986
6987 testCases = append(testCases, test)
6988 }
David Benjamin83f90402015-01-27 01:09:43 -05006989 }
David Benjamin83f90402015-01-27 01:09:43 -05006990}
6991
David Benjaminc565ebb2015-04-03 04:06:36 -04006992func addExportKeyingMaterialTests() {
6993 for _, vers := range tlsVersions {
6994 if vers.version == VersionSSL30 {
6995 continue
6996 }
6997 testCases = append(testCases, testCase{
6998 name: "ExportKeyingMaterial-" + vers.name,
6999 config: Config{
7000 MaxVersion: vers.version,
7001 },
7002 exportKeyingMaterial: 1024,
7003 exportLabel: "label",
7004 exportContext: "context",
7005 useExportContext: true,
7006 })
7007 testCases = append(testCases, testCase{
7008 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7009 config: Config{
7010 MaxVersion: vers.version,
7011 },
7012 exportKeyingMaterial: 1024,
7013 })
7014 testCases = append(testCases, testCase{
7015 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7016 config: Config{
7017 MaxVersion: vers.version,
7018 },
7019 exportKeyingMaterial: 1024,
7020 useExportContext: true,
7021 })
7022 testCases = append(testCases, testCase{
7023 name: "ExportKeyingMaterial-Small-" + vers.name,
7024 config: Config{
7025 MaxVersion: vers.version,
7026 },
7027 exportKeyingMaterial: 1,
7028 exportLabel: "label",
7029 exportContext: "context",
7030 useExportContext: true,
7031 })
7032 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007033
David Benjaminc565ebb2015-04-03 04:06:36 -04007034 testCases = append(testCases, testCase{
7035 name: "ExportKeyingMaterial-SSL3",
7036 config: Config{
7037 MaxVersion: VersionSSL30,
7038 },
7039 exportKeyingMaterial: 1024,
7040 exportLabel: "label",
7041 exportContext: "context",
7042 useExportContext: true,
7043 shouldFail: true,
7044 expectedError: "failed to export keying material",
7045 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007046
7047 // Exporters work during a False Start.
7048 testCases = append(testCases, testCase{
7049 name: "ExportKeyingMaterial-FalseStart",
7050 config: Config{
7051 MaxVersion: VersionTLS12,
7052 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7053 NextProtos: []string{"foo"},
7054 Bugs: ProtocolBugs{
7055 ExpectFalseStart: true,
7056 },
7057 },
7058 flags: []string{
7059 "-false-start",
7060 "-advertise-alpn", "\x03foo",
7061 },
7062 shimWritesFirst: true,
7063 exportKeyingMaterial: 1024,
7064 exportLabel: "label",
7065 exportContext: "context",
7066 useExportContext: true,
7067 })
7068
7069 // Exporters do not work in the middle of a renegotiation. Test this by
7070 // triggering the exporter after every SSL_read call and configuring the
7071 // shim to run asynchronously.
7072 testCases = append(testCases, testCase{
7073 name: "ExportKeyingMaterial-Renegotiate",
7074 config: Config{
7075 MaxVersion: VersionTLS12,
7076 },
7077 renegotiate: 1,
7078 flags: []string{
7079 "-async",
7080 "-use-exporter-between-reads",
7081 "-renegotiate-freely",
7082 "-expect-total-renegotiations", "1",
7083 },
7084 shouldFail: true,
7085 expectedError: "failed to export keying material",
7086 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007087}
7088
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007089func addTLSUniqueTests() {
7090 for _, isClient := range []bool{false, true} {
7091 for _, isResumption := range []bool{false, true} {
7092 for _, hasEMS := range []bool{false, true} {
7093 var suffix string
7094 if isResumption {
7095 suffix = "Resume-"
7096 } else {
7097 suffix = "Full-"
7098 }
7099
7100 if hasEMS {
7101 suffix += "EMS-"
7102 } else {
7103 suffix += "NoEMS-"
7104 }
7105
7106 if isClient {
7107 suffix += "Client"
7108 } else {
7109 suffix += "Server"
7110 }
7111
7112 test := testCase{
7113 name: "TLSUnique-" + suffix,
7114 testTLSUnique: true,
7115 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007116 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007117 Bugs: ProtocolBugs{
7118 NoExtendedMasterSecret: !hasEMS,
7119 },
7120 },
7121 }
7122
7123 if isResumption {
7124 test.resumeSession = true
7125 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007126 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007127 Bugs: ProtocolBugs{
7128 NoExtendedMasterSecret: !hasEMS,
7129 },
7130 }
7131 }
7132
7133 if isResumption && !hasEMS {
7134 test.shouldFail = true
7135 test.expectedError = "failed to get tls-unique"
7136 }
7137
7138 testCases = append(testCases, test)
7139 }
7140 }
7141 }
7142}
7143
Adam Langley09505632015-07-30 18:10:13 -07007144func addCustomExtensionTests() {
7145 expectedContents := "custom extension"
7146 emptyString := ""
7147
7148 for _, isClient := range []bool{false, true} {
7149 suffix := "Server"
7150 flag := "-enable-server-custom-extension"
7151 testType := serverTest
7152 if isClient {
7153 suffix = "Client"
7154 flag = "-enable-client-custom-extension"
7155 testType = clientTest
7156 }
7157
7158 testCases = append(testCases, testCase{
7159 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007160 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007161 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007162 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007163 Bugs: ProtocolBugs{
7164 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007165 ExpectedCustomExtension: &expectedContents,
7166 },
7167 },
7168 flags: []string{flag},
7169 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007170 testCases = append(testCases, testCase{
7171 testType: testType,
7172 name: "CustomExtensions-" + suffix + "-TLS13",
7173 config: Config{
7174 MaxVersion: VersionTLS13,
7175 Bugs: ProtocolBugs{
7176 CustomExtension: expectedContents,
7177 ExpectedCustomExtension: &expectedContents,
7178 },
7179 },
7180 flags: []string{flag},
7181 })
Adam Langley09505632015-07-30 18:10:13 -07007182
7183 // If the parse callback fails, the handshake should also fail.
7184 testCases = append(testCases, testCase{
7185 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007186 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007187 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007188 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007189 Bugs: ProtocolBugs{
7190 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007191 ExpectedCustomExtension: &expectedContents,
7192 },
7193 },
David Benjamin399e7c92015-07-30 23:01:27 -04007194 flags: []string{flag},
7195 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007196 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7197 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007198 testCases = append(testCases, testCase{
7199 testType: testType,
7200 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7201 config: Config{
7202 MaxVersion: VersionTLS13,
7203 Bugs: ProtocolBugs{
7204 CustomExtension: expectedContents + "foo",
7205 ExpectedCustomExtension: &expectedContents,
7206 },
7207 },
7208 flags: []string{flag},
7209 shouldFail: true,
7210 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7211 })
Adam Langley09505632015-07-30 18:10:13 -07007212
7213 // If the add callback fails, the handshake should also fail.
7214 testCases = append(testCases, testCase{
7215 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007216 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007217 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007218 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007219 Bugs: ProtocolBugs{
7220 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007221 ExpectedCustomExtension: &expectedContents,
7222 },
7223 },
David Benjamin399e7c92015-07-30 23:01:27 -04007224 flags: []string{flag, "-custom-extension-fail-add"},
7225 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007226 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7227 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007228 testCases = append(testCases, testCase{
7229 testType: testType,
7230 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7231 config: Config{
7232 MaxVersion: VersionTLS13,
7233 Bugs: ProtocolBugs{
7234 CustomExtension: expectedContents,
7235 ExpectedCustomExtension: &expectedContents,
7236 },
7237 },
7238 flags: []string{flag, "-custom-extension-fail-add"},
7239 shouldFail: true,
7240 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7241 })
Adam Langley09505632015-07-30 18:10:13 -07007242
7243 // If the add callback returns zero, no extension should be
7244 // added.
7245 skipCustomExtension := expectedContents
7246 if isClient {
7247 // For the case where the client skips sending the
7248 // custom extension, the server must not “echo” it.
7249 skipCustomExtension = ""
7250 }
7251 testCases = append(testCases, testCase{
7252 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007253 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007254 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007255 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007256 Bugs: ProtocolBugs{
7257 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007258 ExpectedCustomExtension: &emptyString,
7259 },
7260 },
7261 flags: []string{flag, "-custom-extension-skip"},
7262 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007263 testCases = append(testCases, testCase{
7264 testType: testType,
7265 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7266 config: Config{
7267 MaxVersion: VersionTLS13,
7268 Bugs: ProtocolBugs{
7269 CustomExtension: skipCustomExtension,
7270 ExpectedCustomExtension: &emptyString,
7271 },
7272 },
7273 flags: []string{flag, "-custom-extension-skip"},
7274 })
Adam Langley09505632015-07-30 18:10:13 -07007275 }
7276
7277 // The custom extension add callback should not be called if the client
7278 // doesn't send the extension.
7279 testCases = append(testCases, testCase{
7280 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007281 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007282 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007283 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007284 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007285 ExpectedCustomExtension: &emptyString,
7286 },
7287 },
7288 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7289 })
Adam Langley2deb9842015-08-07 11:15:37 -07007290
Steven Valdez143e8b32016-07-11 13:19:03 -04007291 testCases = append(testCases, testCase{
7292 testType: serverTest,
7293 name: "CustomExtensions-NotCalled-Server-TLS13",
7294 config: Config{
7295 MaxVersion: VersionTLS13,
7296 Bugs: ProtocolBugs{
7297 ExpectedCustomExtension: &emptyString,
7298 },
7299 },
7300 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7301 })
7302
Adam Langley2deb9842015-08-07 11:15:37 -07007303 // Test an unknown extension from the server.
7304 testCases = append(testCases, testCase{
7305 testType: clientTest,
7306 name: "UnknownExtension-Client",
7307 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007308 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007309 Bugs: ProtocolBugs{
7310 CustomExtension: expectedContents,
7311 },
7312 },
David Benjamin0c40a962016-08-01 12:05:50 -04007313 shouldFail: true,
7314 expectedError: ":UNEXPECTED_EXTENSION:",
7315 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007316 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007317 testCases = append(testCases, testCase{
7318 testType: clientTest,
7319 name: "UnknownExtension-Client-TLS13",
7320 config: Config{
7321 MaxVersion: VersionTLS13,
7322 Bugs: ProtocolBugs{
7323 CustomExtension: expectedContents,
7324 },
7325 },
David Benjamin0c40a962016-08-01 12:05:50 -04007326 shouldFail: true,
7327 expectedError: ":UNEXPECTED_EXTENSION:",
7328 expectedLocalError: "remote error: unsupported extension",
7329 })
David Benjamin490469f2016-10-05 22:44:38 -04007330 testCases = append(testCases, testCase{
7331 testType: clientTest,
7332 name: "UnknownUnencryptedExtension-Client-TLS13",
7333 config: Config{
7334 MaxVersion: VersionTLS13,
7335 Bugs: ProtocolBugs{
7336 CustomUnencryptedExtension: expectedContents,
7337 },
7338 },
7339 shouldFail: true,
7340 expectedError: ":UNEXPECTED_EXTENSION:",
7341 // The shim must send an alert, but alerts at this point do not
7342 // get successfully decrypted by the runner.
7343 expectedLocalError: "local error: bad record MAC",
7344 })
7345 testCases = append(testCases, testCase{
7346 testType: clientTest,
7347 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7348 config: Config{
7349 MaxVersion: VersionTLS13,
7350 Bugs: ProtocolBugs{
7351 SendUnencryptedALPN: "foo",
7352 },
7353 },
7354 flags: []string{
7355 "-advertise-alpn", "\x03foo\x03bar",
7356 },
7357 shouldFail: true,
7358 expectedError: ":UNEXPECTED_EXTENSION:",
7359 // The shim must send an alert, but alerts at this point do not
7360 // get successfully decrypted by the runner.
7361 expectedLocalError: "local error: bad record MAC",
7362 })
David Benjamin0c40a962016-08-01 12:05:50 -04007363
7364 // Test a known but unoffered extension from the server.
7365 testCases = append(testCases, testCase{
7366 testType: clientTest,
7367 name: "UnofferedExtension-Client",
7368 config: Config{
7369 MaxVersion: VersionTLS12,
7370 Bugs: ProtocolBugs{
7371 SendALPN: "alpn",
7372 },
7373 },
7374 shouldFail: true,
7375 expectedError: ":UNEXPECTED_EXTENSION:",
7376 expectedLocalError: "remote error: unsupported extension",
7377 })
7378 testCases = append(testCases, testCase{
7379 testType: clientTest,
7380 name: "UnofferedExtension-Client-TLS13",
7381 config: Config{
7382 MaxVersion: VersionTLS13,
7383 Bugs: ProtocolBugs{
7384 SendALPN: "alpn",
7385 },
7386 },
7387 shouldFail: true,
7388 expectedError: ":UNEXPECTED_EXTENSION:",
7389 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007390 })
Adam Langley09505632015-07-30 18:10:13 -07007391}
7392
David Benjaminb36a3952015-12-01 18:53:13 -05007393func addRSAClientKeyExchangeTests() {
7394 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7395 testCases = append(testCases, testCase{
7396 testType: serverTest,
7397 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7398 config: Config{
7399 // Ensure the ClientHello version and final
7400 // version are different, to detect if the
7401 // server uses the wrong one.
7402 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007403 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007404 Bugs: ProtocolBugs{
7405 BadRSAClientKeyExchange: bad,
7406 },
7407 },
7408 shouldFail: true,
7409 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7410 })
7411 }
David Benjamine63d9d72016-09-19 18:27:34 -04007412
7413 // The server must compare whatever was in ClientHello.version for the
7414 // RSA premaster.
7415 testCases = append(testCases, testCase{
7416 testType: serverTest,
7417 name: "SendClientVersion-RSA",
7418 config: Config{
7419 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7420 Bugs: ProtocolBugs{
7421 SendClientVersion: 0x1234,
7422 },
7423 },
7424 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7425 })
David Benjaminb36a3952015-12-01 18:53:13 -05007426}
7427
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007428var testCurves = []struct {
7429 name string
7430 id CurveID
7431}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007432 {"P-256", CurveP256},
7433 {"P-384", CurveP384},
7434 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007435 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007436}
7437
Steven Valdez5440fe02016-07-18 12:40:30 -04007438const bogusCurve = 0x1234
7439
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007440func addCurveTests() {
7441 for _, curve := range testCurves {
7442 testCases = append(testCases, testCase{
7443 name: "CurveTest-Client-" + curve.name,
7444 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007445 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007446 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7447 CurvePreferences: []CurveID{curve.id},
7448 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007449 flags: []string{
7450 "-enable-all-curves",
7451 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7452 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007453 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007454 })
7455 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007456 name: "CurveTest-Client-" + curve.name + "-TLS13",
7457 config: Config{
7458 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007459 CurvePreferences: []CurveID{curve.id},
7460 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007461 flags: []string{
7462 "-enable-all-curves",
7463 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7464 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007465 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007466 })
7467 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007468 testType: serverTest,
7469 name: "CurveTest-Server-" + curve.name,
7470 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007471 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007472 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7473 CurvePreferences: []CurveID{curve.id},
7474 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007475 flags: []string{
7476 "-enable-all-curves",
7477 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7478 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007479 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007480 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007481 testCases = append(testCases, testCase{
7482 testType: serverTest,
7483 name: "CurveTest-Server-" + curve.name + "-TLS13",
7484 config: Config{
7485 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007486 CurvePreferences: []CurveID{curve.id},
7487 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007488 flags: []string{
7489 "-enable-all-curves",
7490 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7491 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007492 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007493 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007494 }
David Benjamin241ae832016-01-15 03:04:54 -05007495
7496 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007497 testCases = append(testCases, testCase{
7498 testType: serverTest,
7499 name: "UnknownCurve",
7500 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007501 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007502 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7503 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7504 },
7505 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007506
Steven Valdez803c77a2016-09-06 14:13:43 -04007507 // The server must be tolerant to bogus curves.
7508 testCases = append(testCases, testCase{
7509 testType: serverTest,
7510 name: "UnknownCurve-TLS13",
7511 config: Config{
7512 MaxVersion: VersionTLS13,
7513 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7514 },
7515 })
7516
David Benjamin4c3ddf72016-06-29 18:13:53 -04007517 // The server must not consider ECDHE ciphers when there are no
7518 // supported curves.
7519 testCases = append(testCases, testCase{
7520 testType: serverTest,
7521 name: "NoSupportedCurves",
7522 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007523 MaxVersion: VersionTLS12,
7524 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7525 Bugs: ProtocolBugs{
7526 NoSupportedCurves: true,
7527 },
7528 },
7529 shouldFail: true,
7530 expectedError: ":NO_SHARED_CIPHER:",
7531 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007532 testCases = append(testCases, testCase{
7533 testType: serverTest,
7534 name: "NoSupportedCurves-TLS13",
7535 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007536 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007537 Bugs: ProtocolBugs{
7538 NoSupportedCurves: true,
7539 },
7540 },
7541 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007542 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007543 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007544
7545 // The server must fall back to another cipher when there are no
7546 // supported curves.
7547 testCases = append(testCases, testCase{
7548 testType: serverTest,
7549 name: "NoCommonCurves",
7550 config: Config{
7551 MaxVersion: VersionTLS12,
7552 CipherSuites: []uint16{
7553 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7554 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7555 },
7556 CurvePreferences: []CurveID{CurveP224},
7557 },
7558 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7559 })
7560
7561 // The client must reject bogus curves and disabled curves.
7562 testCases = append(testCases, testCase{
7563 name: "BadECDHECurve",
7564 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007565 MaxVersion: VersionTLS12,
7566 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7567 Bugs: ProtocolBugs{
7568 SendCurve: bogusCurve,
7569 },
7570 },
7571 shouldFail: true,
7572 expectedError: ":WRONG_CURVE:",
7573 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007574 testCases = append(testCases, testCase{
7575 name: "BadECDHECurve-TLS13",
7576 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007577 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007578 Bugs: ProtocolBugs{
7579 SendCurve: bogusCurve,
7580 },
7581 },
7582 shouldFail: true,
7583 expectedError: ":WRONG_CURVE:",
7584 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007585
7586 testCases = append(testCases, testCase{
7587 name: "UnsupportedCurve",
7588 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007589 MaxVersion: VersionTLS12,
7590 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7591 CurvePreferences: []CurveID{CurveP256},
7592 Bugs: ProtocolBugs{
7593 IgnorePeerCurvePreferences: true,
7594 },
7595 },
7596 flags: []string{"-p384-only"},
7597 shouldFail: true,
7598 expectedError: ":WRONG_CURVE:",
7599 })
7600
David Benjamin4f921572016-07-17 14:20:10 +02007601 testCases = append(testCases, testCase{
7602 // TODO(davidben): Add a TLS 1.3 version where
7603 // HelloRetryRequest requests an unsupported curve.
7604 name: "UnsupportedCurve-ServerHello-TLS13",
7605 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007606 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02007607 CurvePreferences: []CurveID{CurveP384},
7608 Bugs: ProtocolBugs{
7609 SendCurve: CurveP256,
7610 },
7611 },
7612 flags: []string{"-p384-only"},
7613 shouldFail: true,
7614 expectedError: ":WRONG_CURVE:",
7615 })
7616
David Benjamin4c3ddf72016-06-29 18:13:53 -04007617 // Test invalid curve points.
7618 testCases = append(testCases, testCase{
7619 name: "InvalidECDHPoint-Client",
7620 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007621 MaxVersion: VersionTLS12,
7622 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7623 CurvePreferences: []CurveID{CurveP256},
7624 Bugs: ProtocolBugs{
7625 InvalidECDHPoint: true,
7626 },
7627 },
7628 shouldFail: true,
7629 expectedError: ":INVALID_ENCODING:",
7630 })
7631 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007632 name: "InvalidECDHPoint-Client-TLS13",
7633 config: Config{
7634 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007635 CurvePreferences: []CurveID{CurveP256},
7636 Bugs: ProtocolBugs{
7637 InvalidECDHPoint: true,
7638 },
7639 },
7640 shouldFail: true,
7641 expectedError: ":INVALID_ENCODING:",
7642 })
7643 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007644 testType: serverTest,
7645 name: "InvalidECDHPoint-Server",
7646 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007647 MaxVersion: VersionTLS12,
7648 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7649 CurvePreferences: []CurveID{CurveP256},
7650 Bugs: ProtocolBugs{
7651 InvalidECDHPoint: true,
7652 },
7653 },
7654 shouldFail: true,
7655 expectedError: ":INVALID_ENCODING:",
7656 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007657 testCases = append(testCases, testCase{
7658 testType: serverTest,
7659 name: "InvalidECDHPoint-Server-TLS13",
7660 config: Config{
7661 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007662 CurvePreferences: []CurveID{CurveP256},
7663 Bugs: ProtocolBugs{
7664 InvalidECDHPoint: true,
7665 },
7666 },
7667 shouldFail: true,
7668 expectedError: ":INVALID_ENCODING:",
7669 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007670}
7671
Matt Braithwaite54217e42016-06-13 13:03:47 -07007672func addCECPQ1Tests() {
7673 testCases = append(testCases, testCase{
7674 testType: clientTest,
7675 name: "CECPQ1-Client-BadX25519Part",
7676 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007677 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007678 MinVersion: VersionTLS12,
7679 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7680 Bugs: ProtocolBugs{
7681 CECPQ1BadX25519Part: true,
7682 },
7683 },
7684 flags: []string{"-cipher", "kCECPQ1"},
7685 shouldFail: true,
7686 expectedLocalError: "local error: bad record MAC",
7687 })
7688 testCases = append(testCases, testCase{
7689 testType: clientTest,
7690 name: "CECPQ1-Client-BadNewhopePart",
7691 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007692 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007693 MinVersion: VersionTLS12,
7694 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7695 Bugs: ProtocolBugs{
7696 CECPQ1BadNewhopePart: true,
7697 },
7698 },
7699 flags: []string{"-cipher", "kCECPQ1"},
7700 shouldFail: true,
7701 expectedLocalError: "local error: bad record MAC",
7702 })
7703 testCases = append(testCases, testCase{
7704 testType: serverTest,
7705 name: "CECPQ1-Server-BadX25519Part",
7706 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007707 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007708 MinVersion: VersionTLS12,
7709 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7710 Bugs: ProtocolBugs{
7711 CECPQ1BadX25519Part: true,
7712 },
7713 },
7714 flags: []string{"-cipher", "kCECPQ1"},
7715 shouldFail: true,
7716 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7717 })
7718 testCases = append(testCases, testCase{
7719 testType: serverTest,
7720 name: "CECPQ1-Server-BadNewhopePart",
7721 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007722 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007723 MinVersion: VersionTLS12,
7724 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7725 Bugs: ProtocolBugs{
7726 CECPQ1BadNewhopePart: true,
7727 },
7728 },
7729 flags: []string{"-cipher", "kCECPQ1"},
7730 shouldFail: true,
7731 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7732 })
7733}
7734
David Benjamin5c4e8572016-08-19 17:44:53 -04007735func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007736 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007737 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007738 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007739 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007740 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7741 Bugs: ProtocolBugs{
7742 // This is a 1234-bit prime number, generated
7743 // with:
7744 // openssl gendh 1234 | openssl asn1parse -i
7745 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7746 },
7747 },
David Benjamin9e68f192016-06-30 14:55:33 -04007748 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007749 })
7750 testCases = append(testCases, testCase{
7751 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007752 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007753 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007754 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007755 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7756 },
7757 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007758 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007759 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007760}
7761
David Benjaminc9ae27c2016-06-24 22:56:37 -04007762func addTLS13RecordTests() {
7763 testCases = append(testCases, testCase{
7764 name: "TLS13-RecordPadding",
7765 config: Config{
7766 MaxVersion: VersionTLS13,
7767 MinVersion: VersionTLS13,
7768 Bugs: ProtocolBugs{
7769 RecordPadding: 10,
7770 },
7771 },
7772 })
7773
7774 testCases = append(testCases, testCase{
7775 name: "TLS13-EmptyRecords",
7776 config: Config{
7777 MaxVersion: VersionTLS13,
7778 MinVersion: VersionTLS13,
7779 Bugs: ProtocolBugs{
7780 OmitRecordContents: true,
7781 },
7782 },
7783 shouldFail: true,
7784 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7785 })
7786
7787 testCases = append(testCases, testCase{
7788 name: "TLS13-OnlyPadding",
7789 config: Config{
7790 MaxVersion: VersionTLS13,
7791 MinVersion: VersionTLS13,
7792 Bugs: ProtocolBugs{
7793 OmitRecordContents: true,
7794 RecordPadding: 10,
7795 },
7796 },
7797 shouldFail: true,
7798 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7799 })
7800
7801 testCases = append(testCases, testCase{
7802 name: "TLS13-WrongOuterRecord",
7803 config: Config{
7804 MaxVersion: VersionTLS13,
7805 MinVersion: VersionTLS13,
7806 Bugs: ProtocolBugs{
7807 OuterRecordType: recordTypeHandshake,
7808 },
7809 },
7810 shouldFail: true,
7811 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7812 })
7813}
7814
Steven Valdez5b986082016-09-01 12:29:49 -04007815func addSessionTicketTests() {
7816 testCases = append(testCases, testCase{
7817 // In TLS 1.2 and below, empty NewSessionTicket messages
7818 // mean the server changed its mind on sending a ticket.
7819 name: "SendEmptySessionTicket",
7820 config: Config{
7821 MaxVersion: VersionTLS12,
7822 Bugs: ProtocolBugs{
7823 SendEmptySessionTicket: true,
7824 },
7825 },
7826 flags: []string{"-expect-no-session"},
7827 })
7828
7829 // Test that the server ignores unknown PSK modes.
7830 testCases = append(testCases, testCase{
7831 testType: serverTest,
7832 name: "TLS13-SendUnknownModeSessionTicket-Server",
7833 config: Config{
7834 MaxVersion: VersionTLS13,
7835 Bugs: ProtocolBugs{
7836 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7837 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7838 },
7839 },
7840 resumeSession: true,
7841 expectedResumeVersion: VersionTLS13,
7842 })
7843
7844 // Test that the server declines sessions with no matching key exchange mode.
7845 testCases = append(testCases, testCase{
7846 testType: serverTest,
7847 name: "TLS13-SendBadKEModeSessionTicket-Server",
7848 config: Config{
7849 MaxVersion: VersionTLS13,
7850 Bugs: ProtocolBugs{
7851 SendPSKKeyExchangeModes: []byte{0x1a},
7852 },
7853 },
7854 resumeSession: true,
7855 expectResumeRejected: true,
7856 })
7857
7858 // Test that the server declines sessions with no matching auth mode.
7859 testCases = append(testCases, testCase{
7860 testType: serverTest,
7861 name: "TLS13-SendBadAuthModeSessionTicket-Server",
7862 config: Config{
7863 MaxVersion: VersionTLS13,
7864 Bugs: ProtocolBugs{
7865 SendPSKAuthModes: []byte{0x1a},
7866 },
7867 },
7868 resumeSession: true,
7869 expectResumeRejected: true,
7870 })
7871
7872 // Test that the client ignores unknown PSK modes.
7873 testCases = append(testCases, testCase{
7874 testType: clientTest,
7875 name: "TLS13-SendUnknownModeSessionTicket-Client",
7876 config: Config{
7877 MaxVersion: VersionTLS13,
7878 Bugs: ProtocolBugs{
7879 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7880 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7881 },
7882 },
7883 resumeSession: true,
7884 expectedResumeVersion: VersionTLS13,
7885 })
7886
7887 // Test that the client ignores tickets with no matching key exchange mode.
7888 testCases = append(testCases, testCase{
7889 testType: clientTest,
7890 name: "TLS13-SendBadKEModeSessionTicket-Client",
7891 config: Config{
7892 MaxVersion: VersionTLS13,
7893 Bugs: ProtocolBugs{
7894 SendPSKKeyExchangeModes: []byte{0x1a},
7895 },
7896 },
7897 flags: []string{"-expect-no-session"},
7898 })
7899
7900 // Test that the client ignores tickets with no matching auth mode.
7901 testCases = append(testCases, testCase{
7902 testType: clientTest,
7903 name: "TLS13-SendBadAuthModeSessionTicket-Client",
7904 config: Config{
7905 MaxVersion: VersionTLS13,
7906 Bugs: ProtocolBugs{
7907 SendPSKAuthModes: []byte{0x1a},
7908 },
7909 },
7910 flags: []string{"-expect-no-session"},
7911 })
7912}
7913
David Benjamin82261be2016-07-07 14:32:50 -07007914func addChangeCipherSpecTests() {
7915 // Test missing ChangeCipherSpecs.
7916 testCases = append(testCases, testCase{
7917 name: "SkipChangeCipherSpec-Client",
7918 config: Config{
7919 MaxVersion: VersionTLS12,
7920 Bugs: ProtocolBugs{
7921 SkipChangeCipherSpec: true,
7922 },
7923 },
7924 shouldFail: true,
7925 expectedError: ":UNEXPECTED_RECORD:",
7926 })
7927 testCases = append(testCases, testCase{
7928 testType: serverTest,
7929 name: "SkipChangeCipherSpec-Server",
7930 config: Config{
7931 MaxVersion: VersionTLS12,
7932 Bugs: ProtocolBugs{
7933 SkipChangeCipherSpec: true,
7934 },
7935 },
7936 shouldFail: true,
7937 expectedError: ":UNEXPECTED_RECORD:",
7938 })
7939 testCases = append(testCases, testCase{
7940 testType: serverTest,
7941 name: "SkipChangeCipherSpec-Server-NPN",
7942 config: Config{
7943 MaxVersion: VersionTLS12,
7944 NextProtos: []string{"bar"},
7945 Bugs: ProtocolBugs{
7946 SkipChangeCipherSpec: true,
7947 },
7948 },
7949 flags: []string{
7950 "-advertise-npn", "\x03foo\x03bar\x03baz",
7951 },
7952 shouldFail: true,
7953 expectedError: ":UNEXPECTED_RECORD:",
7954 })
7955
7956 // Test synchronization between the handshake and ChangeCipherSpec.
7957 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7958 // rejected. Test both with and without handshake packing to handle both
7959 // when the partial post-CCS message is in its own record and when it is
7960 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007961 for _, packed := range []bool{false, true} {
7962 var suffix string
7963 if packed {
7964 suffix = "-Packed"
7965 }
7966
7967 testCases = append(testCases, testCase{
7968 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7969 config: Config{
7970 MaxVersion: VersionTLS12,
7971 Bugs: ProtocolBugs{
7972 FragmentAcrossChangeCipherSpec: true,
7973 PackHandshakeFlight: packed,
7974 },
7975 },
7976 shouldFail: true,
7977 expectedError: ":UNEXPECTED_RECORD:",
7978 })
7979 testCases = append(testCases, testCase{
7980 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7981 config: Config{
7982 MaxVersion: VersionTLS12,
7983 },
7984 resumeSession: true,
7985 resumeConfig: &Config{
7986 MaxVersion: VersionTLS12,
7987 Bugs: ProtocolBugs{
7988 FragmentAcrossChangeCipherSpec: true,
7989 PackHandshakeFlight: packed,
7990 },
7991 },
7992 shouldFail: true,
7993 expectedError: ":UNEXPECTED_RECORD:",
7994 })
7995 testCases = append(testCases, testCase{
7996 testType: serverTest,
7997 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7998 config: Config{
7999 MaxVersion: VersionTLS12,
8000 Bugs: ProtocolBugs{
8001 FragmentAcrossChangeCipherSpec: true,
8002 PackHandshakeFlight: packed,
8003 },
8004 },
8005 shouldFail: true,
8006 expectedError: ":UNEXPECTED_RECORD:",
8007 })
8008 testCases = append(testCases, testCase{
8009 testType: serverTest,
8010 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8011 config: Config{
8012 MaxVersion: VersionTLS12,
8013 },
8014 resumeSession: true,
8015 resumeConfig: &Config{
8016 MaxVersion: VersionTLS12,
8017 Bugs: ProtocolBugs{
8018 FragmentAcrossChangeCipherSpec: true,
8019 PackHandshakeFlight: packed,
8020 },
8021 },
8022 shouldFail: true,
8023 expectedError: ":UNEXPECTED_RECORD:",
8024 })
8025 testCases = append(testCases, testCase{
8026 testType: serverTest,
8027 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8028 config: Config{
8029 MaxVersion: VersionTLS12,
8030 NextProtos: []string{"bar"},
8031 Bugs: ProtocolBugs{
8032 FragmentAcrossChangeCipherSpec: true,
8033 PackHandshakeFlight: packed,
8034 },
8035 },
8036 flags: []string{
8037 "-advertise-npn", "\x03foo\x03bar\x03baz",
8038 },
8039 shouldFail: true,
8040 expectedError: ":UNEXPECTED_RECORD:",
8041 })
8042 }
8043
David Benjamin61672812016-07-14 23:10:43 -04008044 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8045 // messages in the handshake queue. Do this by testing the server
8046 // reading the client Finished, reversing the flight so Finished comes
8047 // first.
8048 testCases = append(testCases, testCase{
8049 protocol: dtls,
8050 testType: serverTest,
8051 name: "SendUnencryptedFinished-DTLS",
8052 config: Config{
8053 MaxVersion: VersionTLS12,
8054 Bugs: ProtocolBugs{
8055 SendUnencryptedFinished: true,
8056 ReverseHandshakeFragments: true,
8057 },
8058 },
8059 shouldFail: true,
8060 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8061 })
8062
Steven Valdez143e8b32016-07-11 13:19:03 -04008063 // Test synchronization between encryption changes and the handshake in
8064 // TLS 1.3, where ChangeCipherSpec is implicit.
8065 testCases = append(testCases, testCase{
8066 name: "PartialEncryptedExtensionsWithServerHello",
8067 config: Config{
8068 MaxVersion: VersionTLS13,
8069 Bugs: ProtocolBugs{
8070 PartialEncryptedExtensionsWithServerHello: true,
8071 },
8072 },
8073 shouldFail: true,
8074 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8075 })
8076 testCases = append(testCases, testCase{
8077 testType: serverTest,
8078 name: "PartialClientFinishedWithClientHello",
8079 config: Config{
8080 MaxVersion: VersionTLS13,
8081 Bugs: ProtocolBugs{
8082 PartialClientFinishedWithClientHello: true,
8083 },
8084 },
8085 shouldFail: true,
8086 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8087 })
8088
David Benjamin82261be2016-07-07 14:32:50 -07008089 // Test that early ChangeCipherSpecs are handled correctly.
8090 testCases = append(testCases, testCase{
8091 testType: serverTest,
8092 name: "EarlyChangeCipherSpec-server-1",
8093 config: Config{
8094 MaxVersion: VersionTLS12,
8095 Bugs: ProtocolBugs{
8096 EarlyChangeCipherSpec: 1,
8097 },
8098 },
8099 shouldFail: true,
8100 expectedError: ":UNEXPECTED_RECORD:",
8101 })
8102 testCases = append(testCases, testCase{
8103 testType: serverTest,
8104 name: "EarlyChangeCipherSpec-server-2",
8105 config: Config{
8106 MaxVersion: VersionTLS12,
8107 Bugs: ProtocolBugs{
8108 EarlyChangeCipherSpec: 2,
8109 },
8110 },
8111 shouldFail: true,
8112 expectedError: ":UNEXPECTED_RECORD:",
8113 })
8114 testCases = append(testCases, testCase{
8115 protocol: dtls,
8116 name: "StrayChangeCipherSpec",
8117 config: Config{
8118 // TODO(davidben): Once DTLS 1.3 exists, test
8119 // that stray ChangeCipherSpec messages are
8120 // rejected.
8121 MaxVersion: VersionTLS12,
8122 Bugs: ProtocolBugs{
8123 StrayChangeCipherSpec: true,
8124 },
8125 },
8126 })
8127
8128 // Test that the contents of ChangeCipherSpec are checked.
8129 testCases = append(testCases, testCase{
8130 name: "BadChangeCipherSpec-1",
8131 config: Config{
8132 MaxVersion: VersionTLS12,
8133 Bugs: ProtocolBugs{
8134 BadChangeCipherSpec: []byte{2},
8135 },
8136 },
8137 shouldFail: true,
8138 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8139 })
8140 testCases = append(testCases, testCase{
8141 name: "BadChangeCipherSpec-2",
8142 config: Config{
8143 MaxVersion: VersionTLS12,
8144 Bugs: ProtocolBugs{
8145 BadChangeCipherSpec: []byte{1, 1},
8146 },
8147 },
8148 shouldFail: true,
8149 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8150 })
8151 testCases = append(testCases, testCase{
8152 protocol: dtls,
8153 name: "BadChangeCipherSpec-DTLS-1",
8154 config: Config{
8155 MaxVersion: VersionTLS12,
8156 Bugs: ProtocolBugs{
8157 BadChangeCipherSpec: []byte{2},
8158 },
8159 },
8160 shouldFail: true,
8161 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8162 })
8163 testCases = append(testCases, testCase{
8164 protocol: dtls,
8165 name: "BadChangeCipherSpec-DTLS-2",
8166 config: Config{
8167 MaxVersion: VersionTLS12,
8168 Bugs: ProtocolBugs{
8169 BadChangeCipherSpec: []byte{1, 1},
8170 },
8171 },
8172 shouldFail: true,
8173 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8174 })
8175}
8176
David Benjamincd2c8062016-09-09 11:28:16 -04008177type perMessageTest struct {
8178 messageType uint8
8179 test testCase
8180}
8181
8182// makePerMessageTests returns a series of test templates which cover each
8183// message in the TLS handshake. These may be used with bugs like
8184// WrongMessageType to fully test a per-message bug.
8185func makePerMessageTests() []perMessageTest {
8186 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008187 for _, protocol := range []protocol{tls, dtls} {
8188 var suffix string
8189 if protocol == dtls {
8190 suffix = "-DTLS"
8191 }
8192
David Benjamincd2c8062016-09-09 11:28:16 -04008193 ret = append(ret, perMessageTest{
8194 messageType: typeClientHello,
8195 test: testCase{
8196 protocol: protocol,
8197 testType: serverTest,
8198 name: "ClientHello" + suffix,
8199 config: Config{
8200 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008201 },
8202 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008203 })
8204
8205 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008206 ret = append(ret, perMessageTest{
8207 messageType: typeHelloVerifyRequest,
8208 test: testCase{
8209 protocol: protocol,
8210 name: "HelloVerifyRequest" + suffix,
8211 config: Config{
8212 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008213 },
8214 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008215 })
8216 }
8217
David Benjamincd2c8062016-09-09 11:28:16 -04008218 ret = append(ret, perMessageTest{
8219 messageType: typeServerHello,
8220 test: testCase{
8221 protocol: protocol,
8222 name: "ServerHello" + suffix,
8223 config: Config{
8224 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008225 },
8226 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008227 })
8228
David Benjamincd2c8062016-09-09 11:28:16 -04008229 ret = append(ret, perMessageTest{
8230 messageType: typeCertificate,
8231 test: testCase{
8232 protocol: protocol,
8233 name: "ServerCertificate" + suffix,
8234 config: Config{
8235 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008236 },
8237 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008238 })
8239
David Benjamincd2c8062016-09-09 11:28:16 -04008240 ret = append(ret, perMessageTest{
8241 messageType: typeCertificateStatus,
8242 test: testCase{
8243 protocol: protocol,
8244 name: "CertificateStatus" + suffix,
8245 config: Config{
8246 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008247 },
David Benjamincd2c8062016-09-09 11:28:16 -04008248 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008249 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008250 })
8251
David Benjamincd2c8062016-09-09 11:28:16 -04008252 ret = append(ret, perMessageTest{
8253 messageType: typeServerKeyExchange,
8254 test: testCase{
8255 protocol: protocol,
8256 name: "ServerKeyExchange" + suffix,
8257 config: Config{
8258 MaxVersion: VersionTLS12,
8259 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008260 },
8261 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008262 })
8263
David Benjamincd2c8062016-09-09 11:28:16 -04008264 ret = append(ret, perMessageTest{
8265 messageType: typeCertificateRequest,
8266 test: testCase{
8267 protocol: protocol,
8268 name: "CertificateRequest" + suffix,
8269 config: Config{
8270 MaxVersion: VersionTLS12,
8271 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008272 },
8273 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008274 })
8275
David Benjamincd2c8062016-09-09 11:28:16 -04008276 ret = append(ret, perMessageTest{
8277 messageType: typeServerHelloDone,
8278 test: testCase{
8279 protocol: protocol,
8280 name: "ServerHelloDone" + suffix,
8281 config: Config{
8282 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008283 },
8284 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008285 })
8286
David Benjamincd2c8062016-09-09 11:28:16 -04008287 ret = append(ret, perMessageTest{
8288 messageType: typeCertificate,
8289 test: testCase{
8290 testType: serverTest,
8291 protocol: protocol,
8292 name: "ClientCertificate" + suffix,
8293 config: Config{
8294 Certificates: []Certificate{rsaCertificate},
8295 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008296 },
David Benjamincd2c8062016-09-09 11:28:16 -04008297 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008298 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008299 })
8300
David Benjamincd2c8062016-09-09 11:28:16 -04008301 ret = append(ret, perMessageTest{
8302 messageType: typeCertificateVerify,
8303 test: testCase{
8304 testType: serverTest,
8305 protocol: protocol,
8306 name: "CertificateVerify" + suffix,
8307 config: Config{
8308 Certificates: []Certificate{rsaCertificate},
8309 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008310 },
David Benjamincd2c8062016-09-09 11:28:16 -04008311 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008312 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008313 })
8314
David Benjamincd2c8062016-09-09 11:28:16 -04008315 ret = append(ret, perMessageTest{
8316 messageType: typeClientKeyExchange,
8317 test: testCase{
8318 testType: serverTest,
8319 protocol: protocol,
8320 name: "ClientKeyExchange" + suffix,
8321 config: Config{
8322 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008323 },
8324 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008325 })
8326
8327 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008328 ret = append(ret, perMessageTest{
8329 messageType: typeNextProtocol,
8330 test: testCase{
8331 testType: serverTest,
8332 protocol: protocol,
8333 name: "NextProtocol" + suffix,
8334 config: Config{
8335 MaxVersion: VersionTLS12,
8336 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008337 },
David Benjamincd2c8062016-09-09 11:28:16 -04008338 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008339 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008340 })
8341
David Benjamincd2c8062016-09-09 11:28:16 -04008342 ret = append(ret, perMessageTest{
8343 messageType: typeChannelID,
8344 test: testCase{
8345 testType: serverTest,
8346 protocol: protocol,
8347 name: "ChannelID" + suffix,
8348 config: Config{
8349 MaxVersion: VersionTLS12,
8350 ChannelID: channelIDKey,
8351 },
8352 flags: []string{
8353 "-expect-channel-id",
8354 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008355 },
8356 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008357 })
8358 }
8359
David Benjamincd2c8062016-09-09 11:28:16 -04008360 ret = append(ret, perMessageTest{
8361 messageType: typeFinished,
8362 test: testCase{
8363 testType: serverTest,
8364 protocol: protocol,
8365 name: "ClientFinished" + suffix,
8366 config: Config{
8367 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008368 },
8369 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008370 })
8371
David Benjamincd2c8062016-09-09 11:28:16 -04008372 ret = append(ret, perMessageTest{
8373 messageType: typeNewSessionTicket,
8374 test: testCase{
8375 protocol: protocol,
8376 name: "NewSessionTicket" + suffix,
8377 config: Config{
8378 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008379 },
8380 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008381 })
8382
David Benjamincd2c8062016-09-09 11:28:16 -04008383 ret = append(ret, perMessageTest{
8384 messageType: typeFinished,
8385 test: testCase{
8386 protocol: protocol,
8387 name: "ServerFinished" + suffix,
8388 config: Config{
8389 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008390 },
8391 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008392 })
8393
8394 }
David Benjamincd2c8062016-09-09 11:28:16 -04008395
8396 ret = append(ret, perMessageTest{
8397 messageType: typeClientHello,
8398 test: testCase{
8399 testType: serverTest,
8400 name: "TLS13-ClientHello",
8401 config: Config{
8402 MaxVersion: VersionTLS13,
8403 },
8404 },
8405 })
8406
8407 ret = append(ret, perMessageTest{
8408 messageType: typeServerHello,
8409 test: testCase{
8410 name: "TLS13-ServerHello",
8411 config: Config{
8412 MaxVersion: VersionTLS13,
8413 },
8414 },
8415 })
8416
8417 ret = append(ret, perMessageTest{
8418 messageType: typeEncryptedExtensions,
8419 test: testCase{
8420 name: "TLS13-EncryptedExtensions",
8421 config: Config{
8422 MaxVersion: VersionTLS13,
8423 },
8424 },
8425 })
8426
8427 ret = append(ret, perMessageTest{
8428 messageType: typeCertificateRequest,
8429 test: testCase{
8430 name: "TLS13-CertificateRequest",
8431 config: Config{
8432 MaxVersion: VersionTLS13,
8433 ClientAuth: RequireAnyClientCert,
8434 },
8435 },
8436 })
8437
8438 ret = append(ret, perMessageTest{
8439 messageType: typeCertificate,
8440 test: testCase{
8441 name: "TLS13-ServerCertificate",
8442 config: Config{
8443 MaxVersion: VersionTLS13,
8444 },
8445 },
8446 })
8447
8448 ret = append(ret, perMessageTest{
8449 messageType: typeCertificateVerify,
8450 test: testCase{
8451 name: "TLS13-ServerCertificateVerify",
8452 config: Config{
8453 MaxVersion: VersionTLS13,
8454 },
8455 },
8456 })
8457
8458 ret = append(ret, perMessageTest{
8459 messageType: typeFinished,
8460 test: testCase{
8461 name: "TLS13-ServerFinished",
8462 config: Config{
8463 MaxVersion: VersionTLS13,
8464 },
8465 },
8466 })
8467
8468 ret = append(ret, perMessageTest{
8469 messageType: typeCertificate,
8470 test: testCase{
8471 testType: serverTest,
8472 name: "TLS13-ClientCertificate",
8473 config: Config{
8474 Certificates: []Certificate{rsaCertificate},
8475 MaxVersion: VersionTLS13,
8476 },
8477 flags: []string{"-require-any-client-certificate"},
8478 },
8479 })
8480
8481 ret = append(ret, perMessageTest{
8482 messageType: typeCertificateVerify,
8483 test: testCase{
8484 testType: serverTest,
8485 name: "TLS13-ClientCertificateVerify",
8486 config: Config{
8487 Certificates: []Certificate{rsaCertificate},
8488 MaxVersion: VersionTLS13,
8489 },
8490 flags: []string{"-require-any-client-certificate"},
8491 },
8492 })
8493
8494 ret = append(ret, perMessageTest{
8495 messageType: typeFinished,
8496 test: testCase{
8497 testType: serverTest,
8498 name: "TLS13-ClientFinished",
8499 config: Config{
8500 MaxVersion: VersionTLS13,
8501 },
8502 },
8503 })
8504
8505 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008506}
8507
David Benjamincd2c8062016-09-09 11:28:16 -04008508func addWrongMessageTypeTests() {
8509 for _, t := range makePerMessageTests() {
8510 t.test.name = "WrongMessageType-" + t.test.name
8511 t.test.config.Bugs.SendWrongMessageType = t.messageType
8512 t.test.shouldFail = true
8513 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8514 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008515
David Benjamincd2c8062016-09-09 11:28:16 -04008516 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8517 // In TLS 1.3, a bad ServerHello means the client sends
8518 // an unencrypted alert while the server expects
8519 // encryption, so the alert is not readable by runner.
8520 t.test.expectedLocalError = "local error: bad record MAC"
8521 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008522
David Benjamincd2c8062016-09-09 11:28:16 -04008523 testCases = append(testCases, t.test)
8524 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008525}
8526
David Benjamin639846e2016-09-09 11:41:18 -04008527func addTrailingMessageDataTests() {
8528 for _, t := range makePerMessageTests() {
8529 t.test.name = "TrailingMessageData-" + t.test.name
8530 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8531 t.test.shouldFail = true
8532 t.test.expectedError = ":DECODE_ERROR:"
8533 t.test.expectedLocalError = "remote error: error decoding message"
8534
8535 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8536 // In TLS 1.3, a bad ServerHello means the client sends
8537 // an unencrypted alert while the server expects
8538 // encryption, so the alert is not readable by runner.
8539 t.test.expectedLocalError = "local error: bad record MAC"
8540 }
8541
8542 if t.messageType == typeFinished {
8543 // Bad Finished messages read as the verify data having
8544 // the wrong length.
8545 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8546 t.test.expectedLocalError = "remote error: error decrypting message"
8547 }
8548
8549 testCases = append(testCases, t.test)
8550 }
8551}
8552
Steven Valdez143e8b32016-07-11 13:19:03 -04008553func addTLS13HandshakeTests() {
8554 testCases = append(testCases, testCase{
8555 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008556 name: "NegotiatePSKResumption-TLS13",
8557 config: Config{
8558 MaxVersion: VersionTLS13,
8559 Bugs: ProtocolBugs{
8560 NegotiatePSKResumption: true,
8561 },
8562 },
8563 resumeSession: true,
8564 shouldFail: true,
8565 expectedError: ":UNEXPECTED_EXTENSION:",
8566 })
8567
8568 testCases = append(testCases, testCase{
8569 testType: clientTest,
8570 name: "OmitServerHelloSignatureAlgorithms",
8571 config: Config{
8572 MaxVersion: VersionTLS13,
8573 Bugs: ProtocolBugs{
8574 OmitServerHelloSignatureAlgorithms: true,
8575 },
8576 },
8577 shouldFail: true,
8578 expectedError: ":UNEXPECTED_EXTENSION:",
8579 })
8580
8581 testCases = append(testCases, testCase{
8582 testType: clientTest,
8583 name: "IncludeServerHelloSignatureAlgorithms",
8584 config: Config{
8585 MaxVersion: VersionTLS13,
8586 Bugs: ProtocolBugs{
8587 IncludeServerHelloSignatureAlgorithms: true,
8588 },
8589 },
8590 resumeSession: true,
8591 shouldFail: true,
8592 expectedError: ":UNEXPECTED_EXTENSION:",
8593 })
8594
8595 testCases = append(testCases, testCase{
8596 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008597 name: "MissingKeyShare-Client",
8598 config: Config{
8599 MaxVersion: VersionTLS13,
8600 Bugs: ProtocolBugs{
8601 MissingKeyShare: true,
8602 },
8603 },
8604 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008605 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008606 })
8607
8608 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008609 testType: serverTest,
8610 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008611 config: Config{
8612 MaxVersion: VersionTLS13,
8613 Bugs: ProtocolBugs{
8614 MissingKeyShare: true,
8615 },
8616 },
8617 shouldFail: true,
8618 expectedError: ":MISSING_KEY_SHARE:",
8619 })
8620
8621 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008622 testType: serverTest,
8623 name: "DuplicateKeyShares",
8624 config: Config{
8625 MaxVersion: VersionTLS13,
8626 Bugs: ProtocolBugs{
8627 DuplicateKeyShares: true,
8628 },
8629 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008630 shouldFail: true,
8631 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008632 })
8633
8634 testCases = append(testCases, testCase{
8635 testType: clientTest,
8636 name: "EmptyEncryptedExtensions",
8637 config: Config{
8638 MaxVersion: VersionTLS13,
8639 Bugs: ProtocolBugs{
8640 EmptyEncryptedExtensions: true,
8641 },
8642 },
8643 shouldFail: true,
8644 expectedLocalError: "remote error: error decoding message",
8645 })
8646
8647 testCases = append(testCases, testCase{
8648 testType: clientTest,
8649 name: "EncryptedExtensionsWithKeyShare",
8650 config: Config{
8651 MaxVersion: VersionTLS13,
8652 Bugs: ProtocolBugs{
8653 EncryptedExtensionsWithKeyShare: true,
8654 },
8655 },
8656 shouldFail: true,
8657 expectedLocalError: "remote error: unsupported extension",
8658 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008659
8660 testCases = append(testCases, testCase{
8661 testType: serverTest,
8662 name: "SendHelloRetryRequest",
8663 config: Config{
8664 MaxVersion: VersionTLS13,
8665 // Require a HelloRetryRequest for every curve.
8666 DefaultCurves: []CurveID{},
8667 },
8668 expectedCurveID: CurveX25519,
8669 })
8670
8671 testCases = append(testCases, testCase{
8672 testType: serverTest,
8673 name: "SendHelloRetryRequest-2",
8674 config: Config{
8675 MaxVersion: VersionTLS13,
8676 DefaultCurves: []CurveID{CurveP384},
8677 },
8678 // Although the ClientHello did not predict our preferred curve,
8679 // we always select it whether it is predicted or not.
8680 expectedCurveID: CurveX25519,
8681 })
8682
8683 testCases = append(testCases, testCase{
8684 name: "UnknownCurve-HelloRetryRequest",
8685 config: Config{
8686 MaxVersion: VersionTLS13,
8687 // P-384 requires HelloRetryRequest in BoringSSL.
8688 CurvePreferences: []CurveID{CurveP384},
8689 Bugs: ProtocolBugs{
8690 SendHelloRetryRequestCurve: bogusCurve,
8691 },
8692 },
8693 shouldFail: true,
8694 expectedError: ":WRONG_CURVE:",
8695 })
8696
8697 testCases = append(testCases, testCase{
8698 name: "DisabledCurve-HelloRetryRequest",
8699 config: Config{
8700 MaxVersion: VersionTLS13,
8701 CurvePreferences: []CurveID{CurveP256},
8702 Bugs: ProtocolBugs{
8703 IgnorePeerCurvePreferences: true,
8704 },
8705 },
8706 flags: []string{"-p384-only"},
8707 shouldFail: true,
8708 expectedError: ":WRONG_CURVE:",
8709 })
8710
8711 testCases = append(testCases, testCase{
8712 name: "UnnecessaryHelloRetryRequest",
8713 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04008714 MaxVersion: VersionTLS13,
8715 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04008716 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04008717 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04008718 },
8719 },
8720 shouldFail: true,
8721 expectedError: ":WRONG_CURVE:",
8722 })
8723
8724 testCases = append(testCases, testCase{
8725 name: "SecondHelloRetryRequest",
8726 config: Config{
8727 MaxVersion: VersionTLS13,
8728 // P-384 requires HelloRetryRequest in BoringSSL.
8729 CurvePreferences: []CurveID{CurveP384},
8730 Bugs: ProtocolBugs{
8731 SecondHelloRetryRequest: true,
8732 },
8733 },
8734 shouldFail: true,
8735 expectedError: ":UNEXPECTED_MESSAGE:",
8736 })
8737
8738 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04008739 name: "HelloRetryRequest-Empty",
8740 config: Config{
8741 MaxVersion: VersionTLS13,
8742 Bugs: ProtocolBugs{
8743 AlwaysSendHelloRetryRequest: true,
8744 },
8745 },
8746 shouldFail: true,
8747 expectedError: ":DECODE_ERROR:",
8748 })
8749
8750 testCases = append(testCases, testCase{
8751 name: "HelloRetryRequest-DuplicateCurve",
8752 config: Config{
8753 MaxVersion: VersionTLS13,
8754 // P-384 requires a HelloRetryRequest against BoringSSL's default
8755 // configuration. Assert this ExpectMissingKeyShare.
8756 CurvePreferences: []CurveID{CurveP384},
8757 Bugs: ProtocolBugs{
8758 ExpectMissingKeyShare: true,
8759 DuplicateHelloRetryRequestExtensions: true,
8760 },
8761 },
8762 shouldFail: true,
8763 expectedError: ":DUPLICATE_EXTENSION:",
8764 expectedLocalError: "remote error: illegal parameter",
8765 })
8766
8767 testCases = append(testCases, testCase{
8768 name: "HelloRetryRequest-Cookie",
8769 config: Config{
8770 MaxVersion: VersionTLS13,
8771 Bugs: ProtocolBugs{
8772 SendHelloRetryRequestCookie: []byte("cookie"),
8773 },
8774 },
8775 })
8776
8777 testCases = append(testCases, testCase{
8778 name: "HelloRetryRequest-DuplicateCookie",
8779 config: Config{
8780 MaxVersion: VersionTLS13,
8781 Bugs: ProtocolBugs{
8782 SendHelloRetryRequestCookie: []byte("cookie"),
8783 DuplicateHelloRetryRequestExtensions: true,
8784 },
8785 },
8786 shouldFail: true,
8787 expectedError: ":DUPLICATE_EXTENSION:",
8788 expectedLocalError: "remote error: illegal parameter",
8789 })
8790
8791 testCases = append(testCases, testCase{
8792 name: "HelloRetryRequest-EmptyCookie",
8793 config: Config{
8794 MaxVersion: VersionTLS13,
8795 Bugs: ProtocolBugs{
8796 SendHelloRetryRequestCookie: []byte{},
8797 },
8798 },
8799 shouldFail: true,
8800 expectedError: ":DECODE_ERROR:",
8801 })
8802
8803 testCases = append(testCases, testCase{
8804 name: "HelloRetryRequest-Cookie-Curve",
8805 config: Config{
8806 MaxVersion: VersionTLS13,
8807 // P-384 requires HelloRetryRequest in BoringSSL.
8808 CurvePreferences: []CurveID{CurveP384},
8809 Bugs: ProtocolBugs{
8810 SendHelloRetryRequestCookie: []byte("cookie"),
8811 ExpectMissingKeyShare: true,
8812 },
8813 },
8814 })
8815
8816 testCases = append(testCases, testCase{
8817 name: "HelloRetryRequest-Unknown",
8818 config: Config{
8819 MaxVersion: VersionTLS13,
8820 Bugs: ProtocolBugs{
8821 CustomHelloRetryRequestExtension: "extension",
8822 },
8823 },
8824 shouldFail: true,
8825 expectedError: ":UNEXPECTED_EXTENSION:",
8826 expectedLocalError: "remote error: unsupported extension",
8827 })
8828
8829 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008830 testType: serverTest,
8831 name: "SecondClientHelloMissingKeyShare",
8832 config: Config{
8833 MaxVersion: VersionTLS13,
8834 DefaultCurves: []CurveID{},
8835 Bugs: ProtocolBugs{
8836 SecondClientHelloMissingKeyShare: true,
8837 },
8838 },
8839 shouldFail: true,
8840 expectedError: ":MISSING_KEY_SHARE:",
8841 })
8842
8843 testCases = append(testCases, testCase{
8844 testType: serverTest,
8845 name: "SecondClientHelloWrongCurve",
8846 config: Config{
8847 MaxVersion: VersionTLS13,
8848 DefaultCurves: []CurveID{},
8849 Bugs: ProtocolBugs{
8850 MisinterpretHelloRetryRequestCurve: CurveP521,
8851 },
8852 },
8853 shouldFail: true,
8854 expectedError: ":WRONG_CURVE:",
8855 })
8856
8857 testCases = append(testCases, testCase{
8858 name: "HelloRetryRequestVersionMismatch",
8859 config: Config{
8860 MaxVersion: VersionTLS13,
8861 // P-384 requires HelloRetryRequest in BoringSSL.
8862 CurvePreferences: []CurveID{CurveP384},
8863 Bugs: ProtocolBugs{
8864 SendServerHelloVersion: 0x0305,
8865 },
8866 },
8867 shouldFail: true,
8868 expectedError: ":WRONG_VERSION_NUMBER:",
8869 })
8870
8871 testCases = append(testCases, testCase{
8872 name: "HelloRetryRequestCurveMismatch",
8873 config: Config{
8874 MaxVersion: VersionTLS13,
8875 // P-384 requires HelloRetryRequest in BoringSSL.
8876 CurvePreferences: []CurveID{CurveP384},
8877 Bugs: ProtocolBugs{
8878 // Send P-384 (correct) in the HelloRetryRequest.
8879 SendHelloRetryRequestCurve: CurveP384,
8880 // But send P-256 in the ServerHello.
8881 SendCurve: CurveP256,
8882 },
8883 },
8884 shouldFail: true,
8885 expectedError: ":WRONG_CURVE:",
8886 })
8887
8888 // Test the server selecting a curve that requires a HelloRetryRequest
8889 // without sending it.
8890 testCases = append(testCases, testCase{
8891 name: "SkipHelloRetryRequest",
8892 config: Config{
8893 MaxVersion: VersionTLS13,
8894 // P-384 requires HelloRetryRequest in BoringSSL.
8895 CurvePreferences: []CurveID{CurveP384},
8896 Bugs: ProtocolBugs{
8897 SkipHelloRetryRequest: true,
8898 },
8899 },
8900 shouldFail: true,
8901 expectedError: ":WRONG_CURVE:",
8902 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008903
8904 testCases = append(testCases, testCase{
8905 name: "TLS13-RequestContextInHandshake",
8906 config: Config{
8907 MaxVersion: VersionTLS13,
8908 MinVersion: VersionTLS13,
8909 ClientAuth: RequireAnyClientCert,
8910 Bugs: ProtocolBugs{
8911 SendRequestContext: []byte("request context"),
8912 },
8913 },
8914 flags: []string{
8915 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8916 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8917 },
8918 shouldFail: true,
8919 expectedError: ":DECODE_ERROR:",
8920 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008921
8922 testCases = append(testCases, testCase{
8923 testType: serverTest,
8924 name: "TLS13-TrailingKeyShareData",
8925 config: Config{
8926 MaxVersion: VersionTLS13,
8927 Bugs: ProtocolBugs{
8928 TrailingKeyShareData: true,
8929 },
8930 },
8931 shouldFail: true,
8932 expectedError: ":DECODE_ERROR:",
8933 })
David Benjamin7f78df42016-10-05 22:33:19 -04008934
8935 testCases = append(testCases, testCase{
8936 name: "TLS13-AlwaysSelectPSKIdentity",
8937 config: Config{
8938 MaxVersion: VersionTLS13,
8939 Bugs: ProtocolBugs{
8940 AlwaysSelectPSKIdentity: true,
8941 },
8942 },
8943 shouldFail: true,
8944 expectedError: ":UNEXPECTED_EXTENSION:",
8945 })
8946
8947 testCases = append(testCases, testCase{
8948 name: "TLS13-InvalidPSKIdentity",
8949 config: Config{
8950 MaxVersion: VersionTLS13,
8951 Bugs: ProtocolBugs{
8952 SelectPSKIdentityOnResume: 1,
8953 },
8954 },
8955 resumeSession: true,
8956 shouldFail: true,
8957 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
8958 })
David Benjamin1286bee2016-10-07 15:25:06 -04008959
Steven Valdezaf3b8a92016-11-01 12:49:22 -04008960 testCases = append(testCases, testCase{
8961 testType: serverTest,
8962 name: "TLS13-ExtraPSKIdentity",
8963 config: Config{
8964 MaxVersion: VersionTLS13,
8965 Bugs: ProtocolBugs{
8966 ExtraPSKIdentity: true,
8967 },
8968 },
8969 resumeSession: true,
8970 })
8971
David Benjamin1286bee2016-10-07 15:25:06 -04008972 // Test that unknown NewSessionTicket extensions are tolerated.
8973 testCases = append(testCases, testCase{
8974 name: "TLS13-CustomTicketExtension",
8975 config: Config{
8976 MaxVersion: VersionTLS13,
8977 Bugs: ProtocolBugs{
8978 CustomTicketExtension: "1234",
8979 },
8980 },
8981 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008982}
8983
David Benjaminabbbee12016-10-31 19:20:42 -04008984func addTLS13CipherPreferenceTests() {
8985 // Test that client preference is honored if the shim has AES hardware
8986 // and ChaCha20-Poly1305 is preferred otherwise.
8987 testCases = append(testCases, testCase{
8988 testType: serverTest,
8989 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
8990 config: Config{
8991 MaxVersion: VersionTLS13,
8992 CipherSuites: []uint16{
8993 TLS_CHACHA20_POLY1305_SHA256,
8994 TLS_AES_128_GCM_SHA256,
8995 },
8996 },
8997 flags: []string{
8998 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
8999 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9000 },
9001 })
9002
9003 testCases = append(testCases, testCase{
9004 testType: serverTest,
9005 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9006 config: Config{
9007 MaxVersion: VersionTLS13,
9008 CipherSuites: []uint16{
9009 TLS_AES_128_GCM_SHA256,
9010 TLS_CHACHA20_POLY1305_SHA256,
9011 },
9012 },
9013 flags: []string{
9014 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9015 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9016 },
9017 })
9018
9019 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9020 // whether it has AES hardware.
9021 testCases = append(testCases, testCase{
9022 name: "TLS13-CipherPreference-Client",
9023 config: Config{
9024 MaxVersion: VersionTLS13,
9025 // Use the client cipher order. (This is the default but
9026 // is listed to be explicit.)
9027 PreferServerCipherSuites: false,
9028 },
9029 flags: []string{
9030 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9031 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9032 },
9033 })
9034}
9035
David Benjaminf3fbade2016-09-19 13:08:16 -04009036func addPeekTests() {
9037 // Test SSL_peek works, including on empty records.
9038 testCases = append(testCases, testCase{
9039 name: "Peek-Basic",
9040 sendEmptyRecords: 1,
9041 flags: []string{"-peek-then-read"},
9042 })
9043
9044 // Test SSL_peek can drive the initial handshake.
9045 testCases = append(testCases, testCase{
9046 name: "Peek-ImplicitHandshake",
9047 flags: []string{
9048 "-peek-then-read",
9049 "-implicit-handshake",
9050 },
9051 })
9052
9053 // Test SSL_peek can discover and drive a renegotiation.
9054 testCases = append(testCases, testCase{
9055 name: "Peek-Renegotiate",
9056 config: Config{
9057 MaxVersion: VersionTLS12,
9058 },
9059 renegotiate: 1,
9060 flags: []string{
9061 "-peek-then-read",
9062 "-renegotiate-freely",
9063 "-expect-total-renegotiations", "1",
9064 },
9065 })
9066
9067 // Test SSL_peek can discover a close_notify.
9068 testCases = append(testCases, testCase{
9069 name: "Peek-Shutdown",
9070 config: Config{
9071 Bugs: ProtocolBugs{
9072 ExpectCloseNotify: true,
9073 },
9074 },
9075 flags: []string{
9076 "-peek-then-read",
9077 "-check-close-notify",
9078 },
9079 })
9080
9081 // Test SSL_peek can discover an alert.
9082 testCases = append(testCases, testCase{
9083 name: "Peek-Alert",
9084 config: Config{
9085 Bugs: ProtocolBugs{
9086 SendSpuriousAlert: alertRecordOverflow,
9087 },
9088 },
9089 flags: []string{"-peek-then-read"},
9090 shouldFail: true,
9091 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9092 })
9093
9094 // Test SSL_peek can handle KeyUpdate.
9095 testCases = append(testCases, testCase{
9096 name: "Peek-KeyUpdate",
9097 config: Config{
9098 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009099 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009100 sendKeyUpdates: 1,
9101 keyUpdateRequest: keyUpdateNotRequested,
9102 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009103 })
9104}
9105
Adam Langley7c803a62015-06-15 15:35:05 -07009106func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009107 defer wg.Done()
9108
9109 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009110 var err error
9111
9112 if *mallocTest < 0 {
9113 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009114 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009115 } else {
9116 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9117 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009118 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009119 if err != nil {
9120 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9121 }
9122 break
9123 }
9124 }
9125 }
Adam Langley95c29f32014-06-20 12:00:00 -07009126 statusChan <- statusMsg{test: test, err: err}
9127 }
9128}
9129
9130type statusMsg struct {
9131 test *testCase
9132 started bool
9133 err error
9134}
9135
David Benjamin5f237bc2015-02-11 17:14:15 -05009136func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009137 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009138
David Benjamin5f237bc2015-02-11 17:14:15 -05009139 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009140 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009141 if !*pipe {
9142 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009143 var erase string
9144 for i := 0; i < lineLen; i++ {
9145 erase += "\b \b"
9146 }
9147 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009148 }
9149
Adam Langley95c29f32014-06-20 12:00:00 -07009150 if msg.started {
9151 started++
9152 } else {
9153 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009154
9155 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009156 if msg.err == errUnimplemented {
9157 if *pipe {
9158 // Print each test instead of a status line.
9159 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9160 }
9161 unimplemented++
9162 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9163 } else {
9164 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9165 failed++
9166 testOutput.addResult(msg.test.name, "FAIL")
9167 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009168 } else {
9169 if *pipe {
9170 // Print each test instead of a status line.
9171 fmt.Printf("PASSED (%s)\n", msg.test.name)
9172 }
9173 testOutput.addResult(msg.test.name, "PASS")
9174 }
Adam Langley95c29f32014-06-20 12:00:00 -07009175 }
9176
David Benjamin5f237bc2015-02-11 17:14:15 -05009177 if !*pipe {
9178 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009179 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009180 lineLen = len(line)
9181 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009182 }
Adam Langley95c29f32014-06-20 12:00:00 -07009183 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009184
9185 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009186}
9187
9188func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009189 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009190 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009191 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009192
Adam Langley7c803a62015-06-15 15:35:05 -07009193 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009194 addCipherSuiteTests()
9195 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009196 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009197 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009198 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009199 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009200 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009201 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009202 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009203 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009204 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009205 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009206 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009207 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009208 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009209 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009210 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009211 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009212 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009213 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07009214 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04009215 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009216 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009217 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009218 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009219 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009220 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009221 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009222 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009223 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009224 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009225
9226 var wg sync.WaitGroup
9227
Adam Langley7c803a62015-06-15 15:35:05 -07009228 statusChan := make(chan statusMsg, *numWorkers)
9229 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009230 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009231
EKRf71d7ed2016-08-06 13:25:12 -07009232 if len(*shimConfigFile) != 0 {
9233 encoded, err := ioutil.ReadFile(*shimConfigFile)
9234 if err != nil {
9235 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9236 os.Exit(1)
9237 }
9238
9239 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9240 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9241 os.Exit(1)
9242 }
9243 }
9244
David Benjamin025b3d32014-07-01 19:53:04 -04009245 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07009246
Adam Langley7c803a62015-06-15 15:35:05 -07009247 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07009248 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07009249 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07009250 }
9251
David Benjamin270f0a72016-03-17 14:41:36 -04009252 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04009253 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04009254 matched := true
9255 if len(*testToRun) != 0 {
9256 var err error
9257 matched, err = filepath.Match(*testToRun, testCases[i].name)
9258 if err != nil {
9259 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
9260 os.Exit(1)
9261 }
9262 }
9263
EKRf71d7ed2016-08-06 13:25:12 -07009264 if !*includeDisabled {
9265 for pattern := range shimConfig.DisabledTests {
9266 isDisabled, err := filepath.Match(pattern, testCases[i].name)
9267 if err != nil {
9268 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
9269 os.Exit(1)
9270 }
9271
9272 if isDisabled {
9273 matched = false
9274 break
9275 }
9276 }
9277 }
9278
David Benjamin17e12922016-07-28 18:04:43 -04009279 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04009280 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04009281 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07009282 }
9283 }
David Benjamin17e12922016-07-28 18:04:43 -04009284
David Benjamin270f0a72016-03-17 14:41:36 -04009285 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07009286 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04009287 os.Exit(1)
9288 }
Adam Langley95c29f32014-06-20 12:00:00 -07009289
9290 close(testChan)
9291 wg.Wait()
9292 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05009293 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07009294
9295 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05009296
9297 if *jsonOutput != "" {
9298 if err := testOutput.writeTo(*jsonOutput); err != nil {
9299 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
9300 }
9301 }
David Benjamin2ab7a862015-04-04 17:02:18 -04009302
EKR842ae6c2016-07-27 09:22:05 +02009303 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
9304 os.Exit(1)
9305 }
9306
9307 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04009308 os.Exit(1)
9309 }
Adam Langley95c29f32014-06-20 12:00:00 -07009310}