blob: 78e4191336d32005f101cf85bc5692ad69b8f42a [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 }
5515 // RSA-PSS does not exist in TLS 1.2.
5516 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5517 shouldFail = true
5518 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005519 // RSA-PKCS1 does not exist in TLS 1.3.
5520 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5521 shouldFail = true
5522 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005523
5524 var signError, verifyError string
5525 if shouldFail {
5526 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5527 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005528 }
David Benjamin000800a2014-11-14 01:43:59 -05005529
David Benjamin1fb125c2016-07-08 18:52:12 -07005530 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005531
David Benjamin7a41d372016-07-09 11:21:54 -07005532 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005533 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005534 config: Config{
5535 MaxVersion: ver.version,
5536 ClientAuth: RequireAnyClientCert,
5537 VerifySignatureAlgorithms: []signatureAlgorithm{
5538 fakeSigAlg1,
5539 alg.id,
5540 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005541 },
David Benjamin7a41d372016-07-09 11:21:54 -07005542 },
5543 flags: []string{
5544 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5545 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5546 "-enable-all-curves",
5547 },
5548 shouldFail: shouldFail,
5549 expectedError: signError,
5550 expectedPeerSignatureAlgorithm: alg.id,
5551 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005552
David Benjamin7a41d372016-07-09 11:21:54 -07005553 testCases = append(testCases, testCase{
5554 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005555 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005556 config: Config{
5557 MaxVersion: ver.version,
5558 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5559 SignSignatureAlgorithms: []signatureAlgorithm{
5560 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005561 },
David Benjamin7a41d372016-07-09 11:21:54 -07005562 Bugs: ProtocolBugs{
5563 SkipECDSACurveCheck: shouldFail,
5564 IgnoreSignatureVersionChecks: shouldFail,
5565 // The client won't advertise 1.3-only algorithms after
5566 // version negotiation.
5567 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005568 },
David Benjamin7a41d372016-07-09 11:21:54 -07005569 },
5570 flags: []string{
5571 "-require-any-client-certificate",
5572 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5573 "-enable-all-curves",
5574 },
5575 shouldFail: shouldFail,
5576 expectedError: verifyError,
5577 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005578
5579 testCases = append(testCases, testCase{
5580 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005581 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005582 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005583 MaxVersion: ver.version,
5584 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005585 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005586 fakeSigAlg1,
5587 alg.id,
5588 fakeSigAlg2,
5589 },
5590 },
5591 flags: []string{
5592 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5593 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5594 "-enable-all-curves",
5595 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005596 shouldFail: shouldFail,
5597 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005598 expectedPeerSignatureAlgorithm: alg.id,
5599 })
5600
5601 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005602 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005603 config: Config{
5604 MaxVersion: ver.version,
5605 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005606 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005607 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005608 alg.id,
5609 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005610 Bugs: ProtocolBugs{
5611 SkipECDSACurveCheck: shouldFail,
5612 IgnoreSignatureVersionChecks: shouldFail,
5613 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005614 },
5615 flags: []string{
5616 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5617 "-enable-all-curves",
5618 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005619 shouldFail: shouldFail,
5620 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005621 })
David Benjamin5208fd42016-07-13 21:43:25 -04005622
5623 if !shouldFail {
5624 testCases = append(testCases, testCase{
5625 testType: serverTest,
5626 name: "ClientAuth-InvalidSignature" + suffix,
5627 config: Config{
5628 MaxVersion: ver.version,
5629 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5630 SignSignatureAlgorithms: []signatureAlgorithm{
5631 alg.id,
5632 },
5633 Bugs: ProtocolBugs{
5634 InvalidSignature: true,
5635 },
5636 },
5637 flags: []string{
5638 "-require-any-client-certificate",
5639 "-enable-all-curves",
5640 },
5641 shouldFail: true,
5642 expectedError: ":BAD_SIGNATURE:",
5643 })
5644
5645 testCases = append(testCases, testCase{
5646 name: "ServerAuth-InvalidSignature" + suffix,
5647 config: Config{
5648 MaxVersion: ver.version,
5649 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5650 CipherSuites: signingCiphers,
5651 SignSignatureAlgorithms: []signatureAlgorithm{
5652 alg.id,
5653 },
5654 Bugs: ProtocolBugs{
5655 InvalidSignature: true,
5656 },
5657 },
5658 flags: []string{"-enable-all-curves"},
5659 shouldFail: true,
5660 expectedError: ":BAD_SIGNATURE:",
5661 })
5662 }
David Benjaminca3d5452016-07-14 12:51:01 -04005663
5664 if ver.version >= VersionTLS12 && !shouldFail {
5665 testCases = append(testCases, testCase{
5666 name: "ClientAuth-Sign-Negotiate" + suffix,
5667 config: Config{
5668 MaxVersion: ver.version,
5669 ClientAuth: RequireAnyClientCert,
5670 VerifySignatureAlgorithms: allAlgorithms,
5671 },
5672 flags: []string{
5673 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5674 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5675 "-enable-all-curves",
5676 "-signing-prefs", strconv.Itoa(int(alg.id)),
5677 },
5678 expectedPeerSignatureAlgorithm: alg.id,
5679 })
5680
5681 testCases = append(testCases, testCase{
5682 testType: serverTest,
5683 name: "ServerAuth-Sign-Negotiate" + suffix,
5684 config: Config{
5685 MaxVersion: ver.version,
5686 CipherSuites: signingCiphers,
5687 VerifySignatureAlgorithms: allAlgorithms,
5688 },
5689 flags: []string{
5690 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5691 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5692 "-enable-all-curves",
5693 "-signing-prefs", strconv.Itoa(int(alg.id)),
5694 },
5695 expectedPeerSignatureAlgorithm: alg.id,
5696 })
5697 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005698 }
David Benjamin000800a2014-11-14 01:43:59 -05005699 }
5700
Nick Harper60edffd2016-06-21 15:19:24 -07005701 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005702 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005703 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005704 config: Config{
5705 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005706 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005707 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005708 signatureECDSAWithP521AndSHA512,
5709 signatureRSAPKCS1WithSHA384,
5710 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005711 },
5712 },
5713 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005714 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5715 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005716 },
Nick Harper60edffd2016-06-21 15:19:24 -07005717 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005718 })
5719
5720 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005721 name: "ClientAuth-SignatureType-TLS13",
5722 config: Config{
5723 ClientAuth: RequireAnyClientCert,
5724 MaxVersion: VersionTLS13,
5725 VerifySignatureAlgorithms: []signatureAlgorithm{
5726 signatureECDSAWithP521AndSHA512,
5727 signatureRSAPKCS1WithSHA384,
5728 signatureRSAPSSWithSHA384,
5729 signatureECDSAWithSHA1,
5730 },
5731 },
5732 flags: []string{
5733 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5734 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5735 },
5736 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5737 })
5738
5739 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005740 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005741 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005742 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005743 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005744 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005745 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005746 signatureECDSAWithP521AndSHA512,
5747 signatureRSAPKCS1WithSHA384,
5748 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005749 },
5750 },
Nick Harper60edffd2016-06-21 15:19:24 -07005751 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005752 })
5753
Steven Valdez143e8b32016-07-11 13:19:03 -04005754 testCases = append(testCases, testCase{
5755 testType: serverTest,
5756 name: "ServerAuth-SignatureType-TLS13",
5757 config: Config{
5758 MaxVersion: VersionTLS13,
5759 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5760 VerifySignatureAlgorithms: []signatureAlgorithm{
5761 signatureECDSAWithP521AndSHA512,
5762 signatureRSAPKCS1WithSHA384,
5763 signatureRSAPSSWithSHA384,
5764 signatureECDSAWithSHA1,
5765 },
5766 },
5767 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5768 })
5769
David Benjamina95e9f32016-07-08 16:28:04 -07005770 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005771 testCases = append(testCases, testCase{
5772 testType: serverTest,
5773 name: "Verify-ClientAuth-SignatureType",
5774 config: Config{
5775 MaxVersion: VersionTLS12,
5776 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005777 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005778 signatureRSAPKCS1WithSHA256,
5779 },
5780 Bugs: ProtocolBugs{
5781 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5782 },
5783 },
5784 flags: []string{
5785 "-require-any-client-certificate",
5786 },
5787 shouldFail: true,
5788 expectedError: ":WRONG_SIGNATURE_TYPE:",
5789 })
5790
5791 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005792 testType: serverTest,
5793 name: "Verify-ClientAuth-SignatureType-TLS13",
5794 config: Config{
5795 MaxVersion: VersionTLS13,
5796 Certificates: []Certificate{rsaCertificate},
5797 SignSignatureAlgorithms: []signatureAlgorithm{
5798 signatureRSAPSSWithSHA256,
5799 },
5800 Bugs: ProtocolBugs{
5801 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5802 },
5803 },
5804 flags: []string{
5805 "-require-any-client-certificate",
5806 },
5807 shouldFail: true,
5808 expectedError: ":WRONG_SIGNATURE_TYPE:",
5809 })
5810
5811 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005812 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005813 config: Config{
5814 MaxVersion: VersionTLS12,
5815 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005816 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005817 signatureRSAPKCS1WithSHA256,
5818 },
5819 Bugs: ProtocolBugs{
5820 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5821 },
5822 },
5823 shouldFail: true,
5824 expectedError: ":WRONG_SIGNATURE_TYPE:",
5825 })
5826
Steven Valdez143e8b32016-07-11 13:19:03 -04005827 testCases = append(testCases, testCase{
5828 name: "Verify-ServerAuth-SignatureType-TLS13",
5829 config: Config{
5830 MaxVersion: VersionTLS13,
5831 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5832 SignSignatureAlgorithms: []signatureAlgorithm{
5833 signatureRSAPSSWithSHA256,
5834 },
5835 Bugs: ProtocolBugs{
5836 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5837 },
5838 },
5839 shouldFail: true,
5840 expectedError: ":WRONG_SIGNATURE_TYPE:",
5841 })
5842
David Benjamin51dd7d62016-07-08 16:07:01 -07005843 // Test that, if the list is missing, the peer falls back to SHA-1 in
5844 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005845 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005846 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005847 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005848 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005849 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005850 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005851 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005852 },
5853 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005854 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005855 },
5856 },
5857 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005858 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5859 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005860 },
5861 })
5862
5863 testCases = append(testCases, testCase{
5864 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005865 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005866 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005867 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005868 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005869 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005870 },
5871 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005872 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005873 },
5874 },
David Benjaminee32bea2016-08-17 13:36:44 -04005875 flags: []string{
5876 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5877 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5878 },
5879 })
5880
5881 testCases = append(testCases, testCase{
5882 name: "ClientAuth-SHA1-Fallback-ECDSA",
5883 config: Config{
5884 MaxVersion: VersionTLS12,
5885 ClientAuth: RequireAnyClientCert,
5886 VerifySignatureAlgorithms: []signatureAlgorithm{
5887 signatureECDSAWithSHA1,
5888 },
5889 Bugs: ProtocolBugs{
5890 NoSignatureAlgorithms: true,
5891 },
5892 },
5893 flags: []string{
5894 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5895 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5896 },
5897 })
5898
5899 testCases = append(testCases, testCase{
5900 testType: serverTest,
5901 name: "ServerAuth-SHA1-Fallback-ECDSA",
5902 config: Config{
5903 MaxVersion: VersionTLS12,
5904 VerifySignatureAlgorithms: []signatureAlgorithm{
5905 signatureECDSAWithSHA1,
5906 },
5907 Bugs: ProtocolBugs{
5908 NoSignatureAlgorithms: true,
5909 },
5910 },
5911 flags: []string{
5912 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5913 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5914 },
David Benjamin000800a2014-11-14 01:43:59 -05005915 })
David Benjamin72dc7832015-03-16 17:49:43 -04005916
David Benjamin51dd7d62016-07-08 16:07:01 -07005917 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005918 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005919 config: Config{
5920 MaxVersion: VersionTLS13,
5921 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005922 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005923 signatureRSAPKCS1WithSHA1,
5924 },
5925 Bugs: ProtocolBugs{
5926 NoSignatureAlgorithms: true,
5927 },
5928 },
5929 flags: []string{
5930 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5931 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5932 },
David Benjamin48901652016-08-01 12:12:47 -04005933 shouldFail: true,
5934 // An empty CertificateRequest signature algorithm list is a
5935 // syntax error in TLS 1.3.
5936 expectedError: ":DECODE_ERROR:",
5937 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07005938 })
5939
5940 testCases = append(testCases, testCase{
5941 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005942 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005943 config: Config{
5944 MaxVersion: VersionTLS13,
5945 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005946 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005947 signatureRSAPKCS1WithSHA1,
5948 },
5949 Bugs: ProtocolBugs{
5950 NoSignatureAlgorithms: true,
5951 },
5952 },
5953 shouldFail: true,
5954 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5955 })
5956
David Benjaminb62d2872016-07-18 14:55:02 +02005957 // Test that hash preferences are enforced. BoringSSL does not implement
5958 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005959 testCases = append(testCases, testCase{
5960 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005961 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005962 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005963 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005964 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005965 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005966 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005967 },
5968 Bugs: ProtocolBugs{
5969 IgnorePeerSignatureAlgorithmPreferences: true,
5970 },
5971 },
5972 flags: []string{"-require-any-client-certificate"},
5973 shouldFail: true,
5974 expectedError: ":WRONG_SIGNATURE_TYPE:",
5975 })
5976
5977 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005978 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005979 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005980 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005981 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005982 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005983 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005984 },
5985 Bugs: ProtocolBugs{
5986 IgnorePeerSignatureAlgorithmPreferences: true,
5987 },
5988 },
5989 shouldFail: true,
5990 expectedError: ":WRONG_SIGNATURE_TYPE:",
5991 })
David Benjaminb62d2872016-07-18 14:55:02 +02005992 testCases = append(testCases, testCase{
5993 testType: serverTest,
5994 name: "ClientAuth-Enforced-TLS13",
5995 config: Config{
5996 MaxVersion: VersionTLS13,
5997 Certificates: []Certificate{rsaCertificate},
5998 SignSignatureAlgorithms: []signatureAlgorithm{
5999 signatureRSAPKCS1WithMD5,
6000 },
6001 Bugs: ProtocolBugs{
6002 IgnorePeerSignatureAlgorithmPreferences: true,
6003 IgnoreSignatureVersionChecks: true,
6004 },
6005 },
6006 flags: []string{"-require-any-client-certificate"},
6007 shouldFail: true,
6008 expectedError: ":WRONG_SIGNATURE_TYPE:",
6009 })
6010
6011 testCases = append(testCases, testCase{
6012 name: "ServerAuth-Enforced-TLS13",
6013 config: Config{
6014 MaxVersion: VersionTLS13,
6015 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6016 SignSignatureAlgorithms: []signatureAlgorithm{
6017 signatureRSAPKCS1WithMD5,
6018 },
6019 Bugs: ProtocolBugs{
6020 IgnorePeerSignatureAlgorithmPreferences: true,
6021 IgnoreSignatureVersionChecks: true,
6022 },
6023 },
6024 shouldFail: true,
6025 expectedError: ":WRONG_SIGNATURE_TYPE:",
6026 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006027
6028 // Test that the agreed upon digest respects the client preferences and
6029 // the server digests.
6030 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006031 name: "NoCommonAlgorithms-Digests",
6032 config: Config{
6033 MaxVersion: VersionTLS12,
6034 ClientAuth: RequireAnyClientCert,
6035 VerifySignatureAlgorithms: []signatureAlgorithm{
6036 signatureRSAPKCS1WithSHA512,
6037 signatureRSAPKCS1WithSHA1,
6038 },
6039 },
6040 flags: []string{
6041 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6042 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6043 "-digest-prefs", "SHA256",
6044 },
6045 shouldFail: true,
6046 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6047 })
6048 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006049 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006050 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006051 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006052 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006053 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006054 signatureRSAPKCS1WithSHA512,
6055 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006056 },
6057 },
6058 flags: []string{
6059 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6060 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006061 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006062 },
David Benjaminca3d5452016-07-14 12:51:01 -04006063 shouldFail: true,
6064 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6065 })
6066 testCases = append(testCases, testCase{
6067 name: "NoCommonAlgorithms-TLS13",
6068 config: Config{
6069 MaxVersion: VersionTLS13,
6070 ClientAuth: RequireAnyClientCert,
6071 VerifySignatureAlgorithms: []signatureAlgorithm{
6072 signatureRSAPSSWithSHA512,
6073 signatureRSAPSSWithSHA384,
6074 },
6075 },
6076 flags: []string{
6077 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6078 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6079 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6080 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006081 shouldFail: true,
6082 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006083 })
6084 testCases = append(testCases, testCase{
6085 name: "Agree-Digest-SHA256",
6086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006087 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006088 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006089 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006090 signatureRSAPKCS1WithSHA1,
6091 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006092 },
6093 },
6094 flags: []string{
6095 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6096 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006097 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006098 },
Nick Harper60edffd2016-06-21 15:19:24 -07006099 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006100 })
6101 testCases = append(testCases, testCase{
6102 name: "Agree-Digest-SHA1",
6103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006104 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006105 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006106 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006107 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006108 },
6109 },
6110 flags: []string{
6111 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6112 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006113 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006114 },
Nick Harper60edffd2016-06-21 15:19:24 -07006115 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006116 })
6117 testCases = append(testCases, testCase{
6118 name: "Agree-Digest-Default",
6119 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006120 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006121 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006122 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006123 signatureRSAPKCS1WithSHA256,
6124 signatureECDSAWithP256AndSHA256,
6125 signatureRSAPKCS1WithSHA1,
6126 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006127 },
6128 },
6129 flags: []string{
6130 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6131 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6132 },
Nick Harper60edffd2016-06-21 15:19:24 -07006133 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006134 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006135
David Benjaminca3d5452016-07-14 12:51:01 -04006136 // Test that the signing preference list may include extra algorithms
6137 // without negotiation problems.
6138 testCases = append(testCases, testCase{
6139 testType: serverTest,
6140 name: "FilterExtraAlgorithms",
6141 config: Config{
6142 MaxVersion: VersionTLS12,
6143 VerifySignatureAlgorithms: []signatureAlgorithm{
6144 signatureRSAPKCS1WithSHA256,
6145 },
6146 },
6147 flags: []string{
6148 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6149 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6150 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6151 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6152 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6153 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6154 },
6155 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6156 })
6157
David Benjamin4c3ddf72016-06-29 18:13:53 -04006158 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6159 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006160 testCases = append(testCases, testCase{
6161 name: "CheckLeafCurve",
6162 config: Config{
6163 MaxVersion: VersionTLS12,
6164 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006165 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006166 },
6167 flags: []string{"-p384-only"},
6168 shouldFail: true,
6169 expectedError: ":BAD_ECC_CERT:",
6170 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006171
6172 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6173 testCases = append(testCases, testCase{
6174 name: "CheckLeafCurve-TLS13",
6175 config: Config{
6176 MaxVersion: VersionTLS13,
6177 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6178 Certificates: []Certificate{ecdsaP256Certificate},
6179 },
6180 flags: []string{"-p384-only"},
6181 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006182
6183 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6184 testCases = append(testCases, testCase{
6185 name: "ECDSACurveMismatch-Verify-TLS12",
6186 config: Config{
6187 MaxVersion: VersionTLS12,
6188 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6189 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006190 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006191 signatureECDSAWithP384AndSHA384,
6192 },
6193 },
6194 })
6195
6196 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6197 testCases = append(testCases, testCase{
6198 name: "ECDSACurveMismatch-Verify-TLS13",
6199 config: Config{
6200 MaxVersion: VersionTLS13,
6201 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6202 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006203 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006204 signatureECDSAWithP384AndSHA384,
6205 },
6206 Bugs: ProtocolBugs{
6207 SkipECDSACurveCheck: true,
6208 },
6209 },
6210 shouldFail: true,
6211 expectedError: ":WRONG_SIGNATURE_TYPE:",
6212 })
6213
6214 // Signature algorithm selection in TLS 1.3 should take the curve into
6215 // account.
6216 testCases = append(testCases, testCase{
6217 testType: serverTest,
6218 name: "ECDSACurveMismatch-Sign-TLS13",
6219 config: Config{
6220 MaxVersion: VersionTLS13,
6221 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006222 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006223 signatureECDSAWithP384AndSHA384,
6224 signatureECDSAWithP256AndSHA256,
6225 },
6226 },
6227 flags: []string{
6228 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6229 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6230 },
6231 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6232 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006233
6234 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6235 // server does not attempt to sign in that case.
6236 testCases = append(testCases, testCase{
6237 testType: serverTest,
6238 name: "RSA-PSS-Large",
6239 config: Config{
6240 MaxVersion: VersionTLS13,
6241 VerifySignatureAlgorithms: []signatureAlgorithm{
6242 signatureRSAPSSWithSHA512,
6243 },
6244 },
6245 flags: []string{
6246 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6247 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6248 },
6249 shouldFail: true,
6250 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6251 })
David Benjamin000800a2014-11-14 01:43:59 -05006252}
6253
David Benjamin83f90402015-01-27 01:09:43 -05006254// timeouts is the retransmit schedule for BoringSSL. It doubles and
6255// caps at 60 seconds. On the 13th timeout, it gives up.
6256var timeouts = []time.Duration{
6257 1 * time.Second,
6258 2 * time.Second,
6259 4 * time.Second,
6260 8 * time.Second,
6261 16 * time.Second,
6262 32 * time.Second,
6263 60 * time.Second,
6264 60 * time.Second,
6265 60 * time.Second,
6266 60 * time.Second,
6267 60 * time.Second,
6268 60 * time.Second,
6269 60 * time.Second,
6270}
6271
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006272// shortTimeouts is an alternate set of timeouts which would occur if the
6273// initial timeout duration was set to 250ms.
6274var shortTimeouts = []time.Duration{
6275 250 * time.Millisecond,
6276 500 * time.Millisecond,
6277 1 * time.Second,
6278 2 * time.Second,
6279 4 * time.Second,
6280 8 * time.Second,
6281 16 * time.Second,
6282 32 * time.Second,
6283 60 * time.Second,
6284 60 * time.Second,
6285 60 * time.Second,
6286 60 * time.Second,
6287 60 * time.Second,
6288}
6289
David Benjamin83f90402015-01-27 01:09:43 -05006290func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006291 // These tests work by coordinating some behavior on both the shim and
6292 // the runner.
6293 //
6294 // TimeoutSchedule configures the runner to send a series of timeout
6295 // opcodes to the shim (see packetAdaptor) immediately before reading
6296 // each peer handshake flight N. The timeout opcode both simulates a
6297 // timeout in the shim and acts as a synchronization point to help the
6298 // runner bracket each handshake flight.
6299 //
6300 // We assume the shim does not read from the channel eagerly. It must
6301 // first wait until it has sent flight N and is ready to receive
6302 // handshake flight N+1. At this point, it will process the timeout
6303 // opcode. It must then immediately respond with a timeout ACK and act
6304 // as if the shim was idle for the specified amount of time.
6305 //
6306 // The runner then drops all packets received before the ACK and
6307 // continues waiting for flight N. This ordering results in one attempt
6308 // at sending flight N to be dropped. For the test to complete, the
6309 // shim must send flight N again, testing that the shim implements DTLS
6310 // retransmit on a timeout.
6311
Steven Valdez143e8b32016-07-11 13:19:03 -04006312 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006313 // likely be more epochs to cross and the final message's retransmit may
6314 // be more complex.
6315
David Benjamin585d7a42016-06-02 14:58:00 -04006316 for _, async := range []bool{true, false} {
6317 var tests []testCase
6318
6319 // Test that this is indeed the timeout schedule. Stress all
6320 // four patterns of handshake.
6321 for i := 1; i < len(timeouts); i++ {
6322 number := strconv.Itoa(i)
6323 tests = append(tests, testCase{
6324 protocol: dtls,
6325 name: "DTLS-Retransmit-Client-" + number,
6326 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006327 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006328 Bugs: ProtocolBugs{
6329 TimeoutSchedule: timeouts[:i],
6330 },
6331 },
6332 resumeSession: true,
6333 })
6334 tests = append(tests, testCase{
6335 protocol: dtls,
6336 testType: serverTest,
6337 name: "DTLS-Retransmit-Server-" + number,
6338 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006339 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006340 Bugs: ProtocolBugs{
6341 TimeoutSchedule: timeouts[:i],
6342 },
6343 },
6344 resumeSession: true,
6345 })
6346 }
6347
6348 // Test that exceeding the timeout schedule hits a read
6349 // timeout.
6350 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006351 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006352 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006353 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006354 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006355 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006356 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006357 },
6358 },
6359 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006360 shouldFail: true,
6361 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006362 })
David Benjamin585d7a42016-06-02 14:58:00 -04006363
6364 if async {
6365 // Test that timeout handling has a fudge factor, due to API
6366 // problems.
6367 tests = append(tests, testCase{
6368 protocol: dtls,
6369 name: "DTLS-Retransmit-Fudge",
6370 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006371 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006372 Bugs: ProtocolBugs{
6373 TimeoutSchedule: []time.Duration{
6374 timeouts[0] - 10*time.Millisecond,
6375 },
6376 },
6377 },
6378 resumeSession: true,
6379 })
6380 }
6381
6382 // Test that the final Finished retransmitting isn't
6383 // duplicated if the peer badly fragments everything.
6384 tests = append(tests, testCase{
6385 testType: serverTest,
6386 protocol: dtls,
6387 name: "DTLS-Retransmit-Fragmented",
6388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006389 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006390 Bugs: ProtocolBugs{
6391 TimeoutSchedule: []time.Duration{timeouts[0]},
6392 MaxHandshakeRecordLength: 2,
6393 },
6394 },
6395 })
6396
6397 // Test the timeout schedule when a shorter initial timeout duration is set.
6398 tests = append(tests, testCase{
6399 protocol: dtls,
6400 name: "DTLS-Retransmit-Short-Client",
6401 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006402 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006403 Bugs: ProtocolBugs{
6404 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6405 },
6406 },
6407 resumeSession: true,
6408 flags: []string{"-initial-timeout-duration-ms", "250"},
6409 })
6410 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006411 protocol: dtls,
6412 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006413 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006415 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006416 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006417 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006418 },
6419 },
6420 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006421 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006422 })
David Benjamin585d7a42016-06-02 14:58:00 -04006423
6424 for _, test := range tests {
6425 if async {
6426 test.name += "-Async"
6427 test.flags = append(test.flags, "-async")
6428 }
6429
6430 testCases = append(testCases, test)
6431 }
David Benjamin83f90402015-01-27 01:09:43 -05006432 }
David Benjamin83f90402015-01-27 01:09:43 -05006433}
6434
David Benjaminc565ebb2015-04-03 04:06:36 -04006435func addExportKeyingMaterialTests() {
6436 for _, vers := range tlsVersions {
6437 if vers.version == VersionSSL30 {
6438 continue
6439 }
6440 testCases = append(testCases, testCase{
6441 name: "ExportKeyingMaterial-" + vers.name,
6442 config: Config{
6443 MaxVersion: vers.version,
6444 },
6445 exportKeyingMaterial: 1024,
6446 exportLabel: "label",
6447 exportContext: "context",
6448 useExportContext: true,
6449 })
6450 testCases = append(testCases, testCase{
6451 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6452 config: Config{
6453 MaxVersion: vers.version,
6454 },
6455 exportKeyingMaterial: 1024,
6456 })
6457 testCases = append(testCases, testCase{
6458 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6459 config: Config{
6460 MaxVersion: vers.version,
6461 },
6462 exportKeyingMaterial: 1024,
6463 useExportContext: true,
6464 })
6465 testCases = append(testCases, testCase{
6466 name: "ExportKeyingMaterial-Small-" + vers.name,
6467 config: Config{
6468 MaxVersion: vers.version,
6469 },
6470 exportKeyingMaterial: 1,
6471 exportLabel: "label",
6472 exportContext: "context",
6473 useExportContext: true,
6474 })
6475 }
6476 testCases = append(testCases, testCase{
6477 name: "ExportKeyingMaterial-SSL3",
6478 config: Config{
6479 MaxVersion: VersionSSL30,
6480 },
6481 exportKeyingMaterial: 1024,
6482 exportLabel: "label",
6483 exportContext: "context",
6484 useExportContext: true,
6485 shouldFail: true,
6486 expectedError: "failed to export keying material",
6487 })
6488}
6489
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006490func addTLSUniqueTests() {
6491 for _, isClient := range []bool{false, true} {
6492 for _, isResumption := range []bool{false, true} {
6493 for _, hasEMS := range []bool{false, true} {
6494 var suffix string
6495 if isResumption {
6496 suffix = "Resume-"
6497 } else {
6498 suffix = "Full-"
6499 }
6500
6501 if hasEMS {
6502 suffix += "EMS-"
6503 } else {
6504 suffix += "NoEMS-"
6505 }
6506
6507 if isClient {
6508 suffix += "Client"
6509 } else {
6510 suffix += "Server"
6511 }
6512
6513 test := testCase{
6514 name: "TLSUnique-" + suffix,
6515 testTLSUnique: true,
6516 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006517 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006518 Bugs: ProtocolBugs{
6519 NoExtendedMasterSecret: !hasEMS,
6520 },
6521 },
6522 }
6523
6524 if isResumption {
6525 test.resumeSession = true
6526 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006527 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006528 Bugs: ProtocolBugs{
6529 NoExtendedMasterSecret: !hasEMS,
6530 },
6531 }
6532 }
6533
6534 if isResumption && !hasEMS {
6535 test.shouldFail = true
6536 test.expectedError = "failed to get tls-unique"
6537 }
6538
6539 testCases = append(testCases, test)
6540 }
6541 }
6542 }
6543}
6544
Adam Langley09505632015-07-30 18:10:13 -07006545func addCustomExtensionTests() {
6546 expectedContents := "custom extension"
6547 emptyString := ""
6548
6549 for _, isClient := range []bool{false, true} {
6550 suffix := "Server"
6551 flag := "-enable-server-custom-extension"
6552 testType := serverTest
6553 if isClient {
6554 suffix = "Client"
6555 flag = "-enable-client-custom-extension"
6556 testType = clientTest
6557 }
6558
6559 testCases = append(testCases, testCase{
6560 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006561 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006562 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006563 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006564 Bugs: ProtocolBugs{
6565 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006566 ExpectedCustomExtension: &expectedContents,
6567 },
6568 },
6569 flags: []string{flag},
6570 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006571 testCases = append(testCases, testCase{
6572 testType: testType,
6573 name: "CustomExtensions-" + suffix + "-TLS13",
6574 config: Config{
6575 MaxVersion: VersionTLS13,
6576 Bugs: ProtocolBugs{
6577 CustomExtension: expectedContents,
6578 ExpectedCustomExtension: &expectedContents,
6579 },
6580 },
6581 flags: []string{flag},
6582 })
Adam Langley09505632015-07-30 18:10:13 -07006583
6584 // If the parse callback fails, the handshake should also fail.
6585 testCases = append(testCases, testCase{
6586 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006587 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006588 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006589 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006590 Bugs: ProtocolBugs{
6591 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006592 ExpectedCustomExtension: &expectedContents,
6593 },
6594 },
David Benjamin399e7c92015-07-30 23:01:27 -04006595 flags: []string{flag},
6596 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006597 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6598 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006599 testCases = append(testCases, testCase{
6600 testType: testType,
6601 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6602 config: Config{
6603 MaxVersion: VersionTLS13,
6604 Bugs: ProtocolBugs{
6605 CustomExtension: expectedContents + "foo",
6606 ExpectedCustomExtension: &expectedContents,
6607 },
6608 },
6609 flags: []string{flag},
6610 shouldFail: true,
6611 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6612 })
Adam Langley09505632015-07-30 18:10:13 -07006613
6614 // If the add callback fails, the handshake should also fail.
6615 testCases = append(testCases, testCase{
6616 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006617 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006618 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006619 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006620 Bugs: ProtocolBugs{
6621 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006622 ExpectedCustomExtension: &expectedContents,
6623 },
6624 },
David Benjamin399e7c92015-07-30 23:01:27 -04006625 flags: []string{flag, "-custom-extension-fail-add"},
6626 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006627 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6628 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006629 testCases = append(testCases, testCase{
6630 testType: testType,
6631 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6632 config: Config{
6633 MaxVersion: VersionTLS13,
6634 Bugs: ProtocolBugs{
6635 CustomExtension: expectedContents,
6636 ExpectedCustomExtension: &expectedContents,
6637 },
6638 },
6639 flags: []string{flag, "-custom-extension-fail-add"},
6640 shouldFail: true,
6641 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6642 })
Adam Langley09505632015-07-30 18:10:13 -07006643
6644 // If the add callback returns zero, no extension should be
6645 // added.
6646 skipCustomExtension := expectedContents
6647 if isClient {
6648 // For the case where the client skips sending the
6649 // custom extension, the server must not “echo” it.
6650 skipCustomExtension = ""
6651 }
6652 testCases = append(testCases, testCase{
6653 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006654 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006655 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006656 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006657 Bugs: ProtocolBugs{
6658 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006659 ExpectedCustomExtension: &emptyString,
6660 },
6661 },
6662 flags: []string{flag, "-custom-extension-skip"},
6663 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006664 testCases = append(testCases, testCase{
6665 testType: testType,
6666 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6667 config: Config{
6668 MaxVersion: VersionTLS13,
6669 Bugs: ProtocolBugs{
6670 CustomExtension: skipCustomExtension,
6671 ExpectedCustomExtension: &emptyString,
6672 },
6673 },
6674 flags: []string{flag, "-custom-extension-skip"},
6675 })
Adam Langley09505632015-07-30 18:10:13 -07006676 }
6677
6678 // The custom extension add callback should not be called if the client
6679 // doesn't send the extension.
6680 testCases = append(testCases, testCase{
6681 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006682 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006683 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006684 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006685 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006686 ExpectedCustomExtension: &emptyString,
6687 },
6688 },
6689 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6690 })
Adam Langley2deb9842015-08-07 11:15:37 -07006691
Steven Valdez143e8b32016-07-11 13:19:03 -04006692 testCases = append(testCases, testCase{
6693 testType: serverTest,
6694 name: "CustomExtensions-NotCalled-Server-TLS13",
6695 config: Config{
6696 MaxVersion: VersionTLS13,
6697 Bugs: ProtocolBugs{
6698 ExpectedCustomExtension: &emptyString,
6699 },
6700 },
6701 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6702 })
6703
Adam Langley2deb9842015-08-07 11:15:37 -07006704 // Test an unknown extension from the server.
6705 testCases = append(testCases, testCase{
6706 testType: clientTest,
6707 name: "UnknownExtension-Client",
6708 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006709 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006710 Bugs: ProtocolBugs{
6711 CustomExtension: expectedContents,
6712 },
6713 },
David Benjamin0c40a962016-08-01 12:05:50 -04006714 shouldFail: true,
6715 expectedError: ":UNEXPECTED_EXTENSION:",
6716 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006717 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006718 testCases = append(testCases, testCase{
6719 testType: clientTest,
6720 name: "UnknownExtension-Client-TLS13",
6721 config: Config{
6722 MaxVersion: VersionTLS13,
6723 Bugs: ProtocolBugs{
6724 CustomExtension: expectedContents,
6725 },
6726 },
David Benjamin0c40a962016-08-01 12:05:50 -04006727 shouldFail: true,
6728 expectedError: ":UNEXPECTED_EXTENSION:",
6729 expectedLocalError: "remote error: unsupported extension",
6730 })
6731
6732 // Test a known but unoffered extension from the server.
6733 testCases = append(testCases, testCase{
6734 testType: clientTest,
6735 name: "UnofferedExtension-Client",
6736 config: Config{
6737 MaxVersion: VersionTLS12,
6738 Bugs: ProtocolBugs{
6739 SendALPN: "alpn",
6740 },
6741 },
6742 shouldFail: true,
6743 expectedError: ":UNEXPECTED_EXTENSION:",
6744 expectedLocalError: "remote error: unsupported extension",
6745 })
6746 testCases = append(testCases, testCase{
6747 testType: clientTest,
6748 name: "UnofferedExtension-Client-TLS13",
6749 config: Config{
6750 MaxVersion: VersionTLS13,
6751 Bugs: ProtocolBugs{
6752 SendALPN: "alpn",
6753 },
6754 },
6755 shouldFail: true,
6756 expectedError: ":UNEXPECTED_EXTENSION:",
6757 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006758 })
Adam Langley09505632015-07-30 18:10:13 -07006759}
6760
David Benjaminb36a3952015-12-01 18:53:13 -05006761func addRSAClientKeyExchangeTests() {
6762 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6763 testCases = append(testCases, testCase{
6764 testType: serverTest,
6765 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6766 config: Config{
6767 // Ensure the ClientHello version and final
6768 // version are different, to detect if the
6769 // server uses the wrong one.
6770 MaxVersion: VersionTLS11,
6771 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6772 Bugs: ProtocolBugs{
6773 BadRSAClientKeyExchange: bad,
6774 },
6775 },
6776 shouldFail: true,
6777 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6778 })
6779 }
6780}
6781
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006782var testCurves = []struct {
6783 name string
6784 id CurveID
6785}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006786 {"P-256", CurveP256},
6787 {"P-384", CurveP384},
6788 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006789 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006790}
6791
Steven Valdez5440fe02016-07-18 12:40:30 -04006792const bogusCurve = 0x1234
6793
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006794func addCurveTests() {
6795 for _, curve := range testCurves {
6796 testCases = append(testCases, testCase{
6797 name: "CurveTest-Client-" + curve.name,
6798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006799 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006800 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6801 CurvePreferences: []CurveID{curve.id},
6802 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006803 flags: []string{"-enable-all-curves"},
6804 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006805 })
6806 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006807 name: "CurveTest-Client-" + curve.name + "-TLS13",
6808 config: Config{
6809 MaxVersion: VersionTLS13,
6810 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6811 CurvePreferences: []CurveID{curve.id},
6812 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006813 flags: []string{"-enable-all-curves"},
6814 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006815 })
6816 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006817 testType: serverTest,
6818 name: "CurveTest-Server-" + curve.name,
6819 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006820 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006821 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6822 CurvePreferences: []CurveID{curve.id},
6823 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006824 flags: []string{"-enable-all-curves"},
6825 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006826 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006827 testCases = append(testCases, testCase{
6828 testType: serverTest,
6829 name: "CurveTest-Server-" + curve.name + "-TLS13",
6830 config: Config{
6831 MaxVersion: VersionTLS13,
6832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6833 CurvePreferences: []CurveID{curve.id},
6834 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006835 flags: []string{"-enable-all-curves"},
6836 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006837 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006838 }
David Benjamin241ae832016-01-15 03:04:54 -05006839
6840 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006841 testCases = append(testCases, testCase{
6842 testType: serverTest,
6843 name: "UnknownCurve",
6844 config: Config{
6845 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6846 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6847 },
6848 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006849
6850 // The server must not consider ECDHE ciphers when there are no
6851 // supported curves.
6852 testCases = append(testCases, testCase{
6853 testType: serverTest,
6854 name: "NoSupportedCurves",
6855 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006856 MaxVersion: VersionTLS12,
6857 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6858 Bugs: ProtocolBugs{
6859 NoSupportedCurves: true,
6860 },
6861 },
6862 shouldFail: true,
6863 expectedError: ":NO_SHARED_CIPHER:",
6864 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006865 testCases = append(testCases, testCase{
6866 testType: serverTest,
6867 name: "NoSupportedCurves-TLS13",
6868 config: Config{
6869 MaxVersion: VersionTLS13,
6870 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6871 Bugs: ProtocolBugs{
6872 NoSupportedCurves: true,
6873 },
6874 },
6875 shouldFail: true,
6876 expectedError: ":NO_SHARED_CIPHER:",
6877 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006878
6879 // The server must fall back to another cipher when there are no
6880 // supported curves.
6881 testCases = append(testCases, testCase{
6882 testType: serverTest,
6883 name: "NoCommonCurves",
6884 config: Config{
6885 MaxVersion: VersionTLS12,
6886 CipherSuites: []uint16{
6887 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6888 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6889 },
6890 CurvePreferences: []CurveID{CurveP224},
6891 },
6892 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6893 })
6894
6895 // The client must reject bogus curves and disabled curves.
6896 testCases = append(testCases, testCase{
6897 name: "BadECDHECurve",
6898 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006899 MaxVersion: VersionTLS12,
6900 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6901 Bugs: ProtocolBugs{
6902 SendCurve: bogusCurve,
6903 },
6904 },
6905 shouldFail: true,
6906 expectedError: ":WRONG_CURVE:",
6907 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006908 testCases = append(testCases, testCase{
6909 name: "BadECDHECurve-TLS13",
6910 config: Config{
6911 MaxVersion: VersionTLS13,
6912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6913 Bugs: ProtocolBugs{
6914 SendCurve: bogusCurve,
6915 },
6916 },
6917 shouldFail: true,
6918 expectedError: ":WRONG_CURVE:",
6919 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006920
6921 testCases = append(testCases, testCase{
6922 name: "UnsupportedCurve",
6923 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006924 MaxVersion: VersionTLS12,
6925 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6926 CurvePreferences: []CurveID{CurveP256},
6927 Bugs: ProtocolBugs{
6928 IgnorePeerCurvePreferences: true,
6929 },
6930 },
6931 flags: []string{"-p384-only"},
6932 shouldFail: true,
6933 expectedError: ":WRONG_CURVE:",
6934 })
6935
David Benjamin4f921572016-07-17 14:20:10 +02006936 testCases = append(testCases, testCase{
6937 // TODO(davidben): Add a TLS 1.3 version where
6938 // HelloRetryRequest requests an unsupported curve.
6939 name: "UnsupportedCurve-ServerHello-TLS13",
6940 config: Config{
6941 MaxVersion: VersionTLS12,
6942 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6943 CurvePreferences: []CurveID{CurveP384},
6944 Bugs: ProtocolBugs{
6945 SendCurve: CurveP256,
6946 },
6947 },
6948 flags: []string{"-p384-only"},
6949 shouldFail: true,
6950 expectedError: ":WRONG_CURVE:",
6951 })
6952
David Benjamin4c3ddf72016-06-29 18:13:53 -04006953 // Test invalid curve points.
6954 testCases = append(testCases, testCase{
6955 name: "InvalidECDHPoint-Client",
6956 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006957 MaxVersion: VersionTLS12,
6958 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6959 CurvePreferences: []CurveID{CurveP256},
6960 Bugs: ProtocolBugs{
6961 InvalidECDHPoint: true,
6962 },
6963 },
6964 shouldFail: true,
6965 expectedError: ":INVALID_ENCODING:",
6966 })
6967 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006968 name: "InvalidECDHPoint-Client-TLS13",
6969 config: Config{
6970 MaxVersion: VersionTLS13,
6971 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6972 CurvePreferences: []CurveID{CurveP256},
6973 Bugs: ProtocolBugs{
6974 InvalidECDHPoint: true,
6975 },
6976 },
6977 shouldFail: true,
6978 expectedError: ":INVALID_ENCODING:",
6979 })
6980 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006981 testType: serverTest,
6982 name: "InvalidECDHPoint-Server",
6983 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006984 MaxVersion: VersionTLS12,
6985 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6986 CurvePreferences: []CurveID{CurveP256},
6987 Bugs: ProtocolBugs{
6988 InvalidECDHPoint: true,
6989 },
6990 },
6991 shouldFail: true,
6992 expectedError: ":INVALID_ENCODING:",
6993 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006994 testCases = append(testCases, testCase{
6995 testType: serverTest,
6996 name: "InvalidECDHPoint-Server-TLS13",
6997 config: Config{
6998 MaxVersion: VersionTLS13,
6999 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7000 CurvePreferences: []CurveID{CurveP256},
7001 Bugs: ProtocolBugs{
7002 InvalidECDHPoint: true,
7003 },
7004 },
7005 shouldFail: true,
7006 expectedError: ":INVALID_ENCODING:",
7007 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007008}
7009
Matt Braithwaite54217e42016-06-13 13:03:47 -07007010func addCECPQ1Tests() {
7011 testCases = append(testCases, testCase{
7012 testType: clientTest,
7013 name: "CECPQ1-Client-BadX25519Part",
7014 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007015 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007016 MinVersion: VersionTLS12,
7017 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7018 Bugs: ProtocolBugs{
7019 CECPQ1BadX25519Part: true,
7020 },
7021 },
7022 flags: []string{"-cipher", "kCECPQ1"},
7023 shouldFail: true,
7024 expectedLocalError: "local error: bad record MAC",
7025 })
7026 testCases = append(testCases, testCase{
7027 testType: clientTest,
7028 name: "CECPQ1-Client-BadNewhopePart",
7029 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007030 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007031 MinVersion: VersionTLS12,
7032 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7033 Bugs: ProtocolBugs{
7034 CECPQ1BadNewhopePart: true,
7035 },
7036 },
7037 flags: []string{"-cipher", "kCECPQ1"},
7038 shouldFail: true,
7039 expectedLocalError: "local error: bad record MAC",
7040 })
7041 testCases = append(testCases, testCase{
7042 testType: serverTest,
7043 name: "CECPQ1-Server-BadX25519Part",
7044 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007045 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007046 MinVersion: VersionTLS12,
7047 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7048 Bugs: ProtocolBugs{
7049 CECPQ1BadX25519Part: true,
7050 },
7051 },
7052 flags: []string{"-cipher", "kCECPQ1"},
7053 shouldFail: true,
7054 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7055 })
7056 testCases = append(testCases, testCase{
7057 testType: serverTest,
7058 name: "CECPQ1-Server-BadNewhopePart",
7059 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007060 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007061 MinVersion: VersionTLS12,
7062 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7063 Bugs: ProtocolBugs{
7064 CECPQ1BadNewhopePart: true,
7065 },
7066 },
7067 flags: []string{"-cipher", "kCECPQ1"},
7068 shouldFail: true,
7069 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7070 })
7071}
7072
David Benjamin4cc36ad2015-12-19 14:23:26 -05007073func addKeyExchangeInfoTests() {
7074 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05007075 name: "KeyExchangeInfo-DHE-Client",
7076 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007077 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007078 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7079 Bugs: ProtocolBugs{
7080 // This is a 1234-bit prime number, generated
7081 // with:
7082 // openssl gendh 1234 | openssl asn1parse -i
7083 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7084 },
7085 },
David Benjamin9e68f192016-06-30 14:55:33 -04007086 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007087 })
7088 testCases = append(testCases, testCase{
7089 testType: serverTest,
7090 name: "KeyExchangeInfo-DHE-Server",
7091 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007092 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007093 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7094 },
7095 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007096 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007097 })
7098
7099 testCases = append(testCases, testCase{
7100 name: "KeyExchangeInfo-ECDHE-Client",
7101 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007102 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007103 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7104 CurvePreferences: []CurveID{CurveX25519},
7105 },
David Benjamin9e68f192016-06-30 14:55:33 -04007106 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007107 })
7108 testCases = append(testCases, testCase{
7109 testType: serverTest,
7110 name: "KeyExchangeInfo-ECDHE-Server",
7111 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007112 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007113 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7114 CurvePreferences: []CurveID{CurveX25519},
7115 },
David Benjamin9e68f192016-06-30 14:55:33 -04007116 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007117 })
7118}
7119
David Benjaminc9ae27c2016-06-24 22:56:37 -04007120func addTLS13RecordTests() {
7121 testCases = append(testCases, testCase{
7122 name: "TLS13-RecordPadding",
7123 config: Config{
7124 MaxVersion: VersionTLS13,
7125 MinVersion: VersionTLS13,
7126 Bugs: ProtocolBugs{
7127 RecordPadding: 10,
7128 },
7129 },
7130 })
7131
7132 testCases = append(testCases, testCase{
7133 name: "TLS13-EmptyRecords",
7134 config: Config{
7135 MaxVersion: VersionTLS13,
7136 MinVersion: VersionTLS13,
7137 Bugs: ProtocolBugs{
7138 OmitRecordContents: true,
7139 },
7140 },
7141 shouldFail: true,
7142 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7143 })
7144
7145 testCases = append(testCases, testCase{
7146 name: "TLS13-OnlyPadding",
7147 config: Config{
7148 MaxVersion: VersionTLS13,
7149 MinVersion: VersionTLS13,
7150 Bugs: ProtocolBugs{
7151 OmitRecordContents: true,
7152 RecordPadding: 10,
7153 },
7154 },
7155 shouldFail: true,
7156 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7157 })
7158
7159 testCases = append(testCases, testCase{
7160 name: "TLS13-WrongOuterRecord",
7161 config: Config{
7162 MaxVersion: VersionTLS13,
7163 MinVersion: VersionTLS13,
7164 Bugs: ProtocolBugs{
7165 OuterRecordType: recordTypeHandshake,
7166 },
7167 },
7168 shouldFail: true,
7169 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7170 })
7171}
7172
David Benjamin82261be2016-07-07 14:32:50 -07007173func addChangeCipherSpecTests() {
7174 // Test missing ChangeCipherSpecs.
7175 testCases = append(testCases, testCase{
7176 name: "SkipChangeCipherSpec-Client",
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",
7189 config: Config{
7190 MaxVersion: VersionTLS12,
7191 Bugs: ProtocolBugs{
7192 SkipChangeCipherSpec: true,
7193 },
7194 },
7195 shouldFail: true,
7196 expectedError: ":UNEXPECTED_RECORD:",
7197 })
7198 testCases = append(testCases, testCase{
7199 testType: serverTest,
7200 name: "SkipChangeCipherSpec-Server-NPN",
7201 config: Config{
7202 MaxVersion: VersionTLS12,
7203 NextProtos: []string{"bar"},
7204 Bugs: ProtocolBugs{
7205 SkipChangeCipherSpec: true,
7206 },
7207 },
7208 flags: []string{
7209 "-advertise-npn", "\x03foo\x03bar\x03baz",
7210 },
7211 shouldFail: true,
7212 expectedError: ":UNEXPECTED_RECORD:",
7213 })
7214
7215 // Test synchronization between the handshake and ChangeCipherSpec.
7216 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7217 // rejected. Test both with and without handshake packing to handle both
7218 // when the partial post-CCS message is in its own record and when it is
7219 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007220 for _, packed := range []bool{false, true} {
7221 var suffix string
7222 if packed {
7223 suffix = "-Packed"
7224 }
7225
7226 testCases = append(testCases, testCase{
7227 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7228 config: Config{
7229 MaxVersion: VersionTLS12,
7230 Bugs: ProtocolBugs{
7231 FragmentAcrossChangeCipherSpec: true,
7232 PackHandshakeFlight: packed,
7233 },
7234 },
7235 shouldFail: true,
7236 expectedError: ":UNEXPECTED_RECORD:",
7237 })
7238 testCases = append(testCases, testCase{
7239 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7240 config: Config{
7241 MaxVersion: VersionTLS12,
7242 },
7243 resumeSession: true,
7244 resumeConfig: &Config{
7245 MaxVersion: VersionTLS12,
7246 Bugs: ProtocolBugs{
7247 FragmentAcrossChangeCipherSpec: true,
7248 PackHandshakeFlight: packed,
7249 },
7250 },
7251 shouldFail: true,
7252 expectedError: ":UNEXPECTED_RECORD:",
7253 })
7254 testCases = append(testCases, testCase{
7255 testType: serverTest,
7256 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7257 config: Config{
7258 MaxVersion: VersionTLS12,
7259 Bugs: ProtocolBugs{
7260 FragmentAcrossChangeCipherSpec: true,
7261 PackHandshakeFlight: packed,
7262 },
7263 },
7264 shouldFail: true,
7265 expectedError: ":UNEXPECTED_RECORD:",
7266 })
7267 testCases = append(testCases, testCase{
7268 testType: serverTest,
7269 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7270 config: Config{
7271 MaxVersion: VersionTLS12,
7272 },
7273 resumeSession: true,
7274 resumeConfig: &Config{
7275 MaxVersion: VersionTLS12,
7276 Bugs: ProtocolBugs{
7277 FragmentAcrossChangeCipherSpec: true,
7278 PackHandshakeFlight: packed,
7279 },
7280 },
7281 shouldFail: true,
7282 expectedError: ":UNEXPECTED_RECORD:",
7283 })
7284 testCases = append(testCases, testCase{
7285 testType: serverTest,
7286 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7287 config: Config{
7288 MaxVersion: VersionTLS12,
7289 NextProtos: []string{"bar"},
7290 Bugs: ProtocolBugs{
7291 FragmentAcrossChangeCipherSpec: true,
7292 PackHandshakeFlight: packed,
7293 },
7294 },
7295 flags: []string{
7296 "-advertise-npn", "\x03foo\x03bar\x03baz",
7297 },
7298 shouldFail: true,
7299 expectedError: ":UNEXPECTED_RECORD:",
7300 })
7301 }
7302
David Benjamin61672812016-07-14 23:10:43 -04007303 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7304 // messages in the handshake queue. Do this by testing the server
7305 // reading the client Finished, reversing the flight so Finished comes
7306 // first.
7307 testCases = append(testCases, testCase{
7308 protocol: dtls,
7309 testType: serverTest,
7310 name: "SendUnencryptedFinished-DTLS",
7311 config: Config{
7312 MaxVersion: VersionTLS12,
7313 Bugs: ProtocolBugs{
7314 SendUnencryptedFinished: true,
7315 ReverseHandshakeFragments: true,
7316 },
7317 },
7318 shouldFail: true,
7319 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7320 })
7321
Steven Valdez143e8b32016-07-11 13:19:03 -04007322 // Test synchronization between encryption changes and the handshake in
7323 // TLS 1.3, where ChangeCipherSpec is implicit.
7324 testCases = append(testCases, testCase{
7325 name: "PartialEncryptedExtensionsWithServerHello",
7326 config: Config{
7327 MaxVersion: VersionTLS13,
7328 Bugs: ProtocolBugs{
7329 PartialEncryptedExtensionsWithServerHello: true,
7330 },
7331 },
7332 shouldFail: true,
7333 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7334 })
7335 testCases = append(testCases, testCase{
7336 testType: serverTest,
7337 name: "PartialClientFinishedWithClientHello",
7338 config: Config{
7339 MaxVersion: VersionTLS13,
7340 Bugs: ProtocolBugs{
7341 PartialClientFinishedWithClientHello: true,
7342 },
7343 },
7344 shouldFail: true,
7345 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7346 })
7347
David Benjamin82261be2016-07-07 14:32:50 -07007348 // Test that early ChangeCipherSpecs are handled correctly.
7349 testCases = append(testCases, testCase{
7350 testType: serverTest,
7351 name: "EarlyChangeCipherSpec-server-1",
7352 config: Config{
7353 MaxVersion: VersionTLS12,
7354 Bugs: ProtocolBugs{
7355 EarlyChangeCipherSpec: 1,
7356 },
7357 },
7358 shouldFail: true,
7359 expectedError: ":UNEXPECTED_RECORD:",
7360 })
7361 testCases = append(testCases, testCase{
7362 testType: serverTest,
7363 name: "EarlyChangeCipherSpec-server-2",
7364 config: Config{
7365 MaxVersion: VersionTLS12,
7366 Bugs: ProtocolBugs{
7367 EarlyChangeCipherSpec: 2,
7368 },
7369 },
7370 shouldFail: true,
7371 expectedError: ":UNEXPECTED_RECORD:",
7372 })
7373 testCases = append(testCases, testCase{
7374 protocol: dtls,
7375 name: "StrayChangeCipherSpec",
7376 config: Config{
7377 // TODO(davidben): Once DTLS 1.3 exists, test
7378 // that stray ChangeCipherSpec messages are
7379 // rejected.
7380 MaxVersion: VersionTLS12,
7381 Bugs: ProtocolBugs{
7382 StrayChangeCipherSpec: true,
7383 },
7384 },
7385 })
7386
7387 // Test that the contents of ChangeCipherSpec are checked.
7388 testCases = append(testCases, testCase{
7389 name: "BadChangeCipherSpec-1",
7390 config: Config{
7391 MaxVersion: VersionTLS12,
7392 Bugs: ProtocolBugs{
7393 BadChangeCipherSpec: []byte{2},
7394 },
7395 },
7396 shouldFail: true,
7397 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7398 })
7399 testCases = append(testCases, testCase{
7400 name: "BadChangeCipherSpec-2",
7401 config: Config{
7402 MaxVersion: VersionTLS12,
7403 Bugs: ProtocolBugs{
7404 BadChangeCipherSpec: []byte{1, 1},
7405 },
7406 },
7407 shouldFail: true,
7408 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7409 })
7410 testCases = append(testCases, testCase{
7411 protocol: dtls,
7412 name: "BadChangeCipherSpec-DTLS-1",
7413 config: Config{
7414 MaxVersion: VersionTLS12,
7415 Bugs: ProtocolBugs{
7416 BadChangeCipherSpec: []byte{2},
7417 },
7418 },
7419 shouldFail: true,
7420 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7421 })
7422 testCases = append(testCases, testCase{
7423 protocol: dtls,
7424 name: "BadChangeCipherSpec-DTLS-2",
7425 config: Config{
7426 MaxVersion: VersionTLS12,
7427 Bugs: ProtocolBugs{
7428 BadChangeCipherSpec: []byte{1, 1},
7429 },
7430 },
7431 shouldFail: true,
7432 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7433 })
7434}
7435
David Benjamin0b8d5da2016-07-15 00:39:56 -04007436func addWrongMessageTypeTests() {
7437 for _, protocol := range []protocol{tls, dtls} {
7438 var suffix string
7439 if protocol == dtls {
7440 suffix = "-DTLS"
7441 }
7442
7443 testCases = append(testCases, testCase{
7444 protocol: protocol,
7445 testType: serverTest,
7446 name: "WrongMessageType-ClientHello" + suffix,
7447 config: Config{
7448 MaxVersion: VersionTLS12,
7449 Bugs: ProtocolBugs{
7450 SendWrongMessageType: typeClientHello,
7451 },
7452 },
7453 shouldFail: true,
7454 expectedError: ":UNEXPECTED_MESSAGE:",
7455 expectedLocalError: "remote error: unexpected message",
7456 })
7457
7458 if protocol == dtls {
7459 testCases = append(testCases, testCase{
7460 protocol: protocol,
7461 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7462 config: Config{
7463 MaxVersion: VersionTLS12,
7464 Bugs: ProtocolBugs{
7465 SendWrongMessageType: typeHelloVerifyRequest,
7466 },
7467 },
7468 shouldFail: true,
7469 expectedError: ":UNEXPECTED_MESSAGE:",
7470 expectedLocalError: "remote error: unexpected message",
7471 })
7472 }
7473
7474 testCases = append(testCases, testCase{
7475 protocol: protocol,
7476 name: "WrongMessageType-ServerHello" + suffix,
7477 config: Config{
7478 MaxVersion: VersionTLS12,
7479 Bugs: ProtocolBugs{
7480 SendWrongMessageType: typeServerHello,
7481 },
7482 },
7483 shouldFail: true,
7484 expectedError: ":UNEXPECTED_MESSAGE:",
7485 expectedLocalError: "remote error: unexpected message",
7486 })
7487
7488 testCases = append(testCases, testCase{
7489 protocol: protocol,
7490 name: "WrongMessageType-ServerCertificate" + suffix,
7491 config: Config{
7492 MaxVersion: VersionTLS12,
7493 Bugs: ProtocolBugs{
7494 SendWrongMessageType: typeCertificate,
7495 },
7496 },
7497 shouldFail: true,
7498 expectedError: ":UNEXPECTED_MESSAGE:",
7499 expectedLocalError: "remote error: unexpected message",
7500 })
7501
7502 testCases = append(testCases, testCase{
7503 protocol: protocol,
7504 name: "WrongMessageType-CertificateStatus" + suffix,
7505 config: Config{
7506 MaxVersion: VersionTLS12,
7507 Bugs: ProtocolBugs{
7508 SendWrongMessageType: typeCertificateStatus,
7509 },
7510 },
7511 flags: []string{"-enable-ocsp-stapling"},
7512 shouldFail: true,
7513 expectedError: ":UNEXPECTED_MESSAGE:",
7514 expectedLocalError: "remote error: unexpected message",
7515 })
7516
7517 testCases = append(testCases, testCase{
7518 protocol: protocol,
7519 name: "WrongMessageType-ServerKeyExchange" + suffix,
7520 config: Config{
7521 MaxVersion: VersionTLS12,
7522 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7523 Bugs: ProtocolBugs{
7524 SendWrongMessageType: typeServerKeyExchange,
7525 },
7526 },
7527 shouldFail: true,
7528 expectedError: ":UNEXPECTED_MESSAGE:",
7529 expectedLocalError: "remote error: unexpected message",
7530 })
7531
7532 testCases = append(testCases, testCase{
7533 protocol: protocol,
7534 name: "WrongMessageType-CertificateRequest" + suffix,
7535 config: Config{
7536 MaxVersion: VersionTLS12,
7537 ClientAuth: RequireAnyClientCert,
7538 Bugs: ProtocolBugs{
7539 SendWrongMessageType: typeCertificateRequest,
7540 },
7541 },
7542 shouldFail: true,
7543 expectedError: ":UNEXPECTED_MESSAGE:",
7544 expectedLocalError: "remote error: unexpected message",
7545 })
7546
7547 testCases = append(testCases, testCase{
7548 protocol: protocol,
7549 name: "WrongMessageType-ServerHelloDone" + suffix,
7550 config: Config{
7551 MaxVersion: VersionTLS12,
7552 Bugs: ProtocolBugs{
7553 SendWrongMessageType: typeServerHelloDone,
7554 },
7555 },
7556 shouldFail: true,
7557 expectedError: ":UNEXPECTED_MESSAGE:",
7558 expectedLocalError: "remote error: unexpected message",
7559 })
7560
7561 testCases = append(testCases, testCase{
7562 testType: serverTest,
7563 protocol: protocol,
7564 name: "WrongMessageType-ClientCertificate" + suffix,
7565 config: Config{
7566 Certificates: []Certificate{rsaCertificate},
7567 MaxVersion: VersionTLS12,
7568 Bugs: ProtocolBugs{
7569 SendWrongMessageType: typeCertificate,
7570 },
7571 },
7572 flags: []string{"-require-any-client-certificate"},
7573 shouldFail: true,
7574 expectedError: ":UNEXPECTED_MESSAGE:",
7575 expectedLocalError: "remote error: unexpected message",
7576 })
7577
7578 testCases = append(testCases, testCase{
7579 testType: serverTest,
7580 protocol: protocol,
7581 name: "WrongMessageType-CertificateVerify" + suffix,
7582 config: Config{
7583 Certificates: []Certificate{rsaCertificate},
7584 MaxVersion: VersionTLS12,
7585 Bugs: ProtocolBugs{
7586 SendWrongMessageType: typeCertificateVerify,
7587 },
7588 },
7589 flags: []string{"-require-any-client-certificate"},
7590 shouldFail: true,
7591 expectedError: ":UNEXPECTED_MESSAGE:",
7592 expectedLocalError: "remote error: unexpected message",
7593 })
7594
7595 testCases = append(testCases, testCase{
7596 testType: serverTest,
7597 protocol: protocol,
7598 name: "WrongMessageType-ClientKeyExchange" + suffix,
7599 config: Config{
7600 MaxVersion: VersionTLS12,
7601 Bugs: ProtocolBugs{
7602 SendWrongMessageType: typeClientKeyExchange,
7603 },
7604 },
7605 shouldFail: true,
7606 expectedError: ":UNEXPECTED_MESSAGE:",
7607 expectedLocalError: "remote error: unexpected message",
7608 })
7609
7610 if protocol != dtls {
7611 testCases = append(testCases, testCase{
7612 testType: serverTest,
7613 protocol: protocol,
7614 name: "WrongMessageType-NextProtocol" + suffix,
7615 config: Config{
7616 MaxVersion: VersionTLS12,
7617 NextProtos: []string{"bar"},
7618 Bugs: ProtocolBugs{
7619 SendWrongMessageType: typeNextProtocol,
7620 },
7621 },
7622 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7623 shouldFail: true,
7624 expectedError: ":UNEXPECTED_MESSAGE:",
7625 expectedLocalError: "remote error: unexpected message",
7626 })
7627
7628 testCases = append(testCases, testCase{
7629 testType: serverTest,
7630 protocol: protocol,
7631 name: "WrongMessageType-ChannelID" + suffix,
7632 config: Config{
7633 MaxVersion: VersionTLS12,
7634 ChannelID: channelIDKey,
7635 Bugs: ProtocolBugs{
7636 SendWrongMessageType: typeChannelID,
7637 },
7638 },
7639 flags: []string{
7640 "-expect-channel-id",
7641 base64.StdEncoding.EncodeToString(channelIDBytes),
7642 },
7643 shouldFail: true,
7644 expectedError: ":UNEXPECTED_MESSAGE:",
7645 expectedLocalError: "remote error: unexpected message",
7646 })
7647 }
7648
7649 testCases = append(testCases, testCase{
7650 testType: serverTest,
7651 protocol: protocol,
7652 name: "WrongMessageType-ClientFinished" + suffix,
7653 config: Config{
7654 MaxVersion: VersionTLS12,
7655 Bugs: ProtocolBugs{
7656 SendWrongMessageType: typeFinished,
7657 },
7658 },
7659 shouldFail: true,
7660 expectedError: ":UNEXPECTED_MESSAGE:",
7661 expectedLocalError: "remote error: unexpected message",
7662 })
7663
7664 testCases = append(testCases, testCase{
7665 protocol: protocol,
7666 name: "WrongMessageType-NewSessionTicket" + suffix,
7667 config: Config{
7668 MaxVersion: VersionTLS12,
7669 Bugs: ProtocolBugs{
7670 SendWrongMessageType: typeNewSessionTicket,
7671 },
7672 },
7673 shouldFail: true,
7674 expectedError: ":UNEXPECTED_MESSAGE:",
7675 expectedLocalError: "remote error: unexpected message",
7676 })
7677
7678 testCases = append(testCases, testCase{
7679 protocol: protocol,
7680 name: "WrongMessageType-ServerFinished" + suffix,
7681 config: Config{
7682 MaxVersion: VersionTLS12,
7683 Bugs: ProtocolBugs{
7684 SendWrongMessageType: typeFinished,
7685 },
7686 },
7687 shouldFail: true,
7688 expectedError: ":UNEXPECTED_MESSAGE:",
7689 expectedLocalError: "remote error: unexpected message",
7690 })
7691
7692 }
7693}
7694
Steven Valdez143e8b32016-07-11 13:19:03 -04007695func addTLS13WrongMessageTypeTests() {
7696 testCases = append(testCases, testCase{
7697 testType: serverTest,
7698 name: "WrongMessageType-TLS13-ClientHello",
7699 config: Config{
7700 MaxVersion: VersionTLS13,
7701 Bugs: ProtocolBugs{
7702 SendWrongMessageType: typeClientHello,
7703 },
7704 },
7705 shouldFail: true,
7706 expectedError: ":UNEXPECTED_MESSAGE:",
7707 expectedLocalError: "remote error: unexpected message",
7708 })
7709
7710 testCases = append(testCases, testCase{
7711 name: "WrongMessageType-TLS13-ServerHello",
7712 config: Config{
7713 MaxVersion: VersionTLS13,
7714 Bugs: ProtocolBugs{
7715 SendWrongMessageType: typeServerHello,
7716 },
7717 },
7718 shouldFail: true,
7719 expectedError: ":UNEXPECTED_MESSAGE:",
7720 // The alert comes in with the wrong encryption.
7721 expectedLocalError: "local error: bad record MAC",
7722 })
7723
7724 testCases = append(testCases, testCase{
7725 name: "WrongMessageType-TLS13-EncryptedExtensions",
7726 config: Config{
7727 MaxVersion: VersionTLS13,
7728 Bugs: ProtocolBugs{
7729 SendWrongMessageType: typeEncryptedExtensions,
7730 },
7731 },
7732 shouldFail: true,
7733 expectedError: ":UNEXPECTED_MESSAGE:",
7734 expectedLocalError: "remote error: unexpected message",
7735 })
7736
7737 testCases = append(testCases, testCase{
7738 name: "WrongMessageType-TLS13-CertificateRequest",
7739 config: Config{
7740 MaxVersion: VersionTLS13,
7741 ClientAuth: RequireAnyClientCert,
7742 Bugs: ProtocolBugs{
7743 SendWrongMessageType: typeCertificateRequest,
7744 },
7745 },
7746 shouldFail: true,
7747 expectedError: ":UNEXPECTED_MESSAGE:",
7748 expectedLocalError: "remote error: unexpected message",
7749 })
7750
7751 testCases = append(testCases, testCase{
7752 name: "WrongMessageType-TLS13-ServerCertificate",
7753 config: Config{
7754 MaxVersion: VersionTLS13,
7755 Bugs: ProtocolBugs{
7756 SendWrongMessageType: typeCertificate,
7757 },
7758 },
7759 shouldFail: true,
7760 expectedError: ":UNEXPECTED_MESSAGE:",
7761 expectedLocalError: "remote error: unexpected message",
7762 })
7763
7764 testCases = append(testCases, testCase{
7765 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7766 config: Config{
7767 MaxVersion: VersionTLS13,
7768 Bugs: ProtocolBugs{
7769 SendWrongMessageType: typeCertificateVerify,
7770 },
7771 },
7772 shouldFail: true,
7773 expectedError: ":UNEXPECTED_MESSAGE:",
7774 expectedLocalError: "remote error: unexpected message",
7775 })
7776
7777 testCases = append(testCases, testCase{
7778 name: "WrongMessageType-TLS13-ServerFinished",
7779 config: Config{
7780 MaxVersion: VersionTLS13,
7781 Bugs: ProtocolBugs{
7782 SendWrongMessageType: typeFinished,
7783 },
7784 },
7785 shouldFail: true,
7786 expectedError: ":UNEXPECTED_MESSAGE:",
7787 expectedLocalError: "remote error: unexpected message",
7788 })
7789
7790 testCases = append(testCases, testCase{
7791 testType: serverTest,
7792 name: "WrongMessageType-TLS13-ClientCertificate",
7793 config: Config{
7794 Certificates: []Certificate{rsaCertificate},
7795 MaxVersion: VersionTLS13,
7796 Bugs: ProtocolBugs{
7797 SendWrongMessageType: typeCertificate,
7798 },
7799 },
7800 flags: []string{"-require-any-client-certificate"},
7801 shouldFail: true,
7802 expectedError: ":UNEXPECTED_MESSAGE:",
7803 expectedLocalError: "remote error: unexpected message",
7804 })
7805
7806 testCases = append(testCases, testCase{
7807 testType: serverTest,
7808 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7809 config: Config{
7810 Certificates: []Certificate{rsaCertificate},
7811 MaxVersion: VersionTLS13,
7812 Bugs: ProtocolBugs{
7813 SendWrongMessageType: typeCertificateVerify,
7814 },
7815 },
7816 flags: []string{"-require-any-client-certificate"},
7817 shouldFail: true,
7818 expectedError: ":UNEXPECTED_MESSAGE:",
7819 expectedLocalError: "remote error: unexpected message",
7820 })
7821
7822 testCases = append(testCases, testCase{
7823 testType: serverTest,
7824 name: "WrongMessageType-TLS13-ClientFinished",
7825 config: Config{
7826 MaxVersion: VersionTLS13,
7827 Bugs: ProtocolBugs{
7828 SendWrongMessageType: typeFinished,
7829 },
7830 },
7831 shouldFail: true,
7832 expectedError: ":UNEXPECTED_MESSAGE:",
7833 expectedLocalError: "remote error: unexpected message",
7834 })
7835}
7836
7837func addTLS13HandshakeTests() {
7838 testCases = append(testCases, testCase{
7839 testType: clientTest,
7840 name: "MissingKeyShare-Client",
7841 config: Config{
7842 MaxVersion: VersionTLS13,
7843 Bugs: ProtocolBugs{
7844 MissingKeyShare: true,
7845 },
7846 },
7847 shouldFail: true,
7848 expectedError: ":MISSING_KEY_SHARE:",
7849 })
7850
7851 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007852 testType: serverTest,
7853 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007854 config: Config{
7855 MaxVersion: VersionTLS13,
7856 Bugs: ProtocolBugs{
7857 MissingKeyShare: true,
7858 },
7859 },
7860 shouldFail: true,
7861 expectedError: ":MISSING_KEY_SHARE:",
7862 })
7863
7864 testCases = append(testCases, testCase{
7865 testType: clientTest,
7866 name: "ClientHelloMissingKeyShare",
7867 config: Config{
7868 MaxVersion: VersionTLS13,
7869 Bugs: ProtocolBugs{
7870 MissingKeyShare: true,
7871 },
7872 },
7873 shouldFail: true,
7874 expectedError: ":MISSING_KEY_SHARE:",
7875 })
7876
7877 testCases = append(testCases, testCase{
7878 testType: clientTest,
7879 name: "MissingKeyShare",
7880 config: Config{
7881 MaxVersion: VersionTLS13,
7882 Bugs: ProtocolBugs{
7883 MissingKeyShare: true,
7884 },
7885 },
7886 shouldFail: true,
7887 expectedError: ":MISSING_KEY_SHARE:",
7888 })
7889
7890 testCases = append(testCases, testCase{
7891 testType: serverTest,
7892 name: "DuplicateKeyShares",
7893 config: Config{
7894 MaxVersion: VersionTLS13,
7895 Bugs: ProtocolBugs{
7896 DuplicateKeyShares: true,
7897 },
7898 },
7899 })
7900
7901 testCases = append(testCases, testCase{
7902 testType: clientTest,
7903 name: "EmptyEncryptedExtensions",
7904 config: Config{
7905 MaxVersion: VersionTLS13,
7906 Bugs: ProtocolBugs{
7907 EmptyEncryptedExtensions: true,
7908 },
7909 },
7910 shouldFail: true,
7911 expectedLocalError: "remote error: error decoding message",
7912 })
7913
7914 testCases = append(testCases, testCase{
7915 testType: clientTest,
7916 name: "EncryptedExtensionsWithKeyShare",
7917 config: Config{
7918 MaxVersion: VersionTLS13,
7919 Bugs: ProtocolBugs{
7920 EncryptedExtensionsWithKeyShare: true,
7921 },
7922 },
7923 shouldFail: true,
7924 expectedLocalError: "remote error: unsupported extension",
7925 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007926
7927 testCases = append(testCases, testCase{
7928 testType: serverTest,
7929 name: "SendHelloRetryRequest",
7930 config: Config{
7931 MaxVersion: VersionTLS13,
7932 // Require a HelloRetryRequest for every curve.
7933 DefaultCurves: []CurveID{},
7934 },
7935 expectedCurveID: CurveX25519,
7936 })
7937
7938 testCases = append(testCases, testCase{
7939 testType: serverTest,
7940 name: "SendHelloRetryRequest-2",
7941 config: Config{
7942 MaxVersion: VersionTLS13,
7943 DefaultCurves: []CurveID{CurveP384},
7944 },
7945 // Although the ClientHello did not predict our preferred curve,
7946 // we always select it whether it is predicted or not.
7947 expectedCurveID: CurveX25519,
7948 })
7949
7950 testCases = append(testCases, testCase{
7951 name: "UnknownCurve-HelloRetryRequest",
7952 config: Config{
7953 MaxVersion: VersionTLS13,
7954 // P-384 requires HelloRetryRequest in BoringSSL.
7955 CurvePreferences: []CurveID{CurveP384},
7956 Bugs: ProtocolBugs{
7957 SendHelloRetryRequestCurve: bogusCurve,
7958 },
7959 },
7960 shouldFail: true,
7961 expectedError: ":WRONG_CURVE:",
7962 })
7963
7964 testCases = append(testCases, testCase{
7965 name: "DisabledCurve-HelloRetryRequest",
7966 config: Config{
7967 MaxVersion: VersionTLS13,
7968 CurvePreferences: []CurveID{CurveP256},
7969 Bugs: ProtocolBugs{
7970 IgnorePeerCurvePreferences: true,
7971 },
7972 },
7973 flags: []string{"-p384-only"},
7974 shouldFail: true,
7975 expectedError: ":WRONG_CURVE:",
7976 })
7977
7978 testCases = append(testCases, testCase{
7979 name: "UnnecessaryHelloRetryRequest",
7980 config: Config{
7981 MaxVersion: VersionTLS13,
7982 Bugs: ProtocolBugs{
7983 UnnecessaryHelloRetryRequest: true,
7984 },
7985 },
7986 shouldFail: true,
7987 expectedError: ":WRONG_CURVE:",
7988 })
7989
7990 testCases = append(testCases, testCase{
7991 name: "SecondHelloRetryRequest",
7992 config: Config{
7993 MaxVersion: VersionTLS13,
7994 // P-384 requires HelloRetryRequest in BoringSSL.
7995 CurvePreferences: []CurveID{CurveP384},
7996 Bugs: ProtocolBugs{
7997 SecondHelloRetryRequest: true,
7998 },
7999 },
8000 shouldFail: true,
8001 expectedError: ":UNEXPECTED_MESSAGE:",
8002 })
8003
8004 testCases = append(testCases, testCase{
8005 testType: serverTest,
8006 name: "SecondClientHelloMissingKeyShare",
8007 config: Config{
8008 MaxVersion: VersionTLS13,
8009 DefaultCurves: []CurveID{},
8010 Bugs: ProtocolBugs{
8011 SecondClientHelloMissingKeyShare: true,
8012 },
8013 },
8014 shouldFail: true,
8015 expectedError: ":MISSING_KEY_SHARE:",
8016 })
8017
8018 testCases = append(testCases, testCase{
8019 testType: serverTest,
8020 name: "SecondClientHelloWrongCurve",
8021 config: Config{
8022 MaxVersion: VersionTLS13,
8023 DefaultCurves: []CurveID{},
8024 Bugs: ProtocolBugs{
8025 MisinterpretHelloRetryRequestCurve: CurveP521,
8026 },
8027 },
8028 shouldFail: true,
8029 expectedError: ":WRONG_CURVE:",
8030 })
8031
8032 testCases = append(testCases, testCase{
8033 name: "HelloRetryRequestVersionMismatch",
8034 config: Config{
8035 MaxVersion: VersionTLS13,
8036 // P-384 requires HelloRetryRequest in BoringSSL.
8037 CurvePreferences: []CurveID{CurveP384},
8038 Bugs: ProtocolBugs{
8039 SendServerHelloVersion: 0x0305,
8040 },
8041 },
8042 shouldFail: true,
8043 expectedError: ":WRONG_VERSION_NUMBER:",
8044 })
8045
8046 testCases = append(testCases, testCase{
8047 name: "HelloRetryRequestCurveMismatch",
8048 config: Config{
8049 MaxVersion: VersionTLS13,
8050 // P-384 requires HelloRetryRequest in BoringSSL.
8051 CurvePreferences: []CurveID{CurveP384},
8052 Bugs: ProtocolBugs{
8053 // Send P-384 (correct) in the HelloRetryRequest.
8054 SendHelloRetryRequestCurve: CurveP384,
8055 // But send P-256 in the ServerHello.
8056 SendCurve: CurveP256,
8057 },
8058 },
8059 shouldFail: true,
8060 expectedError: ":WRONG_CURVE:",
8061 })
8062
8063 // Test the server selecting a curve that requires a HelloRetryRequest
8064 // without sending it.
8065 testCases = append(testCases, testCase{
8066 name: "SkipHelloRetryRequest",
8067 config: Config{
8068 MaxVersion: VersionTLS13,
8069 // P-384 requires HelloRetryRequest in BoringSSL.
8070 CurvePreferences: []CurveID{CurveP384},
8071 Bugs: ProtocolBugs{
8072 SkipHelloRetryRequest: true,
8073 },
8074 },
8075 shouldFail: true,
8076 expectedError: ":WRONG_CURVE:",
8077 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008078
8079 testCases = append(testCases, testCase{
8080 name: "TLS13-RequestContextInHandshake",
8081 config: Config{
8082 MaxVersion: VersionTLS13,
8083 MinVersion: VersionTLS13,
8084 ClientAuth: RequireAnyClientCert,
8085 Bugs: ProtocolBugs{
8086 SendRequestContext: []byte("request context"),
8087 },
8088 },
8089 flags: []string{
8090 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8091 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8092 },
8093 shouldFail: true,
8094 expectedError: ":DECODE_ERROR:",
8095 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008096}
8097
Adam Langley7c803a62015-06-15 15:35:05 -07008098func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008099 defer wg.Done()
8100
8101 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008102 var err error
8103
8104 if *mallocTest < 0 {
8105 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008106 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008107 } else {
8108 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8109 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008110 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008111 if err != nil {
8112 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8113 }
8114 break
8115 }
8116 }
8117 }
Adam Langley95c29f32014-06-20 12:00:00 -07008118 statusChan <- statusMsg{test: test, err: err}
8119 }
8120}
8121
8122type statusMsg struct {
8123 test *testCase
8124 started bool
8125 err error
8126}
8127
David Benjamin5f237bc2015-02-11 17:14:15 -05008128func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008129 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008130
David Benjamin5f237bc2015-02-11 17:14:15 -05008131 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008132 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008133 if !*pipe {
8134 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008135 var erase string
8136 for i := 0; i < lineLen; i++ {
8137 erase += "\b \b"
8138 }
8139 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008140 }
8141
Adam Langley95c29f32014-06-20 12:00:00 -07008142 if msg.started {
8143 started++
8144 } else {
8145 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008146
8147 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008148 if msg.err == errUnimplemented {
8149 if *pipe {
8150 // Print each test instead of a status line.
8151 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8152 }
8153 unimplemented++
8154 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8155 } else {
8156 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8157 failed++
8158 testOutput.addResult(msg.test.name, "FAIL")
8159 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008160 } else {
8161 if *pipe {
8162 // Print each test instead of a status line.
8163 fmt.Printf("PASSED (%s)\n", msg.test.name)
8164 }
8165 testOutput.addResult(msg.test.name, "PASS")
8166 }
Adam Langley95c29f32014-06-20 12:00:00 -07008167 }
8168
David Benjamin5f237bc2015-02-11 17:14:15 -05008169 if !*pipe {
8170 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008171 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008172 lineLen = len(line)
8173 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008174 }
Adam Langley95c29f32014-06-20 12:00:00 -07008175 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008176
8177 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008178}
8179
8180func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008181 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008182 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008183 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008184
Adam Langley7c803a62015-06-15 15:35:05 -07008185 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008186 addCipherSuiteTests()
8187 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008188 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008189 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008190 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008191 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008192 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008193 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008194 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008195 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008196 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008197 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008198 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008199 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008200 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008201 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008202 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008203 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008204 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008205 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008206 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05008207 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008208 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008209 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008210 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008211 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008212 addTLS13WrongMessageTypeTests()
8213 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008214
8215 var wg sync.WaitGroup
8216
Adam Langley7c803a62015-06-15 15:35:05 -07008217 statusChan := make(chan statusMsg, *numWorkers)
8218 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008219 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008220
EKRf71d7ed2016-08-06 13:25:12 -07008221 if len(*shimConfigFile) != 0 {
8222 encoded, err := ioutil.ReadFile(*shimConfigFile)
8223 if err != nil {
8224 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8225 os.Exit(1)
8226 }
8227
8228 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8229 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8230 os.Exit(1)
8231 }
8232 }
8233
David Benjamin025b3d32014-07-01 19:53:04 -04008234 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008235
Adam Langley7c803a62015-06-15 15:35:05 -07008236 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008237 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008238 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008239 }
8240
David Benjamin270f0a72016-03-17 14:41:36 -04008241 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008242 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008243 matched := true
8244 if len(*testToRun) != 0 {
8245 var err error
8246 matched, err = filepath.Match(*testToRun, testCases[i].name)
8247 if err != nil {
8248 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8249 os.Exit(1)
8250 }
8251 }
8252
EKRf71d7ed2016-08-06 13:25:12 -07008253 if !*includeDisabled {
8254 for pattern := range shimConfig.DisabledTests {
8255 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8256 if err != nil {
8257 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8258 os.Exit(1)
8259 }
8260
8261 if isDisabled {
8262 matched = false
8263 break
8264 }
8265 }
8266 }
8267
David Benjamin17e12922016-07-28 18:04:43 -04008268 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008269 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008270 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008271 }
8272 }
David Benjamin17e12922016-07-28 18:04:43 -04008273
David Benjamin270f0a72016-03-17 14:41:36 -04008274 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008275 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008276 os.Exit(1)
8277 }
Adam Langley95c29f32014-06-20 12:00:00 -07008278
8279 close(testChan)
8280 wg.Wait()
8281 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008282 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008283
8284 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008285
8286 if *jsonOutput != "" {
8287 if err := testOutput.writeTo(*jsonOutput); err != nil {
8288 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8289 }
8290 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008291
EKR842ae6c2016-07-27 09:22:05 +02008292 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8293 os.Exit(1)
8294 }
8295
8296 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008297 os.Exit(1)
8298 }
Adam Langley95c29f32014-06-20 12:00:00 -07008299}