blob: c33ca6a3599305bb2bcfd9c6ed43a4b3995d9ce6 [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 Benjamin9867b7d2016-03-01 23:25:48 -0500369func writeTranscript(test *testCase, isResume bool, data []byte) {
370 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
390 name := test.name
391 if isResume {
392 name += "-Resume"
393 } else {
394 name += "-Normal"
395 }
396
397 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
398 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
399 }
400}
401
David Benjamin3ed59772016-03-08 12:50:21 -0500402// A timeoutConn implements an idle timeout on each Read and Write operation.
403type timeoutConn struct {
404 net.Conn
405 timeout time.Duration
406}
407
408func (t *timeoutConn) Read(b []byte) (int, error) {
409 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
410 return 0, err
411 }
412 return t.Conn.Read(b)
413}
414
415func (t *timeoutConn) Write(b []byte) (int, error) {
416 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
417 return 0, err
418 }
419 return t.Conn.Write(b)
420}
421
David Benjamin8e6db492015-07-25 18:29:23 -0400422func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamine54af062016-08-08 19:21:18 -0400423 if !test.noSessionCache {
424 if config.ClientSessionCache == nil {
425 config.ClientSessionCache = NewLRUClientSessionCache(1)
426 }
427 if config.ServerSessionCache == nil {
428 config.ServerSessionCache = NewLRUServerSessionCache(1)
429 }
430 }
431 if test.testType == clientTest {
432 if len(config.Certificates) == 0 {
433 config.Certificates = []Certificate{rsaCertificate}
434 }
435 } else {
436 // Supply a ServerName to ensure a constant session cache key,
437 // rather than falling back to net.Conn.RemoteAddr.
438 if len(config.ServerName) == 0 {
439 config.ServerName = "test"
440 }
441 }
442 if *fuzzer {
443 config.Bugs.NullAllCiphers = true
444 }
445 if *deterministic {
446 config.Rand = &deterministicRand{}
447 }
448
David Benjamin01784b42016-06-07 18:00:52 -0400449 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500450
David Benjamin6fd297b2014-08-11 18:43:38 -0400451 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500452 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
453 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500454 }
455
David Benjamin9867b7d2016-03-01 23:25:48 -0500456 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500457 local, peer := "client", "server"
458 if test.testType == clientTest {
459 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500460 }
David Benjaminebda9b32015-11-02 15:33:18 -0500461 connDebug := &recordingConn{
462 Conn: conn,
463 isDatagram: test.protocol == dtls,
464 local: local,
465 peer: peer,
466 }
467 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 if *flagDebug {
469 defer connDebug.WriteTo(os.Stdout)
470 }
471 if len(*transcriptDir) != 0 {
472 defer func() {
473 writeTranscript(test, isResume, connDebug.Transcript())
474 }()
475 }
David Benjaminebda9b32015-11-02 15:33:18 -0500476
477 if config.Bugs.PacketAdaptor != nil {
478 config.Bugs.PacketAdaptor.debug = connDebug
479 }
480 }
481
482 if test.replayWrites {
483 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400484 }
485
David Benjamin3ed59772016-03-08 12:50:21 -0500486 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500487 if test.damageFirstWrite {
488 connDamage = newDamageAdaptor(conn)
489 conn = connDamage
490 }
491
David Benjamin6fd297b2014-08-11 18:43:38 -0400492 if test.sendPrefix != "" {
493 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
494 return err
495 }
David Benjamin98e882e2014-08-08 13:24:34 -0400496 }
497
David Benjamin1d5c83e2014-07-22 19:20:02 -0400498 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400499 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400500 if test.protocol == dtls {
501 tlsConn = DTLSServer(conn, config)
502 } else {
503 tlsConn = Server(conn, config)
504 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400505 } else {
506 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400507 if test.protocol == dtls {
508 tlsConn = DTLSClient(conn, config)
509 } else {
510 tlsConn = Client(conn, config)
511 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400512 }
David Benjamin30789da2015-08-29 22:56:45 -0400513 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400514
Adam Langley95c29f32014-06-20 12:00:00 -0700515 if err := tlsConn.Handshake(); err != nil {
516 return err
517 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700518
David Benjamin01fe8202014-09-24 15:21:44 -0400519 // TODO(davidben): move all per-connection expectations into a dedicated
520 // expectations struct that can be specified separately for the two
521 // legs.
522 expectedVersion := test.expectedVersion
523 if isResume && test.expectedResumeVersion != 0 {
524 expectedVersion = test.expectedResumeVersion
525 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700526 connState := tlsConn.ConnectionState()
527 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400528 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400529 }
530
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700531 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400532 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
533 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700534 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
535 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
536 }
David Benjamin90da8c82015-04-20 14:57:57 -0400537
David Benjamina08e49d2014-08-24 01:46:07 -0400538 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700539 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400540 if channelID == nil {
541 return fmt.Errorf("no channel ID negotiated")
542 }
543 if channelID.Curve != channelIDKey.Curve ||
544 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
545 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
546 return fmt.Errorf("incorrect channel ID")
547 }
548 }
549
David Benjaminae2888f2014-09-06 12:58:58 -0400550 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700551 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400552 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
553 }
554 }
555
David Benjaminc7ce9772015-10-09 19:32:41 -0400556 if test.expectNoNextProto {
557 if actual := connState.NegotiatedProtocol; actual != "" {
558 return fmt.Errorf("got unexpected next proto %s", actual)
559 }
560 }
561
David Benjaminfc7b0862014-09-06 13:21:53 -0400562 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700563 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400564 return fmt.Errorf("next proto type mismatch")
565 }
566 }
567
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700568 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500569 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
570 }
571
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100572 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300573 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100574 }
575
Paul Lietar4fac72e2015-09-09 13:44:55 +0100576 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
577 return fmt.Errorf("SCT list mismatch")
578 }
579
Nick Harper60edffd2016-06-21 15:19:24 -0700580 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
581 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400582 }
583
Steven Valdez5440fe02016-07-18 12:40:30 -0400584 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
585 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
586 }
587
David Benjaminc565ebb2015-04-03 04:06:36 -0400588 if test.exportKeyingMaterial > 0 {
589 actual := make([]byte, test.exportKeyingMaterial)
590 if _, err := io.ReadFull(tlsConn, actual); err != nil {
591 return err
592 }
593 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
594 if err != nil {
595 return err
596 }
597 if !bytes.Equal(actual, expected) {
598 return fmt.Errorf("keying material mismatch")
599 }
600 }
601
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700602 if test.testTLSUnique {
603 var peersValue [12]byte
604 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
605 return err
606 }
607 expected := tlsConn.ConnectionState().TLSUnique
608 if !bytes.Equal(peersValue[:], expected) {
609 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
610 }
611 }
612
David Benjamine58c4f52014-08-24 03:47:07 -0400613 if test.shimWritesFirst {
614 var buf [5]byte
615 _, err := io.ReadFull(tlsConn, buf[:])
616 if err != nil {
617 return err
618 }
619 if string(buf[:]) != "hello" {
620 return fmt.Errorf("bad initial message")
621 }
622 }
623
Steven Valdez32635b82016-08-16 11:25:03 -0400624 for i := 0; i < test.sendKeyUpdates; i++ {
625 tlsConn.SendKeyUpdate()
626 }
627
David Benjamina8ebe222015-06-06 03:04:39 -0400628 for i := 0; i < test.sendEmptyRecords; i++ {
629 tlsConn.Write(nil)
630 }
631
David Benjamin24f346d2015-06-06 03:28:08 -0400632 for i := 0; i < test.sendWarningAlerts; i++ {
633 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
634 }
635
David Benjamin47921102016-07-28 11:29:18 -0400636 if test.sendHalfHelloRequest {
637 tlsConn.SendHalfHelloRequest()
638 }
639
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400640 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700641 if test.renegotiateCiphers != nil {
642 config.CipherSuites = test.renegotiateCiphers
643 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400644 for i := 0; i < test.renegotiate; i++ {
645 if err := tlsConn.Renegotiate(); err != nil {
646 return err
647 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700648 }
649 } else if test.renegotiateCiphers != nil {
650 panic("renegotiateCiphers without renegotiate")
651 }
652
David Benjamin5fa3eba2015-01-22 16:35:40 -0500653 if test.damageFirstWrite {
654 connDamage.setDamage(true)
655 tlsConn.Write([]byte("DAMAGED WRITE"))
656 connDamage.setDamage(false)
657 }
658
David Benjamin8e6db492015-07-25 18:29:23 -0400659 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700660 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400661 if test.protocol == dtls {
662 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
663 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700664 // Read until EOF.
665 _, err := io.Copy(ioutil.Discard, tlsConn)
666 return err
667 }
David Benjamin4417d052015-04-05 04:17:25 -0400668 if messageLen == 0 {
669 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700670 }
Adam Langley95c29f32014-06-20 12:00:00 -0700671
David Benjamin8e6db492015-07-25 18:29:23 -0400672 messageCount := test.messageCount
673 if messageCount == 0 {
674 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400675 }
676
David Benjamin8e6db492015-07-25 18:29:23 -0400677 for j := 0; j < messageCount; j++ {
678 testMessage := make([]byte, messageLen)
679 for i := range testMessage {
680 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400681 }
David Benjamin8e6db492015-07-25 18:29:23 -0400682 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700683
Steven Valdez32635b82016-08-16 11:25:03 -0400684 for i := 0; i < test.sendKeyUpdates; i++ {
685 tlsConn.SendKeyUpdate()
686 }
687
David Benjamin8e6db492015-07-25 18:29:23 -0400688 for i := 0; i < test.sendEmptyRecords; i++ {
689 tlsConn.Write(nil)
690 }
691
692 for i := 0; i < test.sendWarningAlerts; i++ {
693 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
694 }
695
David Benjamin4f75aaf2015-09-01 16:53:10 -0400696 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400697 // The shim will not respond.
698 continue
699 }
700
David Benjamin8e6db492015-07-25 18:29:23 -0400701 buf := make([]byte, len(testMessage))
702 if test.protocol == dtls {
703 bufTmp := make([]byte, len(buf)+1)
704 n, err := tlsConn.Read(bufTmp)
705 if err != nil {
706 return err
707 }
708 if n != len(buf) {
709 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
710 }
711 copy(buf, bufTmp)
712 } else {
713 _, err := io.ReadFull(tlsConn, buf)
714 if err != nil {
715 return err
716 }
717 }
718
719 for i, v := range buf {
720 if v != testMessage[i]^0xff {
721 return fmt.Errorf("bad reply contents at byte %d", i)
722 }
Adam Langley95c29f32014-06-20 12:00:00 -0700723 }
724 }
725
726 return nil
727}
728
David Benjamin325b5c32014-07-01 19:40:31 -0400729func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
730 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700731 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400732 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700733 }
David Benjamin325b5c32014-07-01 19:40:31 -0400734 valgrindArgs = append(valgrindArgs, path)
735 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700736
David Benjamin325b5c32014-07-01 19:40:31 -0400737 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700738}
739
David Benjamin325b5c32014-07-01 19:40:31 -0400740func gdbOf(path string, args ...string) *exec.Cmd {
741 xtermArgs := []string{"-e", "gdb", "--args"}
742 xtermArgs = append(xtermArgs, path)
743 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700744
David Benjamin325b5c32014-07-01 19:40:31 -0400745 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700746}
747
David Benjamind16bf342015-12-18 00:53:12 -0500748func lldbOf(path string, args ...string) *exec.Cmd {
749 xtermArgs := []string{"-e", "lldb", "--"}
750 xtermArgs = append(xtermArgs, path)
751 xtermArgs = append(xtermArgs, args...)
752
753 return exec.Command("xterm", xtermArgs...)
754}
755
EKR842ae6c2016-07-27 09:22:05 +0200756var (
757 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
758 errUnimplemented = errors.New("child process does not implement needed flags")
759)
Adam Langley69a01602014-11-17 17:26:55 -0800760
David Benjamin87c8a642015-02-21 01:54:29 -0500761// accept accepts a connection from listener, unless waitChan signals a process
762// exit first.
763func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
764 type connOrError struct {
765 conn net.Conn
766 err error
767 }
768 connChan := make(chan connOrError, 1)
769 go func() {
770 conn, err := listener.Accept()
771 connChan <- connOrError{conn, err}
772 close(connChan)
773 }()
774 select {
775 case result := <-connChan:
776 return result.conn, result.err
777 case childErr := <-waitChan:
778 waitChan <- childErr
779 return nil, fmt.Errorf("child exited early: %s", childErr)
780 }
781}
782
EKRf71d7ed2016-08-06 13:25:12 -0700783func translateExpectedError(errorStr string) string {
784 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
785 return translated
786 }
787
788 if *looseErrors {
789 return ""
790 }
791
792 return errorStr
793}
794
Adam Langley7c803a62015-06-15 15:35:05 -0700795func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700796 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
797 panic("Error expected without shouldFail in " + test.name)
798 }
799
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700800 if test.expectResumeRejected && !test.resumeSession {
801 panic("expectResumeRejected without resumeSession in " + test.name)
802 }
803
David Benjamin87c8a642015-02-21 01:54:29 -0500804 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
805 if err != nil {
806 panic(err)
807 }
808 defer func() {
809 if listener != nil {
810 listener.Close()
811 }
812 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700813
David Benjamin87c8a642015-02-21 01:54:29 -0500814 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400815 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400816 flags = append(flags, "-server")
817
David Benjamin025b3d32014-07-01 19:53:04 -0400818 flags = append(flags, "-key-file")
819 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700820 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400821 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700822 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400823 }
824
825 flags = append(flags, "-cert-file")
826 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700827 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400828 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700829 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400830 }
831 }
David Benjamin5a593af2014-08-11 19:51:50 -0400832
David Benjamin6fd297b2014-08-11 18:43:38 -0400833 if test.protocol == dtls {
834 flags = append(flags, "-dtls")
835 }
836
David Benjamin46662482016-08-17 00:51:00 -0400837 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400838 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400839 resumeCount++
840 if test.resumeRenewedSession {
841 resumeCount++
842 }
843 }
844
845 if resumeCount > 0 {
846 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400847 }
848
David Benjamine58c4f52014-08-24 03:47:07 -0400849 if test.shimWritesFirst {
850 flags = append(flags, "-shim-writes-first")
851 }
852
David Benjamin30789da2015-08-29 22:56:45 -0400853 if test.shimShutsDown {
854 flags = append(flags, "-shim-shuts-down")
855 }
856
David Benjaminc565ebb2015-04-03 04:06:36 -0400857 if test.exportKeyingMaterial > 0 {
858 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
859 flags = append(flags, "-export-label", test.exportLabel)
860 flags = append(flags, "-export-context", test.exportContext)
861 if test.useExportContext {
862 flags = append(flags, "-use-export-context")
863 }
864 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700865 if test.expectResumeRejected {
866 flags = append(flags, "-expect-session-miss")
867 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400868
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700869 if test.testTLSUnique {
870 flags = append(flags, "-tls-unique")
871 }
872
David Benjamin025b3d32014-07-01 19:53:04 -0400873 flags = append(flags, test.flags...)
874
875 var shim *exec.Cmd
876 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700877 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700878 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700879 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500880 } else if *useLLDB {
881 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400882 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700883 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400884 }
David Benjamin025b3d32014-07-01 19:53:04 -0400885 shim.Stdin = os.Stdin
886 var stdoutBuf, stderrBuf bytes.Buffer
887 shim.Stdout = &stdoutBuf
888 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800889 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500890 shim.Env = os.Environ()
891 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800892 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400893 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800894 }
895 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
896 }
David Benjamin025b3d32014-07-01 19:53:04 -0400897
898 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700899 panic(err)
900 }
David Benjamin87c8a642015-02-21 01:54:29 -0500901 waitChan := make(chan error, 1)
902 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700903
904 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700905
David Benjamin87c8a642015-02-21 01:54:29 -0500906 conn, err := acceptOrWait(listener, waitChan)
907 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400908 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500909 conn.Close()
910 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500911
David Benjamin46662482016-08-17 00:51:00 -0400912 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400913 var resumeConfig Config
914 if test.resumeConfig != nil {
915 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400916 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500917 resumeConfig.SessionTicketKey = config.SessionTicketKey
918 resumeConfig.ClientSessionCache = config.ClientSessionCache
919 resumeConfig.ServerSessionCache = config.ServerSessionCache
920 }
David Benjamin2e045a92016-06-08 13:09:56 -0400921 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400922 } else {
923 resumeConfig = config
924 }
David Benjamin87c8a642015-02-21 01:54:29 -0500925 var connResume net.Conn
926 connResume, err = acceptOrWait(listener, waitChan)
927 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400928 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500929 connResume.Close()
930 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400931 }
932
David Benjamin87c8a642015-02-21 01:54:29 -0500933 // Close the listener now. This is to avoid hangs should the shim try to
934 // open more connections than expected.
935 listener.Close()
936 listener = nil
937
938 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800939 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200940 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
941 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800942 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200943 case 89:
944 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800945 }
946 }
Adam Langley95c29f32014-06-20 12:00:00 -0700947
David Benjamin9bea3492016-03-02 10:59:16 -0500948 // Account for Windows line endings.
949 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
950 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500951
952 // Separate the errors from the shim and those from tools like
953 // AddressSanitizer.
954 var extraStderr string
955 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
956 stderr = stderrParts[0]
957 extraStderr = stderrParts[1]
958 }
959
Adam Langley95c29f32014-06-20 12:00:00 -0700960 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700961 expectedError := translateExpectedError(test.expectedError)
962 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200963
Adam Langleyac61fa32014-06-23 12:03:11 -0700964 localError := "none"
965 if err != nil {
966 localError = err.Error()
967 }
968 if len(test.expectedLocalError) != 0 {
969 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
970 }
Adam Langley95c29f32014-06-20 12:00:00 -0700971
972 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700973 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700974 if childErr != nil {
975 childError = childErr.Error()
976 }
977
978 var msg string
979 switch {
980 case failed && !test.shouldFail:
981 msg = "unexpected failure"
982 case !failed && test.shouldFail:
983 msg = "unexpected success"
984 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700985 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700986 default:
987 panic("internal error")
988 }
989
David Benjaminc565ebb2015-04-03 04:06:36 -0400990 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700991 }
992
David Benjaminff3a1492016-03-02 10:12:06 -0500993 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
994 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700995 }
996
997 return nil
998}
999
1000var tlsVersions = []struct {
1001 name string
1002 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001003 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001004 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001005}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001006 {"SSL3", VersionSSL30, "-no-ssl3", false},
1007 {"TLS1", VersionTLS10, "-no-tls1", true},
1008 {"TLS11", VersionTLS11, "-no-tls11", false},
1009 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001010 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001011}
1012
1013var testCipherSuites = []struct {
1014 name string
1015 id uint16
1016}{
1017 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001018 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001019 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001020 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001021 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001022 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001023 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001024 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1025 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001026 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001027 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1028 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001029 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001030 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1031 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001032 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1033 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001034 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001035 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001036 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001037 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001038 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001039 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001040 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001041 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001042 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001043 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001044 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001045 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001046 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001047 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001048 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1049 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1050 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1051 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001052 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1053 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001054 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1055 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001056 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001057 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1058 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001059 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001060 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001061 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001062 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001063}
1064
David Benjamin8b8c0062014-11-23 02:47:52 -05001065func hasComponent(suiteName, component string) bool {
1066 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1067}
1068
David Benjaminf7768e42014-08-31 02:06:47 -04001069func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001070 return hasComponent(suiteName, "GCM") ||
1071 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001072 hasComponent(suiteName, "SHA384") ||
1073 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001074}
1075
Nick Harper1fd39d82016-06-14 18:14:35 -07001076func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001077 // Only AEADs.
1078 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1079 return false
1080 }
1081 // No old CHACHA20_POLY1305.
1082 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1083 return false
1084 }
1085 // Must have ECDHE.
1086 // TODO(davidben,svaldez): Add pure PSK support.
1087 if !hasComponent(suiteName, "ECDHE") {
1088 return false
1089 }
1090 // TODO(davidben,svaldez): Add PSK support.
1091 if hasComponent(suiteName, "PSK") {
1092 return false
1093 }
1094 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001095}
1096
David Benjamin8b8c0062014-11-23 02:47:52 -05001097func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001098 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001099}
1100
Adam Langleya7997f12015-05-14 17:38:50 -07001101func bigFromHex(hex string) *big.Int {
1102 ret, ok := new(big.Int).SetString(hex, 16)
1103 if !ok {
1104 panic("failed to parse hex number 0x" + hex)
1105 }
1106 return ret
1107}
1108
Adam Langley7c803a62015-06-15 15:35:05 -07001109func addBasicTests() {
1110 basicTests := []testCase{
1111 {
Adam Langley7c803a62015-06-15 15:35:05 -07001112 name: "NoFallbackSCSV",
1113 config: Config{
1114 Bugs: ProtocolBugs{
1115 FailIfNotFallbackSCSV: true,
1116 },
1117 },
1118 shouldFail: true,
1119 expectedLocalError: "no fallback SCSV found",
1120 },
1121 {
1122 name: "SendFallbackSCSV",
1123 config: Config{
1124 Bugs: ProtocolBugs{
1125 FailIfNotFallbackSCSV: true,
1126 },
1127 },
1128 flags: []string{"-fallback-scsv"},
1129 },
1130 {
1131 name: "ClientCertificateTypes",
1132 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001133 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001134 ClientAuth: RequestClientCert,
1135 ClientCertificateTypes: []byte{
1136 CertTypeDSSSign,
1137 CertTypeRSASign,
1138 CertTypeECDSASign,
1139 },
1140 },
1141 flags: []string{
1142 "-expect-certificate-types",
1143 base64.StdEncoding.EncodeToString([]byte{
1144 CertTypeDSSSign,
1145 CertTypeRSASign,
1146 CertTypeECDSASign,
1147 }),
1148 },
1149 },
1150 {
Adam Langley7c803a62015-06-15 15:35:05 -07001151 name: "UnauthenticatedECDH",
1152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001153 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001154 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1155 Bugs: ProtocolBugs{
1156 UnauthenticatedECDH: true,
1157 },
1158 },
1159 shouldFail: true,
1160 expectedError: ":UNEXPECTED_MESSAGE:",
1161 },
1162 {
1163 name: "SkipCertificateStatus",
1164 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001165 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001166 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1167 Bugs: ProtocolBugs{
1168 SkipCertificateStatus: true,
1169 },
1170 },
1171 flags: []string{
1172 "-enable-ocsp-stapling",
1173 },
1174 },
1175 {
1176 name: "SkipServerKeyExchange",
1177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001178 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001179 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1180 Bugs: ProtocolBugs{
1181 SkipServerKeyExchange: true,
1182 },
1183 },
1184 shouldFail: true,
1185 expectedError: ":UNEXPECTED_MESSAGE:",
1186 },
1187 {
Adam Langley7c803a62015-06-15 15:35:05 -07001188 testType: serverTest,
1189 name: "Alert",
1190 config: Config{
1191 Bugs: ProtocolBugs{
1192 SendSpuriousAlert: alertRecordOverflow,
1193 },
1194 },
1195 shouldFail: true,
1196 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1197 },
1198 {
1199 protocol: dtls,
1200 testType: serverTest,
1201 name: "Alert-DTLS",
1202 config: Config{
1203 Bugs: ProtocolBugs{
1204 SendSpuriousAlert: alertRecordOverflow,
1205 },
1206 },
1207 shouldFail: true,
1208 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1209 },
1210 {
1211 testType: serverTest,
1212 name: "FragmentAlert",
1213 config: Config{
1214 Bugs: ProtocolBugs{
1215 FragmentAlert: true,
1216 SendSpuriousAlert: alertRecordOverflow,
1217 },
1218 },
1219 shouldFail: true,
1220 expectedError: ":BAD_ALERT:",
1221 },
1222 {
1223 protocol: dtls,
1224 testType: serverTest,
1225 name: "FragmentAlert-DTLS",
1226 config: Config{
1227 Bugs: ProtocolBugs{
1228 FragmentAlert: true,
1229 SendSpuriousAlert: alertRecordOverflow,
1230 },
1231 },
1232 shouldFail: true,
1233 expectedError: ":BAD_ALERT:",
1234 },
1235 {
1236 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001237 name: "DoubleAlert",
1238 config: Config{
1239 Bugs: ProtocolBugs{
1240 DoubleAlert: true,
1241 SendSpuriousAlert: alertRecordOverflow,
1242 },
1243 },
1244 shouldFail: true,
1245 expectedError: ":BAD_ALERT:",
1246 },
1247 {
1248 protocol: dtls,
1249 testType: serverTest,
1250 name: "DoubleAlert-DTLS",
1251 config: Config{
1252 Bugs: ProtocolBugs{
1253 DoubleAlert: true,
1254 SendSpuriousAlert: alertRecordOverflow,
1255 },
1256 },
1257 shouldFail: true,
1258 expectedError: ":BAD_ALERT:",
1259 },
1260 {
Adam Langley7c803a62015-06-15 15:35:05 -07001261 name: "SkipNewSessionTicket",
1262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001263 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001264 Bugs: ProtocolBugs{
1265 SkipNewSessionTicket: true,
1266 },
1267 },
1268 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001269 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001270 },
1271 {
1272 testType: serverTest,
1273 name: "FallbackSCSV",
1274 config: Config{
1275 MaxVersion: VersionTLS11,
1276 Bugs: ProtocolBugs{
1277 SendFallbackSCSV: true,
1278 },
1279 },
1280 shouldFail: true,
1281 expectedError: ":INAPPROPRIATE_FALLBACK:",
1282 },
1283 {
1284 testType: serverTest,
1285 name: "FallbackSCSV-VersionMatch",
1286 config: Config{
1287 Bugs: ProtocolBugs{
1288 SendFallbackSCSV: true,
1289 },
1290 },
1291 },
1292 {
1293 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001294 name: "FallbackSCSV-VersionMatch-TLS12",
1295 config: Config{
1296 MaxVersion: VersionTLS12,
1297 Bugs: ProtocolBugs{
1298 SendFallbackSCSV: true,
1299 },
1300 },
1301 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1302 },
1303 {
1304 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001305 name: "FragmentedClientVersion",
1306 config: Config{
1307 Bugs: ProtocolBugs{
1308 MaxHandshakeRecordLength: 1,
1309 FragmentClientVersion: true,
1310 },
1311 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001312 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001313 },
1314 {
Adam Langley7c803a62015-06-15 15:35:05 -07001315 testType: serverTest,
1316 name: "HttpGET",
1317 sendPrefix: "GET / HTTP/1.0\n",
1318 shouldFail: true,
1319 expectedError: ":HTTP_REQUEST:",
1320 },
1321 {
1322 testType: serverTest,
1323 name: "HttpPOST",
1324 sendPrefix: "POST / HTTP/1.0\n",
1325 shouldFail: true,
1326 expectedError: ":HTTP_REQUEST:",
1327 },
1328 {
1329 testType: serverTest,
1330 name: "HttpHEAD",
1331 sendPrefix: "HEAD / HTTP/1.0\n",
1332 shouldFail: true,
1333 expectedError: ":HTTP_REQUEST:",
1334 },
1335 {
1336 testType: serverTest,
1337 name: "HttpPUT",
1338 sendPrefix: "PUT / HTTP/1.0\n",
1339 shouldFail: true,
1340 expectedError: ":HTTP_REQUEST:",
1341 },
1342 {
1343 testType: serverTest,
1344 name: "HttpCONNECT",
1345 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1346 shouldFail: true,
1347 expectedError: ":HTTPS_PROXY_REQUEST:",
1348 },
1349 {
1350 testType: serverTest,
1351 name: "Garbage",
1352 sendPrefix: "blah",
1353 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001354 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001355 },
1356 {
Adam Langley7c803a62015-06-15 15:35:05 -07001357 name: "RSAEphemeralKey",
1358 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001359 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001360 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1361 Bugs: ProtocolBugs{
1362 RSAEphemeralKey: true,
1363 },
1364 },
1365 shouldFail: true,
1366 expectedError: ":UNEXPECTED_MESSAGE:",
1367 },
1368 {
1369 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001370 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001371 shouldFail: true,
1372 expectedError: ":WRONG_SSL_VERSION:",
1373 },
1374 {
1375 protocol: dtls,
1376 name: "DisableEverything-DTLS",
1377 flags: []string{"-no-tls12", "-no-tls1"},
1378 shouldFail: true,
1379 expectedError: ":WRONG_SSL_VERSION:",
1380 },
1381 {
Adam Langley7c803a62015-06-15 15:35:05 -07001382 protocol: dtls,
1383 testType: serverTest,
1384 name: "MTU",
1385 config: Config{
1386 Bugs: ProtocolBugs{
1387 MaxPacketLength: 256,
1388 },
1389 },
1390 flags: []string{"-mtu", "256"},
1391 },
1392 {
1393 protocol: dtls,
1394 testType: serverTest,
1395 name: "MTUExceeded",
1396 config: Config{
1397 Bugs: ProtocolBugs{
1398 MaxPacketLength: 255,
1399 },
1400 },
1401 flags: []string{"-mtu", "256"},
1402 shouldFail: true,
1403 expectedLocalError: "dtls: exceeded maximum packet length",
1404 },
1405 {
1406 name: "CertMismatchRSA",
1407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001408 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001409 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001410 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001411 Bugs: ProtocolBugs{
1412 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1413 },
1414 },
1415 shouldFail: true,
1416 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1417 },
1418 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001419 name: "CertMismatchRSA-TLS13",
1420 config: Config{
1421 MaxVersion: VersionTLS13,
1422 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1423 Certificates: []Certificate{ecdsaP256Certificate},
1424 Bugs: ProtocolBugs{
1425 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1426 },
1427 },
1428 shouldFail: true,
1429 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1430 },
1431 {
Adam Langley7c803a62015-06-15 15:35:05 -07001432 name: "CertMismatchECDSA",
1433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001434 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001435 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001436 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001437 Bugs: ProtocolBugs{
1438 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1439 },
1440 },
1441 shouldFail: true,
1442 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1443 },
1444 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001445 name: "CertMismatchECDSA-TLS13",
1446 config: Config{
1447 MaxVersion: VersionTLS13,
1448 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1449 Certificates: []Certificate{rsaCertificate},
1450 Bugs: ProtocolBugs{
1451 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1452 },
1453 },
1454 shouldFail: true,
1455 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1456 },
1457 {
Adam Langley7c803a62015-06-15 15:35:05 -07001458 name: "EmptyCertificateList",
1459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001460 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001461 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1462 Bugs: ProtocolBugs{
1463 EmptyCertificateList: true,
1464 },
1465 },
1466 shouldFail: true,
1467 expectedError: ":DECODE_ERROR:",
1468 },
1469 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001470 name: "EmptyCertificateList-TLS13",
1471 config: Config{
1472 MaxVersion: VersionTLS13,
1473 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1474 Bugs: ProtocolBugs{
1475 EmptyCertificateList: true,
1476 },
1477 },
1478 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001479 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001480 },
1481 {
Adam Langley7c803a62015-06-15 15:35:05 -07001482 name: "TLSFatalBadPackets",
1483 damageFirstWrite: true,
1484 shouldFail: true,
1485 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1486 },
1487 {
1488 protocol: dtls,
1489 name: "DTLSIgnoreBadPackets",
1490 damageFirstWrite: true,
1491 },
1492 {
1493 protocol: dtls,
1494 name: "DTLSIgnoreBadPackets-Async",
1495 damageFirstWrite: true,
1496 flags: []string{"-async"},
1497 },
1498 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001499 name: "AppDataBeforeHandshake",
1500 config: Config{
1501 Bugs: ProtocolBugs{
1502 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1503 },
1504 },
1505 shouldFail: true,
1506 expectedError: ":UNEXPECTED_RECORD:",
1507 },
1508 {
1509 name: "AppDataBeforeHandshake-Empty",
1510 config: Config{
1511 Bugs: ProtocolBugs{
1512 AppDataBeforeHandshake: []byte{},
1513 },
1514 },
1515 shouldFail: true,
1516 expectedError: ":UNEXPECTED_RECORD:",
1517 },
1518 {
1519 protocol: dtls,
1520 name: "AppDataBeforeHandshake-DTLS",
1521 config: Config{
1522 Bugs: ProtocolBugs{
1523 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1524 },
1525 },
1526 shouldFail: true,
1527 expectedError: ":UNEXPECTED_RECORD:",
1528 },
1529 {
1530 protocol: dtls,
1531 name: "AppDataBeforeHandshake-DTLS-Empty",
1532 config: Config{
1533 Bugs: ProtocolBugs{
1534 AppDataBeforeHandshake: []byte{},
1535 },
1536 },
1537 shouldFail: true,
1538 expectedError: ":UNEXPECTED_RECORD:",
1539 },
1540 {
Adam Langley7c803a62015-06-15 15:35:05 -07001541 name: "AppDataAfterChangeCipherSpec",
1542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001543 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001544 Bugs: ProtocolBugs{
1545 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1546 },
1547 },
1548 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001549 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001550 },
1551 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001552 name: "AppDataAfterChangeCipherSpec-Empty",
1553 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001554 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001555 Bugs: ProtocolBugs{
1556 AppDataAfterChangeCipherSpec: []byte{},
1557 },
1558 },
1559 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001560 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001561 },
1562 {
Adam Langley7c803a62015-06-15 15:35:05 -07001563 protocol: dtls,
1564 name: "AppDataAfterChangeCipherSpec-DTLS",
1565 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001566 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001567 Bugs: ProtocolBugs{
1568 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1569 },
1570 },
1571 // BoringSSL's DTLS implementation will drop the out-of-order
1572 // application data.
1573 },
1574 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001575 protocol: dtls,
1576 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1577 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001578 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001579 Bugs: ProtocolBugs{
1580 AppDataAfterChangeCipherSpec: []byte{},
1581 },
1582 },
1583 // BoringSSL's DTLS implementation will drop the out-of-order
1584 // application data.
1585 },
1586 {
Adam Langley7c803a62015-06-15 15:35:05 -07001587 name: "AlertAfterChangeCipherSpec",
1588 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001589 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001590 Bugs: ProtocolBugs{
1591 AlertAfterChangeCipherSpec: alertRecordOverflow,
1592 },
1593 },
1594 shouldFail: true,
1595 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1596 },
1597 {
1598 protocol: dtls,
1599 name: "AlertAfterChangeCipherSpec-DTLS",
1600 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001601 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001602 Bugs: ProtocolBugs{
1603 AlertAfterChangeCipherSpec: alertRecordOverflow,
1604 },
1605 },
1606 shouldFail: true,
1607 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1608 },
1609 {
1610 protocol: dtls,
1611 name: "ReorderHandshakeFragments-Small-DTLS",
1612 config: Config{
1613 Bugs: ProtocolBugs{
1614 ReorderHandshakeFragments: true,
1615 // Small enough that every handshake message is
1616 // fragmented.
1617 MaxHandshakeRecordLength: 2,
1618 },
1619 },
1620 },
1621 {
1622 protocol: dtls,
1623 name: "ReorderHandshakeFragments-Large-DTLS",
1624 config: Config{
1625 Bugs: ProtocolBugs{
1626 ReorderHandshakeFragments: true,
1627 // Large enough that no handshake message is
1628 // fragmented.
1629 MaxHandshakeRecordLength: 2048,
1630 },
1631 },
1632 },
1633 {
1634 protocol: dtls,
1635 name: "MixCompleteMessageWithFragments-DTLS",
1636 config: Config{
1637 Bugs: ProtocolBugs{
1638 ReorderHandshakeFragments: true,
1639 MixCompleteMessageWithFragments: true,
1640 MaxHandshakeRecordLength: 2,
1641 },
1642 },
1643 },
1644 {
1645 name: "SendInvalidRecordType",
1646 config: Config{
1647 Bugs: ProtocolBugs{
1648 SendInvalidRecordType: true,
1649 },
1650 },
1651 shouldFail: true,
1652 expectedError: ":UNEXPECTED_RECORD:",
1653 },
1654 {
1655 protocol: dtls,
1656 name: "SendInvalidRecordType-DTLS",
1657 config: Config{
1658 Bugs: ProtocolBugs{
1659 SendInvalidRecordType: true,
1660 },
1661 },
1662 shouldFail: true,
1663 expectedError: ":UNEXPECTED_RECORD:",
1664 },
1665 {
1666 name: "FalseStart-SkipServerSecondLeg",
1667 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001668 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001669 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1670 NextProtos: []string{"foo"},
1671 Bugs: ProtocolBugs{
1672 SkipNewSessionTicket: true,
1673 SkipChangeCipherSpec: true,
1674 SkipFinished: true,
1675 ExpectFalseStart: true,
1676 },
1677 },
1678 flags: []string{
1679 "-false-start",
1680 "-handshake-never-done",
1681 "-advertise-alpn", "\x03foo",
1682 },
1683 shimWritesFirst: true,
1684 shouldFail: true,
1685 expectedError: ":UNEXPECTED_RECORD:",
1686 },
1687 {
1688 name: "FalseStart-SkipServerSecondLeg-Implicit",
1689 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001690 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001691 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1692 NextProtos: []string{"foo"},
1693 Bugs: ProtocolBugs{
1694 SkipNewSessionTicket: true,
1695 SkipChangeCipherSpec: true,
1696 SkipFinished: true,
1697 },
1698 },
1699 flags: []string{
1700 "-implicit-handshake",
1701 "-false-start",
1702 "-handshake-never-done",
1703 "-advertise-alpn", "\x03foo",
1704 },
1705 shouldFail: true,
1706 expectedError: ":UNEXPECTED_RECORD:",
1707 },
1708 {
1709 testType: serverTest,
1710 name: "FailEarlyCallback",
1711 flags: []string{"-fail-early-callback"},
1712 shouldFail: true,
1713 expectedError: ":CONNECTION_REJECTED:",
1714 expectedLocalError: "remote error: access denied",
1715 },
1716 {
Adam Langley7c803a62015-06-15 15:35:05 -07001717 protocol: dtls,
1718 name: "FragmentMessageTypeMismatch-DTLS",
1719 config: Config{
1720 Bugs: ProtocolBugs{
1721 MaxHandshakeRecordLength: 2,
1722 FragmentMessageTypeMismatch: true,
1723 },
1724 },
1725 shouldFail: true,
1726 expectedError: ":FRAGMENT_MISMATCH:",
1727 },
1728 {
1729 protocol: dtls,
1730 name: "FragmentMessageLengthMismatch-DTLS",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 MaxHandshakeRecordLength: 2,
1734 FragmentMessageLengthMismatch: true,
1735 },
1736 },
1737 shouldFail: true,
1738 expectedError: ":FRAGMENT_MISMATCH:",
1739 },
1740 {
1741 protocol: dtls,
1742 name: "SplitFragments-Header-DTLS",
1743 config: Config{
1744 Bugs: ProtocolBugs{
1745 SplitFragments: 2,
1746 },
1747 },
1748 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001749 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001750 },
1751 {
1752 protocol: dtls,
1753 name: "SplitFragments-Boundary-DTLS",
1754 config: Config{
1755 Bugs: ProtocolBugs{
1756 SplitFragments: dtlsRecordHeaderLen,
1757 },
1758 },
1759 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001760 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001761 },
1762 {
1763 protocol: dtls,
1764 name: "SplitFragments-Body-DTLS",
1765 config: Config{
1766 Bugs: ProtocolBugs{
1767 SplitFragments: dtlsRecordHeaderLen + 1,
1768 },
1769 },
1770 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001771 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001772 },
1773 {
1774 protocol: dtls,
1775 name: "SendEmptyFragments-DTLS",
1776 config: Config{
1777 Bugs: ProtocolBugs{
1778 SendEmptyFragments: true,
1779 },
1780 },
1781 },
1782 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001783 name: "BadFinished-Client",
1784 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001785 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001786 Bugs: ProtocolBugs{
1787 BadFinished: true,
1788 },
1789 },
1790 shouldFail: true,
1791 expectedError: ":DIGEST_CHECK_FAILED:",
1792 },
1793 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001794 name: "BadFinished-Client-TLS13",
1795 config: Config{
1796 MaxVersion: VersionTLS13,
1797 Bugs: ProtocolBugs{
1798 BadFinished: true,
1799 },
1800 },
1801 shouldFail: true,
1802 expectedError: ":DIGEST_CHECK_FAILED:",
1803 },
1804 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001805 testType: serverTest,
1806 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001807 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001808 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001809 Bugs: ProtocolBugs{
1810 BadFinished: true,
1811 },
1812 },
1813 shouldFail: true,
1814 expectedError: ":DIGEST_CHECK_FAILED:",
1815 },
1816 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001817 testType: serverTest,
1818 name: "BadFinished-Server-TLS13",
1819 config: Config{
1820 MaxVersion: VersionTLS13,
1821 Bugs: ProtocolBugs{
1822 BadFinished: true,
1823 },
1824 },
1825 shouldFail: true,
1826 expectedError: ":DIGEST_CHECK_FAILED:",
1827 },
1828 {
Adam Langley7c803a62015-06-15 15:35:05 -07001829 name: "FalseStart-BadFinished",
1830 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001831 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1833 NextProtos: []string{"foo"},
1834 Bugs: ProtocolBugs{
1835 BadFinished: true,
1836 ExpectFalseStart: true,
1837 },
1838 },
1839 flags: []string{
1840 "-false-start",
1841 "-handshake-never-done",
1842 "-advertise-alpn", "\x03foo",
1843 },
1844 shimWritesFirst: true,
1845 shouldFail: true,
1846 expectedError: ":DIGEST_CHECK_FAILED:",
1847 },
1848 {
1849 name: "NoFalseStart-NoALPN",
1850 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001851 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001852 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1853 Bugs: ProtocolBugs{
1854 ExpectFalseStart: true,
1855 AlertBeforeFalseStartTest: alertAccessDenied,
1856 },
1857 },
1858 flags: []string{
1859 "-false-start",
1860 },
1861 shimWritesFirst: true,
1862 shouldFail: true,
1863 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1864 expectedLocalError: "tls: peer did not false start: EOF",
1865 },
1866 {
1867 name: "NoFalseStart-NoAEAD",
1868 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001869 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001870 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1871 NextProtos: []string{"foo"},
1872 Bugs: ProtocolBugs{
1873 ExpectFalseStart: true,
1874 AlertBeforeFalseStartTest: alertAccessDenied,
1875 },
1876 },
1877 flags: []string{
1878 "-false-start",
1879 "-advertise-alpn", "\x03foo",
1880 },
1881 shimWritesFirst: true,
1882 shouldFail: true,
1883 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1884 expectedLocalError: "tls: peer did not false start: EOF",
1885 },
1886 {
1887 name: "NoFalseStart-RSA",
1888 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001889 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001890 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1891 NextProtos: []string{"foo"},
1892 Bugs: ProtocolBugs{
1893 ExpectFalseStart: true,
1894 AlertBeforeFalseStartTest: alertAccessDenied,
1895 },
1896 },
1897 flags: []string{
1898 "-false-start",
1899 "-advertise-alpn", "\x03foo",
1900 },
1901 shimWritesFirst: true,
1902 shouldFail: true,
1903 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1904 expectedLocalError: "tls: peer did not false start: EOF",
1905 },
1906 {
1907 name: "NoFalseStart-DHE_RSA",
1908 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001909 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001910 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1911 NextProtos: []string{"foo"},
1912 Bugs: ProtocolBugs{
1913 ExpectFalseStart: true,
1914 AlertBeforeFalseStartTest: alertAccessDenied,
1915 },
1916 },
1917 flags: []string{
1918 "-false-start",
1919 "-advertise-alpn", "\x03foo",
1920 },
1921 shimWritesFirst: true,
1922 shouldFail: true,
1923 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1924 expectedLocalError: "tls: peer did not false start: EOF",
1925 },
1926 {
Adam Langley7c803a62015-06-15 15:35:05 -07001927 protocol: dtls,
1928 name: "SendSplitAlert-Sync",
1929 config: Config{
1930 Bugs: ProtocolBugs{
1931 SendSplitAlert: true,
1932 },
1933 },
1934 },
1935 {
1936 protocol: dtls,
1937 name: "SendSplitAlert-Async",
1938 config: Config{
1939 Bugs: ProtocolBugs{
1940 SendSplitAlert: true,
1941 },
1942 },
1943 flags: []string{"-async"},
1944 },
1945 {
1946 protocol: dtls,
1947 name: "PackDTLSHandshake",
1948 config: Config{
1949 Bugs: ProtocolBugs{
1950 MaxHandshakeRecordLength: 2,
1951 PackHandshakeFragments: 20,
1952 PackHandshakeRecords: 200,
1953 },
1954 },
1955 },
1956 {
Adam Langley7c803a62015-06-15 15:35:05 -07001957 name: "SendEmptyRecords-Pass",
1958 sendEmptyRecords: 32,
1959 },
1960 {
1961 name: "SendEmptyRecords",
1962 sendEmptyRecords: 33,
1963 shouldFail: true,
1964 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1965 },
1966 {
1967 name: "SendEmptyRecords-Async",
1968 sendEmptyRecords: 33,
1969 flags: []string{"-async"},
1970 shouldFail: true,
1971 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1972 },
1973 {
David Benjamine8e84b92016-08-03 15:39:47 -04001974 name: "SendWarningAlerts-Pass",
1975 config: Config{
1976 MaxVersion: VersionTLS12,
1977 },
Adam Langley7c803a62015-06-15 15:35:05 -07001978 sendWarningAlerts: 4,
1979 },
1980 {
David Benjamine8e84b92016-08-03 15:39:47 -04001981 protocol: dtls,
1982 name: "SendWarningAlerts-DTLS-Pass",
1983 config: Config{
1984 MaxVersion: VersionTLS12,
1985 },
Adam Langley7c803a62015-06-15 15:35:05 -07001986 sendWarningAlerts: 4,
1987 },
1988 {
David Benjamine8e84b92016-08-03 15:39:47 -04001989 name: "SendWarningAlerts-TLS13",
1990 config: Config{
1991 MaxVersion: VersionTLS13,
1992 },
1993 sendWarningAlerts: 4,
1994 shouldFail: true,
1995 expectedError: ":BAD_ALERT:",
1996 expectedLocalError: "remote error: error decoding message",
1997 },
1998 {
1999 name: "SendWarningAlerts",
2000 config: Config{
2001 MaxVersion: VersionTLS12,
2002 },
Adam Langley7c803a62015-06-15 15:35:05 -07002003 sendWarningAlerts: 5,
2004 shouldFail: true,
2005 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2006 },
2007 {
David Benjamine8e84b92016-08-03 15:39:47 -04002008 name: "SendWarningAlerts-Async",
2009 config: Config{
2010 MaxVersion: VersionTLS12,
2011 },
Adam Langley7c803a62015-06-15 15:35:05 -07002012 sendWarningAlerts: 5,
2013 flags: []string{"-async"},
2014 shouldFail: true,
2015 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2016 },
David Benjaminba4594a2015-06-18 18:36:15 -04002017 {
Steven Valdez32635b82016-08-16 11:25:03 -04002018 name: "SendKeyUpdates",
2019 config: Config{
2020 MaxVersion: VersionTLS13,
2021 },
2022 sendKeyUpdates: 33,
2023 shouldFail: true,
2024 expectedError: ":TOO_MANY_KEY_UPDATES:",
2025 },
2026 {
David Benjaminba4594a2015-06-18 18:36:15 -04002027 name: "EmptySessionID",
2028 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002029 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002030 SessionTicketsDisabled: true,
2031 },
2032 noSessionCache: true,
2033 flags: []string{"-expect-no-session"},
2034 },
David Benjamin30789da2015-08-29 22:56:45 -04002035 {
2036 name: "Unclean-Shutdown",
2037 config: Config{
2038 Bugs: ProtocolBugs{
2039 NoCloseNotify: true,
2040 ExpectCloseNotify: true,
2041 },
2042 },
2043 shimShutsDown: true,
2044 flags: []string{"-check-close-notify"},
2045 shouldFail: true,
2046 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2047 },
2048 {
2049 name: "Unclean-Shutdown-Ignored",
2050 config: Config{
2051 Bugs: ProtocolBugs{
2052 NoCloseNotify: true,
2053 },
2054 },
2055 shimShutsDown: true,
2056 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002057 {
David Benjaminfa214e42016-05-10 17:03:10 -04002058 name: "Unclean-Shutdown-Alert",
2059 config: Config{
2060 Bugs: ProtocolBugs{
2061 SendAlertOnShutdown: alertDecompressionFailure,
2062 ExpectCloseNotify: true,
2063 },
2064 },
2065 shimShutsDown: true,
2066 flags: []string{"-check-close-notify"},
2067 shouldFail: true,
2068 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2069 },
2070 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002071 name: "LargePlaintext",
2072 config: Config{
2073 Bugs: ProtocolBugs{
2074 SendLargeRecords: true,
2075 },
2076 },
2077 messageLen: maxPlaintext + 1,
2078 shouldFail: true,
2079 expectedError: ":DATA_LENGTH_TOO_LONG:",
2080 },
2081 {
2082 protocol: dtls,
2083 name: "LargePlaintext-DTLS",
2084 config: Config{
2085 Bugs: ProtocolBugs{
2086 SendLargeRecords: true,
2087 },
2088 },
2089 messageLen: maxPlaintext + 1,
2090 shouldFail: true,
2091 expectedError: ":DATA_LENGTH_TOO_LONG:",
2092 },
2093 {
2094 name: "LargeCiphertext",
2095 config: Config{
2096 Bugs: ProtocolBugs{
2097 SendLargeRecords: true,
2098 },
2099 },
2100 messageLen: maxPlaintext * 2,
2101 shouldFail: true,
2102 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2103 },
2104 {
2105 protocol: dtls,
2106 name: "LargeCiphertext-DTLS",
2107 config: Config{
2108 Bugs: ProtocolBugs{
2109 SendLargeRecords: true,
2110 },
2111 },
2112 messageLen: maxPlaintext * 2,
2113 // Unlike the other four cases, DTLS drops records which
2114 // are invalid before authentication, so the connection
2115 // does not fail.
2116 expectMessageDropped: true,
2117 },
David Benjamindd6fed92015-10-23 17:41:12 -04002118 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002119 // In TLS 1.2 and below, empty NewSessionTicket messages
2120 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002121 name: "SendEmptySessionTicket",
2122 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002123 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002124 Bugs: ProtocolBugs{
2125 SendEmptySessionTicket: true,
2126 FailIfSessionOffered: true,
2127 },
2128 },
David Benjamin46662482016-08-17 00:51:00 -04002129 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002130 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002131 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002132 name: "BadHelloRequest-1",
2133 renegotiate: 1,
2134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002135 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002136 Bugs: ProtocolBugs{
2137 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2138 },
2139 },
2140 flags: []string{
2141 "-renegotiate-freely",
2142 "-expect-total-renegotiations", "1",
2143 },
2144 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002145 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002146 },
2147 {
2148 name: "BadHelloRequest-2",
2149 renegotiate: 1,
2150 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002151 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002152 Bugs: ProtocolBugs{
2153 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2154 },
2155 },
2156 flags: []string{
2157 "-renegotiate-freely",
2158 "-expect-total-renegotiations", "1",
2159 },
2160 shouldFail: true,
2161 expectedError: ":BAD_HELLO_REQUEST:",
2162 },
David Benjaminef1b0092015-11-21 14:05:44 -05002163 {
2164 testType: serverTest,
2165 name: "SupportTicketsWithSessionID",
2166 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002167 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002168 SessionTicketsDisabled: true,
2169 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002170 resumeConfig: &Config{
2171 MaxVersion: VersionTLS12,
2172 },
David Benjaminef1b0092015-11-21 14:05:44 -05002173 resumeSession: true,
2174 },
David Benjamin02edcd02016-07-27 17:40:37 -04002175 {
2176 protocol: dtls,
2177 name: "DTLS-SendExtraFinished",
2178 config: Config{
2179 Bugs: ProtocolBugs{
2180 SendExtraFinished: true,
2181 },
2182 },
2183 shouldFail: true,
2184 expectedError: ":UNEXPECTED_RECORD:",
2185 },
2186 {
2187 protocol: dtls,
2188 name: "DTLS-SendExtraFinished-Reordered",
2189 config: Config{
2190 Bugs: ProtocolBugs{
2191 MaxHandshakeRecordLength: 2,
2192 ReorderHandshakeFragments: true,
2193 SendExtraFinished: true,
2194 },
2195 },
2196 shouldFail: true,
2197 expectedError: ":UNEXPECTED_RECORD:",
2198 },
David Benjamine97fb482016-07-29 09:23:07 -04002199 {
2200 testType: serverTest,
2201 name: "V2ClientHello-EmptyRecordPrefix",
2202 config: Config{
2203 // Choose a cipher suite that does not involve
2204 // elliptic curves, so no extensions are
2205 // involved.
2206 MaxVersion: VersionTLS12,
2207 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2208 Bugs: ProtocolBugs{
2209 SendV2ClientHello: true,
2210 },
2211 },
2212 sendPrefix: string([]byte{
2213 byte(recordTypeHandshake),
2214 3, 1, // version
2215 0, 0, // length
2216 }),
2217 // A no-op empty record may not be sent before V2ClientHello.
2218 shouldFail: true,
2219 expectedError: ":WRONG_VERSION_NUMBER:",
2220 },
2221 {
2222 testType: serverTest,
2223 name: "V2ClientHello-WarningAlertPrefix",
2224 config: Config{
2225 // Choose a cipher suite that does not involve
2226 // elliptic curves, so no extensions are
2227 // involved.
2228 MaxVersion: VersionTLS12,
2229 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2230 Bugs: ProtocolBugs{
2231 SendV2ClientHello: true,
2232 },
2233 },
2234 sendPrefix: string([]byte{
2235 byte(recordTypeAlert),
2236 3, 1, // version
2237 0, 2, // length
2238 alertLevelWarning, byte(alertDecompressionFailure),
2239 }),
2240 // A no-op warning alert may not be sent before V2ClientHello.
2241 shouldFail: true,
2242 expectedError: ":WRONG_VERSION_NUMBER:",
2243 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002244 {
2245 testType: clientTest,
2246 name: "KeyUpdate",
2247 config: Config{
2248 MaxVersion: VersionTLS13,
2249 Bugs: ProtocolBugs{
2250 SendKeyUpdateBeforeEveryAppDataRecord: true,
2251 },
2252 },
2253 },
Adam Langley7c803a62015-06-15 15:35:05 -07002254 }
Adam Langley7c803a62015-06-15 15:35:05 -07002255 testCases = append(testCases, basicTests...)
2256}
2257
Adam Langley95c29f32014-06-20 12:00:00 -07002258func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002259 const bogusCipher = 0xfe00
2260
Adam Langley95c29f32014-06-20 12:00:00 -07002261 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002262 const psk = "12345"
2263 const pskIdentity = "luggage combo"
2264
Adam Langley95c29f32014-06-20 12:00:00 -07002265 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002266 var certFile string
2267 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002268 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002269 cert = ecdsaP256Certificate
2270 certFile = ecdsaP256CertificateFile
2271 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002272 } else {
David Benjamin33863262016-07-08 17:20:12 -07002273 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002274 certFile = rsaCertificateFile
2275 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002276 }
2277
David Benjamin48cae082014-10-27 01:06:24 -04002278 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002279 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002280 flags = append(flags,
2281 "-psk", psk,
2282 "-psk-identity", pskIdentity)
2283 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002284 if hasComponent(suite.name, "NULL") {
2285 // NULL ciphers must be explicitly enabled.
2286 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2287 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002288 if hasComponent(suite.name, "CECPQ1") {
2289 // CECPQ1 ciphers must be explicitly enabled.
2290 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2291 }
David Benjamin881f1962016-08-10 18:29:12 -04002292 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2293 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2294 // for now.
2295 flags = append(flags, "-cipher", suite.name)
2296 }
David Benjamin48cae082014-10-27 01:06:24 -04002297
Adam Langley95c29f32014-06-20 12:00:00 -07002298 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002299 for _, protocol := range []protocol{tls, dtls} {
2300 var prefix string
2301 if protocol == dtls {
2302 if !ver.hasDTLS {
2303 continue
2304 }
2305 prefix = "D"
2306 }
Adam Langley95c29f32014-06-20 12:00:00 -07002307
David Benjamin0407e762016-06-17 16:41:18 -04002308 var shouldServerFail, shouldClientFail bool
2309 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2310 // BoringSSL clients accept ECDHE on SSLv3, but
2311 // a BoringSSL server will never select it
2312 // because the extension is missing.
2313 shouldServerFail = true
2314 }
2315 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2316 shouldClientFail = true
2317 shouldServerFail = true
2318 }
David Benjamin54c217c2016-07-13 12:35:25 -04002319 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002320 shouldClientFail = true
2321 shouldServerFail = true
2322 }
David Benjamin0407e762016-06-17 16:41:18 -04002323 if !isDTLSCipher(suite.name) && protocol == dtls {
2324 shouldClientFail = true
2325 shouldServerFail = true
2326 }
David Benjamin4298d772015-12-19 00:18:25 -05002327
David Benjamin0407e762016-06-17 16:41:18 -04002328 var expectedServerError, expectedClientError string
2329 if shouldServerFail {
2330 expectedServerError = ":NO_SHARED_CIPHER:"
2331 }
2332 if shouldClientFail {
2333 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2334 }
David Benjamin025b3d32014-07-01 19:53:04 -04002335
David Benjamin6fd297b2014-08-11 18:43:38 -04002336 testCases = append(testCases, testCase{
2337 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002338 protocol: protocol,
2339
2340 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002341 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002342 MinVersion: ver.version,
2343 MaxVersion: ver.version,
2344 CipherSuites: []uint16{suite.id},
2345 Certificates: []Certificate{cert},
2346 PreSharedKey: []byte(psk),
2347 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002348 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002349 EnableAllCiphers: shouldServerFail,
2350 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002351 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002352 },
2353 certFile: certFile,
2354 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002355 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002356 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002357 shouldFail: shouldServerFail,
2358 expectedError: expectedServerError,
2359 })
2360
2361 testCases = append(testCases, testCase{
2362 testType: clientTest,
2363 protocol: protocol,
2364 name: prefix + ver.name + "-" + suite.name + "-client",
2365 config: Config{
2366 MinVersion: ver.version,
2367 MaxVersion: ver.version,
2368 CipherSuites: []uint16{suite.id},
2369 Certificates: []Certificate{cert},
2370 PreSharedKey: []byte(psk),
2371 PreSharedKeyIdentity: pskIdentity,
2372 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002373 EnableAllCiphers: shouldClientFail,
2374 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002375 },
2376 },
2377 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002378 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002379 shouldFail: shouldClientFail,
2380 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002381 })
David Benjamin2c99d282015-09-01 10:23:00 -04002382
Nick Harper1fd39d82016-06-14 18:14:35 -07002383 if !shouldClientFail {
2384 // Ensure the maximum record size is accepted.
2385 testCases = append(testCases, testCase{
2386 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2387 config: Config{
2388 MinVersion: ver.version,
2389 MaxVersion: ver.version,
2390 CipherSuites: []uint16{suite.id},
2391 Certificates: []Certificate{cert},
2392 PreSharedKey: []byte(psk),
2393 PreSharedKeyIdentity: pskIdentity,
2394 },
2395 flags: flags,
2396 messageLen: maxPlaintext,
2397 })
2398 }
2399 }
David Benjamin2c99d282015-09-01 10:23:00 -04002400 }
Adam Langley95c29f32014-06-20 12:00:00 -07002401 }
Adam Langleya7997f12015-05-14 17:38:50 -07002402
2403 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002404 name: "NoSharedCipher",
2405 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002406 MaxVersion: VersionTLS12,
2407 CipherSuites: []uint16{},
2408 },
2409 shouldFail: true,
2410 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2411 })
2412
2413 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002414 name: "NoSharedCipher-TLS13",
2415 config: Config{
2416 MaxVersion: VersionTLS13,
2417 CipherSuites: []uint16{},
2418 },
2419 shouldFail: true,
2420 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2421 })
2422
2423 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002424 name: "UnsupportedCipherSuite",
2425 config: Config{
2426 MaxVersion: VersionTLS12,
2427 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2428 Bugs: ProtocolBugs{
2429 IgnorePeerCipherPreferences: true,
2430 },
2431 },
2432 flags: []string{"-cipher", "DEFAULT:!RC4"},
2433 shouldFail: true,
2434 expectedError: ":WRONG_CIPHER_RETURNED:",
2435 })
2436
2437 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002438 name: "ServerHelloBogusCipher",
2439 config: Config{
2440 MaxVersion: VersionTLS12,
2441 Bugs: ProtocolBugs{
2442 SendCipherSuite: bogusCipher,
2443 },
2444 },
2445 shouldFail: true,
2446 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2447 })
2448 testCases = append(testCases, testCase{
2449 name: "ServerHelloBogusCipher-TLS13",
2450 config: Config{
2451 MaxVersion: VersionTLS13,
2452 Bugs: ProtocolBugs{
2453 SendCipherSuite: bogusCipher,
2454 },
2455 },
2456 shouldFail: true,
2457 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2458 })
2459
2460 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002461 name: "WeakDH",
2462 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002463 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002464 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2465 Bugs: ProtocolBugs{
2466 // This is a 1023-bit prime number, generated
2467 // with:
2468 // openssl gendh 1023 | openssl asn1parse -i
2469 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2470 },
2471 },
2472 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002473 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002474 })
Adam Langleycef75832015-09-03 14:51:12 -07002475
David Benjamincd24a392015-11-11 13:23:05 -08002476 testCases = append(testCases, testCase{
2477 name: "SillyDH",
2478 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002479 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002480 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2481 Bugs: ProtocolBugs{
2482 // This is a 4097-bit prime number, generated
2483 // with:
2484 // openssl gendh 4097 | openssl asn1parse -i
2485 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2486 },
2487 },
2488 shouldFail: true,
2489 expectedError: ":DH_P_TOO_LONG:",
2490 })
2491
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002492 // This test ensures that Diffie-Hellman public values are padded with
2493 // zeros so that they're the same length as the prime. This is to avoid
2494 // hitting a bug in yaSSL.
2495 testCases = append(testCases, testCase{
2496 testType: serverTest,
2497 name: "DHPublicValuePadded",
2498 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002499 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002500 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2501 Bugs: ProtocolBugs{
2502 RequireDHPublicValueLen: (1025 + 7) / 8,
2503 },
2504 },
2505 flags: []string{"-use-sparse-dh-prime"},
2506 })
David Benjamincd24a392015-11-11 13:23:05 -08002507
David Benjamin241ae832016-01-15 03:04:54 -05002508 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002509 testCases = append(testCases, testCase{
2510 testType: serverTest,
2511 name: "UnknownCipher",
2512 config: Config{
2513 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2514 },
2515 })
2516
Adam Langleycef75832015-09-03 14:51:12 -07002517 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2518 // 1.1 specific cipher suite settings. A server is setup with the given
2519 // cipher lists and then a connection is made for each member of
2520 // expectations. The cipher suite that the server selects must match
2521 // the specified one.
2522 var versionSpecificCiphersTest = []struct {
2523 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2524 // expectations is a map from TLS version to cipher suite id.
2525 expectations map[uint16]uint16
2526 }{
2527 {
2528 // Test that the null case (where no version-specific ciphers are set)
2529 // works as expected.
2530 "RC4-SHA:AES128-SHA", // default ciphers
2531 "", // no ciphers specifically for TLS ≥ 1.0
2532 "", // no ciphers specifically for TLS ≥ 1.1
2533 map[uint16]uint16{
2534 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2535 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2536 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2537 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2538 },
2539 },
2540 {
2541 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2542 // cipher.
2543 "RC4-SHA:AES128-SHA", // default
2544 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2545 "", // no ciphers specifically for TLS ≥ 1.1
2546 map[uint16]uint16{
2547 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2548 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2549 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2550 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2551 },
2552 },
2553 {
2554 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2555 // cipher.
2556 "RC4-SHA:AES128-SHA", // default
2557 "", // no ciphers specifically for TLS ≥ 1.0
2558 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2559 map[uint16]uint16{
2560 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2561 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2562 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2563 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2564 },
2565 },
2566 {
2567 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2568 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2569 "RC4-SHA:AES128-SHA", // default
2570 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2571 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2572 map[uint16]uint16{
2573 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2574 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2575 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2576 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2577 },
2578 },
2579 }
2580
2581 for i, test := range versionSpecificCiphersTest {
2582 for version, expectedCipherSuite := range test.expectations {
2583 flags := []string{"-cipher", test.ciphersDefault}
2584 if len(test.ciphersTLS10) > 0 {
2585 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2586 }
2587 if len(test.ciphersTLS11) > 0 {
2588 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2589 }
2590
2591 testCases = append(testCases, testCase{
2592 testType: serverTest,
2593 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2594 config: Config{
2595 MaxVersion: version,
2596 MinVersion: version,
2597 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2598 },
2599 flags: flags,
2600 expectedCipher: expectedCipherSuite,
2601 })
2602 }
2603 }
Adam Langley95c29f32014-06-20 12:00:00 -07002604}
2605
2606func addBadECDSASignatureTests() {
2607 for badR := BadValue(1); badR < NumBadValues; badR++ {
2608 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002609 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002610 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2611 config: Config{
2612 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002613 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002614 Bugs: ProtocolBugs{
2615 BadECDSAR: badR,
2616 BadECDSAS: badS,
2617 },
2618 },
2619 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002620 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002621 })
2622 }
2623 }
2624}
2625
Adam Langley80842bd2014-06-20 12:00:00 -07002626func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002627 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002628 name: "MaxCBCPadding",
2629 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002630 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002631 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2632 Bugs: ProtocolBugs{
2633 MaxPadding: true,
2634 },
2635 },
2636 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2637 })
David Benjamin025b3d32014-07-01 19:53:04 -04002638 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002639 name: "BadCBCPadding",
2640 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002641 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002642 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2643 Bugs: ProtocolBugs{
2644 PaddingFirstByteBad: true,
2645 },
2646 },
2647 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002648 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002649 })
2650 // OpenSSL previously had an issue where the first byte of padding in
2651 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002652 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002653 name: "BadCBCPadding255",
2654 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002655 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002656 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2657 Bugs: ProtocolBugs{
2658 MaxPadding: true,
2659 PaddingFirstByteBadIf255: true,
2660 },
2661 },
2662 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2663 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002664 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002665 })
2666}
2667
Kenny Root7fdeaf12014-08-05 15:23:37 -07002668func addCBCSplittingTests() {
2669 testCases = append(testCases, testCase{
2670 name: "CBCRecordSplitting",
2671 config: Config{
2672 MaxVersion: VersionTLS10,
2673 MinVersion: VersionTLS10,
2674 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2675 },
David Benjaminac8302a2015-09-01 17:18:15 -04002676 messageLen: -1, // read until EOF
2677 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002678 flags: []string{
2679 "-async",
2680 "-write-different-record-sizes",
2681 "-cbc-record-splitting",
2682 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002683 })
2684 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002685 name: "CBCRecordSplittingPartialWrite",
2686 config: Config{
2687 MaxVersion: VersionTLS10,
2688 MinVersion: VersionTLS10,
2689 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2690 },
2691 messageLen: -1, // read until EOF
2692 flags: []string{
2693 "-async",
2694 "-write-different-record-sizes",
2695 "-cbc-record-splitting",
2696 "-partial-write",
2697 },
2698 })
2699}
2700
David Benjamin636293b2014-07-08 17:59:18 -04002701func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002702 // Add a dummy cert pool to stress certificate authority parsing.
2703 // TODO(davidben): Add tests that those values parse out correctly.
2704 certPool := x509.NewCertPool()
2705 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2706 if err != nil {
2707 panic(err)
2708 }
2709 certPool.AddCert(cert)
2710
David Benjamin636293b2014-07-08 17:59:18 -04002711 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002712 testCases = append(testCases, testCase{
2713 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002714 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002715 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002716 MinVersion: ver.version,
2717 MaxVersion: ver.version,
2718 ClientAuth: RequireAnyClientCert,
2719 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002720 },
2721 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002722 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2723 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002724 },
2725 })
2726 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002727 testType: serverTest,
2728 name: ver.name + "-Server-ClientAuth-RSA",
2729 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002730 MinVersion: ver.version,
2731 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002732 Certificates: []Certificate{rsaCertificate},
2733 },
2734 flags: []string{"-require-any-client-certificate"},
2735 })
David Benjamine098ec22014-08-27 23:13:20 -04002736 if ver.version != VersionSSL30 {
2737 testCases = append(testCases, testCase{
2738 testType: serverTest,
2739 name: ver.name + "-Server-ClientAuth-ECDSA",
2740 config: Config{
2741 MinVersion: ver.version,
2742 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002743 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002744 },
2745 flags: []string{"-require-any-client-certificate"},
2746 })
2747 testCases = append(testCases, testCase{
2748 testType: clientTest,
2749 name: ver.name + "-Client-ClientAuth-ECDSA",
2750 config: Config{
2751 MinVersion: ver.version,
2752 MaxVersion: ver.version,
2753 ClientAuth: RequireAnyClientCert,
2754 ClientCAs: certPool,
2755 },
2756 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002757 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2758 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002759 },
2760 })
2761 }
Adam Langley37646832016-08-01 16:16:46 -07002762
2763 testCases = append(testCases, testCase{
2764 name: "NoClientCertificate-" + ver.name,
2765 config: Config{
2766 MinVersion: ver.version,
2767 MaxVersion: ver.version,
2768 ClientAuth: RequireAnyClientCert,
2769 },
2770 shouldFail: true,
2771 expectedLocalError: "client didn't provide a certificate",
2772 })
2773
2774 testCases = append(testCases, testCase{
2775 // Even if not configured to expect a certificate, OpenSSL will
2776 // return X509_V_OK as the verify_result.
2777 testType: serverTest,
2778 name: "NoClientCertificateRequested-Server-" + ver.name,
2779 config: Config{
2780 MinVersion: ver.version,
2781 MaxVersion: ver.version,
2782 },
2783 flags: []string{
2784 "-expect-verify-result",
2785 },
2786 // TODO(davidben): Switch this to true when TLS 1.3
2787 // supports session resumption.
2788 resumeSession: ver.version < VersionTLS13,
2789 })
2790
2791 testCases = append(testCases, testCase{
2792 // If a client certificate is not provided, OpenSSL will still
2793 // return X509_V_OK as the verify_result.
2794 testType: serverTest,
2795 name: "NoClientCertificate-Server-" + ver.name,
2796 config: Config{
2797 MinVersion: ver.version,
2798 MaxVersion: ver.version,
2799 },
2800 flags: []string{
2801 "-expect-verify-result",
2802 "-verify-peer",
2803 },
2804 // TODO(davidben): Switch this to true when TLS 1.3
2805 // supports session resumption.
2806 resumeSession: ver.version < VersionTLS13,
2807 })
2808
2809 testCases = append(testCases, testCase{
2810 testType: serverTest,
2811 name: "RequireAnyClientCertificate-" + ver.name,
2812 config: Config{
2813 MinVersion: ver.version,
2814 MaxVersion: ver.version,
2815 },
2816 flags: []string{"-require-any-client-certificate"},
2817 shouldFail: true,
2818 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2819 })
2820
2821 if ver.version != VersionSSL30 {
2822 testCases = append(testCases, testCase{
2823 testType: serverTest,
2824 name: "SkipClientCertificate-" + ver.name,
2825 config: Config{
2826 MinVersion: ver.version,
2827 MaxVersion: ver.version,
2828 Bugs: ProtocolBugs{
2829 SkipClientCertificate: true,
2830 },
2831 },
2832 // Setting SSL_VERIFY_PEER allows anonymous clients.
2833 flags: []string{"-verify-peer"},
2834 shouldFail: true,
2835 expectedError: ":UNEXPECTED_MESSAGE:",
2836 })
2837 }
David Benjamin636293b2014-07-08 17:59:18 -04002838 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002839
David Benjaminc032dfa2016-05-12 14:54:57 -04002840 // Client auth is only legal in certificate-based ciphers.
2841 testCases = append(testCases, testCase{
2842 testType: clientTest,
2843 name: "ClientAuth-PSK",
2844 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002845 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002846 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2847 PreSharedKey: []byte("secret"),
2848 ClientAuth: RequireAnyClientCert,
2849 },
2850 flags: []string{
2851 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2852 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2853 "-psk", "secret",
2854 },
2855 shouldFail: true,
2856 expectedError: ":UNEXPECTED_MESSAGE:",
2857 })
2858 testCases = append(testCases, testCase{
2859 testType: clientTest,
2860 name: "ClientAuth-ECDHE_PSK",
2861 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002862 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002863 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2864 PreSharedKey: []byte("secret"),
2865 ClientAuth: RequireAnyClientCert,
2866 },
2867 flags: []string{
2868 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2869 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2870 "-psk", "secret",
2871 },
2872 shouldFail: true,
2873 expectedError: ":UNEXPECTED_MESSAGE:",
2874 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002875
2876 // Regression test for a bug where the client CA list, if explicitly
2877 // set to NULL, was mis-encoded.
2878 testCases = append(testCases, testCase{
2879 testType: serverTest,
2880 name: "Null-Client-CA-List",
2881 config: Config{
2882 MaxVersion: VersionTLS12,
2883 Certificates: []Certificate{rsaCertificate},
2884 },
2885 flags: []string{
2886 "-require-any-client-certificate",
2887 "-use-null-client-ca-list",
2888 },
2889 })
David Benjamin636293b2014-07-08 17:59:18 -04002890}
2891
Adam Langley75712922014-10-10 16:23:43 -07002892func addExtendedMasterSecretTests() {
2893 const expectEMSFlag = "-expect-extended-master-secret"
2894
2895 for _, with := range []bool{false, true} {
2896 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002897 if with {
2898 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002899 }
2900
2901 for _, isClient := range []bool{false, true} {
2902 suffix := "-Server"
2903 testType := serverTest
2904 if isClient {
2905 suffix = "-Client"
2906 testType = clientTest
2907 }
2908
2909 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002910 // In TLS 1.3, the extension is irrelevant and
2911 // always reports as enabled.
2912 var flags []string
2913 if with || ver.version >= VersionTLS13 {
2914 flags = []string{expectEMSFlag}
2915 }
2916
Adam Langley75712922014-10-10 16:23:43 -07002917 test := testCase{
2918 testType: testType,
2919 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2920 config: Config{
2921 MinVersion: ver.version,
2922 MaxVersion: ver.version,
2923 Bugs: ProtocolBugs{
2924 NoExtendedMasterSecret: !with,
2925 RequireExtendedMasterSecret: with,
2926 },
2927 },
David Benjamin48cae082014-10-27 01:06:24 -04002928 flags: flags,
2929 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002930 }
2931 if test.shouldFail {
2932 test.expectedLocalError = "extended master secret required but not supported by peer"
2933 }
2934 testCases = append(testCases, test)
2935 }
2936 }
2937 }
2938
Adam Langleyba5934b2015-06-02 10:50:35 -07002939 for _, isClient := range []bool{false, true} {
2940 for _, supportedInFirstConnection := range []bool{false, true} {
2941 for _, supportedInResumeConnection := range []bool{false, true} {
2942 boolToWord := func(b bool) string {
2943 if b {
2944 return "Yes"
2945 }
2946 return "No"
2947 }
2948 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2949 if isClient {
2950 suffix += "Client"
2951 } else {
2952 suffix += "Server"
2953 }
2954
2955 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002956 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002957 Bugs: ProtocolBugs{
2958 RequireExtendedMasterSecret: true,
2959 },
2960 }
2961
2962 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002963 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002964 Bugs: ProtocolBugs{
2965 NoExtendedMasterSecret: true,
2966 },
2967 }
2968
2969 test := testCase{
2970 name: "ExtendedMasterSecret-" + suffix,
2971 resumeSession: true,
2972 }
2973
2974 if !isClient {
2975 test.testType = serverTest
2976 }
2977
2978 if supportedInFirstConnection {
2979 test.config = supportedConfig
2980 } else {
2981 test.config = noSupportConfig
2982 }
2983
2984 if supportedInResumeConnection {
2985 test.resumeConfig = &supportedConfig
2986 } else {
2987 test.resumeConfig = &noSupportConfig
2988 }
2989
2990 switch suffix {
2991 case "YesToYes-Client", "YesToYes-Server":
2992 // When a session is resumed, it should
2993 // still be aware that its master
2994 // secret was generated via EMS and
2995 // thus it's safe to use tls-unique.
2996 test.flags = []string{expectEMSFlag}
2997 case "NoToYes-Server":
2998 // If an original connection did not
2999 // contain EMS, but a resumption
3000 // handshake does, then a server should
3001 // not resume the session.
3002 test.expectResumeRejected = true
3003 case "YesToNo-Server":
3004 // Resuming an EMS session without the
3005 // EMS extension should cause the
3006 // server to abort the connection.
3007 test.shouldFail = true
3008 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3009 case "NoToYes-Client":
3010 // A client should abort a connection
3011 // where the server resumed a non-EMS
3012 // session but echoed the EMS
3013 // extension.
3014 test.shouldFail = true
3015 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3016 case "YesToNo-Client":
3017 // A client should abort a connection
3018 // where the server didn't echo EMS
3019 // when the session used it.
3020 test.shouldFail = true
3021 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3022 }
3023
3024 testCases = append(testCases, test)
3025 }
3026 }
3027 }
Adam Langley75712922014-10-10 16:23:43 -07003028}
3029
David Benjamin582ba042016-07-07 12:33:25 -07003030type stateMachineTestConfig struct {
3031 protocol protocol
3032 async bool
3033 splitHandshake, packHandshakeFlight bool
3034}
3035
David Benjamin43ec06f2014-08-05 02:28:57 -04003036// Adds tests that try to cover the range of the handshake state machine, under
3037// various conditions. Some of these are redundant with other tests, but they
3038// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003039func addAllStateMachineCoverageTests() {
3040 for _, async := range []bool{false, true} {
3041 for _, protocol := range []protocol{tls, dtls} {
3042 addStateMachineCoverageTests(stateMachineTestConfig{
3043 protocol: protocol,
3044 async: async,
3045 })
3046 addStateMachineCoverageTests(stateMachineTestConfig{
3047 protocol: protocol,
3048 async: async,
3049 splitHandshake: true,
3050 })
3051 if protocol == tls {
3052 addStateMachineCoverageTests(stateMachineTestConfig{
3053 protocol: protocol,
3054 async: async,
3055 packHandshakeFlight: true,
3056 })
3057 }
3058 }
3059 }
3060}
3061
3062func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003063 var tests []testCase
3064
3065 // Basic handshake, with resumption. Client and server,
3066 // session ID and session ticket.
3067 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003068 name: "Basic-Client",
3069 config: Config{
3070 MaxVersion: VersionTLS12,
3071 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003072 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003073 // Ensure session tickets are used, not session IDs.
3074 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003075 })
3076 tests = append(tests, testCase{
3077 name: "Basic-Client-RenewTicket",
3078 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003079 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003080 Bugs: ProtocolBugs{
3081 RenewTicketOnResume: true,
3082 },
3083 },
David Benjamin46662482016-08-17 00:51:00 -04003084 flags: []string{"-expect-ticket-renewal"},
3085 resumeSession: true,
3086 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003087 })
3088 tests = append(tests, testCase{
3089 name: "Basic-Client-NoTicket",
3090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003091 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003092 SessionTicketsDisabled: true,
3093 },
3094 resumeSession: true,
3095 })
3096 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003097 name: "Basic-Client-Implicit",
3098 config: Config{
3099 MaxVersion: VersionTLS12,
3100 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003101 flags: []string{"-implicit-handshake"},
3102 resumeSession: true,
3103 })
3104 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003105 testType: serverTest,
3106 name: "Basic-Server",
3107 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003108 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003109 Bugs: ProtocolBugs{
3110 RequireSessionTickets: true,
3111 },
3112 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003113 resumeSession: true,
3114 })
3115 tests = append(tests, testCase{
3116 testType: serverTest,
3117 name: "Basic-Server-NoTickets",
3118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003119 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003120 SessionTicketsDisabled: true,
3121 },
3122 resumeSession: true,
3123 })
3124 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003125 testType: serverTest,
3126 name: "Basic-Server-Implicit",
3127 config: Config{
3128 MaxVersion: VersionTLS12,
3129 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003130 flags: []string{"-implicit-handshake"},
3131 resumeSession: true,
3132 })
3133 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003134 testType: serverTest,
3135 name: "Basic-Server-EarlyCallback",
3136 config: Config{
3137 MaxVersion: VersionTLS12,
3138 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003139 flags: []string{"-use-early-callback"},
3140 resumeSession: true,
3141 })
3142
Steven Valdez143e8b32016-07-11 13:19:03 -04003143 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003144 if config.protocol == tls {
3145 tests = append(tests, testCase{
3146 name: "TLS13-1RTT-Client",
3147 config: Config{
3148 MaxVersion: VersionTLS13,
3149 MinVersion: VersionTLS13,
3150 },
David Benjamin46662482016-08-17 00:51:00 -04003151 resumeSession: true,
3152 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003153 })
3154
3155 tests = append(tests, testCase{
3156 testType: serverTest,
3157 name: "TLS13-1RTT-Server",
3158 config: Config{
3159 MaxVersion: VersionTLS13,
3160 MinVersion: VersionTLS13,
3161 },
David Benjamin46662482016-08-17 00:51:00 -04003162 resumeSession: true,
3163 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003164 })
3165
3166 tests = append(tests, testCase{
3167 name: "TLS13-HelloRetryRequest-Client",
3168 config: Config{
3169 MaxVersion: VersionTLS13,
3170 MinVersion: VersionTLS13,
3171 // P-384 requires a HelloRetryRequest against
3172 // BoringSSL's default configuration. Assert
3173 // that we do indeed test this with
3174 // ExpectMissingKeyShare.
3175 CurvePreferences: []CurveID{CurveP384},
3176 Bugs: ProtocolBugs{
3177 ExpectMissingKeyShare: true,
3178 },
3179 },
3180 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3181 resumeSession: true,
3182 })
3183
3184 tests = append(tests, testCase{
3185 testType: serverTest,
3186 name: "TLS13-HelloRetryRequest-Server",
3187 config: Config{
3188 MaxVersion: VersionTLS13,
3189 MinVersion: VersionTLS13,
3190 // Require a HelloRetryRequest for every curve.
3191 DefaultCurves: []CurveID{},
3192 },
3193 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3194 resumeSession: true,
3195 })
3196 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003197
David Benjamin760b1dd2015-05-15 23:33:48 -04003198 // TLS client auth.
3199 tests = append(tests, testCase{
3200 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003201 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003202 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003203 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003204 ClientAuth: RequestClientCert,
3205 },
3206 })
3207 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003208 testType: serverTest,
3209 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003210 config: Config{
3211 MaxVersion: VersionTLS12,
3212 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003213 // Setting SSL_VERIFY_PEER allows anonymous clients.
3214 flags: []string{"-verify-peer"},
3215 })
David Benjamin582ba042016-07-07 12:33:25 -07003216 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003217 tests = append(tests, testCase{
3218 testType: clientTest,
3219 name: "ClientAuth-NoCertificate-Client-SSL3",
3220 config: Config{
3221 MaxVersion: VersionSSL30,
3222 ClientAuth: RequestClientCert,
3223 },
3224 })
3225 tests = append(tests, testCase{
3226 testType: serverTest,
3227 name: "ClientAuth-NoCertificate-Server-SSL3",
3228 config: Config{
3229 MaxVersion: VersionSSL30,
3230 },
3231 // Setting SSL_VERIFY_PEER allows anonymous clients.
3232 flags: []string{"-verify-peer"},
3233 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003234 tests = append(tests, testCase{
3235 testType: clientTest,
3236 name: "ClientAuth-NoCertificate-Client-TLS13",
3237 config: Config{
3238 MaxVersion: VersionTLS13,
3239 ClientAuth: RequestClientCert,
3240 },
3241 })
3242 tests = append(tests, testCase{
3243 testType: serverTest,
3244 name: "ClientAuth-NoCertificate-Server-TLS13",
3245 config: Config{
3246 MaxVersion: VersionTLS13,
3247 },
3248 // Setting SSL_VERIFY_PEER allows anonymous clients.
3249 flags: []string{"-verify-peer"},
3250 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003251 }
3252 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003253 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003254 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003255 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003256 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003257 ClientAuth: RequireAnyClientCert,
3258 },
3259 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003260 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3261 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003262 },
3263 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003264 tests = append(tests, testCase{
3265 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003266 name: "ClientAuth-RSA-Client-TLS13",
3267 config: Config{
3268 MaxVersion: VersionTLS13,
3269 ClientAuth: RequireAnyClientCert,
3270 },
3271 flags: []string{
3272 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3273 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3274 },
3275 })
3276 tests = append(tests, testCase{
3277 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003278 name: "ClientAuth-ECDSA-Client",
3279 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003280 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003281 ClientAuth: RequireAnyClientCert,
3282 },
3283 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003284 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3285 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003286 },
3287 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003288 tests = append(tests, testCase{
3289 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003290 name: "ClientAuth-ECDSA-Client-TLS13",
3291 config: Config{
3292 MaxVersion: VersionTLS13,
3293 ClientAuth: RequireAnyClientCert,
3294 },
3295 flags: []string{
3296 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3297 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3298 },
3299 })
3300 tests = append(tests, testCase{
3301 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003302 name: "ClientAuth-NoCertificate-OldCallback",
3303 config: Config{
3304 MaxVersion: VersionTLS12,
3305 ClientAuth: RequestClientCert,
3306 },
3307 flags: []string{"-use-old-client-cert-callback"},
3308 })
3309 tests = append(tests, testCase{
3310 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003311 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3312 config: Config{
3313 MaxVersion: VersionTLS13,
3314 ClientAuth: RequestClientCert,
3315 },
3316 flags: []string{"-use-old-client-cert-callback"},
3317 })
3318 tests = append(tests, testCase{
3319 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003320 name: "ClientAuth-OldCallback",
3321 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003322 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003323 ClientAuth: RequireAnyClientCert,
3324 },
3325 flags: []string{
3326 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3327 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3328 "-use-old-client-cert-callback",
3329 },
3330 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003331 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003332 testType: clientTest,
3333 name: "ClientAuth-OldCallback-TLS13",
3334 config: Config{
3335 MaxVersion: VersionTLS13,
3336 ClientAuth: RequireAnyClientCert,
3337 },
3338 flags: []string{
3339 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3340 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3341 "-use-old-client-cert-callback",
3342 },
3343 })
3344 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003345 testType: serverTest,
3346 name: "ClientAuth-Server",
3347 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003348 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003349 Certificates: []Certificate{rsaCertificate},
3350 },
3351 flags: []string{"-require-any-client-certificate"},
3352 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003353 tests = append(tests, testCase{
3354 testType: serverTest,
3355 name: "ClientAuth-Server-TLS13",
3356 config: Config{
3357 MaxVersion: VersionTLS13,
3358 Certificates: []Certificate{rsaCertificate},
3359 },
3360 flags: []string{"-require-any-client-certificate"},
3361 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003362
David Benjamin4c3ddf72016-06-29 18:13:53 -04003363 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003364 tests = append(tests, testCase{
3365 testType: serverTest,
3366 name: "Basic-Server-RSA",
3367 config: Config{
3368 MaxVersion: VersionTLS12,
3369 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3370 },
3371 flags: []string{
3372 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3373 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3374 },
3375 })
3376 tests = append(tests, testCase{
3377 testType: serverTest,
3378 name: "Basic-Server-ECDHE-RSA",
3379 config: Config{
3380 MaxVersion: VersionTLS12,
3381 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3382 },
3383 flags: []string{
3384 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3385 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3386 },
3387 })
3388 tests = append(tests, testCase{
3389 testType: serverTest,
3390 name: "Basic-Server-ECDHE-ECDSA",
3391 config: Config{
3392 MaxVersion: VersionTLS12,
3393 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3394 },
3395 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003396 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3397 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003398 },
3399 })
3400
David Benjamin760b1dd2015-05-15 23:33:48 -04003401 // No session ticket support; server doesn't send NewSessionTicket.
3402 tests = append(tests, testCase{
3403 name: "SessionTicketsDisabled-Client",
3404 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003405 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003406 SessionTicketsDisabled: true,
3407 },
3408 })
3409 tests = append(tests, testCase{
3410 testType: serverTest,
3411 name: "SessionTicketsDisabled-Server",
3412 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003413 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003414 SessionTicketsDisabled: true,
3415 },
3416 })
3417
3418 // Skip ServerKeyExchange in PSK key exchange if there's no
3419 // identity hint.
3420 tests = append(tests, testCase{
3421 name: "EmptyPSKHint-Client",
3422 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003423 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003424 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3425 PreSharedKey: []byte("secret"),
3426 },
3427 flags: []string{"-psk", "secret"},
3428 })
3429 tests = append(tests, testCase{
3430 testType: serverTest,
3431 name: "EmptyPSKHint-Server",
3432 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003433 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003434 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3435 PreSharedKey: []byte("secret"),
3436 },
3437 flags: []string{"-psk", "secret"},
3438 })
3439
David Benjamin4c3ddf72016-06-29 18:13:53 -04003440 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003441 tests = append(tests, testCase{
3442 testType: clientTest,
3443 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003444 config: Config{
3445 MaxVersion: VersionTLS12,
3446 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003447 flags: []string{
3448 "-enable-ocsp-stapling",
3449 "-expect-ocsp-response",
3450 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003451 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003452 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003453 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003454 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003455 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003456 testType: serverTest,
3457 name: "OCSPStapling-Server",
3458 config: Config{
3459 MaxVersion: VersionTLS12,
3460 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003461 expectedOCSPResponse: testOCSPResponse,
3462 flags: []string{
3463 "-ocsp-response",
3464 base64.StdEncoding.EncodeToString(testOCSPResponse),
3465 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003466 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003467 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003468 tests = append(tests, testCase{
3469 testType: clientTest,
3470 name: "OCSPStapling-Client-TLS13",
3471 config: Config{
3472 MaxVersion: VersionTLS13,
3473 },
3474 flags: []string{
3475 "-enable-ocsp-stapling",
3476 "-expect-ocsp-response",
3477 base64.StdEncoding.EncodeToString(testOCSPResponse),
3478 "-verify-peer",
3479 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003480 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003481 })
3482 tests = append(tests, testCase{
3483 testType: serverTest,
3484 name: "OCSPStapling-Server-TLS13",
3485 config: Config{
3486 MaxVersion: VersionTLS13,
3487 },
3488 expectedOCSPResponse: testOCSPResponse,
3489 flags: []string{
3490 "-ocsp-response",
3491 base64.StdEncoding.EncodeToString(testOCSPResponse),
3492 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003493 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003494 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003495
David Benjamin4c3ddf72016-06-29 18:13:53 -04003496 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003497 for _, vers := range tlsVersions {
3498 if config.protocol == dtls && !vers.hasDTLS {
3499 continue
3500 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003501 for _, testType := range []testType{clientTest, serverTest} {
3502 suffix := "-Client"
3503 if testType == serverTest {
3504 suffix = "-Server"
3505 }
3506 suffix += "-" + vers.name
3507
3508 flag := "-verify-peer"
3509 if testType == serverTest {
3510 flag = "-require-any-client-certificate"
3511 }
3512
3513 tests = append(tests, testCase{
3514 testType: testType,
3515 name: "CertificateVerificationSucceed" + suffix,
3516 config: Config{
3517 MaxVersion: vers.version,
3518 Certificates: []Certificate{rsaCertificate},
3519 },
3520 flags: []string{
3521 flag,
3522 "-expect-verify-result",
3523 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003524 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003525 })
3526 tests = append(tests, testCase{
3527 testType: testType,
3528 name: "CertificateVerificationFail" + suffix,
3529 config: Config{
3530 MaxVersion: vers.version,
3531 Certificates: []Certificate{rsaCertificate},
3532 },
3533 flags: []string{
3534 flag,
3535 "-verify-fail",
3536 },
3537 shouldFail: true,
3538 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3539 })
3540 }
3541
3542 // By default, the client is in a soft fail mode where the peer
3543 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003544 tests = append(tests, testCase{
3545 testType: clientTest,
3546 name: "CertificateVerificationSoftFail-" + vers.name,
3547 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003548 MaxVersion: vers.version,
3549 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003550 },
3551 flags: []string{
3552 "-verify-fail",
3553 "-expect-verify-result",
3554 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003555 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003556 })
3557 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003558
David Benjamin1d4f4c02016-07-26 18:03:08 -04003559 tests = append(tests, testCase{
3560 name: "ShimSendAlert",
3561 flags: []string{"-send-alert"},
3562 shimWritesFirst: true,
3563 shouldFail: true,
3564 expectedLocalError: "remote error: decompression failure",
3565 })
3566
David Benjamin582ba042016-07-07 12:33:25 -07003567 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003568 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003569 name: "Renegotiate-Client",
3570 config: Config{
3571 MaxVersion: VersionTLS12,
3572 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003573 renegotiate: 1,
3574 flags: []string{
3575 "-renegotiate-freely",
3576 "-expect-total-renegotiations", "1",
3577 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003578 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003579
David Benjamin47921102016-07-28 11:29:18 -04003580 tests = append(tests, testCase{
3581 name: "SendHalfHelloRequest",
3582 config: Config{
3583 MaxVersion: VersionTLS12,
3584 Bugs: ProtocolBugs{
3585 PackHelloRequestWithFinished: config.packHandshakeFlight,
3586 },
3587 },
3588 sendHalfHelloRequest: true,
3589 flags: []string{"-renegotiate-ignore"},
3590 shouldFail: true,
3591 expectedError: ":UNEXPECTED_RECORD:",
3592 })
3593
David Benjamin760b1dd2015-05-15 23:33:48 -04003594 // NPN on client and server; results in post-handshake message.
3595 tests = append(tests, testCase{
3596 name: "NPN-Client",
3597 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003598 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003599 NextProtos: []string{"foo"},
3600 },
3601 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003602 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003603 expectedNextProto: "foo",
3604 expectedNextProtoType: npn,
3605 })
3606 tests = append(tests, testCase{
3607 testType: serverTest,
3608 name: "NPN-Server",
3609 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003610 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003611 NextProtos: []string{"bar"},
3612 },
3613 flags: []string{
3614 "-advertise-npn", "\x03foo\x03bar\x03baz",
3615 "-expect-next-proto", "bar",
3616 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003617 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003618 expectedNextProto: "bar",
3619 expectedNextProtoType: npn,
3620 })
3621
3622 // TODO(davidben): Add tests for when False Start doesn't trigger.
3623
3624 // Client does False Start and negotiates NPN.
3625 tests = append(tests, testCase{
3626 name: "FalseStart",
3627 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003628 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003629 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3630 NextProtos: []string{"foo"},
3631 Bugs: ProtocolBugs{
3632 ExpectFalseStart: true,
3633 },
3634 },
3635 flags: []string{
3636 "-false-start",
3637 "-select-next-proto", "foo",
3638 },
3639 shimWritesFirst: true,
3640 resumeSession: true,
3641 })
3642
3643 // Client does False Start and negotiates ALPN.
3644 tests = append(tests, testCase{
3645 name: "FalseStart-ALPN",
3646 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003647 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003648 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3649 NextProtos: []string{"foo"},
3650 Bugs: ProtocolBugs{
3651 ExpectFalseStart: true,
3652 },
3653 },
3654 flags: []string{
3655 "-false-start",
3656 "-advertise-alpn", "\x03foo",
3657 },
3658 shimWritesFirst: true,
3659 resumeSession: true,
3660 })
3661
3662 // Client does False Start but doesn't explicitly call
3663 // SSL_connect.
3664 tests = append(tests, testCase{
3665 name: "FalseStart-Implicit",
3666 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003667 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003668 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3669 NextProtos: []string{"foo"},
3670 },
3671 flags: []string{
3672 "-implicit-handshake",
3673 "-false-start",
3674 "-advertise-alpn", "\x03foo",
3675 },
3676 })
3677
3678 // False Start without session tickets.
3679 tests = append(tests, testCase{
3680 name: "FalseStart-SessionTicketsDisabled",
3681 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003682 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003683 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3684 NextProtos: []string{"foo"},
3685 SessionTicketsDisabled: true,
3686 Bugs: ProtocolBugs{
3687 ExpectFalseStart: true,
3688 },
3689 },
3690 flags: []string{
3691 "-false-start",
3692 "-select-next-proto", "foo",
3693 },
3694 shimWritesFirst: true,
3695 })
3696
Adam Langleydf759b52016-07-11 15:24:37 -07003697 tests = append(tests, testCase{
3698 name: "FalseStart-CECPQ1",
3699 config: Config{
3700 MaxVersion: VersionTLS12,
3701 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3702 NextProtos: []string{"foo"},
3703 Bugs: ProtocolBugs{
3704 ExpectFalseStart: true,
3705 },
3706 },
3707 flags: []string{
3708 "-false-start",
3709 "-cipher", "DEFAULT:kCECPQ1",
3710 "-select-next-proto", "foo",
3711 },
3712 shimWritesFirst: true,
3713 resumeSession: true,
3714 })
3715
David Benjamin760b1dd2015-05-15 23:33:48 -04003716 // Server parses a V2ClientHello.
3717 tests = append(tests, testCase{
3718 testType: serverTest,
3719 name: "SendV2ClientHello",
3720 config: Config{
3721 // Choose a cipher suite that does not involve
3722 // elliptic curves, so no extensions are
3723 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003724 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003725 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3726 Bugs: ProtocolBugs{
3727 SendV2ClientHello: true,
3728 },
3729 },
3730 })
3731
3732 // Client sends a Channel ID.
3733 tests = append(tests, testCase{
3734 name: "ChannelID-Client",
3735 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003736 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003737 RequestChannelID: true,
3738 },
Adam Langley7c803a62015-06-15 15:35:05 -07003739 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003740 resumeSession: true,
3741 expectChannelID: true,
3742 })
3743
3744 // Server accepts a Channel ID.
3745 tests = append(tests, testCase{
3746 testType: serverTest,
3747 name: "ChannelID-Server",
3748 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003749 MaxVersion: VersionTLS12,
3750 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003751 },
3752 flags: []string{
3753 "-expect-channel-id",
3754 base64.StdEncoding.EncodeToString(channelIDBytes),
3755 },
3756 resumeSession: true,
3757 expectChannelID: true,
3758 })
David Benjamin30789da2015-08-29 22:56:45 -04003759
David Benjaminf8fcdf32016-06-08 15:56:13 -04003760 // Channel ID and NPN at the same time, to ensure their relative
3761 // ordering is correct.
3762 tests = append(tests, testCase{
3763 name: "ChannelID-NPN-Client",
3764 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003765 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003766 RequestChannelID: true,
3767 NextProtos: []string{"foo"},
3768 },
3769 flags: []string{
3770 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3771 "-select-next-proto", "foo",
3772 },
3773 resumeSession: true,
3774 expectChannelID: true,
3775 expectedNextProto: "foo",
3776 expectedNextProtoType: npn,
3777 })
3778 tests = append(tests, testCase{
3779 testType: serverTest,
3780 name: "ChannelID-NPN-Server",
3781 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003782 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003783 ChannelID: channelIDKey,
3784 NextProtos: []string{"bar"},
3785 },
3786 flags: []string{
3787 "-expect-channel-id",
3788 base64.StdEncoding.EncodeToString(channelIDBytes),
3789 "-advertise-npn", "\x03foo\x03bar\x03baz",
3790 "-expect-next-proto", "bar",
3791 },
3792 resumeSession: true,
3793 expectChannelID: true,
3794 expectedNextProto: "bar",
3795 expectedNextProtoType: npn,
3796 })
3797
David Benjamin30789da2015-08-29 22:56:45 -04003798 // Bidirectional shutdown with the runner initiating.
3799 tests = append(tests, testCase{
3800 name: "Shutdown-Runner",
3801 config: Config{
3802 Bugs: ProtocolBugs{
3803 ExpectCloseNotify: true,
3804 },
3805 },
3806 flags: []string{"-check-close-notify"},
3807 })
3808
3809 // Bidirectional shutdown with the shim initiating. The runner,
3810 // in the meantime, sends garbage before the close_notify which
3811 // the shim must ignore.
3812 tests = append(tests, testCase{
3813 name: "Shutdown-Shim",
3814 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003815 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003816 Bugs: ProtocolBugs{
3817 ExpectCloseNotify: true,
3818 },
3819 },
3820 shimShutsDown: true,
3821 sendEmptyRecords: 1,
3822 sendWarningAlerts: 1,
3823 flags: []string{"-check-close-notify"},
3824 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003825 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003826 // TODO(davidben): DTLS 1.3 will want a similar thing for
3827 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003828 tests = append(tests, testCase{
3829 name: "SkipHelloVerifyRequest",
3830 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003831 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003832 Bugs: ProtocolBugs{
3833 SkipHelloVerifyRequest: true,
3834 },
3835 },
3836 })
3837 }
3838
David Benjamin760b1dd2015-05-15 23:33:48 -04003839 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003840 test.protocol = config.protocol
3841 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003842 test.name += "-DTLS"
3843 }
David Benjamin582ba042016-07-07 12:33:25 -07003844 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003845 test.name += "-Async"
3846 test.flags = append(test.flags, "-async")
3847 } else {
3848 test.name += "-Sync"
3849 }
David Benjamin582ba042016-07-07 12:33:25 -07003850 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003851 test.name += "-SplitHandshakeRecords"
3852 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003853 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003854 test.config.Bugs.MaxPacketLength = 256
3855 test.flags = append(test.flags, "-mtu", "256")
3856 }
3857 }
David Benjamin582ba042016-07-07 12:33:25 -07003858 if config.packHandshakeFlight {
3859 test.name += "-PackHandshakeFlight"
3860 test.config.Bugs.PackHandshakeFlight = true
3861 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003862 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003863 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003864}
3865
Adam Langley524e7172015-02-20 16:04:00 -08003866func addDDoSCallbackTests() {
3867 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08003868 for _, resume := range []bool{false, true} {
3869 suffix := "Resume"
3870 if resume {
3871 suffix = "No" + suffix
3872 }
3873
3874 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003875 testType: serverTest,
3876 name: "Server-DDoS-OK-" + suffix,
3877 config: Config{
3878 MaxVersion: VersionTLS12,
3879 },
Adam Langley524e7172015-02-20 16:04:00 -08003880 flags: []string{"-install-ddos-callback"},
3881 resumeSession: resume,
3882 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003883 testCases = append(testCases, testCase{
3884 testType: serverTest,
3885 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3886 config: Config{
3887 MaxVersion: VersionTLS13,
3888 },
3889 flags: []string{"-install-ddos-callback"},
3890 resumeSession: resume,
3891 })
Adam Langley524e7172015-02-20 16:04:00 -08003892
3893 failFlag := "-fail-ddos-callback"
3894 if resume {
3895 failFlag = "-fail-second-ddos-callback"
3896 }
3897 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003898 testType: serverTest,
3899 name: "Server-DDoS-Reject-" + suffix,
3900 config: Config{
3901 MaxVersion: VersionTLS12,
3902 },
Adam Langley524e7172015-02-20 16:04:00 -08003903 flags: []string{"-install-ddos-callback", failFlag},
3904 resumeSession: resume,
3905 shouldFail: true,
3906 expectedError: ":CONNECTION_REJECTED:",
3907 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04003908 testCases = append(testCases, testCase{
3909 testType: serverTest,
3910 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3911 config: Config{
3912 MaxVersion: VersionTLS13,
3913 },
3914 flags: []string{"-install-ddos-callback", failFlag},
3915 resumeSession: resume,
3916 shouldFail: true,
3917 expectedError: ":CONNECTION_REJECTED:",
3918 })
Adam Langley524e7172015-02-20 16:04:00 -08003919 }
3920}
3921
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003922func addVersionNegotiationTests() {
3923 for i, shimVers := range tlsVersions {
3924 // Assemble flags to disable all newer versions on the shim.
3925 var flags []string
3926 for _, vers := range tlsVersions[i+1:] {
3927 flags = append(flags, vers.flag)
3928 }
3929
3930 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003931 protocols := []protocol{tls}
3932 if runnerVers.hasDTLS && shimVers.hasDTLS {
3933 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003934 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003935 for _, protocol := range protocols {
3936 expectedVersion := shimVers.version
3937 if runnerVers.version < shimVers.version {
3938 expectedVersion = runnerVers.version
3939 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003940
David Benjamin8b8c0062014-11-23 02:47:52 -05003941 suffix := shimVers.name + "-" + runnerVers.name
3942 if protocol == dtls {
3943 suffix += "-DTLS"
3944 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003945
David Benjamin1eb367c2014-12-12 18:17:51 -05003946 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3947
David Benjamin1e29a6b2014-12-10 02:27:24 -05003948 clientVers := shimVers.version
3949 if clientVers > VersionTLS10 {
3950 clientVers = VersionTLS10
3951 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003952 serverVers := expectedVersion
3953 if expectedVersion >= VersionTLS13 {
3954 serverVers = VersionTLS10
3955 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003956 testCases = append(testCases, testCase{
3957 protocol: protocol,
3958 testType: clientTest,
3959 name: "VersionNegotiation-Client-" + suffix,
3960 config: Config{
3961 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003962 Bugs: ProtocolBugs{
3963 ExpectInitialRecordVersion: clientVers,
3964 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003965 },
3966 flags: flags,
3967 expectedVersion: expectedVersion,
3968 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003969 testCases = append(testCases, testCase{
3970 protocol: protocol,
3971 testType: clientTest,
3972 name: "VersionNegotiation-Client2-" + suffix,
3973 config: Config{
3974 MaxVersion: runnerVers.version,
3975 Bugs: ProtocolBugs{
3976 ExpectInitialRecordVersion: clientVers,
3977 },
3978 },
3979 flags: []string{"-max-version", shimVersFlag},
3980 expectedVersion: expectedVersion,
3981 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003982
3983 testCases = append(testCases, testCase{
3984 protocol: protocol,
3985 testType: serverTest,
3986 name: "VersionNegotiation-Server-" + suffix,
3987 config: Config{
3988 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003989 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003990 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003991 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003992 },
3993 flags: flags,
3994 expectedVersion: expectedVersion,
3995 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003996 testCases = append(testCases, testCase{
3997 protocol: protocol,
3998 testType: serverTest,
3999 name: "VersionNegotiation-Server2-" + suffix,
4000 config: Config{
4001 MaxVersion: runnerVers.version,
4002 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004003 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004004 },
4005 },
4006 flags: []string{"-max-version", shimVersFlag},
4007 expectedVersion: expectedVersion,
4008 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004009 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004010 }
4011 }
David Benjamin95c69562016-06-29 18:15:03 -04004012
4013 // Test for version tolerance.
4014 testCases = append(testCases, testCase{
4015 testType: serverTest,
4016 name: "MinorVersionTolerance",
4017 config: Config{
4018 Bugs: ProtocolBugs{
4019 SendClientVersion: 0x03ff,
4020 },
4021 },
4022 expectedVersion: VersionTLS13,
4023 })
4024 testCases = append(testCases, testCase{
4025 testType: serverTest,
4026 name: "MajorVersionTolerance",
4027 config: Config{
4028 Bugs: ProtocolBugs{
4029 SendClientVersion: 0x0400,
4030 },
4031 },
4032 expectedVersion: VersionTLS13,
4033 })
4034 testCases = append(testCases, testCase{
4035 protocol: dtls,
4036 testType: serverTest,
4037 name: "MinorVersionTolerance-DTLS",
4038 config: Config{
4039 Bugs: ProtocolBugs{
4040 SendClientVersion: 0x03ff,
4041 },
4042 },
4043 expectedVersion: VersionTLS12,
4044 })
4045 testCases = append(testCases, testCase{
4046 protocol: dtls,
4047 testType: serverTest,
4048 name: "MajorVersionTolerance-DTLS",
4049 config: Config{
4050 Bugs: ProtocolBugs{
4051 SendClientVersion: 0x0400,
4052 },
4053 },
4054 expectedVersion: VersionTLS12,
4055 })
4056
4057 // Test that versions below 3.0 are rejected.
4058 testCases = append(testCases, testCase{
4059 testType: serverTest,
4060 name: "VersionTooLow",
4061 config: Config{
4062 Bugs: ProtocolBugs{
4063 SendClientVersion: 0x0200,
4064 },
4065 },
4066 shouldFail: true,
4067 expectedError: ":UNSUPPORTED_PROTOCOL:",
4068 })
4069 testCases = append(testCases, testCase{
4070 protocol: dtls,
4071 testType: serverTest,
4072 name: "VersionTooLow-DTLS",
4073 config: Config{
4074 Bugs: ProtocolBugs{
4075 // 0x0201 is the lowest version expressable in
4076 // DTLS.
4077 SendClientVersion: 0x0201,
4078 },
4079 },
4080 shouldFail: true,
4081 expectedError: ":UNSUPPORTED_PROTOCOL:",
4082 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004083
4084 // Test TLS 1.3's downgrade signal.
4085 testCases = append(testCases, testCase{
4086 name: "Downgrade-TLS12-Client",
4087 config: Config{
4088 Bugs: ProtocolBugs{
4089 NegotiateVersion: VersionTLS12,
4090 },
4091 },
4092 shouldFail: true,
4093 expectedError: ":DOWNGRADE_DETECTED:",
4094 })
4095 testCases = append(testCases, testCase{
4096 testType: serverTest,
4097 name: "Downgrade-TLS12-Server",
4098 config: Config{
4099 Bugs: ProtocolBugs{
4100 SendClientVersion: VersionTLS12,
4101 },
4102 },
4103 shouldFail: true,
4104 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4105 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004106
4107 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4108 // behave correctly when both real maximum and fallback versions are
4109 // set.
4110 testCases = append(testCases, testCase{
4111 name: "Downgrade-TLS12-Client-Fallback",
4112 config: Config{
4113 Bugs: ProtocolBugs{
4114 FailIfNotFallbackSCSV: true,
4115 },
4116 },
4117 flags: []string{
4118 "-max-version", strconv.Itoa(VersionTLS13),
4119 "-fallback-version", strconv.Itoa(VersionTLS12),
4120 },
4121 shouldFail: true,
4122 expectedError: ":DOWNGRADE_DETECTED:",
4123 })
4124 testCases = append(testCases, testCase{
4125 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4126 flags: []string{
4127 "-max-version", strconv.Itoa(VersionTLS12),
4128 "-fallback-version", strconv.Itoa(VersionTLS12),
4129 },
4130 })
4131
4132 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4133 // just have such connections fail than risk getting confused because we
4134 // didn't sent the 1.3 ClientHello.)
4135 testCases = append(testCases, testCase{
4136 name: "Downgrade-TLS12-Fallback-CheckVersion",
4137 config: Config{
4138 Bugs: ProtocolBugs{
4139 NegotiateVersion: VersionTLS13,
4140 FailIfNotFallbackSCSV: true,
4141 },
4142 },
4143 flags: []string{
4144 "-max-version", strconv.Itoa(VersionTLS13),
4145 "-fallback-version", strconv.Itoa(VersionTLS12),
4146 },
4147 shouldFail: true,
4148 expectedError: ":UNSUPPORTED_PROTOCOL:",
4149 })
4150
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004151}
4152
David Benjaminaccb4542014-12-12 23:44:33 -05004153func addMinimumVersionTests() {
4154 for i, shimVers := range tlsVersions {
4155 // Assemble flags to disable all older versions on the shim.
4156 var flags []string
4157 for _, vers := range tlsVersions[:i] {
4158 flags = append(flags, vers.flag)
4159 }
4160
4161 for _, runnerVers := range tlsVersions {
4162 protocols := []protocol{tls}
4163 if runnerVers.hasDTLS && shimVers.hasDTLS {
4164 protocols = append(protocols, dtls)
4165 }
4166 for _, protocol := range protocols {
4167 suffix := shimVers.name + "-" + runnerVers.name
4168 if protocol == dtls {
4169 suffix += "-DTLS"
4170 }
4171 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4172
David Benjaminaccb4542014-12-12 23:44:33 -05004173 var expectedVersion uint16
4174 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004175 var expectedClientError, expectedServerError string
4176 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004177 if runnerVers.version >= shimVers.version {
4178 expectedVersion = runnerVers.version
4179 } else {
4180 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004181 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4182 expectedServerLocalError = "remote error: protocol version not supported"
4183 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4184 // If the client's minimum version is TLS 1.3 and the runner's
4185 // maximum is below TLS 1.2, the runner will fail to select a
4186 // cipher before the shim rejects the selected version.
4187 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4188 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4189 } else {
4190 expectedClientError = expectedServerError
4191 expectedClientLocalError = expectedServerLocalError
4192 }
David Benjaminaccb4542014-12-12 23:44:33 -05004193 }
4194
4195 testCases = append(testCases, testCase{
4196 protocol: protocol,
4197 testType: clientTest,
4198 name: "MinimumVersion-Client-" + suffix,
4199 config: Config{
4200 MaxVersion: runnerVers.version,
4201 },
David Benjamin87909c02014-12-13 01:55:01 -05004202 flags: flags,
4203 expectedVersion: expectedVersion,
4204 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004205 expectedError: expectedClientError,
4206 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004207 })
4208 testCases = append(testCases, testCase{
4209 protocol: protocol,
4210 testType: clientTest,
4211 name: "MinimumVersion-Client2-" + suffix,
4212 config: Config{
4213 MaxVersion: runnerVers.version,
4214 },
David Benjamin87909c02014-12-13 01:55:01 -05004215 flags: []string{"-min-version", shimVersFlag},
4216 expectedVersion: expectedVersion,
4217 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004218 expectedError: expectedClientError,
4219 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004220 })
4221
4222 testCases = append(testCases, testCase{
4223 protocol: protocol,
4224 testType: serverTest,
4225 name: "MinimumVersion-Server-" + suffix,
4226 config: Config{
4227 MaxVersion: runnerVers.version,
4228 },
David Benjamin87909c02014-12-13 01:55:01 -05004229 flags: flags,
4230 expectedVersion: expectedVersion,
4231 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004232 expectedError: expectedServerError,
4233 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004234 })
4235 testCases = append(testCases, testCase{
4236 protocol: protocol,
4237 testType: serverTest,
4238 name: "MinimumVersion-Server2-" + suffix,
4239 config: Config{
4240 MaxVersion: runnerVers.version,
4241 },
David Benjamin87909c02014-12-13 01:55:01 -05004242 flags: []string{"-min-version", shimVersFlag},
4243 expectedVersion: expectedVersion,
4244 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004245 expectedError: expectedServerError,
4246 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004247 })
4248 }
4249 }
4250 }
4251}
4252
David Benjamine78bfde2014-09-06 12:45:15 -04004253func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004254 // TODO(davidben): Extensions, where applicable, all move their server
4255 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4256 // tests for both. Also test interaction with 0-RTT when implemented.
4257
David Benjamin97d17d92016-07-14 16:12:00 -04004258 // Repeat extensions tests all versions except SSL 3.0.
4259 for _, ver := range tlsVersions {
4260 if ver.version == VersionSSL30 {
4261 continue
4262 }
4263
David Benjamin97d17d92016-07-14 16:12:00 -04004264 // Test that duplicate extensions are rejected.
4265 testCases = append(testCases, testCase{
4266 testType: clientTest,
4267 name: "DuplicateExtensionClient-" + ver.name,
4268 config: Config{
4269 MaxVersion: ver.version,
4270 Bugs: ProtocolBugs{
4271 DuplicateExtension: true,
4272 },
David Benjamine78bfde2014-09-06 12:45:15 -04004273 },
David Benjamin97d17d92016-07-14 16:12:00 -04004274 shouldFail: true,
4275 expectedLocalError: "remote error: error decoding message",
4276 })
4277 testCases = append(testCases, testCase{
4278 testType: serverTest,
4279 name: "DuplicateExtensionServer-" + ver.name,
4280 config: Config{
4281 MaxVersion: ver.version,
4282 Bugs: ProtocolBugs{
4283 DuplicateExtension: true,
4284 },
David Benjamine78bfde2014-09-06 12:45:15 -04004285 },
David Benjamin97d17d92016-07-14 16:12:00 -04004286 shouldFail: true,
4287 expectedLocalError: "remote error: error decoding message",
4288 })
4289
4290 // Test SNI.
4291 testCases = append(testCases, testCase{
4292 testType: clientTest,
4293 name: "ServerNameExtensionClient-" + ver.name,
4294 config: Config{
4295 MaxVersion: ver.version,
4296 Bugs: ProtocolBugs{
4297 ExpectServerName: "example.com",
4298 },
David Benjamine78bfde2014-09-06 12:45:15 -04004299 },
David Benjamin97d17d92016-07-14 16:12:00 -04004300 flags: []string{"-host-name", "example.com"},
4301 })
4302 testCases = append(testCases, testCase{
4303 testType: clientTest,
4304 name: "ServerNameExtensionClientMismatch-" + ver.name,
4305 config: Config{
4306 MaxVersion: ver.version,
4307 Bugs: ProtocolBugs{
4308 ExpectServerName: "mismatch.com",
4309 },
David Benjamine78bfde2014-09-06 12:45:15 -04004310 },
David Benjamin97d17d92016-07-14 16:12:00 -04004311 flags: []string{"-host-name", "example.com"},
4312 shouldFail: true,
4313 expectedLocalError: "tls: unexpected server name",
4314 })
4315 testCases = append(testCases, testCase{
4316 testType: clientTest,
4317 name: "ServerNameExtensionClientMissing-" + ver.name,
4318 config: Config{
4319 MaxVersion: ver.version,
4320 Bugs: ProtocolBugs{
4321 ExpectServerName: "missing.com",
4322 },
David Benjamine78bfde2014-09-06 12:45:15 -04004323 },
David Benjamin97d17d92016-07-14 16:12:00 -04004324 shouldFail: true,
4325 expectedLocalError: "tls: unexpected server name",
4326 })
4327 testCases = append(testCases, testCase{
4328 testType: serverTest,
4329 name: "ServerNameExtensionServer-" + ver.name,
4330 config: Config{
4331 MaxVersion: ver.version,
4332 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004333 },
David Benjamin97d17d92016-07-14 16:12:00 -04004334 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004335 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004336 })
4337
4338 // Test ALPN.
4339 testCases = append(testCases, testCase{
4340 testType: clientTest,
4341 name: "ALPNClient-" + ver.name,
4342 config: Config{
4343 MaxVersion: ver.version,
4344 NextProtos: []string{"foo"},
4345 },
4346 flags: []string{
4347 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4348 "-expect-alpn", "foo",
4349 },
4350 expectedNextProto: "foo",
4351 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004352 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004353 })
4354 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004355 testType: clientTest,
4356 name: "ALPNClient-Mismatch-" + ver.name,
4357 config: Config{
4358 MaxVersion: ver.version,
4359 Bugs: ProtocolBugs{
4360 SendALPN: "baz",
4361 },
4362 },
4363 flags: []string{
4364 "-advertise-alpn", "\x03foo\x03bar",
4365 },
4366 shouldFail: true,
4367 expectedError: ":INVALID_ALPN_PROTOCOL:",
4368 expectedLocalError: "remote error: illegal parameter",
4369 })
4370 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004371 testType: serverTest,
4372 name: "ALPNServer-" + ver.name,
4373 config: Config{
4374 MaxVersion: ver.version,
4375 NextProtos: []string{"foo", "bar", "baz"},
4376 },
4377 flags: []string{
4378 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4379 "-select-alpn", "foo",
4380 },
4381 expectedNextProto: "foo",
4382 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004383 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004384 })
4385 testCases = append(testCases, testCase{
4386 testType: serverTest,
4387 name: "ALPNServer-Decline-" + ver.name,
4388 config: Config{
4389 MaxVersion: ver.version,
4390 NextProtos: []string{"foo", "bar", "baz"},
4391 },
4392 flags: []string{"-decline-alpn"},
4393 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004394 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004395 })
4396
David Benjamin25fe85b2016-08-09 20:00:32 -04004397 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4398 // called once.
4399 testCases = append(testCases, testCase{
4400 testType: serverTest,
4401 name: "ALPNServer-Async-" + ver.name,
4402 config: Config{
4403 MaxVersion: ver.version,
4404 NextProtos: []string{"foo", "bar", "baz"},
4405 },
4406 flags: []string{
4407 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4408 "-select-alpn", "foo",
4409 "-async",
4410 },
4411 expectedNextProto: "foo",
4412 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004413 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004414 })
4415
David Benjamin97d17d92016-07-14 16:12:00 -04004416 var emptyString string
4417 testCases = append(testCases, testCase{
4418 testType: clientTest,
4419 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4420 config: Config{
4421 MaxVersion: ver.version,
4422 NextProtos: []string{""},
4423 Bugs: ProtocolBugs{
4424 // A server returning an empty ALPN protocol
4425 // should be rejected.
4426 ALPNProtocol: &emptyString,
4427 },
4428 },
4429 flags: []string{
4430 "-advertise-alpn", "\x03foo",
4431 },
4432 shouldFail: true,
4433 expectedError: ":PARSE_TLSEXT:",
4434 })
4435 testCases = append(testCases, testCase{
4436 testType: serverTest,
4437 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4438 config: Config{
4439 MaxVersion: ver.version,
4440 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004441 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004442 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004443 },
David Benjamin97d17d92016-07-14 16:12:00 -04004444 flags: []string{
4445 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004446 },
David Benjamin97d17d92016-07-14 16:12:00 -04004447 shouldFail: true,
4448 expectedError: ":PARSE_TLSEXT:",
4449 })
4450
4451 // Test NPN and the interaction with ALPN.
4452 if ver.version < VersionTLS13 {
4453 // Test that the server prefers ALPN over NPN.
4454 testCases = append(testCases, testCase{
4455 testType: serverTest,
4456 name: "ALPNServer-Preferred-" + ver.name,
4457 config: Config{
4458 MaxVersion: ver.version,
4459 NextProtos: []string{"foo", "bar", "baz"},
4460 },
4461 flags: []string{
4462 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4463 "-select-alpn", "foo",
4464 "-advertise-npn", "\x03foo\x03bar\x03baz",
4465 },
4466 expectedNextProto: "foo",
4467 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004468 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004469 })
4470 testCases = append(testCases, testCase{
4471 testType: serverTest,
4472 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4473 config: Config{
4474 MaxVersion: ver.version,
4475 NextProtos: []string{"foo", "bar", "baz"},
4476 Bugs: ProtocolBugs{
4477 SwapNPNAndALPN: true,
4478 },
4479 },
4480 flags: []string{
4481 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4482 "-select-alpn", "foo",
4483 "-advertise-npn", "\x03foo\x03bar\x03baz",
4484 },
4485 expectedNextProto: "foo",
4486 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004487 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004488 })
4489
4490 // Test that negotiating both NPN and ALPN is forbidden.
4491 testCases = append(testCases, testCase{
4492 name: "NegotiateALPNAndNPN-" + ver.name,
4493 config: Config{
4494 MaxVersion: ver.version,
4495 NextProtos: []string{"foo", "bar", "baz"},
4496 Bugs: ProtocolBugs{
4497 NegotiateALPNAndNPN: true,
4498 },
4499 },
4500 flags: []string{
4501 "-advertise-alpn", "\x03foo",
4502 "-select-next-proto", "foo",
4503 },
4504 shouldFail: true,
4505 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4506 })
4507 testCases = append(testCases, testCase{
4508 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4509 config: Config{
4510 MaxVersion: ver.version,
4511 NextProtos: []string{"foo", "bar", "baz"},
4512 Bugs: ProtocolBugs{
4513 NegotiateALPNAndNPN: true,
4514 SwapNPNAndALPN: true,
4515 },
4516 },
4517 flags: []string{
4518 "-advertise-alpn", "\x03foo",
4519 "-select-next-proto", "foo",
4520 },
4521 shouldFail: true,
4522 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4523 })
4524
4525 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4526 testCases = append(testCases, testCase{
4527 name: "DisableNPN-" + ver.name,
4528 config: Config{
4529 MaxVersion: ver.version,
4530 NextProtos: []string{"foo"},
4531 },
4532 flags: []string{
4533 "-select-next-proto", "foo",
4534 "-disable-npn",
4535 },
4536 expectNoNextProto: true,
4537 })
4538 }
4539
4540 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004541
4542 // Resume with a corrupt ticket.
4543 testCases = append(testCases, testCase{
4544 testType: serverTest,
4545 name: "CorruptTicket-" + ver.name,
4546 config: Config{
4547 MaxVersion: ver.version,
4548 Bugs: ProtocolBugs{
4549 CorruptTicket: true,
4550 },
4551 },
4552 resumeSession: true,
4553 expectResumeRejected: true,
4554 })
4555 // Test the ticket callback, with and without renewal.
4556 testCases = append(testCases, testCase{
4557 testType: serverTest,
4558 name: "TicketCallback-" + ver.name,
4559 config: Config{
4560 MaxVersion: ver.version,
4561 },
4562 resumeSession: true,
4563 flags: []string{"-use-ticket-callback"},
4564 })
4565 testCases = append(testCases, testCase{
4566 testType: serverTest,
4567 name: "TicketCallback-Renew-" + ver.name,
4568 config: Config{
4569 MaxVersion: ver.version,
4570 Bugs: ProtocolBugs{
4571 ExpectNewTicket: true,
4572 },
4573 },
4574 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4575 resumeSession: true,
4576 })
4577
4578 // Test that the ticket callback is only called once when everything before
4579 // it in the ClientHello is asynchronous. This corrupts the ticket so
4580 // certificate selection callbacks run.
4581 testCases = append(testCases, testCase{
4582 testType: serverTest,
4583 name: "TicketCallback-SingleCall-" + ver.name,
4584 config: Config{
4585 MaxVersion: ver.version,
4586 Bugs: ProtocolBugs{
4587 CorruptTicket: true,
4588 },
4589 },
4590 resumeSession: true,
4591 expectResumeRejected: true,
4592 flags: []string{
4593 "-use-ticket-callback",
4594 "-async",
4595 },
4596 })
4597
4598 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004599 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004600 testCases = append(testCases, testCase{
4601 testType: serverTest,
4602 name: "OversizedSessionId-" + ver.name,
4603 config: Config{
4604 MaxVersion: ver.version,
4605 Bugs: ProtocolBugs{
4606 OversizedSessionId: true,
4607 },
4608 },
4609 resumeSession: true,
4610 shouldFail: true,
4611 expectedError: ":DECODE_ERROR:",
4612 })
4613 }
4614
4615 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4616 // are ignored.
4617 if ver.hasDTLS {
4618 testCases = append(testCases, testCase{
4619 protocol: dtls,
4620 name: "SRTP-Client-" + ver.name,
4621 config: Config{
4622 MaxVersion: ver.version,
4623 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4624 },
4625 flags: []string{
4626 "-srtp-profiles",
4627 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4628 },
4629 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4630 })
4631 testCases = append(testCases, testCase{
4632 protocol: dtls,
4633 testType: serverTest,
4634 name: "SRTP-Server-" + ver.name,
4635 config: Config{
4636 MaxVersion: ver.version,
4637 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4638 },
4639 flags: []string{
4640 "-srtp-profiles",
4641 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4642 },
4643 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4644 })
4645 // Test that the MKI is ignored.
4646 testCases = append(testCases, testCase{
4647 protocol: dtls,
4648 testType: serverTest,
4649 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4650 config: Config{
4651 MaxVersion: ver.version,
4652 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4653 Bugs: ProtocolBugs{
4654 SRTPMasterKeyIdentifer: "bogus",
4655 },
4656 },
4657 flags: []string{
4658 "-srtp-profiles",
4659 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4660 },
4661 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4662 })
4663 // Test that SRTP isn't negotiated on the server if there were
4664 // no matching profiles.
4665 testCases = append(testCases, testCase{
4666 protocol: dtls,
4667 testType: serverTest,
4668 name: "SRTP-Server-NoMatch-" + ver.name,
4669 config: Config{
4670 MaxVersion: ver.version,
4671 SRTPProtectionProfiles: []uint16{100, 101, 102},
4672 },
4673 flags: []string{
4674 "-srtp-profiles",
4675 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4676 },
4677 expectedSRTPProtectionProfile: 0,
4678 })
4679 // Test that the server returning an invalid SRTP profile is
4680 // flagged as an error by the client.
4681 testCases = append(testCases, testCase{
4682 protocol: dtls,
4683 name: "SRTP-Client-NoMatch-" + ver.name,
4684 config: Config{
4685 MaxVersion: ver.version,
4686 Bugs: ProtocolBugs{
4687 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4688 },
4689 },
4690 flags: []string{
4691 "-srtp-profiles",
4692 "SRTP_AES128_CM_SHA1_80",
4693 },
4694 shouldFail: true,
4695 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4696 })
4697 }
4698
4699 // Test SCT list.
4700 testCases = append(testCases, testCase{
4701 name: "SignedCertificateTimestampList-Client-" + ver.name,
4702 testType: clientTest,
4703 config: Config{
4704 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004705 },
David Benjamin97d17d92016-07-14 16:12:00 -04004706 flags: []string{
4707 "-enable-signed-cert-timestamps",
4708 "-expect-signed-cert-timestamps",
4709 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004710 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004711 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004712 })
4713 testCases = append(testCases, testCase{
4714 name: "SendSCTListOnResume-" + ver.name,
4715 config: Config{
4716 MaxVersion: ver.version,
4717 Bugs: ProtocolBugs{
4718 SendSCTListOnResume: []byte("bogus"),
4719 },
David Benjamind98452d2015-06-16 14:16:23 -04004720 },
David Benjamin97d17d92016-07-14 16:12:00 -04004721 flags: []string{
4722 "-enable-signed-cert-timestamps",
4723 "-expect-signed-cert-timestamps",
4724 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004725 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004726 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004727 })
4728 testCases = append(testCases, testCase{
4729 name: "SignedCertificateTimestampList-Server-" + ver.name,
4730 testType: serverTest,
4731 config: Config{
4732 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004733 },
David Benjamin97d17d92016-07-14 16:12:00 -04004734 flags: []string{
4735 "-signed-cert-timestamps",
4736 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004737 },
David Benjamin97d17d92016-07-14 16:12:00 -04004738 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004739 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004740 })
4741 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004742
Paul Lietar4fac72e2015-09-09 13:44:55 +01004743 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004744 testType: clientTest,
4745 name: "ClientHelloPadding",
4746 config: Config{
4747 Bugs: ProtocolBugs{
4748 RequireClientHelloSize: 512,
4749 },
4750 },
4751 // This hostname just needs to be long enough to push the
4752 // ClientHello into F5's danger zone between 256 and 511 bytes
4753 // long.
4754 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4755 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004756
4757 // Extensions should not function in SSL 3.0.
4758 testCases = append(testCases, testCase{
4759 testType: serverTest,
4760 name: "SSLv3Extensions-NoALPN",
4761 config: Config{
4762 MaxVersion: VersionSSL30,
4763 NextProtos: []string{"foo", "bar", "baz"},
4764 },
4765 flags: []string{
4766 "-select-alpn", "foo",
4767 },
4768 expectNoNextProto: true,
4769 })
4770
4771 // Test session tickets separately as they follow a different codepath.
4772 testCases = append(testCases, testCase{
4773 testType: serverTest,
4774 name: "SSLv3Extensions-NoTickets",
4775 config: Config{
4776 MaxVersion: VersionSSL30,
4777 Bugs: ProtocolBugs{
4778 // Historically, session tickets in SSL 3.0
4779 // failed in different ways depending on whether
4780 // the client supported renegotiation_info.
4781 NoRenegotiationInfo: true,
4782 },
4783 },
4784 resumeSession: true,
4785 })
4786 testCases = append(testCases, testCase{
4787 testType: serverTest,
4788 name: "SSLv3Extensions-NoTickets2",
4789 config: Config{
4790 MaxVersion: VersionSSL30,
4791 },
4792 resumeSession: true,
4793 })
4794
4795 // But SSL 3.0 does send and process renegotiation_info.
4796 testCases = append(testCases, testCase{
4797 testType: serverTest,
4798 name: "SSLv3Extensions-RenegotiationInfo",
4799 config: Config{
4800 MaxVersion: VersionSSL30,
4801 Bugs: ProtocolBugs{
4802 RequireRenegotiationInfo: true,
4803 },
4804 },
4805 })
4806 testCases = append(testCases, testCase{
4807 testType: serverTest,
4808 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4809 config: Config{
4810 MaxVersion: VersionSSL30,
4811 Bugs: ProtocolBugs{
4812 NoRenegotiationInfo: true,
4813 SendRenegotiationSCSV: true,
4814 RequireRenegotiationInfo: true,
4815 },
4816 },
4817 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004818
4819 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4820 // in ServerHello.
4821 testCases = append(testCases, testCase{
4822 name: "NPN-Forbidden-TLS13",
4823 config: Config{
4824 MaxVersion: VersionTLS13,
4825 NextProtos: []string{"foo"},
4826 Bugs: ProtocolBugs{
4827 NegotiateNPNAtAllVersions: true,
4828 },
4829 },
4830 flags: []string{"-select-next-proto", "foo"},
4831 shouldFail: true,
4832 expectedError: ":ERROR_PARSING_EXTENSION:",
4833 })
4834 testCases = append(testCases, testCase{
4835 name: "EMS-Forbidden-TLS13",
4836 config: Config{
4837 MaxVersion: VersionTLS13,
4838 Bugs: ProtocolBugs{
4839 NegotiateEMSAtAllVersions: true,
4840 },
4841 },
4842 shouldFail: true,
4843 expectedError: ":ERROR_PARSING_EXTENSION:",
4844 })
4845 testCases = append(testCases, testCase{
4846 name: "RenegotiationInfo-Forbidden-TLS13",
4847 config: Config{
4848 MaxVersion: VersionTLS13,
4849 Bugs: ProtocolBugs{
4850 NegotiateRenegotiationInfoAtAllVersions: true,
4851 },
4852 },
4853 shouldFail: true,
4854 expectedError: ":ERROR_PARSING_EXTENSION:",
4855 })
4856 testCases = append(testCases, testCase{
4857 name: "ChannelID-Forbidden-TLS13",
4858 config: Config{
4859 MaxVersion: VersionTLS13,
4860 RequestChannelID: true,
4861 Bugs: ProtocolBugs{
4862 NegotiateChannelIDAtAllVersions: true,
4863 },
4864 },
4865 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4866 shouldFail: true,
4867 expectedError: ":ERROR_PARSING_EXTENSION:",
4868 })
4869 testCases = append(testCases, testCase{
4870 name: "Ticket-Forbidden-TLS13",
4871 config: Config{
4872 MaxVersion: VersionTLS12,
4873 },
4874 resumeConfig: &Config{
4875 MaxVersion: VersionTLS13,
4876 Bugs: ProtocolBugs{
4877 AdvertiseTicketExtension: true,
4878 },
4879 },
4880 resumeSession: true,
4881 shouldFail: true,
4882 expectedError: ":ERROR_PARSING_EXTENSION:",
4883 })
4884
4885 // Test that illegal extensions in TLS 1.3 are declined by the server if
4886 // offered in ClientHello. The runner's server will fail if this occurs,
4887 // so we exercise the offering path. (EMS and Renegotiation Info are
4888 // implicit in every test.)
4889 testCases = append(testCases, testCase{
4890 testType: serverTest,
4891 name: "ChannelID-Declined-TLS13",
4892 config: Config{
4893 MaxVersion: VersionTLS13,
4894 ChannelID: channelIDKey,
4895 },
4896 flags: []string{"-enable-channel-id"},
4897 })
4898 testCases = append(testCases, testCase{
4899 testType: serverTest,
4900 name: "NPN-Server",
4901 config: Config{
4902 MaxVersion: VersionTLS13,
4903 NextProtos: []string{"bar"},
4904 },
4905 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4906 })
David Benjamine78bfde2014-09-06 12:45:15 -04004907}
4908
David Benjamin01fe8202014-09-24 15:21:44 -04004909func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004910 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004911 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004912 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4913 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4914 // TLS 1.3 only shares ciphers with TLS 1.2, so
4915 // we skip certain combinations and use a
4916 // different cipher to test with.
4917 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4918 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4919 continue
4920 }
4921 }
4922
David Benjamin8b8c0062014-11-23 02:47:52 -05004923 protocols := []protocol{tls}
4924 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4925 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004926 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004927 for _, protocol := range protocols {
4928 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4929 if protocol == dtls {
4930 suffix += "-DTLS"
4931 }
4932
David Benjaminece3de92015-03-16 18:02:20 -04004933 if sessionVers.version == resumeVers.version {
4934 testCases = append(testCases, testCase{
4935 protocol: protocol,
4936 name: "Resume-Client" + suffix,
4937 resumeSession: true,
4938 config: Config{
4939 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004940 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04004941 Bugs: ProtocolBugs{
4942 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
4943 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
4944 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004945 },
David Benjaminece3de92015-03-16 18:02:20 -04004946 expectedVersion: sessionVers.version,
4947 expectedResumeVersion: resumeVers.version,
4948 })
4949 } else {
David Benjamin405da482016-08-08 17:25:07 -04004950 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
4951
4952 // Offering a TLS 1.3 session sends an empty session ID, so
4953 // there is no way to convince a non-lookahead client the
4954 // session was resumed. It will appear to the client that a
4955 // stray ChangeCipherSpec was sent.
4956 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
4957 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04004958 }
4959
David Benjaminece3de92015-03-16 18:02:20 -04004960 testCases = append(testCases, testCase{
4961 protocol: protocol,
4962 name: "Resume-Client-Mismatch" + suffix,
4963 resumeSession: true,
4964 config: Config{
4965 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004966 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004967 },
David Benjaminece3de92015-03-16 18:02:20 -04004968 expectedVersion: sessionVers.version,
4969 resumeConfig: &Config{
4970 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004971 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004972 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04004973 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04004974 },
4975 },
4976 expectedResumeVersion: resumeVers.version,
4977 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004978 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04004979 })
4980 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004981
4982 testCases = append(testCases, testCase{
4983 protocol: protocol,
4984 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004985 resumeSession: true,
4986 config: Config{
4987 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004988 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004989 },
4990 expectedVersion: sessionVers.version,
4991 resumeConfig: &Config{
4992 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004993 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004994 },
4995 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004996 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004997 expectedResumeVersion: resumeVers.version,
4998 })
4999
David Benjamin8b8c0062014-11-23 02:47:52 -05005000 testCases = append(testCases, testCase{
5001 protocol: protocol,
5002 testType: serverTest,
5003 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005004 resumeSession: true,
5005 config: Config{
5006 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005007 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005008 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005009 expectedVersion: sessionVers.version,
5010 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005011 resumeConfig: &Config{
5012 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005013 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005014 Bugs: ProtocolBugs{
5015 SendBothTickets: true,
5016 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005017 },
5018 expectedResumeVersion: resumeVers.version,
5019 })
5020 }
David Benjamin01fe8202014-09-24 15:21:44 -04005021 }
5022 }
David Benjaminece3de92015-03-16 18:02:20 -04005023
5024 testCases = append(testCases, testCase{
5025 name: "Resume-Client-CipherMismatch",
5026 resumeSession: true,
5027 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005028 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005029 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5030 },
5031 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005032 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005033 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5034 Bugs: ProtocolBugs{
5035 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5036 },
5037 },
5038 shouldFail: true,
5039 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5040 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005041
5042 testCases = append(testCases, testCase{
5043 name: "Resume-Client-CipherMismatch-TLS13",
5044 resumeSession: true,
5045 config: Config{
5046 MaxVersion: VersionTLS13,
5047 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5048 },
5049 resumeConfig: &Config{
5050 MaxVersion: VersionTLS13,
5051 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5052 Bugs: ProtocolBugs{
5053 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5054 },
5055 },
5056 shouldFail: true,
5057 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5058 })
David Benjamin01fe8202014-09-24 15:21:44 -04005059}
5060
Adam Langley2ae77d22014-10-28 17:29:33 -07005061func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005062 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005063 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005064 testType: serverTest,
5065 name: "Renegotiate-Server-Forbidden",
5066 config: Config{
5067 MaxVersion: VersionTLS12,
5068 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005069 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005070 shouldFail: true,
5071 expectedError: ":NO_RENEGOTIATION:",
5072 expectedLocalError: "remote error: no renegotiation",
5073 })
Adam Langley5021b222015-06-12 18:27:58 -07005074 // The server shouldn't echo the renegotiation extension unless
5075 // requested by the client.
5076 testCases = append(testCases, testCase{
5077 testType: serverTest,
5078 name: "Renegotiate-Server-NoExt",
5079 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005080 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005081 Bugs: ProtocolBugs{
5082 NoRenegotiationInfo: true,
5083 RequireRenegotiationInfo: true,
5084 },
5085 },
5086 shouldFail: true,
5087 expectedLocalError: "renegotiation extension missing",
5088 })
5089 // The renegotiation SCSV should be sufficient for the server to echo
5090 // the extension.
5091 testCases = append(testCases, testCase{
5092 testType: serverTest,
5093 name: "Renegotiate-Server-NoExt-SCSV",
5094 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005095 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005096 Bugs: ProtocolBugs{
5097 NoRenegotiationInfo: true,
5098 SendRenegotiationSCSV: true,
5099 RequireRenegotiationInfo: true,
5100 },
5101 },
5102 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005103 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005104 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005105 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005106 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005107 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005108 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005109 },
5110 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005111 renegotiate: 1,
5112 flags: []string{
5113 "-renegotiate-freely",
5114 "-expect-total-renegotiations", "1",
5115 },
David Benjamincdea40c2015-03-19 14:09:43 -04005116 })
5117 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005118 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005119 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005120 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005121 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005122 Bugs: ProtocolBugs{
5123 EmptyRenegotiationInfo: true,
5124 },
5125 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005126 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005127 shouldFail: true,
5128 expectedError: ":RENEGOTIATION_MISMATCH:",
5129 })
5130 testCases = append(testCases, testCase{
5131 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005132 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005133 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005134 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005135 Bugs: ProtocolBugs{
5136 BadRenegotiationInfo: true,
5137 },
5138 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005139 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005140 shouldFail: true,
5141 expectedError: ":RENEGOTIATION_MISMATCH:",
5142 })
5143 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005144 name: "Renegotiate-Client-Downgrade",
5145 renegotiate: 1,
5146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005147 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005148 Bugs: ProtocolBugs{
5149 NoRenegotiationInfoAfterInitial: true,
5150 },
5151 },
5152 flags: []string{"-renegotiate-freely"},
5153 shouldFail: true,
5154 expectedError: ":RENEGOTIATION_MISMATCH:",
5155 })
5156 testCases = append(testCases, testCase{
5157 name: "Renegotiate-Client-Upgrade",
5158 renegotiate: 1,
5159 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005160 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005161 Bugs: ProtocolBugs{
5162 NoRenegotiationInfoInInitial: true,
5163 },
5164 },
5165 flags: []string{"-renegotiate-freely"},
5166 shouldFail: true,
5167 expectedError: ":RENEGOTIATION_MISMATCH:",
5168 })
5169 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005170 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005171 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005172 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005173 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005174 Bugs: ProtocolBugs{
5175 NoRenegotiationInfo: true,
5176 },
5177 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005178 flags: []string{
5179 "-renegotiate-freely",
5180 "-expect-total-renegotiations", "1",
5181 },
David Benjamincff0b902015-05-15 23:09:47 -04005182 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005183
5184 // Test that the server may switch ciphers on renegotiation without
5185 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005186 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005187 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005188 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005189 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005190 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005191 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5192 },
5193 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005194 flags: []string{
5195 "-renegotiate-freely",
5196 "-expect-total-renegotiations", "1",
5197 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005198 })
5199 testCases = append(testCases, testCase{
5200 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005201 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005202 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005203 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005204 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5205 },
5206 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005207 flags: []string{
5208 "-renegotiate-freely",
5209 "-expect-total-renegotiations", "1",
5210 },
David Benjaminb16346b2015-04-08 19:16:58 -04005211 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005212
5213 // Test that the server may not switch versions on renegotiation.
5214 testCases = append(testCases, testCase{
5215 name: "Renegotiate-Client-SwitchVersion",
5216 config: Config{
5217 MaxVersion: VersionTLS12,
5218 // Pick a cipher which exists at both versions.
5219 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5220 Bugs: ProtocolBugs{
5221 NegotiateVersionOnRenego: VersionTLS11,
5222 },
5223 },
5224 renegotiate: 1,
5225 flags: []string{
5226 "-renegotiate-freely",
5227 "-expect-total-renegotiations", "1",
5228 },
5229 shouldFail: true,
5230 expectedError: ":WRONG_SSL_VERSION:",
5231 })
5232
David Benjaminb16346b2015-04-08 19:16:58 -04005233 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005234 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005235 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005236 config: Config{
5237 MaxVersion: VersionTLS10,
5238 Bugs: ProtocolBugs{
5239 RequireSameRenegoClientVersion: true,
5240 },
5241 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005242 flags: []string{
5243 "-renegotiate-freely",
5244 "-expect-total-renegotiations", "1",
5245 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005246 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005247 testCases = append(testCases, testCase{
5248 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005249 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005250 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005251 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005252 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5253 NextProtos: []string{"foo"},
5254 },
5255 flags: []string{
5256 "-false-start",
5257 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005258 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005259 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005260 },
5261 shimWritesFirst: true,
5262 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005263
5264 // Client-side renegotiation controls.
5265 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005266 name: "Renegotiate-Client-Forbidden-1",
5267 config: Config{
5268 MaxVersion: VersionTLS12,
5269 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005270 renegotiate: 1,
5271 shouldFail: true,
5272 expectedError: ":NO_RENEGOTIATION:",
5273 expectedLocalError: "remote error: no renegotiation",
5274 })
5275 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005276 name: "Renegotiate-Client-Once-1",
5277 config: Config{
5278 MaxVersion: VersionTLS12,
5279 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005280 renegotiate: 1,
5281 flags: []string{
5282 "-renegotiate-once",
5283 "-expect-total-renegotiations", "1",
5284 },
5285 })
5286 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005287 name: "Renegotiate-Client-Freely-1",
5288 config: Config{
5289 MaxVersion: VersionTLS12,
5290 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005291 renegotiate: 1,
5292 flags: []string{
5293 "-renegotiate-freely",
5294 "-expect-total-renegotiations", "1",
5295 },
5296 })
5297 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005298 name: "Renegotiate-Client-Once-2",
5299 config: Config{
5300 MaxVersion: VersionTLS12,
5301 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005302 renegotiate: 2,
5303 flags: []string{"-renegotiate-once"},
5304 shouldFail: true,
5305 expectedError: ":NO_RENEGOTIATION:",
5306 expectedLocalError: "remote error: no renegotiation",
5307 })
5308 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005309 name: "Renegotiate-Client-Freely-2",
5310 config: Config{
5311 MaxVersion: VersionTLS12,
5312 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005313 renegotiate: 2,
5314 flags: []string{
5315 "-renegotiate-freely",
5316 "-expect-total-renegotiations", "2",
5317 },
5318 })
Adam Langley27a0d082015-11-03 13:34:10 -08005319 testCases = append(testCases, testCase{
5320 name: "Renegotiate-Client-NoIgnore",
5321 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005322 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005323 Bugs: ProtocolBugs{
5324 SendHelloRequestBeforeEveryAppDataRecord: true,
5325 },
5326 },
5327 shouldFail: true,
5328 expectedError: ":NO_RENEGOTIATION:",
5329 })
5330 testCases = append(testCases, testCase{
5331 name: "Renegotiate-Client-Ignore",
5332 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005333 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005334 Bugs: ProtocolBugs{
5335 SendHelloRequestBeforeEveryAppDataRecord: true,
5336 },
5337 },
5338 flags: []string{
5339 "-renegotiate-ignore",
5340 "-expect-total-renegotiations", "0",
5341 },
5342 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005343
David Benjamin397c8e62016-07-08 14:14:36 -07005344 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005345 testCases = append(testCases, testCase{
5346 name: "StrayHelloRequest",
5347 config: Config{
5348 MaxVersion: VersionTLS12,
5349 Bugs: ProtocolBugs{
5350 SendHelloRequestBeforeEveryHandshakeMessage: true,
5351 },
5352 },
5353 })
5354 testCases = append(testCases, testCase{
5355 name: "StrayHelloRequest-Packed",
5356 config: Config{
5357 MaxVersion: VersionTLS12,
5358 Bugs: ProtocolBugs{
5359 PackHandshakeFlight: true,
5360 SendHelloRequestBeforeEveryHandshakeMessage: true,
5361 },
5362 },
5363 })
5364
David Benjamin12d2c482016-07-24 10:56:51 -04005365 // Test renegotiation works if HelloRequest and server Finished come in
5366 // the same record.
5367 testCases = append(testCases, testCase{
5368 name: "Renegotiate-Client-Packed",
5369 config: Config{
5370 MaxVersion: VersionTLS12,
5371 Bugs: ProtocolBugs{
5372 PackHandshakeFlight: true,
5373 PackHelloRequestWithFinished: true,
5374 },
5375 },
5376 renegotiate: 1,
5377 flags: []string{
5378 "-renegotiate-freely",
5379 "-expect-total-renegotiations", "1",
5380 },
5381 })
5382
David Benjamin397c8e62016-07-08 14:14:36 -07005383 // Renegotiation is forbidden in TLS 1.3.
5384 testCases = append(testCases, testCase{
5385 name: "Renegotiate-Client-TLS13",
5386 config: Config{
5387 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005388 Bugs: ProtocolBugs{
5389 SendHelloRequestBeforeEveryAppDataRecord: true,
5390 },
David Benjamin397c8e62016-07-08 14:14:36 -07005391 },
David Benjamin397c8e62016-07-08 14:14:36 -07005392 flags: []string{
5393 "-renegotiate-freely",
5394 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005395 shouldFail: true,
5396 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005397 })
5398
5399 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5400 testCases = append(testCases, testCase{
5401 name: "StrayHelloRequest-TLS13",
5402 config: Config{
5403 MaxVersion: VersionTLS13,
5404 Bugs: ProtocolBugs{
5405 SendHelloRequestBeforeEveryHandshakeMessage: true,
5406 },
5407 },
5408 shouldFail: true,
5409 expectedError: ":UNEXPECTED_MESSAGE:",
5410 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005411}
5412
David Benjamin5e961c12014-11-07 01:48:35 -05005413func addDTLSReplayTests() {
5414 // Test that sequence number replays are detected.
5415 testCases = append(testCases, testCase{
5416 protocol: dtls,
5417 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005418 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005419 replayWrites: true,
5420 })
5421
David Benjamin8e6db492015-07-25 18:29:23 -04005422 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005423 // than the retransmit window.
5424 testCases = append(testCases, testCase{
5425 protocol: dtls,
5426 name: "DTLS-Replay-LargeGaps",
5427 config: Config{
5428 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005429 SequenceNumberMapping: func(in uint64) uint64 {
5430 return in * 127
5431 },
David Benjamin5e961c12014-11-07 01:48:35 -05005432 },
5433 },
David Benjamin8e6db492015-07-25 18:29:23 -04005434 messageCount: 200,
5435 replayWrites: true,
5436 })
5437
5438 // Test the incoming sequence number changing non-monotonically.
5439 testCases = append(testCases, testCase{
5440 protocol: dtls,
5441 name: "DTLS-Replay-NonMonotonic",
5442 config: Config{
5443 Bugs: ProtocolBugs{
5444 SequenceNumberMapping: func(in uint64) uint64 {
5445 return in ^ 31
5446 },
5447 },
5448 },
5449 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005450 replayWrites: true,
5451 })
5452}
5453
Nick Harper60edffd2016-06-21 15:19:24 -07005454var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005455 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005456 id signatureAlgorithm
5457 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005458}{
Nick Harper60edffd2016-06-21 15:19:24 -07005459 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5460 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5461 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5462 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005463 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005464 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5465 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5466 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005467 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5468 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5469 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005470 // Tests for key types prior to TLS 1.2.
5471 {"RSA", 0, testCertRSA},
5472 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005473}
5474
Nick Harper60edffd2016-06-21 15:19:24 -07005475const fakeSigAlg1 signatureAlgorithm = 0x2a01
5476const fakeSigAlg2 signatureAlgorithm = 0xff01
5477
5478func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005479 // Not all ciphers involve a signature. Advertise a list which gives all
5480 // versions a signing cipher.
5481 signingCiphers := []uint16{
5482 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5483 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5484 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5485 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5486 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5487 }
5488
David Benjaminca3d5452016-07-14 12:51:01 -04005489 var allAlgorithms []signatureAlgorithm
5490 for _, alg := range testSignatureAlgorithms {
5491 if alg.id != 0 {
5492 allAlgorithms = append(allAlgorithms, alg.id)
5493 }
5494 }
5495
Nick Harper60edffd2016-06-21 15:19:24 -07005496 // Make sure each signature algorithm works. Include some fake values in
5497 // the list and ensure they're ignored.
5498 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005499 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005500 if (ver.version < VersionTLS12) != (alg.id == 0) {
5501 continue
5502 }
5503
5504 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5505 // or remove it in C.
5506 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005507 continue
5508 }
Nick Harper60edffd2016-06-21 15:19:24 -07005509
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005510 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005511 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005512 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5513 shouldFail = true
5514 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005515 // RSA-PKCS1 does not exist in TLS 1.3.
5516 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5517 shouldFail = true
5518 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005519
5520 var signError, verifyError string
5521 if shouldFail {
5522 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5523 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005524 }
David Benjamin000800a2014-11-14 01:43:59 -05005525
David Benjamin1fb125c2016-07-08 18:52:12 -07005526 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005527
David Benjamin7a41d372016-07-09 11:21:54 -07005528 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005529 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005530 config: Config{
5531 MaxVersion: ver.version,
5532 ClientAuth: RequireAnyClientCert,
5533 VerifySignatureAlgorithms: []signatureAlgorithm{
5534 fakeSigAlg1,
5535 alg.id,
5536 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005537 },
David Benjamin7a41d372016-07-09 11:21:54 -07005538 },
5539 flags: []string{
5540 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5541 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5542 "-enable-all-curves",
5543 },
5544 shouldFail: shouldFail,
5545 expectedError: signError,
5546 expectedPeerSignatureAlgorithm: alg.id,
5547 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005548
David Benjamin7a41d372016-07-09 11:21:54 -07005549 testCases = append(testCases, testCase{
5550 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005551 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005552 config: Config{
5553 MaxVersion: ver.version,
5554 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5555 SignSignatureAlgorithms: []signatureAlgorithm{
5556 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005557 },
David Benjamin7a41d372016-07-09 11:21:54 -07005558 Bugs: ProtocolBugs{
5559 SkipECDSACurveCheck: shouldFail,
5560 IgnoreSignatureVersionChecks: shouldFail,
5561 // The client won't advertise 1.3-only algorithms after
5562 // version negotiation.
5563 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005564 },
David Benjamin7a41d372016-07-09 11:21:54 -07005565 },
5566 flags: []string{
5567 "-require-any-client-certificate",
5568 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5569 "-enable-all-curves",
5570 },
5571 shouldFail: shouldFail,
5572 expectedError: verifyError,
5573 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005574
5575 testCases = append(testCases, testCase{
5576 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005577 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005578 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005579 MaxVersion: ver.version,
5580 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005581 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005582 fakeSigAlg1,
5583 alg.id,
5584 fakeSigAlg2,
5585 },
5586 },
5587 flags: []string{
5588 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5589 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5590 "-enable-all-curves",
5591 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005592 shouldFail: shouldFail,
5593 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005594 expectedPeerSignatureAlgorithm: alg.id,
5595 })
5596
5597 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005598 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005599 config: Config{
5600 MaxVersion: ver.version,
5601 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005602 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005603 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005604 alg.id,
5605 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005606 Bugs: ProtocolBugs{
5607 SkipECDSACurveCheck: shouldFail,
5608 IgnoreSignatureVersionChecks: shouldFail,
5609 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005610 },
5611 flags: []string{
5612 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5613 "-enable-all-curves",
5614 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005615 shouldFail: shouldFail,
5616 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005617 })
David Benjamin5208fd42016-07-13 21:43:25 -04005618
5619 if !shouldFail {
5620 testCases = append(testCases, testCase{
5621 testType: serverTest,
5622 name: "ClientAuth-InvalidSignature" + suffix,
5623 config: Config{
5624 MaxVersion: ver.version,
5625 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5626 SignSignatureAlgorithms: []signatureAlgorithm{
5627 alg.id,
5628 },
5629 Bugs: ProtocolBugs{
5630 InvalidSignature: true,
5631 },
5632 },
5633 flags: []string{
5634 "-require-any-client-certificate",
5635 "-enable-all-curves",
5636 },
5637 shouldFail: true,
5638 expectedError: ":BAD_SIGNATURE:",
5639 })
5640
5641 testCases = append(testCases, testCase{
5642 name: "ServerAuth-InvalidSignature" + suffix,
5643 config: Config{
5644 MaxVersion: ver.version,
5645 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5646 CipherSuites: signingCiphers,
5647 SignSignatureAlgorithms: []signatureAlgorithm{
5648 alg.id,
5649 },
5650 Bugs: ProtocolBugs{
5651 InvalidSignature: true,
5652 },
5653 },
5654 flags: []string{"-enable-all-curves"},
5655 shouldFail: true,
5656 expectedError: ":BAD_SIGNATURE:",
5657 })
5658 }
David Benjaminca3d5452016-07-14 12:51:01 -04005659
5660 if ver.version >= VersionTLS12 && !shouldFail {
5661 testCases = append(testCases, testCase{
5662 name: "ClientAuth-Sign-Negotiate" + suffix,
5663 config: Config{
5664 MaxVersion: ver.version,
5665 ClientAuth: RequireAnyClientCert,
5666 VerifySignatureAlgorithms: allAlgorithms,
5667 },
5668 flags: []string{
5669 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5670 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5671 "-enable-all-curves",
5672 "-signing-prefs", strconv.Itoa(int(alg.id)),
5673 },
5674 expectedPeerSignatureAlgorithm: alg.id,
5675 })
5676
5677 testCases = append(testCases, testCase{
5678 testType: serverTest,
5679 name: "ServerAuth-Sign-Negotiate" + suffix,
5680 config: Config{
5681 MaxVersion: ver.version,
5682 CipherSuites: signingCiphers,
5683 VerifySignatureAlgorithms: allAlgorithms,
5684 },
5685 flags: []string{
5686 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5687 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5688 "-enable-all-curves",
5689 "-signing-prefs", strconv.Itoa(int(alg.id)),
5690 },
5691 expectedPeerSignatureAlgorithm: alg.id,
5692 })
5693 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005694 }
David Benjamin000800a2014-11-14 01:43:59 -05005695 }
5696
Nick Harper60edffd2016-06-21 15:19:24 -07005697 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005698 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005699 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005700 config: Config{
5701 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005702 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005703 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005704 signatureECDSAWithP521AndSHA512,
5705 signatureRSAPKCS1WithSHA384,
5706 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005707 },
5708 },
5709 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005710 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5711 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005712 },
Nick Harper60edffd2016-06-21 15:19:24 -07005713 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005714 })
5715
5716 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005717 name: "ClientAuth-SignatureType-TLS13",
5718 config: Config{
5719 ClientAuth: RequireAnyClientCert,
5720 MaxVersion: VersionTLS13,
5721 VerifySignatureAlgorithms: []signatureAlgorithm{
5722 signatureECDSAWithP521AndSHA512,
5723 signatureRSAPKCS1WithSHA384,
5724 signatureRSAPSSWithSHA384,
5725 signatureECDSAWithSHA1,
5726 },
5727 },
5728 flags: []string{
5729 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5730 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5731 },
5732 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5733 })
5734
5735 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005736 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005737 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005738 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005739 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005740 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005741 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005742 signatureECDSAWithP521AndSHA512,
5743 signatureRSAPKCS1WithSHA384,
5744 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005745 },
5746 },
Nick Harper60edffd2016-06-21 15:19:24 -07005747 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005748 })
5749
Steven Valdez143e8b32016-07-11 13:19:03 -04005750 testCases = append(testCases, testCase{
5751 testType: serverTest,
5752 name: "ServerAuth-SignatureType-TLS13",
5753 config: Config{
5754 MaxVersion: VersionTLS13,
5755 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5756 VerifySignatureAlgorithms: []signatureAlgorithm{
5757 signatureECDSAWithP521AndSHA512,
5758 signatureRSAPKCS1WithSHA384,
5759 signatureRSAPSSWithSHA384,
5760 signatureECDSAWithSHA1,
5761 },
5762 },
5763 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5764 })
5765
David Benjamina95e9f32016-07-08 16:28:04 -07005766 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005767 testCases = append(testCases, testCase{
5768 testType: serverTest,
5769 name: "Verify-ClientAuth-SignatureType",
5770 config: Config{
5771 MaxVersion: VersionTLS12,
5772 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005773 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005774 signatureRSAPKCS1WithSHA256,
5775 },
5776 Bugs: ProtocolBugs{
5777 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5778 },
5779 },
5780 flags: []string{
5781 "-require-any-client-certificate",
5782 },
5783 shouldFail: true,
5784 expectedError: ":WRONG_SIGNATURE_TYPE:",
5785 })
5786
5787 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005788 testType: serverTest,
5789 name: "Verify-ClientAuth-SignatureType-TLS13",
5790 config: Config{
5791 MaxVersion: VersionTLS13,
5792 Certificates: []Certificate{rsaCertificate},
5793 SignSignatureAlgorithms: []signatureAlgorithm{
5794 signatureRSAPSSWithSHA256,
5795 },
5796 Bugs: ProtocolBugs{
5797 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5798 },
5799 },
5800 flags: []string{
5801 "-require-any-client-certificate",
5802 },
5803 shouldFail: true,
5804 expectedError: ":WRONG_SIGNATURE_TYPE:",
5805 })
5806
5807 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005808 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005809 config: Config{
5810 MaxVersion: VersionTLS12,
5811 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005812 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005813 signatureRSAPKCS1WithSHA256,
5814 },
5815 Bugs: ProtocolBugs{
5816 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5817 },
5818 },
5819 shouldFail: true,
5820 expectedError: ":WRONG_SIGNATURE_TYPE:",
5821 })
5822
Steven Valdez143e8b32016-07-11 13:19:03 -04005823 testCases = append(testCases, testCase{
5824 name: "Verify-ServerAuth-SignatureType-TLS13",
5825 config: Config{
5826 MaxVersion: VersionTLS13,
5827 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5828 SignSignatureAlgorithms: []signatureAlgorithm{
5829 signatureRSAPSSWithSHA256,
5830 },
5831 Bugs: ProtocolBugs{
5832 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5833 },
5834 },
5835 shouldFail: true,
5836 expectedError: ":WRONG_SIGNATURE_TYPE:",
5837 })
5838
David Benjamin51dd7d62016-07-08 16:07:01 -07005839 // Test that, if the list is missing, the peer falls back to SHA-1 in
5840 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005841 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005842 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005843 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005844 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005845 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005846 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005847 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005848 },
5849 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005850 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005851 },
5852 },
5853 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005854 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5855 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005856 },
5857 })
5858
5859 testCases = append(testCases, testCase{
5860 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005861 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005862 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005863 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005864 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005865 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005866 },
5867 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005868 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005869 },
5870 },
David Benjaminee32bea2016-08-17 13:36:44 -04005871 flags: []string{
5872 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5873 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5874 },
5875 })
5876
5877 testCases = append(testCases, testCase{
5878 name: "ClientAuth-SHA1-Fallback-ECDSA",
5879 config: Config{
5880 MaxVersion: VersionTLS12,
5881 ClientAuth: RequireAnyClientCert,
5882 VerifySignatureAlgorithms: []signatureAlgorithm{
5883 signatureECDSAWithSHA1,
5884 },
5885 Bugs: ProtocolBugs{
5886 NoSignatureAlgorithms: true,
5887 },
5888 },
5889 flags: []string{
5890 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5891 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5892 },
5893 })
5894
5895 testCases = append(testCases, testCase{
5896 testType: serverTest,
5897 name: "ServerAuth-SHA1-Fallback-ECDSA",
5898 config: Config{
5899 MaxVersion: VersionTLS12,
5900 VerifySignatureAlgorithms: []signatureAlgorithm{
5901 signatureECDSAWithSHA1,
5902 },
5903 Bugs: ProtocolBugs{
5904 NoSignatureAlgorithms: true,
5905 },
5906 },
5907 flags: []string{
5908 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5909 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5910 },
David Benjamin000800a2014-11-14 01:43:59 -05005911 })
David Benjamin72dc7832015-03-16 17:49:43 -04005912
David Benjamin51dd7d62016-07-08 16:07:01 -07005913 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005914 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005915 config: Config{
5916 MaxVersion: VersionTLS13,
5917 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005918 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005919 signatureRSAPKCS1WithSHA1,
5920 },
5921 Bugs: ProtocolBugs{
5922 NoSignatureAlgorithms: true,
5923 },
5924 },
5925 flags: []string{
5926 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5927 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5928 },
David Benjamin48901652016-08-01 12:12:47 -04005929 shouldFail: true,
5930 // An empty CertificateRequest signature algorithm list is a
5931 // syntax error in TLS 1.3.
5932 expectedError: ":DECODE_ERROR:",
5933 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07005934 })
5935
5936 testCases = append(testCases, testCase{
5937 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005938 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005939 config: Config{
5940 MaxVersion: VersionTLS13,
5941 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005942 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005943 signatureRSAPKCS1WithSHA1,
5944 },
5945 Bugs: ProtocolBugs{
5946 NoSignatureAlgorithms: true,
5947 },
5948 },
5949 shouldFail: true,
5950 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5951 })
5952
David Benjaminb62d2872016-07-18 14:55:02 +02005953 // Test that hash preferences are enforced. BoringSSL does not implement
5954 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005955 testCases = append(testCases, testCase{
5956 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005957 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005958 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005959 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005960 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005961 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005962 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005963 },
5964 Bugs: ProtocolBugs{
5965 IgnorePeerSignatureAlgorithmPreferences: true,
5966 },
5967 },
5968 flags: []string{"-require-any-client-certificate"},
5969 shouldFail: true,
5970 expectedError: ":WRONG_SIGNATURE_TYPE:",
5971 })
5972
5973 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005974 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005975 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005976 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005977 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005978 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005979 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005980 },
5981 Bugs: ProtocolBugs{
5982 IgnorePeerSignatureAlgorithmPreferences: true,
5983 },
5984 },
5985 shouldFail: true,
5986 expectedError: ":WRONG_SIGNATURE_TYPE:",
5987 })
David Benjaminb62d2872016-07-18 14:55:02 +02005988 testCases = append(testCases, testCase{
5989 testType: serverTest,
5990 name: "ClientAuth-Enforced-TLS13",
5991 config: Config{
5992 MaxVersion: VersionTLS13,
5993 Certificates: []Certificate{rsaCertificate},
5994 SignSignatureAlgorithms: []signatureAlgorithm{
5995 signatureRSAPKCS1WithMD5,
5996 },
5997 Bugs: ProtocolBugs{
5998 IgnorePeerSignatureAlgorithmPreferences: true,
5999 IgnoreSignatureVersionChecks: true,
6000 },
6001 },
6002 flags: []string{"-require-any-client-certificate"},
6003 shouldFail: true,
6004 expectedError: ":WRONG_SIGNATURE_TYPE:",
6005 })
6006
6007 testCases = append(testCases, testCase{
6008 name: "ServerAuth-Enforced-TLS13",
6009 config: Config{
6010 MaxVersion: VersionTLS13,
6011 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6012 SignSignatureAlgorithms: []signatureAlgorithm{
6013 signatureRSAPKCS1WithMD5,
6014 },
6015 Bugs: ProtocolBugs{
6016 IgnorePeerSignatureAlgorithmPreferences: true,
6017 IgnoreSignatureVersionChecks: true,
6018 },
6019 },
6020 shouldFail: true,
6021 expectedError: ":WRONG_SIGNATURE_TYPE:",
6022 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006023
6024 // Test that the agreed upon digest respects the client preferences and
6025 // the server digests.
6026 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006027 name: "NoCommonAlgorithms-Digests",
6028 config: Config{
6029 MaxVersion: VersionTLS12,
6030 ClientAuth: RequireAnyClientCert,
6031 VerifySignatureAlgorithms: []signatureAlgorithm{
6032 signatureRSAPKCS1WithSHA512,
6033 signatureRSAPKCS1WithSHA1,
6034 },
6035 },
6036 flags: []string{
6037 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6038 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6039 "-digest-prefs", "SHA256",
6040 },
6041 shouldFail: true,
6042 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6043 })
6044 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006045 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006046 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006047 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006048 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006049 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006050 signatureRSAPKCS1WithSHA512,
6051 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006052 },
6053 },
6054 flags: []string{
6055 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6056 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006057 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006058 },
David Benjaminca3d5452016-07-14 12:51:01 -04006059 shouldFail: true,
6060 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6061 })
6062 testCases = append(testCases, testCase{
6063 name: "NoCommonAlgorithms-TLS13",
6064 config: Config{
6065 MaxVersion: VersionTLS13,
6066 ClientAuth: RequireAnyClientCert,
6067 VerifySignatureAlgorithms: []signatureAlgorithm{
6068 signatureRSAPSSWithSHA512,
6069 signatureRSAPSSWithSHA384,
6070 },
6071 },
6072 flags: []string{
6073 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6074 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6075 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6076 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006077 shouldFail: true,
6078 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006079 })
6080 testCases = append(testCases, testCase{
6081 name: "Agree-Digest-SHA256",
6082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006083 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006084 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006085 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006086 signatureRSAPKCS1WithSHA1,
6087 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006088 },
6089 },
6090 flags: []string{
6091 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6092 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006093 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006094 },
Nick Harper60edffd2016-06-21 15:19:24 -07006095 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006096 })
6097 testCases = append(testCases, testCase{
6098 name: "Agree-Digest-SHA1",
6099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006100 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006101 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006102 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006103 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006104 },
6105 },
6106 flags: []string{
6107 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6108 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006109 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006110 },
Nick Harper60edffd2016-06-21 15:19:24 -07006111 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006112 })
6113 testCases = append(testCases, testCase{
6114 name: "Agree-Digest-Default",
6115 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006116 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006117 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006118 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006119 signatureRSAPKCS1WithSHA256,
6120 signatureECDSAWithP256AndSHA256,
6121 signatureRSAPKCS1WithSHA1,
6122 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006123 },
6124 },
6125 flags: []string{
6126 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6127 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6128 },
Nick Harper60edffd2016-06-21 15:19:24 -07006129 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006130 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006131
David Benjaminca3d5452016-07-14 12:51:01 -04006132 // Test that the signing preference list may include extra algorithms
6133 // without negotiation problems.
6134 testCases = append(testCases, testCase{
6135 testType: serverTest,
6136 name: "FilterExtraAlgorithms",
6137 config: Config{
6138 MaxVersion: VersionTLS12,
6139 VerifySignatureAlgorithms: []signatureAlgorithm{
6140 signatureRSAPKCS1WithSHA256,
6141 },
6142 },
6143 flags: []string{
6144 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6145 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6146 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6147 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6148 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6149 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6150 },
6151 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6152 })
6153
David Benjamin4c3ddf72016-06-29 18:13:53 -04006154 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6155 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006156 testCases = append(testCases, testCase{
6157 name: "CheckLeafCurve",
6158 config: Config{
6159 MaxVersion: VersionTLS12,
6160 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006161 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006162 },
6163 flags: []string{"-p384-only"},
6164 shouldFail: true,
6165 expectedError: ":BAD_ECC_CERT:",
6166 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006167
6168 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6169 testCases = append(testCases, testCase{
6170 name: "CheckLeafCurve-TLS13",
6171 config: Config{
6172 MaxVersion: VersionTLS13,
6173 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6174 Certificates: []Certificate{ecdsaP256Certificate},
6175 },
6176 flags: []string{"-p384-only"},
6177 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006178
6179 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6180 testCases = append(testCases, testCase{
6181 name: "ECDSACurveMismatch-Verify-TLS12",
6182 config: Config{
6183 MaxVersion: VersionTLS12,
6184 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6185 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006186 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006187 signatureECDSAWithP384AndSHA384,
6188 },
6189 },
6190 })
6191
6192 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6193 testCases = append(testCases, testCase{
6194 name: "ECDSACurveMismatch-Verify-TLS13",
6195 config: Config{
6196 MaxVersion: VersionTLS13,
6197 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6198 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006199 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006200 signatureECDSAWithP384AndSHA384,
6201 },
6202 Bugs: ProtocolBugs{
6203 SkipECDSACurveCheck: true,
6204 },
6205 },
6206 shouldFail: true,
6207 expectedError: ":WRONG_SIGNATURE_TYPE:",
6208 })
6209
6210 // Signature algorithm selection in TLS 1.3 should take the curve into
6211 // account.
6212 testCases = append(testCases, testCase{
6213 testType: serverTest,
6214 name: "ECDSACurveMismatch-Sign-TLS13",
6215 config: Config{
6216 MaxVersion: VersionTLS13,
6217 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006218 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006219 signatureECDSAWithP384AndSHA384,
6220 signatureECDSAWithP256AndSHA256,
6221 },
6222 },
6223 flags: []string{
6224 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6225 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6226 },
6227 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6228 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006229
6230 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6231 // server does not attempt to sign in that case.
6232 testCases = append(testCases, testCase{
6233 testType: serverTest,
6234 name: "RSA-PSS-Large",
6235 config: Config{
6236 MaxVersion: VersionTLS13,
6237 VerifySignatureAlgorithms: []signatureAlgorithm{
6238 signatureRSAPSSWithSHA512,
6239 },
6240 },
6241 flags: []string{
6242 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6243 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6244 },
6245 shouldFail: true,
6246 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6247 })
David Benjamin000800a2014-11-14 01:43:59 -05006248}
6249
David Benjamin83f90402015-01-27 01:09:43 -05006250// timeouts is the retransmit schedule for BoringSSL. It doubles and
6251// caps at 60 seconds. On the 13th timeout, it gives up.
6252var timeouts = []time.Duration{
6253 1 * time.Second,
6254 2 * time.Second,
6255 4 * time.Second,
6256 8 * time.Second,
6257 16 * time.Second,
6258 32 * time.Second,
6259 60 * time.Second,
6260 60 * time.Second,
6261 60 * time.Second,
6262 60 * time.Second,
6263 60 * time.Second,
6264 60 * time.Second,
6265 60 * time.Second,
6266}
6267
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006268// shortTimeouts is an alternate set of timeouts which would occur if the
6269// initial timeout duration was set to 250ms.
6270var shortTimeouts = []time.Duration{
6271 250 * time.Millisecond,
6272 500 * time.Millisecond,
6273 1 * time.Second,
6274 2 * time.Second,
6275 4 * time.Second,
6276 8 * time.Second,
6277 16 * time.Second,
6278 32 * time.Second,
6279 60 * time.Second,
6280 60 * time.Second,
6281 60 * time.Second,
6282 60 * time.Second,
6283 60 * time.Second,
6284}
6285
David Benjamin83f90402015-01-27 01:09:43 -05006286func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006287 // These tests work by coordinating some behavior on both the shim and
6288 // the runner.
6289 //
6290 // TimeoutSchedule configures the runner to send a series of timeout
6291 // opcodes to the shim (see packetAdaptor) immediately before reading
6292 // each peer handshake flight N. The timeout opcode both simulates a
6293 // timeout in the shim and acts as a synchronization point to help the
6294 // runner bracket each handshake flight.
6295 //
6296 // We assume the shim does not read from the channel eagerly. It must
6297 // first wait until it has sent flight N and is ready to receive
6298 // handshake flight N+1. At this point, it will process the timeout
6299 // opcode. It must then immediately respond with a timeout ACK and act
6300 // as if the shim was idle for the specified amount of time.
6301 //
6302 // The runner then drops all packets received before the ACK and
6303 // continues waiting for flight N. This ordering results in one attempt
6304 // at sending flight N to be dropped. For the test to complete, the
6305 // shim must send flight N again, testing that the shim implements DTLS
6306 // retransmit on a timeout.
6307
Steven Valdez143e8b32016-07-11 13:19:03 -04006308 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006309 // likely be more epochs to cross and the final message's retransmit may
6310 // be more complex.
6311
David Benjamin585d7a42016-06-02 14:58:00 -04006312 for _, async := range []bool{true, false} {
6313 var tests []testCase
6314
6315 // Test that this is indeed the timeout schedule. Stress all
6316 // four patterns of handshake.
6317 for i := 1; i < len(timeouts); i++ {
6318 number := strconv.Itoa(i)
6319 tests = append(tests, testCase{
6320 protocol: dtls,
6321 name: "DTLS-Retransmit-Client-" + number,
6322 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006323 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006324 Bugs: ProtocolBugs{
6325 TimeoutSchedule: timeouts[:i],
6326 },
6327 },
6328 resumeSession: true,
6329 })
6330 tests = append(tests, testCase{
6331 protocol: dtls,
6332 testType: serverTest,
6333 name: "DTLS-Retransmit-Server-" + number,
6334 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006335 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006336 Bugs: ProtocolBugs{
6337 TimeoutSchedule: timeouts[:i],
6338 },
6339 },
6340 resumeSession: true,
6341 })
6342 }
6343
6344 // Test that exceeding the timeout schedule hits a read
6345 // timeout.
6346 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006347 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006348 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006350 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006351 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006352 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006353 },
6354 },
6355 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006356 shouldFail: true,
6357 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006358 })
David Benjamin585d7a42016-06-02 14:58:00 -04006359
6360 if async {
6361 // Test that timeout handling has a fudge factor, due to API
6362 // problems.
6363 tests = append(tests, testCase{
6364 protocol: dtls,
6365 name: "DTLS-Retransmit-Fudge",
6366 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006367 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006368 Bugs: ProtocolBugs{
6369 TimeoutSchedule: []time.Duration{
6370 timeouts[0] - 10*time.Millisecond,
6371 },
6372 },
6373 },
6374 resumeSession: true,
6375 })
6376 }
6377
6378 // Test that the final Finished retransmitting isn't
6379 // duplicated if the peer badly fragments everything.
6380 tests = append(tests, testCase{
6381 testType: serverTest,
6382 protocol: dtls,
6383 name: "DTLS-Retransmit-Fragmented",
6384 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006385 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006386 Bugs: ProtocolBugs{
6387 TimeoutSchedule: []time.Duration{timeouts[0]},
6388 MaxHandshakeRecordLength: 2,
6389 },
6390 },
6391 })
6392
6393 // Test the timeout schedule when a shorter initial timeout duration is set.
6394 tests = append(tests, testCase{
6395 protocol: dtls,
6396 name: "DTLS-Retransmit-Short-Client",
6397 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006398 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006399 Bugs: ProtocolBugs{
6400 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6401 },
6402 },
6403 resumeSession: true,
6404 flags: []string{"-initial-timeout-duration-ms", "250"},
6405 })
6406 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006407 protocol: dtls,
6408 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006409 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006411 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006412 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006413 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006414 },
6415 },
6416 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006417 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006418 })
David Benjamin585d7a42016-06-02 14:58:00 -04006419
6420 for _, test := range tests {
6421 if async {
6422 test.name += "-Async"
6423 test.flags = append(test.flags, "-async")
6424 }
6425
6426 testCases = append(testCases, test)
6427 }
David Benjamin83f90402015-01-27 01:09:43 -05006428 }
David Benjamin83f90402015-01-27 01:09:43 -05006429}
6430
David Benjaminc565ebb2015-04-03 04:06:36 -04006431func addExportKeyingMaterialTests() {
6432 for _, vers := range tlsVersions {
6433 if vers.version == VersionSSL30 {
6434 continue
6435 }
6436 testCases = append(testCases, testCase{
6437 name: "ExportKeyingMaterial-" + vers.name,
6438 config: Config{
6439 MaxVersion: vers.version,
6440 },
6441 exportKeyingMaterial: 1024,
6442 exportLabel: "label",
6443 exportContext: "context",
6444 useExportContext: true,
6445 })
6446 testCases = append(testCases, testCase{
6447 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6448 config: Config{
6449 MaxVersion: vers.version,
6450 },
6451 exportKeyingMaterial: 1024,
6452 })
6453 testCases = append(testCases, testCase{
6454 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6455 config: Config{
6456 MaxVersion: vers.version,
6457 },
6458 exportKeyingMaterial: 1024,
6459 useExportContext: true,
6460 })
6461 testCases = append(testCases, testCase{
6462 name: "ExportKeyingMaterial-Small-" + vers.name,
6463 config: Config{
6464 MaxVersion: vers.version,
6465 },
6466 exportKeyingMaterial: 1,
6467 exportLabel: "label",
6468 exportContext: "context",
6469 useExportContext: true,
6470 })
6471 }
6472 testCases = append(testCases, testCase{
6473 name: "ExportKeyingMaterial-SSL3",
6474 config: Config{
6475 MaxVersion: VersionSSL30,
6476 },
6477 exportKeyingMaterial: 1024,
6478 exportLabel: "label",
6479 exportContext: "context",
6480 useExportContext: true,
6481 shouldFail: true,
6482 expectedError: "failed to export keying material",
6483 })
6484}
6485
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006486func addTLSUniqueTests() {
6487 for _, isClient := range []bool{false, true} {
6488 for _, isResumption := range []bool{false, true} {
6489 for _, hasEMS := range []bool{false, true} {
6490 var suffix string
6491 if isResumption {
6492 suffix = "Resume-"
6493 } else {
6494 suffix = "Full-"
6495 }
6496
6497 if hasEMS {
6498 suffix += "EMS-"
6499 } else {
6500 suffix += "NoEMS-"
6501 }
6502
6503 if isClient {
6504 suffix += "Client"
6505 } else {
6506 suffix += "Server"
6507 }
6508
6509 test := testCase{
6510 name: "TLSUnique-" + suffix,
6511 testTLSUnique: true,
6512 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006513 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006514 Bugs: ProtocolBugs{
6515 NoExtendedMasterSecret: !hasEMS,
6516 },
6517 },
6518 }
6519
6520 if isResumption {
6521 test.resumeSession = true
6522 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006523 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006524 Bugs: ProtocolBugs{
6525 NoExtendedMasterSecret: !hasEMS,
6526 },
6527 }
6528 }
6529
6530 if isResumption && !hasEMS {
6531 test.shouldFail = true
6532 test.expectedError = "failed to get tls-unique"
6533 }
6534
6535 testCases = append(testCases, test)
6536 }
6537 }
6538 }
6539}
6540
Adam Langley09505632015-07-30 18:10:13 -07006541func addCustomExtensionTests() {
6542 expectedContents := "custom extension"
6543 emptyString := ""
6544
6545 for _, isClient := range []bool{false, true} {
6546 suffix := "Server"
6547 flag := "-enable-server-custom-extension"
6548 testType := serverTest
6549 if isClient {
6550 suffix = "Client"
6551 flag = "-enable-client-custom-extension"
6552 testType = clientTest
6553 }
6554
6555 testCases = append(testCases, testCase{
6556 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006557 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006558 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006559 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006560 Bugs: ProtocolBugs{
6561 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006562 ExpectedCustomExtension: &expectedContents,
6563 },
6564 },
6565 flags: []string{flag},
6566 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006567 testCases = append(testCases, testCase{
6568 testType: testType,
6569 name: "CustomExtensions-" + suffix + "-TLS13",
6570 config: Config{
6571 MaxVersion: VersionTLS13,
6572 Bugs: ProtocolBugs{
6573 CustomExtension: expectedContents,
6574 ExpectedCustomExtension: &expectedContents,
6575 },
6576 },
6577 flags: []string{flag},
6578 })
Adam Langley09505632015-07-30 18:10:13 -07006579
6580 // If the parse callback fails, the handshake should also fail.
6581 testCases = append(testCases, testCase{
6582 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006583 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006584 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006585 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006586 Bugs: ProtocolBugs{
6587 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006588 ExpectedCustomExtension: &expectedContents,
6589 },
6590 },
David Benjamin399e7c92015-07-30 23:01:27 -04006591 flags: []string{flag},
6592 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006593 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6594 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006595 testCases = append(testCases, testCase{
6596 testType: testType,
6597 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6598 config: Config{
6599 MaxVersion: VersionTLS13,
6600 Bugs: ProtocolBugs{
6601 CustomExtension: expectedContents + "foo",
6602 ExpectedCustomExtension: &expectedContents,
6603 },
6604 },
6605 flags: []string{flag},
6606 shouldFail: true,
6607 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6608 })
Adam Langley09505632015-07-30 18:10:13 -07006609
6610 // If the add callback fails, the handshake should also fail.
6611 testCases = append(testCases, testCase{
6612 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006613 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006614 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006615 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006616 Bugs: ProtocolBugs{
6617 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006618 ExpectedCustomExtension: &expectedContents,
6619 },
6620 },
David Benjamin399e7c92015-07-30 23:01:27 -04006621 flags: []string{flag, "-custom-extension-fail-add"},
6622 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006623 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6624 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006625 testCases = append(testCases, testCase{
6626 testType: testType,
6627 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6628 config: Config{
6629 MaxVersion: VersionTLS13,
6630 Bugs: ProtocolBugs{
6631 CustomExtension: expectedContents,
6632 ExpectedCustomExtension: &expectedContents,
6633 },
6634 },
6635 flags: []string{flag, "-custom-extension-fail-add"},
6636 shouldFail: true,
6637 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6638 })
Adam Langley09505632015-07-30 18:10:13 -07006639
6640 // If the add callback returns zero, no extension should be
6641 // added.
6642 skipCustomExtension := expectedContents
6643 if isClient {
6644 // For the case where the client skips sending the
6645 // custom extension, the server must not “echo” it.
6646 skipCustomExtension = ""
6647 }
6648 testCases = append(testCases, testCase{
6649 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006650 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006651 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006652 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006653 Bugs: ProtocolBugs{
6654 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006655 ExpectedCustomExtension: &emptyString,
6656 },
6657 },
6658 flags: []string{flag, "-custom-extension-skip"},
6659 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006660 testCases = append(testCases, testCase{
6661 testType: testType,
6662 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6663 config: Config{
6664 MaxVersion: VersionTLS13,
6665 Bugs: ProtocolBugs{
6666 CustomExtension: skipCustomExtension,
6667 ExpectedCustomExtension: &emptyString,
6668 },
6669 },
6670 flags: []string{flag, "-custom-extension-skip"},
6671 })
Adam Langley09505632015-07-30 18:10:13 -07006672 }
6673
6674 // The custom extension add callback should not be called if the client
6675 // doesn't send the extension.
6676 testCases = append(testCases, testCase{
6677 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006678 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006679 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006680 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006681 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006682 ExpectedCustomExtension: &emptyString,
6683 },
6684 },
6685 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6686 })
Adam Langley2deb9842015-08-07 11:15:37 -07006687
Steven Valdez143e8b32016-07-11 13:19:03 -04006688 testCases = append(testCases, testCase{
6689 testType: serverTest,
6690 name: "CustomExtensions-NotCalled-Server-TLS13",
6691 config: Config{
6692 MaxVersion: VersionTLS13,
6693 Bugs: ProtocolBugs{
6694 ExpectedCustomExtension: &emptyString,
6695 },
6696 },
6697 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6698 })
6699
Adam Langley2deb9842015-08-07 11:15:37 -07006700 // Test an unknown extension from the server.
6701 testCases = append(testCases, testCase{
6702 testType: clientTest,
6703 name: "UnknownExtension-Client",
6704 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006705 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006706 Bugs: ProtocolBugs{
6707 CustomExtension: expectedContents,
6708 },
6709 },
David Benjamin0c40a962016-08-01 12:05:50 -04006710 shouldFail: true,
6711 expectedError: ":UNEXPECTED_EXTENSION:",
6712 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006713 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006714 testCases = append(testCases, testCase{
6715 testType: clientTest,
6716 name: "UnknownExtension-Client-TLS13",
6717 config: Config{
6718 MaxVersion: VersionTLS13,
6719 Bugs: ProtocolBugs{
6720 CustomExtension: expectedContents,
6721 },
6722 },
David Benjamin0c40a962016-08-01 12:05:50 -04006723 shouldFail: true,
6724 expectedError: ":UNEXPECTED_EXTENSION:",
6725 expectedLocalError: "remote error: unsupported extension",
6726 })
6727
6728 // Test a known but unoffered extension from the server.
6729 testCases = append(testCases, testCase{
6730 testType: clientTest,
6731 name: "UnofferedExtension-Client",
6732 config: Config{
6733 MaxVersion: VersionTLS12,
6734 Bugs: ProtocolBugs{
6735 SendALPN: "alpn",
6736 },
6737 },
6738 shouldFail: true,
6739 expectedError: ":UNEXPECTED_EXTENSION:",
6740 expectedLocalError: "remote error: unsupported extension",
6741 })
6742 testCases = append(testCases, testCase{
6743 testType: clientTest,
6744 name: "UnofferedExtension-Client-TLS13",
6745 config: Config{
6746 MaxVersion: VersionTLS13,
6747 Bugs: ProtocolBugs{
6748 SendALPN: "alpn",
6749 },
6750 },
6751 shouldFail: true,
6752 expectedError: ":UNEXPECTED_EXTENSION:",
6753 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006754 })
Adam Langley09505632015-07-30 18:10:13 -07006755}
6756
David Benjaminb36a3952015-12-01 18:53:13 -05006757func addRSAClientKeyExchangeTests() {
6758 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6759 testCases = append(testCases, testCase{
6760 testType: serverTest,
6761 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6762 config: Config{
6763 // Ensure the ClientHello version and final
6764 // version are different, to detect if the
6765 // server uses the wrong one.
6766 MaxVersion: VersionTLS11,
6767 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6768 Bugs: ProtocolBugs{
6769 BadRSAClientKeyExchange: bad,
6770 },
6771 },
6772 shouldFail: true,
6773 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6774 })
6775 }
6776}
6777
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006778var testCurves = []struct {
6779 name string
6780 id CurveID
6781}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006782 {"P-256", CurveP256},
6783 {"P-384", CurveP384},
6784 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006785 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006786}
6787
Steven Valdez5440fe02016-07-18 12:40:30 -04006788const bogusCurve = 0x1234
6789
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006790func addCurveTests() {
6791 for _, curve := range testCurves {
6792 testCases = append(testCases, testCase{
6793 name: "CurveTest-Client-" + curve.name,
6794 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006795 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006796 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6797 CurvePreferences: []CurveID{curve.id},
6798 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006799 flags: []string{
6800 "-enable-all-curves",
6801 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6802 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006803 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006804 })
6805 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006806 name: "CurveTest-Client-" + curve.name + "-TLS13",
6807 config: Config{
6808 MaxVersion: VersionTLS13,
6809 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6810 CurvePreferences: []CurveID{curve.id},
6811 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006812 flags: []string{
6813 "-enable-all-curves",
6814 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6815 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006816 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006817 })
6818 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006819 testType: serverTest,
6820 name: "CurveTest-Server-" + curve.name,
6821 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006822 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006823 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6824 CurvePreferences: []CurveID{curve.id},
6825 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006826 flags: []string{
6827 "-enable-all-curves",
6828 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6829 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006830 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006831 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006832 testCases = append(testCases, testCase{
6833 testType: serverTest,
6834 name: "CurveTest-Server-" + curve.name + "-TLS13",
6835 config: Config{
6836 MaxVersion: VersionTLS13,
6837 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6838 CurvePreferences: []CurveID{curve.id},
6839 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006840 flags: []string{
6841 "-enable-all-curves",
6842 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6843 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006844 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006845 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006846 }
David Benjamin241ae832016-01-15 03:04:54 -05006847
6848 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006849 testCases = append(testCases, testCase{
6850 testType: serverTest,
6851 name: "UnknownCurve",
6852 config: Config{
6853 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6854 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6855 },
6856 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006857
6858 // The server must not consider ECDHE ciphers when there are no
6859 // supported curves.
6860 testCases = append(testCases, testCase{
6861 testType: serverTest,
6862 name: "NoSupportedCurves",
6863 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006864 MaxVersion: VersionTLS12,
6865 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6866 Bugs: ProtocolBugs{
6867 NoSupportedCurves: true,
6868 },
6869 },
6870 shouldFail: true,
6871 expectedError: ":NO_SHARED_CIPHER:",
6872 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006873 testCases = append(testCases, testCase{
6874 testType: serverTest,
6875 name: "NoSupportedCurves-TLS13",
6876 config: Config{
6877 MaxVersion: VersionTLS13,
6878 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6879 Bugs: ProtocolBugs{
6880 NoSupportedCurves: true,
6881 },
6882 },
6883 shouldFail: true,
6884 expectedError: ":NO_SHARED_CIPHER:",
6885 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006886
6887 // The server must fall back to another cipher when there are no
6888 // supported curves.
6889 testCases = append(testCases, testCase{
6890 testType: serverTest,
6891 name: "NoCommonCurves",
6892 config: Config{
6893 MaxVersion: VersionTLS12,
6894 CipherSuites: []uint16{
6895 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6896 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6897 },
6898 CurvePreferences: []CurveID{CurveP224},
6899 },
6900 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6901 })
6902
6903 // The client must reject bogus curves and disabled curves.
6904 testCases = append(testCases, testCase{
6905 name: "BadECDHECurve",
6906 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006907 MaxVersion: VersionTLS12,
6908 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6909 Bugs: ProtocolBugs{
6910 SendCurve: bogusCurve,
6911 },
6912 },
6913 shouldFail: true,
6914 expectedError: ":WRONG_CURVE:",
6915 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006916 testCases = append(testCases, testCase{
6917 name: "BadECDHECurve-TLS13",
6918 config: Config{
6919 MaxVersion: VersionTLS13,
6920 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6921 Bugs: ProtocolBugs{
6922 SendCurve: bogusCurve,
6923 },
6924 },
6925 shouldFail: true,
6926 expectedError: ":WRONG_CURVE:",
6927 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006928
6929 testCases = append(testCases, testCase{
6930 name: "UnsupportedCurve",
6931 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006932 MaxVersion: VersionTLS12,
6933 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6934 CurvePreferences: []CurveID{CurveP256},
6935 Bugs: ProtocolBugs{
6936 IgnorePeerCurvePreferences: true,
6937 },
6938 },
6939 flags: []string{"-p384-only"},
6940 shouldFail: true,
6941 expectedError: ":WRONG_CURVE:",
6942 })
6943
David Benjamin4f921572016-07-17 14:20:10 +02006944 testCases = append(testCases, testCase{
6945 // TODO(davidben): Add a TLS 1.3 version where
6946 // HelloRetryRequest requests an unsupported curve.
6947 name: "UnsupportedCurve-ServerHello-TLS13",
6948 config: Config{
6949 MaxVersion: VersionTLS12,
6950 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6951 CurvePreferences: []CurveID{CurveP384},
6952 Bugs: ProtocolBugs{
6953 SendCurve: CurveP256,
6954 },
6955 },
6956 flags: []string{"-p384-only"},
6957 shouldFail: true,
6958 expectedError: ":WRONG_CURVE:",
6959 })
6960
David Benjamin4c3ddf72016-06-29 18:13:53 -04006961 // Test invalid curve points.
6962 testCases = append(testCases, testCase{
6963 name: "InvalidECDHPoint-Client",
6964 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006965 MaxVersion: VersionTLS12,
6966 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6967 CurvePreferences: []CurveID{CurveP256},
6968 Bugs: ProtocolBugs{
6969 InvalidECDHPoint: true,
6970 },
6971 },
6972 shouldFail: true,
6973 expectedError: ":INVALID_ENCODING:",
6974 })
6975 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006976 name: "InvalidECDHPoint-Client-TLS13",
6977 config: Config{
6978 MaxVersion: VersionTLS13,
6979 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6980 CurvePreferences: []CurveID{CurveP256},
6981 Bugs: ProtocolBugs{
6982 InvalidECDHPoint: true,
6983 },
6984 },
6985 shouldFail: true,
6986 expectedError: ":INVALID_ENCODING:",
6987 })
6988 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006989 testType: serverTest,
6990 name: "InvalidECDHPoint-Server",
6991 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006992 MaxVersion: VersionTLS12,
6993 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6994 CurvePreferences: []CurveID{CurveP256},
6995 Bugs: ProtocolBugs{
6996 InvalidECDHPoint: true,
6997 },
6998 },
6999 shouldFail: true,
7000 expectedError: ":INVALID_ENCODING:",
7001 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007002 testCases = append(testCases, testCase{
7003 testType: serverTest,
7004 name: "InvalidECDHPoint-Server-TLS13",
7005 config: Config{
7006 MaxVersion: VersionTLS13,
7007 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7008 CurvePreferences: []CurveID{CurveP256},
7009 Bugs: ProtocolBugs{
7010 InvalidECDHPoint: true,
7011 },
7012 },
7013 shouldFail: true,
7014 expectedError: ":INVALID_ENCODING:",
7015 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007016}
7017
Matt Braithwaite54217e42016-06-13 13:03:47 -07007018func addCECPQ1Tests() {
7019 testCases = append(testCases, testCase{
7020 testType: clientTest,
7021 name: "CECPQ1-Client-BadX25519Part",
7022 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007023 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007024 MinVersion: VersionTLS12,
7025 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7026 Bugs: ProtocolBugs{
7027 CECPQ1BadX25519Part: true,
7028 },
7029 },
7030 flags: []string{"-cipher", "kCECPQ1"},
7031 shouldFail: true,
7032 expectedLocalError: "local error: bad record MAC",
7033 })
7034 testCases = append(testCases, testCase{
7035 testType: clientTest,
7036 name: "CECPQ1-Client-BadNewhopePart",
7037 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007038 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007039 MinVersion: VersionTLS12,
7040 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7041 Bugs: ProtocolBugs{
7042 CECPQ1BadNewhopePart: true,
7043 },
7044 },
7045 flags: []string{"-cipher", "kCECPQ1"},
7046 shouldFail: true,
7047 expectedLocalError: "local error: bad record MAC",
7048 })
7049 testCases = append(testCases, testCase{
7050 testType: serverTest,
7051 name: "CECPQ1-Server-BadX25519Part",
7052 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007053 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007054 MinVersion: VersionTLS12,
7055 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7056 Bugs: ProtocolBugs{
7057 CECPQ1BadX25519Part: true,
7058 },
7059 },
7060 flags: []string{"-cipher", "kCECPQ1"},
7061 shouldFail: true,
7062 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7063 })
7064 testCases = append(testCases, testCase{
7065 testType: serverTest,
7066 name: "CECPQ1-Server-BadNewhopePart",
7067 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007068 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007069 MinVersion: VersionTLS12,
7070 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7071 Bugs: ProtocolBugs{
7072 CECPQ1BadNewhopePart: true,
7073 },
7074 },
7075 flags: []string{"-cipher", "kCECPQ1"},
7076 shouldFail: true,
7077 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7078 })
7079}
7080
David Benjamin5c4e8572016-08-19 17:44:53 -04007081func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007082 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007083 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007084 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007085 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007086 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7087 Bugs: ProtocolBugs{
7088 // This is a 1234-bit prime number, generated
7089 // with:
7090 // openssl gendh 1234 | openssl asn1parse -i
7091 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7092 },
7093 },
David Benjamin9e68f192016-06-30 14:55:33 -04007094 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007095 })
7096 testCases = append(testCases, testCase{
7097 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007098 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007099 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007100 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007101 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7102 },
7103 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007104 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007105 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007106}
7107
David Benjaminc9ae27c2016-06-24 22:56:37 -04007108func addTLS13RecordTests() {
7109 testCases = append(testCases, testCase{
7110 name: "TLS13-RecordPadding",
7111 config: Config{
7112 MaxVersion: VersionTLS13,
7113 MinVersion: VersionTLS13,
7114 Bugs: ProtocolBugs{
7115 RecordPadding: 10,
7116 },
7117 },
7118 })
7119
7120 testCases = append(testCases, testCase{
7121 name: "TLS13-EmptyRecords",
7122 config: Config{
7123 MaxVersion: VersionTLS13,
7124 MinVersion: VersionTLS13,
7125 Bugs: ProtocolBugs{
7126 OmitRecordContents: true,
7127 },
7128 },
7129 shouldFail: true,
7130 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7131 })
7132
7133 testCases = append(testCases, testCase{
7134 name: "TLS13-OnlyPadding",
7135 config: Config{
7136 MaxVersion: VersionTLS13,
7137 MinVersion: VersionTLS13,
7138 Bugs: ProtocolBugs{
7139 OmitRecordContents: true,
7140 RecordPadding: 10,
7141 },
7142 },
7143 shouldFail: true,
7144 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7145 })
7146
7147 testCases = append(testCases, testCase{
7148 name: "TLS13-WrongOuterRecord",
7149 config: Config{
7150 MaxVersion: VersionTLS13,
7151 MinVersion: VersionTLS13,
7152 Bugs: ProtocolBugs{
7153 OuterRecordType: recordTypeHandshake,
7154 },
7155 },
7156 shouldFail: true,
7157 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7158 })
7159}
7160
David Benjamin82261be2016-07-07 14:32:50 -07007161func addChangeCipherSpecTests() {
7162 // Test missing ChangeCipherSpecs.
7163 testCases = append(testCases, testCase{
7164 name: "SkipChangeCipherSpec-Client",
7165 config: Config{
7166 MaxVersion: VersionTLS12,
7167 Bugs: ProtocolBugs{
7168 SkipChangeCipherSpec: true,
7169 },
7170 },
7171 shouldFail: true,
7172 expectedError: ":UNEXPECTED_RECORD:",
7173 })
7174 testCases = append(testCases, testCase{
7175 testType: serverTest,
7176 name: "SkipChangeCipherSpec-Server",
7177 config: Config{
7178 MaxVersion: VersionTLS12,
7179 Bugs: ProtocolBugs{
7180 SkipChangeCipherSpec: true,
7181 },
7182 },
7183 shouldFail: true,
7184 expectedError: ":UNEXPECTED_RECORD:",
7185 })
7186 testCases = append(testCases, testCase{
7187 testType: serverTest,
7188 name: "SkipChangeCipherSpec-Server-NPN",
7189 config: Config{
7190 MaxVersion: VersionTLS12,
7191 NextProtos: []string{"bar"},
7192 Bugs: ProtocolBugs{
7193 SkipChangeCipherSpec: true,
7194 },
7195 },
7196 flags: []string{
7197 "-advertise-npn", "\x03foo\x03bar\x03baz",
7198 },
7199 shouldFail: true,
7200 expectedError: ":UNEXPECTED_RECORD:",
7201 })
7202
7203 // Test synchronization between the handshake and ChangeCipherSpec.
7204 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7205 // rejected. Test both with and without handshake packing to handle both
7206 // when the partial post-CCS message is in its own record and when it is
7207 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007208 for _, packed := range []bool{false, true} {
7209 var suffix string
7210 if packed {
7211 suffix = "-Packed"
7212 }
7213
7214 testCases = append(testCases, testCase{
7215 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7216 config: Config{
7217 MaxVersion: VersionTLS12,
7218 Bugs: ProtocolBugs{
7219 FragmentAcrossChangeCipherSpec: true,
7220 PackHandshakeFlight: packed,
7221 },
7222 },
7223 shouldFail: true,
7224 expectedError: ":UNEXPECTED_RECORD:",
7225 })
7226 testCases = append(testCases, testCase{
7227 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7228 config: Config{
7229 MaxVersion: VersionTLS12,
7230 },
7231 resumeSession: true,
7232 resumeConfig: &Config{
7233 MaxVersion: VersionTLS12,
7234 Bugs: ProtocolBugs{
7235 FragmentAcrossChangeCipherSpec: true,
7236 PackHandshakeFlight: packed,
7237 },
7238 },
7239 shouldFail: true,
7240 expectedError: ":UNEXPECTED_RECORD:",
7241 })
7242 testCases = append(testCases, testCase{
7243 testType: serverTest,
7244 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7245 config: Config{
7246 MaxVersion: VersionTLS12,
7247 Bugs: ProtocolBugs{
7248 FragmentAcrossChangeCipherSpec: true,
7249 PackHandshakeFlight: packed,
7250 },
7251 },
7252 shouldFail: true,
7253 expectedError: ":UNEXPECTED_RECORD:",
7254 })
7255 testCases = append(testCases, testCase{
7256 testType: serverTest,
7257 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7258 config: Config{
7259 MaxVersion: VersionTLS12,
7260 },
7261 resumeSession: true,
7262 resumeConfig: &Config{
7263 MaxVersion: VersionTLS12,
7264 Bugs: ProtocolBugs{
7265 FragmentAcrossChangeCipherSpec: true,
7266 PackHandshakeFlight: packed,
7267 },
7268 },
7269 shouldFail: true,
7270 expectedError: ":UNEXPECTED_RECORD:",
7271 })
7272 testCases = append(testCases, testCase{
7273 testType: serverTest,
7274 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7275 config: Config{
7276 MaxVersion: VersionTLS12,
7277 NextProtos: []string{"bar"},
7278 Bugs: ProtocolBugs{
7279 FragmentAcrossChangeCipherSpec: true,
7280 PackHandshakeFlight: packed,
7281 },
7282 },
7283 flags: []string{
7284 "-advertise-npn", "\x03foo\x03bar\x03baz",
7285 },
7286 shouldFail: true,
7287 expectedError: ":UNEXPECTED_RECORD:",
7288 })
7289 }
7290
David Benjamin61672812016-07-14 23:10:43 -04007291 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7292 // messages in the handshake queue. Do this by testing the server
7293 // reading the client Finished, reversing the flight so Finished comes
7294 // first.
7295 testCases = append(testCases, testCase{
7296 protocol: dtls,
7297 testType: serverTest,
7298 name: "SendUnencryptedFinished-DTLS",
7299 config: Config{
7300 MaxVersion: VersionTLS12,
7301 Bugs: ProtocolBugs{
7302 SendUnencryptedFinished: true,
7303 ReverseHandshakeFragments: true,
7304 },
7305 },
7306 shouldFail: true,
7307 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7308 })
7309
Steven Valdez143e8b32016-07-11 13:19:03 -04007310 // Test synchronization between encryption changes and the handshake in
7311 // TLS 1.3, where ChangeCipherSpec is implicit.
7312 testCases = append(testCases, testCase{
7313 name: "PartialEncryptedExtensionsWithServerHello",
7314 config: Config{
7315 MaxVersion: VersionTLS13,
7316 Bugs: ProtocolBugs{
7317 PartialEncryptedExtensionsWithServerHello: true,
7318 },
7319 },
7320 shouldFail: true,
7321 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7322 })
7323 testCases = append(testCases, testCase{
7324 testType: serverTest,
7325 name: "PartialClientFinishedWithClientHello",
7326 config: Config{
7327 MaxVersion: VersionTLS13,
7328 Bugs: ProtocolBugs{
7329 PartialClientFinishedWithClientHello: true,
7330 },
7331 },
7332 shouldFail: true,
7333 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7334 })
7335
David Benjamin82261be2016-07-07 14:32:50 -07007336 // Test that early ChangeCipherSpecs are handled correctly.
7337 testCases = append(testCases, testCase{
7338 testType: serverTest,
7339 name: "EarlyChangeCipherSpec-server-1",
7340 config: Config{
7341 MaxVersion: VersionTLS12,
7342 Bugs: ProtocolBugs{
7343 EarlyChangeCipherSpec: 1,
7344 },
7345 },
7346 shouldFail: true,
7347 expectedError: ":UNEXPECTED_RECORD:",
7348 })
7349 testCases = append(testCases, testCase{
7350 testType: serverTest,
7351 name: "EarlyChangeCipherSpec-server-2",
7352 config: Config{
7353 MaxVersion: VersionTLS12,
7354 Bugs: ProtocolBugs{
7355 EarlyChangeCipherSpec: 2,
7356 },
7357 },
7358 shouldFail: true,
7359 expectedError: ":UNEXPECTED_RECORD:",
7360 })
7361 testCases = append(testCases, testCase{
7362 protocol: dtls,
7363 name: "StrayChangeCipherSpec",
7364 config: Config{
7365 // TODO(davidben): Once DTLS 1.3 exists, test
7366 // that stray ChangeCipherSpec messages are
7367 // rejected.
7368 MaxVersion: VersionTLS12,
7369 Bugs: ProtocolBugs{
7370 StrayChangeCipherSpec: true,
7371 },
7372 },
7373 })
7374
7375 // Test that the contents of ChangeCipherSpec are checked.
7376 testCases = append(testCases, testCase{
7377 name: "BadChangeCipherSpec-1",
7378 config: Config{
7379 MaxVersion: VersionTLS12,
7380 Bugs: ProtocolBugs{
7381 BadChangeCipherSpec: []byte{2},
7382 },
7383 },
7384 shouldFail: true,
7385 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7386 })
7387 testCases = append(testCases, testCase{
7388 name: "BadChangeCipherSpec-2",
7389 config: Config{
7390 MaxVersion: VersionTLS12,
7391 Bugs: ProtocolBugs{
7392 BadChangeCipherSpec: []byte{1, 1},
7393 },
7394 },
7395 shouldFail: true,
7396 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7397 })
7398 testCases = append(testCases, testCase{
7399 protocol: dtls,
7400 name: "BadChangeCipherSpec-DTLS-1",
7401 config: Config{
7402 MaxVersion: VersionTLS12,
7403 Bugs: ProtocolBugs{
7404 BadChangeCipherSpec: []byte{2},
7405 },
7406 },
7407 shouldFail: true,
7408 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7409 })
7410 testCases = append(testCases, testCase{
7411 protocol: dtls,
7412 name: "BadChangeCipherSpec-DTLS-2",
7413 config: Config{
7414 MaxVersion: VersionTLS12,
7415 Bugs: ProtocolBugs{
7416 BadChangeCipherSpec: []byte{1, 1},
7417 },
7418 },
7419 shouldFail: true,
7420 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7421 })
7422}
7423
David Benjamin0b8d5da2016-07-15 00:39:56 -04007424func addWrongMessageTypeTests() {
7425 for _, protocol := range []protocol{tls, dtls} {
7426 var suffix string
7427 if protocol == dtls {
7428 suffix = "-DTLS"
7429 }
7430
7431 testCases = append(testCases, testCase{
7432 protocol: protocol,
7433 testType: serverTest,
7434 name: "WrongMessageType-ClientHello" + suffix,
7435 config: Config{
7436 MaxVersion: VersionTLS12,
7437 Bugs: ProtocolBugs{
7438 SendWrongMessageType: typeClientHello,
7439 },
7440 },
7441 shouldFail: true,
7442 expectedError: ":UNEXPECTED_MESSAGE:",
7443 expectedLocalError: "remote error: unexpected message",
7444 })
7445
7446 if protocol == dtls {
7447 testCases = append(testCases, testCase{
7448 protocol: protocol,
7449 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7450 config: Config{
7451 MaxVersion: VersionTLS12,
7452 Bugs: ProtocolBugs{
7453 SendWrongMessageType: typeHelloVerifyRequest,
7454 },
7455 },
7456 shouldFail: true,
7457 expectedError: ":UNEXPECTED_MESSAGE:",
7458 expectedLocalError: "remote error: unexpected message",
7459 })
7460 }
7461
7462 testCases = append(testCases, testCase{
7463 protocol: protocol,
7464 name: "WrongMessageType-ServerHello" + suffix,
7465 config: Config{
7466 MaxVersion: VersionTLS12,
7467 Bugs: ProtocolBugs{
7468 SendWrongMessageType: typeServerHello,
7469 },
7470 },
7471 shouldFail: true,
7472 expectedError: ":UNEXPECTED_MESSAGE:",
7473 expectedLocalError: "remote error: unexpected message",
7474 })
7475
7476 testCases = append(testCases, testCase{
7477 protocol: protocol,
7478 name: "WrongMessageType-ServerCertificate" + suffix,
7479 config: Config{
7480 MaxVersion: VersionTLS12,
7481 Bugs: ProtocolBugs{
7482 SendWrongMessageType: typeCertificate,
7483 },
7484 },
7485 shouldFail: true,
7486 expectedError: ":UNEXPECTED_MESSAGE:",
7487 expectedLocalError: "remote error: unexpected message",
7488 })
7489
7490 testCases = append(testCases, testCase{
7491 protocol: protocol,
7492 name: "WrongMessageType-CertificateStatus" + suffix,
7493 config: Config{
7494 MaxVersion: VersionTLS12,
7495 Bugs: ProtocolBugs{
7496 SendWrongMessageType: typeCertificateStatus,
7497 },
7498 },
7499 flags: []string{"-enable-ocsp-stapling"},
7500 shouldFail: true,
7501 expectedError: ":UNEXPECTED_MESSAGE:",
7502 expectedLocalError: "remote error: unexpected message",
7503 })
7504
7505 testCases = append(testCases, testCase{
7506 protocol: protocol,
7507 name: "WrongMessageType-ServerKeyExchange" + suffix,
7508 config: Config{
7509 MaxVersion: VersionTLS12,
7510 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7511 Bugs: ProtocolBugs{
7512 SendWrongMessageType: typeServerKeyExchange,
7513 },
7514 },
7515 shouldFail: true,
7516 expectedError: ":UNEXPECTED_MESSAGE:",
7517 expectedLocalError: "remote error: unexpected message",
7518 })
7519
7520 testCases = append(testCases, testCase{
7521 protocol: protocol,
7522 name: "WrongMessageType-CertificateRequest" + suffix,
7523 config: Config{
7524 MaxVersion: VersionTLS12,
7525 ClientAuth: RequireAnyClientCert,
7526 Bugs: ProtocolBugs{
7527 SendWrongMessageType: typeCertificateRequest,
7528 },
7529 },
7530 shouldFail: true,
7531 expectedError: ":UNEXPECTED_MESSAGE:",
7532 expectedLocalError: "remote error: unexpected message",
7533 })
7534
7535 testCases = append(testCases, testCase{
7536 protocol: protocol,
7537 name: "WrongMessageType-ServerHelloDone" + suffix,
7538 config: Config{
7539 MaxVersion: VersionTLS12,
7540 Bugs: ProtocolBugs{
7541 SendWrongMessageType: typeServerHelloDone,
7542 },
7543 },
7544 shouldFail: true,
7545 expectedError: ":UNEXPECTED_MESSAGE:",
7546 expectedLocalError: "remote error: unexpected message",
7547 })
7548
7549 testCases = append(testCases, testCase{
7550 testType: serverTest,
7551 protocol: protocol,
7552 name: "WrongMessageType-ClientCertificate" + suffix,
7553 config: Config{
7554 Certificates: []Certificate{rsaCertificate},
7555 MaxVersion: VersionTLS12,
7556 Bugs: ProtocolBugs{
7557 SendWrongMessageType: typeCertificate,
7558 },
7559 },
7560 flags: []string{"-require-any-client-certificate"},
7561 shouldFail: true,
7562 expectedError: ":UNEXPECTED_MESSAGE:",
7563 expectedLocalError: "remote error: unexpected message",
7564 })
7565
7566 testCases = append(testCases, testCase{
7567 testType: serverTest,
7568 protocol: protocol,
7569 name: "WrongMessageType-CertificateVerify" + suffix,
7570 config: Config{
7571 Certificates: []Certificate{rsaCertificate},
7572 MaxVersion: VersionTLS12,
7573 Bugs: ProtocolBugs{
7574 SendWrongMessageType: typeCertificateVerify,
7575 },
7576 },
7577 flags: []string{"-require-any-client-certificate"},
7578 shouldFail: true,
7579 expectedError: ":UNEXPECTED_MESSAGE:",
7580 expectedLocalError: "remote error: unexpected message",
7581 })
7582
7583 testCases = append(testCases, testCase{
7584 testType: serverTest,
7585 protocol: protocol,
7586 name: "WrongMessageType-ClientKeyExchange" + suffix,
7587 config: Config{
7588 MaxVersion: VersionTLS12,
7589 Bugs: ProtocolBugs{
7590 SendWrongMessageType: typeClientKeyExchange,
7591 },
7592 },
7593 shouldFail: true,
7594 expectedError: ":UNEXPECTED_MESSAGE:",
7595 expectedLocalError: "remote error: unexpected message",
7596 })
7597
7598 if protocol != dtls {
7599 testCases = append(testCases, testCase{
7600 testType: serverTest,
7601 protocol: protocol,
7602 name: "WrongMessageType-NextProtocol" + suffix,
7603 config: Config{
7604 MaxVersion: VersionTLS12,
7605 NextProtos: []string{"bar"},
7606 Bugs: ProtocolBugs{
7607 SendWrongMessageType: typeNextProtocol,
7608 },
7609 },
7610 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7611 shouldFail: true,
7612 expectedError: ":UNEXPECTED_MESSAGE:",
7613 expectedLocalError: "remote error: unexpected message",
7614 })
7615
7616 testCases = append(testCases, testCase{
7617 testType: serverTest,
7618 protocol: protocol,
7619 name: "WrongMessageType-ChannelID" + suffix,
7620 config: Config{
7621 MaxVersion: VersionTLS12,
7622 ChannelID: channelIDKey,
7623 Bugs: ProtocolBugs{
7624 SendWrongMessageType: typeChannelID,
7625 },
7626 },
7627 flags: []string{
7628 "-expect-channel-id",
7629 base64.StdEncoding.EncodeToString(channelIDBytes),
7630 },
7631 shouldFail: true,
7632 expectedError: ":UNEXPECTED_MESSAGE:",
7633 expectedLocalError: "remote error: unexpected message",
7634 })
7635 }
7636
7637 testCases = append(testCases, testCase{
7638 testType: serverTest,
7639 protocol: protocol,
7640 name: "WrongMessageType-ClientFinished" + suffix,
7641 config: Config{
7642 MaxVersion: VersionTLS12,
7643 Bugs: ProtocolBugs{
7644 SendWrongMessageType: typeFinished,
7645 },
7646 },
7647 shouldFail: true,
7648 expectedError: ":UNEXPECTED_MESSAGE:",
7649 expectedLocalError: "remote error: unexpected message",
7650 })
7651
7652 testCases = append(testCases, testCase{
7653 protocol: protocol,
7654 name: "WrongMessageType-NewSessionTicket" + suffix,
7655 config: Config{
7656 MaxVersion: VersionTLS12,
7657 Bugs: ProtocolBugs{
7658 SendWrongMessageType: typeNewSessionTicket,
7659 },
7660 },
7661 shouldFail: true,
7662 expectedError: ":UNEXPECTED_MESSAGE:",
7663 expectedLocalError: "remote error: unexpected message",
7664 })
7665
7666 testCases = append(testCases, testCase{
7667 protocol: protocol,
7668 name: "WrongMessageType-ServerFinished" + suffix,
7669 config: Config{
7670 MaxVersion: VersionTLS12,
7671 Bugs: ProtocolBugs{
7672 SendWrongMessageType: typeFinished,
7673 },
7674 },
7675 shouldFail: true,
7676 expectedError: ":UNEXPECTED_MESSAGE:",
7677 expectedLocalError: "remote error: unexpected message",
7678 })
7679
7680 }
7681}
7682
Steven Valdez143e8b32016-07-11 13:19:03 -04007683func addTLS13WrongMessageTypeTests() {
7684 testCases = append(testCases, testCase{
7685 testType: serverTest,
7686 name: "WrongMessageType-TLS13-ClientHello",
7687 config: Config{
7688 MaxVersion: VersionTLS13,
7689 Bugs: ProtocolBugs{
7690 SendWrongMessageType: typeClientHello,
7691 },
7692 },
7693 shouldFail: true,
7694 expectedError: ":UNEXPECTED_MESSAGE:",
7695 expectedLocalError: "remote error: unexpected message",
7696 })
7697
7698 testCases = append(testCases, testCase{
7699 name: "WrongMessageType-TLS13-ServerHello",
7700 config: Config{
7701 MaxVersion: VersionTLS13,
7702 Bugs: ProtocolBugs{
7703 SendWrongMessageType: typeServerHello,
7704 },
7705 },
7706 shouldFail: true,
7707 expectedError: ":UNEXPECTED_MESSAGE:",
7708 // The alert comes in with the wrong encryption.
7709 expectedLocalError: "local error: bad record MAC",
7710 })
7711
7712 testCases = append(testCases, testCase{
7713 name: "WrongMessageType-TLS13-EncryptedExtensions",
7714 config: Config{
7715 MaxVersion: VersionTLS13,
7716 Bugs: ProtocolBugs{
7717 SendWrongMessageType: typeEncryptedExtensions,
7718 },
7719 },
7720 shouldFail: true,
7721 expectedError: ":UNEXPECTED_MESSAGE:",
7722 expectedLocalError: "remote error: unexpected message",
7723 })
7724
7725 testCases = append(testCases, testCase{
7726 name: "WrongMessageType-TLS13-CertificateRequest",
7727 config: Config{
7728 MaxVersion: VersionTLS13,
7729 ClientAuth: RequireAnyClientCert,
7730 Bugs: ProtocolBugs{
7731 SendWrongMessageType: typeCertificateRequest,
7732 },
7733 },
7734 shouldFail: true,
7735 expectedError: ":UNEXPECTED_MESSAGE:",
7736 expectedLocalError: "remote error: unexpected message",
7737 })
7738
7739 testCases = append(testCases, testCase{
7740 name: "WrongMessageType-TLS13-ServerCertificate",
7741 config: Config{
7742 MaxVersion: VersionTLS13,
7743 Bugs: ProtocolBugs{
7744 SendWrongMessageType: typeCertificate,
7745 },
7746 },
7747 shouldFail: true,
7748 expectedError: ":UNEXPECTED_MESSAGE:",
7749 expectedLocalError: "remote error: unexpected message",
7750 })
7751
7752 testCases = append(testCases, testCase{
7753 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7754 config: Config{
7755 MaxVersion: VersionTLS13,
7756 Bugs: ProtocolBugs{
7757 SendWrongMessageType: typeCertificateVerify,
7758 },
7759 },
7760 shouldFail: true,
7761 expectedError: ":UNEXPECTED_MESSAGE:",
7762 expectedLocalError: "remote error: unexpected message",
7763 })
7764
7765 testCases = append(testCases, testCase{
7766 name: "WrongMessageType-TLS13-ServerFinished",
7767 config: Config{
7768 MaxVersion: VersionTLS13,
7769 Bugs: ProtocolBugs{
7770 SendWrongMessageType: typeFinished,
7771 },
7772 },
7773 shouldFail: true,
7774 expectedError: ":UNEXPECTED_MESSAGE:",
7775 expectedLocalError: "remote error: unexpected message",
7776 })
7777
7778 testCases = append(testCases, testCase{
7779 testType: serverTest,
7780 name: "WrongMessageType-TLS13-ClientCertificate",
7781 config: Config{
7782 Certificates: []Certificate{rsaCertificate},
7783 MaxVersion: VersionTLS13,
7784 Bugs: ProtocolBugs{
7785 SendWrongMessageType: typeCertificate,
7786 },
7787 },
7788 flags: []string{"-require-any-client-certificate"},
7789 shouldFail: true,
7790 expectedError: ":UNEXPECTED_MESSAGE:",
7791 expectedLocalError: "remote error: unexpected message",
7792 })
7793
7794 testCases = append(testCases, testCase{
7795 testType: serverTest,
7796 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7797 config: Config{
7798 Certificates: []Certificate{rsaCertificate},
7799 MaxVersion: VersionTLS13,
7800 Bugs: ProtocolBugs{
7801 SendWrongMessageType: typeCertificateVerify,
7802 },
7803 },
7804 flags: []string{"-require-any-client-certificate"},
7805 shouldFail: true,
7806 expectedError: ":UNEXPECTED_MESSAGE:",
7807 expectedLocalError: "remote error: unexpected message",
7808 })
7809
7810 testCases = append(testCases, testCase{
7811 testType: serverTest,
7812 name: "WrongMessageType-TLS13-ClientFinished",
7813 config: Config{
7814 MaxVersion: VersionTLS13,
7815 Bugs: ProtocolBugs{
7816 SendWrongMessageType: typeFinished,
7817 },
7818 },
7819 shouldFail: true,
7820 expectedError: ":UNEXPECTED_MESSAGE:",
7821 expectedLocalError: "remote error: unexpected message",
7822 })
7823}
7824
7825func addTLS13HandshakeTests() {
7826 testCases = append(testCases, testCase{
7827 testType: clientTest,
7828 name: "MissingKeyShare-Client",
7829 config: Config{
7830 MaxVersion: VersionTLS13,
7831 Bugs: ProtocolBugs{
7832 MissingKeyShare: true,
7833 },
7834 },
7835 shouldFail: true,
7836 expectedError: ":MISSING_KEY_SHARE:",
7837 })
7838
7839 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007840 testType: serverTest,
7841 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007842 config: Config{
7843 MaxVersion: VersionTLS13,
7844 Bugs: ProtocolBugs{
7845 MissingKeyShare: true,
7846 },
7847 },
7848 shouldFail: true,
7849 expectedError: ":MISSING_KEY_SHARE:",
7850 })
7851
7852 testCases = append(testCases, testCase{
7853 testType: clientTest,
7854 name: "ClientHelloMissingKeyShare",
7855 config: Config{
7856 MaxVersion: VersionTLS13,
7857 Bugs: ProtocolBugs{
7858 MissingKeyShare: true,
7859 },
7860 },
7861 shouldFail: true,
7862 expectedError: ":MISSING_KEY_SHARE:",
7863 })
7864
7865 testCases = append(testCases, testCase{
7866 testType: clientTest,
7867 name: "MissingKeyShare",
7868 config: Config{
7869 MaxVersion: VersionTLS13,
7870 Bugs: ProtocolBugs{
7871 MissingKeyShare: true,
7872 },
7873 },
7874 shouldFail: true,
7875 expectedError: ":MISSING_KEY_SHARE:",
7876 })
7877
7878 testCases = append(testCases, testCase{
7879 testType: serverTest,
7880 name: "DuplicateKeyShares",
7881 config: Config{
7882 MaxVersion: VersionTLS13,
7883 Bugs: ProtocolBugs{
7884 DuplicateKeyShares: true,
7885 },
7886 },
7887 })
7888
7889 testCases = append(testCases, testCase{
7890 testType: clientTest,
7891 name: "EmptyEncryptedExtensions",
7892 config: Config{
7893 MaxVersion: VersionTLS13,
7894 Bugs: ProtocolBugs{
7895 EmptyEncryptedExtensions: true,
7896 },
7897 },
7898 shouldFail: true,
7899 expectedLocalError: "remote error: error decoding message",
7900 })
7901
7902 testCases = append(testCases, testCase{
7903 testType: clientTest,
7904 name: "EncryptedExtensionsWithKeyShare",
7905 config: Config{
7906 MaxVersion: VersionTLS13,
7907 Bugs: ProtocolBugs{
7908 EncryptedExtensionsWithKeyShare: true,
7909 },
7910 },
7911 shouldFail: true,
7912 expectedLocalError: "remote error: unsupported extension",
7913 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007914
7915 testCases = append(testCases, testCase{
7916 testType: serverTest,
7917 name: "SendHelloRetryRequest",
7918 config: Config{
7919 MaxVersion: VersionTLS13,
7920 // Require a HelloRetryRequest for every curve.
7921 DefaultCurves: []CurveID{},
7922 },
7923 expectedCurveID: CurveX25519,
7924 })
7925
7926 testCases = append(testCases, testCase{
7927 testType: serverTest,
7928 name: "SendHelloRetryRequest-2",
7929 config: Config{
7930 MaxVersion: VersionTLS13,
7931 DefaultCurves: []CurveID{CurveP384},
7932 },
7933 // Although the ClientHello did not predict our preferred curve,
7934 // we always select it whether it is predicted or not.
7935 expectedCurveID: CurveX25519,
7936 })
7937
7938 testCases = append(testCases, testCase{
7939 name: "UnknownCurve-HelloRetryRequest",
7940 config: Config{
7941 MaxVersion: VersionTLS13,
7942 // P-384 requires HelloRetryRequest in BoringSSL.
7943 CurvePreferences: []CurveID{CurveP384},
7944 Bugs: ProtocolBugs{
7945 SendHelloRetryRequestCurve: bogusCurve,
7946 },
7947 },
7948 shouldFail: true,
7949 expectedError: ":WRONG_CURVE:",
7950 })
7951
7952 testCases = append(testCases, testCase{
7953 name: "DisabledCurve-HelloRetryRequest",
7954 config: Config{
7955 MaxVersion: VersionTLS13,
7956 CurvePreferences: []CurveID{CurveP256},
7957 Bugs: ProtocolBugs{
7958 IgnorePeerCurvePreferences: true,
7959 },
7960 },
7961 flags: []string{"-p384-only"},
7962 shouldFail: true,
7963 expectedError: ":WRONG_CURVE:",
7964 })
7965
7966 testCases = append(testCases, testCase{
7967 name: "UnnecessaryHelloRetryRequest",
7968 config: Config{
7969 MaxVersion: VersionTLS13,
7970 Bugs: ProtocolBugs{
7971 UnnecessaryHelloRetryRequest: true,
7972 },
7973 },
7974 shouldFail: true,
7975 expectedError: ":WRONG_CURVE:",
7976 })
7977
7978 testCases = append(testCases, testCase{
7979 name: "SecondHelloRetryRequest",
7980 config: Config{
7981 MaxVersion: VersionTLS13,
7982 // P-384 requires HelloRetryRequest in BoringSSL.
7983 CurvePreferences: []CurveID{CurveP384},
7984 Bugs: ProtocolBugs{
7985 SecondHelloRetryRequest: true,
7986 },
7987 },
7988 shouldFail: true,
7989 expectedError: ":UNEXPECTED_MESSAGE:",
7990 })
7991
7992 testCases = append(testCases, testCase{
7993 testType: serverTest,
7994 name: "SecondClientHelloMissingKeyShare",
7995 config: Config{
7996 MaxVersion: VersionTLS13,
7997 DefaultCurves: []CurveID{},
7998 Bugs: ProtocolBugs{
7999 SecondClientHelloMissingKeyShare: true,
8000 },
8001 },
8002 shouldFail: true,
8003 expectedError: ":MISSING_KEY_SHARE:",
8004 })
8005
8006 testCases = append(testCases, testCase{
8007 testType: serverTest,
8008 name: "SecondClientHelloWrongCurve",
8009 config: Config{
8010 MaxVersion: VersionTLS13,
8011 DefaultCurves: []CurveID{},
8012 Bugs: ProtocolBugs{
8013 MisinterpretHelloRetryRequestCurve: CurveP521,
8014 },
8015 },
8016 shouldFail: true,
8017 expectedError: ":WRONG_CURVE:",
8018 })
8019
8020 testCases = append(testCases, testCase{
8021 name: "HelloRetryRequestVersionMismatch",
8022 config: Config{
8023 MaxVersion: VersionTLS13,
8024 // P-384 requires HelloRetryRequest in BoringSSL.
8025 CurvePreferences: []CurveID{CurveP384},
8026 Bugs: ProtocolBugs{
8027 SendServerHelloVersion: 0x0305,
8028 },
8029 },
8030 shouldFail: true,
8031 expectedError: ":WRONG_VERSION_NUMBER:",
8032 })
8033
8034 testCases = append(testCases, testCase{
8035 name: "HelloRetryRequestCurveMismatch",
8036 config: Config{
8037 MaxVersion: VersionTLS13,
8038 // P-384 requires HelloRetryRequest in BoringSSL.
8039 CurvePreferences: []CurveID{CurveP384},
8040 Bugs: ProtocolBugs{
8041 // Send P-384 (correct) in the HelloRetryRequest.
8042 SendHelloRetryRequestCurve: CurveP384,
8043 // But send P-256 in the ServerHello.
8044 SendCurve: CurveP256,
8045 },
8046 },
8047 shouldFail: true,
8048 expectedError: ":WRONG_CURVE:",
8049 })
8050
8051 // Test the server selecting a curve that requires a HelloRetryRequest
8052 // without sending it.
8053 testCases = append(testCases, testCase{
8054 name: "SkipHelloRetryRequest",
8055 config: Config{
8056 MaxVersion: VersionTLS13,
8057 // P-384 requires HelloRetryRequest in BoringSSL.
8058 CurvePreferences: []CurveID{CurveP384},
8059 Bugs: ProtocolBugs{
8060 SkipHelloRetryRequest: true,
8061 },
8062 },
8063 shouldFail: true,
8064 expectedError: ":WRONG_CURVE:",
8065 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008066
8067 testCases = append(testCases, testCase{
8068 name: "TLS13-RequestContextInHandshake",
8069 config: Config{
8070 MaxVersion: VersionTLS13,
8071 MinVersion: VersionTLS13,
8072 ClientAuth: RequireAnyClientCert,
8073 Bugs: ProtocolBugs{
8074 SendRequestContext: []byte("request context"),
8075 },
8076 },
8077 flags: []string{
8078 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8079 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8080 },
8081 shouldFail: true,
8082 expectedError: ":DECODE_ERROR:",
8083 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008084}
8085
Adam Langley7c803a62015-06-15 15:35:05 -07008086func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008087 defer wg.Done()
8088
8089 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008090 var err error
8091
8092 if *mallocTest < 0 {
8093 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008094 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008095 } else {
8096 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8097 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008098 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008099 if err != nil {
8100 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8101 }
8102 break
8103 }
8104 }
8105 }
Adam Langley95c29f32014-06-20 12:00:00 -07008106 statusChan <- statusMsg{test: test, err: err}
8107 }
8108}
8109
8110type statusMsg struct {
8111 test *testCase
8112 started bool
8113 err error
8114}
8115
David Benjamin5f237bc2015-02-11 17:14:15 -05008116func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008117 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008118
David Benjamin5f237bc2015-02-11 17:14:15 -05008119 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008120 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008121 if !*pipe {
8122 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008123 var erase string
8124 for i := 0; i < lineLen; i++ {
8125 erase += "\b \b"
8126 }
8127 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008128 }
8129
Adam Langley95c29f32014-06-20 12:00:00 -07008130 if msg.started {
8131 started++
8132 } else {
8133 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008134
8135 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008136 if msg.err == errUnimplemented {
8137 if *pipe {
8138 // Print each test instead of a status line.
8139 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8140 }
8141 unimplemented++
8142 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8143 } else {
8144 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8145 failed++
8146 testOutput.addResult(msg.test.name, "FAIL")
8147 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008148 } else {
8149 if *pipe {
8150 // Print each test instead of a status line.
8151 fmt.Printf("PASSED (%s)\n", msg.test.name)
8152 }
8153 testOutput.addResult(msg.test.name, "PASS")
8154 }
Adam Langley95c29f32014-06-20 12:00:00 -07008155 }
8156
David Benjamin5f237bc2015-02-11 17:14:15 -05008157 if !*pipe {
8158 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008159 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008160 lineLen = len(line)
8161 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008162 }
Adam Langley95c29f32014-06-20 12:00:00 -07008163 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008164
8165 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008166}
8167
8168func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008169 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008170 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008171 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008172
Adam Langley7c803a62015-06-15 15:35:05 -07008173 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008174 addCipherSuiteTests()
8175 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008176 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008177 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008178 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008179 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008180 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008181 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008182 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008183 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008184 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008185 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008186 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008187 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008188 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008189 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008190 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008191 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008192 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008193 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008194 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008195 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008196 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008197 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008198 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008199 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008200 addTLS13WrongMessageTypeTests()
8201 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008202
8203 var wg sync.WaitGroup
8204
Adam Langley7c803a62015-06-15 15:35:05 -07008205 statusChan := make(chan statusMsg, *numWorkers)
8206 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008207 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008208
EKRf71d7ed2016-08-06 13:25:12 -07008209 if len(*shimConfigFile) != 0 {
8210 encoded, err := ioutil.ReadFile(*shimConfigFile)
8211 if err != nil {
8212 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8213 os.Exit(1)
8214 }
8215
8216 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8217 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8218 os.Exit(1)
8219 }
8220 }
8221
David Benjamin025b3d32014-07-01 19:53:04 -04008222 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008223
Adam Langley7c803a62015-06-15 15:35:05 -07008224 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008225 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008226 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008227 }
8228
David Benjamin270f0a72016-03-17 14:41:36 -04008229 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008230 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008231 matched := true
8232 if len(*testToRun) != 0 {
8233 var err error
8234 matched, err = filepath.Match(*testToRun, testCases[i].name)
8235 if err != nil {
8236 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8237 os.Exit(1)
8238 }
8239 }
8240
EKRf71d7ed2016-08-06 13:25:12 -07008241 if !*includeDisabled {
8242 for pattern := range shimConfig.DisabledTests {
8243 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8244 if err != nil {
8245 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8246 os.Exit(1)
8247 }
8248
8249 if isDisabled {
8250 matched = false
8251 break
8252 }
8253 }
8254 }
8255
David Benjamin17e12922016-07-28 18:04:43 -04008256 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008257 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008258 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008259 }
8260 }
David Benjamin17e12922016-07-28 18:04:43 -04008261
David Benjamin270f0a72016-03-17 14:41:36 -04008262 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008263 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008264 os.Exit(1)
8265 }
Adam Langley95c29f32014-06-20 12:00:00 -07008266
8267 close(testChan)
8268 wg.Wait()
8269 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008270 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008271
8272 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008273
8274 if *jsonOutput != "" {
8275 if err := testOutput.writeTo(*jsonOutput); err != nil {
8276 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8277 }
8278 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008279
EKR842ae6c2016-07-27 09:22:05 +02008280 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8281 os.Exit(1)
8282 }
8283
8284 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008285 os.Exit(1)
8286 }
Adam Langley95c29f32014-06-20 12:00:00 -07008287}