blob: 4599687524102a49ac0c029e92728ccbeaa063ef [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
Adam Langley69a01602014-11-17 17:26:55 -080065)
Adam Langley95c29f32014-06-20 12:00:00 -070066
EKRf71d7ed2016-08-06 13:25:12 -070067// ShimConfigurations is used with the “json” package and represents a shim
68// config file.
69type ShimConfiguration struct {
70 // DisabledTests maps from a glob-based pattern to a freeform string.
71 // The glob pattern is used to exclude tests from being run and the
72 // freeform string is unparsed but expected to explain why the test is
73 // disabled.
74 DisabledTests map[string]string
75
76 // ErrorMap maps from expected error strings to the correct error
77 // string for the shim in question. For example, it might map
78 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
79 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
80 ErrorMap map[string]string
81}
82
83var shimConfig ShimConfiguration
84
David Benjamin33863262016-07-08 17:20:12 -070085type testCert int
86
David Benjamin025b3d32014-07-01 19:53:04 -040087const (
David Benjamin33863262016-07-08 17:20:12 -070088 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040089 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070090 testCertECDSAP256
91 testCertECDSAP384
92 testCertECDSAP521
93)
94
95const (
96 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040097 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070098 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
99 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
100 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400101)
102
103const (
David Benjamina08e49d2014-08-24 01:46:07 -0400104 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400105 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700106 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
107 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
108 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400109 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400110)
111
David Benjamin7944a9f2016-07-12 22:27:01 -0400112var (
113 rsaCertificate Certificate
114 rsa1024Certificate Certificate
115 ecdsaP256Certificate Certificate
116 ecdsaP384Certificate Certificate
117 ecdsaP521Certificate Certificate
118)
David Benjamin33863262016-07-08 17:20:12 -0700119
120var testCerts = []struct {
121 id testCert
122 certFile, keyFile string
123 cert *Certificate
124}{
125 {
126 id: testCertRSA,
127 certFile: rsaCertificateFile,
128 keyFile: rsaKeyFile,
129 cert: &rsaCertificate,
130 },
131 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400132 id: testCertRSA1024,
133 certFile: rsa1024CertificateFile,
134 keyFile: rsa1024KeyFile,
135 cert: &rsa1024Certificate,
136 },
137 {
David Benjamin33863262016-07-08 17:20:12 -0700138 id: testCertECDSAP256,
139 certFile: ecdsaP256CertificateFile,
140 keyFile: ecdsaP256KeyFile,
141 cert: &ecdsaP256Certificate,
142 },
143 {
144 id: testCertECDSAP384,
145 certFile: ecdsaP384CertificateFile,
146 keyFile: ecdsaP384KeyFile,
147 cert: &ecdsaP384Certificate,
148 },
149 {
150 id: testCertECDSAP521,
151 certFile: ecdsaP521CertificateFile,
152 keyFile: ecdsaP521KeyFile,
153 cert: &ecdsaP521Certificate,
154 },
155}
156
David Benjamina08e49d2014-08-24 01:46:07 -0400157var channelIDKey *ecdsa.PrivateKey
158var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700159
David Benjamin61f95272014-11-25 01:55:35 -0500160var testOCSPResponse = []byte{1, 2, 3, 4}
161var testSCTList = []byte{5, 6, 7, 8}
162
Adam Langley95c29f32014-06-20 12:00:00 -0700163func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700164 for i := range testCerts {
165 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
166 if err != nil {
167 panic(err)
168 }
169 cert.OCSPStaple = testOCSPResponse
170 cert.SignedCertificateTimestampList = testSCTList
171 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700172 }
David Benjamina08e49d2014-08-24 01:46:07 -0400173
Adam Langley7c803a62015-06-15 15:35:05 -0700174 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400175 if err != nil {
176 panic(err)
177 }
178 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
179 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
180 panic("bad key type")
181 }
182 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
183 if err != nil {
184 panic(err)
185 }
186 if channelIDKey.Curve != elliptic.P256() {
187 panic("bad curve")
188 }
189
190 channelIDBytes = make([]byte, 64)
191 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
192 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700193}
194
David Benjamin33863262016-07-08 17:20:12 -0700195func getRunnerCertificate(t testCert) Certificate {
196 for _, cert := range testCerts {
197 if cert.id == t {
198 return *cert.cert
199 }
200 }
201 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700202}
203
David Benjamin33863262016-07-08 17:20:12 -0700204func getShimCertificate(t testCert) string {
205 for _, cert := range testCerts {
206 if cert.id == t {
207 return cert.certFile
208 }
209 }
210 panic("Unknown test certificate")
211}
212
213func getShimKey(t testCert) string {
214 for _, cert := range testCerts {
215 if cert.id == t {
216 return cert.keyFile
217 }
218 }
219 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700220}
221
David Benjamin025b3d32014-07-01 19:53:04 -0400222type testType int
223
224const (
225 clientTest testType = iota
226 serverTest
227)
228
David Benjamin6fd297b2014-08-11 18:43:38 -0400229type protocol int
230
231const (
232 tls protocol = iota
233 dtls
234)
235
David Benjaminfc7b0862014-09-06 13:21:53 -0400236const (
237 alpn = 1
238 npn = 2
239)
240
Adam Langley95c29f32014-06-20 12:00:00 -0700241type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400242 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400243 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700244 name string
245 config Config
246 shouldFail bool
247 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700248 // expectedLocalError, if not empty, contains a substring that must be
249 // found in the local error.
250 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400251 // expectedVersion, if non-zero, specifies the TLS version that must be
252 // negotiated.
253 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400254 // expectedResumeVersion, if non-zero, specifies the TLS version that
255 // must be negotiated on resumption. If zero, expectedVersion is used.
256 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400257 // expectedCipher, if non-zero, specifies the TLS cipher suite that
258 // should be negotiated.
259 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400260 // expectChannelID controls whether the connection should have
261 // negotiated a Channel ID with channelIDKey.
262 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400263 // expectedNextProto controls whether the connection should
264 // negotiate a next protocol via NPN or ALPN.
265 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400266 // expectNoNextProto, if true, means that no next protocol should be
267 // negotiated.
268 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400269 // expectedNextProtoType, if non-zero, is the expected next
270 // protocol negotiation mechanism.
271 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500272 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
273 // should be negotiated. If zero, none should be negotiated.
274 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100275 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
276 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100277 // expectedSCTList, if not nil, is the expected SCT list to be received.
278 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700279 // expectedPeerSignatureAlgorithm, if not zero, is the signature
280 // algorithm that the peer should have used in the handshake.
281 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400282 // expectedCurveID, if not zero, is the curve that the handshake should
283 // have used.
284 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700285 // messageLen is the length, in bytes, of the test message that will be
286 // sent.
287 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400288 // messageCount is the number of test messages that will be sent.
289 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400290 // certFile is the path to the certificate to use for the server.
291 certFile string
292 // keyFile is the path to the private key to use for the server.
293 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400294 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400295 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400296 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400297 // resumeRenewedSession controls whether a third connection should be
298 // tested which attempts to resume the second connection's session.
299 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700300 // expectResumeRejected, if true, specifies that the attempted
301 // resumption must be rejected by the client. This is only valid for a
302 // serverTest.
303 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400304 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500305 // resumption. Unless newSessionsOnResume is set,
306 // SessionTicketKey, ServerSessionCache, and
307 // ClientSessionCache are copied from the initial connection's
308 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400309 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500310 // newSessionsOnResume, if true, will cause resumeConfig to
311 // use a different session resumption context.
312 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400313 // noSessionCache, if true, will cause the server to run without a
314 // session cache.
315 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400316 // sendPrefix sends a prefix on the socket before actually performing a
317 // handshake.
318 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400319 // shimWritesFirst controls whether the shim sends an initial "hello"
320 // message before doing a roundtrip with the runner.
321 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400322 // shimShutsDown, if true, runs a test where the shim shuts down the
323 // connection immediately after the handshake rather than echoing
324 // messages from the runner.
325 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400326 // renegotiate indicates the number of times the connection should be
327 // renegotiated during the exchange.
328 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400329 // sendHalfHelloRequest, if true, causes the server to send half a
330 // HelloRequest when the handshake completes.
331 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700332 // renegotiateCiphers is a list of ciphersuite ids that will be
333 // switched in just before renegotiation.
334 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500335 // replayWrites, if true, configures the underlying transport
336 // to replay every write it makes in DTLS tests.
337 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500338 // damageFirstWrite, if true, configures the underlying transport to
339 // damage the final byte of the first application data write.
340 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400341 // exportKeyingMaterial, if non-zero, configures the test to exchange
342 // keying material and verify they match.
343 exportKeyingMaterial int
344 exportLabel string
345 exportContext string
346 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400347 // flags, if not empty, contains a list of command-line flags that will
348 // be passed to the shim program.
349 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700350 // testTLSUnique, if true, causes the shim to send the tls-unique value
351 // which will be compared against the expected value.
352 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400353 // sendEmptyRecords is the number of consecutive empty records to send
354 // before and after the test message.
355 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400356 // sendWarningAlerts is the number of consecutive warning alerts to send
357 // before and after the test message.
358 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400359 // sendKeyUpdates is the number of consecutive key updates to send
360 // before and after the test message.
361 sendKeyUpdates int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400362 // expectMessageDropped, if true, means the test message is expected to
363 // be dropped by the client rather than echoed back.
364 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700365}
366
Adam Langley7c803a62015-06-15 15:35:05 -0700367var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700368
David Benjaminc07afb72016-09-22 10:18:58 -0400369func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500370 if len(data) == 0 {
371 return
372 }
373
374 protocol := "tls"
375 if test.protocol == dtls {
376 protocol = "dtls"
377 }
378
379 side := "client"
380 if test.testType == serverTest {
381 side = "server"
382 }
383
384 dir := path.Join(*transcriptDir, protocol, side)
385 if err := os.MkdirAll(dir, 0755); err != nil {
386 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
387 return
388 }
389
David Benjaminc07afb72016-09-22 10:18:58 -0400390 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500391 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
392 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
393 }
394}
395
David Benjamin3ed59772016-03-08 12:50:21 -0500396// A timeoutConn implements an idle timeout on each Read and Write operation.
397type timeoutConn struct {
398 net.Conn
399 timeout time.Duration
400}
401
402func (t *timeoutConn) Read(b []byte) (int, error) {
403 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
404 return 0, err
405 }
406 return t.Conn.Read(b)
407}
408
409func (t *timeoutConn) Write(b []byte) (int, error) {
410 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
411 return 0, err
412 }
413 return t.Conn.Write(b)
414}
415
David Benjaminc07afb72016-09-22 10:18:58 -0400416func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400417 if !test.noSessionCache {
418 if config.ClientSessionCache == nil {
419 config.ClientSessionCache = NewLRUClientSessionCache(1)
420 }
421 if config.ServerSessionCache == nil {
422 config.ServerSessionCache = NewLRUServerSessionCache(1)
423 }
424 }
425 if test.testType == clientTest {
426 if len(config.Certificates) == 0 {
427 config.Certificates = []Certificate{rsaCertificate}
428 }
429 } else {
430 // Supply a ServerName to ensure a constant session cache key,
431 // rather than falling back to net.Conn.RemoteAddr.
432 if len(config.ServerName) == 0 {
433 config.ServerName = "test"
434 }
435 }
436 if *fuzzer {
437 config.Bugs.NullAllCiphers = true
438 }
David Benjamin01a90572016-09-22 00:11:43 -0400439 if *deterministic {
440 config.Time = func() time.Time { return time.Unix(1234, 1234) }
441 }
David Benjamine54af062016-08-08 19:21:18 -0400442
David Benjamin01784b42016-06-07 18:00:52 -0400443 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500444
David Benjamin6fd297b2014-08-11 18:43:38 -0400445 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500446 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
447 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500448 }
449
David Benjamin9867b7d2016-03-01 23:25:48 -0500450 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500451 local, peer := "client", "server"
452 if test.testType == clientTest {
453 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500454 }
David Benjaminebda9b32015-11-02 15:33:18 -0500455 connDebug := &recordingConn{
456 Conn: conn,
457 isDatagram: test.protocol == dtls,
458 local: local,
459 peer: peer,
460 }
461 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500462 if *flagDebug {
463 defer connDebug.WriteTo(os.Stdout)
464 }
465 if len(*transcriptDir) != 0 {
466 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400467 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 }()
469 }
David Benjaminebda9b32015-11-02 15:33:18 -0500470
471 if config.Bugs.PacketAdaptor != nil {
472 config.Bugs.PacketAdaptor.debug = connDebug
473 }
474 }
475
476 if test.replayWrites {
477 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400478 }
479
David Benjamin3ed59772016-03-08 12:50:21 -0500480 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500481 if test.damageFirstWrite {
482 connDamage = newDamageAdaptor(conn)
483 conn = connDamage
484 }
485
David Benjamin6fd297b2014-08-11 18:43:38 -0400486 if test.sendPrefix != "" {
487 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
488 return err
489 }
David Benjamin98e882e2014-08-08 13:24:34 -0400490 }
491
David Benjamin1d5c83e2014-07-22 19:20:02 -0400492 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400493 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400494 if test.protocol == dtls {
495 tlsConn = DTLSServer(conn, config)
496 } else {
497 tlsConn = Server(conn, config)
498 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400499 } else {
500 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.protocol == dtls {
502 tlsConn = DTLSClient(conn, config)
503 } else {
504 tlsConn = Client(conn, config)
505 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400506 }
David Benjamin30789da2015-08-29 22:56:45 -0400507 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400508
Adam Langley95c29f32014-06-20 12:00:00 -0700509 if err := tlsConn.Handshake(); err != nil {
510 return err
511 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700512
David Benjamin01fe8202014-09-24 15:21:44 -0400513 // TODO(davidben): move all per-connection expectations into a dedicated
514 // expectations struct that can be specified separately for the two
515 // legs.
516 expectedVersion := test.expectedVersion
517 if isResume && test.expectedResumeVersion != 0 {
518 expectedVersion = test.expectedResumeVersion
519 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700520 connState := tlsConn.ConnectionState()
521 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400522 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400523 }
524
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700525 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400526 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
527 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700528 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
529 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
530 }
David Benjamin90da8c82015-04-20 14:57:57 -0400531
David Benjamina08e49d2014-08-24 01:46:07 -0400532 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700533 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400534 if channelID == nil {
535 return fmt.Errorf("no channel ID negotiated")
536 }
537 if channelID.Curve != channelIDKey.Curve ||
538 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
539 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
540 return fmt.Errorf("incorrect channel ID")
541 }
542 }
543
David Benjaminae2888f2014-09-06 12:58:58 -0400544 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700545 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400546 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
547 }
548 }
549
David Benjaminc7ce9772015-10-09 19:32:41 -0400550 if test.expectNoNextProto {
551 if actual := connState.NegotiatedProtocol; actual != "" {
552 return fmt.Errorf("got unexpected next proto %s", actual)
553 }
554 }
555
David Benjaminfc7b0862014-09-06 13:21:53 -0400556 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700557 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400558 return fmt.Errorf("next proto type mismatch")
559 }
560 }
561
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700562 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500563 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
564 }
565
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100566 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300567 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100568 }
569
Paul Lietar4fac72e2015-09-09 13:44:55 +0100570 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
571 return fmt.Errorf("SCT list mismatch")
572 }
573
Nick Harper60edffd2016-06-21 15:19:24 -0700574 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
575 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400576 }
577
Steven Valdez5440fe02016-07-18 12:40:30 -0400578 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
579 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
580 }
581
David Benjaminc565ebb2015-04-03 04:06:36 -0400582 if test.exportKeyingMaterial > 0 {
583 actual := make([]byte, test.exportKeyingMaterial)
584 if _, err := io.ReadFull(tlsConn, actual); err != nil {
585 return err
586 }
587 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
588 if err != nil {
589 return err
590 }
591 if !bytes.Equal(actual, expected) {
592 return fmt.Errorf("keying material mismatch")
593 }
594 }
595
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700596 if test.testTLSUnique {
597 var peersValue [12]byte
598 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
599 return err
600 }
601 expected := tlsConn.ConnectionState().TLSUnique
602 if !bytes.Equal(peersValue[:], expected) {
603 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
604 }
605 }
606
David Benjamine58c4f52014-08-24 03:47:07 -0400607 if test.shimWritesFirst {
608 var buf [5]byte
609 _, err := io.ReadFull(tlsConn, buf[:])
610 if err != nil {
611 return err
612 }
613 if string(buf[:]) != "hello" {
614 return fmt.Errorf("bad initial message")
615 }
616 }
617
Steven Valdez32635b82016-08-16 11:25:03 -0400618 for i := 0; i < test.sendKeyUpdates; i++ {
David Benjamin7f0965a2016-09-30 15:14:01 -0400619 if err := tlsConn.SendKeyUpdate(); err != nil {
620 return err
621 }
Steven Valdez32635b82016-08-16 11:25:03 -0400622 }
623
David Benjamina8ebe222015-06-06 03:04:39 -0400624 for i := 0; i < test.sendEmptyRecords; i++ {
625 tlsConn.Write(nil)
626 }
627
David Benjamin24f346d2015-06-06 03:28:08 -0400628 for i := 0; i < test.sendWarningAlerts; i++ {
629 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
630 }
631
David Benjamin47921102016-07-28 11:29:18 -0400632 if test.sendHalfHelloRequest {
633 tlsConn.SendHalfHelloRequest()
634 }
635
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400636 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700637 if test.renegotiateCiphers != nil {
638 config.CipherSuites = test.renegotiateCiphers
639 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400640 for i := 0; i < test.renegotiate; i++ {
641 if err := tlsConn.Renegotiate(); err != nil {
642 return err
643 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700644 }
645 } else if test.renegotiateCiphers != nil {
646 panic("renegotiateCiphers without renegotiate")
647 }
648
David Benjamin5fa3eba2015-01-22 16:35:40 -0500649 if test.damageFirstWrite {
650 connDamage.setDamage(true)
651 tlsConn.Write([]byte("DAMAGED WRITE"))
652 connDamage.setDamage(false)
653 }
654
David Benjamin8e6db492015-07-25 18:29:23 -0400655 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700656 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400657 if test.protocol == dtls {
658 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
659 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700660 // Read until EOF.
661 _, err := io.Copy(ioutil.Discard, tlsConn)
662 return err
663 }
David Benjamin4417d052015-04-05 04:17:25 -0400664 if messageLen == 0 {
665 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700666 }
Adam Langley95c29f32014-06-20 12:00:00 -0700667
David Benjamin8e6db492015-07-25 18:29:23 -0400668 messageCount := test.messageCount
669 if messageCount == 0 {
670 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400671 }
672
David Benjamin8e6db492015-07-25 18:29:23 -0400673 for j := 0; j < messageCount; j++ {
674 testMessage := make([]byte, messageLen)
675 for i := range testMessage {
676 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400677 }
David Benjamin8e6db492015-07-25 18:29:23 -0400678 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700679
Steven Valdez32635b82016-08-16 11:25:03 -0400680 for i := 0; i < test.sendKeyUpdates; i++ {
681 tlsConn.SendKeyUpdate()
682 }
683
David Benjamin8e6db492015-07-25 18:29:23 -0400684 for i := 0; i < test.sendEmptyRecords; i++ {
685 tlsConn.Write(nil)
686 }
687
688 for i := 0; i < test.sendWarningAlerts; i++ {
689 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
690 }
691
David Benjamin4f75aaf2015-09-01 16:53:10 -0400692 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400693 // The shim will not respond.
694 continue
695 }
696
David Benjamin8e6db492015-07-25 18:29:23 -0400697 buf := make([]byte, len(testMessage))
698 if test.protocol == dtls {
699 bufTmp := make([]byte, len(buf)+1)
700 n, err := tlsConn.Read(bufTmp)
701 if err != nil {
702 return err
703 }
704 if n != len(buf) {
705 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
706 }
707 copy(buf, bufTmp)
708 } else {
709 _, err := io.ReadFull(tlsConn, buf)
710 if err != nil {
711 return err
712 }
713 }
714
715 for i, v := range buf {
716 if v != testMessage[i]^0xff {
717 return fmt.Errorf("bad reply contents at byte %d", i)
718 }
Adam Langley95c29f32014-06-20 12:00:00 -0700719 }
720 }
721
722 return nil
723}
724
David Benjamin325b5c32014-07-01 19:40:31 -0400725func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400726 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700727 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400728 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700729 }
David Benjamin325b5c32014-07-01 19:40:31 -0400730 valgrindArgs = append(valgrindArgs, path)
731 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700732
David Benjamin325b5c32014-07-01 19:40:31 -0400733 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700734}
735
David Benjamin325b5c32014-07-01 19:40:31 -0400736func gdbOf(path string, args ...string) *exec.Cmd {
737 xtermArgs := []string{"-e", "gdb", "--args"}
738 xtermArgs = append(xtermArgs, path)
739 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700740
David Benjamin325b5c32014-07-01 19:40:31 -0400741 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700742}
743
David Benjamind16bf342015-12-18 00:53:12 -0500744func lldbOf(path string, args ...string) *exec.Cmd {
745 xtermArgs := []string{"-e", "lldb", "--"}
746 xtermArgs = append(xtermArgs, path)
747 xtermArgs = append(xtermArgs, args...)
748
749 return exec.Command("xterm", xtermArgs...)
750}
751
EKR842ae6c2016-07-27 09:22:05 +0200752var (
753 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
754 errUnimplemented = errors.New("child process does not implement needed flags")
755)
Adam Langley69a01602014-11-17 17:26:55 -0800756
David Benjamin87c8a642015-02-21 01:54:29 -0500757// accept accepts a connection from listener, unless waitChan signals a process
758// exit first.
759func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
760 type connOrError struct {
761 conn net.Conn
762 err error
763 }
764 connChan := make(chan connOrError, 1)
765 go func() {
766 conn, err := listener.Accept()
767 connChan <- connOrError{conn, err}
768 close(connChan)
769 }()
770 select {
771 case result := <-connChan:
772 return result.conn, result.err
773 case childErr := <-waitChan:
774 waitChan <- childErr
775 return nil, fmt.Errorf("child exited early: %s", childErr)
776 }
777}
778
EKRf71d7ed2016-08-06 13:25:12 -0700779func translateExpectedError(errorStr string) string {
780 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
781 return translated
782 }
783
784 if *looseErrors {
785 return ""
786 }
787
788 return errorStr
789}
790
Adam Langley7c803a62015-06-15 15:35:05 -0700791func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400792 // Help debugging panics on the Go side.
793 defer func() {
794 if r := recover(); r != nil {
795 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
796 panic(r)
797 }
798 }()
799
Adam Langley38311732014-10-16 19:04:35 -0700800 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
801 panic("Error expected without shouldFail in " + test.name)
802 }
803
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700804 if test.expectResumeRejected && !test.resumeSession {
805 panic("expectResumeRejected without resumeSession in " + test.name)
806 }
807
David Benjamin87c8a642015-02-21 01:54:29 -0500808 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
809 if err != nil {
810 panic(err)
811 }
812 defer func() {
813 if listener != nil {
814 listener.Close()
815 }
816 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700817
David Benjamin87c8a642015-02-21 01:54:29 -0500818 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400819 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400820 flags = append(flags, "-server")
821
David Benjamin025b3d32014-07-01 19:53:04 -0400822 flags = append(flags, "-key-file")
823 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700824 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400825 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700826 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400827 }
828
829 flags = append(flags, "-cert-file")
830 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700831 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400832 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700833 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400834 }
835 }
David Benjamin5a593af2014-08-11 19:51:50 -0400836
David Benjamin6fd297b2014-08-11 18:43:38 -0400837 if test.protocol == dtls {
838 flags = append(flags, "-dtls")
839 }
840
David Benjamin46662482016-08-17 00:51:00 -0400841 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400842 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400843 resumeCount++
844 if test.resumeRenewedSession {
845 resumeCount++
846 }
847 }
848
849 if resumeCount > 0 {
850 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400851 }
852
David Benjamine58c4f52014-08-24 03:47:07 -0400853 if test.shimWritesFirst {
854 flags = append(flags, "-shim-writes-first")
855 }
856
David Benjamin30789da2015-08-29 22:56:45 -0400857 if test.shimShutsDown {
858 flags = append(flags, "-shim-shuts-down")
859 }
860
David Benjaminc565ebb2015-04-03 04:06:36 -0400861 if test.exportKeyingMaterial > 0 {
862 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
863 flags = append(flags, "-export-label", test.exportLabel)
864 flags = append(flags, "-export-context", test.exportContext)
865 if test.useExportContext {
866 flags = append(flags, "-use-export-context")
867 }
868 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700869 if test.expectResumeRejected {
870 flags = append(flags, "-expect-session-miss")
871 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400872
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700873 if test.testTLSUnique {
874 flags = append(flags, "-tls-unique")
875 }
876
David Benjamin025b3d32014-07-01 19:53:04 -0400877 flags = append(flags, test.flags...)
878
879 var shim *exec.Cmd
880 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700881 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700882 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700883 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500884 } else if *useLLDB {
885 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400886 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700887 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400888 }
David Benjamin025b3d32014-07-01 19:53:04 -0400889 shim.Stdin = os.Stdin
890 var stdoutBuf, stderrBuf bytes.Buffer
891 shim.Stdout = &stdoutBuf
892 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800893 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500894 shim.Env = os.Environ()
895 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800896 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400897 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800898 }
899 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
900 }
David Benjamin025b3d32014-07-01 19:53:04 -0400901
902 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700903 panic(err)
904 }
David Benjamin87c8a642015-02-21 01:54:29 -0500905 waitChan := make(chan error, 1)
906 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700907
908 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700909
David Benjamin7a4aaa42016-09-20 17:58:14 -0400910 if *deterministic {
911 config.Rand = &deterministicRand{}
912 }
913
David Benjamin87c8a642015-02-21 01:54:29 -0500914 conn, err := acceptOrWait(listener, waitChan)
915 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400916 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500917 conn.Close()
918 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500919
David Benjamin46662482016-08-17 00:51:00 -0400920 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400921 var resumeConfig Config
922 if test.resumeConfig != nil {
923 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400924 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500925 resumeConfig.SessionTicketKey = config.SessionTicketKey
926 resumeConfig.ClientSessionCache = config.ClientSessionCache
927 resumeConfig.ServerSessionCache = config.ServerSessionCache
928 }
David Benjamin2e045a92016-06-08 13:09:56 -0400929 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400930 } else {
931 resumeConfig = config
932 }
David Benjamin87c8a642015-02-21 01:54:29 -0500933 var connResume net.Conn
934 connResume, err = acceptOrWait(listener, waitChan)
935 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400936 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500937 connResume.Close()
938 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400939 }
940
David Benjamin87c8a642015-02-21 01:54:29 -0500941 // Close the listener now. This is to avoid hangs should the shim try to
942 // open more connections than expected.
943 listener.Close()
944 listener = nil
945
946 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400947 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800948 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200949 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
950 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800951 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200952 case 89:
953 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400954 case 99:
955 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800956 }
957 }
Adam Langley95c29f32014-06-20 12:00:00 -0700958
David Benjamin9bea3492016-03-02 10:59:16 -0500959 // Account for Windows line endings.
960 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
961 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500962
963 // Separate the errors from the shim and those from tools like
964 // AddressSanitizer.
965 var extraStderr string
966 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
967 stderr = stderrParts[0]
968 extraStderr = stderrParts[1]
969 }
970
Adam Langley95c29f32014-06-20 12:00:00 -0700971 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700972 expectedError := translateExpectedError(test.expectedError)
973 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200974
Adam Langleyac61fa32014-06-23 12:03:11 -0700975 localError := "none"
976 if err != nil {
977 localError = err.Error()
978 }
979 if len(test.expectedLocalError) != 0 {
980 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
981 }
Adam Langley95c29f32014-06-20 12:00:00 -0700982
983 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700984 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700985 if childErr != nil {
986 childError = childErr.Error()
987 }
988
989 var msg string
990 switch {
991 case failed && !test.shouldFail:
992 msg = "unexpected failure"
993 case !failed && test.shouldFail:
994 msg = "unexpected success"
995 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700996 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700997 default:
998 panic("internal error")
999 }
1000
David Benjamin9aafb642016-09-20 19:36:53 -04001001 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001002 }
1003
David Benjamind2ba8892016-09-20 19:41:04 -04001004 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001005 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001006 }
1007
David Benjamind2ba8892016-09-20 19:41:04 -04001008 if *useValgrind && isValgrindError {
1009 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1010 }
1011
Adam Langley95c29f32014-06-20 12:00:00 -07001012 return nil
1013}
1014
1015var tlsVersions = []struct {
1016 name string
1017 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001018 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001019 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001020}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001021 {"SSL3", VersionSSL30, "-no-ssl3", false},
1022 {"TLS1", VersionTLS10, "-no-tls1", true},
1023 {"TLS11", VersionTLS11, "-no-tls11", false},
1024 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001025 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001026}
1027
1028var testCipherSuites = []struct {
1029 name string
1030 id uint16
1031}{
1032 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001033 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001034 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001035 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001036 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001037 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001038 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001039 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1040 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001041 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001042 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1043 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001044 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001045 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1046 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001047 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1048 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001049 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001050 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001051 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001052 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001053 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001054 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001055 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001056 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001057 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001058 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001059 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001060 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001061 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1062 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1063 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1064 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001065 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1066 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001067 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1068 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001069 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001070 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1071 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1072 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001073 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001074}
1075
David Benjamin8b8c0062014-11-23 02:47:52 -05001076func hasComponent(suiteName, component string) bool {
1077 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1078}
1079
David Benjaminf7768e42014-08-31 02:06:47 -04001080func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001081 return hasComponent(suiteName, "GCM") ||
1082 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001083 hasComponent(suiteName, "SHA384") ||
1084 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001085}
1086
Nick Harper1fd39d82016-06-14 18:14:35 -07001087func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001088 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001089}
1090
David Benjamin8b8c0062014-11-23 02:47:52 -05001091func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001092 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001093}
1094
Adam Langleya7997f12015-05-14 17:38:50 -07001095func bigFromHex(hex string) *big.Int {
1096 ret, ok := new(big.Int).SetString(hex, 16)
1097 if !ok {
1098 panic("failed to parse hex number 0x" + hex)
1099 }
1100 return ret
1101}
1102
Adam Langley7c803a62015-06-15 15:35:05 -07001103func addBasicTests() {
1104 basicTests := []testCase{
1105 {
Adam Langley7c803a62015-06-15 15:35:05 -07001106 name: "NoFallbackSCSV",
1107 config: Config{
1108 Bugs: ProtocolBugs{
1109 FailIfNotFallbackSCSV: true,
1110 },
1111 },
1112 shouldFail: true,
1113 expectedLocalError: "no fallback SCSV found",
1114 },
1115 {
1116 name: "SendFallbackSCSV",
1117 config: Config{
1118 Bugs: ProtocolBugs{
1119 FailIfNotFallbackSCSV: true,
1120 },
1121 },
1122 flags: []string{"-fallback-scsv"},
1123 },
1124 {
1125 name: "ClientCertificateTypes",
1126 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001127 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001128 ClientAuth: RequestClientCert,
1129 ClientCertificateTypes: []byte{
1130 CertTypeDSSSign,
1131 CertTypeRSASign,
1132 CertTypeECDSASign,
1133 },
1134 },
1135 flags: []string{
1136 "-expect-certificate-types",
1137 base64.StdEncoding.EncodeToString([]byte{
1138 CertTypeDSSSign,
1139 CertTypeRSASign,
1140 CertTypeECDSASign,
1141 }),
1142 },
1143 },
1144 {
Adam Langley7c803a62015-06-15 15:35:05 -07001145 name: "UnauthenticatedECDH",
1146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001147 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001148 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1149 Bugs: ProtocolBugs{
1150 UnauthenticatedECDH: true,
1151 },
1152 },
1153 shouldFail: true,
1154 expectedError: ":UNEXPECTED_MESSAGE:",
1155 },
1156 {
1157 name: "SkipCertificateStatus",
1158 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001159 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001160 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1161 Bugs: ProtocolBugs{
1162 SkipCertificateStatus: true,
1163 },
1164 },
1165 flags: []string{
1166 "-enable-ocsp-stapling",
1167 },
1168 },
1169 {
1170 name: "SkipServerKeyExchange",
1171 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001172 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001173 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1174 Bugs: ProtocolBugs{
1175 SkipServerKeyExchange: true,
1176 },
1177 },
1178 shouldFail: true,
1179 expectedError: ":UNEXPECTED_MESSAGE:",
1180 },
1181 {
Adam Langley7c803a62015-06-15 15:35:05 -07001182 testType: serverTest,
1183 name: "Alert",
1184 config: Config{
1185 Bugs: ProtocolBugs{
1186 SendSpuriousAlert: alertRecordOverflow,
1187 },
1188 },
1189 shouldFail: true,
1190 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1191 },
1192 {
1193 protocol: dtls,
1194 testType: serverTest,
1195 name: "Alert-DTLS",
1196 config: Config{
1197 Bugs: ProtocolBugs{
1198 SendSpuriousAlert: alertRecordOverflow,
1199 },
1200 },
1201 shouldFail: true,
1202 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1203 },
1204 {
1205 testType: serverTest,
1206 name: "FragmentAlert",
1207 config: Config{
1208 Bugs: ProtocolBugs{
1209 FragmentAlert: true,
1210 SendSpuriousAlert: alertRecordOverflow,
1211 },
1212 },
1213 shouldFail: true,
1214 expectedError: ":BAD_ALERT:",
1215 },
1216 {
1217 protocol: dtls,
1218 testType: serverTest,
1219 name: "FragmentAlert-DTLS",
1220 config: Config{
1221 Bugs: ProtocolBugs{
1222 FragmentAlert: true,
1223 SendSpuriousAlert: alertRecordOverflow,
1224 },
1225 },
1226 shouldFail: true,
1227 expectedError: ":BAD_ALERT:",
1228 },
1229 {
1230 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001231 name: "DoubleAlert",
1232 config: Config{
1233 Bugs: ProtocolBugs{
1234 DoubleAlert: true,
1235 SendSpuriousAlert: alertRecordOverflow,
1236 },
1237 },
1238 shouldFail: true,
1239 expectedError: ":BAD_ALERT:",
1240 },
1241 {
1242 protocol: dtls,
1243 testType: serverTest,
1244 name: "DoubleAlert-DTLS",
1245 config: Config{
1246 Bugs: ProtocolBugs{
1247 DoubleAlert: true,
1248 SendSpuriousAlert: alertRecordOverflow,
1249 },
1250 },
1251 shouldFail: true,
1252 expectedError: ":BAD_ALERT:",
1253 },
1254 {
Adam Langley7c803a62015-06-15 15:35:05 -07001255 name: "SkipNewSessionTicket",
1256 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001257 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001258 Bugs: ProtocolBugs{
1259 SkipNewSessionTicket: true,
1260 },
1261 },
1262 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001263 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001264 },
1265 {
1266 testType: serverTest,
1267 name: "FallbackSCSV",
1268 config: Config{
1269 MaxVersion: VersionTLS11,
1270 Bugs: ProtocolBugs{
1271 SendFallbackSCSV: true,
1272 },
1273 },
1274 shouldFail: true,
1275 expectedError: ":INAPPROPRIATE_FALLBACK:",
1276 },
1277 {
1278 testType: serverTest,
1279 name: "FallbackSCSV-VersionMatch",
1280 config: Config{
1281 Bugs: ProtocolBugs{
1282 SendFallbackSCSV: true,
1283 },
1284 },
1285 },
1286 {
1287 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001288 name: "FallbackSCSV-VersionMatch-TLS12",
1289 config: Config{
1290 MaxVersion: VersionTLS12,
1291 Bugs: ProtocolBugs{
1292 SendFallbackSCSV: true,
1293 },
1294 },
1295 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1296 },
1297 {
1298 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001299 name: "FragmentedClientVersion",
1300 config: Config{
1301 Bugs: ProtocolBugs{
1302 MaxHandshakeRecordLength: 1,
1303 FragmentClientVersion: true,
1304 },
1305 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001306 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001307 },
1308 {
Adam Langley7c803a62015-06-15 15:35:05 -07001309 testType: serverTest,
1310 name: "HttpGET",
1311 sendPrefix: "GET / HTTP/1.0\n",
1312 shouldFail: true,
1313 expectedError: ":HTTP_REQUEST:",
1314 },
1315 {
1316 testType: serverTest,
1317 name: "HttpPOST",
1318 sendPrefix: "POST / HTTP/1.0\n",
1319 shouldFail: true,
1320 expectedError: ":HTTP_REQUEST:",
1321 },
1322 {
1323 testType: serverTest,
1324 name: "HttpHEAD",
1325 sendPrefix: "HEAD / HTTP/1.0\n",
1326 shouldFail: true,
1327 expectedError: ":HTTP_REQUEST:",
1328 },
1329 {
1330 testType: serverTest,
1331 name: "HttpPUT",
1332 sendPrefix: "PUT / HTTP/1.0\n",
1333 shouldFail: true,
1334 expectedError: ":HTTP_REQUEST:",
1335 },
1336 {
1337 testType: serverTest,
1338 name: "HttpCONNECT",
1339 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1340 shouldFail: true,
1341 expectedError: ":HTTPS_PROXY_REQUEST:",
1342 },
1343 {
1344 testType: serverTest,
1345 name: "Garbage",
1346 sendPrefix: "blah",
1347 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001348 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001349 },
1350 {
Adam Langley7c803a62015-06-15 15:35:05 -07001351 name: "RSAEphemeralKey",
1352 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001353 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001354 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1355 Bugs: ProtocolBugs{
1356 RSAEphemeralKey: true,
1357 },
1358 },
1359 shouldFail: true,
1360 expectedError: ":UNEXPECTED_MESSAGE:",
1361 },
1362 {
1363 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001364 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001365 shouldFail: true,
1366 expectedError: ":WRONG_SSL_VERSION:",
1367 },
1368 {
1369 protocol: dtls,
1370 name: "DisableEverything-DTLS",
1371 flags: []string{"-no-tls12", "-no-tls1"},
1372 shouldFail: true,
1373 expectedError: ":WRONG_SSL_VERSION:",
1374 },
1375 {
Adam Langley7c803a62015-06-15 15:35:05 -07001376 protocol: dtls,
1377 testType: serverTest,
1378 name: "MTU",
1379 config: Config{
1380 Bugs: ProtocolBugs{
1381 MaxPacketLength: 256,
1382 },
1383 },
1384 flags: []string{"-mtu", "256"},
1385 },
1386 {
1387 protocol: dtls,
1388 testType: serverTest,
1389 name: "MTUExceeded",
1390 config: Config{
1391 Bugs: ProtocolBugs{
1392 MaxPacketLength: 255,
1393 },
1394 },
1395 flags: []string{"-mtu", "256"},
1396 shouldFail: true,
1397 expectedLocalError: "dtls: exceeded maximum packet length",
1398 },
1399 {
1400 name: "CertMismatchRSA",
1401 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001402 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001403 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001404 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001405 Bugs: ProtocolBugs{
1406 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1407 },
1408 },
1409 shouldFail: true,
1410 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1411 },
1412 {
1413 name: "CertMismatchECDSA",
1414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001415 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001416 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001417 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001418 Bugs: ProtocolBugs{
1419 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1420 },
1421 },
1422 shouldFail: true,
1423 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1424 },
1425 {
1426 name: "EmptyCertificateList",
1427 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001428 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001429 Bugs: ProtocolBugs{
1430 EmptyCertificateList: true,
1431 },
1432 },
1433 shouldFail: true,
1434 expectedError: ":DECODE_ERROR:",
1435 },
1436 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001437 name: "EmptyCertificateList-TLS13",
1438 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001439 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001440 Bugs: ProtocolBugs{
1441 EmptyCertificateList: true,
1442 },
1443 },
1444 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001445 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001446 },
1447 {
Adam Langley7c803a62015-06-15 15:35:05 -07001448 name: "TLSFatalBadPackets",
1449 damageFirstWrite: true,
1450 shouldFail: true,
1451 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1452 },
1453 {
1454 protocol: dtls,
1455 name: "DTLSIgnoreBadPackets",
1456 damageFirstWrite: true,
1457 },
1458 {
1459 protocol: dtls,
1460 name: "DTLSIgnoreBadPackets-Async",
1461 damageFirstWrite: true,
1462 flags: []string{"-async"},
1463 },
1464 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001465 name: "AppDataBeforeHandshake",
1466 config: Config{
1467 Bugs: ProtocolBugs{
1468 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1469 },
1470 },
1471 shouldFail: true,
1472 expectedError: ":UNEXPECTED_RECORD:",
1473 },
1474 {
1475 name: "AppDataBeforeHandshake-Empty",
1476 config: Config{
1477 Bugs: ProtocolBugs{
1478 AppDataBeforeHandshake: []byte{},
1479 },
1480 },
1481 shouldFail: true,
1482 expectedError: ":UNEXPECTED_RECORD:",
1483 },
1484 {
1485 protocol: dtls,
1486 name: "AppDataBeforeHandshake-DTLS",
1487 config: Config{
1488 Bugs: ProtocolBugs{
1489 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1490 },
1491 },
1492 shouldFail: true,
1493 expectedError: ":UNEXPECTED_RECORD:",
1494 },
1495 {
1496 protocol: dtls,
1497 name: "AppDataBeforeHandshake-DTLS-Empty",
1498 config: Config{
1499 Bugs: ProtocolBugs{
1500 AppDataBeforeHandshake: []byte{},
1501 },
1502 },
1503 shouldFail: true,
1504 expectedError: ":UNEXPECTED_RECORD:",
1505 },
1506 {
Adam Langley7c803a62015-06-15 15:35:05 -07001507 name: "AppDataAfterChangeCipherSpec",
1508 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001509 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001510 Bugs: ProtocolBugs{
1511 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1512 },
1513 },
1514 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001515 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001516 },
1517 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001518 name: "AppDataAfterChangeCipherSpec-Empty",
1519 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001520 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001521 Bugs: ProtocolBugs{
1522 AppDataAfterChangeCipherSpec: []byte{},
1523 },
1524 },
1525 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001526 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001527 },
1528 {
Adam Langley7c803a62015-06-15 15:35:05 -07001529 protocol: dtls,
1530 name: "AppDataAfterChangeCipherSpec-DTLS",
1531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001532 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001533 Bugs: ProtocolBugs{
1534 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1535 },
1536 },
1537 // BoringSSL's DTLS implementation will drop the out-of-order
1538 // application data.
1539 },
1540 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001541 protocol: dtls,
1542 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1543 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001544 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001545 Bugs: ProtocolBugs{
1546 AppDataAfterChangeCipherSpec: []byte{},
1547 },
1548 },
1549 // BoringSSL's DTLS implementation will drop the out-of-order
1550 // application data.
1551 },
1552 {
Adam Langley7c803a62015-06-15 15:35:05 -07001553 name: "AlertAfterChangeCipherSpec",
1554 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001555 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001556 Bugs: ProtocolBugs{
1557 AlertAfterChangeCipherSpec: alertRecordOverflow,
1558 },
1559 },
1560 shouldFail: true,
1561 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1562 },
1563 {
1564 protocol: dtls,
1565 name: "AlertAfterChangeCipherSpec-DTLS",
1566 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001567 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001568 Bugs: ProtocolBugs{
1569 AlertAfterChangeCipherSpec: alertRecordOverflow,
1570 },
1571 },
1572 shouldFail: true,
1573 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1574 },
1575 {
1576 protocol: dtls,
1577 name: "ReorderHandshakeFragments-Small-DTLS",
1578 config: Config{
1579 Bugs: ProtocolBugs{
1580 ReorderHandshakeFragments: true,
1581 // Small enough that every handshake message is
1582 // fragmented.
1583 MaxHandshakeRecordLength: 2,
1584 },
1585 },
1586 },
1587 {
1588 protocol: dtls,
1589 name: "ReorderHandshakeFragments-Large-DTLS",
1590 config: Config{
1591 Bugs: ProtocolBugs{
1592 ReorderHandshakeFragments: true,
1593 // Large enough that no handshake message is
1594 // fragmented.
1595 MaxHandshakeRecordLength: 2048,
1596 },
1597 },
1598 },
1599 {
1600 protocol: dtls,
1601 name: "MixCompleteMessageWithFragments-DTLS",
1602 config: Config{
1603 Bugs: ProtocolBugs{
1604 ReorderHandshakeFragments: true,
1605 MixCompleteMessageWithFragments: true,
1606 MaxHandshakeRecordLength: 2,
1607 },
1608 },
1609 },
1610 {
1611 name: "SendInvalidRecordType",
1612 config: Config{
1613 Bugs: ProtocolBugs{
1614 SendInvalidRecordType: true,
1615 },
1616 },
1617 shouldFail: true,
1618 expectedError: ":UNEXPECTED_RECORD:",
1619 },
1620 {
1621 protocol: dtls,
1622 name: "SendInvalidRecordType-DTLS",
1623 config: Config{
1624 Bugs: ProtocolBugs{
1625 SendInvalidRecordType: true,
1626 },
1627 },
1628 shouldFail: true,
1629 expectedError: ":UNEXPECTED_RECORD:",
1630 },
1631 {
1632 name: "FalseStart-SkipServerSecondLeg",
1633 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001634 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001635 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1636 NextProtos: []string{"foo"},
1637 Bugs: ProtocolBugs{
1638 SkipNewSessionTicket: true,
1639 SkipChangeCipherSpec: true,
1640 SkipFinished: true,
1641 ExpectFalseStart: true,
1642 },
1643 },
1644 flags: []string{
1645 "-false-start",
1646 "-handshake-never-done",
1647 "-advertise-alpn", "\x03foo",
1648 },
1649 shimWritesFirst: true,
1650 shouldFail: true,
1651 expectedError: ":UNEXPECTED_RECORD:",
1652 },
1653 {
1654 name: "FalseStart-SkipServerSecondLeg-Implicit",
1655 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001656 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001657 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1658 NextProtos: []string{"foo"},
1659 Bugs: ProtocolBugs{
1660 SkipNewSessionTicket: true,
1661 SkipChangeCipherSpec: true,
1662 SkipFinished: true,
1663 },
1664 },
1665 flags: []string{
1666 "-implicit-handshake",
1667 "-false-start",
1668 "-handshake-never-done",
1669 "-advertise-alpn", "\x03foo",
1670 },
1671 shouldFail: true,
1672 expectedError: ":UNEXPECTED_RECORD:",
1673 },
1674 {
1675 testType: serverTest,
1676 name: "FailEarlyCallback",
1677 flags: []string{"-fail-early-callback"},
1678 shouldFail: true,
1679 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001680 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001681 },
1682 {
Adam Langley7c803a62015-06-15 15:35:05 -07001683 protocol: dtls,
1684 name: "FragmentMessageTypeMismatch-DTLS",
1685 config: Config{
1686 Bugs: ProtocolBugs{
1687 MaxHandshakeRecordLength: 2,
1688 FragmentMessageTypeMismatch: true,
1689 },
1690 },
1691 shouldFail: true,
1692 expectedError: ":FRAGMENT_MISMATCH:",
1693 },
1694 {
1695 protocol: dtls,
1696 name: "FragmentMessageLengthMismatch-DTLS",
1697 config: Config{
1698 Bugs: ProtocolBugs{
1699 MaxHandshakeRecordLength: 2,
1700 FragmentMessageLengthMismatch: true,
1701 },
1702 },
1703 shouldFail: true,
1704 expectedError: ":FRAGMENT_MISMATCH:",
1705 },
1706 {
1707 protocol: dtls,
1708 name: "SplitFragments-Header-DTLS",
1709 config: Config{
1710 Bugs: ProtocolBugs{
1711 SplitFragments: 2,
1712 },
1713 },
1714 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001715 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001716 },
1717 {
1718 protocol: dtls,
1719 name: "SplitFragments-Boundary-DTLS",
1720 config: Config{
1721 Bugs: ProtocolBugs{
1722 SplitFragments: dtlsRecordHeaderLen,
1723 },
1724 },
1725 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001726 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001727 },
1728 {
1729 protocol: dtls,
1730 name: "SplitFragments-Body-DTLS",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 SplitFragments: dtlsRecordHeaderLen + 1,
1734 },
1735 },
1736 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001737 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001738 },
1739 {
1740 protocol: dtls,
1741 name: "SendEmptyFragments-DTLS",
1742 config: Config{
1743 Bugs: ProtocolBugs{
1744 SendEmptyFragments: true,
1745 },
1746 },
1747 },
1748 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001749 name: "BadFinished-Client",
1750 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001751 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001752 Bugs: ProtocolBugs{
1753 BadFinished: true,
1754 },
1755 },
1756 shouldFail: true,
1757 expectedError: ":DIGEST_CHECK_FAILED:",
1758 },
1759 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001760 name: "BadFinished-Client-TLS13",
1761 config: Config{
1762 MaxVersion: VersionTLS13,
1763 Bugs: ProtocolBugs{
1764 BadFinished: true,
1765 },
1766 },
1767 shouldFail: true,
1768 expectedError: ":DIGEST_CHECK_FAILED:",
1769 },
1770 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001771 testType: serverTest,
1772 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001774 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001775 Bugs: ProtocolBugs{
1776 BadFinished: true,
1777 },
1778 },
1779 shouldFail: true,
1780 expectedError: ":DIGEST_CHECK_FAILED:",
1781 },
1782 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001783 testType: serverTest,
1784 name: "BadFinished-Server-TLS13",
1785 config: Config{
1786 MaxVersion: VersionTLS13,
1787 Bugs: ProtocolBugs{
1788 BadFinished: true,
1789 },
1790 },
1791 shouldFail: true,
1792 expectedError: ":DIGEST_CHECK_FAILED:",
1793 },
1794 {
Adam Langley7c803a62015-06-15 15:35:05 -07001795 name: "FalseStart-BadFinished",
1796 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001797 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001798 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1799 NextProtos: []string{"foo"},
1800 Bugs: ProtocolBugs{
1801 BadFinished: true,
1802 ExpectFalseStart: true,
1803 },
1804 },
1805 flags: []string{
1806 "-false-start",
1807 "-handshake-never-done",
1808 "-advertise-alpn", "\x03foo",
1809 },
1810 shimWritesFirst: true,
1811 shouldFail: true,
1812 expectedError: ":DIGEST_CHECK_FAILED:",
1813 },
1814 {
1815 name: "NoFalseStart-NoALPN",
1816 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001817 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001818 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1819 Bugs: ProtocolBugs{
1820 ExpectFalseStart: true,
1821 AlertBeforeFalseStartTest: alertAccessDenied,
1822 },
1823 },
1824 flags: []string{
1825 "-false-start",
1826 },
1827 shimWritesFirst: true,
1828 shouldFail: true,
1829 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1830 expectedLocalError: "tls: peer did not false start: EOF",
1831 },
1832 {
1833 name: "NoFalseStart-NoAEAD",
1834 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001835 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001836 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1837 NextProtos: []string{"foo"},
1838 Bugs: ProtocolBugs{
1839 ExpectFalseStart: true,
1840 AlertBeforeFalseStartTest: alertAccessDenied,
1841 },
1842 },
1843 flags: []string{
1844 "-false-start",
1845 "-advertise-alpn", "\x03foo",
1846 },
1847 shimWritesFirst: true,
1848 shouldFail: true,
1849 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1850 expectedLocalError: "tls: peer did not false start: EOF",
1851 },
1852 {
1853 name: "NoFalseStart-RSA",
1854 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001855 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001856 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1857 NextProtos: []string{"foo"},
1858 Bugs: ProtocolBugs{
1859 ExpectFalseStart: true,
1860 AlertBeforeFalseStartTest: alertAccessDenied,
1861 },
1862 },
1863 flags: []string{
1864 "-false-start",
1865 "-advertise-alpn", "\x03foo",
1866 },
1867 shimWritesFirst: true,
1868 shouldFail: true,
1869 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1870 expectedLocalError: "tls: peer did not false start: EOF",
1871 },
1872 {
1873 name: "NoFalseStart-DHE_RSA",
1874 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001875 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001876 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1877 NextProtos: []string{"foo"},
1878 Bugs: ProtocolBugs{
1879 ExpectFalseStart: true,
1880 AlertBeforeFalseStartTest: alertAccessDenied,
1881 },
1882 },
1883 flags: []string{
1884 "-false-start",
1885 "-advertise-alpn", "\x03foo",
1886 },
1887 shimWritesFirst: true,
1888 shouldFail: true,
1889 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1890 expectedLocalError: "tls: peer did not false start: EOF",
1891 },
1892 {
Adam Langley7c803a62015-06-15 15:35:05 -07001893 protocol: dtls,
1894 name: "SendSplitAlert-Sync",
1895 config: Config{
1896 Bugs: ProtocolBugs{
1897 SendSplitAlert: true,
1898 },
1899 },
1900 },
1901 {
1902 protocol: dtls,
1903 name: "SendSplitAlert-Async",
1904 config: Config{
1905 Bugs: ProtocolBugs{
1906 SendSplitAlert: true,
1907 },
1908 },
1909 flags: []string{"-async"},
1910 },
1911 {
1912 protocol: dtls,
1913 name: "PackDTLSHandshake",
1914 config: Config{
1915 Bugs: ProtocolBugs{
1916 MaxHandshakeRecordLength: 2,
1917 PackHandshakeFragments: 20,
1918 PackHandshakeRecords: 200,
1919 },
1920 },
1921 },
1922 {
Adam Langley7c803a62015-06-15 15:35:05 -07001923 name: "SendEmptyRecords-Pass",
1924 sendEmptyRecords: 32,
1925 },
1926 {
1927 name: "SendEmptyRecords",
1928 sendEmptyRecords: 33,
1929 shouldFail: true,
1930 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1931 },
1932 {
1933 name: "SendEmptyRecords-Async",
1934 sendEmptyRecords: 33,
1935 flags: []string{"-async"},
1936 shouldFail: true,
1937 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1938 },
1939 {
David Benjamine8e84b92016-08-03 15:39:47 -04001940 name: "SendWarningAlerts-Pass",
1941 config: Config{
1942 MaxVersion: VersionTLS12,
1943 },
Adam Langley7c803a62015-06-15 15:35:05 -07001944 sendWarningAlerts: 4,
1945 },
1946 {
David Benjamine8e84b92016-08-03 15:39:47 -04001947 protocol: dtls,
1948 name: "SendWarningAlerts-DTLS-Pass",
1949 config: Config{
1950 MaxVersion: VersionTLS12,
1951 },
Adam Langley7c803a62015-06-15 15:35:05 -07001952 sendWarningAlerts: 4,
1953 },
1954 {
David Benjamine8e84b92016-08-03 15:39:47 -04001955 name: "SendWarningAlerts-TLS13",
1956 config: Config{
1957 MaxVersion: VersionTLS13,
1958 },
1959 sendWarningAlerts: 4,
1960 shouldFail: true,
1961 expectedError: ":BAD_ALERT:",
1962 expectedLocalError: "remote error: error decoding message",
1963 },
1964 {
1965 name: "SendWarningAlerts",
1966 config: Config{
1967 MaxVersion: VersionTLS12,
1968 },
Adam Langley7c803a62015-06-15 15:35:05 -07001969 sendWarningAlerts: 5,
1970 shouldFail: true,
1971 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1972 },
1973 {
David Benjamine8e84b92016-08-03 15:39:47 -04001974 name: "SendWarningAlerts-Async",
1975 config: Config{
1976 MaxVersion: VersionTLS12,
1977 },
Adam Langley7c803a62015-06-15 15:35:05 -07001978 sendWarningAlerts: 5,
1979 flags: []string{"-async"},
1980 shouldFail: true,
1981 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1982 },
David Benjaminba4594a2015-06-18 18:36:15 -04001983 {
Steven Valdez32635b82016-08-16 11:25:03 -04001984 name: "SendKeyUpdates",
1985 config: Config{
1986 MaxVersion: VersionTLS13,
1987 },
1988 sendKeyUpdates: 33,
1989 shouldFail: true,
1990 expectedError: ":TOO_MANY_KEY_UPDATES:",
1991 },
1992 {
David Benjaminba4594a2015-06-18 18:36:15 -04001993 name: "EmptySessionID",
1994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001995 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001996 SessionTicketsDisabled: true,
1997 },
1998 noSessionCache: true,
1999 flags: []string{"-expect-no-session"},
2000 },
David Benjamin30789da2015-08-29 22:56:45 -04002001 {
2002 name: "Unclean-Shutdown",
2003 config: Config{
2004 Bugs: ProtocolBugs{
2005 NoCloseNotify: true,
2006 ExpectCloseNotify: true,
2007 },
2008 },
2009 shimShutsDown: true,
2010 flags: []string{"-check-close-notify"},
2011 shouldFail: true,
2012 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2013 },
2014 {
2015 name: "Unclean-Shutdown-Ignored",
2016 config: Config{
2017 Bugs: ProtocolBugs{
2018 NoCloseNotify: true,
2019 },
2020 },
2021 shimShutsDown: true,
2022 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002023 {
David Benjaminfa214e42016-05-10 17:03:10 -04002024 name: "Unclean-Shutdown-Alert",
2025 config: Config{
2026 Bugs: ProtocolBugs{
2027 SendAlertOnShutdown: alertDecompressionFailure,
2028 ExpectCloseNotify: true,
2029 },
2030 },
2031 shimShutsDown: true,
2032 flags: []string{"-check-close-notify"},
2033 shouldFail: true,
2034 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2035 },
2036 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002037 name: "LargePlaintext",
2038 config: Config{
2039 Bugs: ProtocolBugs{
2040 SendLargeRecords: true,
2041 },
2042 },
2043 messageLen: maxPlaintext + 1,
2044 shouldFail: true,
2045 expectedError: ":DATA_LENGTH_TOO_LONG:",
2046 },
2047 {
2048 protocol: dtls,
2049 name: "LargePlaintext-DTLS",
2050 config: Config{
2051 Bugs: ProtocolBugs{
2052 SendLargeRecords: true,
2053 },
2054 },
2055 messageLen: maxPlaintext + 1,
2056 shouldFail: true,
2057 expectedError: ":DATA_LENGTH_TOO_LONG:",
2058 },
2059 {
2060 name: "LargeCiphertext",
2061 config: Config{
2062 Bugs: ProtocolBugs{
2063 SendLargeRecords: true,
2064 },
2065 },
2066 messageLen: maxPlaintext * 2,
2067 shouldFail: true,
2068 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2069 },
2070 {
2071 protocol: dtls,
2072 name: "LargeCiphertext-DTLS",
2073 config: Config{
2074 Bugs: ProtocolBugs{
2075 SendLargeRecords: true,
2076 },
2077 },
2078 messageLen: maxPlaintext * 2,
2079 // Unlike the other four cases, DTLS drops records which
2080 // are invalid before authentication, so the connection
2081 // does not fail.
2082 expectMessageDropped: true,
2083 },
David Benjamindd6fed92015-10-23 17:41:12 -04002084 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002085 name: "BadHelloRequest-1",
2086 renegotiate: 1,
2087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002088 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002089 Bugs: ProtocolBugs{
2090 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2091 },
2092 },
2093 flags: []string{
2094 "-renegotiate-freely",
2095 "-expect-total-renegotiations", "1",
2096 },
2097 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002098 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002099 },
2100 {
2101 name: "BadHelloRequest-2",
2102 renegotiate: 1,
2103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002104 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002105 Bugs: ProtocolBugs{
2106 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2107 },
2108 },
2109 flags: []string{
2110 "-renegotiate-freely",
2111 "-expect-total-renegotiations", "1",
2112 },
2113 shouldFail: true,
2114 expectedError: ":BAD_HELLO_REQUEST:",
2115 },
David Benjaminef1b0092015-11-21 14:05:44 -05002116 {
2117 testType: serverTest,
2118 name: "SupportTicketsWithSessionID",
2119 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002120 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002121 SessionTicketsDisabled: true,
2122 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002123 resumeConfig: &Config{
2124 MaxVersion: VersionTLS12,
2125 },
David Benjaminef1b0092015-11-21 14:05:44 -05002126 resumeSession: true,
2127 },
David Benjamin02edcd02016-07-27 17:40:37 -04002128 {
2129 protocol: dtls,
2130 name: "DTLS-SendExtraFinished",
2131 config: Config{
2132 Bugs: ProtocolBugs{
2133 SendExtraFinished: true,
2134 },
2135 },
2136 shouldFail: true,
2137 expectedError: ":UNEXPECTED_RECORD:",
2138 },
2139 {
2140 protocol: dtls,
2141 name: "DTLS-SendExtraFinished-Reordered",
2142 config: Config{
2143 Bugs: ProtocolBugs{
2144 MaxHandshakeRecordLength: 2,
2145 ReorderHandshakeFragments: true,
2146 SendExtraFinished: true,
2147 },
2148 },
2149 shouldFail: true,
2150 expectedError: ":UNEXPECTED_RECORD:",
2151 },
David Benjamine97fb482016-07-29 09:23:07 -04002152 {
2153 testType: serverTest,
2154 name: "V2ClientHello-EmptyRecordPrefix",
2155 config: Config{
2156 // Choose a cipher suite that does not involve
2157 // elliptic curves, so no extensions are
2158 // involved.
2159 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002160 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002161 Bugs: ProtocolBugs{
2162 SendV2ClientHello: true,
2163 },
2164 },
2165 sendPrefix: string([]byte{
2166 byte(recordTypeHandshake),
2167 3, 1, // version
2168 0, 0, // length
2169 }),
2170 // A no-op empty record may not be sent before V2ClientHello.
2171 shouldFail: true,
2172 expectedError: ":WRONG_VERSION_NUMBER:",
2173 },
2174 {
2175 testType: serverTest,
2176 name: "V2ClientHello-WarningAlertPrefix",
2177 config: Config{
2178 // Choose a cipher suite that does not involve
2179 // elliptic curves, so no extensions are
2180 // involved.
2181 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002182 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002183 Bugs: ProtocolBugs{
2184 SendV2ClientHello: true,
2185 },
2186 },
2187 sendPrefix: string([]byte{
2188 byte(recordTypeAlert),
2189 3, 1, // version
2190 0, 2, // length
2191 alertLevelWarning, byte(alertDecompressionFailure),
2192 }),
2193 // A no-op warning alert may not be sent before V2ClientHello.
2194 shouldFail: true,
2195 expectedError: ":WRONG_VERSION_NUMBER:",
2196 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002197 {
2198 testType: clientTest,
2199 name: "KeyUpdate",
2200 config: Config{
2201 MaxVersion: VersionTLS13,
2202 Bugs: ProtocolBugs{
2203 SendKeyUpdateBeforeEveryAppDataRecord: true,
2204 },
2205 },
2206 },
David Benjaminabe94e32016-09-04 14:18:58 -04002207 {
2208 name: "SendSNIWarningAlert",
2209 config: Config{
2210 MaxVersion: VersionTLS12,
2211 Bugs: ProtocolBugs{
2212 SendSNIWarningAlert: true,
2213 },
2214 },
2215 },
David Benjaminc241d792016-09-09 10:34:20 -04002216 {
2217 testType: serverTest,
2218 name: "ExtraCompressionMethods-TLS12",
2219 config: Config{
2220 MaxVersion: VersionTLS12,
2221 Bugs: ProtocolBugs{
2222 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2223 },
2224 },
2225 },
2226 {
2227 testType: serverTest,
2228 name: "ExtraCompressionMethods-TLS13",
2229 config: Config{
2230 MaxVersion: VersionTLS13,
2231 Bugs: ProtocolBugs{
2232 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2233 },
2234 },
2235 shouldFail: true,
2236 expectedError: ":INVALID_COMPRESSION_LIST:",
2237 expectedLocalError: "remote error: illegal parameter",
2238 },
2239 {
2240 testType: serverTest,
2241 name: "NoNullCompression-TLS12",
2242 config: Config{
2243 MaxVersion: VersionTLS12,
2244 Bugs: ProtocolBugs{
2245 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2246 },
2247 },
2248 shouldFail: true,
2249 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2250 expectedLocalError: "remote error: illegal parameter",
2251 },
2252 {
2253 testType: serverTest,
2254 name: "NoNullCompression-TLS13",
2255 config: Config{
2256 MaxVersion: VersionTLS13,
2257 Bugs: ProtocolBugs{
2258 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2259 },
2260 },
2261 shouldFail: true,
2262 expectedError: ":INVALID_COMPRESSION_LIST:",
2263 expectedLocalError: "remote error: illegal parameter",
2264 },
David Benjamin65ac9972016-09-02 21:35:25 -04002265 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002266 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002267 config: Config{
2268 MaxVersion: VersionTLS12,
2269 Bugs: ProtocolBugs{
2270 ExpectGREASE: true,
2271 },
2272 },
2273 flags: []string{"-enable-grease"},
2274 },
2275 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002276 name: "GREASE-Client-TLS13",
2277 config: Config{
2278 MaxVersion: VersionTLS13,
2279 Bugs: ProtocolBugs{
2280 ExpectGREASE: true,
2281 },
2282 },
2283 flags: []string{"-enable-grease"},
2284 },
2285 {
2286 testType: serverTest,
2287 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002288 config: Config{
2289 MaxVersion: VersionTLS13,
2290 Bugs: ProtocolBugs{
2291 ExpectGREASE: true,
2292 },
2293 },
2294 flags: []string{"-enable-grease"},
2295 },
Adam Langley7c803a62015-06-15 15:35:05 -07002296 }
Adam Langley7c803a62015-06-15 15:35:05 -07002297 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002298
2299 // Test that very large messages can be received.
2300 cert := rsaCertificate
2301 for i := 0; i < 50; i++ {
2302 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2303 }
2304 testCases = append(testCases, testCase{
2305 name: "LargeMessage",
2306 config: Config{
2307 Certificates: []Certificate{cert},
2308 },
2309 })
2310 testCases = append(testCases, testCase{
2311 protocol: dtls,
2312 name: "LargeMessage-DTLS",
2313 config: Config{
2314 Certificates: []Certificate{cert},
2315 },
2316 })
2317
2318 // They are rejected if the maximum certificate chain length is capped.
2319 testCases = append(testCases, testCase{
2320 name: "LargeMessage-Reject",
2321 config: Config{
2322 Certificates: []Certificate{cert},
2323 },
2324 flags: []string{"-max-cert-list", "16384"},
2325 shouldFail: true,
2326 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2327 })
2328 testCases = append(testCases, testCase{
2329 protocol: dtls,
2330 name: "LargeMessage-Reject-DTLS",
2331 config: Config{
2332 Certificates: []Certificate{cert},
2333 },
2334 flags: []string{"-max-cert-list", "16384"},
2335 shouldFail: true,
2336 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2337 })
Adam Langley7c803a62015-06-15 15:35:05 -07002338}
2339
Adam Langley95c29f32014-06-20 12:00:00 -07002340func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002341 const bogusCipher = 0xfe00
2342
Adam Langley95c29f32014-06-20 12:00:00 -07002343 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002344 const psk = "12345"
2345 const pskIdentity = "luggage combo"
2346
Adam Langley95c29f32014-06-20 12:00:00 -07002347 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002348 var certFile string
2349 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002350 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002351 cert = ecdsaP256Certificate
2352 certFile = ecdsaP256CertificateFile
2353 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002354 } else {
David Benjamin33863262016-07-08 17:20:12 -07002355 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002356 certFile = rsaCertificateFile
2357 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002358 }
2359
David Benjamin48cae082014-10-27 01:06:24 -04002360 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002361 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002362 flags = append(flags,
2363 "-psk", psk,
2364 "-psk-identity", pskIdentity)
2365 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002366 if hasComponent(suite.name, "NULL") {
2367 // NULL ciphers must be explicitly enabled.
2368 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2369 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002370 if hasComponent(suite.name, "CECPQ1") {
2371 // CECPQ1 ciphers must be explicitly enabled.
2372 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2373 }
David Benjamin881f1962016-08-10 18:29:12 -04002374 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2375 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2376 // for now.
2377 flags = append(flags, "-cipher", suite.name)
2378 }
David Benjamin48cae082014-10-27 01:06:24 -04002379
Adam Langley95c29f32014-06-20 12:00:00 -07002380 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002381 for _, protocol := range []protocol{tls, dtls} {
2382 var prefix string
2383 if protocol == dtls {
2384 if !ver.hasDTLS {
2385 continue
2386 }
2387 prefix = "D"
2388 }
Adam Langley95c29f32014-06-20 12:00:00 -07002389
David Benjamin0407e762016-06-17 16:41:18 -04002390 var shouldServerFail, shouldClientFail bool
2391 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2392 // BoringSSL clients accept ECDHE on SSLv3, but
2393 // a BoringSSL server will never select it
2394 // because the extension is missing.
2395 shouldServerFail = true
2396 }
2397 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2398 shouldClientFail = true
2399 shouldServerFail = true
2400 }
David Benjamin54c217c2016-07-13 12:35:25 -04002401 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002402 shouldClientFail = true
2403 shouldServerFail = true
2404 }
Steven Valdez803c77a2016-09-06 14:13:43 -04002405 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2406 shouldClientFail = true
2407 shouldServerFail = true
2408 }
David Benjamin0407e762016-06-17 16:41:18 -04002409 if !isDTLSCipher(suite.name) && protocol == dtls {
2410 shouldClientFail = true
2411 shouldServerFail = true
2412 }
David Benjamin4298d772015-12-19 00:18:25 -05002413
David Benjamin5ecb88b2016-10-04 17:51:35 -04002414 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002415 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002416 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002417 if shouldServerFail {
2418 expectedServerError = ":NO_SHARED_CIPHER:"
2419 }
2420 if shouldClientFail {
2421 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002422 // Configure the server to select ciphers as normal but
2423 // select an incompatible cipher in ServerHello.
2424 serverCipherSuites = nil
2425 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002426 }
David Benjamin025b3d32014-07-01 19:53:04 -04002427
David Benjamin6fd297b2014-08-11 18:43:38 -04002428 testCases = append(testCases, testCase{
2429 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002430 protocol: protocol,
2431
2432 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002433 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002434 MinVersion: ver.version,
2435 MaxVersion: ver.version,
2436 CipherSuites: []uint16{suite.id},
2437 Certificates: []Certificate{cert},
2438 PreSharedKey: []byte(psk),
2439 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002440 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002441 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002442 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002443 },
2444 certFile: certFile,
2445 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002446 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002447 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002448 shouldFail: shouldServerFail,
2449 expectedError: expectedServerError,
2450 })
2451
2452 testCases = append(testCases, testCase{
2453 testType: clientTest,
2454 protocol: protocol,
2455 name: prefix + ver.name + "-" + suite.name + "-client",
2456 config: Config{
2457 MinVersion: ver.version,
2458 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002459 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002460 Certificates: []Certificate{cert},
2461 PreSharedKey: []byte(psk),
2462 PreSharedKeyIdentity: pskIdentity,
2463 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002464 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002465 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002466 },
2467 },
2468 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002469 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002470 shouldFail: shouldClientFail,
2471 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002472 })
David Benjamin2c99d282015-09-01 10:23:00 -04002473
Nick Harper1fd39d82016-06-14 18:14:35 -07002474 if !shouldClientFail {
2475 // Ensure the maximum record size is accepted.
2476 testCases = append(testCases, testCase{
2477 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2478 config: Config{
2479 MinVersion: ver.version,
2480 MaxVersion: ver.version,
2481 CipherSuites: []uint16{suite.id},
2482 Certificates: []Certificate{cert},
2483 PreSharedKey: []byte(psk),
2484 PreSharedKeyIdentity: pskIdentity,
2485 },
2486 flags: flags,
2487 messageLen: maxPlaintext,
2488 })
2489 }
2490 }
David Benjamin2c99d282015-09-01 10:23:00 -04002491 }
Adam Langley95c29f32014-06-20 12:00:00 -07002492 }
Adam Langleya7997f12015-05-14 17:38:50 -07002493
2494 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002495 name: "NoSharedCipher",
2496 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002497 MaxVersion: VersionTLS12,
2498 CipherSuites: []uint16{},
2499 },
2500 shouldFail: true,
2501 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2502 })
2503
2504 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002505 name: "NoSharedCipher-TLS13",
2506 config: Config{
2507 MaxVersion: VersionTLS13,
2508 CipherSuites: []uint16{},
2509 },
2510 shouldFail: true,
2511 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2512 })
2513
2514 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002515 name: "UnsupportedCipherSuite",
2516 config: Config{
2517 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002518 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002519 Bugs: ProtocolBugs{
2520 IgnorePeerCipherPreferences: true,
2521 },
2522 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002523 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002524 shouldFail: true,
2525 expectedError: ":WRONG_CIPHER_RETURNED:",
2526 })
2527
2528 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002529 name: "ServerHelloBogusCipher",
2530 config: Config{
2531 MaxVersion: VersionTLS12,
2532 Bugs: ProtocolBugs{
2533 SendCipherSuite: bogusCipher,
2534 },
2535 },
2536 shouldFail: true,
2537 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2538 })
2539 testCases = append(testCases, testCase{
2540 name: "ServerHelloBogusCipher-TLS13",
2541 config: Config{
2542 MaxVersion: VersionTLS13,
2543 Bugs: ProtocolBugs{
2544 SendCipherSuite: bogusCipher,
2545 },
2546 },
2547 shouldFail: true,
2548 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2549 })
2550
2551 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002552 name: "WeakDH",
2553 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002554 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002555 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2556 Bugs: ProtocolBugs{
2557 // This is a 1023-bit prime number, generated
2558 // with:
2559 // openssl gendh 1023 | openssl asn1parse -i
2560 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2561 },
2562 },
2563 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002564 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002565 })
Adam Langleycef75832015-09-03 14:51:12 -07002566
David Benjamincd24a392015-11-11 13:23:05 -08002567 testCases = append(testCases, testCase{
2568 name: "SillyDH",
2569 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002570 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002571 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2572 Bugs: ProtocolBugs{
2573 // This is a 4097-bit prime number, generated
2574 // with:
2575 // openssl gendh 4097 | openssl asn1parse -i
2576 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2577 },
2578 },
2579 shouldFail: true,
2580 expectedError: ":DH_P_TOO_LONG:",
2581 })
2582
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002583 // This test ensures that Diffie-Hellman public values are padded with
2584 // zeros so that they're the same length as the prime. This is to avoid
2585 // hitting a bug in yaSSL.
2586 testCases = append(testCases, testCase{
2587 testType: serverTest,
2588 name: "DHPublicValuePadded",
2589 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002590 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002591 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2592 Bugs: ProtocolBugs{
2593 RequireDHPublicValueLen: (1025 + 7) / 8,
2594 },
2595 },
2596 flags: []string{"-use-sparse-dh-prime"},
2597 })
David Benjamincd24a392015-11-11 13:23:05 -08002598
David Benjamin241ae832016-01-15 03:04:54 -05002599 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002600 testCases = append(testCases, testCase{
2601 testType: serverTest,
2602 name: "UnknownCipher",
2603 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002604 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002605 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002606 Bugs: ProtocolBugs{
2607 AdvertiseAllConfiguredCiphers: true,
2608 },
2609 },
2610 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002611
2612 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002613 testCases = append(testCases, testCase{
2614 testType: serverTest,
2615 name: "UnknownCipher-TLS13",
2616 config: Config{
2617 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002618 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002619 Bugs: ProtocolBugs{
2620 AdvertiseAllConfiguredCiphers: true,
2621 },
David Benjamin241ae832016-01-15 03:04:54 -05002622 },
2623 })
2624
David Benjamin78679342016-09-16 19:42:05 -04002625 // Test empty ECDHE_PSK identity hints work as expected.
2626 testCases = append(testCases, testCase{
2627 name: "EmptyECDHEPSKHint",
2628 config: Config{
2629 MaxVersion: VersionTLS12,
2630 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2631 PreSharedKey: []byte("secret"),
2632 },
2633 flags: []string{"-psk", "secret"},
2634 })
2635
2636 // Test empty PSK identity hints work as expected, even if an explicit
2637 // ServerKeyExchange is sent.
2638 testCases = append(testCases, testCase{
2639 name: "ExplicitEmptyPSKHint",
2640 config: Config{
2641 MaxVersion: VersionTLS12,
2642 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2643 PreSharedKey: []byte("secret"),
2644 Bugs: ProtocolBugs{
2645 AlwaysSendPreSharedKeyIdentityHint: true,
2646 },
2647 },
2648 flags: []string{"-psk", "secret"},
2649 })
2650
Adam Langleycef75832015-09-03 14:51:12 -07002651 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2652 // 1.1 specific cipher suite settings. A server is setup with the given
2653 // cipher lists and then a connection is made for each member of
2654 // expectations. The cipher suite that the server selects must match
2655 // the specified one.
2656 var versionSpecificCiphersTest = []struct {
2657 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2658 // expectations is a map from TLS version to cipher suite id.
2659 expectations map[uint16]uint16
2660 }{
2661 {
2662 // Test that the null case (where no version-specific ciphers are set)
2663 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002664 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2665 "", // no ciphers specifically for TLS ≥ 1.0
2666 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002667 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002668 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2669 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2670 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2671 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002672 },
2673 },
2674 {
2675 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2676 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002677 "DES-CBC3-SHA:AES128-SHA", // default
2678 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2679 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002680 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002681 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002682 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2683 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2684 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2685 },
2686 },
2687 {
2688 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2689 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002690 "DES-CBC3-SHA:AES128-SHA", // default
2691 "", // no ciphers specifically for TLS ≥ 1.0
2692 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002693 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002694 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2695 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002696 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2697 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2698 },
2699 },
2700 {
2701 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2702 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002703 "DES-CBC3-SHA:AES128-SHA", // default
2704 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2705 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002706 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002707 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002708 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2709 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2710 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2711 },
2712 },
2713 }
2714
2715 for i, test := range versionSpecificCiphersTest {
2716 for version, expectedCipherSuite := range test.expectations {
2717 flags := []string{"-cipher", test.ciphersDefault}
2718 if len(test.ciphersTLS10) > 0 {
2719 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2720 }
2721 if len(test.ciphersTLS11) > 0 {
2722 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2723 }
2724
2725 testCases = append(testCases, testCase{
2726 testType: serverTest,
2727 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2728 config: Config{
2729 MaxVersion: version,
2730 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002731 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Adam Langleycef75832015-09-03 14:51:12 -07002732 },
2733 flags: flags,
2734 expectedCipher: expectedCipherSuite,
2735 })
2736 }
2737 }
Adam Langley95c29f32014-06-20 12:00:00 -07002738}
2739
2740func addBadECDSASignatureTests() {
2741 for badR := BadValue(1); badR < NumBadValues; badR++ {
2742 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002743 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002744 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2745 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002746 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002747 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002748 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002749 Bugs: ProtocolBugs{
2750 BadECDSAR: badR,
2751 BadECDSAS: badS,
2752 },
2753 },
2754 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002755 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002756 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002757 testCases = append(testCases, testCase{
2758 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2759 config: Config{
2760 MaxVersion: VersionTLS13,
2761 Certificates: []Certificate{ecdsaP256Certificate},
2762 Bugs: ProtocolBugs{
2763 BadECDSAR: badR,
2764 BadECDSAS: badS,
2765 },
2766 },
2767 shouldFail: true,
2768 expectedError: ":BAD_SIGNATURE:",
2769 })
Adam Langley95c29f32014-06-20 12:00:00 -07002770 }
2771 }
2772}
2773
Adam Langley80842bd2014-06-20 12:00:00 -07002774func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002775 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002776 name: "MaxCBCPadding",
2777 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002778 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002779 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2780 Bugs: ProtocolBugs{
2781 MaxPadding: true,
2782 },
2783 },
2784 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2785 })
David Benjamin025b3d32014-07-01 19:53:04 -04002786 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002787 name: "BadCBCPadding",
2788 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002789 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002790 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2791 Bugs: ProtocolBugs{
2792 PaddingFirstByteBad: true,
2793 },
2794 },
2795 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002796 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002797 })
2798 // OpenSSL previously had an issue where the first byte of padding in
2799 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002800 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002801 name: "BadCBCPadding255",
2802 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002803 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002804 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2805 Bugs: ProtocolBugs{
2806 MaxPadding: true,
2807 PaddingFirstByteBadIf255: true,
2808 },
2809 },
2810 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2811 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002812 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002813 })
2814}
2815
Kenny Root7fdeaf12014-08-05 15:23:37 -07002816func addCBCSplittingTests() {
2817 testCases = append(testCases, testCase{
2818 name: "CBCRecordSplitting",
2819 config: Config{
2820 MaxVersion: VersionTLS10,
2821 MinVersion: VersionTLS10,
2822 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2823 },
David Benjaminac8302a2015-09-01 17:18:15 -04002824 messageLen: -1, // read until EOF
2825 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002826 flags: []string{
2827 "-async",
2828 "-write-different-record-sizes",
2829 "-cbc-record-splitting",
2830 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002831 })
2832 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002833 name: "CBCRecordSplittingPartialWrite",
2834 config: Config{
2835 MaxVersion: VersionTLS10,
2836 MinVersion: VersionTLS10,
2837 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2838 },
2839 messageLen: -1, // read until EOF
2840 flags: []string{
2841 "-async",
2842 "-write-different-record-sizes",
2843 "-cbc-record-splitting",
2844 "-partial-write",
2845 },
2846 })
2847}
2848
David Benjamin636293b2014-07-08 17:59:18 -04002849func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002850 // Add a dummy cert pool to stress certificate authority parsing.
2851 // TODO(davidben): Add tests that those values parse out correctly.
2852 certPool := x509.NewCertPool()
2853 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2854 if err != nil {
2855 panic(err)
2856 }
2857 certPool.AddCert(cert)
2858
David Benjamin636293b2014-07-08 17:59:18 -04002859 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002860 testCases = append(testCases, testCase{
2861 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002862 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002863 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002864 MinVersion: ver.version,
2865 MaxVersion: ver.version,
2866 ClientAuth: RequireAnyClientCert,
2867 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002868 },
2869 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002870 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2871 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002872 },
2873 })
2874 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002875 testType: serverTest,
2876 name: ver.name + "-Server-ClientAuth-RSA",
2877 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002878 MinVersion: ver.version,
2879 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002880 Certificates: []Certificate{rsaCertificate},
2881 },
2882 flags: []string{"-require-any-client-certificate"},
2883 })
David Benjamine098ec22014-08-27 23:13:20 -04002884 if ver.version != VersionSSL30 {
2885 testCases = append(testCases, testCase{
2886 testType: serverTest,
2887 name: ver.name + "-Server-ClientAuth-ECDSA",
2888 config: Config{
2889 MinVersion: ver.version,
2890 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002891 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002892 },
2893 flags: []string{"-require-any-client-certificate"},
2894 })
2895 testCases = append(testCases, testCase{
2896 testType: clientTest,
2897 name: ver.name + "-Client-ClientAuth-ECDSA",
2898 config: Config{
2899 MinVersion: ver.version,
2900 MaxVersion: ver.version,
2901 ClientAuth: RequireAnyClientCert,
2902 ClientCAs: certPool,
2903 },
2904 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002905 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2906 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002907 },
2908 })
2909 }
Adam Langley37646832016-08-01 16:16:46 -07002910
2911 testCases = append(testCases, testCase{
2912 name: "NoClientCertificate-" + ver.name,
2913 config: Config{
2914 MinVersion: ver.version,
2915 MaxVersion: ver.version,
2916 ClientAuth: RequireAnyClientCert,
2917 },
2918 shouldFail: true,
2919 expectedLocalError: "client didn't provide a certificate",
2920 })
2921
2922 testCases = append(testCases, testCase{
2923 // Even if not configured to expect a certificate, OpenSSL will
2924 // return X509_V_OK as the verify_result.
2925 testType: serverTest,
2926 name: "NoClientCertificateRequested-Server-" + ver.name,
2927 config: Config{
2928 MinVersion: ver.version,
2929 MaxVersion: ver.version,
2930 },
2931 flags: []string{
2932 "-expect-verify-result",
2933 },
2934 // TODO(davidben): Switch this to true when TLS 1.3
2935 // supports session resumption.
2936 resumeSession: ver.version < VersionTLS13,
2937 })
2938
2939 testCases = append(testCases, testCase{
2940 // If a client certificate is not provided, OpenSSL will still
2941 // return X509_V_OK as the verify_result.
2942 testType: serverTest,
2943 name: "NoClientCertificate-Server-" + ver.name,
2944 config: Config{
2945 MinVersion: ver.version,
2946 MaxVersion: ver.version,
2947 },
2948 flags: []string{
2949 "-expect-verify-result",
2950 "-verify-peer",
2951 },
2952 // TODO(davidben): Switch this to true when TLS 1.3
2953 // supports session resumption.
2954 resumeSession: ver.version < VersionTLS13,
2955 })
2956
2957 testCases = append(testCases, testCase{
2958 testType: serverTest,
2959 name: "RequireAnyClientCertificate-" + ver.name,
2960 config: Config{
2961 MinVersion: ver.version,
2962 MaxVersion: ver.version,
2963 },
2964 flags: []string{"-require-any-client-certificate"},
2965 shouldFail: true,
2966 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2967 })
2968
2969 if ver.version != VersionSSL30 {
2970 testCases = append(testCases, testCase{
2971 testType: serverTest,
2972 name: "SkipClientCertificate-" + ver.name,
2973 config: Config{
2974 MinVersion: ver.version,
2975 MaxVersion: ver.version,
2976 Bugs: ProtocolBugs{
2977 SkipClientCertificate: true,
2978 },
2979 },
2980 // Setting SSL_VERIFY_PEER allows anonymous clients.
2981 flags: []string{"-verify-peer"},
2982 shouldFail: true,
2983 expectedError: ":UNEXPECTED_MESSAGE:",
2984 })
2985 }
David Benjamin636293b2014-07-08 17:59:18 -04002986 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002987
David Benjaminc032dfa2016-05-12 14:54:57 -04002988 // Client auth is only legal in certificate-based ciphers.
2989 testCases = append(testCases, testCase{
2990 testType: clientTest,
2991 name: "ClientAuth-PSK",
2992 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002993 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002994 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2995 PreSharedKey: []byte("secret"),
2996 ClientAuth: RequireAnyClientCert,
2997 },
2998 flags: []string{
2999 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3000 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3001 "-psk", "secret",
3002 },
3003 shouldFail: true,
3004 expectedError: ":UNEXPECTED_MESSAGE:",
3005 })
3006 testCases = append(testCases, testCase{
3007 testType: clientTest,
3008 name: "ClientAuth-ECDHE_PSK",
3009 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003010 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003011 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3012 PreSharedKey: []byte("secret"),
3013 ClientAuth: RequireAnyClientCert,
3014 },
3015 flags: []string{
3016 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3017 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3018 "-psk", "secret",
3019 },
3020 shouldFail: true,
3021 expectedError: ":UNEXPECTED_MESSAGE:",
3022 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003023
3024 // Regression test for a bug where the client CA list, if explicitly
3025 // set to NULL, was mis-encoded.
3026 testCases = append(testCases, testCase{
3027 testType: serverTest,
3028 name: "Null-Client-CA-List",
3029 config: Config{
3030 MaxVersion: VersionTLS12,
3031 Certificates: []Certificate{rsaCertificate},
3032 },
3033 flags: []string{
3034 "-require-any-client-certificate",
3035 "-use-null-client-ca-list",
3036 },
3037 })
David Benjamin636293b2014-07-08 17:59:18 -04003038}
3039
Adam Langley75712922014-10-10 16:23:43 -07003040func addExtendedMasterSecretTests() {
3041 const expectEMSFlag = "-expect-extended-master-secret"
3042
3043 for _, with := range []bool{false, true} {
3044 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003045 if with {
3046 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003047 }
3048
3049 for _, isClient := range []bool{false, true} {
3050 suffix := "-Server"
3051 testType := serverTest
3052 if isClient {
3053 suffix = "-Client"
3054 testType = clientTest
3055 }
3056
3057 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003058 // In TLS 1.3, the extension is irrelevant and
3059 // always reports as enabled.
3060 var flags []string
3061 if with || ver.version >= VersionTLS13 {
3062 flags = []string{expectEMSFlag}
3063 }
3064
Adam Langley75712922014-10-10 16:23:43 -07003065 test := testCase{
3066 testType: testType,
3067 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3068 config: Config{
3069 MinVersion: ver.version,
3070 MaxVersion: ver.version,
3071 Bugs: ProtocolBugs{
3072 NoExtendedMasterSecret: !with,
3073 RequireExtendedMasterSecret: with,
3074 },
3075 },
David Benjamin48cae082014-10-27 01:06:24 -04003076 flags: flags,
3077 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003078 }
3079 if test.shouldFail {
3080 test.expectedLocalError = "extended master secret required but not supported by peer"
3081 }
3082 testCases = append(testCases, test)
3083 }
3084 }
3085 }
3086
Adam Langleyba5934b2015-06-02 10:50:35 -07003087 for _, isClient := range []bool{false, true} {
3088 for _, supportedInFirstConnection := range []bool{false, true} {
3089 for _, supportedInResumeConnection := range []bool{false, true} {
3090 boolToWord := func(b bool) string {
3091 if b {
3092 return "Yes"
3093 }
3094 return "No"
3095 }
3096 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3097 if isClient {
3098 suffix += "Client"
3099 } else {
3100 suffix += "Server"
3101 }
3102
3103 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003104 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003105 Bugs: ProtocolBugs{
3106 RequireExtendedMasterSecret: true,
3107 },
3108 }
3109
3110 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003111 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003112 Bugs: ProtocolBugs{
3113 NoExtendedMasterSecret: true,
3114 },
3115 }
3116
3117 test := testCase{
3118 name: "ExtendedMasterSecret-" + suffix,
3119 resumeSession: true,
3120 }
3121
3122 if !isClient {
3123 test.testType = serverTest
3124 }
3125
3126 if supportedInFirstConnection {
3127 test.config = supportedConfig
3128 } else {
3129 test.config = noSupportConfig
3130 }
3131
3132 if supportedInResumeConnection {
3133 test.resumeConfig = &supportedConfig
3134 } else {
3135 test.resumeConfig = &noSupportConfig
3136 }
3137
3138 switch suffix {
3139 case "YesToYes-Client", "YesToYes-Server":
3140 // When a session is resumed, it should
3141 // still be aware that its master
3142 // secret was generated via EMS and
3143 // thus it's safe to use tls-unique.
3144 test.flags = []string{expectEMSFlag}
3145 case "NoToYes-Server":
3146 // If an original connection did not
3147 // contain EMS, but a resumption
3148 // handshake does, then a server should
3149 // not resume the session.
3150 test.expectResumeRejected = true
3151 case "YesToNo-Server":
3152 // Resuming an EMS session without the
3153 // EMS extension should cause the
3154 // server to abort the connection.
3155 test.shouldFail = true
3156 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3157 case "NoToYes-Client":
3158 // A client should abort a connection
3159 // where the server resumed a non-EMS
3160 // session but echoed the EMS
3161 // extension.
3162 test.shouldFail = true
3163 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3164 case "YesToNo-Client":
3165 // A client should abort a connection
3166 // where the server didn't echo EMS
3167 // when the session used it.
3168 test.shouldFail = true
3169 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3170 }
3171
3172 testCases = append(testCases, test)
3173 }
3174 }
3175 }
David Benjamin163c9562016-08-29 23:14:17 -04003176
3177 // Switching EMS on renegotiation is forbidden.
3178 testCases = append(testCases, testCase{
3179 name: "ExtendedMasterSecret-Renego-NoEMS",
3180 config: Config{
3181 MaxVersion: VersionTLS12,
3182 Bugs: ProtocolBugs{
3183 NoExtendedMasterSecret: true,
3184 NoExtendedMasterSecretOnRenegotiation: true,
3185 },
3186 },
3187 renegotiate: 1,
3188 flags: []string{
3189 "-renegotiate-freely",
3190 "-expect-total-renegotiations", "1",
3191 },
3192 })
3193
3194 testCases = append(testCases, testCase{
3195 name: "ExtendedMasterSecret-Renego-Upgrade",
3196 config: Config{
3197 MaxVersion: VersionTLS12,
3198 Bugs: ProtocolBugs{
3199 NoExtendedMasterSecret: true,
3200 },
3201 },
3202 renegotiate: 1,
3203 flags: []string{
3204 "-renegotiate-freely",
3205 "-expect-total-renegotiations", "1",
3206 },
3207 shouldFail: true,
3208 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3209 })
3210
3211 testCases = append(testCases, testCase{
3212 name: "ExtendedMasterSecret-Renego-Downgrade",
3213 config: Config{
3214 MaxVersion: VersionTLS12,
3215 Bugs: ProtocolBugs{
3216 NoExtendedMasterSecretOnRenegotiation: true,
3217 },
3218 },
3219 renegotiate: 1,
3220 flags: []string{
3221 "-renegotiate-freely",
3222 "-expect-total-renegotiations", "1",
3223 },
3224 shouldFail: true,
3225 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3226 })
Adam Langley75712922014-10-10 16:23:43 -07003227}
3228
David Benjamin582ba042016-07-07 12:33:25 -07003229type stateMachineTestConfig struct {
3230 protocol protocol
3231 async bool
3232 splitHandshake, packHandshakeFlight bool
3233}
3234
David Benjamin43ec06f2014-08-05 02:28:57 -04003235// Adds tests that try to cover the range of the handshake state machine, under
3236// various conditions. Some of these are redundant with other tests, but they
3237// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003238func addAllStateMachineCoverageTests() {
3239 for _, async := range []bool{false, true} {
3240 for _, protocol := range []protocol{tls, dtls} {
3241 addStateMachineCoverageTests(stateMachineTestConfig{
3242 protocol: protocol,
3243 async: async,
3244 })
3245 addStateMachineCoverageTests(stateMachineTestConfig{
3246 protocol: protocol,
3247 async: async,
3248 splitHandshake: true,
3249 })
3250 if protocol == tls {
3251 addStateMachineCoverageTests(stateMachineTestConfig{
3252 protocol: protocol,
3253 async: async,
3254 packHandshakeFlight: true,
3255 })
3256 }
3257 }
3258 }
3259}
3260
3261func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003262 var tests []testCase
3263
3264 // Basic handshake, with resumption. Client and server,
3265 // session ID and session ticket.
3266 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003267 name: "Basic-Client",
3268 config: Config{
3269 MaxVersion: VersionTLS12,
3270 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003271 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003272 // Ensure session tickets are used, not session IDs.
3273 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003274 })
3275 tests = append(tests, testCase{
3276 name: "Basic-Client-RenewTicket",
3277 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003278 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003279 Bugs: ProtocolBugs{
3280 RenewTicketOnResume: true,
3281 },
3282 },
David Benjamin46662482016-08-17 00:51:00 -04003283 flags: []string{"-expect-ticket-renewal"},
3284 resumeSession: true,
3285 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003286 })
3287 tests = append(tests, testCase{
3288 name: "Basic-Client-NoTicket",
3289 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003290 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003291 SessionTicketsDisabled: true,
3292 },
3293 resumeSession: true,
3294 })
3295 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003296 name: "Basic-Client-Implicit",
3297 config: Config{
3298 MaxVersion: VersionTLS12,
3299 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003300 flags: []string{"-implicit-handshake"},
3301 resumeSession: true,
3302 })
3303 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003304 testType: serverTest,
3305 name: "Basic-Server",
3306 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003307 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003308 Bugs: ProtocolBugs{
3309 RequireSessionTickets: true,
3310 },
3311 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003312 resumeSession: true,
3313 })
3314 tests = append(tests, testCase{
3315 testType: serverTest,
3316 name: "Basic-Server-NoTickets",
3317 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003318 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003319 SessionTicketsDisabled: true,
3320 },
3321 resumeSession: true,
3322 })
3323 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003324 testType: serverTest,
3325 name: "Basic-Server-Implicit",
3326 config: Config{
3327 MaxVersion: VersionTLS12,
3328 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003329 flags: []string{"-implicit-handshake"},
3330 resumeSession: true,
3331 })
3332 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003333 testType: serverTest,
3334 name: "Basic-Server-EarlyCallback",
3335 config: Config{
3336 MaxVersion: VersionTLS12,
3337 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003338 flags: []string{"-use-early-callback"},
3339 resumeSession: true,
3340 })
3341
Steven Valdez143e8b32016-07-11 13:19:03 -04003342 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003343 if config.protocol == tls {
3344 tests = append(tests, testCase{
3345 name: "TLS13-1RTT-Client",
3346 config: Config{
3347 MaxVersion: VersionTLS13,
3348 MinVersion: VersionTLS13,
3349 },
David Benjamin46662482016-08-17 00:51:00 -04003350 resumeSession: true,
3351 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003352 })
3353
3354 tests = append(tests, testCase{
3355 testType: serverTest,
3356 name: "TLS13-1RTT-Server",
3357 config: Config{
3358 MaxVersion: VersionTLS13,
3359 MinVersion: VersionTLS13,
3360 },
David Benjamin46662482016-08-17 00:51:00 -04003361 resumeSession: true,
3362 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003363 })
3364
3365 tests = append(tests, testCase{
3366 name: "TLS13-HelloRetryRequest-Client",
3367 config: Config{
3368 MaxVersion: VersionTLS13,
3369 MinVersion: VersionTLS13,
3370 // P-384 requires a HelloRetryRequest against
3371 // BoringSSL's default configuration. Assert
3372 // that we do indeed test this with
3373 // ExpectMissingKeyShare.
3374 CurvePreferences: []CurveID{CurveP384},
3375 Bugs: ProtocolBugs{
3376 ExpectMissingKeyShare: true,
3377 },
3378 },
3379 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3380 resumeSession: true,
3381 })
3382
3383 tests = append(tests, testCase{
3384 testType: serverTest,
3385 name: "TLS13-HelloRetryRequest-Server",
3386 config: Config{
3387 MaxVersion: VersionTLS13,
3388 MinVersion: VersionTLS13,
3389 // Require a HelloRetryRequest for every curve.
3390 DefaultCurves: []CurveID{},
3391 },
3392 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3393 resumeSession: true,
3394 })
3395 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003396
David Benjamin760b1dd2015-05-15 23:33:48 -04003397 // TLS client auth.
3398 tests = append(tests, testCase{
3399 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003400 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003401 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003402 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003403 ClientAuth: RequestClientCert,
3404 },
3405 })
3406 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003407 testType: serverTest,
3408 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003409 config: Config{
3410 MaxVersion: VersionTLS12,
3411 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003412 // Setting SSL_VERIFY_PEER allows anonymous clients.
3413 flags: []string{"-verify-peer"},
3414 })
David Benjamin582ba042016-07-07 12:33:25 -07003415 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003416 tests = append(tests, testCase{
3417 testType: clientTest,
3418 name: "ClientAuth-NoCertificate-Client-SSL3",
3419 config: Config{
3420 MaxVersion: VersionSSL30,
3421 ClientAuth: RequestClientCert,
3422 },
3423 })
3424 tests = append(tests, testCase{
3425 testType: serverTest,
3426 name: "ClientAuth-NoCertificate-Server-SSL3",
3427 config: Config{
3428 MaxVersion: VersionSSL30,
3429 },
3430 // Setting SSL_VERIFY_PEER allows anonymous clients.
3431 flags: []string{"-verify-peer"},
3432 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003433 tests = append(tests, testCase{
3434 testType: clientTest,
3435 name: "ClientAuth-NoCertificate-Client-TLS13",
3436 config: Config{
3437 MaxVersion: VersionTLS13,
3438 ClientAuth: RequestClientCert,
3439 },
3440 })
3441 tests = append(tests, testCase{
3442 testType: serverTest,
3443 name: "ClientAuth-NoCertificate-Server-TLS13",
3444 config: Config{
3445 MaxVersion: VersionTLS13,
3446 },
3447 // Setting SSL_VERIFY_PEER allows anonymous clients.
3448 flags: []string{"-verify-peer"},
3449 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003450 }
3451 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003452 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003453 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003454 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003455 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003456 ClientAuth: RequireAnyClientCert,
3457 },
3458 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003459 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3460 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003461 },
3462 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003463 tests = append(tests, testCase{
3464 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003465 name: "ClientAuth-RSA-Client-TLS13",
3466 config: Config{
3467 MaxVersion: VersionTLS13,
3468 ClientAuth: RequireAnyClientCert,
3469 },
3470 flags: []string{
3471 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3472 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3473 },
3474 })
3475 tests = append(tests, testCase{
3476 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003477 name: "ClientAuth-ECDSA-Client",
3478 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003479 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003480 ClientAuth: RequireAnyClientCert,
3481 },
3482 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003483 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3484 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003485 },
3486 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003487 tests = append(tests, testCase{
3488 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003489 name: "ClientAuth-ECDSA-Client-TLS13",
3490 config: Config{
3491 MaxVersion: VersionTLS13,
3492 ClientAuth: RequireAnyClientCert,
3493 },
3494 flags: []string{
3495 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3496 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3497 },
3498 })
3499 tests = append(tests, testCase{
3500 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003501 name: "ClientAuth-NoCertificate-OldCallback",
3502 config: Config{
3503 MaxVersion: VersionTLS12,
3504 ClientAuth: RequestClientCert,
3505 },
3506 flags: []string{"-use-old-client-cert-callback"},
3507 })
3508 tests = append(tests, testCase{
3509 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003510 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3511 config: Config{
3512 MaxVersion: VersionTLS13,
3513 ClientAuth: RequestClientCert,
3514 },
3515 flags: []string{"-use-old-client-cert-callback"},
3516 })
3517 tests = append(tests, testCase{
3518 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003519 name: "ClientAuth-OldCallback",
3520 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003521 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003522 ClientAuth: RequireAnyClientCert,
3523 },
3524 flags: []string{
3525 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3526 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3527 "-use-old-client-cert-callback",
3528 },
3529 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003530 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003531 testType: clientTest,
3532 name: "ClientAuth-OldCallback-TLS13",
3533 config: Config{
3534 MaxVersion: VersionTLS13,
3535 ClientAuth: RequireAnyClientCert,
3536 },
3537 flags: []string{
3538 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3539 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3540 "-use-old-client-cert-callback",
3541 },
3542 })
3543 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003544 testType: serverTest,
3545 name: "ClientAuth-Server",
3546 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003547 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003548 Certificates: []Certificate{rsaCertificate},
3549 },
3550 flags: []string{"-require-any-client-certificate"},
3551 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003552 tests = append(tests, testCase{
3553 testType: serverTest,
3554 name: "ClientAuth-Server-TLS13",
3555 config: Config{
3556 MaxVersion: VersionTLS13,
3557 Certificates: []Certificate{rsaCertificate},
3558 },
3559 flags: []string{"-require-any-client-certificate"},
3560 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003561
David Benjamin4c3ddf72016-06-29 18:13:53 -04003562 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003563 tests = append(tests, testCase{
3564 testType: serverTest,
3565 name: "Basic-Server-RSA",
3566 config: Config{
3567 MaxVersion: VersionTLS12,
3568 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3569 },
3570 flags: []string{
3571 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3572 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3573 },
3574 })
3575 tests = append(tests, testCase{
3576 testType: serverTest,
3577 name: "Basic-Server-ECDHE-RSA",
3578 config: Config{
3579 MaxVersion: VersionTLS12,
3580 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3581 },
3582 flags: []string{
3583 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3584 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3585 },
3586 })
3587 tests = append(tests, testCase{
3588 testType: serverTest,
3589 name: "Basic-Server-ECDHE-ECDSA",
3590 config: Config{
3591 MaxVersion: VersionTLS12,
3592 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3593 },
3594 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003595 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3596 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003597 },
3598 })
3599
David Benjamin760b1dd2015-05-15 23:33:48 -04003600 // No session ticket support; server doesn't send NewSessionTicket.
3601 tests = append(tests, testCase{
3602 name: "SessionTicketsDisabled-Client",
3603 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003604 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003605 SessionTicketsDisabled: true,
3606 },
3607 })
3608 tests = append(tests, testCase{
3609 testType: serverTest,
3610 name: "SessionTicketsDisabled-Server",
3611 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003612 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003613 SessionTicketsDisabled: true,
3614 },
3615 })
3616
3617 // Skip ServerKeyExchange in PSK key exchange if there's no
3618 // identity hint.
3619 tests = append(tests, testCase{
3620 name: "EmptyPSKHint-Client",
3621 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003622 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003623 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3624 PreSharedKey: []byte("secret"),
3625 },
3626 flags: []string{"-psk", "secret"},
3627 })
3628 tests = append(tests, testCase{
3629 testType: serverTest,
3630 name: "EmptyPSKHint-Server",
3631 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003632 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003633 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3634 PreSharedKey: []byte("secret"),
3635 },
3636 flags: []string{"-psk", "secret"},
3637 })
3638
David Benjamin4c3ddf72016-06-29 18:13:53 -04003639 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003640 tests = append(tests, testCase{
3641 testType: clientTest,
3642 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003643 config: Config{
3644 MaxVersion: VersionTLS12,
3645 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003646 flags: []string{
3647 "-enable-ocsp-stapling",
3648 "-expect-ocsp-response",
3649 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003650 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003651 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003652 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003653 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003654 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003655 testType: serverTest,
3656 name: "OCSPStapling-Server",
3657 config: Config{
3658 MaxVersion: VersionTLS12,
3659 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003660 expectedOCSPResponse: testOCSPResponse,
3661 flags: []string{
3662 "-ocsp-response",
3663 base64.StdEncoding.EncodeToString(testOCSPResponse),
3664 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003665 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003666 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003667 tests = append(tests, testCase{
3668 testType: clientTest,
3669 name: "OCSPStapling-Client-TLS13",
3670 config: Config{
3671 MaxVersion: VersionTLS13,
3672 },
3673 flags: []string{
3674 "-enable-ocsp-stapling",
3675 "-expect-ocsp-response",
3676 base64.StdEncoding.EncodeToString(testOCSPResponse),
3677 "-verify-peer",
3678 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003679 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003680 })
3681 tests = append(tests, testCase{
3682 testType: serverTest,
3683 name: "OCSPStapling-Server-TLS13",
3684 config: Config{
3685 MaxVersion: VersionTLS13,
3686 },
3687 expectedOCSPResponse: testOCSPResponse,
3688 flags: []string{
3689 "-ocsp-response",
3690 base64.StdEncoding.EncodeToString(testOCSPResponse),
3691 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003692 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003693 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003694
David Benjamin4c3ddf72016-06-29 18:13:53 -04003695 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003696 for _, vers := range tlsVersions {
3697 if config.protocol == dtls && !vers.hasDTLS {
3698 continue
3699 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003700 for _, testType := range []testType{clientTest, serverTest} {
3701 suffix := "-Client"
3702 if testType == serverTest {
3703 suffix = "-Server"
3704 }
3705 suffix += "-" + vers.name
3706
3707 flag := "-verify-peer"
3708 if testType == serverTest {
3709 flag = "-require-any-client-certificate"
3710 }
3711
3712 tests = append(tests, testCase{
3713 testType: testType,
3714 name: "CertificateVerificationSucceed" + suffix,
3715 config: Config{
3716 MaxVersion: vers.version,
3717 Certificates: []Certificate{rsaCertificate},
3718 },
3719 flags: []string{
3720 flag,
3721 "-expect-verify-result",
3722 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003723 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003724 })
3725 tests = append(tests, testCase{
3726 testType: testType,
3727 name: "CertificateVerificationFail" + suffix,
3728 config: Config{
3729 MaxVersion: vers.version,
3730 Certificates: []Certificate{rsaCertificate},
3731 },
3732 flags: []string{
3733 flag,
3734 "-verify-fail",
3735 },
3736 shouldFail: true,
3737 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3738 })
3739 }
3740
3741 // By default, the client is in a soft fail mode where the peer
3742 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003743 tests = append(tests, testCase{
3744 testType: clientTest,
3745 name: "CertificateVerificationSoftFail-" + vers.name,
3746 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003747 MaxVersion: vers.version,
3748 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003749 },
3750 flags: []string{
3751 "-verify-fail",
3752 "-expect-verify-result",
3753 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003754 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003755 })
3756 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003757
David Benjamin1d4f4c02016-07-26 18:03:08 -04003758 tests = append(tests, testCase{
3759 name: "ShimSendAlert",
3760 flags: []string{"-send-alert"},
3761 shimWritesFirst: true,
3762 shouldFail: true,
3763 expectedLocalError: "remote error: decompression failure",
3764 })
3765
David Benjamin582ba042016-07-07 12:33:25 -07003766 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003767 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003768 name: "Renegotiate-Client",
3769 config: Config{
3770 MaxVersion: VersionTLS12,
3771 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003772 renegotiate: 1,
3773 flags: []string{
3774 "-renegotiate-freely",
3775 "-expect-total-renegotiations", "1",
3776 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003777 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003778
David Benjamin47921102016-07-28 11:29:18 -04003779 tests = append(tests, testCase{
3780 name: "SendHalfHelloRequest",
3781 config: Config{
3782 MaxVersion: VersionTLS12,
3783 Bugs: ProtocolBugs{
3784 PackHelloRequestWithFinished: config.packHandshakeFlight,
3785 },
3786 },
3787 sendHalfHelloRequest: true,
3788 flags: []string{"-renegotiate-ignore"},
3789 shouldFail: true,
3790 expectedError: ":UNEXPECTED_RECORD:",
3791 })
3792
David Benjamin760b1dd2015-05-15 23:33:48 -04003793 // NPN on client and server; results in post-handshake message.
3794 tests = append(tests, testCase{
3795 name: "NPN-Client",
3796 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003797 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003798 NextProtos: []string{"foo"},
3799 },
3800 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003801 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003802 expectedNextProto: "foo",
3803 expectedNextProtoType: npn,
3804 })
3805 tests = append(tests, testCase{
3806 testType: serverTest,
3807 name: "NPN-Server",
3808 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003809 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003810 NextProtos: []string{"bar"},
3811 },
3812 flags: []string{
3813 "-advertise-npn", "\x03foo\x03bar\x03baz",
3814 "-expect-next-proto", "bar",
3815 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003816 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003817 expectedNextProto: "bar",
3818 expectedNextProtoType: npn,
3819 })
3820
3821 // TODO(davidben): Add tests for when False Start doesn't trigger.
3822
3823 // Client does False Start and negotiates NPN.
3824 tests = append(tests, testCase{
3825 name: "FalseStart",
3826 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003827 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003828 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3829 NextProtos: []string{"foo"},
3830 Bugs: ProtocolBugs{
3831 ExpectFalseStart: true,
3832 },
3833 },
3834 flags: []string{
3835 "-false-start",
3836 "-select-next-proto", "foo",
3837 },
3838 shimWritesFirst: true,
3839 resumeSession: true,
3840 })
3841
3842 // Client does False Start and negotiates ALPN.
3843 tests = append(tests, testCase{
3844 name: "FalseStart-ALPN",
3845 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003846 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003847 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3848 NextProtos: []string{"foo"},
3849 Bugs: ProtocolBugs{
3850 ExpectFalseStart: true,
3851 },
3852 },
3853 flags: []string{
3854 "-false-start",
3855 "-advertise-alpn", "\x03foo",
3856 },
3857 shimWritesFirst: true,
3858 resumeSession: true,
3859 })
3860
3861 // Client does False Start but doesn't explicitly call
3862 // SSL_connect.
3863 tests = append(tests, testCase{
3864 name: "FalseStart-Implicit",
3865 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003866 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003867 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3868 NextProtos: []string{"foo"},
3869 },
3870 flags: []string{
3871 "-implicit-handshake",
3872 "-false-start",
3873 "-advertise-alpn", "\x03foo",
3874 },
3875 })
3876
3877 // False Start without session tickets.
3878 tests = append(tests, testCase{
3879 name: "FalseStart-SessionTicketsDisabled",
3880 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003881 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003882 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3883 NextProtos: []string{"foo"},
3884 SessionTicketsDisabled: true,
3885 Bugs: ProtocolBugs{
3886 ExpectFalseStart: true,
3887 },
3888 },
3889 flags: []string{
3890 "-false-start",
3891 "-select-next-proto", "foo",
3892 },
3893 shimWritesFirst: true,
3894 })
3895
Adam Langleydf759b52016-07-11 15:24:37 -07003896 tests = append(tests, testCase{
3897 name: "FalseStart-CECPQ1",
3898 config: Config{
3899 MaxVersion: VersionTLS12,
3900 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3901 NextProtos: []string{"foo"},
3902 Bugs: ProtocolBugs{
3903 ExpectFalseStart: true,
3904 },
3905 },
3906 flags: []string{
3907 "-false-start",
3908 "-cipher", "DEFAULT:kCECPQ1",
3909 "-select-next-proto", "foo",
3910 },
3911 shimWritesFirst: true,
3912 resumeSession: true,
3913 })
3914
David Benjamin760b1dd2015-05-15 23:33:48 -04003915 // Server parses a V2ClientHello.
3916 tests = append(tests, testCase{
3917 testType: serverTest,
3918 name: "SendV2ClientHello",
3919 config: Config{
3920 // Choose a cipher suite that does not involve
3921 // elliptic curves, so no extensions are
3922 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003923 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003924 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003925 Bugs: ProtocolBugs{
3926 SendV2ClientHello: true,
3927 },
3928 },
3929 })
3930
3931 // Client sends a Channel ID.
3932 tests = append(tests, testCase{
3933 name: "ChannelID-Client",
3934 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003935 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003936 RequestChannelID: true,
3937 },
Adam Langley7c803a62015-06-15 15:35:05 -07003938 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003939 resumeSession: true,
3940 expectChannelID: true,
3941 })
3942
3943 // Server accepts a Channel ID.
3944 tests = append(tests, testCase{
3945 testType: serverTest,
3946 name: "ChannelID-Server",
3947 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003948 MaxVersion: VersionTLS12,
3949 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003950 },
3951 flags: []string{
3952 "-expect-channel-id",
3953 base64.StdEncoding.EncodeToString(channelIDBytes),
3954 },
3955 resumeSession: true,
3956 expectChannelID: true,
3957 })
David Benjamin30789da2015-08-29 22:56:45 -04003958
David Benjaminf8fcdf32016-06-08 15:56:13 -04003959 // Channel ID and NPN at the same time, to ensure their relative
3960 // ordering is correct.
3961 tests = append(tests, testCase{
3962 name: "ChannelID-NPN-Client",
3963 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003964 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003965 RequestChannelID: true,
3966 NextProtos: []string{"foo"},
3967 },
3968 flags: []string{
3969 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3970 "-select-next-proto", "foo",
3971 },
3972 resumeSession: true,
3973 expectChannelID: true,
3974 expectedNextProto: "foo",
3975 expectedNextProtoType: npn,
3976 })
3977 tests = append(tests, testCase{
3978 testType: serverTest,
3979 name: "ChannelID-NPN-Server",
3980 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003981 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003982 ChannelID: channelIDKey,
3983 NextProtos: []string{"bar"},
3984 },
3985 flags: []string{
3986 "-expect-channel-id",
3987 base64.StdEncoding.EncodeToString(channelIDBytes),
3988 "-advertise-npn", "\x03foo\x03bar\x03baz",
3989 "-expect-next-proto", "bar",
3990 },
3991 resumeSession: true,
3992 expectChannelID: true,
3993 expectedNextProto: "bar",
3994 expectedNextProtoType: npn,
3995 })
3996
David Benjamin30789da2015-08-29 22:56:45 -04003997 // Bidirectional shutdown with the runner initiating.
3998 tests = append(tests, testCase{
3999 name: "Shutdown-Runner",
4000 config: Config{
4001 Bugs: ProtocolBugs{
4002 ExpectCloseNotify: true,
4003 },
4004 },
4005 flags: []string{"-check-close-notify"},
4006 })
4007
4008 // Bidirectional shutdown with the shim initiating. The runner,
4009 // in the meantime, sends garbage before the close_notify which
4010 // the shim must ignore.
4011 tests = append(tests, testCase{
4012 name: "Shutdown-Shim",
4013 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004014 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004015 Bugs: ProtocolBugs{
4016 ExpectCloseNotify: true,
4017 },
4018 },
4019 shimShutsDown: true,
4020 sendEmptyRecords: 1,
4021 sendWarningAlerts: 1,
4022 flags: []string{"-check-close-notify"},
4023 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004024 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004025 // TODO(davidben): DTLS 1.3 will want a similar thing for
4026 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004027 tests = append(tests, testCase{
4028 name: "SkipHelloVerifyRequest",
4029 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004030 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004031 Bugs: ProtocolBugs{
4032 SkipHelloVerifyRequest: true,
4033 },
4034 },
4035 })
4036 }
4037
David Benjamin760b1dd2015-05-15 23:33:48 -04004038 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004039 test.protocol = config.protocol
4040 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004041 test.name += "-DTLS"
4042 }
David Benjamin582ba042016-07-07 12:33:25 -07004043 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004044 test.name += "-Async"
4045 test.flags = append(test.flags, "-async")
4046 } else {
4047 test.name += "-Sync"
4048 }
David Benjamin582ba042016-07-07 12:33:25 -07004049 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004050 test.name += "-SplitHandshakeRecords"
4051 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004052 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004053 test.config.Bugs.MaxPacketLength = 256
4054 test.flags = append(test.flags, "-mtu", "256")
4055 }
4056 }
David Benjamin582ba042016-07-07 12:33:25 -07004057 if config.packHandshakeFlight {
4058 test.name += "-PackHandshakeFlight"
4059 test.config.Bugs.PackHandshakeFlight = true
4060 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004061 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004062 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004063}
4064
Adam Langley524e7172015-02-20 16:04:00 -08004065func addDDoSCallbackTests() {
4066 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004067 for _, resume := range []bool{false, true} {
4068 suffix := "Resume"
4069 if resume {
4070 suffix = "No" + suffix
4071 }
4072
4073 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004074 testType: serverTest,
4075 name: "Server-DDoS-OK-" + suffix,
4076 config: Config{
4077 MaxVersion: VersionTLS12,
4078 },
Adam Langley524e7172015-02-20 16:04:00 -08004079 flags: []string{"-install-ddos-callback"},
4080 resumeSession: resume,
4081 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004082 testCases = append(testCases, testCase{
4083 testType: serverTest,
4084 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4085 config: Config{
4086 MaxVersion: VersionTLS13,
4087 },
4088 flags: []string{"-install-ddos-callback"},
4089 resumeSession: resume,
4090 })
Adam Langley524e7172015-02-20 16:04:00 -08004091
4092 failFlag := "-fail-ddos-callback"
4093 if resume {
4094 failFlag = "-fail-second-ddos-callback"
4095 }
4096 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004097 testType: serverTest,
4098 name: "Server-DDoS-Reject-" + suffix,
4099 config: Config{
4100 MaxVersion: VersionTLS12,
4101 },
David Benjamin2c66e072016-09-16 15:58:00 -04004102 flags: []string{"-install-ddos-callback", failFlag},
4103 resumeSession: resume,
4104 shouldFail: true,
4105 expectedError: ":CONNECTION_REJECTED:",
4106 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004107 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004108 testCases = append(testCases, testCase{
4109 testType: serverTest,
4110 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4111 config: Config{
4112 MaxVersion: VersionTLS13,
4113 },
David Benjamin2c66e072016-09-16 15:58:00 -04004114 flags: []string{"-install-ddos-callback", failFlag},
4115 resumeSession: resume,
4116 shouldFail: true,
4117 expectedError: ":CONNECTION_REJECTED:",
4118 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004119 })
Adam Langley524e7172015-02-20 16:04:00 -08004120 }
4121}
4122
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004123func addVersionNegotiationTests() {
4124 for i, shimVers := range tlsVersions {
4125 // Assemble flags to disable all newer versions on the shim.
4126 var flags []string
4127 for _, vers := range tlsVersions[i+1:] {
4128 flags = append(flags, vers.flag)
4129 }
4130
Steven Valdezfdd10992016-09-15 16:27:05 -04004131 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004132 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004133 protocols := []protocol{tls}
4134 if runnerVers.hasDTLS && shimVers.hasDTLS {
4135 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004136 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004137 for _, protocol := range protocols {
4138 expectedVersion := shimVers.version
4139 if runnerVers.version < shimVers.version {
4140 expectedVersion = runnerVers.version
4141 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004142
David Benjamin8b8c0062014-11-23 02:47:52 -05004143 suffix := shimVers.name + "-" + runnerVers.name
4144 if protocol == dtls {
4145 suffix += "-DTLS"
4146 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004147
David Benjamin1eb367c2014-12-12 18:17:51 -05004148 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4149
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004150 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004151 clientVers := shimVers.version
4152 if clientVers > VersionTLS10 {
4153 clientVers = VersionTLS10
4154 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004155 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004156 serverVers := expectedVersion
4157 if expectedVersion >= VersionTLS13 {
4158 serverVers = VersionTLS10
4159 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004160 serverVers = versionToWire(serverVers, protocol == dtls)
4161
David Benjamin8b8c0062014-11-23 02:47:52 -05004162 testCases = append(testCases, testCase{
4163 protocol: protocol,
4164 testType: clientTest,
4165 name: "VersionNegotiation-Client-" + suffix,
4166 config: Config{
4167 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004168 Bugs: ProtocolBugs{
4169 ExpectInitialRecordVersion: clientVers,
4170 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004171 },
4172 flags: flags,
4173 expectedVersion: expectedVersion,
4174 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004175 testCases = append(testCases, testCase{
4176 protocol: protocol,
4177 testType: clientTest,
4178 name: "VersionNegotiation-Client2-" + suffix,
4179 config: Config{
4180 MaxVersion: runnerVers.version,
4181 Bugs: ProtocolBugs{
4182 ExpectInitialRecordVersion: clientVers,
4183 },
4184 },
4185 flags: []string{"-max-version", shimVersFlag},
4186 expectedVersion: expectedVersion,
4187 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004188
4189 testCases = append(testCases, testCase{
4190 protocol: protocol,
4191 testType: serverTest,
4192 name: "VersionNegotiation-Server-" + suffix,
4193 config: Config{
4194 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004195 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004196 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004197 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004198 },
4199 flags: flags,
4200 expectedVersion: expectedVersion,
4201 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004202 testCases = append(testCases, testCase{
4203 protocol: protocol,
4204 testType: serverTest,
4205 name: "VersionNegotiation-Server2-" + suffix,
4206 config: Config{
4207 MaxVersion: runnerVers.version,
4208 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004209 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004210 },
4211 },
4212 flags: []string{"-max-version", shimVersFlag},
4213 expectedVersion: expectedVersion,
4214 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004215 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004216 }
4217 }
David Benjamin95c69562016-06-29 18:15:03 -04004218
Steven Valdezfdd10992016-09-15 16:27:05 -04004219 // Test the version extension at all versions.
4220 for _, vers := range tlsVersions {
4221 protocols := []protocol{tls}
4222 if vers.hasDTLS {
4223 protocols = append(protocols, dtls)
4224 }
4225 for _, protocol := range protocols {
4226 suffix := vers.name
4227 if protocol == dtls {
4228 suffix += "-DTLS"
4229 }
4230
4231 wireVersion := versionToWire(vers.version, protocol == dtls)
4232 testCases = append(testCases, testCase{
4233 protocol: protocol,
4234 testType: serverTest,
4235 name: "VersionNegotiationExtension-" + suffix,
4236 config: Config{
4237 Bugs: ProtocolBugs{
4238 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4239 },
4240 },
4241 expectedVersion: vers.version,
4242 })
4243 }
4244
4245 }
4246
4247 // If all versions are unknown, negotiation fails.
4248 testCases = append(testCases, testCase{
4249 testType: serverTest,
4250 name: "NoSupportedVersions",
4251 config: Config{
4252 Bugs: ProtocolBugs{
4253 SendSupportedVersions: []uint16{0x1111},
4254 },
4255 },
4256 shouldFail: true,
4257 expectedError: ":UNSUPPORTED_PROTOCOL:",
4258 })
4259 testCases = append(testCases, testCase{
4260 protocol: dtls,
4261 testType: serverTest,
4262 name: "NoSupportedVersions-DTLS",
4263 config: Config{
4264 Bugs: ProtocolBugs{
4265 SendSupportedVersions: []uint16{0x1111},
4266 },
4267 },
4268 shouldFail: true,
4269 expectedError: ":UNSUPPORTED_PROTOCOL:",
4270 })
4271
4272 testCases = append(testCases, testCase{
4273 testType: serverTest,
4274 name: "ClientHelloVersionTooHigh",
4275 config: Config{
4276 MaxVersion: VersionTLS13,
4277 Bugs: ProtocolBugs{
4278 SendClientVersion: 0x0304,
4279 OmitSupportedVersions: true,
4280 },
4281 },
4282 expectedVersion: VersionTLS12,
4283 })
4284
4285 testCases = append(testCases, testCase{
4286 testType: serverTest,
4287 name: "ConflictingVersionNegotiation",
4288 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004289 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004290 SendClientVersion: VersionTLS12,
4291 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004292 },
4293 },
David Benjaminad75a662016-09-30 15:42:59 -04004294 // The extension takes precedence over the ClientHello version.
4295 expectedVersion: VersionTLS11,
4296 })
4297
4298 testCases = append(testCases, testCase{
4299 testType: serverTest,
4300 name: "ConflictingVersionNegotiation-2",
4301 config: Config{
4302 Bugs: ProtocolBugs{
4303 SendClientVersion: VersionTLS11,
4304 SendSupportedVersions: []uint16{VersionTLS12},
4305 },
4306 },
4307 // The extension takes precedence over the ClientHello version.
4308 expectedVersion: VersionTLS12,
4309 })
4310
4311 testCases = append(testCases, testCase{
4312 testType: serverTest,
4313 name: "RejectFinalTLS13",
4314 config: Config{
4315 Bugs: ProtocolBugs{
4316 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4317 },
4318 },
4319 // We currently implement a draft TLS 1.3 version. Ensure that
4320 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004321 expectedVersion: VersionTLS12,
4322 })
4323
David Benjamin95c69562016-06-29 18:15:03 -04004324 // Test for version tolerance.
4325 testCases = append(testCases, testCase{
4326 testType: serverTest,
4327 name: "MinorVersionTolerance",
4328 config: Config{
4329 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004330 SendClientVersion: 0x03ff,
4331 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004332 },
4333 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004334 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004335 })
4336 testCases = append(testCases, testCase{
4337 testType: serverTest,
4338 name: "MajorVersionTolerance",
4339 config: Config{
4340 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004341 SendClientVersion: 0x0400,
4342 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004343 },
4344 },
David Benjaminad75a662016-09-30 15:42:59 -04004345 // TLS 1.3 must be negotiated with the supported_versions
4346 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004347 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004348 })
David Benjaminad75a662016-09-30 15:42:59 -04004349 testCases = append(testCases, testCase{
4350 testType: serverTest,
4351 name: "VersionTolerance-TLS13",
4352 config: Config{
4353 Bugs: ProtocolBugs{
4354 // Although TLS 1.3 does not use
4355 // ClientHello.version, it still tolerates high
4356 // values there.
4357 SendClientVersion: 0x0400,
4358 },
4359 },
4360 expectedVersion: VersionTLS13,
4361 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004362
David Benjamin95c69562016-06-29 18:15:03 -04004363 testCases = append(testCases, testCase{
4364 protocol: dtls,
4365 testType: serverTest,
4366 name: "MinorVersionTolerance-DTLS",
4367 config: Config{
4368 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004369 SendClientVersion: 0xfe00,
4370 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004371 },
4372 },
4373 expectedVersion: VersionTLS12,
4374 })
4375 testCases = append(testCases, testCase{
4376 protocol: dtls,
4377 testType: serverTest,
4378 name: "MajorVersionTolerance-DTLS",
4379 config: Config{
4380 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004381 SendClientVersion: 0xfdff,
4382 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004383 },
4384 },
4385 expectedVersion: VersionTLS12,
4386 })
4387
4388 // Test that versions below 3.0 are rejected.
4389 testCases = append(testCases, testCase{
4390 testType: serverTest,
4391 name: "VersionTooLow",
4392 config: Config{
4393 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004394 SendClientVersion: 0x0200,
4395 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004396 },
4397 },
4398 shouldFail: true,
4399 expectedError: ":UNSUPPORTED_PROTOCOL:",
4400 })
4401 testCases = append(testCases, testCase{
4402 protocol: dtls,
4403 testType: serverTest,
4404 name: "VersionTooLow-DTLS",
4405 config: Config{
4406 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004407 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004408 },
4409 },
4410 shouldFail: true,
4411 expectedError: ":UNSUPPORTED_PROTOCOL:",
4412 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004413
David Benjamin2dc02042016-09-19 19:57:37 -04004414 testCases = append(testCases, testCase{
4415 name: "ServerBogusVersion",
4416 config: Config{
4417 Bugs: ProtocolBugs{
4418 SendServerHelloVersion: 0x1234,
4419 },
4420 },
4421 shouldFail: true,
4422 expectedError: ":UNSUPPORTED_PROTOCOL:",
4423 })
4424
David Benjamin1f61f0d2016-07-10 12:20:35 -04004425 // Test TLS 1.3's downgrade signal.
4426 testCases = append(testCases, testCase{
4427 name: "Downgrade-TLS12-Client",
4428 config: Config{
4429 Bugs: ProtocolBugs{
4430 NegotiateVersion: VersionTLS12,
4431 },
4432 },
David Benjamin592b5322016-09-30 15:15:01 -04004433 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004434 // TODO(davidben): This test should fail once TLS 1.3 is final
4435 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004436 })
4437 testCases = append(testCases, testCase{
4438 testType: serverTest,
4439 name: "Downgrade-TLS12-Server",
4440 config: Config{
4441 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004442 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004443 },
4444 },
David Benjamin592b5322016-09-30 15:15:01 -04004445 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004446 // TODO(davidben): This test should fail once TLS 1.3 is final
4447 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004448 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004449}
4450
David Benjaminaccb4542014-12-12 23:44:33 -05004451func addMinimumVersionTests() {
4452 for i, shimVers := range tlsVersions {
4453 // Assemble flags to disable all older versions on the shim.
4454 var flags []string
4455 for _, vers := range tlsVersions[:i] {
4456 flags = append(flags, vers.flag)
4457 }
4458
4459 for _, runnerVers := range tlsVersions {
4460 protocols := []protocol{tls}
4461 if runnerVers.hasDTLS && shimVers.hasDTLS {
4462 protocols = append(protocols, dtls)
4463 }
4464 for _, protocol := range protocols {
4465 suffix := shimVers.name + "-" + runnerVers.name
4466 if protocol == dtls {
4467 suffix += "-DTLS"
4468 }
4469 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4470
David Benjaminaccb4542014-12-12 23:44:33 -05004471 var expectedVersion uint16
4472 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004473 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004474 if runnerVers.version >= shimVers.version {
4475 expectedVersion = runnerVers.version
4476 } else {
4477 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004478 expectedError = ":UNSUPPORTED_PROTOCOL:"
4479 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004480 }
4481
4482 testCases = append(testCases, testCase{
4483 protocol: protocol,
4484 testType: clientTest,
4485 name: "MinimumVersion-Client-" + suffix,
4486 config: Config{
4487 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004488 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004489 // Ensure the server does not decline to
4490 // select a version (versions extension) or
4491 // cipher (some ciphers depend on versions).
4492 NegotiateVersion: runnerVers.version,
4493 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004494 },
David Benjaminaccb4542014-12-12 23:44:33 -05004495 },
David Benjamin87909c02014-12-13 01:55:01 -05004496 flags: flags,
4497 expectedVersion: expectedVersion,
4498 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004499 expectedError: expectedError,
4500 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004501 })
4502 testCases = append(testCases, testCase{
4503 protocol: protocol,
4504 testType: clientTest,
4505 name: "MinimumVersion-Client2-" + suffix,
4506 config: Config{
4507 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004508 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004509 // Ensure the server does not decline to
4510 // select a version (versions extension) or
4511 // cipher (some ciphers depend on versions).
4512 NegotiateVersion: runnerVers.version,
4513 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004514 },
David Benjaminaccb4542014-12-12 23:44:33 -05004515 },
David Benjamin87909c02014-12-13 01:55:01 -05004516 flags: []string{"-min-version", shimVersFlag},
4517 expectedVersion: expectedVersion,
4518 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004519 expectedError: expectedError,
4520 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004521 })
4522
4523 testCases = append(testCases, testCase{
4524 protocol: protocol,
4525 testType: serverTest,
4526 name: "MinimumVersion-Server-" + suffix,
4527 config: Config{
4528 MaxVersion: runnerVers.version,
4529 },
David Benjamin87909c02014-12-13 01:55:01 -05004530 flags: flags,
4531 expectedVersion: expectedVersion,
4532 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004533 expectedError: expectedError,
4534 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004535 })
4536 testCases = append(testCases, testCase{
4537 protocol: protocol,
4538 testType: serverTest,
4539 name: "MinimumVersion-Server2-" + suffix,
4540 config: Config{
4541 MaxVersion: runnerVers.version,
4542 },
David Benjamin87909c02014-12-13 01:55:01 -05004543 flags: []string{"-min-version", shimVersFlag},
4544 expectedVersion: expectedVersion,
4545 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004546 expectedError: expectedError,
4547 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004548 })
4549 }
4550 }
4551 }
4552}
4553
David Benjamine78bfde2014-09-06 12:45:15 -04004554func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004555 // TODO(davidben): Extensions, where applicable, all move their server
4556 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4557 // tests for both. Also test interaction with 0-RTT when implemented.
4558
David Benjamin97d17d92016-07-14 16:12:00 -04004559 // Repeat extensions tests all versions except SSL 3.0.
4560 for _, ver := range tlsVersions {
4561 if ver.version == VersionSSL30 {
4562 continue
4563 }
4564
David Benjamin97d17d92016-07-14 16:12:00 -04004565 // Test that duplicate extensions are rejected.
4566 testCases = append(testCases, testCase{
4567 testType: clientTest,
4568 name: "DuplicateExtensionClient-" + ver.name,
4569 config: Config{
4570 MaxVersion: ver.version,
4571 Bugs: ProtocolBugs{
4572 DuplicateExtension: true,
4573 },
David Benjamine78bfde2014-09-06 12:45:15 -04004574 },
David Benjamin97d17d92016-07-14 16:12:00 -04004575 shouldFail: true,
4576 expectedLocalError: "remote error: error decoding message",
4577 })
4578 testCases = append(testCases, testCase{
4579 testType: serverTest,
4580 name: "DuplicateExtensionServer-" + ver.name,
4581 config: Config{
4582 MaxVersion: ver.version,
4583 Bugs: ProtocolBugs{
4584 DuplicateExtension: true,
4585 },
David Benjamine78bfde2014-09-06 12:45:15 -04004586 },
David Benjamin97d17d92016-07-14 16:12:00 -04004587 shouldFail: true,
4588 expectedLocalError: "remote error: error decoding message",
4589 })
4590
4591 // Test SNI.
4592 testCases = append(testCases, testCase{
4593 testType: clientTest,
4594 name: "ServerNameExtensionClient-" + ver.name,
4595 config: Config{
4596 MaxVersion: ver.version,
4597 Bugs: ProtocolBugs{
4598 ExpectServerName: "example.com",
4599 },
David Benjamine78bfde2014-09-06 12:45:15 -04004600 },
David Benjamin97d17d92016-07-14 16:12:00 -04004601 flags: []string{"-host-name", "example.com"},
4602 })
4603 testCases = append(testCases, testCase{
4604 testType: clientTest,
4605 name: "ServerNameExtensionClientMismatch-" + ver.name,
4606 config: Config{
4607 MaxVersion: ver.version,
4608 Bugs: ProtocolBugs{
4609 ExpectServerName: "mismatch.com",
4610 },
David Benjamine78bfde2014-09-06 12:45:15 -04004611 },
David Benjamin97d17d92016-07-14 16:12:00 -04004612 flags: []string{"-host-name", "example.com"},
4613 shouldFail: true,
4614 expectedLocalError: "tls: unexpected server name",
4615 })
4616 testCases = append(testCases, testCase{
4617 testType: clientTest,
4618 name: "ServerNameExtensionClientMissing-" + ver.name,
4619 config: Config{
4620 MaxVersion: ver.version,
4621 Bugs: ProtocolBugs{
4622 ExpectServerName: "missing.com",
4623 },
David Benjamine78bfde2014-09-06 12:45:15 -04004624 },
David Benjamin97d17d92016-07-14 16:12:00 -04004625 shouldFail: true,
4626 expectedLocalError: "tls: unexpected server name",
4627 })
4628 testCases = append(testCases, testCase{
4629 testType: serverTest,
4630 name: "ServerNameExtensionServer-" + ver.name,
4631 config: Config{
4632 MaxVersion: ver.version,
4633 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004634 },
David Benjamin97d17d92016-07-14 16:12:00 -04004635 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004636 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004637 })
4638
4639 // Test ALPN.
4640 testCases = append(testCases, testCase{
4641 testType: clientTest,
4642 name: "ALPNClient-" + ver.name,
4643 config: Config{
4644 MaxVersion: ver.version,
4645 NextProtos: []string{"foo"},
4646 },
4647 flags: []string{
4648 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4649 "-expect-alpn", "foo",
4650 },
4651 expectedNextProto: "foo",
4652 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004653 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004654 })
4655 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004656 testType: clientTest,
4657 name: "ALPNClient-Mismatch-" + ver.name,
4658 config: Config{
4659 MaxVersion: ver.version,
4660 Bugs: ProtocolBugs{
4661 SendALPN: "baz",
4662 },
4663 },
4664 flags: []string{
4665 "-advertise-alpn", "\x03foo\x03bar",
4666 },
4667 shouldFail: true,
4668 expectedError: ":INVALID_ALPN_PROTOCOL:",
4669 expectedLocalError: "remote error: illegal parameter",
4670 })
4671 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004672 testType: serverTest,
4673 name: "ALPNServer-" + ver.name,
4674 config: Config{
4675 MaxVersion: ver.version,
4676 NextProtos: []string{"foo", "bar", "baz"},
4677 },
4678 flags: []string{
4679 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4680 "-select-alpn", "foo",
4681 },
4682 expectedNextProto: "foo",
4683 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004684 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004685 })
4686 testCases = append(testCases, testCase{
4687 testType: serverTest,
4688 name: "ALPNServer-Decline-" + ver.name,
4689 config: Config{
4690 MaxVersion: ver.version,
4691 NextProtos: []string{"foo", "bar", "baz"},
4692 },
4693 flags: []string{"-decline-alpn"},
4694 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004695 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004696 })
4697
David Benjamin25fe85b2016-08-09 20:00:32 -04004698 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4699 // called once.
4700 testCases = append(testCases, testCase{
4701 testType: serverTest,
4702 name: "ALPNServer-Async-" + ver.name,
4703 config: Config{
4704 MaxVersion: ver.version,
4705 NextProtos: []string{"foo", "bar", "baz"},
4706 },
4707 flags: []string{
4708 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4709 "-select-alpn", "foo",
4710 "-async",
4711 },
4712 expectedNextProto: "foo",
4713 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004714 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004715 })
4716
David Benjamin97d17d92016-07-14 16:12:00 -04004717 var emptyString string
4718 testCases = append(testCases, testCase{
4719 testType: clientTest,
4720 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4721 config: Config{
4722 MaxVersion: ver.version,
4723 NextProtos: []string{""},
4724 Bugs: ProtocolBugs{
4725 // A server returning an empty ALPN protocol
4726 // should be rejected.
4727 ALPNProtocol: &emptyString,
4728 },
4729 },
4730 flags: []string{
4731 "-advertise-alpn", "\x03foo",
4732 },
4733 shouldFail: true,
4734 expectedError: ":PARSE_TLSEXT:",
4735 })
4736 testCases = append(testCases, testCase{
4737 testType: serverTest,
4738 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4739 config: Config{
4740 MaxVersion: ver.version,
4741 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004742 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004743 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004744 },
David Benjamin97d17d92016-07-14 16:12:00 -04004745 flags: []string{
4746 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004747 },
David Benjamin97d17d92016-07-14 16:12:00 -04004748 shouldFail: true,
4749 expectedError: ":PARSE_TLSEXT:",
4750 })
4751
4752 // Test NPN and the interaction with ALPN.
4753 if ver.version < VersionTLS13 {
4754 // Test that the server prefers ALPN over NPN.
4755 testCases = append(testCases, testCase{
4756 testType: serverTest,
4757 name: "ALPNServer-Preferred-" + ver.name,
4758 config: Config{
4759 MaxVersion: ver.version,
4760 NextProtos: []string{"foo", "bar", "baz"},
4761 },
4762 flags: []string{
4763 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4764 "-select-alpn", "foo",
4765 "-advertise-npn", "\x03foo\x03bar\x03baz",
4766 },
4767 expectedNextProto: "foo",
4768 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004769 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004770 })
4771 testCases = append(testCases, testCase{
4772 testType: serverTest,
4773 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4774 config: Config{
4775 MaxVersion: ver.version,
4776 NextProtos: []string{"foo", "bar", "baz"},
4777 Bugs: ProtocolBugs{
4778 SwapNPNAndALPN: true,
4779 },
4780 },
4781 flags: []string{
4782 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4783 "-select-alpn", "foo",
4784 "-advertise-npn", "\x03foo\x03bar\x03baz",
4785 },
4786 expectedNextProto: "foo",
4787 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004788 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004789 })
4790
4791 // Test that negotiating both NPN and ALPN is forbidden.
4792 testCases = append(testCases, testCase{
4793 name: "NegotiateALPNAndNPN-" + ver.name,
4794 config: Config{
4795 MaxVersion: ver.version,
4796 NextProtos: []string{"foo", "bar", "baz"},
4797 Bugs: ProtocolBugs{
4798 NegotiateALPNAndNPN: true,
4799 },
4800 },
4801 flags: []string{
4802 "-advertise-alpn", "\x03foo",
4803 "-select-next-proto", "foo",
4804 },
4805 shouldFail: true,
4806 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4807 })
4808 testCases = append(testCases, testCase{
4809 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4810 config: Config{
4811 MaxVersion: ver.version,
4812 NextProtos: []string{"foo", "bar", "baz"},
4813 Bugs: ProtocolBugs{
4814 NegotiateALPNAndNPN: true,
4815 SwapNPNAndALPN: true,
4816 },
4817 },
4818 flags: []string{
4819 "-advertise-alpn", "\x03foo",
4820 "-select-next-proto", "foo",
4821 },
4822 shouldFail: true,
4823 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4824 })
4825
4826 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4827 testCases = append(testCases, testCase{
4828 name: "DisableNPN-" + ver.name,
4829 config: Config{
4830 MaxVersion: ver.version,
4831 NextProtos: []string{"foo"},
4832 },
4833 flags: []string{
4834 "-select-next-proto", "foo",
4835 "-disable-npn",
4836 },
4837 expectNoNextProto: true,
4838 })
4839 }
4840
4841 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004842
4843 // Resume with a corrupt ticket.
4844 testCases = append(testCases, testCase{
4845 testType: serverTest,
4846 name: "CorruptTicket-" + ver.name,
4847 config: Config{
4848 MaxVersion: ver.version,
4849 Bugs: ProtocolBugs{
4850 CorruptTicket: true,
4851 },
4852 },
4853 resumeSession: true,
4854 expectResumeRejected: true,
4855 })
4856 // Test the ticket callback, with and without renewal.
4857 testCases = append(testCases, testCase{
4858 testType: serverTest,
4859 name: "TicketCallback-" + ver.name,
4860 config: Config{
4861 MaxVersion: ver.version,
4862 },
4863 resumeSession: true,
4864 flags: []string{"-use-ticket-callback"},
4865 })
4866 testCases = append(testCases, testCase{
4867 testType: serverTest,
4868 name: "TicketCallback-Renew-" + ver.name,
4869 config: Config{
4870 MaxVersion: ver.version,
4871 Bugs: ProtocolBugs{
4872 ExpectNewTicket: true,
4873 },
4874 },
4875 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4876 resumeSession: true,
4877 })
4878
4879 // Test that the ticket callback is only called once when everything before
4880 // it in the ClientHello is asynchronous. This corrupts the ticket so
4881 // certificate selection callbacks run.
4882 testCases = append(testCases, testCase{
4883 testType: serverTest,
4884 name: "TicketCallback-SingleCall-" + ver.name,
4885 config: Config{
4886 MaxVersion: ver.version,
4887 Bugs: ProtocolBugs{
4888 CorruptTicket: true,
4889 },
4890 },
4891 resumeSession: true,
4892 expectResumeRejected: true,
4893 flags: []string{
4894 "-use-ticket-callback",
4895 "-async",
4896 },
4897 })
4898
4899 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004900 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004901 testCases = append(testCases, testCase{
4902 testType: serverTest,
4903 name: "OversizedSessionId-" + ver.name,
4904 config: Config{
4905 MaxVersion: ver.version,
4906 Bugs: ProtocolBugs{
4907 OversizedSessionId: true,
4908 },
4909 },
4910 resumeSession: true,
4911 shouldFail: true,
4912 expectedError: ":DECODE_ERROR:",
4913 })
4914 }
4915
4916 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4917 // are ignored.
4918 if ver.hasDTLS {
4919 testCases = append(testCases, testCase{
4920 protocol: dtls,
4921 name: "SRTP-Client-" + ver.name,
4922 config: Config{
4923 MaxVersion: ver.version,
4924 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4925 },
4926 flags: []string{
4927 "-srtp-profiles",
4928 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4929 },
4930 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4931 })
4932 testCases = append(testCases, testCase{
4933 protocol: dtls,
4934 testType: serverTest,
4935 name: "SRTP-Server-" + ver.name,
4936 config: Config{
4937 MaxVersion: ver.version,
4938 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4939 },
4940 flags: []string{
4941 "-srtp-profiles",
4942 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4943 },
4944 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4945 })
4946 // Test that the MKI is ignored.
4947 testCases = append(testCases, testCase{
4948 protocol: dtls,
4949 testType: serverTest,
4950 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4951 config: Config{
4952 MaxVersion: ver.version,
4953 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4954 Bugs: ProtocolBugs{
4955 SRTPMasterKeyIdentifer: "bogus",
4956 },
4957 },
4958 flags: []string{
4959 "-srtp-profiles",
4960 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4961 },
4962 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4963 })
4964 // Test that SRTP isn't negotiated on the server if there were
4965 // no matching profiles.
4966 testCases = append(testCases, testCase{
4967 protocol: dtls,
4968 testType: serverTest,
4969 name: "SRTP-Server-NoMatch-" + ver.name,
4970 config: Config{
4971 MaxVersion: ver.version,
4972 SRTPProtectionProfiles: []uint16{100, 101, 102},
4973 },
4974 flags: []string{
4975 "-srtp-profiles",
4976 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4977 },
4978 expectedSRTPProtectionProfile: 0,
4979 })
4980 // Test that the server returning an invalid SRTP profile is
4981 // flagged as an error by the client.
4982 testCases = append(testCases, testCase{
4983 protocol: dtls,
4984 name: "SRTP-Client-NoMatch-" + ver.name,
4985 config: Config{
4986 MaxVersion: ver.version,
4987 Bugs: ProtocolBugs{
4988 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4989 },
4990 },
4991 flags: []string{
4992 "-srtp-profiles",
4993 "SRTP_AES128_CM_SHA1_80",
4994 },
4995 shouldFail: true,
4996 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4997 })
4998 }
4999
5000 // Test SCT list.
5001 testCases = append(testCases, testCase{
5002 name: "SignedCertificateTimestampList-Client-" + ver.name,
5003 testType: clientTest,
5004 config: Config{
5005 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005006 },
David Benjamin97d17d92016-07-14 16:12:00 -04005007 flags: []string{
5008 "-enable-signed-cert-timestamps",
5009 "-expect-signed-cert-timestamps",
5010 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005011 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005012 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005013 })
David Benjamindaa88502016-10-04 16:32:16 -04005014
5015 // The SCT extension did not specify that it must only be sent on resumption as it
5016 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005017 testCases = append(testCases, testCase{
5018 name: "SendSCTListOnResume-" + ver.name,
5019 config: Config{
5020 MaxVersion: ver.version,
5021 Bugs: ProtocolBugs{
5022 SendSCTListOnResume: []byte("bogus"),
5023 },
David Benjamind98452d2015-06-16 14:16:23 -04005024 },
David Benjamin97d17d92016-07-14 16:12:00 -04005025 flags: []string{
5026 "-enable-signed-cert-timestamps",
5027 "-expect-signed-cert-timestamps",
5028 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005029 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005030 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005031 })
David Benjamindaa88502016-10-04 16:32:16 -04005032
David Benjamin97d17d92016-07-14 16:12:00 -04005033 testCases = append(testCases, testCase{
5034 name: "SignedCertificateTimestampList-Server-" + ver.name,
5035 testType: serverTest,
5036 config: Config{
5037 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005038 },
David Benjamin97d17d92016-07-14 16:12:00 -04005039 flags: []string{
5040 "-signed-cert-timestamps",
5041 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005042 },
David Benjamin97d17d92016-07-14 16:12:00 -04005043 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005044 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005045 })
5046 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005047
Paul Lietar4fac72e2015-09-09 13:44:55 +01005048 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005049 testType: clientTest,
5050 name: "ClientHelloPadding",
5051 config: Config{
5052 Bugs: ProtocolBugs{
5053 RequireClientHelloSize: 512,
5054 },
5055 },
5056 // This hostname just needs to be long enough to push the
5057 // ClientHello into F5's danger zone between 256 and 511 bytes
5058 // long.
5059 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5060 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005061
5062 // Extensions should not function in SSL 3.0.
5063 testCases = append(testCases, testCase{
5064 testType: serverTest,
5065 name: "SSLv3Extensions-NoALPN",
5066 config: Config{
5067 MaxVersion: VersionSSL30,
5068 NextProtos: []string{"foo", "bar", "baz"},
5069 },
5070 flags: []string{
5071 "-select-alpn", "foo",
5072 },
5073 expectNoNextProto: true,
5074 })
5075
5076 // Test session tickets separately as they follow a different codepath.
5077 testCases = append(testCases, testCase{
5078 testType: serverTest,
5079 name: "SSLv3Extensions-NoTickets",
5080 config: Config{
5081 MaxVersion: VersionSSL30,
5082 Bugs: ProtocolBugs{
5083 // Historically, session tickets in SSL 3.0
5084 // failed in different ways depending on whether
5085 // the client supported renegotiation_info.
5086 NoRenegotiationInfo: true,
5087 },
5088 },
5089 resumeSession: true,
5090 })
5091 testCases = append(testCases, testCase{
5092 testType: serverTest,
5093 name: "SSLv3Extensions-NoTickets2",
5094 config: Config{
5095 MaxVersion: VersionSSL30,
5096 },
5097 resumeSession: true,
5098 })
5099
5100 // But SSL 3.0 does send and process renegotiation_info.
5101 testCases = append(testCases, testCase{
5102 testType: serverTest,
5103 name: "SSLv3Extensions-RenegotiationInfo",
5104 config: Config{
5105 MaxVersion: VersionSSL30,
5106 Bugs: ProtocolBugs{
5107 RequireRenegotiationInfo: true,
5108 },
5109 },
5110 })
5111 testCases = append(testCases, testCase{
5112 testType: serverTest,
5113 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5114 config: Config{
5115 MaxVersion: VersionSSL30,
5116 Bugs: ProtocolBugs{
5117 NoRenegotiationInfo: true,
5118 SendRenegotiationSCSV: true,
5119 RequireRenegotiationInfo: true,
5120 },
5121 },
5122 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005123
5124 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5125 // in ServerHello.
5126 testCases = append(testCases, testCase{
5127 name: "NPN-Forbidden-TLS13",
5128 config: Config{
5129 MaxVersion: VersionTLS13,
5130 NextProtos: []string{"foo"},
5131 Bugs: ProtocolBugs{
5132 NegotiateNPNAtAllVersions: true,
5133 },
5134 },
5135 flags: []string{"-select-next-proto", "foo"},
5136 shouldFail: true,
5137 expectedError: ":ERROR_PARSING_EXTENSION:",
5138 })
5139 testCases = append(testCases, testCase{
5140 name: "EMS-Forbidden-TLS13",
5141 config: Config{
5142 MaxVersion: VersionTLS13,
5143 Bugs: ProtocolBugs{
5144 NegotiateEMSAtAllVersions: true,
5145 },
5146 },
5147 shouldFail: true,
5148 expectedError: ":ERROR_PARSING_EXTENSION:",
5149 })
5150 testCases = append(testCases, testCase{
5151 name: "RenegotiationInfo-Forbidden-TLS13",
5152 config: Config{
5153 MaxVersion: VersionTLS13,
5154 Bugs: ProtocolBugs{
5155 NegotiateRenegotiationInfoAtAllVersions: true,
5156 },
5157 },
5158 shouldFail: true,
5159 expectedError: ":ERROR_PARSING_EXTENSION:",
5160 })
5161 testCases = append(testCases, testCase{
5162 name: "ChannelID-Forbidden-TLS13",
5163 config: Config{
5164 MaxVersion: VersionTLS13,
5165 RequestChannelID: true,
5166 Bugs: ProtocolBugs{
5167 NegotiateChannelIDAtAllVersions: true,
5168 },
5169 },
5170 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
5171 shouldFail: true,
5172 expectedError: ":ERROR_PARSING_EXTENSION:",
5173 })
5174 testCases = append(testCases, testCase{
5175 name: "Ticket-Forbidden-TLS13",
5176 config: Config{
5177 MaxVersion: VersionTLS12,
5178 },
5179 resumeConfig: &Config{
5180 MaxVersion: VersionTLS13,
5181 Bugs: ProtocolBugs{
5182 AdvertiseTicketExtension: true,
5183 },
5184 },
5185 resumeSession: true,
5186 shouldFail: true,
5187 expectedError: ":ERROR_PARSING_EXTENSION:",
5188 })
5189
5190 // Test that illegal extensions in TLS 1.3 are declined by the server if
5191 // offered in ClientHello. The runner's server will fail if this occurs,
5192 // so we exercise the offering path. (EMS and Renegotiation Info are
5193 // implicit in every test.)
5194 testCases = append(testCases, testCase{
5195 testType: serverTest,
5196 name: "ChannelID-Declined-TLS13",
5197 config: Config{
5198 MaxVersion: VersionTLS13,
5199 ChannelID: channelIDKey,
5200 },
5201 flags: []string{"-enable-channel-id"},
5202 })
5203 testCases = append(testCases, testCase{
5204 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005205 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005206 config: Config{
5207 MaxVersion: VersionTLS13,
5208 NextProtos: []string{"bar"},
5209 },
5210 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5211 })
David Benjamin196df5b2016-09-21 16:23:27 -04005212
5213 testCases = append(testCases, testCase{
5214 testType: serverTest,
5215 name: "InvalidChannelIDSignature",
5216 config: Config{
5217 MaxVersion: VersionTLS12,
5218 ChannelID: channelIDKey,
5219 Bugs: ProtocolBugs{
5220 InvalidChannelIDSignature: true,
5221 },
5222 },
5223 flags: []string{"-enable-channel-id"},
5224 shouldFail: true,
5225 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5226 expectedLocalError: "remote error: error decrypting message",
5227 })
David Benjamindaa88502016-10-04 16:32:16 -04005228
5229 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5230 // tolerated.
5231 testCases = append(testCases, testCase{
5232 name: "SendOCSPResponseOnResume-TLS12",
5233 config: Config{
5234 MaxVersion: VersionTLS12,
5235 Bugs: ProtocolBugs{
5236 SendOCSPResponseOnResume: []byte("bogus"),
5237 },
5238 },
5239 flags: []string{
5240 "-enable-ocsp-stapling",
5241 "-expect-ocsp-response",
5242 base64.StdEncoding.EncodeToString(testOCSPResponse),
5243 },
5244 resumeSession: true,
5245 })
5246
5247 // Beginning TLS 1.3, enforce this does not happen.
5248 testCases = append(testCases, testCase{
5249 name: "SendOCSPResponseOnResume-TLS13",
5250 config: Config{
5251 MaxVersion: VersionTLS13,
5252 Bugs: ProtocolBugs{
5253 SendOCSPResponseOnResume: []byte("bogus"),
5254 },
5255 },
5256 flags: []string{
5257 "-enable-ocsp-stapling",
5258 "-expect-ocsp-response",
5259 base64.StdEncoding.EncodeToString(testOCSPResponse),
5260 },
5261 resumeSession: true,
5262 shouldFail: true,
5263 expectedError: ":ERROR_PARSING_EXTENSION:",
5264 })
David Benjamine78bfde2014-09-06 12:45:15 -04005265}
5266
David Benjamin01fe8202014-09-24 15:21:44 -04005267func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005268 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005269 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005270 // SSL 3.0 does not have tickets and TLS 1.3 does not
5271 // have session IDs, so skip their cross-resumption
5272 // tests.
5273 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5274 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5275 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005276 }
5277
David Benjamin8b8c0062014-11-23 02:47:52 -05005278 protocols := []protocol{tls}
5279 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5280 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005281 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005282 for _, protocol := range protocols {
5283 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5284 if protocol == dtls {
5285 suffix += "-DTLS"
5286 }
5287
David Benjaminece3de92015-03-16 18:02:20 -04005288 if sessionVers.version == resumeVers.version {
5289 testCases = append(testCases, testCase{
5290 protocol: protocol,
5291 name: "Resume-Client" + suffix,
5292 resumeSession: true,
5293 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005294 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005295 Bugs: ProtocolBugs{
5296 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5297 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5298 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005299 },
David Benjaminece3de92015-03-16 18:02:20 -04005300 expectedVersion: sessionVers.version,
5301 expectedResumeVersion: resumeVers.version,
5302 })
5303 } else {
David Benjamin405da482016-08-08 17:25:07 -04005304 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5305
5306 // Offering a TLS 1.3 session sends an empty session ID, so
5307 // there is no way to convince a non-lookahead client the
5308 // session was resumed. It will appear to the client that a
5309 // stray ChangeCipherSpec was sent.
5310 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5311 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005312 }
5313
David Benjaminece3de92015-03-16 18:02:20 -04005314 testCases = append(testCases, testCase{
5315 protocol: protocol,
5316 name: "Resume-Client-Mismatch" + suffix,
5317 resumeSession: true,
5318 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005319 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005320 },
David Benjaminece3de92015-03-16 18:02:20 -04005321 expectedVersion: sessionVers.version,
5322 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005323 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005324 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005325 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005326 },
5327 },
5328 expectedResumeVersion: resumeVers.version,
5329 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005330 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005331 })
5332 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005333
5334 testCases = append(testCases, testCase{
5335 protocol: protocol,
5336 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005337 resumeSession: true,
5338 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005339 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005340 },
5341 expectedVersion: sessionVers.version,
5342 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005343 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005344 },
5345 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005346 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005347 expectedResumeVersion: resumeVers.version,
5348 })
5349
David Benjamin8b8c0062014-11-23 02:47:52 -05005350 testCases = append(testCases, testCase{
5351 protocol: protocol,
5352 testType: serverTest,
5353 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005354 resumeSession: true,
5355 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005356 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005357 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005358 expectedVersion: sessionVers.version,
5359 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005360 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005361 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005362 Bugs: ProtocolBugs{
5363 SendBothTickets: true,
5364 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005365 },
5366 expectedResumeVersion: resumeVers.version,
5367 })
5368 }
David Benjamin01fe8202014-09-24 15:21:44 -04005369 }
5370 }
David Benjaminece3de92015-03-16 18:02:20 -04005371
5372 testCases = append(testCases, testCase{
5373 name: "Resume-Client-CipherMismatch",
5374 resumeSession: true,
5375 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005376 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005377 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5378 },
5379 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005380 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005381 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5382 Bugs: ProtocolBugs{
5383 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5384 },
5385 },
5386 shouldFail: true,
5387 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5388 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005389
5390 testCases = append(testCases, testCase{
5391 name: "Resume-Client-CipherMismatch-TLS13",
5392 resumeSession: true,
5393 config: Config{
5394 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005395 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005396 },
5397 resumeConfig: &Config{
5398 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005399 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005400 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005401 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005402 },
5403 },
5404 shouldFail: true,
5405 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5406 })
David Benjamin01fe8202014-09-24 15:21:44 -04005407}
5408
Adam Langley2ae77d22014-10-28 17:29:33 -07005409func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005410 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005411 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005412 testType: serverTest,
5413 name: "Renegotiate-Server-Forbidden",
5414 config: Config{
5415 MaxVersion: VersionTLS12,
5416 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005417 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005418 shouldFail: true,
5419 expectedError: ":NO_RENEGOTIATION:",
5420 expectedLocalError: "remote error: no renegotiation",
5421 })
Adam Langley5021b222015-06-12 18:27:58 -07005422 // The server shouldn't echo the renegotiation extension unless
5423 // requested by the client.
5424 testCases = append(testCases, testCase{
5425 testType: serverTest,
5426 name: "Renegotiate-Server-NoExt",
5427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005428 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005429 Bugs: ProtocolBugs{
5430 NoRenegotiationInfo: true,
5431 RequireRenegotiationInfo: true,
5432 },
5433 },
5434 shouldFail: true,
5435 expectedLocalError: "renegotiation extension missing",
5436 })
5437 // The renegotiation SCSV should be sufficient for the server to echo
5438 // the extension.
5439 testCases = append(testCases, testCase{
5440 testType: serverTest,
5441 name: "Renegotiate-Server-NoExt-SCSV",
5442 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005443 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005444 Bugs: ProtocolBugs{
5445 NoRenegotiationInfo: true,
5446 SendRenegotiationSCSV: true,
5447 RequireRenegotiationInfo: true,
5448 },
5449 },
5450 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005451 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005452 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005453 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005454 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005455 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005456 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005457 },
5458 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005459 renegotiate: 1,
5460 flags: []string{
5461 "-renegotiate-freely",
5462 "-expect-total-renegotiations", "1",
5463 },
David Benjamincdea40c2015-03-19 14:09:43 -04005464 })
5465 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005466 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005467 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005468 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005469 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005470 Bugs: ProtocolBugs{
5471 EmptyRenegotiationInfo: true,
5472 },
5473 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005474 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005475 shouldFail: true,
5476 expectedError: ":RENEGOTIATION_MISMATCH:",
5477 })
5478 testCases = append(testCases, testCase{
5479 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005480 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005481 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005482 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005483 Bugs: ProtocolBugs{
5484 BadRenegotiationInfo: true,
5485 },
5486 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005487 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005488 shouldFail: true,
5489 expectedError: ":RENEGOTIATION_MISMATCH:",
5490 })
5491 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005492 name: "Renegotiate-Client-Downgrade",
5493 renegotiate: 1,
5494 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005495 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005496 Bugs: ProtocolBugs{
5497 NoRenegotiationInfoAfterInitial: true,
5498 },
5499 },
5500 flags: []string{"-renegotiate-freely"},
5501 shouldFail: true,
5502 expectedError: ":RENEGOTIATION_MISMATCH:",
5503 })
5504 testCases = append(testCases, testCase{
5505 name: "Renegotiate-Client-Upgrade",
5506 renegotiate: 1,
5507 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005508 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005509 Bugs: ProtocolBugs{
5510 NoRenegotiationInfoInInitial: true,
5511 },
5512 },
5513 flags: []string{"-renegotiate-freely"},
5514 shouldFail: true,
5515 expectedError: ":RENEGOTIATION_MISMATCH:",
5516 })
5517 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005518 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005519 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005520 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005521 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005522 Bugs: ProtocolBugs{
5523 NoRenegotiationInfo: true,
5524 },
5525 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005526 flags: []string{
5527 "-renegotiate-freely",
5528 "-expect-total-renegotiations", "1",
5529 },
David Benjamincff0b902015-05-15 23:09:47 -04005530 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005531
5532 // Test that the server may switch ciphers on renegotiation without
5533 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005534 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005535 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005536 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005537 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005538 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005539 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005540 },
5541 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005542 flags: []string{
5543 "-renegotiate-freely",
5544 "-expect-total-renegotiations", "1",
5545 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005546 })
5547 testCases = append(testCases, testCase{
5548 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005549 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005550 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005551 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005552 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5553 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005554 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005555 flags: []string{
5556 "-renegotiate-freely",
5557 "-expect-total-renegotiations", "1",
5558 },
David Benjaminb16346b2015-04-08 19:16:58 -04005559 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005560
5561 // Test that the server may not switch versions on renegotiation.
5562 testCases = append(testCases, testCase{
5563 name: "Renegotiate-Client-SwitchVersion",
5564 config: Config{
5565 MaxVersion: VersionTLS12,
5566 // Pick a cipher which exists at both versions.
5567 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5568 Bugs: ProtocolBugs{
5569 NegotiateVersionOnRenego: VersionTLS11,
5570 },
5571 },
5572 renegotiate: 1,
5573 flags: []string{
5574 "-renegotiate-freely",
5575 "-expect-total-renegotiations", "1",
5576 },
5577 shouldFail: true,
5578 expectedError: ":WRONG_SSL_VERSION:",
5579 })
5580
David Benjaminb16346b2015-04-08 19:16:58 -04005581 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005582 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005583 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005584 config: Config{
5585 MaxVersion: VersionTLS10,
5586 Bugs: ProtocolBugs{
5587 RequireSameRenegoClientVersion: true,
5588 },
5589 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005590 flags: []string{
5591 "-renegotiate-freely",
5592 "-expect-total-renegotiations", "1",
5593 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005594 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005595 testCases = append(testCases, testCase{
5596 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005597 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005598 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005599 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005600 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5601 NextProtos: []string{"foo"},
5602 },
5603 flags: []string{
5604 "-false-start",
5605 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005606 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005607 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005608 },
5609 shimWritesFirst: true,
5610 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005611
5612 // Client-side renegotiation controls.
5613 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005614 name: "Renegotiate-Client-Forbidden-1",
5615 config: Config{
5616 MaxVersion: VersionTLS12,
5617 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005618 renegotiate: 1,
5619 shouldFail: true,
5620 expectedError: ":NO_RENEGOTIATION:",
5621 expectedLocalError: "remote error: no renegotiation",
5622 })
5623 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005624 name: "Renegotiate-Client-Once-1",
5625 config: Config{
5626 MaxVersion: VersionTLS12,
5627 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005628 renegotiate: 1,
5629 flags: []string{
5630 "-renegotiate-once",
5631 "-expect-total-renegotiations", "1",
5632 },
5633 })
5634 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005635 name: "Renegotiate-Client-Freely-1",
5636 config: Config{
5637 MaxVersion: VersionTLS12,
5638 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005639 renegotiate: 1,
5640 flags: []string{
5641 "-renegotiate-freely",
5642 "-expect-total-renegotiations", "1",
5643 },
5644 })
5645 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005646 name: "Renegotiate-Client-Once-2",
5647 config: Config{
5648 MaxVersion: VersionTLS12,
5649 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005650 renegotiate: 2,
5651 flags: []string{"-renegotiate-once"},
5652 shouldFail: true,
5653 expectedError: ":NO_RENEGOTIATION:",
5654 expectedLocalError: "remote error: no renegotiation",
5655 })
5656 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005657 name: "Renegotiate-Client-Freely-2",
5658 config: Config{
5659 MaxVersion: VersionTLS12,
5660 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005661 renegotiate: 2,
5662 flags: []string{
5663 "-renegotiate-freely",
5664 "-expect-total-renegotiations", "2",
5665 },
5666 })
Adam Langley27a0d082015-11-03 13:34:10 -08005667 testCases = append(testCases, testCase{
5668 name: "Renegotiate-Client-NoIgnore",
5669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005670 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005671 Bugs: ProtocolBugs{
5672 SendHelloRequestBeforeEveryAppDataRecord: true,
5673 },
5674 },
5675 shouldFail: true,
5676 expectedError: ":NO_RENEGOTIATION:",
5677 })
5678 testCases = append(testCases, testCase{
5679 name: "Renegotiate-Client-Ignore",
5680 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005681 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005682 Bugs: ProtocolBugs{
5683 SendHelloRequestBeforeEveryAppDataRecord: true,
5684 },
5685 },
5686 flags: []string{
5687 "-renegotiate-ignore",
5688 "-expect-total-renegotiations", "0",
5689 },
5690 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005691
David Benjamin34941c02016-10-08 11:45:31 -04005692 // Renegotiation is not allowed at SSL 3.0.
5693 testCases = append(testCases, testCase{
5694 name: "Renegotiate-Client-SSL3",
5695 config: Config{
5696 MaxVersion: VersionSSL30,
5697 },
5698 renegotiate: 1,
5699 flags: []string{
5700 "-renegotiate-freely",
5701 "-expect-total-renegotiations", "1",
5702 },
5703 shouldFail: true,
5704 expectedError: ":NO_RENEGOTIATION:",
5705 expectedLocalError: "remote error: no renegotiation",
5706 })
5707
David Benjamin397c8e62016-07-08 14:14:36 -07005708 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005709 testCases = append(testCases, testCase{
5710 name: "StrayHelloRequest",
5711 config: Config{
5712 MaxVersion: VersionTLS12,
5713 Bugs: ProtocolBugs{
5714 SendHelloRequestBeforeEveryHandshakeMessage: true,
5715 },
5716 },
5717 })
5718 testCases = append(testCases, testCase{
5719 name: "StrayHelloRequest-Packed",
5720 config: Config{
5721 MaxVersion: VersionTLS12,
5722 Bugs: ProtocolBugs{
5723 PackHandshakeFlight: true,
5724 SendHelloRequestBeforeEveryHandshakeMessage: true,
5725 },
5726 },
5727 })
5728
David Benjamin12d2c482016-07-24 10:56:51 -04005729 // Test renegotiation works if HelloRequest and server Finished come in
5730 // the same record.
5731 testCases = append(testCases, testCase{
5732 name: "Renegotiate-Client-Packed",
5733 config: Config{
5734 MaxVersion: VersionTLS12,
5735 Bugs: ProtocolBugs{
5736 PackHandshakeFlight: true,
5737 PackHelloRequestWithFinished: true,
5738 },
5739 },
5740 renegotiate: 1,
5741 flags: []string{
5742 "-renegotiate-freely",
5743 "-expect-total-renegotiations", "1",
5744 },
5745 })
5746
David Benjamin397c8e62016-07-08 14:14:36 -07005747 // Renegotiation is forbidden in TLS 1.3.
5748 testCases = append(testCases, testCase{
5749 name: "Renegotiate-Client-TLS13",
5750 config: Config{
5751 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005752 Bugs: ProtocolBugs{
5753 SendHelloRequestBeforeEveryAppDataRecord: true,
5754 },
David Benjamin397c8e62016-07-08 14:14:36 -07005755 },
David Benjamin397c8e62016-07-08 14:14:36 -07005756 flags: []string{
5757 "-renegotiate-freely",
5758 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005759 shouldFail: true,
5760 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005761 })
5762
5763 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5764 testCases = append(testCases, testCase{
5765 name: "StrayHelloRequest-TLS13",
5766 config: Config{
5767 MaxVersion: VersionTLS13,
5768 Bugs: ProtocolBugs{
5769 SendHelloRequestBeforeEveryHandshakeMessage: true,
5770 },
5771 },
5772 shouldFail: true,
5773 expectedError: ":UNEXPECTED_MESSAGE:",
5774 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005775}
5776
David Benjamin5e961c12014-11-07 01:48:35 -05005777func addDTLSReplayTests() {
5778 // Test that sequence number replays are detected.
5779 testCases = append(testCases, testCase{
5780 protocol: dtls,
5781 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005782 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005783 replayWrites: true,
5784 })
5785
David Benjamin8e6db492015-07-25 18:29:23 -04005786 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005787 // than the retransmit window.
5788 testCases = append(testCases, testCase{
5789 protocol: dtls,
5790 name: "DTLS-Replay-LargeGaps",
5791 config: Config{
5792 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005793 SequenceNumberMapping: func(in uint64) uint64 {
5794 return in * 127
5795 },
David Benjamin5e961c12014-11-07 01:48:35 -05005796 },
5797 },
David Benjamin8e6db492015-07-25 18:29:23 -04005798 messageCount: 200,
5799 replayWrites: true,
5800 })
5801
5802 // Test the incoming sequence number changing non-monotonically.
5803 testCases = append(testCases, testCase{
5804 protocol: dtls,
5805 name: "DTLS-Replay-NonMonotonic",
5806 config: Config{
5807 Bugs: ProtocolBugs{
5808 SequenceNumberMapping: func(in uint64) uint64 {
5809 return in ^ 31
5810 },
5811 },
5812 },
5813 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005814 replayWrites: true,
5815 })
5816}
5817
Nick Harper60edffd2016-06-21 15:19:24 -07005818var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005819 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005820 id signatureAlgorithm
5821 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005822}{
Nick Harper60edffd2016-06-21 15:19:24 -07005823 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5824 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5825 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5826 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005827 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005828 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5829 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5830 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005831 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5832 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5833 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005834 // Tests for key types prior to TLS 1.2.
5835 {"RSA", 0, testCertRSA},
5836 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005837}
5838
Nick Harper60edffd2016-06-21 15:19:24 -07005839const fakeSigAlg1 signatureAlgorithm = 0x2a01
5840const fakeSigAlg2 signatureAlgorithm = 0xff01
5841
5842func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005843 // Not all ciphers involve a signature. Advertise a list which gives all
5844 // versions a signing cipher.
5845 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04005846 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04005847 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5848 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5849 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5850 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5851 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5852 }
5853
David Benjaminca3d5452016-07-14 12:51:01 -04005854 var allAlgorithms []signatureAlgorithm
5855 for _, alg := range testSignatureAlgorithms {
5856 if alg.id != 0 {
5857 allAlgorithms = append(allAlgorithms, alg.id)
5858 }
5859 }
5860
Nick Harper60edffd2016-06-21 15:19:24 -07005861 // Make sure each signature algorithm works. Include some fake values in
5862 // the list and ensure they're ignored.
5863 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005864 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005865 if (ver.version < VersionTLS12) != (alg.id == 0) {
5866 continue
5867 }
5868
5869 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5870 // or remove it in C.
5871 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005872 continue
5873 }
Nick Harper60edffd2016-06-21 15:19:24 -07005874
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005875 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005876 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005877 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5878 shouldFail = true
5879 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005880 // RSA-PKCS1 does not exist in TLS 1.3.
5881 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5882 shouldFail = true
5883 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005884
5885 var signError, verifyError string
5886 if shouldFail {
5887 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5888 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005889 }
David Benjamin000800a2014-11-14 01:43:59 -05005890
David Benjamin1fb125c2016-07-08 18:52:12 -07005891 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005892
David Benjamin7a41d372016-07-09 11:21:54 -07005893 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005894 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005895 config: Config{
5896 MaxVersion: ver.version,
5897 ClientAuth: RequireAnyClientCert,
5898 VerifySignatureAlgorithms: []signatureAlgorithm{
5899 fakeSigAlg1,
5900 alg.id,
5901 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005902 },
David Benjamin7a41d372016-07-09 11:21:54 -07005903 },
5904 flags: []string{
5905 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5906 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5907 "-enable-all-curves",
5908 },
5909 shouldFail: shouldFail,
5910 expectedError: signError,
5911 expectedPeerSignatureAlgorithm: alg.id,
5912 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005913
David Benjamin7a41d372016-07-09 11:21:54 -07005914 testCases = append(testCases, testCase{
5915 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005916 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005917 config: Config{
5918 MaxVersion: ver.version,
5919 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5920 SignSignatureAlgorithms: []signatureAlgorithm{
5921 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005922 },
David Benjamin7a41d372016-07-09 11:21:54 -07005923 Bugs: ProtocolBugs{
5924 SkipECDSACurveCheck: shouldFail,
5925 IgnoreSignatureVersionChecks: shouldFail,
5926 // The client won't advertise 1.3-only algorithms after
5927 // version negotiation.
5928 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005929 },
David Benjamin7a41d372016-07-09 11:21:54 -07005930 },
5931 flags: []string{
5932 "-require-any-client-certificate",
5933 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5934 "-enable-all-curves",
5935 },
5936 shouldFail: shouldFail,
5937 expectedError: verifyError,
5938 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005939
5940 testCases = append(testCases, testCase{
5941 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005942 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005943 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005944 MaxVersion: ver.version,
5945 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005946 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005947 fakeSigAlg1,
5948 alg.id,
5949 fakeSigAlg2,
5950 },
5951 },
5952 flags: []string{
5953 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5954 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5955 "-enable-all-curves",
5956 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005957 shouldFail: shouldFail,
5958 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005959 expectedPeerSignatureAlgorithm: alg.id,
5960 })
5961
5962 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005963 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005964 config: Config{
5965 MaxVersion: ver.version,
5966 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005967 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005968 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005969 alg.id,
5970 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005971 Bugs: ProtocolBugs{
5972 SkipECDSACurveCheck: shouldFail,
5973 IgnoreSignatureVersionChecks: shouldFail,
5974 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005975 },
5976 flags: []string{
5977 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5978 "-enable-all-curves",
5979 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005980 shouldFail: shouldFail,
5981 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005982 })
David Benjamin5208fd42016-07-13 21:43:25 -04005983
5984 if !shouldFail {
5985 testCases = append(testCases, testCase{
5986 testType: serverTest,
5987 name: "ClientAuth-InvalidSignature" + suffix,
5988 config: Config{
5989 MaxVersion: ver.version,
5990 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5991 SignSignatureAlgorithms: []signatureAlgorithm{
5992 alg.id,
5993 },
5994 Bugs: ProtocolBugs{
5995 InvalidSignature: true,
5996 },
5997 },
5998 flags: []string{
5999 "-require-any-client-certificate",
6000 "-enable-all-curves",
6001 },
6002 shouldFail: true,
6003 expectedError: ":BAD_SIGNATURE:",
6004 })
6005
6006 testCases = append(testCases, testCase{
6007 name: "ServerAuth-InvalidSignature" + suffix,
6008 config: Config{
6009 MaxVersion: ver.version,
6010 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6011 CipherSuites: signingCiphers,
6012 SignSignatureAlgorithms: []signatureAlgorithm{
6013 alg.id,
6014 },
6015 Bugs: ProtocolBugs{
6016 InvalidSignature: true,
6017 },
6018 },
6019 flags: []string{"-enable-all-curves"},
6020 shouldFail: true,
6021 expectedError: ":BAD_SIGNATURE:",
6022 })
6023 }
David Benjaminca3d5452016-07-14 12:51:01 -04006024
6025 if ver.version >= VersionTLS12 && !shouldFail {
6026 testCases = append(testCases, testCase{
6027 name: "ClientAuth-Sign-Negotiate" + suffix,
6028 config: Config{
6029 MaxVersion: ver.version,
6030 ClientAuth: RequireAnyClientCert,
6031 VerifySignatureAlgorithms: allAlgorithms,
6032 },
6033 flags: []string{
6034 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6035 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6036 "-enable-all-curves",
6037 "-signing-prefs", strconv.Itoa(int(alg.id)),
6038 },
6039 expectedPeerSignatureAlgorithm: alg.id,
6040 })
6041
6042 testCases = append(testCases, testCase{
6043 testType: serverTest,
6044 name: "ServerAuth-Sign-Negotiate" + suffix,
6045 config: Config{
6046 MaxVersion: ver.version,
6047 CipherSuites: signingCiphers,
6048 VerifySignatureAlgorithms: allAlgorithms,
6049 },
6050 flags: []string{
6051 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6052 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6053 "-enable-all-curves",
6054 "-signing-prefs", strconv.Itoa(int(alg.id)),
6055 },
6056 expectedPeerSignatureAlgorithm: alg.id,
6057 })
6058 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006059 }
David Benjamin000800a2014-11-14 01:43:59 -05006060 }
6061
Nick Harper60edffd2016-06-21 15:19:24 -07006062 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006063 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006064 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006065 config: Config{
6066 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006067 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006068 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006069 signatureECDSAWithP521AndSHA512,
6070 signatureRSAPKCS1WithSHA384,
6071 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006072 },
6073 },
6074 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006075 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6076 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006077 },
Nick Harper60edffd2016-06-21 15:19:24 -07006078 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006079 })
6080
6081 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006082 name: "ClientAuth-SignatureType-TLS13",
6083 config: Config{
6084 ClientAuth: RequireAnyClientCert,
6085 MaxVersion: VersionTLS13,
6086 VerifySignatureAlgorithms: []signatureAlgorithm{
6087 signatureECDSAWithP521AndSHA512,
6088 signatureRSAPKCS1WithSHA384,
6089 signatureRSAPSSWithSHA384,
6090 signatureECDSAWithSHA1,
6091 },
6092 },
6093 flags: []string{
6094 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6095 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6096 },
6097 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6098 })
6099
6100 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006101 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006102 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006104 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006105 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006106 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006107 signatureECDSAWithP521AndSHA512,
6108 signatureRSAPKCS1WithSHA384,
6109 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006110 },
6111 },
Nick Harper60edffd2016-06-21 15:19:24 -07006112 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006113 })
6114
Steven Valdez143e8b32016-07-11 13:19:03 -04006115 testCases = append(testCases, testCase{
6116 testType: serverTest,
6117 name: "ServerAuth-SignatureType-TLS13",
6118 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006119 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006120 VerifySignatureAlgorithms: []signatureAlgorithm{
6121 signatureECDSAWithP521AndSHA512,
6122 signatureRSAPKCS1WithSHA384,
6123 signatureRSAPSSWithSHA384,
6124 signatureECDSAWithSHA1,
6125 },
6126 },
6127 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6128 })
6129
David Benjamina95e9f32016-07-08 16:28:04 -07006130 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006131 testCases = append(testCases, testCase{
6132 testType: serverTest,
6133 name: "Verify-ClientAuth-SignatureType",
6134 config: Config{
6135 MaxVersion: VersionTLS12,
6136 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006137 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006138 signatureRSAPKCS1WithSHA256,
6139 },
6140 Bugs: ProtocolBugs{
6141 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6142 },
6143 },
6144 flags: []string{
6145 "-require-any-client-certificate",
6146 },
6147 shouldFail: true,
6148 expectedError: ":WRONG_SIGNATURE_TYPE:",
6149 })
6150
6151 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006152 testType: serverTest,
6153 name: "Verify-ClientAuth-SignatureType-TLS13",
6154 config: Config{
6155 MaxVersion: VersionTLS13,
6156 Certificates: []Certificate{rsaCertificate},
6157 SignSignatureAlgorithms: []signatureAlgorithm{
6158 signatureRSAPSSWithSHA256,
6159 },
6160 Bugs: ProtocolBugs{
6161 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6162 },
6163 },
6164 flags: []string{
6165 "-require-any-client-certificate",
6166 },
6167 shouldFail: true,
6168 expectedError: ":WRONG_SIGNATURE_TYPE:",
6169 })
6170
6171 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006172 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006173 config: Config{
6174 MaxVersion: VersionTLS12,
6175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006176 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006177 signatureRSAPKCS1WithSHA256,
6178 },
6179 Bugs: ProtocolBugs{
6180 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6181 },
6182 },
6183 shouldFail: true,
6184 expectedError: ":WRONG_SIGNATURE_TYPE:",
6185 })
6186
Steven Valdez143e8b32016-07-11 13:19:03 -04006187 testCases = append(testCases, testCase{
6188 name: "Verify-ServerAuth-SignatureType-TLS13",
6189 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006190 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006191 SignSignatureAlgorithms: []signatureAlgorithm{
6192 signatureRSAPSSWithSHA256,
6193 },
6194 Bugs: ProtocolBugs{
6195 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6196 },
6197 },
6198 shouldFail: true,
6199 expectedError: ":WRONG_SIGNATURE_TYPE:",
6200 })
6201
David Benjamin51dd7d62016-07-08 16:07:01 -07006202 // Test that, if the list is missing, the peer falls back to SHA-1 in
6203 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006204 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006205 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006206 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006207 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006208 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006209 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006210 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006211 },
6212 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006213 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006214 },
6215 },
6216 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006217 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6218 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006219 },
6220 })
6221
6222 testCases = append(testCases, testCase{
6223 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006224 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006225 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006226 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006227 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006228 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006229 },
6230 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006231 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006232 },
6233 },
David Benjaminee32bea2016-08-17 13:36:44 -04006234 flags: []string{
6235 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6236 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6237 },
6238 })
6239
6240 testCases = append(testCases, testCase{
6241 name: "ClientAuth-SHA1-Fallback-ECDSA",
6242 config: Config{
6243 MaxVersion: VersionTLS12,
6244 ClientAuth: RequireAnyClientCert,
6245 VerifySignatureAlgorithms: []signatureAlgorithm{
6246 signatureECDSAWithSHA1,
6247 },
6248 Bugs: ProtocolBugs{
6249 NoSignatureAlgorithms: true,
6250 },
6251 },
6252 flags: []string{
6253 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6254 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6255 },
6256 })
6257
6258 testCases = append(testCases, testCase{
6259 testType: serverTest,
6260 name: "ServerAuth-SHA1-Fallback-ECDSA",
6261 config: Config{
6262 MaxVersion: VersionTLS12,
6263 VerifySignatureAlgorithms: []signatureAlgorithm{
6264 signatureECDSAWithSHA1,
6265 },
6266 Bugs: ProtocolBugs{
6267 NoSignatureAlgorithms: true,
6268 },
6269 },
6270 flags: []string{
6271 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6272 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6273 },
David Benjamin000800a2014-11-14 01:43:59 -05006274 })
David Benjamin72dc7832015-03-16 17:49:43 -04006275
David Benjamin51dd7d62016-07-08 16:07:01 -07006276 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006277 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006278 config: Config{
6279 MaxVersion: VersionTLS13,
6280 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006281 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006282 signatureRSAPKCS1WithSHA1,
6283 },
6284 Bugs: ProtocolBugs{
6285 NoSignatureAlgorithms: true,
6286 },
6287 },
6288 flags: []string{
6289 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6290 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6291 },
David Benjamin48901652016-08-01 12:12:47 -04006292 shouldFail: true,
6293 // An empty CertificateRequest signature algorithm list is a
6294 // syntax error in TLS 1.3.
6295 expectedError: ":DECODE_ERROR:",
6296 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006297 })
6298
6299 testCases = append(testCases, testCase{
6300 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006301 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006302 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006303 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006304 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006305 signatureRSAPKCS1WithSHA1,
6306 },
6307 Bugs: ProtocolBugs{
6308 NoSignatureAlgorithms: true,
6309 },
6310 },
6311 shouldFail: true,
6312 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6313 })
6314
David Benjaminb62d2872016-07-18 14:55:02 +02006315 // Test that hash preferences are enforced. BoringSSL does not implement
6316 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006317 testCases = append(testCases, testCase{
6318 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006319 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006320 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006321 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006322 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006323 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006324 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006325 },
6326 Bugs: ProtocolBugs{
6327 IgnorePeerSignatureAlgorithmPreferences: true,
6328 },
6329 },
6330 flags: []string{"-require-any-client-certificate"},
6331 shouldFail: true,
6332 expectedError: ":WRONG_SIGNATURE_TYPE:",
6333 })
6334
6335 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006336 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006337 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006338 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006339 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006340 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006341 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006342 },
6343 Bugs: ProtocolBugs{
6344 IgnorePeerSignatureAlgorithmPreferences: true,
6345 },
6346 },
6347 shouldFail: true,
6348 expectedError: ":WRONG_SIGNATURE_TYPE:",
6349 })
David Benjaminb62d2872016-07-18 14:55:02 +02006350 testCases = append(testCases, testCase{
6351 testType: serverTest,
6352 name: "ClientAuth-Enforced-TLS13",
6353 config: Config{
6354 MaxVersion: VersionTLS13,
6355 Certificates: []Certificate{rsaCertificate},
6356 SignSignatureAlgorithms: []signatureAlgorithm{
6357 signatureRSAPKCS1WithMD5,
6358 },
6359 Bugs: ProtocolBugs{
6360 IgnorePeerSignatureAlgorithmPreferences: true,
6361 IgnoreSignatureVersionChecks: true,
6362 },
6363 },
6364 flags: []string{"-require-any-client-certificate"},
6365 shouldFail: true,
6366 expectedError: ":WRONG_SIGNATURE_TYPE:",
6367 })
6368
6369 testCases = append(testCases, testCase{
6370 name: "ServerAuth-Enforced-TLS13",
6371 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006372 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006373 SignSignatureAlgorithms: []signatureAlgorithm{
6374 signatureRSAPKCS1WithMD5,
6375 },
6376 Bugs: ProtocolBugs{
6377 IgnorePeerSignatureAlgorithmPreferences: true,
6378 IgnoreSignatureVersionChecks: true,
6379 },
6380 },
6381 shouldFail: true,
6382 expectedError: ":WRONG_SIGNATURE_TYPE:",
6383 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006384
6385 // Test that the agreed upon digest respects the client preferences and
6386 // the server digests.
6387 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006388 name: "NoCommonAlgorithms-Digests",
6389 config: Config{
6390 MaxVersion: VersionTLS12,
6391 ClientAuth: RequireAnyClientCert,
6392 VerifySignatureAlgorithms: []signatureAlgorithm{
6393 signatureRSAPKCS1WithSHA512,
6394 signatureRSAPKCS1WithSHA1,
6395 },
6396 },
6397 flags: []string{
6398 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6399 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6400 "-digest-prefs", "SHA256",
6401 },
6402 shouldFail: true,
6403 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6404 })
6405 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006406 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006408 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006409 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006410 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006411 signatureRSAPKCS1WithSHA512,
6412 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006413 },
6414 },
6415 flags: []string{
6416 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6417 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006418 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006419 },
David Benjaminca3d5452016-07-14 12:51:01 -04006420 shouldFail: true,
6421 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6422 })
6423 testCases = append(testCases, testCase{
6424 name: "NoCommonAlgorithms-TLS13",
6425 config: Config{
6426 MaxVersion: VersionTLS13,
6427 ClientAuth: RequireAnyClientCert,
6428 VerifySignatureAlgorithms: []signatureAlgorithm{
6429 signatureRSAPSSWithSHA512,
6430 signatureRSAPSSWithSHA384,
6431 },
6432 },
6433 flags: []string{
6434 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6435 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6436 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6437 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006438 shouldFail: true,
6439 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006440 })
6441 testCases = append(testCases, testCase{
6442 name: "Agree-Digest-SHA256",
6443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006444 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006445 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006446 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006447 signatureRSAPKCS1WithSHA1,
6448 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006449 },
6450 },
6451 flags: []string{
6452 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6453 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006454 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006455 },
Nick Harper60edffd2016-06-21 15:19:24 -07006456 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006457 })
6458 testCases = append(testCases, testCase{
6459 name: "Agree-Digest-SHA1",
6460 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006461 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006462 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006463 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006464 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006465 },
6466 },
6467 flags: []string{
6468 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6469 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006470 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006471 },
Nick Harper60edffd2016-06-21 15:19:24 -07006472 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006473 })
6474 testCases = append(testCases, testCase{
6475 name: "Agree-Digest-Default",
6476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006477 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006478 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006479 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006480 signatureRSAPKCS1WithSHA256,
6481 signatureECDSAWithP256AndSHA256,
6482 signatureRSAPKCS1WithSHA1,
6483 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006484 },
6485 },
6486 flags: []string{
6487 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6488 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6489 },
Nick Harper60edffd2016-06-21 15:19:24 -07006490 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006491 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006492
David Benjaminca3d5452016-07-14 12:51:01 -04006493 // Test that the signing preference list may include extra algorithms
6494 // without negotiation problems.
6495 testCases = append(testCases, testCase{
6496 testType: serverTest,
6497 name: "FilterExtraAlgorithms",
6498 config: Config{
6499 MaxVersion: VersionTLS12,
6500 VerifySignatureAlgorithms: []signatureAlgorithm{
6501 signatureRSAPKCS1WithSHA256,
6502 },
6503 },
6504 flags: []string{
6505 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6506 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6507 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6508 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6509 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6510 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6511 },
6512 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6513 })
6514
David Benjamin4c3ddf72016-06-29 18:13:53 -04006515 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6516 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006517 testCases = append(testCases, testCase{
6518 name: "CheckLeafCurve",
6519 config: Config{
6520 MaxVersion: VersionTLS12,
6521 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006522 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006523 },
6524 flags: []string{"-p384-only"},
6525 shouldFail: true,
6526 expectedError: ":BAD_ECC_CERT:",
6527 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006528
6529 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6530 testCases = append(testCases, testCase{
6531 name: "CheckLeafCurve-TLS13",
6532 config: Config{
6533 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07006534 Certificates: []Certificate{ecdsaP256Certificate},
6535 },
6536 flags: []string{"-p384-only"},
6537 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006538
6539 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6540 testCases = append(testCases, testCase{
6541 name: "ECDSACurveMismatch-Verify-TLS12",
6542 config: Config{
6543 MaxVersion: VersionTLS12,
6544 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6545 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006546 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006547 signatureECDSAWithP384AndSHA384,
6548 },
6549 },
6550 })
6551
6552 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6553 testCases = append(testCases, testCase{
6554 name: "ECDSACurveMismatch-Verify-TLS13",
6555 config: Config{
6556 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07006557 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006558 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006559 signatureECDSAWithP384AndSHA384,
6560 },
6561 Bugs: ProtocolBugs{
6562 SkipECDSACurveCheck: true,
6563 },
6564 },
6565 shouldFail: true,
6566 expectedError: ":WRONG_SIGNATURE_TYPE:",
6567 })
6568
6569 // Signature algorithm selection in TLS 1.3 should take the curve into
6570 // account.
6571 testCases = append(testCases, testCase{
6572 testType: serverTest,
6573 name: "ECDSACurveMismatch-Sign-TLS13",
6574 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006575 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006576 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006577 signatureECDSAWithP384AndSHA384,
6578 signatureECDSAWithP256AndSHA256,
6579 },
6580 },
6581 flags: []string{
6582 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6583 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6584 },
6585 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6586 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006587
6588 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6589 // server does not attempt to sign in that case.
6590 testCases = append(testCases, testCase{
6591 testType: serverTest,
6592 name: "RSA-PSS-Large",
6593 config: Config{
6594 MaxVersion: VersionTLS13,
6595 VerifySignatureAlgorithms: []signatureAlgorithm{
6596 signatureRSAPSSWithSHA512,
6597 },
6598 },
6599 flags: []string{
6600 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6601 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6602 },
6603 shouldFail: true,
6604 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6605 })
David Benjamin57e929f2016-08-30 00:30:38 -04006606
6607 // Test that RSA-PSS is enabled by default for TLS 1.2.
6608 testCases = append(testCases, testCase{
6609 testType: clientTest,
6610 name: "RSA-PSS-Default-Verify",
6611 config: Config{
6612 MaxVersion: VersionTLS12,
6613 SignSignatureAlgorithms: []signatureAlgorithm{
6614 signatureRSAPSSWithSHA256,
6615 },
6616 },
6617 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6618 })
6619
6620 testCases = append(testCases, testCase{
6621 testType: serverTest,
6622 name: "RSA-PSS-Default-Sign",
6623 config: Config{
6624 MaxVersion: VersionTLS12,
6625 VerifySignatureAlgorithms: []signatureAlgorithm{
6626 signatureRSAPSSWithSHA256,
6627 },
6628 },
6629 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6630 })
David Benjamin000800a2014-11-14 01:43:59 -05006631}
6632
David Benjamin83f90402015-01-27 01:09:43 -05006633// timeouts is the retransmit schedule for BoringSSL. It doubles and
6634// caps at 60 seconds. On the 13th timeout, it gives up.
6635var timeouts = []time.Duration{
6636 1 * time.Second,
6637 2 * time.Second,
6638 4 * time.Second,
6639 8 * time.Second,
6640 16 * time.Second,
6641 32 * time.Second,
6642 60 * time.Second,
6643 60 * time.Second,
6644 60 * time.Second,
6645 60 * time.Second,
6646 60 * time.Second,
6647 60 * time.Second,
6648 60 * time.Second,
6649}
6650
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006651// shortTimeouts is an alternate set of timeouts which would occur if the
6652// initial timeout duration was set to 250ms.
6653var shortTimeouts = []time.Duration{
6654 250 * time.Millisecond,
6655 500 * time.Millisecond,
6656 1 * time.Second,
6657 2 * time.Second,
6658 4 * time.Second,
6659 8 * time.Second,
6660 16 * time.Second,
6661 32 * time.Second,
6662 60 * time.Second,
6663 60 * time.Second,
6664 60 * time.Second,
6665 60 * time.Second,
6666 60 * time.Second,
6667}
6668
David Benjamin83f90402015-01-27 01:09:43 -05006669func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006670 // These tests work by coordinating some behavior on both the shim and
6671 // the runner.
6672 //
6673 // TimeoutSchedule configures the runner to send a series of timeout
6674 // opcodes to the shim (see packetAdaptor) immediately before reading
6675 // each peer handshake flight N. The timeout opcode both simulates a
6676 // timeout in the shim and acts as a synchronization point to help the
6677 // runner bracket each handshake flight.
6678 //
6679 // We assume the shim does not read from the channel eagerly. It must
6680 // first wait until it has sent flight N and is ready to receive
6681 // handshake flight N+1. At this point, it will process the timeout
6682 // opcode. It must then immediately respond with a timeout ACK and act
6683 // as if the shim was idle for the specified amount of time.
6684 //
6685 // The runner then drops all packets received before the ACK and
6686 // continues waiting for flight N. This ordering results in one attempt
6687 // at sending flight N to be dropped. For the test to complete, the
6688 // shim must send flight N again, testing that the shim implements DTLS
6689 // retransmit on a timeout.
6690
Steven Valdez143e8b32016-07-11 13:19:03 -04006691 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006692 // likely be more epochs to cross and the final message's retransmit may
6693 // be more complex.
6694
David Benjamin585d7a42016-06-02 14:58:00 -04006695 for _, async := range []bool{true, false} {
6696 var tests []testCase
6697
6698 // Test that this is indeed the timeout schedule. Stress all
6699 // four patterns of handshake.
6700 for i := 1; i < len(timeouts); i++ {
6701 number := strconv.Itoa(i)
6702 tests = append(tests, testCase{
6703 protocol: dtls,
6704 name: "DTLS-Retransmit-Client-" + number,
6705 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006706 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006707 Bugs: ProtocolBugs{
6708 TimeoutSchedule: timeouts[:i],
6709 },
6710 },
6711 resumeSession: true,
6712 })
6713 tests = append(tests, testCase{
6714 protocol: dtls,
6715 testType: serverTest,
6716 name: "DTLS-Retransmit-Server-" + number,
6717 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006718 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006719 Bugs: ProtocolBugs{
6720 TimeoutSchedule: timeouts[:i],
6721 },
6722 },
6723 resumeSession: true,
6724 })
6725 }
6726
6727 // Test that exceeding the timeout schedule hits a read
6728 // timeout.
6729 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006730 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006731 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006732 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006733 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006734 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006735 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006736 },
6737 },
6738 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006739 shouldFail: true,
6740 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006741 })
David Benjamin585d7a42016-06-02 14:58:00 -04006742
6743 if async {
6744 // Test that timeout handling has a fudge factor, due to API
6745 // problems.
6746 tests = append(tests, testCase{
6747 protocol: dtls,
6748 name: "DTLS-Retransmit-Fudge",
6749 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006750 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006751 Bugs: ProtocolBugs{
6752 TimeoutSchedule: []time.Duration{
6753 timeouts[0] - 10*time.Millisecond,
6754 },
6755 },
6756 },
6757 resumeSession: true,
6758 })
6759 }
6760
6761 // Test that the final Finished retransmitting isn't
6762 // duplicated if the peer badly fragments everything.
6763 tests = append(tests, testCase{
6764 testType: serverTest,
6765 protocol: dtls,
6766 name: "DTLS-Retransmit-Fragmented",
6767 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006768 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006769 Bugs: ProtocolBugs{
6770 TimeoutSchedule: []time.Duration{timeouts[0]},
6771 MaxHandshakeRecordLength: 2,
6772 },
6773 },
6774 })
6775
6776 // Test the timeout schedule when a shorter initial timeout duration is set.
6777 tests = append(tests, testCase{
6778 protocol: dtls,
6779 name: "DTLS-Retransmit-Short-Client",
6780 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006781 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006782 Bugs: ProtocolBugs{
6783 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6784 },
6785 },
6786 resumeSession: true,
6787 flags: []string{"-initial-timeout-duration-ms", "250"},
6788 })
6789 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006790 protocol: dtls,
6791 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006792 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006793 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006794 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006795 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006796 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006797 },
6798 },
6799 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006800 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006801 })
David Benjamin585d7a42016-06-02 14:58:00 -04006802
6803 for _, test := range tests {
6804 if async {
6805 test.name += "-Async"
6806 test.flags = append(test.flags, "-async")
6807 }
6808
6809 testCases = append(testCases, test)
6810 }
David Benjamin83f90402015-01-27 01:09:43 -05006811 }
David Benjamin83f90402015-01-27 01:09:43 -05006812}
6813
David Benjaminc565ebb2015-04-03 04:06:36 -04006814func addExportKeyingMaterialTests() {
6815 for _, vers := range tlsVersions {
6816 if vers.version == VersionSSL30 {
6817 continue
6818 }
6819 testCases = append(testCases, testCase{
6820 name: "ExportKeyingMaterial-" + vers.name,
6821 config: Config{
6822 MaxVersion: vers.version,
6823 },
6824 exportKeyingMaterial: 1024,
6825 exportLabel: "label",
6826 exportContext: "context",
6827 useExportContext: true,
6828 })
6829 testCases = append(testCases, testCase{
6830 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6831 config: Config{
6832 MaxVersion: vers.version,
6833 },
6834 exportKeyingMaterial: 1024,
6835 })
6836 testCases = append(testCases, testCase{
6837 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6838 config: Config{
6839 MaxVersion: vers.version,
6840 },
6841 exportKeyingMaterial: 1024,
6842 useExportContext: true,
6843 })
6844 testCases = append(testCases, testCase{
6845 name: "ExportKeyingMaterial-Small-" + vers.name,
6846 config: Config{
6847 MaxVersion: vers.version,
6848 },
6849 exportKeyingMaterial: 1,
6850 exportLabel: "label",
6851 exportContext: "context",
6852 useExportContext: true,
6853 })
6854 }
6855 testCases = append(testCases, testCase{
6856 name: "ExportKeyingMaterial-SSL3",
6857 config: Config{
6858 MaxVersion: VersionSSL30,
6859 },
6860 exportKeyingMaterial: 1024,
6861 exportLabel: "label",
6862 exportContext: "context",
6863 useExportContext: true,
6864 shouldFail: true,
6865 expectedError: "failed to export keying material",
6866 })
6867}
6868
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006869func addTLSUniqueTests() {
6870 for _, isClient := range []bool{false, true} {
6871 for _, isResumption := range []bool{false, true} {
6872 for _, hasEMS := range []bool{false, true} {
6873 var suffix string
6874 if isResumption {
6875 suffix = "Resume-"
6876 } else {
6877 suffix = "Full-"
6878 }
6879
6880 if hasEMS {
6881 suffix += "EMS-"
6882 } else {
6883 suffix += "NoEMS-"
6884 }
6885
6886 if isClient {
6887 suffix += "Client"
6888 } else {
6889 suffix += "Server"
6890 }
6891
6892 test := testCase{
6893 name: "TLSUnique-" + suffix,
6894 testTLSUnique: true,
6895 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006896 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006897 Bugs: ProtocolBugs{
6898 NoExtendedMasterSecret: !hasEMS,
6899 },
6900 },
6901 }
6902
6903 if isResumption {
6904 test.resumeSession = true
6905 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006906 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006907 Bugs: ProtocolBugs{
6908 NoExtendedMasterSecret: !hasEMS,
6909 },
6910 }
6911 }
6912
6913 if isResumption && !hasEMS {
6914 test.shouldFail = true
6915 test.expectedError = "failed to get tls-unique"
6916 }
6917
6918 testCases = append(testCases, test)
6919 }
6920 }
6921 }
6922}
6923
Adam Langley09505632015-07-30 18:10:13 -07006924func addCustomExtensionTests() {
6925 expectedContents := "custom extension"
6926 emptyString := ""
6927
6928 for _, isClient := range []bool{false, true} {
6929 suffix := "Server"
6930 flag := "-enable-server-custom-extension"
6931 testType := serverTest
6932 if isClient {
6933 suffix = "Client"
6934 flag = "-enable-client-custom-extension"
6935 testType = clientTest
6936 }
6937
6938 testCases = append(testCases, testCase{
6939 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006940 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006941 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006942 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006943 Bugs: ProtocolBugs{
6944 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006945 ExpectedCustomExtension: &expectedContents,
6946 },
6947 },
6948 flags: []string{flag},
6949 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006950 testCases = append(testCases, testCase{
6951 testType: testType,
6952 name: "CustomExtensions-" + suffix + "-TLS13",
6953 config: Config{
6954 MaxVersion: VersionTLS13,
6955 Bugs: ProtocolBugs{
6956 CustomExtension: expectedContents,
6957 ExpectedCustomExtension: &expectedContents,
6958 },
6959 },
6960 flags: []string{flag},
6961 })
Adam Langley09505632015-07-30 18:10:13 -07006962
6963 // If the parse callback fails, the handshake should also fail.
6964 testCases = append(testCases, testCase{
6965 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006966 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006967 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006968 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006969 Bugs: ProtocolBugs{
6970 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006971 ExpectedCustomExtension: &expectedContents,
6972 },
6973 },
David Benjamin399e7c92015-07-30 23:01:27 -04006974 flags: []string{flag},
6975 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006976 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6977 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006978 testCases = append(testCases, testCase{
6979 testType: testType,
6980 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6981 config: Config{
6982 MaxVersion: VersionTLS13,
6983 Bugs: ProtocolBugs{
6984 CustomExtension: expectedContents + "foo",
6985 ExpectedCustomExtension: &expectedContents,
6986 },
6987 },
6988 flags: []string{flag},
6989 shouldFail: true,
6990 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6991 })
Adam Langley09505632015-07-30 18:10:13 -07006992
6993 // If the add callback fails, the handshake should also fail.
6994 testCases = append(testCases, testCase{
6995 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006996 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006998 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006999 Bugs: ProtocolBugs{
7000 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007001 ExpectedCustomExtension: &expectedContents,
7002 },
7003 },
David Benjamin399e7c92015-07-30 23:01:27 -04007004 flags: []string{flag, "-custom-extension-fail-add"},
7005 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007006 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7007 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007008 testCases = append(testCases, testCase{
7009 testType: testType,
7010 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7011 config: Config{
7012 MaxVersion: VersionTLS13,
7013 Bugs: ProtocolBugs{
7014 CustomExtension: expectedContents,
7015 ExpectedCustomExtension: &expectedContents,
7016 },
7017 },
7018 flags: []string{flag, "-custom-extension-fail-add"},
7019 shouldFail: true,
7020 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7021 })
Adam Langley09505632015-07-30 18:10:13 -07007022
7023 // If the add callback returns zero, no extension should be
7024 // added.
7025 skipCustomExtension := expectedContents
7026 if isClient {
7027 // For the case where the client skips sending the
7028 // custom extension, the server must not “echo” it.
7029 skipCustomExtension = ""
7030 }
7031 testCases = append(testCases, testCase{
7032 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007033 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007034 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007035 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007036 Bugs: ProtocolBugs{
7037 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007038 ExpectedCustomExtension: &emptyString,
7039 },
7040 },
7041 flags: []string{flag, "-custom-extension-skip"},
7042 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007043 testCases = append(testCases, testCase{
7044 testType: testType,
7045 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7046 config: Config{
7047 MaxVersion: VersionTLS13,
7048 Bugs: ProtocolBugs{
7049 CustomExtension: skipCustomExtension,
7050 ExpectedCustomExtension: &emptyString,
7051 },
7052 },
7053 flags: []string{flag, "-custom-extension-skip"},
7054 })
Adam Langley09505632015-07-30 18:10:13 -07007055 }
7056
7057 // The custom extension add callback should not be called if the client
7058 // doesn't send the extension.
7059 testCases = append(testCases, testCase{
7060 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007061 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007062 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007063 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007064 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007065 ExpectedCustomExtension: &emptyString,
7066 },
7067 },
7068 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7069 })
Adam Langley2deb9842015-08-07 11:15:37 -07007070
Steven Valdez143e8b32016-07-11 13:19:03 -04007071 testCases = append(testCases, testCase{
7072 testType: serverTest,
7073 name: "CustomExtensions-NotCalled-Server-TLS13",
7074 config: Config{
7075 MaxVersion: VersionTLS13,
7076 Bugs: ProtocolBugs{
7077 ExpectedCustomExtension: &emptyString,
7078 },
7079 },
7080 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7081 })
7082
Adam Langley2deb9842015-08-07 11:15:37 -07007083 // Test an unknown extension from the server.
7084 testCases = append(testCases, testCase{
7085 testType: clientTest,
7086 name: "UnknownExtension-Client",
7087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007088 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007089 Bugs: ProtocolBugs{
7090 CustomExtension: expectedContents,
7091 },
7092 },
David Benjamin0c40a962016-08-01 12:05:50 -04007093 shouldFail: true,
7094 expectedError: ":UNEXPECTED_EXTENSION:",
7095 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007096 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007097 testCases = append(testCases, testCase{
7098 testType: clientTest,
7099 name: "UnknownExtension-Client-TLS13",
7100 config: Config{
7101 MaxVersion: VersionTLS13,
7102 Bugs: ProtocolBugs{
7103 CustomExtension: expectedContents,
7104 },
7105 },
David Benjamin0c40a962016-08-01 12:05:50 -04007106 shouldFail: true,
7107 expectedError: ":UNEXPECTED_EXTENSION:",
7108 expectedLocalError: "remote error: unsupported extension",
7109 })
7110
7111 // Test a known but unoffered extension from the server.
7112 testCases = append(testCases, testCase{
7113 testType: clientTest,
7114 name: "UnofferedExtension-Client",
7115 config: Config{
7116 MaxVersion: VersionTLS12,
7117 Bugs: ProtocolBugs{
7118 SendALPN: "alpn",
7119 },
7120 },
7121 shouldFail: true,
7122 expectedError: ":UNEXPECTED_EXTENSION:",
7123 expectedLocalError: "remote error: unsupported extension",
7124 })
7125 testCases = append(testCases, testCase{
7126 testType: clientTest,
7127 name: "UnofferedExtension-Client-TLS13",
7128 config: Config{
7129 MaxVersion: VersionTLS13,
7130 Bugs: ProtocolBugs{
7131 SendALPN: "alpn",
7132 },
7133 },
7134 shouldFail: true,
7135 expectedError: ":UNEXPECTED_EXTENSION:",
7136 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007137 })
Adam Langley09505632015-07-30 18:10:13 -07007138}
7139
David Benjaminb36a3952015-12-01 18:53:13 -05007140func addRSAClientKeyExchangeTests() {
7141 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7142 testCases = append(testCases, testCase{
7143 testType: serverTest,
7144 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7145 config: Config{
7146 // Ensure the ClientHello version and final
7147 // version are different, to detect if the
7148 // server uses the wrong one.
7149 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007150 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007151 Bugs: ProtocolBugs{
7152 BadRSAClientKeyExchange: bad,
7153 },
7154 },
7155 shouldFail: true,
7156 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7157 })
7158 }
David Benjamine63d9d72016-09-19 18:27:34 -04007159
7160 // The server must compare whatever was in ClientHello.version for the
7161 // RSA premaster.
7162 testCases = append(testCases, testCase{
7163 testType: serverTest,
7164 name: "SendClientVersion-RSA",
7165 config: Config{
7166 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7167 Bugs: ProtocolBugs{
7168 SendClientVersion: 0x1234,
7169 },
7170 },
7171 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7172 })
David Benjaminb36a3952015-12-01 18:53:13 -05007173}
7174
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007175var testCurves = []struct {
7176 name string
7177 id CurveID
7178}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007179 {"P-256", CurveP256},
7180 {"P-384", CurveP384},
7181 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007182 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007183}
7184
Steven Valdez5440fe02016-07-18 12:40:30 -04007185const bogusCurve = 0x1234
7186
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007187func addCurveTests() {
7188 for _, curve := range testCurves {
7189 testCases = append(testCases, testCase{
7190 name: "CurveTest-Client-" + curve.name,
7191 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007192 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007193 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7194 CurvePreferences: []CurveID{curve.id},
7195 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007196 flags: []string{
7197 "-enable-all-curves",
7198 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7199 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007200 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007201 })
7202 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007203 name: "CurveTest-Client-" + curve.name + "-TLS13",
7204 config: Config{
7205 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007206 CurvePreferences: []CurveID{curve.id},
7207 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007208 flags: []string{
7209 "-enable-all-curves",
7210 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7211 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007212 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007213 })
7214 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007215 testType: serverTest,
7216 name: "CurveTest-Server-" + curve.name,
7217 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007218 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007219 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7220 CurvePreferences: []CurveID{curve.id},
7221 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007222 flags: []string{
7223 "-enable-all-curves",
7224 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7225 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007226 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007227 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007228 testCases = append(testCases, testCase{
7229 testType: serverTest,
7230 name: "CurveTest-Server-" + curve.name + "-TLS13",
7231 config: Config{
7232 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007233 CurvePreferences: []CurveID{curve.id},
7234 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007235 flags: []string{
7236 "-enable-all-curves",
7237 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7238 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007239 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007240 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007241 }
David Benjamin241ae832016-01-15 03:04:54 -05007242
7243 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007244 testCases = append(testCases, testCase{
7245 testType: serverTest,
7246 name: "UnknownCurve",
7247 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007248 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007249 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7250 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7251 },
7252 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007253
Steven Valdez803c77a2016-09-06 14:13:43 -04007254 // The server must be tolerant to bogus curves.
7255 testCases = append(testCases, testCase{
7256 testType: serverTest,
7257 name: "UnknownCurve-TLS13",
7258 config: Config{
7259 MaxVersion: VersionTLS13,
7260 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7261 },
7262 })
7263
David Benjamin4c3ddf72016-06-29 18:13:53 -04007264 // The server must not consider ECDHE ciphers when there are no
7265 // supported curves.
7266 testCases = append(testCases, testCase{
7267 testType: serverTest,
7268 name: "NoSupportedCurves",
7269 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007270 MaxVersion: VersionTLS12,
7271 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7272 Bugs: ProtocolBugs{
7273 NoSupportedCurves: true,
7274 },
7275 },
7276 shouldFail: true,
7277 expectedError: ":NO_SHARED_CIPHER:",
7278 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007279 testCases = append(testCases, testCase{
7280 testType: serverTest,
7281 name: "NoSupportedCurves-TLS13",
7282 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007283 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007284 Bugs: ProtocolBugs{
7285 NoSupportedCurves: true,
7286 },
7287 },
7288 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007289 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007290 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007291
7292 // The server must fall back to another cipher when there are no
7293 // supported curves.
7294 testCases = append(testCases, testCase{
7295 testType: serverTest,
7296 name: "NoCommonCurves",
7297 config: Config{
7298 MaxVersion: VersionTLS12,
7299 CipherSuites: []uint16{
7300 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7301 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7302 },
7303 CurvePreferences: []CurveID{CurveP224},
7304 },
7305 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7306 })
7307
7308 // The client must reject bogus curves and disabled curves.
7309 testCases = append(testCases, testCase{
7310 name: "BadECDHECurve",
7311 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007312 MaxVersion: VersionTLS12,
7313 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7314 Bugs: ProtocolBugs{
7315 SendCurve: bogusCurve,
7316 },
7317 },
7318 shouldFail: true,
7319 expectedError: ":WRONG_CURVE:",
7320 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007321 testCases = append(testCases, testCase{
7322 name: "BadECDHECurve-TLS13",
7323 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007324 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007325 Bugs: ProtocolBugs{
7326 SendCurve: bogusCurve,
7327 },
7328 },
7329 shouldFail: true,
7330 expectedError: ":WRONG_CURVE:",
7331 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007332
7333 testCases = append(testCases, testCase{
7334 name: "UnsupportedCurve",
7335 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007336 MaxVersion: VersionTLS12,
7337 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7338 CurvePreferences: []CurveID{CurveP256},
7339 Bugs: ProtocolBugs{
7340 IgnorePeerCurvePreferences: true,
7341 },
7342 },
7343 flags: []string{"-p384-only"},
7344 shouldFail: true,
7345 expectedError: ":WRONG_CURVE:",
7346 })
7347
David Benjamin4f921572016-07-17 14:20:10 +02007348 testCases = append(testCases, testCase{
7349 // TODO(davidben): Add a TLS 1.3 version where
7350 // HelloRetryRequest requests an unsupported curve.
7351 name: "UnsupportedCurve-ServerHello-TLS13",
7352 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007353 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02007354 CurvePreferences: []CurveID{CurveP384},
7355 Bugs: ProtocolBugs{
7356 SendCurve: CurveP256,
7357 },
7358 },
7359 flags: []string{"-p384-only"},
7360 shouldFail: true,
7361 expectedError: ":WRONG_CURVE:",
7362 })
7363
David Benjamin4c3ddf72016-06-29 18:13:53 -04007364 // Test invalid curve points.
7365 testCases = append(testCases, testCase{
7366 name: "InvalidECDHPoint-Client",
7367 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007368 MaxVersion: VersionTLS12,
7369 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7370 CurvePreferences: []CurveID{CurveP256},
7371 Bugs: ProtocolBugs{
7372 InvalidECDHPoint: true,
7373 },
7374 },
7375 shouldFail: true,
7376 expectedError: ":INVALID_ENCODING:",
7377 })
7378 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007379 name: "InvalidECDHPoint-Client-TLS13",
7380 config: Config{
7381 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007382 CurvePreferences: []CurveID{CurveP256},
7383 Bugs: ProtocolBugs{
7384 InvalidECDHPoint: true,
7385 },
7386 },
7387 shouldFail: true,
7388 expectedError: ":INVALID_ENCODING:",
7389 })
7390 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007391 testType: serverTest,
7392 name: "InvalidECDHPoint-Server",
7393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007394 MaxVersion: VersionTLS12,
7395 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7396 CurvePreferences: []CurveID{CurveP256},
7397 Bugs: ProtocolBugs{
7398 InvalidECDHPoint: true,
7399 },
7400 },
7401 shouldFail: true,
7402 expectedError: ":INVALID_ENCODING:",
7403 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007404 testCases = append(testCases, testCase{
7405 testType: serverTest,
7406 name: "InvalidECDHPoint-Server-TLS13",
7407 config: Config{
7408 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007409 CurvePreferences: []CurveID{CurveP256},
7410 Bugs: ProtocolBugs{
7411 InvalidECDHPoint: true,
7412 },
7413 },
7414 shouldFail: true,
7415 expectedError: ":INVALID_ENCODING:",
7416 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007417}
7418
Matt Braithwaite54217e42016-06-13 13:03:47 -07007419func addCECPQ1Tests() {
7420 testCases = append(testCases, testCase{
7421 testType: clientTest,
7422 name: "CECPQ1-Client-BadX25519Part",
7423 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007424 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007425 MinVersion: VersionTLS12,
7426 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7427 Bugs: ProtocolBugs{
7428 CECPQ1BadX25519Part: true,
7429 },
7430 },
7431 flags: []string{"-cipher", "kCECPQ1"},
7432 shouldFail: true,
7433 expectedLocalError: "local error: bad record MAC",
7434 })
7435 testCases = append(testCases, testCase{
7436 testType: clientTest,
7437 name: "CECPQ1-Client-BadNewhopePart",
7438 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007439 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007440 MinVersion: VersionTLS12,
7441 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7442 Bugs: ProtocolBugs{
7443 CECPQ1BadNewhopePart: true,
7444 },
7445 },
7446 flags: []string{"-cipher", "kCECPQ1"},
7447 shouldFail: true,
7448 expectedLocalError: "local error: bad record MAC",
7449 })
7450 testCases = append(testCases, testCase{
7451 testType: serverTest,
7452 name: "CECPQ1-Server-BadX25519Part",
7453 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007454 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007455 MinVersion: VersionTLS12,
7456 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7457 Bugs: ProtocolBugs{
7458 CECPQ1BadX25519Part: true,
7459 },
7460 },
7461 flags: []string{"-cipher", "kCECPQ1"},
7462 shouldFail: true,
7463 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7464 })
7465 testCases = append(testCases, testCase{
7466 testType: serverTest,
7467 name: "CECPQ1-Server-BadNewhopePart",
7468 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007469 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007470 MinVersion: VersionTLS12,
7471 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7472 Bugs: ProtocolBugs{
7473 CECPQ1BadNewhopePart: true,
7474 },
7475 },
7476 flags: []string{"-cipher", "kCECPQ1"},
7477 shouldFail: true,
7478 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7479 })
7480}
7481
David Benjamin5c4e8572016-08-19 17:44:53 -04007482func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007483 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007484 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007485 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007486 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007487 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7488 Bugs: ProtocolBugs{
7489 // This is a 1234-bit prime number, generated
7490 // with:
7491 // openssl gendh 1234 | openssl asn1parse -i
7492 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7493 },
7494 },
David Benjamin9e68f192016-06-30 14:55:33 -04007495 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007496 })
7497 testCases = append(testCases, testCase{
7498 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007499 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007500 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007501 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007502 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7503 },
7504 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007505 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007506 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007507}
7508
David Benjaminc9ae27c2016-06-24 22:56:37 -04007509func addTLS13RecordTests() {
7510 testCases = append(testCases, testCase{
7511 name: "TLS13-RecordPadding",
7512 config: Config{
7513 MaxVersion: VersionTLS13,
7514 MinVersion: VersionTLS13,
7515 Bugs: ProtocolBugs{
7516 RecordPadding: 10,
7517 },
7518 },
7519 })
7520
7521 testCases = append(testCases, testCase{
7522 name: "TLS13-EmptyRecords",
7523 config: Config{
7524 MaxVersion: VersionTLS13,
7525 MinVersion: VersionTLS13,
7526 Bugs: ProtocolBugs{
7527 OmitRecordContents: true,
7528 },
7529 },
7530 shouldFail: true,
7531 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7532 })
7533
7534 testCases = append(testCases, testCase{
7535 name: "TLS13-OnlyPadding",
7536 config: Config{
7537 MaxVersion: VersionTLS13,
7538 MinVersion: VersionTLS13,
7539 Bugs: ProtocolBugs{
7540 OmitRecordContents: true,
7541 RecordPadding: 10,
7542 },
7543 },
7544 shouldFail: true,
7545 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7546 })
7547
7548 testCases = append(testCases, testCase{
7549 name: "TLS13-WrongOuterRecord",
7550 config: Config{
7551 MaxVersion: VersionTLS13,
7552 MinVersion: VersionTLS13,
7553 Bugs: ProtocolBugs{
7554 OuterRecordType: recordTypeHandshake,
7555 },
7556 },
7557 shouldFail: true,
7558 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7559 })
7560}
7561
Steven Valdez5b986082016-09-01 12:29:49 -04007562func addSessionTicketTests() {
7563 testCases = append(testCases, testCase{
7564 // In TLS 1.2 and below, empty NewSessionTicket messages
7565 // mean the server changed its mind on sending a ticket.
7566 name: "SendEmptySessionTicket",
7567 config: Config{
7568 MaxVersion: VersionTLS12,
7569 Bugs: ProtocolBugs{
7570 SendEmptySessionTicket: true,
7571 },
7572 },
7573 flags: []string{"-expect-no-session"},
7574 })
7575
7576 // Test that the server ignores unknown PSK modes.
7577 testCases = append(testCases, testCase{
7578 testType: serverTest,
7579 name: "TLS13-SendUnknownModeSessionTicket-Server",
7580 config: Config{
7581 MaxVersion: VersionTLS13,
7582 Bugs: ProtocolBugs{
7583 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7584 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7585 },
7586 },
7587 resumeSession: true,
7588 expectedResumeVersion: VersionTLS13,
7589 })
7590
7591 // Test that the server declines sessions with no matching key exchange mode.
7592 testCases = append(testCases, testCase{
7593 testType: serverTest,
7594 name: "TLS13-SendBadKEModeSessionTicket-Server",
7595 config: Config{
7596 MaxVersion: VersionTLS13,
7597 Bugs: ProtocolBugs{
7598 SendPSKKeyExchangeModes: []byte{0x1a},
7599 },
7600 },
7601 resumeSession: true,
7602 expectResumeRejected: true,
7603 })
7604
7605 // Test that the server declines sessions with no matching auth mode.
7606 testCases = append(testCases, testCase{
7607 testType: serverTest,
7608 name: "TLS13-SendBadAuthModeSessionTicket-Server",
7609 config: Config{
7610 MaxVersion: VersionTLS13,
7611 Bugs: ProtocolBugs{
7612 SendPSKAuthModes: []byte{0x1a},
7613 },
7614 },
7615 resumeSession: true,
7616 expectResumeRejected: true,
7617 })
7618
7619 // Test that the client ignores unknown PSK modes.
7620 testCases = append(testCases, testCase{
7621 testType: clientTest,
7622 name: "TLS13-SendUnknownModeSessionTicket-Client",
7623 config: Config{
7624 MaxVersion: VersionTLS13,
7625 Bugs: ProtocolBugs{
7626 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7627 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7628 },
7629 },
7630 resumeSession: true,
7631 expectedResumeVersion: VersionTLS13,
7632 })
7633
7634 // Test that the client ignores tickets with no matching key exchange mode.
7635 testCases = append(testCases, testCase{
7636 testType: clientTest,
7637 name: "TLS13-SendBadKEModeSessionTicket-Client",
7638 config: Config{
7639 MaxVersion: VersionTLS13,
7640 Bugs: ProtocolBugs{
7641 SendPSKKeyExchangeModes: []byte{0x1a},
7642 },
7643 },
7644 flags: []string{"-expect-no-session"},
7645 })
7646
7647 // Test that the client ignores tickets with no matching auth mode.
7648 testCases = append(testCases, testCase{
7649 testType: clientTest,
7650 name: "TLS13-SendBadAuthModeSessionTicket-Client",
7651 config: Config{
7652 MaxVersion: VersionTLS13,
7653 Bugs: ProtocolBugs{
7654 SendPSKAuthModes: []byte{0x1a},
7655 },
7656 },
7657 flags: []string{"-expect-no-session"},
7658 })
7659}
7660
David Benjamin82261be2016-07-07 14:32:50 -07007661func addChangeCipherSpecTests() {
7662 // Test missing ChangeCipherSpecs.
7663 testCases = append(testCases, testCase{
7664 name: "SkipChangeCipherSpec-Client",
7665 config: Config{
7666 MaxVersion: VersionTLS12,
7667 Bugs: ProtocolBugs{
7668 SkipChangeCipherSpec: true,
7669 },
7670 },
7671 shouldFail: true,
7672 expectedError: ":UNEXPECTED_RECORD:",
7673 })
7674 testCases = append(testCases, testCase{
7675 testType: serverTest,
7676 name: "SkipChangeCipherSpec-Server",
7677 config: Config{
7678 MaxVersion: VersionTLS12,
7679 Bugs: ProtocolBugs{
7680 SkipChangeCipherSpec: true,
7681 },
7682 },
7683 shouldFail: true,
7684 expectedError: ":UNEXPECTED_RECORD:",
7685 })
7686 testCases = append(testCases, testCase{
7687 testType: serverTest,
7688 name: "SkipChangeCipherSpec-Server-NPN",
7689 config: Config{
7690 MaxVersion: VersionTLS12,
7691 NextProtos: []string{"bar"},
7692 Bugs: ProtocolBugs{
7693 SkipChangeCipherSpec: true,
7694 },
7695 },
7696 flags: []string{
7697 "-advertise-npn", "\x03foo\x03bar\x03baz",
7698 },
7699 shouldFail: true,
7700 expectedError: ":UNEXPECTED_RECORD:",
7701 })
7702
7703 // Test synchronization between the handshake and ChangeCipherSpec.
7704 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7705 // rejected. Test both with and without handshake packing to handle both
7706 // when the partial post-CCS message is in its own record and when it is
7707 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007708 for _, packed := range []bool{false, true} {
7709 var suffix string
7710 if packed {
7711 suffix = "-Packed"
7712 }
7713
7714 testCases = append(testCases, testCase{
7715 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7716 config: Config{
7717 MaxVersion: VersionTLS12,
7718 Bugs: ProtocolBugs{
7719 FragmentAcrossChangeCipherSpec: true,
7720 PackHandshakeFlight: packed,
7721 },
7722 },
7723 shouldFail: true,
7724 expectedError: ":UNEXPECTED_RECORD:",
7725 })
7726 testCases = append(testCases, testCase{
7727 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7728 config: Config{
7729 MaxVersion: VersionTLS12,
7730 },
7731 resumeSession: true,
7732 resumeConfig: &Config{
7733 MaxVersion: VersionTLS12,
7734 Bugs: ProtocolBugs{
7735 FragmentAcrossChangeCipherSpec: true,
7736 PackHandshakeFlight: packed,
7737 },
7738 },
7739 shouldFail: true,
7740 expectedError: ":UNEXPECTED_RECORD:",
7741 })
7742 testCases = append(testCases, testCase{
7743 testType: serverTest,
7744 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7745 config: Config{
7746 MaxVersion: VersionTLS12,
7747 Bugs: ProtocolBugs{
7748 FragmentAcrossChangeCipherSpec: true,
7749 PackHandshakeFlight: packed,
7750 },
7751 },
7752 shouldFail: true,
7753 expectedError: ":UNEXPECTED_RECORD:",
7754 })
7755 testCases = append(testCases, testCase{
7756 testType: serverTest,
7757 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7758 config: Config{
7759 MaxVersion: VersionTLS12,
7760 },
7761 resumeSession: true,
7762 resumeConfig: &Config{
7763 MaxVersion: VersionTLS12,
7764 Bugs: ProtocolBugs{
7765 FragmentAcrossChangeCipherSpec: true,
7766 PackHandshakeFlight: packed,
7767 },
7768 },
7769 shouldFail: true,
7770 expectedError: ":UNEXPECTED_RECORD:",
7771 })
7772 testCases = append(testCases, testCase{
7773 testType: serverTest,
7774 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7775 config: Config{
7776 MaxVersion: VersionTLS12,
7777 NextProtos: []string{"bar"},
7778 Bugs: ProtocolBugs{
7779 FragmentAcrossChangeCipherSpec: true,
7780 PackHandshakeFlight: packed,
7781 },
7782 },
7783 flags: []string{
7784 "-advertise-npn", "\x03foo\x03bar\x03baz",
7785 },
7786 shouldFail: true,
7787 expectedError: ":UNEXPECTED_RECORD:",
7788 })
7789 }
7790
David Benjamin61672812016-07-14 23:10:43 -04007791 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7792 // messages in the handshake queue. Do this by testing the server
7793 // reading the client Finished, reversing the flight so Finished comes
7794 // first.
7795 testCases = append(testCases, testCase{
7796 protocol: dtls,
7797 testType: serverTest,
7798 name: "SendUnencryptedFinished-DTLS",
7799 config: Config{
7800 MaxVersion: VersionTLS12,
7801 Bugs: ProtocolBugs{
7802 SendUnencryptedFinished: true,
7803 ReverseHandshakeFragments: true,
7804 },
7805 },
7806 shouldFail: true,
7807 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7808 })
7809
Steven Valdez143e8b32016-07-11 13:19:03 -04007810 // Test synchronization between encryption changes and the handshake in
7811 // TLS 1.3, where ChangeCipherSpec is implicit.
7812 testCases = append(testCases, testCase{
7813 name: "PartialEncryptedExtensionsWithServerHello",
7814 config: Config{
7815 MaxVersion: VersionTLS13,
7816 Bugs: ProtocolBugs{
7817 PartialEncryptedExtensionsWithServerHello: true,
7818 },
7819 },
7820 shouldFail: true,
7821 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7822 })
7823 testCases = append(testCases, testCase{
7824 testType: serverTest,
7825 name: "PartialClientFinishedWithClientHello",
7826 config: Config{
7827 MaxVersion: VersionTLS13,
7828 Bugs: ProtocolBugs{
7829 PartialClientFinishedWithClientHello: true,
7830 },
7831 },
7832 shouldFail: true,
7833 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7834 })
7835
David Benjamin82261be2016-07-07 14:32:50 -07007836 // Test that early ChangeCipherSpecs are handled correctly.
7837 testCases = append(testCases, testCase{
7838 testType: serverTest,
7839 name: "EarlyChangeCipherSpec-server-1",
7840 config: Config{
7841 MaxVersion: VersionTLS12,
7842 Bugs: ProtocolBugs{
7843 EarlyChangeCipherSpec: 1,
7844 },
7845 },
7846 shouldFail: true,
7847 expectedError: ":UNEXPECTED_RECORD:",
7848 })
7849 testCases = append(testCases, testCase{
7850 testType: serverTest,
7851 name: "EarlyChangeCipherSpec-server-2",
7852 config: Config{
7853 MaxVersion: VersionTLS12,
7854 Bugs: ProtocolBugs{
7855 EarlyChangeCipherSpec: 2,
7856 },
7857 },
7858 shouldFail: true,
7859 expectedError: ":UNEXPECTED_RECORD:",
7860 })
7861 testCases = append(testCases, testCase{
7862 protocol: dtls,
7863 name: "StrayChangeCipherSpec",
7864 config: Config{
7865 // TODO(davidben): Once DTLS 1.3 exists, test
7866 // that stray ChangeCipherSpec messages are
7867 // rejected.
7868 MaxVersion: VersionTLS12,
7869 Bugs: ProtocolBugs{
7870 StrayChangeCipherSpec: true,
7871 },
7872 },
7873 })
7874
7875 // Test that the contents of ChangeCipherSpec are checked.
7876 testCases = append(testCases, testCase{
7877 name: "BadChangeCipherSpec-1",
7878 config: Config{
7879 MaxVersion: VersionTLS12,
7880 Bugs: ProtocolBugs{
7881 BadChangeCipherSpec: []byte{2},
7882 },
7883 },
7884 shouldFail: true,
7885 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7886 })
7887 testCases = append(testCases, testCase{
7888 name: "BadChangeCipherSpec-2",
7889 config: Config{
7890 MaxVersion: VersionTLS12,
7891 Bugs: ProtocolBugs{
7892 BadChangeCipherSpec: []byte{1, 1},
7893 },
7894 },
7895 shouldFail: true,
7896 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7897 })
7898 testCases = append(testCases, testCase{
7899 protocol: dtls,
7900 name: "BadChangeCipherSpec-DTLS-1",
7901 config: Config{
7902 MaxVersion: VersionTLS12,
7903 Bugs: ProtocolBugs{
7904 BadChangeCipherSpec: []byte{2},
7905 },
7906 },
7907 shouldFail: true,
7908 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7909 })
7910 testCases = append(testCases, testCase{
7911 protocol: dtls,
7912 name: "BadChangeCipherSpec-DTLS-2",
7913 config: Config{
7914 MaxVersion: VersionTLS12,
7915 Bugs: ProtocolBugs{
7916 BadChangeCipherSpec: []byte{1, 1},
7917 },
7918 },
7919 shouldFail: true,
7920 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7921 })
7922}
7923
David Benjamincd2c8062016-09-09 11:28:16 -04007924type perMessageTest struct {
7925 messageType uint8
7926 test testCase
7927}
7928
7929// makePerMessageTests returns a series of test templates which cover each
7930// message in the TLS handshake. These may be used with bugs like
7931// WrongMessageType to fully test a per-message bug.
7932func makePerMessageTests() []perMessageTest {
7933 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007934 for _, protocol := range []protocol{tls, dtls} {
7935 var suffix string
7936 if protocol == dtls {
7937 suffix = "-DTLS"
7938 }
7939
David Benjamincd2c8062016-09-09 11:28:16 -04007940 ret = append(ret, perMessageTest{
7941 messageType: typeClientHello,
7942 test: testCase{
7943 protocol: protocol,
7944 testType: serverTest,
7945 name: "ClientHello" + suffix,
7946 config: Config{
7947 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007948 },
7949 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007950 })
7951
7952 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007953 ret = append(ret, perMessageTest{
7954 messageType: typeHelloVerifyRequest,
7955 test: testCase{
7956 protocol: protocol,
7957 name: "HelloVerifyRequest" + suffix,
7958 config: Config{
7959 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007960 },
7961 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007962 })
7963 }
7964
David Benjamincd2c8062016-09-09 11:28:16 -04007965 ret = append(ret, perMessageTest{
7966 messageType: typeServerHello,
7967 test: testCase{
7968 protocol: protocol,
7969 name: "ServerHello" + suffix,
7970 config: Config{
7971 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007972 },
7973 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007974 })
7975
David Benjamincd2c8062016-09-09 11:28:16 -04007976 ret = append(ret, perMessageTest{
7977 messageType: typeCertificate,
7978 test: testCase{
7979 protocol: protocol,
7980 name: "ServerCertificate" + suffix,
7981 config: Config{
7982 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007983 },
7984 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007985 })
7986
David Benjamincd2c8062016-09-09 11:28:16 -04007987 ret = append(ret, perMessageTest{
7988 messageType: typeCertificateStatus,
7989 test: testCase{
7990 protocol: protocol,
7991 name: "CertificateStatus" + suffix,
7992 config: Config{
7993 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007994 },
David Benjamincd2c8062016-09-09 11:28:16 -04007995 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007996 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007997 })
7998
David Benjamincd2c8062016-09-09 11:28:16 -04007999 ret = append(ret, perMessageTest{
8000 messageType: typeServerKeyExchange,
8001 test: testCase{
8002 protocol: protocol,
8003 name: "ServerKeyExchange" + suffix,
8004 config: Config{
8005 MaxVersion: VersionTLS12,
8006 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008007 },
8008 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008009 })
8010
David Benjamincd2c8062016-09-09 11:28:16 -04008011 ret = append(ret, perMessageTest{
8012 messageType: typeCertificateRequest,
8013 test: testCase{
8014 protocol: protocol,
8015 name: "CertificateRequest" + suffix,
8016 config: Config{
8017 MaxVersion: VersionTLS12,
8018 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008019 },
8020 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008021 })
8022
David Benjamincd2c8062016-09-09 11:28:16 -04008023 ret = append(ret, perMessageTest{
8024 messageType: typeServerHelloDone,
8025 test: testCase{
8026 protocol: protocol,
8027 name: "ServerHelloDone" + suffix,
8028 config: Config{
8029 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008030 },
8031 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008032 })
8033
David Benjamincd2c8062016-09-09 11:28:16 -04008034 ret = append(ret, perMessageTest{
8035 messageType: typeCertificate,
8036 test: testCase{
8037 testType: serverTest,
8038 protocol: protocol,
8039 name: "ClientCertificate" + suffix,
8040 config: Config{
8041 Certificates: []Certificate{rsaCertificate},
8042 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008043 },
David Benjamincd2c8062016-09-09 11:28:16 -04008044 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008045 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008046 })
8047
David Benjamincd2c8062016-09-09 11:28:16 -04008048 ret = append(ret, perMessageTest{
8049 messageType: typeCertificateVerify,
8050 test: testCase{
8051 testType: serverTest,
8052 protocol: protocol,
8053 name: "CertificateVerify" + suffix,
8054 config: Config{
8055 Certificates: []Certificate{rsaCertificate},
8056 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008057 },
David Benjamincd2c8062016-09-09 11:28:16 -04008058 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008059 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008060 })
8061
David Benjamincd2c8062016-09-09 11:28:16 -04008062 ret = append(ret, perMessageTest{
8063 messageType: typeClientKeyExchange,
8064 test: testCase{
8065 testType: serverTest,
8066 protocol: protocol,
8067 name: "ClientKeyExchange" + suffix,
8068 config: Config{
8069 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008070 },
8071 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008072 })
8073
8074 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008075 ret = append(ret, perMessageTest{
8076 messageType: typeNextProtocol,
8077 test: testCase{
8078 testType: serverTest,
8079 protocol: protocol,
8080 name: "NextProtocol" + suffix,
8081 config: Config{
8082 MaxVersion: VersionTLS12,
8083 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008084 },
David Benjamincd2c8062016-09-09 11:28:16 -04008085 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008086 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008087 })
8088
David Benjamincd2c8062016-09-09 11:28:16 -04008089 ret = append(ret, perMessageTest{
8090 messageType: typeChannelID,
8091 test: testCase{
8092 testType: serverTest,
8093 protocol: protocol,
8094 name: "ChannelID" + suffix,
8095 config: Config{
8096 MaxVersion: VersionTLS12,
8097 ChannelID: channelIDKey,
8098 },
8099 flags: []string{
8100 "-expect-channel-id",
8101 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008102 },
8103 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008104 })
8105 }
8106
David Benjamincd2c8062016-09-09 11:28:16 -04008107 ret = append(ret, perMessageTest{
8108 messageType: typeFinished,
8109 test: testCase{
8110 testType: serverTest,
8111 protocol: protocol,
8112 name: "ClientFinished" + suffix,
8113 config: Config{
8114 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008115 },
8116 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008117 })
8118
David Benjamincd2c8062016-09-09 11:28:16 -04008119 ret = append(ret, perMessageTest{
8120 messageType: typeNewSessionTicket,
8121 test: testCase{
8122 protocol: protocol,
8123 name: "NewSessionTicket" + suffix,
8124 config: Config{
8125 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008126 },
8127 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008128 })
8129
David Benjamincd2c8062016-09-09 11:28:16 -04008130 ret = append(ret, perMessageTest{
8131 messageType: typeFinished,
8132 test: testCase{
8133 protocol: protocol,
8134 name: "ServerFinished" + suffix,
8135 config: Config{
8136 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008137 },
8138 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008139 })
8140
8141 }
David Benjamincd2c8062016-09-09 11:28:16 -04008142
8143 ret = append(ret, perMessageTest{
8144 messageType: typeClientHello,
8145 test: testCase{
8146 testType: serverTest,
8147 name: "TLS13-ClientHello",
8148 config: Config{
8149 MaxVersion: VersionTLS13,
8150 },
8151 },
8152 })
8153
8154 ret = append(ret, perMessageTest{
8155 messageType: typeServerHello,
8156 test: testCase{
8157 name: "TLS13-ServerHello",
8158 config: Config{
8159 MaxVersion: VersionTLS13,
8160 },
8161 },
8162 })
8163
8164 ret = append(ret, perMessageTest{
8165 messageType: typeEncryptedExtensions,
8166 test: testCase{
8167 name: "TLS13-EncryptedExtensions",
8168 config: Config{
8169 MaxVersion: VersionTLS13,
8170 },
8171 },
8172 })
8173
8174 ret = append(ret, perMessageTest{
8175 messageType: typeCertificateRequest,
8176 test: testCase{
8177 name: "TLS13-CertificateRequest",
8178 config: Config{
8179 MaxVersion: VersionTLS13,
8180 ClientAuth: RequireAnyClientCert,
8181 },
8182 },
8183 })
8184
8185 ret = append(ret, perMessageTest{
8186 messageType: typeCertificate,
8187 test: testCase{
8188 name: "TLS13-ServerCertificate",
8189 config: Config{
8190 MaxVersion: VersionTLS13,
8191 },
8192 },
8193 })
8194
8195 ret = append(ret, perMessageTest{
8196 messageType: typeCertificateVerify,
8197 test: testCase{
8198 name: "TLS13-ServerCertificateVerify",
8199 config: Config{
8200 MaxVersion: VersionTLS13,
8201 },
8202 },
8203 })
8204
8205 ret = append(ret, perMessageTest{
8206 messageType: typeFinished,
8207 test: testCase{
8208 name: "TLS13-ServerFinished",
8209 config: Config{
8210 MaxVersion: VersionTLS13,
8211 },
8212 },
8213 })
8214
8215 ret = append(ret, perMessageTest{
8216 messageType: typeCertificate,
8217 test: testCase{
8218 testType: serverTest,
8219 name: "TLS13-ClientCertificate",
8220 config: Config{
8221 Certificates: []Certificate{rsaCertificate},
8222 MaxVersion: VersionTLS13,
8223 },
8224 flags: []string{"-require-any-client-certificate"},
8225 },
8226 })
8227
8228 ret = append(ret, perMessageTest{
8229 messageType: typeCertificateVerify,
8230 test: testCase{
8231 testType: serverTest,
8232 name: "TLS13-ClientCertificateVerify",
8233 config: Config{
8234 Certificates: []Certificate{rsaCertificate},
8235 MaxVersion: VersionTLS13,
8236 },
8237 flags: []string{"-require-any-client-certificate"},
8238 },
8239 })
8240
8241 ret = append(ret, perMessageTest{
8242 messageType: typeFinished,
8243 test: testCase{
8244 testType: serverTest,
8245 name: "TLS13-ClientFinished",
8246 config: Config{
8247 MaxVersion: VersionTLS13,
8248 },
8249 },
8250 })
8251
8252 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008253}
8254
David Benjamincd2c8062016-09-09 11:28:16 -04008255func addWrongMessageTypeTests() {
8256 for _, t := range makePerMessageTests() {
8257 t.test.name = "WrongMessageType-" + t.test.name
8258 t.test.config.Bugs.SendWrongMessageType = t.messageType
8259 t.test.shouldFail = true
8260 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8261 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008262
David Benjamincd2c8062016-09-09 11:28:16 -04008263 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8264 // In TLS 1.3, a bad ServerHello means the client sends
8265 // an unencrypted alert while the server expects
8266 // encryption, so the alert is not readable by runner.
8267 t.test.expectedLocalError = "local error: bad record MAC"
8268 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008269
David Benjamincd2c8062016-09-09 11:28:16 -04008270 testCases = append(testCases, t.test)
8271 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008272}
8273
David Benjamin639846e2016-09-09 11:41:18 -04008274func addTrailingMessageDataTests() {
8275 for _, t := range makePerMessageTests() {
8276 t.test.name = "TrailingMessageData-" + t.test.name
8277 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8278 t.test.shouldFail = true
8279 t.test.expectedError = ":DECODE_ERROR:"
8280 t.test.expectedLocalError = "remote error: error decoding message"
8281
8282 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8283 // In TLS 1.3, a bad ServerHello means the client sends
8284 // an unencrypted alert while the server expects
8285 // encryption, so the alert is not readable by runner.
8286 t.test.expectedLocalError = "local error: bad record MAC"
8287 }
8288
8289 if t.messageType == typeFinished {
8290 // Bad Finished messages read as the verify data having
8291 // the wrong length.
8292 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8293 t.test.expectedLocalError = "remote error: error decrypting message"
8294 }
8295
8296 testCases = append(testCases, t.test)
8297 }
8298}
8299
Steven Valdez143e8b32016-07-11 13:19:03 -04008300func addTLS13HandshakeTests() {
8301 testCases = append(testCases, testCase{
8302 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008303 name: "NegotiatePSKResumption-TLS13",
8304 config: Config{
8305 MaxVersion: VersionTLS13,
8306 Bugs: ProtocolBugs{
8307 NegotiatePSKResumption: true,
8308 },
8309 },
8310 resumeSession: true,
8311 shouldFail: true,
8312 expectedError: ":UNEXPECTED_EXTENSION:",
8313 })
8314
8315 testCases = append(testCases, testCase{
8316 testType: clientTest,
8317 name: "OmitServerHelloSignatureAlgorithms",
8318 config: Config{
8319 MaxVersion: VersionTLS13,
8320 Bugs: ProtocolBugs{
8321 OmitServerHelloSignatureAlgorithms: true,
8322 },
8323 },
8324 shouldFail: true,
8325 expectedError: ":UNEXPECTED_EXTENSION:",
8326 })
8327
8328 testCases = append(testCases, testCase{
8329 testType: clientTest,
8330 name: "IncludeServerHelloSignatureAlgorithms",
8331 config: Config{
8332 MaxVersion: VersionTLS13,
8333 Bugs: ProtocolBugs{
8334 IncludeServerHelloSignatureAlgorithms: true,
8335 },
8336 },
8337 resumeSession: true,
8338 shouldFail: true,
8339 expectedError: ":UNEXPECTED_EXTENSION:",
8340 })
8341
8342 testCases = append(testCases, testCase{
8343 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008344 name: "MissingKeyShare-Client",
8345 config: Config{
8346 MaxVersion: VersionTLS13,
8347 Bugs: ProtocolBugs{
8348 MissingKeyShare: true,
8349 },
8350 },
8351 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008352 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008353 })
8354
8355 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008356 testType: serverTest,
8357 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008358 config: Config{
8359 MaxVersion: VersionTLS13,
8360 Bugs: ProtocolBugs{
8361 MissingKeyShare: true,
8362 },
8363 },
8364 shouldFail: true,
8365 expectedError: ":MISSING_KEY_SHARE:",
8366 })
8367
8368 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008369 testType: serverTest,
8370 name: "DuplicateKeyShares",
8371 config: Config{
8372 MaxVersion: VersionTLS13,
8373 Bugs: ProtocolBugs{
8374 DuplicateKeyShares: true,
8375 },
8376 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008377 shouldFail: true,
8378 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008379 })
8380
8381 testCases = append(testCases, testCase{
8382 testType: clientTest,
8383 name: "EmptyEncryptedExtensions",
8384 config: Config{
8385 MaxVersion: VersionTLS13,
8386 Bugs: ProtocolBugs{
8387 EmptyEncryptedExtensions: true,
8388 },
8389 },
8390 shouldFail: true,
8391 expectedLocalError: "remote error: error decoding message",
8392 })
8393
8394 testCases = append(testCases, testCase{
8395 testType: clientTest,
8396 name: "EncryptedExtensionsWithKeyShare",
8397 config: Config{
8398 MaxVersion: VersionTLS13,
8399 Bugs: ProtocolBugs{
8400 EncryptedExtensionsWithKeyShare: true,
8401 },
8402 },
8403 shouldFail: true,
8404 expectedLocalError: "remote error: unsupported extension",
8405 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008406
8407 testCases = append(testCases, testCase{
8408 testType: serverTest,
8409 name: "SendHelloRetryRequest",
8410 config: Config{
8411 MaxVersion: VersionTLS13,
8412 // Require a HelloRetryRequest for every curve.
8413 DefaultCurves: []CurveID{},
8414 },
8415 expectedCurveID: CurveX25519,
8416 })
8417
8418 testCases = append(testCases, testCase{
8419 testType: serverTest,
8420 name: "SendHelloRetryRequest-2",
8421 config: Config{
8422 MaxVersion: VersionTLS13,
8423 DefaultCurves: []CurveID{CurveP384},
8424 },
8425 // Although the ClientHello did not predict our preferred curve,
8426 // we always select it whether it is predicted or not.
8427 expectedCurveID: CurveX25519,
8428 })
8429
8430 testCases = append(testCases, testCase{
8431 name: "UnknownCurve-HelloRetryRequest",
8432 config: Config{
8433 MaxVersion: VersionTLS13,
8434 // P-384 requires HelloRetryRequest in BoringSSL.
8435 CurvePreferences: []CurveID{CurveP384},
8436 Bugs: ProtocolBugs{
8437 SendHelloRetryRequestCurve: bogusCurve,
8438 },
8439 },
8440 shouldFail: true,
8441 expectedError: ":WRONG_CURVE:",
8442 })
8443
8444 testCases = append(testCases, testCase{
8445 name: "DisabledCurve-HelloRetryRequest",
8446 config: Config{
8447 MaxVersion: VersionTLS13,
8448 CurvePreferences: []CurveID{CurveP256},
8449 Bugs: ProtocolBugs{
8450 IgnorePeerCurvePreferences: true,
8451 },
8452 },
8453 flags: []string{"-p384-only"},
8454 shouldFail: true,
8455 expectedError: ":WRONG_CURVE:",
8456 })
8457
8458 testCases = append(testCases, testCase{
8459 name: "UnnecessaryHelloRetryRequest",
8460 config: Config{
8461 MaxVersion: VersionTLS13,
8462 Bugs: ProtocolBugs{
8463 UnnecessaryHelloRetryRequest: true,
8464 },
8465 },
8466 shouldFail: true,
8467 expectedError: ":WRONG_CURVE:",
8468 })
8469
8470 testCases = append(testCases, testCase{
8471 name: "SecondHelloRetryRequest",
8472 config: Config{
8473 MaxVersion: VersionTLS13,
8474 // P-384 requires HelloRetryRequest in BoringSSL.
8475 CurvePreferences: []CurveID{CurveP384},
8476 Bugs: ProtocolBugs{
8477 SecondHelloRetryRequest: true,
8478 },
8479 },
8480 shouldFail: true,
8481 expectedError: ":UNEXPECTED_MESSAGE:",
8482 })
8483
8484 testCases = append(testCases, testCase{
8485 testType: serverTest,
8486 name: "SecondClientHelloMissingKeyShare",
8487 config: Config{
8488 MaxVersion: VersionTLS13,
8489 DefaultCurves: []CurveID{},
8490 Bugs: ProtocolBugs{
8491 SecondClientHelloMissingKeyShare: true,
8492 },
8493 },
8494 shouldFail: true,
8495 expectedError: ":MISSING_KEY_SHARE:",
8496 })
8497
8498 testCases = append(testCases, testCase{
8499 testType: serverTest,
8500 name: "SecondClientHelloWrongCurve",
8501 config: Config{
8502 MaxVersion: VersionTLS13,
8503 DefaultCurves: []CurveID{},
8504 Bugs: ProtocolBugs{
8505 MisinterpretHelloRetryRequestCurve: CurveP521,
8506 },
8507 },
8508 shouldFail: true,
8509 expectedError: ":WRONG_CURVE:",
8510 })
8511
8512 testCases = append(testCases, testCase{
8513 name: "HelloRetryRequestVersionMismatch",
8514 config: Config{
8515 MaxVersion: VersionTLS13,
8516 // P-384 requires HelloRetryRequest in BoringSSL.
8517 CurvePreferences: []CurveID{CurveP384},
8518 Bugs: ProtocolBugs{
8519 SendServerHelloVersion: 0x0305,
8520 },
8521 },
8522 shouldFail: true,
8523 expectedError: ":WRONG_VERSION_NUMBER:",
8524 })
8525
8526 testCases = append(testCases, testCase{
8527 name: "HelloRetryRequestCurveMismatch",
8528 config: Config{
8529 MaxVersion: VersionTLS13,
8530 // P-384 requires HelloRetryRequest in BoringSSL.
8531 CurvePreferences: []CurveID{CurveP384},
8532 Bugs: ProtocolBugs{
8533 // Send P-384 (correct) in the HelloRetryRequest.
8534 SendHelloRetryRequestCurve: CurveP384,
8535 // But send P-256 in the ServerHello.
8536 SendCurve: CurveP256,
8537 },
8538 },
8539 shouldFail: true,
8540 expectedError: ":WRONG_CURVE:",
8541 })
8542
8543 // Test the server selecting a curve that requires a HelloRetryRequest
8544 // without sending it.
8545 testCases = append(testCases, testCase{
8546 name: "SkipHelloRetryRequest",
8547 config: Config{
8548 MaxVersion: VersionTLS13,
8549 // P-384 requires HelloRetryRequest in BoringSSL.
8550 CurvePreferences: []CurveID{CurveP384},
8551 Bugs: ProtocolBugs{
8552 SkipHelloRetryRequest: true,
8553 },
8554 },
8555 shouldFail: true,
8556 expectedError: ":WRONG_CURVE:",
8557 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008558
8559 testCases = append(testCases, testCase{
8560 name: "TLS13-RequestContextInHandshake",
8561 config: Config{
8562 MaxVersion: VersionTLS13,
8563 MinVersion: VersionTLS13,
8564 ClientAuth: RequireAnyClientCert,
8565 Bugs: ProtocolBugs{
8566 SendRequestContext: []byte("request context"),
8567 },
8568 },
8569 flags: []string{
8570 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8571 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8572 },
8573 shouldFail: true,
8574 expectedError: ":DECODE_ERROR:",
8575 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008576
8577 testCases = append(testCases, testCase{
8578 testType: serverTest,
8579 name: "TLS13-TrailingKeyShareData",
8580 config: Config{
8581 MaxVersion: VersionTLS13,
8582 Bugs: ProtocolBugs{
8583 TrailingKeyShareData: true,
8584 },
8585 },
8586 shouldFail: true,
8587 expectedError: ":DECODE_ERROR:",
8588 })
David Benjamin7f78df42016-10-05 22:33:19 -04008589
8590 testCases = append(testCases, testCase{
8591 name: "TLS13-AlwaysSelectPSKIdentity",
8592 config: Config{
8593 MaxVersion: VersionTLS13,
8594 Bugs: ProtocolBugs{
8595 AlwaysSelectPSKIdentity: true,
8596 },
8597 },
8598 shouldFail: true,
8599 expectedError: ":UNEXPECTED_EXTENSION:",
8600 })
8601
8602 testCases = append(testCases, testCase{
8603 name: "TLS13-InvalidPSKIdentity",
8604 config: Config{
8605 MaxVersion: VersionTLS13,
8606 Bugs: ProtocolBugs{
8607 SelectPSKIdentityOnResume: 1,
8608 },
8609 },
8610 resumeSession: true,
8611 shouldFail: true,
8612 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
8613 })
David Benjamin1286bee2016-10-07 15:25:06 -04008614
8615 // Test that unknown NewSessionTicket extensions are tolerated.
8616 testCases = append(testCases, testCase{
8617 name: "TLS13-CustomTicketExtension",
8618 config: Config{
8619 MaxVersion: VersionTLS13,
8620 Bugs: ProtocolBugs{
8621 CustomTicketExtension: "1234",
8622 },
8623 },
8624 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008625}
8626
David Benjaminf3fbade2016-09-19 13:08:16 -04008627func addPeekTests() {
8628 // Test SSL_peek works, including on empty records.
8629 testCases = append(testCases, testCase{
8630 name: "Peek-Basic",
8631 sendEmptyRecords: 1,
8632 flags: []string{"-peek-then-read"},
8633 })
8634
8635 // Test SSL_peek can drive the initial handshake.
8636 testCases = append(testCases, testCase{
8637 name: "Peek-ImplicitHandshake",
8638 flags: []string{
8639 "-peek-then-read",
8640 "-implicit-handshake",
8641 },
8642 })
8643
8644 // Test SSL_peek can discover and drive a renegotiation.
8645 testCases = append(testCases, testCase{
8646 name: "Peek-Renegotiate",
8647 config: Config{
8648 MaxVersion: VersionTLS12,
8649 },
8650 renegotiate: 1,
8651 flags: []string{
8652 "-peek-then-read",
8653 "-renegotiate-freely",
8654 "-expect-total-renegotiations", "1",
8655 },
8656 })
8657
8658 // Test SSL_peek can discover a close_notify.
8659 testCases = append(testCases, testCase{
8660 name: "Peek-Shutdown",
8661 config: Config{
8662 Bugs: ProtocolBugs{
8663 ExpectCloseNotify: true,
8664 },
8665 },
8666 flags: []string{
8667 "-peek-then-read",
8668 "-check-close-notify",
8669 },
8670 })
8671
8672 // Test SSL_peek can discover an alert.
8673 testCases = append(testCases, testCase{
8674 name: "Peek-Alert",
8675 config: Config{
8676 Bugs: ProtocolBugs{
8677 SendSpuriousAlert: alertRecordOverflow,
8678 },
8679 },
8680 flags: []string{"-peek-then-read"},
8681 shouldFail: true,
8682 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8683 })
8684
8685 // Test SSL_peek can handle KeyUpdate.
8686 testCases = append(testCases, testCase{
8687 name: "Peek-KeyUpdate",
8688 config: Config{
8689 MaxVersion: VersionTLS13,
8690 Bugs: ProtocolBugs{
8691 SendKeyUpdateBeforeEveryAppDataRecord: true,
8692 },
8693 },
8694 flags: []string{"-peek-then-read"},
8695 })
8696}
8697
Adam Langley7c803a62015-06-15 15:35:05 -07008698func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008699 defer wg.Done()
8700
8701 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008702 var err error
8703
8704 if *mallocTest < 0 {
8705 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008706 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008707 } else {
8708 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8709 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008710 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008711 if err != nil {
8712 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8713 }
8714 break
8715 }
8716 }
8717 }
Adam Langley95c29f32014-06-20 12:00:00 -07008718 statusChan <- statusMsg{test: test, err: err}
8719 }
8720}
8721
8722type statusMsg struct {
8723 test *testCase
8724 started bool
8725 err error
8726}
8727
David Benjamin5f237bc2015-02-11 17:14:15 -05008728func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008729 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008730
David Benjamin5f237bc2015-02-11 17:14:15 -05008731 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008732 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008733 if !*pipe {
8734 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008735 var erase string
8736 for i := 0; i < lineLen; i++ {
8737 erase += "\b \b"
8738 }
8739 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008740 }
8741
Adam Langley95c29f32014-06-20 12:00:00 -07008742 if msg.started {
8743 started++
8744 } else {
8745 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008746
8747 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008748 if msg.err == errUnimplemented {
8749 if *pipe {
8750 // Print each test instead of a status line.
8751 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8752 }
8753 unimplemented++
8754 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8755 } else {
8756 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8757 failed++
8758 testOutput.addResult(msg.test.name, "FAIL")
8759 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008760 } else {
8761 if *pipe {
8762 // Print each test instead of a status line.
8763 fmt.Printf("PASSED (%s)\n", msg.test.name)
8764 }
8765 testOutput.addResult(msg.test.name, "PASS")
8766 }
Adam Langley95c29f32014-06-20 12:00:00 -07008767 }
8768
David Benjamin5f237bc2015-02-11 17:14:15 -05008769 if !*pipe {
8770 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008771 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008772 lineLen = len(line)
8773 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008774 }
Adam Langley95c29f32014-06-20 12:00:00 -07008775 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008776
8777 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008778}
8779
8780func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008781 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008782 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008783 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008784
Adam Langley7c803a62015-06-15 15:35:05 -07008785 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008786 addCipherSuiteTests()
8787 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008788 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008789 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008790 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008791 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008792 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008793 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008794 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008795 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008796 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008797 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008798 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008799 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008800 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008801 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008802 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008803 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008804 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008805 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008806 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008807 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04008808 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008809 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008810 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008811 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008812 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008813 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008814 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008815 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008816
8817 var wg sync.WaitGroup
8818
Adam Langley7c803a62015-06-15 15:35:05 -07008819 statusChan := make(chan statusMsg, *numWorkers)
8820 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008821 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008822
EKRf71d7ed2016-08-06 13:25:12 -07008823 if len(*shimConfigFile) != 0 {
8824 encoded, err := ioutil.ReadFile(*shimConfigFile)
8825 if err != nil {
8826 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8827 os.Exit(1)
8828 }
8829
8830 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8831 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8832 os.Exit(1)
8833 }
8834 }
8835
David Benjamin025b3d32014-07-01 19:53:04 -04008836 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008837
Adam Langley7c803a62015-06-15 15:35:05 -07008838 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008839 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008840 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008841 }
8842
David Benjamin270f0a72016-03-17 14:41:36 -04008843 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008844 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008845 matched := true
8846 if len(*testToRun) != 0 {
8847 var err error
8848 matched, err = filepath.Match(*testToRun, testCases[i].name)
8849 if err != nil {
8850 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8851 os.Exit(1)
8852 }
8853 }
8854
EKRf71d7ed2016-08-06 13:25:12 -07008855 if !*includeDisabled {
8856 for pattern := range shimConfig.DisabledTests {
8857 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8858 if err != nil {
8859 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8860 os.Exit(1)
8861 }
8862
8863 if isDisabled {
8864 matched = false
8865 break
8866 }
8867 }
8868 }
8869
David Benjamin17e12922016-07-28 18:04:43 -04008870 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008871 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008872 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008873 }
8874 }
David Benjamin17e12922016-07-28 18:04:43 -04008875
David Benjamin270f0a72016-03-17 14:41:36 -04008876 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008877 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008878 os.Exit(1)
8879 }
Adam Langley95c29f32014-06-20 12:00:00 -07008880
8881 close(testChan)
8882 wg.Wait()
8883 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008884 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008885
8886 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008887
8888 if *jsonOutput != "" {
8889 if err := testOutput.writeTo(*jsonOutput); err != nil {
8890 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8891 }
8892 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008893
EKR842ae6c2016-07-27 09:22:05 +02008894 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8895 os.Exit(1)
8896 }
8897
8898 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008899 os.Exit(1)
8900 }
Adam Langley95c29f32014-06-20 12:00:00 -07008901}