blob: c350ac5bbfac6892d2027291cc289f98d0109b31 [file] [log] [blame]
David Benjamind316cba2016-06-02 16:17:39 -04001// 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 Benjaminc895d6b2016-08-11 13:26:41 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
David Benjamind316cba2016-06-02 16:17:39 -040014
Kenny Roote99801b2015-11-06 15:31:15 -080015package runner
Adam Langleyd9e397b2015-01-22 14:27:53 -080016
17import (
18 "bytes"
19 "crypto/ecdsa"
20 "crypto/elliptic"
21 "crypto/x509"
22 "encoding/base64"
David Benjaminc895d6b2016-08-11 13:26:41 -040023 "encoding/json"
Adam Langleyd9e397b2015-01-22 14:27:53 -080024 "encoding/pem"
David Benjaminc895d6b2016-08-11 13:26:41 -040025 "errors"
Adam Langleyd9e397b2015-01-22 14:27:53 -080026 "flag"
27 "fmt"
28 "io"
29 "io/ioutil"
Adam Langleyf4e42722015-06-04 17:45:09 -070030 "math/big"
Adam Langleyd9e397b2015-01-22 14:27:53 -080031 "net"
32 "os"
33 "os/exec"
34 "path"
David Benjaminc895d6b2016-08-11 13:26:41 -040035 "path/filepath"
Adam Langleyd9e397b2015-01-22 14:27:53 -080036 "runtime"
37 "strconv"
38 "strings"
39 "sync"
40 "syscall"
Adam Langleye9ada862015-05-11 17:20:37 -070041 "time"
Adam Langleyd9e397b2015-01-22 14:27:53 -080042)
43
44var (
David Benjaminc895d6b2016-08-11 13:26:41 -040045 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.")
53 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
54 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.")
62 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
63 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.")
65)
66
67// 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
85type testCert int
86
87const (
88 testCertRSA testCert = iota
89 testCertRSA1024
90 testCertECDSAP256
91 testCertECDSAP384
92 testCertECDSAP521
Adam Langleyd9e397b2015-01-22 14:27:53 -080093)
94
95const (
David Benjaminc895d6b2016-08-11 13:26:41 -040096 rsaCertificateFile = "cert.pem"
97 rsa1024CertificateFile = "rsa_1024_cert.pem"
98 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
99 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
100 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
Adam Langleyd9e397b2015-01-22 14:27:53 -0800101)
102
103const (
104 rsaKeyFile = "key.pem"
David Benjaminc895d6b2016-08-11 13:26:41 -0400105 rsa1024KeyFile = "rsa_1024_key.pem"
106 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
107 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
108 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
Adam Langleyd9e397b2015-01-22 14:27:53 -0800109 channelIDKeyFile = "channel_id_key.pem"
110)
111
David Benjaminc895d6b2016-08-11 13:26:41 -0400112var (
113 rsaCertificate Certificate
114 rsa1024Certificate Certificate
115 ecdsaP256Certificate Certificate
116 ecdsaP384Certificate Certificate
117 ecdsaP521Certificate Certificate
118)
119
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 {
132 id: testCertRSA1024,
133 certFile: rsa1024CertificateFile,
134 keyFile: rsa1024KeyFile,
135 cert: &rsa1024Certificate,
136 },
137 {
138 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
Adam Langleyd9e397b2015-01-22 14:27:53 -0800157var channelIDKey *ecdsa.PrivateKey
158var channelIDBytes []byte
159
160var testOCSPResponse = []byte{1, 2, 3, 4}
161var testSCTList = []byte{5, 6, 7, 8}
162
163func initCertificates() {
David Benjaminc895d6b2016-08-11 13:26:41 -0400164 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 Langleyd9e397b2015-01-22 14:27:53 -0800172 }
Adam Langleyd9e397b2015-01-22 14:27:53 -0800173
Kenny Rootb8494592015-09-25 02:29:14 +0000174 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
Adam Langleyd9e397b2015-01-22 14:27:53 -0800175 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)
193}
194
David Benjaminc895d6b2016-08-11 13:26:41 -0400195func 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 Langleyd9e397b2015-01-22 14:27:53 -0800202}
203
David Benjaminc895d6b2016-08-11 13:26:41 -0400204func 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 Langleyd9e397b2015-01-22 14:27:53 -0800220}
221
222type testType int
223
224const (
225 clientTest testType = iota
226 serverTest
227)
228
229type protocol int
230
231const (
232 tls protocol = iota
233 dtls
234)
235
236const (
237 alpn = 1
238 npn = 2
239)
240
241type testCase struct {
242 testType testType
243 protocol protocol
244 name string
245 config Config
246 shouldFail bool
247 expectedError string
248 // expectedLocalError, if not empty, contains a substring that must be
249 // found in the local error.
250 expectedLocalError string
251 // expectedVersion, if non-zero, specifies the TLS version that must be
252 // negotiated.
253 expectedVersion uint16
254 // expectedResumeVersion, if non-zero, specifies the TLS version that
255 // must be negotiated on resumption. If zero, expectedVersion is used.
256 expectedResumeVersion uint16
Adam Langleye9ada862015-05-11 17:20:37 -0700257 // expectedCipher, if non-zero, specifies the TLS cipher suite that
258 // should be negotiated.
259 expectedCipher uint16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800260 // expectChannelID controls whether the connection should have
261 // negotiated a Channel ID with channelIDKey.
262 expectChannelID bool
263 // expectedNextProto controls whether the connection should
264 // negotiate a next protocol via NPN or ALPN.
265 expectedNextProto string
Kenny Roote99801b2015-11-06 15:31:15 -0800266 // expectNoNextProto, if true, means that no next protocol should be
267 // negotiated.
268 expectNoNextProto bool
Adam Langleyd9e397b2015-01-22 14:27:53 -0800269 // expectedNextProtoType, if non-zero, is the expected next
270 // protocol negotiation mechanism.
271 expectedNextProtoType int
272 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
273 // should be negotiated. If zero, none should be negotiated.
274 expectedSRTPProtectionProfile uint16
Kenny Rootb8494592015-09-25 02:29:14 +0000275 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
276 expectedOCSPResponse []uint8
277 // expectedSCTList, if not nil, is the expected SCT list to be received.
278 expectedSCTList []uint8
David Benjaminc895d6b2016-08-11 13:26:41 -0400279 // expectedPeerSignatureAlgorithm, if not zero, is the signature
280 // algorithm that the peer should have used in the handshake.
281 expectedPeerSignatureAlgorithm signatureAlgorithm
282 // expectedCurveID, if not zero, is the curve that the handshake should
283 // have used.
284 expectedCurveID CurveID
Adam Langleyd9e397b2015-01-22 14:27:53 -0800285 // messageLen is the length, in bytes, of the test message that will be
286 // sent.
287 messageLen int
Kenny Rootb8494592015-09-25 02:29:14 +0000288 // messageCount is the number of test messages that will be sent.
289 messageCount int
Adam Langleyd9e397b2015-01-22 14:27:53 -0800290 // 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
294 // resumeSession controls whether a second connection should be tested
295 // which attempts to resume the first session.
296 resumeSession bool
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400297 // resumeRenewedSession controls whether a third connection should be
298 // tested which attempts to resume the second connection's session.
299 resumeRenewedSession bool
Adam Langleyf4e42722015-06-04 17:45:09 -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
Adam Langleyd9e397b2015-01-22 14:27:53 -0800304 // resumeConfig, if not nil, points to a Config to be used on
305 // 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.
309 resumeConfig *Config
310 // newSessionsOnResume, if true, will cause resumeConfig to
311 // use a different session resumption context.
312 newSessionsOnResume bool
Kenny Rootb8494592015-09-25 02:29:14 +0000313 // noSessionCache, if true, will cause the server to run without a
314 // session cache.
315 noSessionCache bool
Adam Langleyd9e397b2015-01-22 14:27:53 -0800316 // sendPrefix sends a prefix on the socket before actually performing a
317 // handshake.
318 sendPrefix string
319 // shimWritesFirst controls whether the shim sends an initial "hello"
320 // message before doing a roundtrip with the runner.
321 shimWritesFirst bool
Kenny Rootb8494592015-09-25 02:29:14 +0000322 // 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
Kenny Roote99801b2015-11-06 15:31:15 -0800326 // renegotiate indicates the number of times the connection should be
327 // renegotiated during the exchange.
328 renegotiate int
David Benjaminc895d6b2016-08-11 13:26:41 -0400329 // sendHalfHelloRequest, if true, causes the server to send half a
330 // HelloRequest when the handshake completes.
331 sendHalfHelloRequest bool
Adam Langleyd9e397b2015-01-22 14:27:53 -0800332 // renegotiateCiphers is a list of ciphersuite ids that will be
333 // switched in just before renegotiation.
334 renegotiateCiphers []uint16
335 // replayWrites, if true, configures the underlying transport
336 // to replay every write it makes in DTLS tests.
337 replayWrites bool
338 // damageFirstWrite, if true, configures the underlying transport to
339 // damage the final byte of the first application data write.
340 damageFirstWrite bool
Adam Langleye9ada862015-05-11 17:20:37 -0700341 // 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
Adam Langleyd9e397b2015-01-22 14:27:53 -0800347 // flags, if not empty, contains a list of command-line flags that will
348 // be passed to the shim program.
349 flags []string
Adam Langleyf4e42722015-06-04 17:45:09 -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
Kenny Rootb8494592015-09-25 02:29:14 +0000353 // sendEmptyRecords is the number of consecutive empty records to send
354 // before and after the test message.
355 sendEmptyRecords int
356 // sendWarningAlerts is the number of consecutive warning alerts to send
357 // before and after the test message.
358 sendWarningAlerts int
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400359 // sendKeyUpdates is the number of consecutive key updates to send
360 // before and after the test message.
361 sendKeyUpdates int
Kenny Rootb8494592015-09-25 02:29:14 +0000362 // expectMessageDropped, if true, means the test message is expected to
363 // be dropped by the client rather than echoed back.
364 expectMessageDropped bool
Adam Langleyd9e397b2015-01-22 14:27:53 -0800365}
366
Kenny Rootb8494592015-09-25 02:29:14 +0000367var testCases []testCase
Adam Langleyd9e397b2015-01-22 14:27:53 -0800368
David Benjamin4969cc92016-04-22 15:02:23 -0400369func 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
402// 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
Kenny Rootb8494592015-09-25 02:29:14 +0000422func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjaminf0c4a6c2016-08-11 13:26:41 -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 }
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400445
David Benjamin6e899c72016-06-09 18:02:18 -0400446 conn = &timeoutConn{conn, *idleTimeout}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800447
448 if test.protocol == dtls {
Adam Langleye9ada862015-05-11 17:20:37 -0700449 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
450 conn = config.Bugs.PacketAdaptor
Adam Langleyfad63272015-11-12 12:15:39 -0800451 }
452
David Benjamin4969cc92016-04-22 15:02:23 -0400453 if *flagDebug || len(*transcriptDir) != 0 {
Adam Langleyfad63272015-11-12 12:15:39 -0800454 local, peer := "client", "server"
455 if test.testType == clientTest {
456 local, peer = peer, local
Adam Langleyd9e397b2015-01-22 14:27:53 -0800457 }
Adam Langleyfad63272015-11-12 12:15:39 -0800458 connDebug := &recordingConn{
459 Conn: conn,
460 isDatagram: test.protocol == dtls,
461 local: local,
462 peer: peer,
463 }
464 conn = connDebug
David Benjamin4969cc92016-04-22 15:02:23 -0400465 if *flagDebug {
466 defer connDebug.WriteTo(os.Stdout)
467 }
468 if len(*transcriptDir) != 0 {
469 defer func() {
470 writeTranscript(test, isResume, connDebug.Transcript())
471 }()
472 }
Adam Langleyfad63272015-11-12 12:15:39 -0800473
474 if config.Bugs.PacketAdaptor != nil {
475 config.Bugs.PacketAdaptor.debug = connDebug
476 }
477 }
478
479 if test.replayWrites {
480 conn = newReplayAdaptor(conn)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800481 }
482
David Benjamin4969cc92016-04-22 15:02:23 -0400483 var connDamage *damageAdaptor
Adam Langleyd9e397b2015-01-22 14:27:53 -0800484 if test.damageFirstWrite {
485 connDamage = newDamageAdaptor(conn)
486 conn = connDamage
487 }
488
489 if test.sendPrefix != "" {
490 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
491 return err
492 }
493 }
494
495 var tlsConn *Conn
496 if test.testType == clientTest {
497 if test.protocol == dtls {
498 tlsConn = DTLSServer(conn, config)
499 } else {
500 tlsConn = Server(conn, config)
501 }
502 } else {
503 config.InsecureSkipVerify = true
504 if test.protocol == dtls {
505 tlsConn = DTLSClient(conn, config)
506 } else {
507 tlsConn = Client(conn, config)
508 }
509 }
Kenny Rootb8494592015-09-25 02:29:14 +0000510 defer tlsConn.Close()
Adam Langleyd9e397b2015-01-22 14:27:53 -0800511
512 if err := tlsConn.Handshake(); err != nil {
513 return err
514 }
515
516 // TODO(davidben): move all per-connection expectations into a dedicated
517 // expectations struct that can be specified separately for the two
518 // legs.
519 expectedVersion := test.expectedVersion
520 if isResume && test.expectedResumeVersion != 0 {
521 expectedVersion = test.expectedResumeVersion
522 }
Adam Langleyf4e42722015-06-04 17:45:09 -0700523 connState := tlsConn.ConnectionState()
524 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
Adam Langleyd9e397b2015-01-22 14:27:53 -0800525 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
526 }
527
Adam Langleyf4e42722015-06-04 17:45:09 -0700528 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
Adam Langleye9ada862015-05-11 17:20:37 -0700529 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
530 }
Adam Langleyf4e42722015-06-04 17:45:09 -0700531 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
532 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
533 }
Adam Langleye9ada862015-05-11 17:20:37 -0700534
Adam Langleyd9e397b2015-01-22 14:27:53 -0800535 if test.expectChannelID {
Adam Langleyf4e42722015-06-04 17:45:09 -0700536 channelID := connState.ChannelID
Adam Langleyd9e397b2015-01-22 14:27:53 -0800537 if channelID == nil {
538 return fmt.Errorf("no channel ID negotiated")
539 }
540 if channelID.Curve != channelIDKey.Curve ||
541 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
542 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
543 return fmt.Errorf("incorrect channel ID")
544 }
545 }
546
547 if expected := test.expectedNextProto; expected != "" {
Adam Langleyf4e42722015-06-04 17:45:09 -0700548 if actual := connState.NegotiatedProtocol; actual != expected {
Adam Langleyd9e397b2015-01-22 14:27:53 -0800549 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
550 }
551 }
552
Kenny Roote99801b2015-11-06 15:31:15 -0800553 if test.expectNoNextProto {
554 if actual := connState.NegotiatedProtocol; actual != "" {
555 return fmt.Errorf("got unexpected next proto %s", actual)
556 }
557 }
558
Adam Langleyd9e397b2015-01-22 14:27:53 -0800559 if test.expectedNextProtoType != 0 {
Adam Langleyf4e42722015-06-04 17:45:09 -0700560 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
Adam Langleyd9e397b2015-01-22 14:27:53 -0800561 return fmt.Errorf("next proto type mismatch")
562 }
563 }
564
Adam Langleyf4e42722015-06-04 17:45:09 -0700565 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
Adam Langleyd9e397b2015-01-22 14:27:53 -0800566 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
567 }
568
Kenny Rootb8494592015-09-25 02:29:14 +0000569 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400570 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Kenny Rootb8494592015-09-25 02:29:14 +0000571 }
572
573 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
574 return fmt.Errorf("SCT list mismatch")
575 }
576
David Benjaminc895d6b2016-08-11 13:26:41 -0400577 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
578 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
579 }
580
581 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
582 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
Kenny Rootb8494592015-09-25 02:29:14 +0000583 }
584
Adam Langleye9ada862015-05-11 17:20:37 -0700585 if test.exportKeyingMaterial > 0 {
586 actual := make([]byte, test.exportKeyingMaterial)
587 if _, err := io.ReadFull(tlsConn, actual); err != nil {
588 return err
589 }
590 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
591 if err != nil {
592 return err
593 }
594 if !bytes.Equal(actual, expected) {
595 return fmt.Errorf("keying material mismatch")
596 }
597 }
598
Adam Langleyf4e42722015-06-04 17:45:09 -0700599 if test.testTLSUnique {
600 var peersValue [12]byte
601 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
602 return err
603 }
604 expected := tlsConn.ConnectionState().TLSUnique
605 if !bytes.Equal(peersValue[:], expected) {
606 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
607 }
608 }
609
Adam Langleyd9e397b2015-01-22 14:27:53 -0800610 if test.shimWritesFirst {
611 var buf [5]byte
612 _, err := io.ReadFull(tlsConn, buf[:])
613 if err != nil {
614 return err
615 }
616 if string(buf[:]) != "hello" {
617 return fmt.Errorf("bad initial message")
618 }
619 }
620
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400621 for i := 0; i < test.sendKeyUpdates; i++ {
622 tlsConn.SendKeyUpdate()
623 }
624
Kenny Rootb8494592015-09-25 02:29:14 +0000625 for i := 0; i < test.sendEmptyRecords; i++ {
626 tlsConn.Write(nil)
627 }
628
629 for i := 0; i < test.sendWarningAlerts; i++ {
630 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
631 }
632
David Benjaminc895d6b2016-08-11 13:26:41 -0400633 if test.sendHalfHelloRequest {
634 tlsConn.SendHalfHelloRequest()
635 }
636
Kenny Roote99801b2015-11-06 15:31:15 -0800637 if test.renegotiate > 0 {
Adam Langleyd9e397b2015-01-22 14:27:53 -0800638 if test.renegotiateCiphers != nil {
639 config.CipherSuites = test.renegotiateCiphers
640 }
Kenny Roote99801b2015-11-06 15:31:15 -0800641 for i := 0; i < test.renegotiate; i++ {
642 if err := tlsConn.Renegotiate(); err != nil {
643 return err
644 }
Adam Langleyd9e397b2015-01-22 14:27:53 -0800645 }
646 } else if test.renegotiateCiphers != nil {
647 panic("renegotiateCiphers without renegotiate")
648 }
649
650 if test.damageFirstWrite {
651 connDamage.setDamage(true)
652 tlsConn.Write([]byte("DAMAGED WRITE"))
653 connDamage.setDamage(false)
654 }
655
Kenny Rootb8494592015-09-25 02:29:14 +0000656 messageLen := test.messageLen
Adam Langleyd9e397b2015-01-22 14:27:53 -0800657 if messageLen < 0 {
658 if test.protocol == dtls {
659 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
660 }
661 // Read until EOF.
662 _, err := io.Copy(ioutil.Discard, tlsConn)
663 return err
664 }
Adam Langleye9ada862015-05-11 17:20:37 -0700665 if messageLen == 0 {
666 messageLen = 32
Adam Langleyd9e397b2015-01-22 14:27:53 -0800667 }
668
Kenny Rootb8494592015-09-25 02:29:14 +0000669 messageCount := test.messageCount
670 if messageCount == 0 {
671 messageCount = 1
Adam Langleyd9e397b2015-01-22 14:27:53 -0800672 }
673
Kenny Rootb8494592015-09-25 02:29:14 +0000674 for j := 0; j < messageCount; j++ {
675 testMessage := make([]byte, messageLen)
676 for i := range testMessage {
677 testMessage[i] = 0x42 ^ byte(j)
678 }
679 tlsConn.Write(testMessage)
680
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400681 for i := 0; i < test.sendKeyUpdates; i++ {
682 tlsConn.SendKeyUpdate()
683 }
684
Kenny Rootb8494592015-09-25 02:29:14 +0000685 for i := 0; i < test.sendEmptyRecords; i++ {
686 tlsConn.Write(nil)
687 }
688
689 for i := 0; i < test.sendWarningAlerts; i++ {
690 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
691 }
692
693 if test.shimShutsDown || test.expectMessageDropped {
694 // The shim will not respond.
695 continue
696 }
697
698 buf := make([]byte, len(testMessage))
699 if test.protocol == dtls {
700 bufTmp := make([]byte, len(buf)+1)
701 n, err := tlsConn.Read(bufTmp)
702 if err != nil {
703 return err
704 }
705 if n != len(buf) {
706 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
707 }
708 copy(buf, bufTmp)
709 } else {
710 _, err := io.ReadFull(tlsConn, buf)
711 if err != nil {
712 return err
713 }
714 }
715
716 for i, v := range buf {
717 if v != testMessage[i]^0xff {
718 return fmt.Errorf("bad reply contents at byte %d", i)
719 }
Adam Langleyd9e397b2015-01-22 14:27:53 -0800720 }
721 }
722
723 return nil
724}
725
726func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamin7c0d06c2016-08-11 13:26:41 -0400727 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800728 if dbAttach {
729 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
730 }
731 valgrindArgs = append(valgrindArgs, path)
732 valgrindArgs = append(valgrindArgs, args...)
733
734 return exec.Command("valgrind", valgrindArgs...)
735}
736
737func gdbOf(path string, args ...string) *exec.Cmd {
738 xtermArgs := []string{"-e", "gdb", "--args"}
739 xtermArgs = append(xtermArgs, path)
740 xtermArgs = append(xtermArgs, args...)
741
742 return exec.Command("xterm", xtermArgs...)
743}
744
Adam Langley4139edb2016-01-13 15:00:54 -0800745func lldbOf(path string, args ...string) *exec.Cmd {
746 xtermArgs := []string{"-e", "lldb", "--"}
747 xtermArgs = append(xtermArgs, path)
748 xtermArgs = append(xtermArgs, args...)
749
750 return exec.Command("xterm", xtermArgs...)
751}
752
David Benjaminc895d6b2016-08-11 13:26:41 -0400753var (
754 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
755 errUnimplemented = errors.New("child process does not implement needed flags")
756)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800757
Adam Langleye9ada862015-05-11 17:20:37 -0700758// accept accepts a connection from listener, unless waitChan signals a process
759// exit first.
760func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
761 type connOrError struct {
762 conn net.Conn
763 err error
764 }
765 connChan := make(chan connOrError, 1)
766 go func() {
767 conn, err := listener.Accept()
768 connChan <- connOrError{conn, err}
769 close(connChan)
770 }()
771 select {
772 case result := <-connChan:
773 return result.conn, result.err
774 case childErr := <-waitChan:
775 waitChan <- childErr
776 return nil, fmt.Errorf("child exited early: %s", childErr)
777 }
778}
779
David Benjaminc895d6b2016-08-11 13:26:41 -0400780func translateExpectedError(errorStr string) string {
781 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
782 return translated
783 }
784
785 if *looseErrors {
786 return ""
787 }
788
789 return errorStr
790}
791
Kenny Rootb8494592015-09-25 02:29:14 +0000792func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langleyd9e397b2015-01-22 14:27:53 -0800793 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
794 panic("Error expected without shouldFail in " + test.name)
795 }
796
Adam Langleyf4e42722015-06-04 17:45:09 -0700797 if test.expectResumeRejected && !test.resumeSession {
798 panic("expectResumeRejected without resumeSession in " + test.name)
799 }
800
Adam Langleye9ada862015-05-11 17:20:37 -0700801 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
802 if err != nil {
803 panic(err)
804 }
805 defer func() {
806 if listener != nil {
807 listener.Close()
808 }
809 }()
Adam Langleyd9e397b2015-01-22 14:27:53 -0800810
Adam Langleye9ada862015-05-11 17:20:37 -0700811 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800812 if test.testType == serverTest {
813 flags = append(flags, "-server")
814
815 flags = append(flags, "-key-file")
816 if test.keyFile == "" {
Kenny Rootb8494592015-09-25 02:29:14 +0000817 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
Adam Langleyd9e397b2015-01-22 14:27:53 -0800818 } else {
Kenny Rootb8494592015-09-25 02:29:14 +0000819 flags = append(flags, path.Join(*resourceDir, test.keyFile))
Adam Langleyd9e397b2015-01-22 14:27:53 -0800820 }
821
822 flags = append(flags, "-cert-file")
823 if test.certFile == "" {
Kenny Rootb8494592015-09-25 02:29:14 +0000824 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
Adam Langleyd9e397b2015-01-22 14:27:53 -0800825 } else {
Kenny Rootb8494592015-09-25 02:29:14 +0000826 flags = append(flags, path.Join(*resourceDir, test.certFile))
Adam Langleyd9e397b2015-01-22 14:27:53 -0800827 }
828 }
829
830 if test.protocol == dtls {
831 flags = append(flags, "-dtls")
832 }
833
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400834 var resumeCount int
Adam Langleyd9e397b2015-01-22 14:27:53 -0800835 if test.resumeSession {
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400836 resumeCount++
837 if test.resumeRenewedSession {
838 resumeCount++
839 }
840 }
841
842 if resumeCount > 0 {
843 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
Adam Langleyd9e397b2015-01-22 14:27:53 -0800844 }
845
846 if test.shimWritesFirst {
847 flags = append(flags, "-shim-writes-first")
848 }
849
Kenny Rootb8494592015-09-25 02:29:14 +0000850 if test.shimShutsDown {
851 flags = append(flags, "-shim-shuts-down")
852 }
853
Adam Langleye9ada862015-05-11 17:20:37 -0700854 if test.exportKeyingMaterial > 0 {
855 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
856 flags = append(flags, "-export-label", test.exportLabel)
857 flags = append(flags, "-export-context", test.exportContext)
858 if test.useExportContext {
859 flags = append(flags, "-use-export-context")
860 }
861 }
Adam Langleyf4e42722015-06-04 17:45:09 -0700862 if test.expectResumeRejected {
863 flags = append(flags, "-expect-session-miss")
864 }
865
866 if test.testTLSUnique {
867 flags = append(flags, "-tls-unique")
868 }
Adam Langleye9ada862015-05-11 17:20:37 -0700869
Adam Langleyd9e397b2015-01-22 14:27:53 -0800870 flags = append(flags, test.flags...)
871
872 var shim *exec.Cmd
873 if *useValgrind {
Kenny Rootb8494592015-09-25 02:29:14 +0000874 shim = valgrindOf(false, shimPath, flags...)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800875 } else if *useGDB {
Kenny Rootb8494592015-09-25 02:29:14 +0000876 shim = gdbOf(shimPath, flags...)
Adam Langley4139edb2016-01-13 15:00:54 -0800877 } else if *useLLDB {
878 shim = lldbOf(shimPath, flags...)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800879 } else {
Kenny Rootb8494592015-09-25 02:29:14 +0000880 shim = exec.Command(shimPath, flags...)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800881 }
Adam Langleyd9e397b2015-01-22 14:27:53 -0800882 shim.Stdin = os.Stdin
883 var stdoutBuf, stderrBuf bytes.Buffer
884 shim.Stdout = &stdoutBuf
885 shim.Stderr = &stderrBuf
886 if mallocNumToFail >= 0 {
Adam Langleye9ada862015-05-11 17:20:37 -0700887 shim.Env = os.Environ()
888 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langleyd9e397b2015-01-22 14:27:53 -0800889 if *mallocTestDebug {
Kenny Rootb8494592015-09-25 02:29:14 +0000890 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langleyd9e397b2015-01-22 14:27:53 -0800891 }
892 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
893 }
894
895 if err := shim.Start(); err != nil {
896 panic(err)
897 }
Adam Langleye9ada862015-05-11 17:20:37 -0700898 waitChan := make(chan error, 1)
899 go func() { waitChan <- shim.Wait() }()
Adam Langleyd9e397b2015-01-22 14:27:53 -0800900
901 config := test.config
Adam Langleyd9e397b2015-01-22 14:27:53 -0800902
David Benjamin7c0d06c2016-08-11 13:26:41 -0400903 if *deterministic {
904 config.Rand = &deterministicRand{}
905 }
906
Adam Langleye9ada862015-05-11 17:20:37 -0700907 conn, err := acceptOrWait(listener, waitChan)
908 if err == nil {
Kenny Rootb8494592015-09-25 02:29:14 +0000909 err = doExchange(test, &config, conn, false /* not a resumption */)
Adam Langleye9ada862015-05-11 17:20:37 -0700910 conn.Close()
911 }
Adam Langleyd9e397b2015-01-22 14:27:53 -0800912
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400913 for i := 0; err == nil && i < resumeCount; i++ {
Adam Langleyd9e397b2015-01-22 14:27:53 -0800914 var resumeConfig Config
915 if test.resumeConfig != nil {
916 resumeConfig = *test.resumeConfig
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400917 if !test.newSessionsOnResume {
Adam Langleyd9e397b2015-01-22 14:27:53 -0800918 resumeConfig.SessionTicketKey = config.SessionTicketKey
919 resumeConfig.ClientSessionCache = config.ClientSessionCache
920 resumeConfig.ServerSessionCache = config.ServerSessionCache
921 }
David Benjamin6e899c72016-06-09 18:02:18 -0400922 resumeConfig.Rand = config.Rand
Adam Langleyd9e397b2015-01-22 14:27:53 -0800923 } else {
924 resumeConfig = config
925 }
Adam Langleye9ada862015-05-11 17:20:37 -0700926 var connResume net.Conn
927 connResume, err = acceptOrWait(listener, waitChan)
928 if err == nil {
Kenny Rootb8494592015-09-25 02:29:14 +0000929 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
Adam Langleye9ada862015-05-11 17:20:37 -0700930 connResume.Close()
931 }
Adam Langleyd9e397b2015-01-22 14:27:53 -0800932 }
Adam Langleyd9e397b2015-01-22 14:27:53 -0800933
Adam Langleye9ada862015-05-11 17:20:37 -0700934 // Close the listener now. This is to avoid hangs should the shim try to
935 // open more connections than expected.
936 listener.Close()
937 listener = nil
938
939 childErr := <-waitChan
David Benjamin7c0d06c2016-08-11 13:26:41 -0400940 var isValgrindError bool
Adam Langleyd9e397b2015-01-22 14:27:53 -0800941 if exitError, ok := childErr.(*exec.ExitError); ok {
David Benjaminc895d6b2016-08-11 13:26:41 -0400942 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
943 case 88:
Adam Langleyd9e397b2015-01-22 14:27:53 -0800944 return errMoreMallocs
David Benjaminc895d6b2016-08-11 13:26:41 -0400945 case 89:
946 return errUnimplemented
David Benjamin7c0d06c2016-08-11 13:26:41 -0400947 case 99:
948 isValgrindError = true
Adam Langleyd9e397b2015-01-22 14:27:53 -0800949 }
950 }
951
David Benjamin4969cc92016-04-22 15:02:23 -0400952 // Account for Windows line endings.
953 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
954 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
955
956 // Separate the errors from the shim and those from tools like
957 // AddressSanitizer.
958 var extraStderr string
959 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
960 stderr = stderrParts[0]
961 extraStderr = stderrParts[1]
962 }
963
Adam Langleyd9e397b2015-01-22 14:27:53 -0800964 failed := err != nil || childErr != nil
David Benjaminc895d6b2016-08-11 13:26:41 -0400965 expectedError := translateExpectedError(test.expectedError)
966 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
967
Adam Langleyd9e397b2015-01-22 14:27:53 -0800968 localError := "none"
969 if err != nil {
970 localError = err.Error()
971 }
972 if len(test.expectedLocalError) != 0 {
973 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
974 }
975
976 if failed != test.shouldFail || failed && !correctFailure {
977 childError := "none"
978 if childErr != nil {
979 childError = childErr.Error()
980 }
981
982 var msg string
983 switch {
984 case failed && !test.shouldFail:
985 msg = "unexpected failure"
986 case !failed && test.shouldFail:
987 msg = "unexpected success"
988 case failed && !correctFailure:
David Benjaminc895d6b2016-08-11 13:26:41 -0400989 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langleyd9e397b2015-01-22 14:27:53 -0800990 default:
991 panic("internal error")
992 }
993
David Benjamin7c0d06c2016-08-11 13:26:41 -0400994 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800995 }
996
David Benjamin7c0d06c2016-08-11 13:26:41 -0400997 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjamin4969cc92016-04-22 15:02:23 -0400998 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800999 }
1000
David Benjamin7c0d06c2016-08-11 13:26:41 -04001001 if *useValgrind && isValgrindError {
1002 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1003 }
1004
Adam Langleyd9e397b2015-01-22 14:27:53 -08001005 return nil
1006}
1007
1008var tlsVersions = []struct {
1009 name string
1010 version uint16
1011 flag string
1012 hasDTLS bool
1013}{
1014 {"SSL3", VersionSSL30, "-no-ssl3", false},
1015 {"TLS1", VersionTLS10, "-no-tls1", true},
1016 {"TLS11", VersionTLS11, "-no-tls11", false},
1017 {"TLS12", VersionTLS12, "-no-tls12", true},
David Benjaminc895d6b2016-08-11 13:26:41 -04001018 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langleyd9e397b2015-01-22 14:27:53 -08001019}
1020
1021var testCipherSuites = []struct {
1022 name string
1023 id uint16
1024}{
1025 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
1026 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
1027 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
1028 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
1029 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
1030 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
1031 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
1032 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1033 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
1034 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
1035 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1036 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
1037 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
1038 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1039 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
1040 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1041 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
1042 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
1043 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
Adam Langleye9ada862015-05-11 17:20:37 -07001044 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley4139edb2016-01-13 15:00:54 -08001045 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langleyd9e397b2015-01-22 14:27:53 -08001046 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1047 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1048 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
1049 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
1050 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
1051 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
Adam Langleye9ada862015-05-11 17:20:37 -07001052 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley4139edb2016-01-13 15:00:54 -08001053 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
David Benjamind316cba2016-06-02 16:17:39 -04001054 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1055 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1056 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1057 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langleyd9e397b2015-01-22 14:27:53 -08001058 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1059 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley0e6bb1c2015-06-15 13:52:15 -07001060 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1061 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
Adam Langley4139edb2016-01-13 15:00:54 -08001062 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin6e899c72016-06-09 18:02:18 -04001063 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1064 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Kenny Rootb8494592015-09-25 02:29:14 +00001065 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langleyd9e397b2015-01-22 14:27:53 -08001066}
1067
1068func hasComponent(suiteName, component string) bool {
1069 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1070}
1071
1072func isTLS12Only(suiteName string) bool {
1073 return hasComponent(suiteName, "GCM") ||
1074 hasComponent(suiteName, "SHA256") ||
Adam Langleye9ada862015-05-11 17:20:37 -07001075 hasComponent(suiteName, "SHA384") ||
1076 hasComponent(suiteName, "POLY1305")
Adam Langleyd9e397b2015-01-22 14:27:53 -08001077}
1078
David Benjaminc895d6b2016-08-11 13:26:41 -04001079func isTLS13Suite(suiteName string) bool {
1080 // Only AEADs.
1081 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1082 return false
1083 }
1084 // No old CHACHA20_POLY1305.
1085 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1086 return false
1087 }
1088 // Must have ECDHE.
1089 // TODO(davidben,svaldez): Add pure PSK support.
1090 if !hasComponent(suiteName, "ECDHE") {
1091 return false
1092 }
1093 // TODO(davidben,svaldez): Add PSK support.
1094 if hasComponent(suiteName, "PSK") {
1095 return false
1096 }
1097 return true
1098}
1099
Adam Langleyd9e397b2015-01-22 14:27:53 -08001100func isDTLSCipher(suiteName string) bool {
Kenny Rootb8494592015-09-25 02:29:14 +00001101 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
Adam Langleyd9e397b2015-01-22 14:27:53 -08001102}
1103
Adam Langleyf4e42722015-06-04 17:45:09 -07001104func bigFromHex(hex string) *big.Int {
1105 ret, ok := new(big.Int).SetString(hex, 16)
1106 if !ok {
1107 panic("failed to parse hex number 0x" + hex)
1108 }
1109 return ret
1110}
1111
Kenny Rootb8494592015-09-25 02:29:14 +00001112func addBasicTests() {
1113 basicTests := []testCase{
1114 {
Kenny Rootb8494592015-09-25 02:29:14 +00001115 name: "NoFallbackSCSV",
1116 config: Config{
1117 Bugs: ProtocolBugs{
1118 FailIfNotFallbackSCSV: true,
1119 },
1120 },
1121 shouldFail: true,
1122 expectedLocalError: "no fallback SCSV found",
1123 },
1124 {
1125 name: "SendFallbackSCSV",
1126 config: Config{
1127 Bugs: ProtocolBugs{
1128 FailIfNotFallbackSCSV: true,
1129 },
1130 },
1131 flags: []string{"-fallback-scsv"},
1132 },
1133 {
1134 name: "ClientCertificateTypes",
1135 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001136 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001137 ClientAuth: RequestClientCert,
1138 ClientCertificateTypes: []byte{
1139 CertTypeDSSSign,
1140 CertTypeRSASign,
1141 CertTypeECDSASign,
1142 },
1143 },
1144 flags: []string{
1145 "-expect-certificate-types",
1146 base64.StdEncoding.EncodeToString([]byte{
1147 CertTypeDSSSign,
1148 CertTypeRSASign,
1149 CertTypeECDSASign,
1150 }),
1151 },
1152 },
1153 {
Kenny Rootb8494592015-09-25 02:29:14 +00001154 name: "UnauthenticatedECDH",
1155 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001156 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1158 Bugs: ProtocolBugs{
1159 UnauthenticatedECDH: true,
1160 },
1161 },
1162 shouldFail: true,
1163 expectedError: ":UNEXPECTED_MESSAGE:",
1164 },
1165 {
1166 name: "SkipCertificateStatus",
1167 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001168 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001169 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1170 Bugs: ProtocolBugs{
1171 SkipCertificateStatus: true,
1172 },
1173 },
1174 flags: []string{
1175 "-enable-ocsp-stapling",
1176 },
1177 },
1178 {
1179 name: "SkipServerKeyExchange",
1180 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001181 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001182 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1183 Bugs: ProtocolBugs{
1184 SkipServerKeyExchange: true,
1185 },
1186 },
1187 shouldFail: true,
1188 expectedError: ":UNEXPECTED_MESSAGE:",
1189 },
1190 {
Kenny Rootb8494592015-09-25 02:29:14 +00001191 testType: serverTest,
1192 name: "Alert",
1193 config: Config{
1194 Bugs: ProtocolBugs{
1195 SendSpuriousAlert: alertRecordOverflow,
1196 },
1197 },
1198 shouldFail: true,
1199 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1200 },
1201 {
1202 protocol: dtls,
1203 testType: serverTest,
1204 name: "Alert-DTLS",
1205 config: Config{
1206 Bugs: ProtocolBugs{
1207 SendSpuriousAlert: alertRecordOverflow,
1208 },
1209 },
1210 shouldFail: true,
1211 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1212 },
1213 {
1214 testType: serverTest,
1215 name: "FragmentAlert",
1216 config: Config{
1217 Bugs: ProtocolBugs{
1218 FragmentAlert: true,
1219 SendSpuriousAlert: alertRecordOverflow,
1220 },
1221 },
1222 shouldFail: true,
1223 expectedError: ":BAD_ALERT:",
1224 },
1225 {
1226 protocol: dtls,
1227 testType: serverTest,
1228 name: "FragmentAlert-DTLS",
1229 config: Config{
1230 Bugs: ProtocolBugs{
1231 FragmentAlert: true,
1232 SendSpuriousAlert: alertRecordOverflow,
1233 },
1234 },
1235 shouldFail: true,
1236 expectedError: ":BAD_ALERT:",
1237 },
1238 {
1239 testType: serverTest,
David Benjamin4969cc92016-04-22 15:02:23 -04001240 name: "DoubleAlert",
1241 config: Config{
1242 Bugs: ProtocolBugs{
1243 DoubleAlert: true,
1244 SendSpuriousAlert: alertRecordOverflow,
1245 },
1246 },
1247 shouldFail: true,
1248 expectedError: ":BAD_ALERT:",
1249 },
1250 {
1251 protocol: dtls,
1252 testType: serverTest,
1253 name: "DoubleAlert-DTLS",
1254 config: Config{
1255 Bugs: ProtocolBugs{
1256 DoubleAlert: true,
1257 SendSpuriousAlert: alertRecordOverflow,
1258 },
1259 },
1260 shouldFail: true,
1261 expectedError: ":BAD_ALERT:",
1262 },
1263 {
Kenny Rootb8494592015-09-25 02:29:14 +00001264 name: "SkipNewSessionTicket",
1265 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001266 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001267 Bugs: ProtocolBugs{
1268 SkipNewSessionTicket: true,
1269 },
1270 },
1271 shouldFail: true,
Adam Langley4139edb2016-01-13 15:00:54 -08001272 expectedError: ":UNEXPECTED_RECORD:",
Kenny Rootb8494592015-09-25 02:29:14 +00001273 },
1274 {
1275 testType: serverTest,
1276 name: "FallbackSCSV",
1277 config: Config{
1278 MaxVersion: VersionTLS11,
1279 Bugs: ProtocolBugs{
1280 SendFallbackSCSV: true,
1281 },
1282 },
1283 shouldFail: true,
1284 expectedError: ":INAPPROPRIATE_FALLBACK:",
1285 },
1286 {
1287 testType: serverTest,
1288 name: "FallbackSCSV-VersionMatch",
1289 config: Config{
1290 Bugs: ProtocolBugs{
1291 SendFallbackSCSV: true,
1292 },
1293 },
1294 },
1295 {
1296 testType: serverTest,
David Benjaminc895d6b2016-08-11 13:26:41 -04001297 name: "FallbackSCSV-VersionMatch-TLS12",
1298 config: Config{
1299 MaxVersion: VersionTLS12,
1300 Bugs: ProtocolBugs{
1301 SendFallbackSCSV: true,
1302 },
1303 },
1304 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1305 },
1306 {
1307 testType: serverTest,
Kenny Rootb8494592015-09-25 02:29:14 +00001308 name: "FragmentedClientVersion",
1309 config: Config{
1310 Bugs: ProtocolBugs{
1311 MaxHandshakeRecordLength: 1,
1312 FragmentClientVersion: true,
1313 },
1314 },
David Benjaminc895d6b2016-08-11 13:26:41 -04001315 expectedVersion: VersionTLS13,
Kenny Rootb8494592015-09-25 02:29:14 +00001316 },
1317 {
1318 testType: serverTest,
1319 name: "HttpGET",
1320 sendPrefix: "GET / HTTP/1.0\n",
1321 shouldFail: true,
1322 expectedError: ":HTTP_REQUEST:",
1323 },
1324 {
1325 testType: serverTest,
1326 name: "HttpPOST",
1327 sendPrefix: "POST / HTTP/1.0\n",
1328 shouldFail: true,
1329 expectedError: ":HTTP_REQUEST:",
1330 },
1331 {
1332 testType: serverTest,
1333 name: "HttpHEAD",
1334 sendPrefix: "HEAD / HTTP/1.0\n",
1335 shouldFail: true,
1336 expectedError: ":HTTP_REQUEST:",
1337 },
1338 {
1339 testType: serverTest,
1340 name: "HttpPUT",
1341 sendPrefix: "PUT / HTTP/1.0\n",
1342 shouldFail: true,
1343 expectedError: ":HTTP_REQUEST:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "HttpCONNECT",
1348 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1349 shouldFail: true,
1350 expectedError: ":HTTPS_PROXY_REQUEST:",
1351 },
1352 {
1353 testType: serverTest,
1354 name: "Garbage",
1355 sendPrefix: "blah",
1356 shouldFail: true,
1357 expectedError: ":WRONG_VERSION_NUMBER:",
1358 },
1359 {
Kenny Rootb8494592015-09-25 02:29:14 +00001360 name: "RSAEphemeralKey",
1361 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001362 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001363 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1364 Bugs: ProtocolBugs{
1365 RSAEphemeralKey: true,
1366 },
1367 },
1368 shouldFail: true,
1369 expectedError: ":UNEXPECTED_MESSAGE:",
1370 },
1371 {
1372 name: "DisableEverything",
David Benjamind316cba2016-06-02 16:17:39 -04001373 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Kenny Rootb8494592015-09-25 02:29:14 +00001374 shouldFail: true,
1375 expectedError: ":WRONG_SSL_VERSION:",
1376 },
1377 {
1378 protocol: dtls,
1379 name: "DisableEverything-DTLS",
1380 flags: []string{"-no-tls12", "-no-tls1"},
1381 shouldFail: true,
1382 expectedError: ":WRONG_SSL_VERSION:",
1383 },
1384 {
Kenny Rootb8494592015-09-25 02:29:14 +00001385 protocol: dtls,
1386 testType: serverTest,
1387 name: "MTU",
1388 config: Config{
1389 Bugs: ProtocolBugs{
1390 MaxPacketLength: 256,
1391 },
1392 },
1393 flags: []string{"-mtu", "256"},
1394 },
1395 {
1396 protocol: dtls,
1397 testType: serverTest,
1398 name: "MTUExceeded",
1399 config: Config{
1400 Bugs: ProtocolBugs{
1401 MaxPacketLength: 255,
1402 },
1403 },
1404 flags: []string{"-mtu", "256"},
1405 shouldFail: true,
1406 expectedLocalError: "dtls: exceeded maximum packet length",
1407 },
1408 {
1409 name: "CertMismatchRSA",
1410 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001411 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001412 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjaminc895d6b2016-08-11 13:26:41 -04001413 Certificates: []Certificate{ecdsaP256Certificate},
1414 Bugs: ProtocolBugs{
1415 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1416 },
1417 },
1418 shouldFail: true,
1419 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1420 },
1421 {
1422 name: "CertMismatchRSA-TLS13",
1423 config: Config{
1424 MaxVersion: VersionTLS13,
1425 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1426 Certificates: []Certificate{ecdsaP256Certificate},
Kenny Rootb8494592015-09-25 02:29:14 +00001427 Bugs: ProtocolBugs{
1428 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1429 },
1430 },
1431 shouldFail: true,
1432 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1433 },
1434 {
1435 name: "CertMismatchECDSA",
1436 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001437 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001438 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminc895d6b2016-08-11 13:26:41 -04001439 Certificates: []Certificate{rsaCertificate},
1440 Bugs: ProtocolBugs{
1441 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1442 },
1443 },
1444 shouldFail: true,
1445 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1446 },
1447 {
1448 name: "CertMismatchECDSA-TLS13",
1449 config: Config{
1450 MaxVersion: VersionTLS13,
1451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1452 Certificates: []Certificate{rsaCertificate},
Kenny Rootb8494592015-09-25 02:29:14 +00001453 Bugs: ProtocolBugs{
1454 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1455 },
1456 },
1457 shouldFail: true,
1458 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1459 },
1460 {
1461 name: "EmptyCertificateList",
1462 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001463 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001464 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1465 Bugs: ProtocolBugs{
1466 EmptyCertificateList: true,
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":DECODE_ERROR:",
1471 },
1472 {
David Benjaminc895d6b2016-08-11 13:26:41 -04001473 name: "EmptyCertificateList-TLS13",
1474 config: Config{
1475 MaxVersion: VersionTLS13,
1476 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1477 Bugs: ProtocolBugs{
1478 EmptyCertificateList: true,
1479 },
1480 },
1481 shouldFail: true,
1482 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
1483 },
1484 {
Kenny Rootb8494592015-09-25 02:29:14 +00001485 name: "TLSFatalBadPackets",
1486 damageFirstWrite: true,
1487 shouldFail: true,
1488 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1489 },
1490 {
1491 protocol: dtls,
1492 name: "DTLSIgnoreBadPackets",
1493 damageFirstWrite: true,
1494 },
1495 {
1496 protocol: dtls,
1497 name: "DTLSIgnoreBadPackets-Async",
1498 damageFirstWrite: true,
1499 flags: []string{"-async"},
1500 },
1501 {
1502 name: "AppDataBeforeHandshake",
1503 config: Config{
1504 Bugs: ProtocolBugs{
1505 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1506 },
1507 },
1508 shouldFail: true,
1509 expectedError: ":UNEXPECTED_RECORD:",
1510 },
1511 {
1512 name: "AppDataBeforeHandshake-Empty",
1513 config: Config{
1514 Bugs: ProtocolBugs{
1515 AppDataBeforeHandshake: []byte{},
1516 },
1517 },
1518 shouldFail: true,
1519 expectedError: ":UNEXPECTED_RECORD:",
1520 },
1521 {
1522 protocol: dtls,
1523 name: "AppDataBeforeHandshake-DTLS",
1524 config: Config{
1525 Bugs: ProtocolBugs{
1526 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1527 },
1528 },
1529 shouldFail: true,
1530 expectedError: ":UNEXPECTED_RECORD:",
1531 },
1532 {
1533 protocol: dtls,
1534 name: "AppDataBeforeHandshake-DTLS-Empty",
1535 config: Config{
1536 Bugs: ProtocolBugs{
1537 AppDataBeforeHandshake: []byte{},
1538 },
1539 },
1540 shouldFail: true,
1541 expectedError: ":UNEXPECTED_RECORD:",
1542 },
1543 {
1544 name: "AppDataAfterChangeCipherSpec",
1545 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001546 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001547 Bugs: ProtocolBugs{
1548 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1549 },
1550 },
1551 shouldFail: true,
Adam Langley4139edb2016-01-13 15:00:54 -08001552 expectedError: ":UNEXPECTED_RECORD:",
Kenny Rootb8494592015-09-25 02:29:14 +00001553 },
1554 {
1555 name: "AppDataAfterChangeCipherSpec-Empty",
1556 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001557 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001558 Bugs: ProtocolBugs{
1559 AppDataAfterChangeCipherSpec: []byte{},
1560 },
1561 },
1562 shouldFail: true,
Adam Langley4139edb2016-01-13 15:00:54 -08001563 expectedError: ":UNEXPECTED_RECORD:",
Kenny Rootb8494592015-09-25 02:29:14 +00001564 },
1565 {
1566 protocol: dtls,
1567 name: "AppDataAfterChangeCipherSpec-DTLS",
1568 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001569 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001570 Bugs: ProtocolBugs{
1571 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1572 },
1573 },
1574 // BoringSSL's DTLS implementation will drop the out-of-order
1575 // application data.
1576 },
1577 {
1578 protocol: dtls,
1579 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1580 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001581 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001582 Bugs: ProtocolBugs{
1583 AppDataAfterChangeCipherSpec: []byte{},
1584 },
1585 },
1586 // BoringSSL's DTLS implementation will drop the out-of-order
1587 // application data.
1588 },
1589 {
1590 name: "AlertAfterChangeCipherSpec",
1591 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001592 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001593 Bugs: ProtocolBugs{
1594 AlertAfterChangeCipherSpec: alertRecordOverflow,
1595 },
1596 },
1597 shouldFail: true,
1598 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1599 },
1600 {
1601 protocol: dtls,
1602 name: "AlertAfterChangeCipherSpec-DTLS",
1603 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001604 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001605 Bugs: ProtocolBugs{
1606 AlertAfterChangeCipherSpec: alertRecordOverflow,
1607 },
1608 },
1609 shouldFail: true,
1610 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1611 },
1612 {
1613 protocol: dtls,
1614 name: "ReorderHandshakeFragments-Small-DTLS",
1615 config: Config{
1616 Bugs: ProtocolBugs{
1617 ReorderHandshakeFragments: true,
1618 // Small enough that every handshake message is
1619 // fragmented.
1620 MaxHandshakeRecordLength: 2,
1621 },
1622 },
1623 },
1624 {
1625 protocol: dtls,
1626 name: "ReorderHandshakeFragments-Large-DTLS",
1627 config: Config{
1628 Bugs: ProtocolBugs{
1629 ReorderHandshakeFragments: true,
1630 // Large enough that no handshake message is
1631 // fragmented.
1632 MaxHandshakeRecordLength: 2048,
1633 },
1634 },
1635 },
1636 {
1637 protocol: dtls,
1638 name: "MixCompleteMessageWithFragments-DTLS",
1639 config: Config{
1640 Bugs: ProtocolBugs{
1641 ReorderHandshakeFragments: true,
1642 MixCompleteMessageWithFragments: true,
1643 MaxHandshakeRecordLength: 2,
1644 },
1645 },
1646 },
1647 {
1648 name: "SendInvalidRecordType",
1649 config: Config{
1650 Bugs: ProtocolBugs{
1651 SendInvalidRecordType: true,
1652 },
1653 },
1654 shouldFail: true,
1655 expectedError: ":UNEXPECTED_RECORD:",
1656 },
1657 {
1658 protocol: dtls,
1659 name: "SendInvalidRecordType-DTLS",
1660 config: Config{
1661 Bugs: ProtocolBugs{
1662 SendInvalidRecordType: true,
1663 },
1664 },
1665 shouldFail: true,
1666 expectedError: ":UNEXPECTED_RECORD:",
1667 },
1668 {
1669 name: "FalseStart-SkipServerSecondLeg",
1670 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001671 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001672 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1673 NextProtos: []string{"foo"},
1674 Bugs: ProtocolBugs{
1675 SkipNewSessionTicket: true,
1676 SkipChangeCipherSpec: true,
1677 SkipFinished: true,
1678 ExpectFalseStart: true,
1679 },
1680 },
1681 flags: []string{
1682 "-false-start",
1683 "-handshake-never-done",
1684 "-advertise-alpn", "\x03foo",
1685 },
1686 shimWritesFirst: true,
1687 shouldFail: true,
1688 expectedError: ":UNEXPECTED_RECORD:",
1689 },
1690 {
1691 name: "FalseStart-SkipServerSecondLeg-Implicit",
1692 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001693 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001694 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1695 NextProtos: []string{"foo"},
1696 Bugs: ProtocolBugs{
1697 SkipNewSessionTicket: true,
1698 SkipChangeCipherSpec: true,
1699 SkipFinished: true,
1700 },
1701 },
1702 flags: []string{
1703 "-implicit-handshake",
1704 "-false-start",
1705 "-handshake-never-done",
1706 "-advertise-alpn", "\x03foo",
1707 },
1708 shouldFail: true,
1709 expectedError: ":UNEXPECTED_RECORD:",
1710 },
1711 {
1712 testType: serverTest,
1713 name: "FailEarlyCallback",
1714 flags: []string{"-fail-early-callback"},
1715 shouldFail: true,
1716 expectedError: ":CONNECTION_REJECTED:",
David Benjamin7c0d06c2016-08-11 13:26:41 -04001717 expectedLocalError: "remote error: handshake failure",
Kenny Rootb8494592015-09-25 02:29:14 +00001718 },
1719 {
Kenny Rootb8494592015-09-25 02:29:14 +00001720 protocol: dtls,
1721 name: "FragmentMessageTypeMismatch-DTLS",
1722 config: Config{
1723 Bugs: ProtocolBugs{
1724 MaxHandshakeRecordLength: 2,
1725 FragmentMessageTypeMismatch: true,
1726 },
1727 },
1728 shouldFail: true,
1729 expectedError: ":FRAGMENT_MISMATCH:",
1730 },
1731 {
1732 protocol: dtls,
1733 name: "FragmentMessageLengthMismatch-DTLS",
1734 config: Config{
1735 Bugs: ProtocolBugs{
1736 MaxHandshakeRecordLength: 2,
1737 FragmentMessageLengthMismatch: true,
1738 },
1739 },
1740 shouldFail: true,
1741 expectedError: ":FRAGMENT_MISMATCH:",
1742 },
1743 {
1744 protocol: dtls,
1745 name: "SplitFragments-Header-DTLS",
1746 config: Config{
1747 Bugs: ProtocolBugs{
1748 SplitFragments: 2,
1749 },
1750 },
1751 shouldFail: true,
David Benjamin6e899c72016-06-09 18:02:18 -04001752 expectedError: ":BAD_HANDSHAKE_RECORD:",
Kenny Rootb8494592015-09-25 02:29:14 +00001753 },
1754 {
1755 protocol: dtls,
1756 name: "SplitFragments-Boundary-DTLS",
1757 config: Config{
1758 Bugs: ProtocolBugs{
1759 SplitFragments: dtlsRecordHeaderLen,
1760 },
1761 },
1762 shouldFail: true,
David Benjamin6e899c72016-06-09 18:02:18 -04001763 expectedError: ":BAD_HANDSHAKE_RECORD:",
Kenny Rootb8494592015-09-25 02:29:14 +00001764 },
1765 {
1766 protocol: dtls,
1767 name: "SplitFragments-Body-DTLS",
1768 config: Config{
1769 Bugs: ProtocolBugs{
1770 SplitFragments: dtlsRecordHeaderLen + 1,
1771 },
1772 },
1773 shouldFail: true,
David Benjamin6e899c72016-06-09 18:02:18 -04001774 expectedError: ":BAD_HANDSHAKE_RECORD:",
Kenny Rootb8494592015-09-25 02:29:14 +00001775 },
1776 {
1777 protocol: dtls,
1778 name: "SendEmptyFragments-DTLS",
1779 config: Config{
1780 Bugs: ProtocolBugs{
1781 SendEmptyFragments: true,
1782 },
1783 },
1784 },
1785 {
David Benjamin4969cc92016-04-22 15:02:23 -04001786 name: "BadFinished-Client",
1787 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001788 MaxVersion: VersionTLS12,
1789 Bugs: ProtocolBugs{
1790 BadFinished: true,
1791 },
1792 },
1793 shouldFail: true,
1794 expectedError: ":DIGEST_CHECK_FAILED:",
1795 },
1796 {
1797 name: "BadFinished-Client-TLS13",
1798 config: Config{
1799 MaxVersion: VersionTLS13,
David Benjamin4969cc92016-04-22 15:02:23 -04001800 Bugs: ProtocolBugs{
1801 BadFinished: true,
1802 },
1803 },
1804 shouldFail: true,
1805 expectedError: ":DIGEST_CHECK_FAILED:",
1806 },
1807 {
1808 testType: serverTest,
1809 name: "BadFinished-Server",
Kenny Rootb8494592015-09-25 02:29:14 +00001810 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001811 MaxVersion: VersionTLS12,
1812 Bugs: ProtocolBugs{
1813 BadFinished: true,
1814 },
1815 },
1816 shouldFail: true,
1817 expectedError: ":DIGEST_CHECK_FAILED:",
1818 },
1819 {
1820 testType: serverTest,
1821 name: "BadFinished-Server-TLS13",
1822 config: Config{
1823 MaxVersion: VersionTLS13,
Kenny Rootb8494592015-09-25 02:29:14 +00001824 Bugs: ProtocolBugs{
1825 BadFinished: true,
1826 },
1827 },
1828 shouldFail: true,
1829 expectedError: ":DIGEST_CHECK_FAILED:",
1830 },
1831 {
1832 name: "FalseStart-BadFinished",
1833 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001834 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1836 NextProtos: []string{"foo"},
1837 Bugs: ProtocolBugs{
1838 BadFinished: true,
1839 ExpectFalseStart: true,
1840 },
1841 },
1842 flags: []string{
1843 "-false-start",
1844 "-handshake-never-done",
1845 "-advertise-alpn", "\x03foo",
1846 },
1847 shimWritesFirst: true,
1848 shouldFail: true,
1849 expectedError: ":DIGEST_CHECK_FAILED:",
1850 },
1851 {
1852 name: "NoFalseStart-NoALPN",
1853 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001854 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001855 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1856 Bugs: ProtocolBugs{
1857 ExpectFalseStart: true,
1858 AlertBeforeFalseStartTest: alertAccessDenied,
1859 },
1860 },
1861 flags: []string{
1862 "-false-start",
1863 },
1864 shimWritesFirst: true,
1865 shouldFail: true,
1866 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1867 expectedLocalError: "tls: peer did not false start: EOF",
1868 },
1869 {
1870 name: "NoFalseStart-NoAEAD",
1871 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001872 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001873 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1874 NextProtos: []string{"foo"},
1875 Bugs: ProtocolBugs{
1876 ExpectFalseStart: true,
1877 AlertBeforeFalseStartTest: alertAccessDenied,
1878 },
1879 },
1880 flags: []string{
1881 "-false-start",
1882 "-advertise-alpn", "\x03foo",
1883 },
1884 shimWritesFirst: true,
1885 shouldFail: true,
1886 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1887 expectedLocalError: "tls: peer did not false start: EOF",
1888 },
1889 {
1890 name: "NoFalseStart-RSA",
1891 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001892 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001893 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1894 NextProtos: []string{"foo"},
1895 Bugs: ProtocolBugs{
1896 ExpectFalseStart: true,
1897 AlertBeforeFalseStartTest: alertAccessDenied,
1898 },
1899 },
1900 flags: []string{
1901 "-false-start",
1902 "-advertise-alpn", "\x03foo",
1903 },
1904 shimWritesFirst: true,
1905 shouldFail: true,
1906 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1907 expectedLocalError: "tls: peer did not false start: EOF",
1908 },
1909 {
1910 name: "NoFalseStart-DHE_RSA",
1911 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04001912 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00001913 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1914 NextProtos: []string{"foo"},
1915 Bugs: ProtocolBugs{
1916 ExpectFalseStart: true,
1917 AlertBeforeFalseStartTest: alertAccessDenied,
1918 },
1919 },
1920 flags: []string{
1921 "-false-start",
1922 "-advertise-alpn", "\x03foo",
1923 },
1924 shimWritesFirst: true,
1925 shouldFail: true,
1926 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1927 expectedLocalError: "tls: peer did not false start: EOF",
1928 },
1929 {
Kenny Rootb8494592015-09-25 02:29:14 +00001930 protocol: dtls,
1931 name: "SendSplitAlert-Sync",
1932 config: Config{
1933 Bugs: ProtocolBugs{
1934 SendSplitAlert: true,
1935 },
1936 },
1937 },
1938 {
1939 protocol: dtls,
1940 name: "SendSplitAlert-Async",
1941 config: Config{
1942 Bugs: ProtocolBugs{
1943 SendSplitAlert: true,
1944 },
1945 },
1946 flags: []string{"-async"},
1947 },
1948 {
1949 protocol: dtls,
1950 name: "PackDTLSHandshake",
1951 config: Config{
1952 Bugs: ProtocolBugs{
1953 MaxHandshakeRecordLength: 2,
1954 PackHandshakeFragments: 20,
1955 PackHandshakeRecords: 200,
1956 },
1957 },
1958 },
1959 {
Kenny Rootb8494592015-09-25 02:29:14 +00001960 name: "SendEmptyRecords-Pass",
1961 sendEmptyRecords: 32,
1962 },
1963 {
1964 name: "SendEmptyRecords",
1965 sendEmptyRecords: 33,
1966 shouldFail: true,
1967 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1968 },
1969 {
1970 name: "SendEmptyRecords-Async",
1971 sendEmptyRecords: 33,
1972 flags: []string{"-async"},
1973 shouldFail: true,
1974 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1975 },
1976 {
David Benjaminc895d6b2016-08-11 13:26:41 -04001977 name: "SendWarningAlerts-Pass",
1978 config: Config{
1979 MaxVersion: VersionTLS12,
1980 },
Kenny Rootb8494592015-09-25 02:29:14 +00001981 sendWarningAlerts: 4,
1982 },
1983 {
David Benjaminc895d6b2016-08-11 13:26:41 -04001984 protocol: dtls,
1985 name: "SendWarningAlerts-DTLS-Pass",
1986 config: Config{
1987 MaxVersion: VersionTLS12,
1988 },
Kenny Rootb8494592015-09-25 02:29:14 +00001989 sendWarningAlerts: 4,
1990 },
1991 {
David Benjaminc895d6b2016-08-11 13:26:41 -04001992 name: "SendWarningAlerts-TLS13",
1993 config: Config{
1994 MaxVersion: VersionTLS13,
1995 },
1996 sendWarningAlerts: 4,
1997 shouldFail: true,
1998 expectedError: ":BAD_ALERT:",
1999 expectedLocalError: "remote error: error decoding message",
2000 },
2001 {
2002 name: "SendWarningAlerts",
2003 config: Config{
2004 MaxVersion: VersionTLS12,
2005 },
Kenny Rootb8494592015-09-25 02:29:14 +00002006 sendWarningAlerts: 5,
2007 shouldFail: true,
2008 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2009 },
2010 {
David Benjaminc895d6b2016-08-11 13:26:41 -04002011 name: "SendWarningAlerts-Async",
2012 config: Config{
2013 MaxVersion: VersionTLS12,
2014 },
Kenny Rootb8494592015-09-25 02:29:14 +00002015 sendWarningAlerts: 5,
2016 flags: []string{"-async"},
2017 shouldFail: true,
2018 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2019 },
2020 {
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002021 name: "SendKeyUpdates",
2022 config: Config{
2023 MaxVersion: VersionTLS13,
2024 },
2025 sendKeyUpdates: 33,
2026 shouldFail: true,
2027 expectedError: ":TOO_MANY_KEY_UPDATES:",
2028 },
2029 {
Kenny Rootb8494592015-09-25 02:29:14 +00002030 name: "EmptySessionID",
2031 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002032 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00002033 SessionTicketsDisabled: true,
2034 },
2035 noSessionCache: true,
2036 flags: []string{"-expect-no-session"},
2037 },
2038 {
2039 name: "Unclean-Shutdown",
2040 config: Config{
2041 Bugs: ProtocolBugs{
2042 NoCloseNotify: true,
2043 ExpectCloseNotify: true,
2044 },
2045 },
2046 shimShutsDown: true,
2047 flags: []string{"-check-close-notify"},
2048 shouldFail: true,
2049 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2050 },
2051 {
2052 name: "Unclean-Shutdown-Ignored",
2053 config: Config{
2054 Bugs: ProtocolBugs{
2055 NoCloseNotify: true,
2056 },
2057 },
2058 shimShutsDown: true,
2059 },
2060 {
David Benjamind316cba2016-06-02 16:17:39 -04002061 name: "Unclean-Shutdown-Alert",
2062 config: Config{
2063 Bugs: ProtocolBugs{
2064 SendAlertOnShutdown: alertDecompressionFailure,
2065 ExpectCloseNotify: true,
2066 },
2067 },
2068 shimShutsDown: true,
2069 flags: []string{"-check-close-notify"},
2070 shouldFail: true,
2071 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2072 },
2073 {
Kenny Rootb8494592015-09-25 02:29:14 +00002074 name: "LargePlaintext",
2075 config: Config{
2076 Bugs: ProtocolBugs{
2077 SendLargeRecords: true,
2078 },
2079 },
2080 messageLen: maxPlaintext + 1,
2081 shouldFail: true,
2082 expectedError: ":DATA_LENGTH_TOO_LONG:",
2083 },
2084 {
2085 protocol: dtls,
2086 name: "LargePlaintext-DTLS",
2087 config: Config{
2088 Bugs: ProtocolBugs{
2089 SendLargeRecords: true,
2090 },
2091 },
2092 messageLen: maxPlaintext + 1,
2093 shouldFail: true,
2094 expectedError: ":DATA_LENGTH_TOO_LONG:",
2095 },
2096 {
2097 name: "LargeCiphertext",
2098 config: Config{
2099 Bugs: ProtocolBugs{
2100 SendLargeRecords: true,
2101 },
2102 },
2103 messageLen: maxPlaintext * 2,
2104 shouldFail: true,
2105 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2106 },
2107 {
2108 protocol: dtls,
2109 name: "LargeCiphertext-DTLS",
2110 config: Config{
2111 Bugs: ProtocolBugs{
2112 SendLargeRecords: true,
2113 },
2114 },
2115 messageLen: maxPlaintext * 2,
2116 // Unlike the other four cases, DTLS drops records which
2117 // are invalid before authentication, so the connection
2118 // does not fail.
2119 expectMessageDropped: true,
2120 },
Kenny Roote99801b2015-11-06 15:31:15 -08002121 {
David Benjaminc895d6b2016-08-11 13:26:41 -04002122 // In TLS 1.2 and below, empty NewSessionTicket messages
2123 // mean the server changed its mind on sending a ticket.
Kenny Roote99801b2015-11-06 15:31:15 -08002124 name: "SendEmptySessionTicket",
2125 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002126 MaxVersion: VersionTLS12,
Kenny Roote99801b2015-11-06 15:31:15 -08002127 Bugs: ProtocolBugs{
2128 SendEmptySessionTicket: true,
2129 FailIfSessionOffered: true,
2130 },
2131 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002132 flags: []string{"-expect-no-session"},
Kenny Roote99801b2015-11-06 15:31:15 -08002133 },
Adam Langley4139edb2016-01-13 15:00:54 -08002134 {
Adam Langley4139edb2016-01-13 15:00:54 -08002135 name: "BadHelloRequest-1",
2136 renegotiate: 1,
2137 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002138 MaxVersion: VersionTLS12,
Adam Langley4139edb2016-01-13 15:00:54 -08002139 Bugs: ProtocolBugs{
2140 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2141 },
2142 },
2143 flags: []string{
2144 "-renegotiate-freely",
2145 "-expect-total-renegotiations", "1",
2146 },
2147 shouldFail: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04002148 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
Adam Langley4139edb2016-01-13 15:00:54 -08002149 },
2150 {
2151 name: "BadHelloRequest-2",
2152 renegotiate: 1,
2153 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002154 MaxVersion: VersionTLS12,
Adam Langley4139edb2016-01-13 15:00:54 -08002155 Bugs: ProtocolBugs{
2156 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2157 },
2158 },
2159 flags: []string{
2160 "-renegotiate-freely",
2161 "-expect-total-renegotiations", "1",
2162 },
2163 shouldFail: true,
2164 expectedError: ":BAD_HELLO_REQUEST:",
2165 },
David Benjamin4969cc92016-04-22 15:02:23 -04002166 {
2167 testType: serverTest,
2168 name: "SupportTicketsWithSessionID",
2169 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002170 MaxVersion: VersionTLS12,
David Benjamin4969cc92016-04-22 15:02:23 -04002171 SessionTicketsDisabled: true,
2172 },
David Benjaminc895d6b2016-08-11 13:26:41 -04002173 resumeConfig: &Config{
2174 MaxVersion: VersionTLS12,
2175 },
David Benjamin4969cc92016-04-22 15:02:23 -04002176 resumeSession: true,
2177 },
2178 {
David Benjaminc895d6b2016-08-11 13:26:41 -04002179 protocol: dtls,
2180 name: "DTLS-SendExtraFinished",
David Benjamin4969cc92016-04-22 15:02:23 -04002181 config: Config{
David Benjamin4969cc92016-04-22 15:02:23 -04002182 Bugs: ProtocolBugs{
David Benjaminc895d6b2016-08-11 13:26:41 -04002183 SendExtraFinished: true,
David Benjamin4969cc92016-04-22 15:02:23 -04002184 },
2185 },
2186 shouldFail: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04002187 expectedError: ":UNEXPECTED_RECORD:",
2188 },
2189 {
2190 protocol: dtls,
2191 name: "DTLS-SendExtraFinished-Reordered",
2192 config: Config{
2193 Bugs: ProtocolBugs{
2194 MaxHandshakeRecordLength: 2,
2195 ReorderHandshakeFragments: true,
2196 SendExtraFinished: true,
2197 },
2198 },
2199 shouldFail: true,
2200 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4969cc92016-04-22 15:02:23 -04002201 },
2202 {
2203 testType: serverTest,
David Benjaminc895d6b2016-08-11 13:26:41 -04002204 name: "V2ClientHello-EmptyRecordPrefix",
David Benjamin4969cc92016-04-22 15:02:23 -04002205 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002206 // Choose a cipher suite that does not involve
2207 // elliptic curves, so no extensions are
2208 // involved.
2209 MaxVersion: VersionTLS12,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002210 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin4969cc92016-04-22 15:02:23 -04002211 Bugs: ProtocolBugs{
David Benjaminc895d6b2016-08-11 13:26:41 -04002212 SendV2ClientHello: true,
David Benjamin4969cc92016-04-22 15:02:23 -04002213 },
2214 },
David Benjaminc895d6b2016-08-11 13:26:41 -04002215 sendPrefix: string([]byte{
2216 byte(recordTypeHandshake),
2217 3, 1, // version
2218 0, 0, // length
2219 }),
2220 // A no-op empty record may not be sent before V2ClientHello.
David Benjamin4969cc92016-04-22 15:02:23 -04002221 shouldFail: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04002222 expectedError: ":WRONG_VERSION_NUMBER:",
2223 },
2224 {
2225 testType: serverTest,
2226 name: "V2ClientHello-WarningAlertPrefix",
2227 config: Config{
2228 // Choose a cipher suite that does not involve
2229 // elliptic curves, so no extensions are
2230 // involved.
2231 MaxVersion: VersionTLS12,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002232 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminc895d6b2016-08-11 13:26:41 -04002233 Bugs: ProtocolBugs{
2234 SendV2ClientHello: true,
2235 },
2236 },
2237 sendPrefix: string([]byte{
2238 byte(recordTypeAlert),
2239 3, 1, // version
2240 0, 2, // length
2241 alertLevelWarning, byte(alertDecompressionFailure),
2242 }),
2243 // A no-op warning alert may not be sent before V2ClientHello.
2244 shouldFail: true,
2245 expectedError: ":WRONG_VERSION_NUMBER:",
2246 },
2247 {
2248 testType: clientTest,
2249 name: "KeyUpdate",
2250 config: Config{
2251 MaxVersion: VersionTLS13,
2252 Bugs: ProtocolBugs{
2253 SendKeyUpdateBeforeEveryAppDataRecord: true,
2254 },
2255 },
David Benjamin4969cc92016-04-22 15:02:23 -04002256 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002257 {
2258 name: "SendSNIWarningAlert",
2259 config: Config{
2260 MaxVersion: VersionTLS12,
2261 Bugs: ProtocolBugs{
2262 SendSNIWarningAlert: true,
2263 },
2264 },
2265 },
2266 {
2267 testType: serverTest,
2268 name: "ExtraCompressionMethods-TLS12",
2269 config: Config{
2270 MaxVersion: VersionTLS12,
2271 Bugs: ProtocolBugs{
2272 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2273 },
2274 },
2275 },
2276 {
2277 testType: serverTest,
2278 name: "ExtraCompressionMethods-TLS13",
2279 config: Config{
2280 MaxVersion: VersionTLS13,
2281 Bugs: ProtocolBugs{
2282 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2283 },
2284 },
2285 shouldFail: true,
2286 expectedError: ":INVALID_COMPRESSION_LIST:",
2287 expectedLocalError: "remote error: illegal parameter",
2288 },
2289 {
2290 testType: serverTest,
2291 name: "NoNullCompression-TLS12",
2292 config: Config{
2293 MaxVersion: VersionTLS12,
2294 Bugs: ProtocolBugs{
2295 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2296 },
2297 },
2298 shouldFail: true,
2299 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2300 expectedLocalError: "remote error: illegal parameter",
2301 },
2302 {
2303 testType: serverTest,
2304 name: "NoNullCompression-TLS13",
2305 config: Config{
2306 MaxVersion: VersionTLS13,
2307 Bugs: ProtocolBugs{
2308 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2309 },
2310 },
2311 shouldFail: true,
2312 expectedError: ":INVALID_COMPRESSION_LIST:",
2313 expectedLocalError: "remote error: illegal parameter",
2314 },
Kenny Rootb8494592015-09-25 02:29:14 +00002315 }
2316 testCases = append(testCases, basicTests...)
2317}
2318
Adam Langleyd9e397b2015-01-22 14:27:53 -08002319func addCipherSuiteTests() {
David Benjaminc895d6b2016-08-11 13:26:41 -04002320 const bogusCipher = 0xfe00
2321
Adam Langleyd9e397b2015-01-22 14:27:53 -08002322 for _, suite := range testCipherSuites {
2323 const psk = "12345"
2324 const pskIdentity = "luggage combo"
2325
2326 var cert Certificate
2327 var certFile string
2328 var keyFile string
2329 if hasComponent(suite.name, "ECDSA") {
David Benjaminc895d6b2016-08-11 13:26:41 -04002330 cert = ecdsaP256Certificate
2331 certFile = ecdsaP256CertificateFile
2332 keyFile = ecdsaP256KeyFile
Adam Langleyd9e397b2015-01-22 14:27:53 -08002333 } else {
David Benjaminc895d6b2016-08-11 13:26:41 -04002334 cert = rsaCertificate
Adam Langleyd9e397b2015-01-22 14:27:53 -08002335 certFile = rsaCertificateFile
2336 keyFile = rsaKeyFile
2337 }
2338
2339 var flags []string
2340 if hasComponent(suite.name, "PSK") {
2341 flags = append(flags,
2342 "-psk", psk,
2343 "-psk-identity", pskIdentity)
2344 }
Kenny Rootb8494592015-09-25 02:29:14 +00002345 if hasComponent(suite.name, "NULL") {
2346 // NULL ciphers must be explicitly enabled.
2347 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2348 }
David Benjamind316cba2016-06-02 16:17:39 -04002349 if hasComponent(suite.name, "CECPQ1") {
2350 // CECPQ1 ciphers must be explicitly enabled.
2351 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2352 }
David Benjaminc895d6b2016-08-11 13:26:41 -04002353 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2354 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2355 // for now.
2356 flags = append(flags, "-cipher", suite.name)
2357 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08002358
2359 for _, ver := range tlsVersions {
David Benjaminc895d6b2016-08-11 13:26:41 -04002360 for _, protocol := range []protocol{tls, dtls} {
2361 var prefix string
2362 if protocol == dtls {
2363 if !ver.hasDTLS {
2364 continue
2365 }
2366 prefix = "D"
2367 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08002368
David Benjaminc895d6b2016-08-11 13:26:41 -04002369 var shouldServerFail, shouldClientFail bool
2370 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2371 // BoringSSL clients accept ECDHE on SSLv3, but
2372 // a BoringSSL server will never select it
2373 // because the extension is missing.
2374 shouldServerFail = true
2375 }
2376 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2377 shouldClientFail = true
2378 shouldServerFail = true
2379 }
2380 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2381 shouldClientFail = true
2382 shouldServerFail = true
2383 }
2384 if !isDTLSCipher(suite.name) && protocol == dtls {
2385 shouldClientFail = true
2386 shouldServerFail = true
2387 }
Adam Langley4139edb2016-01-13 15:00:54 -08002388
David Benjaminc895d6b2016-08-11 13:26:41 -04002389 var expectedServerError, expectedClientError string
2390 if shouldServerFail {
2391 expectedServerError = ":NO_SHARED_CIPHER:"
2392 }
2393 if shouldClientFail {
2394 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2395 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08002396
Adam Langleyd9e397b2015-01-22 14:27:53 -08002397 testCases = append(testCases, testCase{
2398 testType: serverTest,
David Benjaminc895d6b2016-08-11 13:26:41 -04002399 protocol: protocol,
2400
2401 name: prefix + ver.name + "-" + suite.name + "-server",
Adam Langleyd9e397b2015-01-22 14:27:53 -08002402 config: Config{
2403 MinVersion: ver.version,
2404 MaxVersion: ver.version,
2405 CipherSuites: []uint16{suite.id},
2406 Certificates: []Certificate{cert},
2407 PreSharedKey: []byte(psk),
2408 PreSharedKeyIdentity: pskIdentity,
David Benjaminc895d6b2016-08-11 13:26:41 -04002409 Bugs: ProtocolBugs{
2410 EnableAllCiphers: shouldServerFail,
2411 IgnorePeerCipherPreferences: shouldServerFail,
2412 },
Adam Langleyd9e397b2015-01-22 14:27:53 -08002413 },
2414 certFile: certFile,
2415 keyFile: keyFile,
2416 flags: flags,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002417 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04002418 shouldFail: shouldServerFail,
2419 expectedError: expectedServerError,
Adam Langleyd9e397b2015-01-22 14:27:53 -08002420 })
Kenny Rootb8494592015-09-25 02:29:14 +00002421
David Benjaminc895d6b2016-08-11 13:26:41 -04002422 testCases = append(testCases, testCase{
2423 testType: clientTest,
2424 protocol: protocol,
2425 name: prefix + ver.name + "-" + suite.name + "-client",
2426 config: Config{
2427 MinVersion: ver.version,
2428 MaxVersion: ver.version,
2429 CipherSuites: []uint16{suite.id},
2430 Certificates: []Certificate{cert},
2431 PreSharedKey: []byte(psk),
2432 PreSharedKeyIdentity: pskIdentity,
2433 Bugs: ProtocolBugs{
2434 EnableAllCiphers: shouldClientFail,
2435 IgnorePeerCipherPreferences: shouldClientFail,
2436 },
2437 },
2438 flags: flags,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002439 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04002440 shouldFail: shouldClientFail,
2441 expectedError: expectedClientError,
2442 })
2443
2444 if !shouldClientFail {
2445 // Ensure the maximum record size is accepted.
2446 testCases = append(testCases, testCase{
2447 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2448 config: Config{
2449 MinVersion: ver.version,
2450 MaxVersion: ver.version,
2451 CipherSuites: []uint16{suite.id},
2452 Certificates: []Certificate{cert},
2453 PreSharedKey: []byte(psk),
2454 PreSharedKeyIdentity: pskIdentity,
2455 },
2456 flags: flags,
2457 messageLen: maxPlaintext,
2458 })
2459 }
2460 }
Kenny Rootb8494592015-09-25 02:29:14 +00002461 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08002462 }
Adam Langleyf4e42722015-06-04 17:45:09 -07002463
2464 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04002465 name: "NoSharedCipher",
2466 config: Config{
2467 MaxVersion: VersionTLS12,
2468 CipherSuites: []uint16{},
2469 },
2470 shouldFail: true,
2471 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2472 })
2473
2474 testCases = append(testCases, testCase{
2475 name: "NoSharedCipher-TLS13",
2476 config: Config{
2477 MaxVersion: VersionTLS13,
2478 CipherSuites: []uint16{},
2479 },
2480 shouldFail: true,
2481 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2482 })
2483
2484 testCases = append(testCases, testCase{
2485 name: "UnsupportedCipherSuite",
2486 config: Config{
2487 MaxVersion: VersionTLS12,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002488 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminc895d6b2016-08-11 13:26:41 -04002489 Bugs: ProtocolBugs{
2490 IgnorePeerCipherPreferences: true,
2491 },
2492 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002493 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjaminc895d6b2016-08-11 13:26:41 -04002494 shouldFail: true,
2495 expectedError: ":WRONG_CIPHER_RETURNED:",
2496 })
2497
2498 testCases = append(testCases, testCase{
2499 name: "ServerHelloBogusCipher",
2500 config: Config{
2501 MaxVersion: VersionTLS12,
2502 Bugs: ProtocolBugs{
2503 SendCipherSuite: bogusCipher,
2504 },
2505 },
2506 shouldFail: true,
2507 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2508 })
2509 testCases = append(testCases, testCase{
2510 name: "ServerHelloBogusCipher-TLS13",
2511 config: Config{
2512 MaxVersion: VersionTLS13,
2513 Bugs: ProtocolBugs{
2514 SendCipherSuite: bogusCipher,
2515 },
2516 },
2517 shouldFail: true,
2518 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2519 })
2520
2521 testCases = append(testCases, testCase{
Adam Langleyf4e42722015-06-04 17:45:09 -07002522 name: "WeakDH",
2523 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002524 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07002525 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2526 Bugs: ProtocolBugs{
2527 // This is a 1023-bit prime number, generated
2528 // with:
2529 // openssl gendh 1023 | openssl asn1parse -i
2530 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2531 },
2532 },
2533 shouldFail: true,
Adam Langley4139edb2016-01-13 15:00:54 -08002534 expectedError: ":BAD_DH_P_LENGTH:",
2535 })
2536
2537 testCases = append(testCases, testCase{
2538 name: "SillyDH",
2539 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002540 MaxVersion: VersionTLS12,
Adam Langley4139edb2016-01-13 15:00:54 -08002541 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2542 Bugs: ProtocolBugs{
2543 // This is a 4097-bit prime number, generated
2544 // with:
2545 // openssl gendh 4097 | openssl asn1parse -i
2546 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2547 },
2548 },
2549 shouldFail: true,
2550 expectedError: ":DH_P_TOO_LONG:",
2551 })
2552
2553 // This test ensures that Diffie-Hellman public values are padded with
2554 // zeros so that they're the same length as the prime. This is to avoid
2555 // hitting a bug in yaSSL.
2556 testCases = append(testCases, testCase{
2557 testType: serverTest,
2558 name: "DHPublicValuePadded",
2559 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002560 MaxVersion: VersionTLS12,
Adam Langley4139edb2016-01-13 15:00:54 -08002561 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2562 Bugs: ProtocolBugs{
2563 RequireDHPublicValueLen: (1025 + 7) / 8,
2564 },
2565 },
2566 flags: []string{"-use-sparse-dh-prime"},
Adam Langleyf4e42722015-06-04 17:45:09 -07002567 })
Kenny Rootb8494592015-09-25 02:29:14 +00002568
David Benjamin4969cc92016-04-22 15:02:23 -04002569 // The server must be tolerant to bogus ciphers.
David Benjamin4969cc92016-04-22 15:02:23 -04002570 testCases = append(testCases, testCase{
2571 testType: serverTest,
2572 name: "UnknownCipher",
2573 config: Config{
2574 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2575 },
2576 })
2577
David Benjamin7c0d06c2016-08-11 13:26:41 -04002578 // Test empty ECDHE_PSK identity hints work as expected.
2579 testCases = append(testCases, testCase{
2580 name: "EmptyECDHEPSKHint",
2581 config: Config{
2582 MaxVersion: VersionTLS12,
2583 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2584 PreSharedKey: []byte("secret"),
2585 },
2586 flags: []string{"-psk", "secret"},
2587 })
2588
2589 // Test empty PSK identity hints work as expected, even if an explicit
2590 // ServerKeyExchange is sent.
2591 testCases = append(testCases, testCase{
2592 name: "ExplicitEmptyPSKHint",
2593 config: Config{
2594 MaxVersion: VersionTLS12,
2595 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2596 PreSharedKey: []byte("secret"),
2597 Bugs: ProtocolBugs{
2598 AlwaysSendPreSharedKeyIdentityHint: true,
2599 },
2600 },
2601 flags: []string{"-psk", "secret"},
2602 })
2603
Kenny Rootb8494592015-09-25 02:29:14 +00002604 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2605 // 1.1 specific cipher suite settings. A server is setup with the given
2606 // cipher lists and then a connection is made for each member of
2607 // expectations. The cipher suite that the server selects must match
2608 // the specified one.
2609 var versionSpecificCiphersTest = []struct {
2610 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2611 // expectations is a map from TLS version to cipher suite id.
2612 expectations map[uint16]uint16
2613 }{
2614 {
2615 // Test that the null case (where no version-specific ciphers are set)
2616 // works as expected.
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002617 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2618 "", // no ciphers specifically for TLS ≥ 1.0
2619 "", // no ciphers specifically for TLS ≥ 1.1
Kenny Rootb8494592015-09-25 02:29:14 +00002620 map[uint16]uint16{
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002621 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2622 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2623 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2624 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Kenny Rootb8494592015-09-25 02:29:14 +00002625 },
2626 },
2627 {
2628 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2629 // cipher.
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002630 "DES-CBC3-SHA:AES128-SHA", // default
2631 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2632 "", // no ciphers specifically for TLS ≥ 1.1
Kenny Rootb8494592015-09-25 02:29:14 +00002633 map[uint16]uint16{
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002634 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Kenny Rootb8494592015-09-25 02:29:14 +00002635 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2636 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2637 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2638 },
2639 },
2640 {
2641 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2642 // cipher.
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002643 "DES-CBC3-SHA:AES128-SHA", // default
2644 "", // no ciphers specifically for TLS ≥ 1.0
2645 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Kenny Rootb8494592015-09-25 02:29:14 +00002646 map[uint16]uint16{
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002647 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2648 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Kenny Rootb8494592015-09-25 02:29:14 +00002649 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2650 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2651 },
2652 },
2653 {
2654 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2655 // mask ciphers_tls10 for TLS 1.1 and 1.2.
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002656 "DES-CBC3-SHA:AES128-SHA", // default
2657 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2658 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Kenny Rootb8494592015-09-25 02:29:14 +00002659 map[uint16]uint16{
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002660 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Kenny Rootb8494592015-09-25 02:29:14 +00002661 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2662 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2663 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2664 },
2665 },
2666 }
2667
2668 for i, test := range versionSpecificCiphersTest {
2669 for version, expectedCipherSuite := range test.expectations {
2670 flags := []string{"-cipher", test.ciphersDefault}
2671 if len(test.ciphersTLS10) > 0 {
2672 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2673 }
2674 if len(test.ciphersTLS11) > 0 {
2675 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2676 }
2677
2678 testCases = append(testCases, testCase{
2679 testType: serverTest,
2680 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2681 config: Config{
2682 MaxVersion: version,
2683 MinVersion: version,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002684 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Kenny Rootb8494592015-09-25 02:29:14 +00002685 },
2686 flags: flags,
2687 expectedCipher: expectedCipherSuite,
2688 })
2689 }
2690 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08002691}
2692
2693func addBadECDSASignatureTests() {
2694 for badR := BadValue(1); badR < NumBadValues; badR++ {
2695 for badS := BadValue(1); badS < NumBadValues; badS++ {
2696 testCases = append(testCases, testCase{
2697 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2698 config: Config{
2699 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjaminc895d6b2016-08-11 13:26:41 -04002700 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langleyd9e397b2015-01-22 14:27:53 -08002701 Bugs: ProtocolBugs{
2702 BadECDSAR: badR,
2703 BadECDSAS: badS,
2704 },
2705 },
2706 shouldFail: true,
David Benjamin4969cc92016-04-22 15:02:23 -04002707 expectedError: ":BAD_SIGNATURE:",
Adam Langleyd9e397b2015-01-22 14:27:53 -08002708 })
2709 }
2710 }
2711}
2712
2713func addCBCPaddingTests() {
2714 testCases = append(testCases, testCase{
2715 name: "MaxCBCPadding",
2716 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002717 MaxVersion: VersionTLS12,
Adam Langleyd9e397b2015-01-22 14:27:53 -08002718 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2719 Bugs: ProtocolBugs{
2720 MaxPadding: true,
2721 },
2722 },
2723 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2724 })
2725 testCases = append(testCases, testCase{
2726 name: "BadCBCPadding",
2727 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002728 MaxVersion: VersionTLS12,
Adam Langleyd9e397b2015-01-22 14:27:53 -08002729 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2730 Bugs: ProtocolBugs{
2731 PaddingFirstByteBad: true,
2732 },
2733 },
2734 shouldFail: true,
David Benjamin4969cc92016-04-22 15:02:23 -04002735 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langleyd9e397b2015-01-22 14:27:53 -08002736 })
2737 // OpenSSL previously had an issue where the first byte of padding in
2738 // 255 bytes of padding wasn't checked.
2739 testCases = append(testCases, testCase{
2740 name: "BadCBCPadding255",
2741 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002742 MaxVersion: VersionTLS12,
Adam Langleyd9e397b2015-01-22 14:27:53 -08002743 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2744 Bugs: ProtocolBugs{
2745 MaxPadding: true,
2746 PaddingFirstByteBadIf255: true,
2747 },
2748 },
2749 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2750 shouldFail: true,
David Benjamin4969cc92016-04-22 15:02:23 -04002751 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langleyd9e397b2015-01-22 14:27:53 -08002752 })
2753}
2754
2755func addCBCSplittingTests() {
2756 testCases = append(testCases, testCase{
2757 name: "CBCRecordSplitting",
2758 config: Config{
2759 MaxVersion: VersionTLS10,
2760 MinVersion: VersionTLS10,
2761 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2762 },
Kenny Rootb8494592015-09-25 02:29:14 +00002763 messageLen: -1, // read until EOF
2764 resumeSession: true,
Adam Langleyd9e397b2015-01-22 14:27:53 -08002765 flags: []string{
2766 "-async",
2767 "-write-different-record-sizes",
2768 "-cbc-record-splitting",
2769 },
2770 })
2771 testCases = append(testCases, testCase{
2772 name: "CBCRecordSplittingPartialWrite",
2773 config: Config{
2774 MaxVersion: VersionTLS10,
2775 MinVersion: VersionTLS10,
2776 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2777 },
2778 messageLen: -1, // read until EOF
2779 flags: []string{
2780 "-async",
2781 "-write-different-record-sizes",
2782 "-cbc-record-splitting",
2783 "-partial-write",
2784 },
2785 })
2786}
2787
2788func addClientAuthTests() {
2789 // Add a dummy cert pool to stress certificate authority parsing.
2790 // TODO(davidben): Add tests that those values parse out correctly.
2791 certPool := x509.NewCertPool()
2792 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2793 if err != nil {
2794 panic(err)
2795 }
2796 certPool.AddCert(cert)
2797
2798 for _, ver := range tlsVersions {
2799 testCases = append(testCases, testCase{
2800 testType: clientTest,
2801 name: ver.name + "-Client-ClientAuth-RSA",
2802 config: Config{
2803 MinVersion: ver.version,
2804 MaxVersion: ver.version,
2805 ClientAuth: RequireAnyClientCert,
2806 ClientCAs: certPool,
2807 },
2808 flags: []string{
Kenny Rootb8494592015-09-25 02:29:14 +00002809 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2810 "-key-file", path.Join(*resourceDir, rsaKeyFile),
Adam Langleyd9e397b2015-01-22 14:27:53 -08002811 },
2812 })
2813 testCases = append(testCases, testCase{
2814 testType: serverTest,
2815 name: ver.name + "-Server-ClientAuth-RSA",
2816 config: Config{
2817 MinVersion: ver.version,
2818 MaxVersion: ver.version,
2819 Certificates: []Certificate{rsaCertificate},
2820 },
2821 flags: []string{"-require-any-client-certificate"},
2822 })
2823 if ver.version != VersionSSL30 {
2824 testCases = append(testCases, testCase{
2825 testType: serverTest,
2826 name: ver.name + "-Server-ClientAuth-ECDSA",
2827 config: Config{
2828 MinVersion: ver.version,
2829 MaxVersion: ver.version,
David Benjaminc895d6b2016-08-11 13:26:41 -04002830 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langleyd9e397b2015-01-22 14:27:53 -08002831 },
2832 flags: []string{"-require-any-client-certificate"},
2833 })
2834 testCases = append(testCases, testCase{
2835 testType: clientTest,
2836 name: ver.name + "-Client-ClientAuth-ECDSA",
2837 config: Config{
2838 MinVersion: ver.version,
2839 MaxVersion: ver.version,
2840 ClientAuth: RequireAnyClientCert,
2841 ClientCAs: certPool,
2842 },
2843 flags: []string{
David Benjaminc895d6b2016-08-11 13:26:41 -04002844 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2845 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
Adam Langleyd9e397b2015-01-22 14:27:53 -08002846 },
2847 })
2848 }
David Benjaminf0c4a6c2016-08-11 13:26:41 -04002849
2850 testCases = append(testCases, testCase{
2851 name: "NoClientCertificate-" + ver.name,
2852 config: Config{
2853 MinVersion: ver.version,
2854 MaxVersion: ver.version,
2855 ClientAuth: RequireAnyClientCert,
2856 },
2857 shouldFail: true,
2858 expectedLocalError: "client didn't provide a certificate",
2859 })
2860
2861 testCases = append(testCases, testCase{
2862 // Even if not configured to expect a certificate, OpenSSL will
2863 // return X509_V_OK as the verify_result.
2864 testType: serverTest,
2865 name: "NoClientCertificateRequested-Server-" + ver.name,
2866 config: Config{
2867 MinVersion: ver.version,
2868 MaxVersion: ver.version,
2869 },
2870 flags: []string{
2871 "-expect-verify-result",
2872 },
2873 // TODO(davidben): Switch this to true when TLS 1.3
2874 // supports session resumption.
2875 resumeSession: ver.version < VersionTLS13,
2876 })
2877
2878 testCases = append(testCases, testCase{
2879 // If a client certificate is not provided, OpenSSL will still
2880 // return X509_V_OK as the verify_result.
2881 testType: serverTest,
2882 name: "NoClientCertificate-Server-" + ver.name,
2883 config: Config{
2884 MinVersion: ver.version,
2885 MaxVersion: ver.version,
2886 },
2887 flags: []string{
2888 "-expect-verify-result",
2889 "-verify-peer",
2890 },
2891 // TODO(davidben): Switch this to true when TLS 1.3
2892 // supports session resumption.
2893 resumeSession: ver.version < VersionTLS13,
2894 })
2895
2896 testCases = append(testCases, testCase{
2897 testType: serverTest,
2898 name: "RequireAnyClientCertificate-" + ver.name,
2899 config: Config{
2900 MinVersion: ver.version,
2901 MaxVersion: ver.version,
2902 },
2903 flags: []string{"-require-any-client-certificate"},
2904 shouldFail: true,
2905 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2906 })
2907
2908 if ver.version != VersionSSL30 {
2909 testCases = append(testCases, testCase{
2910 testType: serverTest,
2911 name: "SkipClientCertificate-" + ver.name,
2912 config: Config{
2913 MinVersion: ver.version,
2914 MaxVersion: ver.version,
2915 Bugs: ProtocolBugs{
2916 SkipClientCertificate: true,
2917 },
2918 },
2919 // Setting SSL_VERIFY_PEER allows anonymous clients.
2920 flags: []string{"-verify-peer"},
2921 shouldFail: true,
2922 expectedError: ":UNEXPECTED_MESSAGE:",
2923 })
2924 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08002925 }
David Benjamin4969cc92016-04-22 15:02:23 -04002926
David Benjamind316cba2016-06-02 16:17:39 -04002927 // Client auth is only legal in certificate-based ciphers.
2928 testCases = append(testCases, testCase{
2929 testType: clientTest,
2930 name: "ClientAuth-PSK",
2931 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002932 MaxVersion: VersionTLS12,
David Benjamind316cba2016-06-02 16:17:39 -04002933 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2934 PreSharedKey: []byte("secret"),
2935 ClientAuth: RequireAnyClientCert,
2936 },
2937 flags: []string{
2938 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2939 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2940 "-psk", "secret",
2941 },
2942 shouldFail: true,
2943 expectedError: ":UNEXPECTED_MESSAGE:",
2944 })
2945 testCases = append(testCases, testCase{
2946 testType: clientTest,
2947 name: "ClientAuth-ECDHE_PSK",
2948 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04002949 MaxVersion: VersionTLS12,
David Benjamind316cba2016-06-02 16:17:39 -04002950 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2951 PreSharedKey: []byte("secret"),
2952 ClientAuth: RequireAnyClientCert,
2953 },
2954 flags: []string{
2955 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2956 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2957 "-psk", "secret",
2958 },
2959 shouldFail: true,
2960 expectedError: ":UNEXPECTED_MESSAGE:",
2961 })
David Benjaminc895d6b2016-08-11 13:26:41 -04002962
2963 // Regression test for a bug where the client CA list, if explicitly
2964 // set to NULL, was mis-encoded.
2965 testCases = append(testCases, testCase{
2966 testType: serverTest,
2967 name: "Null-Client-CA-List",
2968 config: Config{
2969 MaxVersion: VersionTLS12,
2970 Certificates: []Certificate{rsaCertificate},
2971 },
2972 flags: []string{
2973 "-require-any-client-certificate",
2974 "-use-null-client-ca-list",
2975 },
2976 })
Adam Langleyd9e397b2015-01-22 14:27:53 -08002977}
2978
2979func addExtendedMasterSecretTests() {
2980 const expectEMSFlag = "-expect-extended-master-secret"
2981
2982 for _, with := range []bool{false, true} {
2983 prefix := "No"
Adam Langleyd9e397b2015-01-22 14:27:53 -08002984 if with {
2985 prefix = ""
Adam Langleyd9e397b2015-01-22 14:27:53 -08002986 }
2987
2988 for _, isClient := range []bool{false, true} {
2989 suffix := "-Server"
2990 testType := serverTest
2991 if isClient {
2992 suffix = "-Client"
2993 testType = clientTest
2994 }
2995
2996 for _, ver := range tlsVersions {
David Benjaminc895d6b2016-08-11 13:26:41 -04002997 // In TLS 1.3, the extension is irrelevant and
2998 // always reports as enabled.
2999 var flags []string
3000 if with || ver.version >= VersionTLS13 {
3001 flags = []string{expectEMSFlag}
3002 }
3003
Adam Langleyd9e397b2015-01-22 14:27:53 -08003004 test := testCase{
3005 testType: testType,
3006 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3007 config: Config{
3008 MinVersion: ver.version,
3009 MaxVersion: ver.version,
3010 Bugs: ProtocolBugs{
3011 NoExtendedMasterSecret: !with,
3012 RequireExtendedMasterSecret: with,
3013 },
3014 },
3015 flags: flags,
3016 shouldFail: ver.version == VersionSSL30 && with,
3017 }
3018 if test.shouldFail {
3019 test.expectedLocalError = "extended master secret required but not supported by peer"
3020 }
3021 testCases = append(testCases, test)
3022 }
3023 }
3024 }
3025
Adam Langleyf4e42722015-06-04 17:45:09 -07003026 for _, isClient := range []bool{false, true} {
3027 for _, supportedInFirstConnection := range []bool{false, true} {
3028 for _, supportedInResumeConnection := range []bool{false, true} {
3029 boolToWord := func(b bool) string {
3030 if b {
3031 return "Yes"
3032 }
3033 return "No"
3034 }
3035 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3036 if isClient {
3037 suffix += "Client"
3038 } else {
3039 suffix += "Server"
3040 }
3041
3042 supportedConfig := Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003043 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003044 Bugs: ProtocolBugs{
3045 RequireExtendedMasterSecret: true,
3046 },
3047 }
3048
3049 noSupportConfig := Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003050 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003051 Bugs: ProtocolBugs{
3052 NoExtendedMasterSecret: true,
3053 },
3054 }
3055
3056 test := testCase{
3057 name: "ExtendedMasterSecret-" + suffix,
3058 resumeSession: true,
3059 }
3060
3061 if !isClient {
3062 test.testType = serverTest
3063 }
3064
3065 if supportedInFirstConnection {
3066 test.config = supportedConfig
3067 } else {
3068 test.config = noSupportConfig
3069 }
3070
3071 if supportedInResumeConnection {
3072 test.resumeConfig = &supportedConfig
3073 } else {
3074 test.resumeConfig = &noSupportConfig
3075 }
3076
3077 switch suffix {
3078 case "YesToYes-Client", "YesToYes-Server":
3079 // When a session is resumed, it should
3080 // still be aware that its master
3081 // secret was generated via EMS and
3082 // thus it's safe to use tls-unique.
3083 test.flags = []string{expectEMSFlag}
3084 case "NoToYes-Server":
3085 // If an original connection did not
3086 // contain EMS, but a resumption
3087 // handshake does, then a server should
3088 // not resume the session.
3089 test.expectResumeRejected = true
3090 case "YesToNo-Server":
3091 // Resuming an EMS session without the
3092 // EMS extension should cause the
3093 // server to abort the connection.
3094 test.shouldFail = true
3095 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3096 case "NoToYes-Client":
3097 // A client should abort a connection
3098 // where the server resumed a non-EMS
3099 // session but echoed the EMS
3100 // extension.
3101 test.shouldFail = true
3102 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3103 case "YesToNo-Client":
3104 // A client should abort a connection
3105 // where the server didn't echo EMS
3106 // when the session used it.
3107 test.shouldFail = true
3108 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3109 }
3110
3111 testCases = append(testCases, test)
3112 }
3113 }
3114 }
David Benjaminf0c4a6c2016-08-11 13:26:41 -04003115
3116 // Switching EMS on renegotiation is forbidden.
3117 testCases = append(testCases, testCase{
3118 name: "ExtendedMasterSecret-Renego-NoEMS",
3119 config: Config{
3120 MaxVersion: VersionTLS12,
3121 Bugs: ProtocolBugs{
3122 NoExtendedMasterSecret: true,
3123 NoExtendedMasterSecretOnRenegotiation: true,
3124 },
3125 },
3126 renegotiate: 1,
3127 flags: []string{
3128 "-renegotiate-freely",
3129 "-expect-total-renegotiations", "1",
3130 },
3131 })
3132
3133 testCases = append(testCases, testCase{
3134 name: "ExtendedMasterSecret-Renego-Upgrade",
3135 config: Config{
3136 MaxVersion: VersionTLS12,
3137 Bugs: ProtocolBugs{
3138 NoExtendedMasterSecret: true,
3139 },
3140 },
3141 renegotiate: 1,
3142 flags: []string{
3143 "-renegotiate-freely",
3144 "-expect-total-renegotiations", "1",
3145 },
3146 shouldFail: true,
3147 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3148 })
3149
3150 testCases = append(testCases, testCase{
3151 name: "ExtendedMasterSecret-Renego-Downgrade",
3152 config: Config{
3153 MaxVersion: VersionTLS12,
3154 Bugs: ProtocolBugs{
3155 NoExtendedMasterSecretOnRenegotiation: true,
3156 },
3157 },
3158 renegotiate: 1,
3159 flags: []string{
3160 "-renegotiate-freely",
3161 "-expect-total-renegotiations", "1",
3162 },
3163 shouldFail: true,
3164 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3165 })
Adam Langleyd9e397b2015-01-22 14:27:53 -08003166}
3167
David Benjaminc895d6b2016-08-11 13:26:41 -04003168type stateMachineTestConfig struct {
3169 protocol protocol
3170 async bool
3171 splitHandshake, packHandshakeFlight bool
3172}
3173
Adam Langleyd9e397b2015-01-22 14:27:53 -08003174// Adds tests that try to cover the range of the handshake state machine, under
3175// various conditions. Some of these are redundant with other tests, but they
3176// only cover the synchronous case.
David Benjaminc895d6b2016-08-11 13:26:41 -04003177func addAllStateMachineCoverageTests() {
3178 for _, async := range []bool{false, true} {
3179 for _, protocol := range []protocol{tls, dtls} {
3180 addStateMachineCoverageTests(stateMachineTestConfig{
3181 protocol: protocol,
3182 async: async,
3183 })
3184 addStateMachineCoverageTests(stateMachineTestConfig{
3185 protocol: protocol,
3186 async: async,
3187 splitHandshake: true,
3188 })
3189 if protocol == tls {
3190 addStateMachineCoverageTests(stateMachineTestConfig{
3191 protocol: protocol,
3192 async: async,
3193 packHandshakeFlight: true,
3194 })
3195 }
3196 }
3197 }
3198}
3199
3200func addStateMachineCoverageTests(config stateMachineTestConfig) {
Adam Langleyf4e42722015-06-04 17:45:09 -07003201 var tests []testCase
3202
3203 // Basic handshake, with resumption. Client and server,
3204 // session ID and session ticket.
3205 tests = append(tests, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04003206 name: "Basic-Client",
3207 config: Config{
3208 MaxVersion: VersionTLS12,
3209 },
Adam Langleyf4e42722015-06-04 17:45:09 -07003210 resumeSession: true,
David Benjamin4969cc92016-04-22 15:02:23 -04003211 // Ensure session tickets are used, not session IDs.
3212 noSessionCache: true,
Adam Langleyf4e42722015-06-04 17:45:09 -07003213 })
3214 tests = append(tests, testCase{
3215 name: "Basic-Client-RenewTicket",
3216 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003217 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003218 Bugs: ProtocolBugs{
3219 RenewTicketOnResume: true,
3220 },
3221 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04003222 flags: []string{"-expect-ticket-renewal"},
3223 resumeSession: true,
3224 resumeRenewedSession: true,
Adam Langleyf4e42722015-06-04 17:45:09 -07003225 })
3226 tests = append(tests, testCase{
3227 name: "Basic-Client-NoTicket",
3228 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003229 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003230 SessionTicketsDisabled: true,
3231 },
3232 resumeSession: true,
3233 })
3234 tests = append(tests, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04003235 name: "Basic-Client-Implicit",
3236 config: Config{
3237 MaxVersion: VersionTLS12,
3238 },
Adam Langleyf4e42722015-06-04 17:45:09 -07003239 flags: []string{"-implicit-handshake"},
3240 resumeSession: true,
3241 })
3242 tests = append(tests, testCase{
David Benjamin4969cc92016-04-22 15:02:23 -04003243 testType: serverTest,
3244 name: "Basic-Server",
3245 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003246 MaxVersion: VersionTLS12,
David Benjamin4969cc92016-04-22 15:02:23 -04003247 Bugs: ProtocolBugs{
3248 RequireSessionTickets: true,
3249 },
3250 },
Adam Langleyf4e42722015-06-04 17:45:09 -07003251 resumeSession: true,
3252 })
3253 tests = append(tests, testCase{
3254 testType: serverTest,
3255 name: "Basic-Server-NoTickets",
3256 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003257 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003258 SessionTicketsDisabled: true,
3259 },
3260 resumeSession: true,
3261 })
3262 tests = append(tests, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04003263 testType: serverTest,
3264 name: "Basic-Server-Implicit",
3265 config: Config{
3266 MaxVersion: VersionTLS12,
3267 },
Adam Langleyf4e42722015-06-04 17:45:09 -07003268 flags: []string{"-implicit-handshake"},
3269 resumeSession: true,
3270 })
3271 tests = append(tests, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04003272 testType: serverTest,
3273 name: "Basic-Server-EarlyCallback",
3274 config: Config{
3275 MaxVersion: VersionTLS12,
3276 },
Adam Langleyf4e42722015-06-04 17:45:09 -07003277 flags: []string{"-use-early-callback"},
3278 resumeSession: true,
3279 })
3280
David Benjaminc895d6b2016-08-11 13:26:41 -04003281 // TLS 1.3 basic handshake shapes.
David Benjaminf0c4a6c2016-08-11 13:26:41 -04003282 if config.protocol == tls {
3283 tests = append(tests, testCase{
3284 name: "TLS13-1RTT-Client",
3285 config: Config{
3286 MaxVersion: VersionTLS13,
3287 MinVersion: VersionTLS13,
3288 },
3289 resumeSession: true,
3290 resumeRenewedSession: true,
3291 })
3292
3293 tests = append(tests, testCase{
3294 testType: serverTest,
3295 name: "TLS13-1RTT-Server",
3296 config: Config{
3297 MaxVersion: VersionTLS13,
3298 MinVersion: VersionTLS13,
3299 },
3300 resumeSession: true,
3301 resumeRenewedSession: true,
3302 })
3303
3304 tests = append(tests, testCase{
3305 name: "TLS13-HelloRetryRequest-Client",
3306 config: Config{
3307 MaxVersion: VersionTLS13,
3308 MinVersion: VersionTLS13,
3309 // P-384 requires a HelloRetryRequest against
3310 // BoringSSL's default configuration. Assert
3311 // that we do indeed test this with
3312 // ExpectMissingKeyShare.
3313 CurvePreferences: []CurveID{CurveP384},
3314 Bugs: ProtocolBugs{
3315 ExpectMissingKeyShare: true,
3316 },
3317 },
3318 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3319 resumeSession: true,
3320 })
3321
3322 tests = append(tests, testCase{
3323 testType: serverTest,
3324 name: "TLS13-HelloRetryRequest-Server",
3325 config: Config{
3326 MaxVersion: VersionTLS13,
3327 MinVersion: VersionTLS13,
3328 // Require a HelloRetryRequest for every curve.
3329 DefaultCurves: []CurveID{},
3330 },
3331 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3332 resumeSession: true,
3333 })
3334 }
David Benjaminc895d6b2016-08-11 13:26:41 -04003335
Adam Langleyf4e42722015-06-04 17:45:09 -07003336 // TLS client auth.
3337 tests = append(tests, testCase{
3338 testType: clientTest,
David Benjamin4969cc92016-04-22 15:02:23 -04003339 name: "ClientAuth-NoCertificate-Client",
3340 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003341 MaxVersion: VersionTLS12,
David Benjamin4969cc92016-04-22 15:02:23 -04003342 ClientAuth: RequestClientCert,
3343 },
3344 })
3345 tests = append(tests, testCase{
3346 testType: serverTest,
3347 name: "ClientAuth-NoCertificate-Server",
David Benjaminc895d6b2016-08-11 13:26:41 -04003348 config: Config{
3349 MaxVersion: VersionTLS12,
3350 },
David Benjamin4969cc92016-04-22 15:02:23 -04003351 // Setting SSL_VERIFY_PEER allows anonymous clients.
3352 flags: []string{"-verify-peer"},
3353 })
David Benjaminc895d6b2016-08-11 13:26:41 -04003354 if config.protocol == tls {
David Benjamin4969cc92016-04-22 15:02:23 -04003355 tests = append(tests, testCase{
3356 testType: clientTest,
3357 name: "ClientAuth-NoCertificate-Client-SSL3",
3358 config: Config{
3359 MaxVersion: VersionSSL30,
3360 ClientAuth: RequestClientCert,
3361 },
3362 })
3363 tests = append(tests, testCase{
3364 testType: serverTest,
3365 name: "ClientAuth-NoCertificate-Server-SSL3",
3366 config: Config{
3367 MaxVersion: VersionSSL30,
3368 },
3369 // Setting SSL_VERIFY_PEER allows anonymous clients.
3370 flags: []string{"-verify-peer"},
3371 })
David Benjaminc895d6b2016-08-11 13:26:41 -04003372 tests = append(tests, testCase{
3373 testType: clientTest,
3374 name: "ClientAuth-NoCertificate-Client-TLS13",
3375 config: Config{
3376 MaxVersion: VersionTLS13,
3377 ClientAuth: RequestClientCert,
3378 },
3379 })
3380 tests = append(tests, testCase{
3381 testType: serverTest,
3382 name: "ClientAuth-NoCertificate-Server-TLS13",
3383 config: Config{
3384 MaxVersion: VersionTLS13,
3385 },
3386 // Setting SSL_VERIFY_PEER allows anonymous clients.
3387 flags: []string{"-verify-peer"},
3388 })
David Benjamin4969cc92016-04-22 15:02:23 -04003389 }
3390 tests = append(tests, testCase{
3391 testType: clientTest,
Kenny Roote99801b2015-11-06 15:31:15 -08003392 name: "ClientAuth-RSA-Client",
Adam Langleyf4e42722015-06-04 17:45:09 -07003393 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003394 MaxVersion: VersionTLS12,
3395 ClientAuth: RequireAnyClientCert,
3396 },
3397 flags: []string{
3398 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3399 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3400 },
3401 })
3402 tests = append(tests, testCase{
3403 testType: clientTest,
3404 name: "ClientAuth-RSA-Client-TLS13",
3405 config: Config{
3406 MaxVersion: VersionTLS13,
Adam Langleyf4e42722015-06-04 17:45:09 -07003407 ClientAuth: RequireAnyClientCert,
3408 },
3409 flags: []string{
Kenny Rootb8494592015-09-25 02:29:14 +00003410 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3411 "-key-file", path.Join(*resourceDir, rsaKeyFile),
Adam Langleyf4e42722015-06-04 17:45:09 -07003412 },
3413 })
Kenny Roote99801b2015-11-06 15:31:15 -08003414 tests = append(tests, testCase{
3415 testType: clientTest,
3416 name: "ClientAuth-ECDSA-Client",
3417 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003418 MaxVersion: VersionTLS12,
Kenny Roote99801b2015-11-06 15:31:15 -08003419 ClientAuth: RequireAnyClientCert,
3420 },
3421 flags: []string{
David Benjaminc895d6b2016-08-11 13:26:41 -04003422 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3423 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
Kenny Roote99801b2015-11-06 15:31:15 -08003424 },
3425 })
David Benjamin4969cc92016-04-22 15:02:23 -04003426 tests = append(tests, testCase{
3427 testType: clientTest,
David Benjaminc895d6b2016-08-11 13:26:41 -04003428 name: "ClientAuth-ECDSA-Client-TLS13",
3429 config: Config{
3430 MaxVersion: VersionTLS13,
3431 ClientAuth: RequireAnyClientCert,
3432 },
3433 flags: []string{
3434 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3435 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3436 },
3437 })
3438 tests = append(tests, testCase{
3439 testType: clientTest,
3440 name: "ClientAuth-NoCertificate-OldCallback",
3441 config: Config{
3442 MaxVersion: VersionTLS12,
3443 ClientAuth: RequestClientCert,
3444 },
3445 flags: []string{"-use-old-client-cert-callback"},
3446 })
3447 tests = append(tests, testCase{
3448 testType: clientTest,
3449 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3450 config: Config{
3451 MaxVersion: VersionTLS13,
3452 ClientAuth: RequestClientCert,
3453 },
3454 flags: []string{"-use-old-client-cert-callback"},
3455 })
3456 tests = append(tests, testCase{
3457 testType: clientTest,
David Benjamin4969cc92016-04-22 15:02:23 -04003458 name: "ClientAuth-OldCallback",
3459 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003460 MaxVersion: VersionTLS12,
David Benjamin4969cc92016-04-22 15:02:23 -04003461 ClientAuth: RequireAnyClientCert,
3462 },
3463 flags: []string{
3464 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3465 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3466 "-use-old-client-cert-callback",
3467 },
3468 })
David Benjaminc895d6b2016-08-11 13:26:41 -04003469 tests = append(tests, testCase{
3470 testType: clientTest,
3471 name: "ClientAuth-OldCallback-TLS13",
3472 config: Config{
3473 MaxVersion: VersionTLS13,
3474 ClientAuth: RequireAnyClientCert,
3475 },
3476 flags: []string{
3477 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3478 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3479 "-use-old-client-cert-callback",
3480 },
3481 })
Adam Langleyf4e42722015-06-04 17:45:09 -07003482 tests = append(tests, testCase{
3483 testType: serverTest,
3484 name: "ClientAuth-Server",
3485 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003486 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003487 Certificates: []Certificate{rsaCertificate},
3488 },
3489 flags: []string{"-require-any-client-certificate"},
3490 })
David Benjaminc895d6b2016-08-11 13:26:41 -04003491 tests = append(tests, testCase{
3492 testType: serverTest,
3493 name: "ClientAuth-Server-TLS13",
3494 config: Config{
3495 MaxVersion: VersionTLS13,
3496 Certificates: []Certificate{rsaCertificate},
3497 },
3498 flags: []string{"-require-any-client-certificate"},
3499 })
3500
3501 // Test each key exchange on the server side for async keys.
3502 tests = append(tests, testCase{
3503 testType: serverTest,
3504 name: "Basic-Server-RSA",
3505 config: Config{
3506 MaxVersion: VersionTLS12,
3507 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3508 },
3509 flags: []string{
3510 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3511 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3512 },
3513 })
3514 tests = append(tests, testCase{
3515 testType: serverTest,
3516 name: "Basic-Server-ECDHE-RSA",
3517 config: Config{
3518 MaxVersion: VersionTLS12,
3519 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3520 },
3521 flags: []string{
3522 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3523 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3524 },
3525 })
3526 tests = append(tests, testCase{
3527 testType: serverTest,
3528 name: "Basic-Server-ECDHE-ECDSA",
3529 config: Config{
3530 MaxVersion: VersionTLS12,
3531 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3532 },
3533 flags: []string{
3534 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3535 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3536 },
3537 })
Adam Langleyf4e42722015-06-04 17:45:09 -07003538
3539 // No session ticket support; server doesn't send NewSessionTicket.
3540 tests = append(tests, testCase{
3541 name: "SessionTicketsDisabled-Client",
3542 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003543 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003544 SessionTicketsDisabled: true,
3545 },
3546 })
3547 tests = append(tests, testCase{
3548 testType: serverTest,
3549 name: "SessionTicketsDisabled-Server",
3550 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003551 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003552 SessionTicketsDisabled: true,
3553 },
3554 })
3555
3556 // Skip ServerKeyExchange in PSK key exchange if there's no
3557 // identity hint.
3558 tests = append(tests, testCase{
3559 name: "EmptyPSKHint-Client",
3560 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003561 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003562 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3563 PreSharedKey: []byte("secret"),
3564 },
3565 flags: []string{"-psk", "secret"},
3566 })
3567 tests = append(tests, testCase{
3568 testType: serverTest,
3569 name: "EmptyPSKHint-Server",
3570 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003571 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003572 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3573 PreSharedKey: []byte("secret"),
3574 },
3575 flags: []string{"-psk", "secret"},
3576 })
3577
David Benjaminc895d6b2016-08-11 13:26:41 -04003578 // OCSP stapling tests.
Kenny Rootb8494592015-09-25 02:29:14 +00003579 tests = append(tests, testCase{
3580 testType: clientTest,
3581 name: "OCSPStapling-Client",
David Benjaminc895d6b2016-08-11 13:26:41 -04003582 config: Config{
3583 MaxVersion: VersionTLS12,
3584 },
Kenny Rootb8494592015-09-25 02:29:14 +00003585 flags: []string{
3586 "-enable-ocsp-stapling",
3587 "-expect-ocsp-response",
3588 base64.StdEncoding.EncodeToString(testOCSPResponse),
3589 "-verify-peer",
3590 },
3591 resumeSession: true,
3592 })
Kenny Rootb8494592015-09-25 02:29:14 +00003593 tests = append(tests, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04003594 testType: serverTest,
3595 name: "OCSPStapling-Server",
3596 config: Config{
3597 MaxVersion: VersionTLS12,
3598 },
Kenny Rootb8494592015-09-25 02:29:14 +00003599 expectedOCSPResponse: testOCSPResponse,
3600 flags: []string{
3601 "-ocsp-response",
3602 base64.StdEncoding.EncodeToString(testOCSPResponse),
3603 },
3604 resumeSession: true,
3605 })
Kenny Rootb8494592015-09-25 02:29:14 +00003606 tests = append(tests, testCase{
3607 testType: clientTest,
David Benjaminc895d6b2016-08-11 13:26:41 -04003608 name: "OCSPStapling-Client-TLS13",
3609 config: Config{
3610 MaxVersion: VersionTLS13,
3611 },
Kenny Rootb8494592015-09-25 02:29:14 +00003612 flags: []string{
David Benjaminc895d6b2016-08-11 13:26:41 -04003613 "-enable-ocsp-stapling",
3614 "-expect-ocsp-response",
3615 base64.StdEncoding.EncodeToString(testOCSPResponse),
Kenny Rootb8494592015-09-25 02:29:14 +00003616 "-verify-peer",
3617 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04003618 resumeSession: true,
Kenny Rootb8494592015-09-25 02:29:14 +00003619 })
Kenny Rootb8494592015-09-25 02:29:14 +00003620 tests = append(tests, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04003621 testType: serverTest,
3622 name: "OCSPStapling-Server-TLS13",
3623 config: Config{
3624 MaxVersion: VersionTLS13,
Kenny Rootb8494592015-09-25 02:29:14 +00003625 },
David Benjaminc895d6b2016-08-11 13:26:41 -04003626 expectedOCSPResponse: testOCSPResponse,
3627 flags: []string{
3628 "-ocsp-response",
3629 base64.StdEncoding.EncodeToString(testOCSPResponse),
3630 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04003631 resumeSession: true,
Kenny Rootb8494592015-09-25 02:29:14 +00003632 })
3633
David Benjaminc895d6b2016-08-11 13:26:41 -04003634 // Certificate verification tests.
3635 for _, vers := range tlsVersions {
3636 if config.protocol == dtls && !vers.hasDTLS {
3637 continue
3638 }
3639 for _, testType := range []testType{clientTest, serverTest} {
3640 suffix := "-Client"
3641 if testType == serverTest {
3642 suffix = "-Server"
3643 }
3644 suffix += "-" + vers.name
Kenny Rootb8494592015-09-25 02:29:14 +00003645
David Benjaminc895d6b2016-08-11 13:26:41 -04003646 flag := "-verify-peer"
3647 if testType == serverTest {
3648 flag = "-require-any-client-certificate"
3649 }
3650
3651 tests = append(tests, testCase{
3652 testType: testType,
3653 name: "CertificateVerificationSucceed" + suffix,
3654 config: Config{
3655 MaxVersion: vers.version,
3656 Certificates: []Certificate{rsaCertificate},
3657 },
3658 flags: []string{
3659 flag,
3660 "-expect-verify-result",
3661 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04003662 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04003663 })
3664 tests = append(tests, testCase{
3665 testType: testType,
3666 name: "CertificateVerificationFail" + suffix,
3667 config: Config{
3668 MaxVersion: vers.version,
3669 Certificates: []Certificate{rsaCertificate},
3670 },
3671 flags: []string{
3672 flag,
3673 "-verify-fail",
3674 },
3675 shouldFail: true,
3676 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3677 })
3678 }
3679
3680 // By default, the client is in a soft fail mode where the peer
3681 // certificate is verified but failures are non-fatal.
Adam Langleyf4e42722015-06-04 17:45:09 -07003682 tests = append(tests, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04003683 testType: clientTest,
3684 name: "CertificateVerificationSoftFail-" + vers.name,
3685 config: Config{
3686 MaxVersion: vers.version,
3687 Certificates: []Certificate{rsaCertificate},
3688 },
3689 flags: []string{
3690 "-verify-fail",
3691 "-expect-verify-result",
3692 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04003693 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04003694 })
3695 }
3696
3697 tests = append(tests, testCase{
3698 name: "ShimSendAlert",
3699 flags: []string{"-send-alert"},
3700 shimWritesFirst: true,
3701 shouldFail: true,
3702 expectedLocalError: "remote error: decompression failure",
3703 })
3704
3705 if config.protocol == tls {
3706 tests = append(tests, testCase{
3707 name: "Renegotiate-Client",
3708 config: Config{
3709 MaxVersion: VersionTLS12,
3710 },
Kenny Roote99801b2015-11-06 15:31:15 -08003711 renegotiate: 1,
3712 flags: []string{
3713 "-renegotiate-freely",
3714 "-expect-total-renegotiations", "1",
3715 },
Adam Langleyf4e42722015-06-04 17:45:09 -07003716 })
David Benjaminc895d6b2016-08-11 13:26:41 -04003717
3718 tests = append(tests, testCase{
3719 name: "SendHalfHelloRequest",
3720 config: Config{
3721 MaxVersion: VersionTLS12,
3722 Bugs: ProtocolBugs{
3723 PackHelloRequestWithFinished: config.packHandshakeFlight,
3724 },
3725 },
3726 sendHalfHelloRequest: true,
3727 flags: []string{"-renegotiate-ignore"},
3728 shouldFail: true,
3729 expectedError: ":UNEXPECTED_RECORD:",
3730 })
3731
Adam Langleyf4e42722015-06-04 17:45:09 -07003732 // NPN on client and server; results in post-handshake message.
3733 tests = append(tests, testCase{
3734 name: "NPN-Client",
3735 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003736 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003737 NextProtos: []string{"foo"},
3738 },
3739 flags: []string{"-select-next-proto", "foo"},
David Benjaminc895d6b2016-08-11 13:26:41 -04003740 resumeSession: true,
Adam Langleyf4e42722015-06-04 17:45:09 -07003741 expectedNextProto: "foo",
3742 expectedNextProtoType: npn,
3743 })
3744 tests = append(tests, testCase{
3745 testType: serverTest,
3746 name: "NPN-Server",
3747 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003748 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003749 NextProtos: []string{"bar"},
3750 },
3751 flags: []string{
3752 "-advertise-npn", "\x03foo\x03bar\x03baz",
3753 "-expect-next-proto", "bar",
3754 },
David Benjaminc895d6b2016-08-11 13:26:41 -04003755 resumeSession: true,
Adam Langleyf4e42722015-06-04 17:45:09 -07003756 expectedNextProto: "bar",
3757 expectedNextProtoType: npn,
3758 })
3759
3760 // TODO(davidben): Add tests for when False Start doesn't trigger.
3761
3762 // Client does False Start and negotiates NPN.
3763 tests = append(tests, testCase{
3764 name: "FalseStart",
3765 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003766 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003767 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3768 NextProtos: []string{"foo"},
3769 Bugs: ProtocolBugs{
3770 ExpectFalseStart: true,
3771 },
3772 },
3773 flags: []string{
3774 "-false-start",
3775 "-select-next-proto", "foo",
3776 },
3777 shimWritesFirst: true,
3778 resumeSession: true,
3779 })
3780
3781 // Client does False Start and negotiates ALPN.
3782 tests = append(tests, testCase{
3783 name: "FalseStart-ALPN",
3784 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003785 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3787 NextProtos: []string{"foo"},
3788 Bugs: ProtocolBugs{
3789 ExpectFalseStart: true,
3790 },
3791 },
3792 flags: []string{
3793 "-false-start",
3794 "-advertise-alpn", "\x03foo",
3795 },
3796 shimWritesFirst: true,
3797 resumeSession: true,
3798 })
3799
3800 // Client does False Start but doesn't explicitly call
3801 // SSL_connect.
3802 tests = append(tests, testCase{
3803 name: "FalseStart-Implicit",
3804 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003805 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3807 NextProtos: []string{"foo"},
3808 },
3809 flags: []string{
3810 "-implicit-handshake",
3811 "-false-start",
3812 "-advertise-alpn", "\x03foo",
3813 },
3814 })
3815
3816 // False Start without session tickets.
3817 tests = append(tests, testCase{
3818 name: "FalseStart-SessionTicketsDisabled",
3819 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003820 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003821 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3822 NextProtos: []string{"foo"},
3823 SessionTicketsDisabled: true,
3824 Bugs: ProtocolBugs{
3825 ExpectFalseStart: true,
3826 },
3827 },
3828 flags: []string{
3829 "-false-start",
3830 "-select-next-proto", "foo",
3831 },
3832 shimWritesFirst: true,
3833 })
3834
David Benjaminc895d6b2016-08-11 13:26:41 -04003835 tests = append(tests, testCase{
3836 name: "FalseStart-CECPQ1",
3837 config: Config{
3838 MaxVersion: VersionTLS12,
3839 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3840 NextProtos: []string{"foo"},
3841 Bugs: ProtocolBugs{
3842 ExpectFalseStart: true,
3843 },
3844 },
3845 flags: []string{
3846 "-false-start",
3847 "-cipher", "DEFAULT:kCECPQ1",
3848 "-select-next-proto", "foo",
3849 },
3850 shimWritesFirst: true,
3851 resumeSession: true,
3852 })
3853
Adam Langleyf4e42722015-06-04 17:45:09 -07003854 // Server parses a V2ClientHello.
3855 tests = append(tests, testCase{
3856 testType: serverTest,
3857 name: "SendV2ClientHello",
3858 config: Config{
3859 // Choose a cipher suite that does not involve
3860 // elliptic curves, so no extensions are
3861 // involved.
David Benjaminc895d6b2016-08-11 13:26:41 -04003862 MaxVersion: VersionTLS12,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04003863 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleyf4e42722015-06-04 17:45:09 -07003864 Bugs: ProtocolBugs{
3865 SendV2ClientHello: true,
3866 },
3867 },
3868 })
3869
3870 // Client sends a Channel ID.
3871 tests = append(tests, testCase{
3872 name: "ChannelID-Client",
3873 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003874 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003875 RequestChannelID: true,
3876 },
Kenny Rootb8494592015-09-25 02:29:14 +00003877 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
Adam Langleyf4e42722015-06-04 17:45:09 -07003878 resumeSession: true,
3879 expectChannelID: true,
3880 })
3881
3882 // Server accepts a Channel ID.
3883 tests = append(tests, testCase{
3884 testType: serverTest,
3885 name: "ChannelID-Server",
3886 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003887 MaxVersion: VersionTLS12,
3888 ChannelID: channelIDKey,
Adam Langleyf4e42722015-06-04 17:45:09 -07003889 },
3890 flags: []string{
3891 "-expect-channel-id",
3892 base64.StdEncoding.EncodeToString(channelIDBytes),
3893 },
3894 resumeSession: true,
3895 expectChannelID: true,
3896 })
Kenny Rootb8494592015-09-25 02:29:14 +00003897
David Benjaminc895d6b2016-08-11 13:26:41 -04003898 // Channel ID and NPN at the same time, to ensure their relative
3899 // ordering is correct.
3900 tests = append(tests, testCase{
3901 name: "ChannelID-NPN-Client",
3902 config: Config{
3903 MaxVersion: VersionTLS12,
3904 RequestChannelID: true,
3905 NextProtos: []string{"foo"},
3906 },
3907 flags: []string{
3908 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3909 "-select-next-proto", "foo",
3910 },
3911 resumeSession: true,
3912 expectChannelID: true,
3913 expectedNextProto: "foo",
3914 expectedNextProtoType: npn,
3915 })
3916 tests = append(tests, testCase{
3917 testType: serverTest,
3918 name: "ChannelID-NPN-Server",
3919 config: Config{
3920 MaxVersion: VersionTLS12,
3921 ChannelID: channelIDKey,
3922 NextProtos: []string{"bar"},
3923 },
3924 flags: []string{
3925 "-expect-channel-id",
3926 base64.StdEncoding.EncodeToString(channelIDBytes),
3927 "-advertise-npn", "\x03foo\x03bar\x03baz",
3928 "-expect-next-proto", "bar",
3929 },
3930 resumeSession: true,
3931 expectChannelID: true,
3932 expectedNextProto: "bar",
3933 expectedNextProtoType: npn,
3934 })
3935
Kenny Rootb8494592015-09-25 02:29:14 +00003936 // Bidirectional shutdown with the runner initiating.
3937 tests = append(tests, testCase{
3938 name: "Shutdown-Runner",
3939 config: Config{
3940 Bugs: ProtocolBugs{
3941 ExpectCloseNotify: true,
3942 },
3943 },
3944 flags: []string{"-check-close-notify"},
3945 })
3946
3947 // Bidirectional shutdown with the shim initiating. The runner,
3948 // in the meantime, sends garbage before the close_notify which
3949 // the shim must ignore.
3950 tests = append(tests, testCase{
3951 name: "Shutdown-Shim",
3952 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003953 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00003954 Bugs: ProtocolBugs{
3955 ExpectCloseNotify: true,
3956 },
3957 },
3958 shimShutsDown: true,
3959 sendEmptyRecords: 1,
3960 sendWarningAlerts: 1,
3961 flags: []string{"-check-close-notify"},
3962 })
Adam Langleyf4e42722015-06-04 17:45:09 -07003963 } else {
David Benjaminc895d6b2016-08-11 13:26:41 -04003964 // TODO(davidben): DTLS 1.3 will want a similar thing for
3965 // HelloRetryRequest.
Adam Langleyf4e42722015-06-04 17:45:09 -07003966 tests = append(tests, testCase{
3967 name: "SkipHelloVerifyRequest",
3968 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04003969 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07003970 Bugs: ProtocolBugs{
3971 SkipHelloVerifyRequest: true,
3972 },
3973 },
3974 })
3975 }
3976
Adam Langleyf4e42722015-06-04 17:45:09 -07003977 for _, test := range tests {
David Benjaminc895d6b2016-08-11 13:26:41 -04003978 test.protocol = config.protocol
3979 if config.protocol == dtls {
Adam Langleyfad63272015-11-12 12:15:39 -08003980 test.name += "-DTLS"
3981 }
David Benjaminc895d6b2016-08-11 13:26:41 -04003982 if config.async {
Adam Langleyfad63272015-11-12 12:15:39 -08003983 test.name += "-Async"
3984 test.flags = append(test.flags, "-async")
3985 } else {
3986 test.name += "-Sync"
3987 }
David Benjaminc895d6b2016-08-11 13:26:41 -04003988 if config.splitHandshake {
Adam Langleyfad63272015-11-12 12:15:39 -08003989 test.name += "-SplitHandshakeRecords"
3990 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjaminc895d6b2016-08-11 13:26:41 -04003991 if config.protocol == dtls {
Adam Langleyfad63272015-11-12 12:15:39 -08003992 test.config.Bugs.MaxPacketLength = 256
3993 test.flags = append(test.flags, "-mtu", "256")
3994 }
3995 }
David Benjaminc895d6b2016-08-11 13:26:41 -04003996 if config.packHandshakeFlight {
3997 test.name += "-PackHandshakeFlight"
3998 test.config.Bugs.PackHandshakeFlight = true
3999 }
Adam Langleyf4e42722015-06-04 17:45:09 -07004000 testCases = append(testCases, test)
Adam Langleye9ada862015-05-11 17:20:37 -07004001 }
4002}
4003
4004func addDDoSCallbackTests() {
4005 // DDoS callback.
Adam Langleye9ada862015-05-11 17:20:37 -07004006 for _, resume := range []bool{false, true} {
4007 suffix := "Resume"
4008 if resume {
4009 suffix = "No" + suffix
4010 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08004011
4012 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04004013 testType: serverTest,
4014 name: "Server-DDoS-OK-" + suffix,
4015 config: Config{
4016 MaxVersion: VersionTLS12,
4017 },
Adam Langleye9ada862015-05-11 17:20:37 -07004018 flags: []string{"-install-ddos-callback"},
4019 resumeSession: resume,
4020 })
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004021 testCases = append(testCases, testCase{
4022 testType: serverTest,
4023 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4024 config: Config{
4025 MaxVersion: VersionTLS13,
4026 },
4027 flags: []string{"-install-ddos-callback"},
4028 resumeSession: resume,
4029 })
Adam Langleye9ada862015-05-11 17:20:37 -07004030
4031 failFlag := "-fail-ddos-callback"
4032 if resume {
4033 failFlag = "-fail-second-ddos-callback"
4034 }
4035 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04004036 testType: serverTest,
4037 name: "Server-DDoS-Reject-" + suffix,
4038 config: Config{
4039 MaxVersion: VersionTLS12,
4040 },
David Benjamin7c0d06c2016-08-11 13:26:41 -04004041 flags: []string{"-install-ddos-callback", failFlag},
4042 resumeSession: resume,
4043 shouldFail: true,
4044 expectedError: ":CONNECTION_REJECTED:",
4045 expectedLocalError: "remote error: internal error",
Adam Langleyd9e397b2015-01-22 14:27:53 -08004046 })
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004047 testCases = append(testCases, testCase{
4048 testType: serverTest,
4049 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4050 config: Config{
4051 MaxVersion: VersionTLS13,
4052 },
David Benjamin7c0d06c2016-08-11 13:26:41 -04004053 flags: []string{"-install-ddos-callback", failFlag},
4054 resumeSession: resume,
4055 shouldFail: true,
4056 expectedError: ":CONNECTION_REJECTED:",
4057 expectedLocalError: "remote error: internal error",
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004058 })
Adam Langleyd9e397b2015-01-22 14:27:53 -08004059 }
4060}
4061
4062func addVersionNegotiationTests() {
4063 for i, shimVers := range tlsVersions {
4064 // Assemble flags to disable all newer versions on the shim.
4065 var flags []string
4066 for _, vers := range tlsVersions[i+1:] {
4067 flags = append(flags, vers.flag)
4068 }
4069
4070 for _, runnerVers := range tlsVersions {
4071 protocols := []protocol{tls}
4072 if runnerVers.hasDTLS && shimVers.hasDTLS {
4073 protocols = append(protocols, dtls)
4074 }
4075 for _, protocol := range protocols {
4076 expectedVersion := shimVers.version
4077 if runnerVers.version < shimVers.version {
4078 expectedVersion = runnerVers.version
4079 }
4080
4081 suffix := shimVers.name + "-" + runnerVers.name
4082 if protocol == dtls {
4083 suffix += "-DTLS"
4084 }
4085
4086 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4087
4088 clientVers := shimVers.version
4089 if clientVers > VersionTLS10 {
4090 clientVers = VersionTLS10
4091 }
David Benjaminc895d6b2016-08-11 13:26:41 -04004092 serverVers := expectedVersion
4093 if expectedVersion >= VersionTLS13 {
4094 serverVers = VersionTLS10
4095 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08004096 testCases = append(testCases, testCase{
4097 protocol: protocol,
4098 testType: clientTest,
4099 name: "VersionNegotiation-Client-" + suffix,
4100 config: Config{
4101 MaxVersion: runnerVers.version,
4102 Bugs: ProtocolBugs{
4103 ExpectInitialRecordVersion: clientVers,
4104 },
4105 },
4106 flags: flags,
4107 expectedVersion: expectedVersion,
4108 })
4109 testCases = append(testCases, testCase{
4110 protocol: protocol,
4111 testType: clientTest,
4112 name: "VersionNegotiation-Client2-" + suffix,
4113 config: Config{
4114 MaxVersion: runnerVers.version,
4115 Bugs: ProtocolBugs{
4116 ExpectInitialRecordVersion: clientVers,
4117 },
4118 },
4119 flags: []string{"-max-version", shimVersFlag},
4120 expectedVersion: expectedVersion,
4121 })
4122
4123 testCases = append(testCases, testCase{
4124 protocol: protocol,
4125 testType: serverTest,
4126 name: "VersionNegotiation-Server-" + suffix,
4127 config: Config{
4128 MaxVersion: runnerVers.version,
4129 Bugs: ProtocolBugs{
David Benjaminc895d6b2016-08-11 13:26:41 -04004130 ExpectInitialRecordVersion: serverVers,
Adam Langleyd9e397b2015-01-22 14:27:53 -08004131 },
4132 },
4133 flags: flags,
4134 expectedVersion: expectedVersion,
4135 })
4136 testCases = append(testCases, testCase{
4137 protocol: protocol,
4138 testType: serverTest,
4139 name: "VersionNegotiation-Server2-" + suffix,
4140 config: Config{
4141 MaxVersion: runnerVers.version,
4142 Bugs: ProtocolBugs{
David Benjaminc895d6b2016-08-11 13:26:41 -04004143 ExpectInitialRecordVersion: serverVers,
Adam Langleyd9e397b2015-01-22 14:27:53 -08004144 },
4145 },
4146 flags: []string{"-max-version", shimVersFlag},
4147 expectedVersion: expectedVersion,
4148 })
4149 }
4150 }
4151 }
David Benjaminc895d6b2016-08-11 13:26:41 -04004152
4153 // Test for version tolerance.
4154 testCases = append(testCases, testCase{
4155 testType: serverTest,
4156 name: "MinorVersionTolerance",
4157 config: Config{
4158 Bugs: ProtocolBugs{
4159 SendClientVersion: 0x03ff,
4160 },
4161 },
4162 expectedVersion: VersionTLS13,
4163 })
4164 testCases = append(testCases, testCase{
4165 testType: serverTest,
4166 name: "MajorVersionTolerance",
4167 config: Config{
4168 Bugs: ProtocolBugs{
4169 SendClientVersion: 0x0400,
4170 },
4171 },
4172 expectedVersion: VersionTLS13,
4173 })
4174 testCases = append(testCases, testCase{
4175 protocol: dtls,
4176 testType: serverTest,
4177 name: "MinorVersionTolerance-DTLS",
4178 config: Config{
4179 Bugs: ProtocolBugs{
4180 SendClientVersion: 0x03ff,
4181 },
4182 },
4183 expectedVersion: VersionTLS12,
4184 })
4185 testCases = append(testCases, testCase{
4186 protocol: dtls,
4187 testType: serverTest,
4188 name: "MajorVersionTolerance-DTLS",
4189 config: Config{
4190 Bugs: ProtocolBugs{
4191 SendClientVersion: 0x0400,
4192 },
4193 },
4194 expectedVersion: VersionTLS12,
4195 })
4196
4197 // Test that versions below 3.0 are rejected.
4198 testCases = append(testCases, testCase{
4199 testType: serverTest,
4200 name: "VersionTooLow",
4201 config: Config{
4202 Bugs: ProtocolBugs{
4203 SendClientVersion: 0x0200,
4204 },
4205 },
4206 shouldFail: true,
4207 expectedError: ":UNSUPPORTED_PROTOCOL:",
4208 })
4209 testCases = append(testCases, testCase{
4210 protocol: dtls,
4211 testType: serverTest,
4212 name: "VersionTooLow-DTLS",
4213 config: Config{
4214 Bugs: ProtocolBugs{
4215 // 0x0201 is the lowest version expressable in
4216 // DTLS.
4217 SendClientVersion: 0x0201,
4218 },
4219 },
4220 shouldFail: true,
4221 expectedError: ":UNSUPPORTED_PROTOCOL:",
4222 })
4223
David Benjamin7c0d06c2016-08-11 13:26:41 -04004224 testCases = append(testCases, testCase{
4225 name: "ServerBogusVersion",
4226 config: Config{
4227 Bugs: ProtocolBugs{
4228 SendServerHelloVersion: 0x1234,
4229 },
4230 },
4231 shouldFail: true,
4232 expectedError: ":UNSUPPORTED_PROTOCOL:",
4233 })
4234
David Benjaminc895d6b2016-08-11 13:26:41 -04004235 // Test TLS 1.3's downgrade signal.
4236 testCases = append(testCases, testCase{
4237 name: "Downgrade-TLS12-Client",
4238 config: Config{
4239 Bugs: ProtocolBugs{
4240 NegotiateVersion: VersionTLS12,
4241 },
4242 },
David Benjamin7c0d06c2016-08-11 13:26:41 -04004243 // TODO(davidben): This test should fail once TLS 1.3 is final
4244 // and the fallback signal restored.
David Benjaminc895d6b2016-08-11 13:26:41 -04004245 })
4246 testCases = append(testCases, testCase{
4247 testType: serverTest,
4248 name: "Downgrade-TLS12-Server",
4249 config: Config{
4250 Bugs: ProtocolBugs{
4251 SendClientVersion: VersionTLS12,
4252 },
4253 },
David Benjamin7c0d06c2016-08-11 13:26:41 -04004254 // TODO(davidben): This test should fail once TLS 1.3 is final
4255 // and the fallback signal restored.
David Benjaminc895d6b2016-08-11 13:26:41 -04004256 })
Adam Langleyd9e397b2015-01-22 14:27:53 -08004257}
4258
4259func addMinimumVersionTests() {
4260 for i, shimVers := range tlsVersions {
4261 // Assemble flags to disable all older versions on the shim.
4262 var flags []string
4263 for _, vers := range tlsVersions[:i] {
4264 flags = append(flags, vers.flag)
4265 }
4266
4267 for _, runnerVers := range tlsVersions {
4268 protocols := []protocol{tls}
4269 if runnerVers.hasDTLS && shimVers.hasDTLS {
4270 protocols = append(protocols, dtls)
4271 }
4272 for _, protocol := range protocols {
4273 suffix := shimVers.name + "-" + runnerVers.name
4274 if protocol == dtls {
4275 suffix += "-DTLS"
4276 }
4277 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4278
4279 var expectedVersion uint16
4280 var shouldFail bool
David Benjaminc895d6b2016-08-11 13:26:41 -04004281 var expectedClientError, expectedServerError string
4282 var expectedClientLocalError, expectedServerLocalError string
Adam Langleyd9e397b2015-01-22 14:27:53 -08004283 if runnerVers.version >= shimVers.version {
4284 expectedVersion = runnerVers.version
4285 } else {
4286 shouldFail = true
David Benjaminc895d6b2016-08-11 13:26:41 -04004287 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4288 expectedServerLocalError = "remote error: protocol version not supported"
4289 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4290 // If the client's minimum version is TLS 1.3 and the runner's
4291 // maximum is below TLS 1.2, the runner will fail to select a
4292 // cipher before the shim rejects the selected version.
4293 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4294 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4295 } else {
4296 expectedClientError = expectedServerError
4297 expectedClientLocalError = expectedServerLocalError
4298 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08004299 }
4300
4301 testCases = append(testCases, testCase{
4302 protocol: protocol,
4303 testType: clientTest,
4304 name: "MinimumVersion-Client-" + suffix,
4305 config: Config{
4306 MaxVersion: runnerVers.version,
4307 },
4308 flags: flags,
4309 expectedVersion: expectedVersion,
4310 shouldFail: shouldFail,
David Benjaminc895d6b2016-08-11 13:26:41 -04004311 expectedError: expectedClientError,
4312 expectedLocalError: expectedClientLocalError,
Adam Langleyd9e397b2015-01-22 14:27:53 -08004313 })
4314 testCases = append(testCases, testCase{
4315 protocol: protocol,
4316 testType: clientTest,
4317 name: "MinimumVersion-Client2-" + suffix,
4318 config: Config{
4319 MaxVersion: runnerVers.version,
4320 },
4321 flags: []string{"-min-version", shimVersFlag},
4322 expectedVersion: expectedVersion,
4323 shouldFail: shouldFail,
David Benjaminc895d6b2016-08-11 13:26:41 -04004324 expectedError: expectedClientError,
4325 expectedLocalError: expectedClientLocalError,
Adam Langleyd9e397b2015-01-22 14:27:53 -08004326 })
4327
4328 testCases = append(testCases, testCase{
4329 protocol: protocol,
4330 testType: serverTest,
4331 name: "MinimumVersion-Server-" + suffix,
4332 config: Config{
4333 MaxVersion: runnerVers.version,
4334 },
4335 flags: flags,
4336 expectedVersion: expectedVersion,
4337 shouldFail: shouldFail,
David Benjaminc895d6b2016-08-11 13:26:41 -04004338 expectedError: expectedServerError,
4339 expectedLocalError: expectedServerLocalError,
Adam Langleyd9e397b2015-01-22 14:27:53 -08004340 })
4341 testCases = append(testCases, testCase{
4342 protocol: protocol,
4343 testType: serverTest,
4344 name: "MinimumVersion-Server2-" + suffix,
4345 config: Config{
4346 MaxVersion: runnerVers.version,
4347 },
4348 flags: []string{"-min-version", shimVersFlag},
4349 expectedVersion: expectedVersion,
4350 shouldFail: shouldFail,
David Benjaminc895d6b2016-08-11 13:26:41 -04004351 expectedError: expectedServerError,
4352 expectedLocalError: expectedServerLocalError,
Adam Langleyd9e397b2015-01-22 14:27:53 -08004353 })
4354 }
4355 }
4356 }
4357}
4358
Adam Langleyd9e397b2015-01-22 14:27:53 -08004359func addExtensionTests() {
David Benjaminc895d6b2016-08-11 13:26:41 -04004360 // TODO(davidben): Extensions, where applicable, all move their server
4361 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4362 // tests for both. Also test interaction with 0-RTT when implemented.
4363
4364 // Repeat extensions tests all versions except SSL 3.0.
4365 for _, ver := range tlsVersions {
4366 if ver.version == VersionSSL30 {
4367 continue
4368 }
4369
David Benjaminc895d6b2016-08-11 13:26:41 -04004370 // Test that duplicate extensions are rejected.
4371 testCases = append(testCases, testCase{
4372 testType: clientTest,
4373 name: "DuplicateExtensionClient-" + ver.name,
4374 config: Config{
4375 MaxVersion: ver.version,
4376 Bugs: ProtocolBugs{
4377 DuplicateExtension: true,
4378 },
Adam Langleyd9e397b2015-01-22 14:27:53 -08004379 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004380 shouldFail: true,
4381 expectedLocalError: "remote error: error decoding message",
4382 })
4383 testCases = append(testCases, testCase{
4384 testType: serverTest,
4385 name: "DuplicateExtensionServer-" + ver.name,
4386 config: Config{
4387 MaxVersion: ver.version,
4388 Bugs: ProtocolBugs{
4389 DuplicateExtension: true,
4390 },
Adam Langleyd9e397b2015-01-22 14:27:53 -08004391 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004392 shouldFail: true,
4393 expectedLocalError: "remote error: error decoding message",
4394 })
4395
4396 // Test SNI.
4397 testCases = append(testCases, testCase{
4398 testType: clientTest,
4399 name: "ServerNameExtensionClient-" + ver.name,
4400 config: Config{
4401 MaxVersion: ver.version,
4402 Bugs: ProtocolBugs{
4403 ExpectServerName: "example.com",
4404 },
Adam Langleyd9e397b2015-01-22 14:27:53 -08004405 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004406 flags: []string{"-host-name", "example.com"},
4407 })
4408 testCases = append(testCases, testCase{
4409 testType: clientTest,
4410 name: "ServerNameExtensionClientMismatch-" + ver.name,
4411 config: Config{
4412 MaxVersion: ver.version,
4413 Bugs: ProtocolBugs{
4414 ExpectServerName: "mismatch.com",
4415 },
Adam Langleyd9e397b2015-01-22 14:27:53 -08004416 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004417 flags: []string{"-host-name", "example.com"},
4418 shouldFail: true,
4419 expectedLocalError: "tls: unexpected server name",
4420 })
4421 testCases = append(testCases, testCase{
4422 testType: clientTest,
4423 name: "ServerNameExtensionClientMissing-" + ver.name,
4424 config: Config{
4425 MaxVersion: ver.version,
4426 Bugs: ProtocolBugs{
4427 ExpectServerName: "missing.com",
4428 },
Adam Langleyd9e397b2015-01-22 14:27:53 -08004429 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004430 shouldFail: true,
4431 expectedLocalError: "tls: unexpected server name",
4432 })
4433 testCases = append(testCases, testCase{
4434 testType: serverTest,
4435 name: "ServerNameExtensionServer-" + ver.name,
4436 config: Config{
4437 MaxVersion: ver.version,
4438 ServerName: "example.com",
Adam Langleyd9e397b2015-01-22 14:27:53 -08004439 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004440 flags: []string{"-expect-server-name", "example.com"},
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004441 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04004442 })
4443
4444 // Test ALPN.
4445 testCases = append(testCases, testCase{
4446 testType: clientTest,
4447 name: "ALPNClient-" + ver.name,
4448 config: Config{
4449 MaxVersion: ver.version,
4450 NextProtos: []string{"foo"},
4451 },
4452 flags: []string{
4453 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4454 "-expect-alpn", "foo",
4455 },
4456 expectedNextProto: "foo",
4457 expectedNextProtoType: alpn,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004458 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04004459 })
4460 testCases = append(testCases, testCase{
4461 testType: clientTest,
4462 name: "ALPNClient-Mismatch-" + ver.name,
4463 config: Config{
4464 MaxVersion: ver.version,
4465 Bugs: ProtocolBugs{
4466 SendALPN: "baz",
4467 },
4468 },
4469 flags: []string{
4470 "-advertise-alpn", "\x03foo\x03bar",
4471 },
4472 shouldFail: true,
4473 expectedError: ":INVALID_ALPN_PROTOCOL:",
4474 expectedLocalError: "remote error: illegal parameter",
4475 })
4476 testCases = append(testCases, testCase{
4477 testType: serverTest,
4478 name: "ALPNServer-" + ver.name,
4479 config: Config{
4480 MaxVersion: ver.version,
4481 NextProtos: []string{"foo", "bar", "baz"},
4482 },
4483 flags: []string{
4484 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4485 "-select-alpn", "foo",
4486 },
4487 expectedNextProto: "foo",
4488 expectedNextProtoType: alpn,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004489 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04004490 })
4491 testCases = append(testCases, testCase{
4492 testType: serverTest,
4493 name: "ALPNServer-Decline-" + ver.name,
4494 config: Config{
4495 MaxVersion: ver.version,
4496 NextProtos: []string{"foo", "bar", "baz"},
4497 },
4498 flags: []string{"-decline-alpn"},
4499 expectNoNextProto: true,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004500 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04004501 })
4502
4503 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4504 // called once.
4505 testCases = append(testCases, testCase{
4506 testType: serverTest,
4507 name: "ALPNServer-Async-" + ver.name,
4508 config: Config{
4509 MaxVersion: ver.version,
4510 NextProtos: []string{"foo", "bar", "baz"},
4511 },
4512 flags: []string{
4513 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4514 "-select-alpn", "foo",
4515 "-async",
4516 },
4517 expectedNextProto: "foo",
4518 expectedNextProtoType: alpn,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004519 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04004520 })
4521
4522 var emptyString string
4523 testCases = append(testCases, testCase{
4524 testType: clientTest,
4525 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4526 config: Config{
4527 MaxVersion: ver.version,
4528 NextProtos: []string{""},
4529 Bugs: ProtocolBugs{
4530 // A server returning an empty ALPN protocol
4531 // should be rejected.
4532 ALPNProtocol: &emptyString,
4533 },
4534 },
4535 flags: []string{
4536 "-advertise-alpn", "\x03foo",
4537 },
4538 shouldFail: true,
4539 expectedError: ":PARSE_TLSEXT:",
4540 })
4541 testCases = append(testCases, testCase{
4542 testType: serverTest,
4543 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4544 config: Config{
4545 MaxVersion: ver.version,
4546 // A ClientHello containing an empty ALPN protocol
Kenny Rootb8494592015-09-25 02:29:14 +00004547 // should be rejected.
David Benjaminc895d6b2016-08-11 13:26:41 -04004548 NextProtos: []string{"foo", "", "baz"},
Kenny Rootb8494592015-09-25 02:29:14 +00004549 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004550 flags: []string{
4551 "-select-alpn", "foo",
Kenny Rootb8494592015-09-25 02:29:14 +00004552 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004553 shouldFail: true,
4554 expectedError: ":PARSE_TLSEXT:",
4555 })
4556
4557 // Test NPN and the interaction with ALPN.
4558 if ver.version < VersionTLS13 {
4559 // Test that the server prefers ALPN over NPN.
4560 testCases = append(testCases, testCase{
4561 testType: serverTest,
4562 name: "ALPNServer-Preferred-" + ver.name,
4563 config: Config{
4564 MaxVersion: ver.version,
4565 NextProtos: []string{"foo", "bar", "baz"},
4566 },
4567 flags: []string{
4568 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4569 "-select-alpn", "foo",
4570 "-advertise-npn", "\x03foo\x03bar\x03baz",
4571 },
4572 expectedNextProto: "foo",
4573 expectedNextProtoType: alpn,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004574 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04004575 })
4576 testCases = append(testCases, testCase{
4577 testType: serverTest,
4578 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4579 config: Config{
4580 MaxVersion: ver.version,
4581 NextProtos: []string{"foo", "bar", "baz"},
4582 Bugs: ProtocolBugs{
4583 SwapNPNAndALPN: true,
4584 },
4585 },
4586 flags: []string{
4587 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4588 "-select-alpn", "foo",
4589 "-advertise-npn", "\x03foo\x03bar\x03baz",
4590 },
4591 expectedNextProto: "foo",
4592 expectedNextProtoType: alpn,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004593 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04004594 })
4595
4596 // Test that negotiating both NPN and ALPN is forbidden.
4597 testCases = append(testCases, testCase{
4598 name: "NegotiateALPNAndNPN-" + ver.name,
4599 config: Config{
4600 MaxVersion: ver.version,
4601 NextProtos: []string{"foo", "bar", "baz"},
4602 Bugs: ProtocolBugs{
4603 NegotiateALPNAndNPN: true,
4604 },
4605 },
4606 flags: []string{
4607 "-advertise-alpn", "\x03foo",
4608 "-select-next-proto", "foo",
4609 },
4610 shouldFail: true,
4611 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4612 })
4613 testCases = append(testCases, testCase{
4614 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4615 config: Config{
4616 MaxVersion: ver.version,
4617 NextProtos: []string{"foo", "bar", "baz"},
4618 Bugs: ProtocolBugs{
4619 NegotiateALPNAndNPN: true,
4620 SwapNPNAndALPN: true,
4621 },
4622 },
4623 flags: []string{
4624 "-advertise-alpn", "\x03foo",
4625 "-select-next-proto", "foo",
4626 },
4627 shouldFail: true,
4628 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4629 })
4630
4631 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4632 testCases = append(testCases, testCase{
4633 name: "DisableNPN-" + ver.name,
4634 config: Config{
4635 MaxVersion: ver.version,
4636 NextProtos: []string{"foo"},
4637 },
4638 flags: []string{
4639 "-select-next-proto", "foo",
4640 "-disable-npn",
4641 },
4642 expectNoNextProto: true,
4643 })
4644 }
4645
4646 // Test ticket behavior.
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004647
4648 // Resume with a corrupt ticket.
4649 testCases = append(testCases, testCase{
4650 testType: serverTest,
4651 name: "CorruptTicket-" + ver.name,
4652 config: Config{
4653 MaxVersion: ver.version,
4654 Bugs: ProtocolBugs{
4655 CorruptTicket: true,
4656 },
4657 },
4658 resumeSession: true,
4659 expectResumeRejected: true,
4660 })
4661 // Test the ticket callback, with and without renewal.
4662 testCases = append(testCases, testCase{
4663 testType: serverTest,
4664 name: "TicketCallback-" + ver.name,
4665 config: Config{
4666 MaxVersion: ver.version,
4667 },
4668 resumeSession: true,
4669 flags: []string{"-use-ticket-callback"},
4670 })
4671 testCases = append(testCases, testCase{
4672 testType: serverTest,
4673 name: "TicketCallback-Renew-" + ver.name,
4674 config: Config{
4675 MaxVersion: ver.version,
4676 Bugs: ProtocolBugs{
4677 ExpectNewTicket: true,
4678 },
4679 },
4680 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4681 resumeSession: true,
4682 })
4683
4684 // Test that the ticket callback is only called once when everything before
4685 // it in the ClientHello is asynchronous. This corrupts the ticket so
4686 // certificate selection callbacks run.
4687 testCases = append(testCases, testCase{
4688 testType: serverTest,
4689 name: "TicketCallback-SingleCall-" + ver.name,
4690 config: Config{
4691 MaxVersion: ver.version,
4692 Bugs: ProtocolBugs{
4693 CorruptTicket: true,
4694 },
4695 },
4696 resumeSession: true,
4697 expectResumeRejected: true,
4698 flags: []string{
4699 "-use-ticket-callback",
4700 "-async",
4701 },
4702 })
4703
4704 // Resume with an oversized session id.
David Benjaminc895d6b2016-08-11 13:26:41 -04004705 if ver.version < VersionTLS13 {
David Benjaminc895d6b2016-08-11 13:26:41 -04004706 testCases = append(testCases, testCase{
4707 testType: serverTest,
4708 name: "OversizedSessionId-" + ver.name,
4709 config: Config{
4710 MaxVersion: ver.version,
4711 Bugs: ProtocolBugs{
4712 OversizedSessionId: true,
4713 },
4714 },
4715 resumeSession: true,
4716 shouldFail: true,
4717 expectedError: ":DECODE_ERROR:",
4718 })
4719 }
4720
4721 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4722 // are ignored.
4723 if ver.hasDTLS {
4724 testCases = append(testCases, testCase{
4725 protocol: dtls,
4726 name: "SRTP-Client-" + ver.name,
4727 config: Config{
4728 MaxVersion: ver.version,
4729 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4730 },
4731 flags: []string{
4732 "-srtp-profiles",
4733 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4734 },
4735 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4736 })
4737 testCases = append(testCases, testCase{
4738 protocol: dtls,
4739 testType: serverTest,
4740 name: "SRTP-Server-" + ver.name,
4741 config: Config{
4742 MaxVersion: ver.version,
4743 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4744 },
4745 flags: []string{
4746 "-srtp-profiles",
4747 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4748 },
4749 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4750 })
4751 // Test that the MKI is ignored.
4752 testCases = append(testCases, testCase{
4753 protocol: dtls,
4754 testType: serverTest,
4755 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4756 config: Config{
4757 MaxVersion: ver.version,
4758 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4759 Bugs: ProtocolBugs{
4760 SRTPMasterKeyIdentifer: "bogus",
4761 },
4762 },
4763 flags: []string{
4764 "-srtp-profiles",
4765 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4766 },
4767 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4768 })
4769 // Test that SRTP isn't negotiated on the server if there were
4770 // no matching profiles.
4771 testCases = append(testCases, testCase{
4772 protocol: dtls,
4773 testType: serverTest,
4774 name: "SRTP-Server-NoMatch-" + ver.name,
4775 config: Config{
4776 MaxVersion: ver.version,
4777 SRTPProtectionProfiles: []uint16{100, 101, 102},
4778 },
4779 flags: []string{
4780 "-srtp-profiles",
4781 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4782 },
4783 expectedSRTPProtectionProfile: 0,
4784 })
4785 // Test that the server returning an invalid SRTP profile is
4786 // flagged as an error by the client.
4787 testCases = append(testCases, testCase{
4788 protocol: dtls,
4789 name: "SRTP-Client-NoMatch-" + ver.name,
4790 config: Config{
4791 MaxVersion: ver.version,
4792 Bugs: ProtocolBugs{
4793 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4794 },
4795 },
4796 flags: []string{
4797 "-srtp-profiles",
4798 "SRTP_AES128_CM_SHA1_80",
4799 },
4800 shouldFail: true,
4801 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4802 })
4803 }
4804
4805 // Test SCT list.
4806 testCases = append(testCases, testCase{
4807 name: "SignedCertificateTimestampList-Client-" + ver.name,
4808 testType: clientTest,
4809 config: Config{
4810 MaxVersion: ver.version,
Kenny Rootb8494592015-09-25 02:29:14 +00004811 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004812 flags: []string{
4813 "-enable-signed-cert-timestamps",
4814 "-expect-signed-cert-timestamps",
4815 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langleyd9e397b2015-01-22 14:27:53 -08004816 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004817 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04004818 })
4819 testCases = append(testCases, testCase{
4820 name: "SendSCTListOnResume-" + ver.name,
4821 config: Config{
4822 MaxVersion: ver.version,
4823 Bugs: ProtocolBugs{
4824 SendSCTListOnResume: []byte("bogus"),
4825 },
Kenny Rootb8494592015-09-25 02:29:14 +00004826 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004827 flags: []string{
4828 "-enable-signed-cert-timestamps",
4829 "-expect-signed-cert-timestamps",
4830 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langleyd9e397b2015-01-22 14:27:53 -08004831 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004832 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04004833 })
4834 testCases = append(testCases, testCase{
4835 name: "SignedCertificateTimestampList-Server-" + ver.name,
4836 testType: serverTest,
4837 config: Config{
4838 MaxVersion: ver.version,
Adam Langleyd9e397b2015-01-22 14:27:53 -08004839 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004840 flags: []string{
4841 "-signed-cert-timestamps",
4842 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langleyd9e397b2015-01-22 14:27:53 -08004843 },
David Benjaminc895d6b2016-08-11 13:26:41 -04004844 expectedSCTList: testSCTList,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04004845 resumeSession: true,
David Benjaminc895d6b2016-08-11 13:26:41 -04004846 })
4847 }
4848
Kenny Rootb8494592015-09-25 02:29:14 +00004849 testCases = append(testCases, testCase{
4850 testType: clientTest,
4851 name: "ClientHelloPadding",
4852 config: Config{
4853 Bugs: ProtocolBugs{
4854 RequireClientHelloSize: 512,
4855 },
4856 },
4857 // This hostname just needs to be long enough to push the
4858 // ClientHello into F5's danger zone between 256 and 511 bytes
4859 // long.
4860 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
Adam Langleyd9e397b2015-01-22 14:27:53 -08004861 })
Kenny Roote99801b2015-11-06 15:31:15 -08004862
4863 // Extensions should not function in SSL 3.0.
4864 testCases = append(testCases, testCase{
4865 testType: serverTest,
4866 name: "SSLv3Extensions-NoALPN",
4867 config: Config{
4868 MaxVersion: VersionSSL30,
4869 NextProtos: []string{"foo", "bar", "baz"},
4870 },
4871 flags: []string{
4872 "-select-alpn", "foo",
4873 },
4874 expectNoNextProto: true,
4875 })
4876
4877 // Test session tickets separately as they follow a different codepath.
4878 testCases = append(testCases, testCase{
4879 testType: serverTest,
4880 name: "SSLv3Extensions-NoTickets",
4881 config: Config{
4882 MaxVersion: VersionSSL30,
4883 Bugs: ProtocolBugs{
4884 // Historically, session tickets in SSL 3.0
4885 // failed in different ways depending on whether
4886 // the client supported renegotiation_info.
4887 NoRenegotiationInfo: true,
4888 },
4889 },
4890 resumeSession: true,
4891 })
4892 testCases = append(testCases, testCase{
4893 testType: serverTest,
4894 name: "SSLv3Extensions-NoTickets2",
4895 config: Config{
4896 MaxVersion: VersionSSL30,
4897 },
4898 resumeSession: true,
4899 })
4900
4901 // But SSL 3.0 does send and process renegotiation_info.
4902 testCases = append(testCases, testCase{
4903 testType: serverTest,
4904 name: "SSLv3Extensions-RenegotiationInfo",
4905 config: Config{
4906 MaxVersion: VersionSSL30,
4907 Bugs: ProtocolBugs{
4908 RequireRenegotiationInfo: true,
4909 },
4910 },
4911 })
4912 testCases = append(testCases, testCase{
4913 testType: serverTest,
4914 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4915 config: Config{
4916 MaxVersion: VersionSSL30,
4917 Bugs: ProtocolBugs{
4918 NoRenegotiationInfo: true,
4919 SendRenegotiationSCSV: true,
4920 RequireRenegotiationInfo: true,
4921 },
4922 },
4923 })
David Benjaminc895d6b2016-08-11 13:26:41 -04004924
4925 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4926 // in ServerHello.
4927 testCases = append(testCases, testCase{
4928 name: "NPN-Forbidden-TLS13",
4929 config: Config{
4930 MaxVersion: VersionTLS13,
4931 NextProtos: []string{"foo"},
4932 Bugs: ProtocolBugs{
4933 NegotiateNPNAtAllVersions: true,
4934 },
4935 },
4936 flags: []string{"-select-next-proto", "foo"},
4937 shouldFail: true,
4938 expectedError: ":ERROR_PARSING_EXTENSION:",
4939 })
4940 testCases = append(testCases, testCase{
4941 name: "EMS-Forbidden-TLS13",
4942 config: Config{
4943 MaxVersion: VersionTLS13,
4944 Bugs: ProtocolBugs{
4945 NegotiateEMSAtAllVersions: true,
4946 },
4947 },
4948 shouldFail: true,
4949 expectedError: ":ERROR_PARSING_EXTENSION:",
4950 })
4951 testCases = append(testCases, testCase{
4952 name: "RenegotiationInfo-Forbidden-TLS13",
4953 config: Config{
4954 MaxVersion: VersionTLS13,
4955 Bugs: ProtocolBugs{
4956 NegotiateRenegotiationInfoAtAllVersions: true,
4957 },
4958 },
4959 shouldFail: true,
4960 expectedError: ":ERROR_PARSING_EXTENSION:",
4961 })
4962 testCases = append(testCases, testCase{
4963 name: "ChannelID-Forbidden-TLS13",
4964 config: Config{
4965 MaxVersion: VersionTLS13,
4966 RequestChannelID: true,
4967 Bugs: ProtocolBugs{
4968 NegotiateChannelIDAtAllVersions: true,
4969 },
4970 },
4971 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4972 shouldFail: true,
4973 expectedError: ":ERROR_PARSING_EXTENSION:",
4974 })
4975 testCases = append(testCases, testCase{
4976 name: "Ticket-Forbidden-TLS13",
4977 config: Config{
4978 MaxVersion: VersionTLS12,
4979 },
4980 resumeConfig: &Config{
4981 MaxVersion: VersionTLS13,
4982 Bugs: ProtocolBugs{
4983 AdvertiseTicketExtension: true,
4984 },
4985 },
4986 resumeSession: true,
4987 shouldFail: true,
4988 expectedError: ":ERROR_PARSING_EXTENSION:",
4989 })
4990
4991 // Test that illegal extensions in TLS 1.3 are declined by the server if
4992 // offered in ClientHello. The runner's server will fail if this occurs,
4993 // so we exercise the offering path. (EMS and Renegotiation Info are
4994 // implicit in every test.)
4995 testCases = append(testCases, testCase{
4996 testType: serverTest,
4997 name: "ChannelID-Declined-TLS13",
4998 config: Config{
4999 MaxVersion: VersionTLS13,
5000 ChannelID: channelIDKey,
5001 },
5002 flags: []string{"-enable-channel-id"},
5003 })
5004 testCases = append(testCases, testCase{
5005 testType: serverTest,
5006 name: "NPN-Server",
5007 config: Config{
5008 MaxVersion: VersionTLS13,
5009 NextProtos: []string{"bar"},
5010 },
5011 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5012 })
Adam Langleyd9e397b2015-01-22 14:27:53 -08005013}
5014
5015func addResumptionVersionTests() {
5016 for _, sessionVers := range tlsVersions {
5017 for _, resumeVers := range tlsVersions {
David Benjaminc895d6b2016-08-11 13:26:41 -04005018 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5019 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5020 // TLS 1.3 only shares ciphers with TLS 1.2, so
5021 // we skip certain combinations and use a
5022 // different cipher to test with.
5023 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5024 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5025 continue
5026 }
5027 }
5028
Adam Langleyd9e397b2015-01-22 14:27:53 -08005029 protocols := []protocol{tls}
5030 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5031 protocols = append(protocols, dtls)
5032 }
5033 for _, protocol := range protocols {
5034 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5035 if protocol == dtls {
5036 suffix += "-DTLS"
5037 }
5038
Adam Langleye9ada862015-05-11 17:20:37 -07005039 if sessionVers.version == resumeVers.version {
5040 testCases = append(testCases, testCase{
5041 protocol: protocol,
5042 name: "Resume-Client" + suffix,
5043 resumeSession: true,
5044 config: Config{
5045 MaxVersion: sessionVers.version,
David Benjaminc895d6b2016-08-11 13:26:41 -04005046 CipherSuites: []uint16{cipher},
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005047 Bugs: ProtocolBugs{
5048 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5049 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5050 },
Adam Langleyd9e397b2015-01-22 14:27:53 -08005051 },
Adam Langleye9ada862015-05-11 17:20:37 -07005052 expectedVersion: sessionVers.version,
5053 expectedResumeVersion: resumeVers.version,
5054 })
5055 } else {
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005056 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5057
5058 // Offering a TLS 1.3 session sends an empty session ID, so
5059 // there is no way to convince a non-lookahead client the
5060 // session was resumed. It will appear to the client that a
5061 // stray ChangeCipherSpec was sent.
5062 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5063 error = ":UNEXPECTED_RECORD:"
5064 }
5065
Adam Langleye9ada862015-05-11 17:20:37 -07005066 testCases = append(testCases, testCase{
5067 protocol: protocol,
5068 name: "Resume-Client-Mismatch" + suffix,
5069 resumeSession: true,
5070 config: Config{
5071 MaxVersion: sessionVers.version,
David Benjaminc895d6b2016-08-11 13:26:41 -04005072 CipherSuites: []uint16{cipher},
Adam Langleyd9e397b2015-01-22 14:27:53 -08005073 },
Adam Langleye9ada862015-05-11 17:20:37 -07005074 expectedVersion: sessionVers.version,
5075 resumeConfig: &Config{
5076 MaxVersion: resumeVers.version,
David Benjaminc895d6b2016-08-11 13:26:41 -04005077 CipherSuites: []uint16{cipher},
Adam Langleye9ada862015-05-11 17:20:37 -07005078 Bugs: ProtocolBugs{
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005079 AcceptAnySession: true,
Adam Langleye9ada862015-05-11 17:20:37 -07005080 },
5081 },
5082 expectedResumeVersion: resumeVers.version,
5083 shouldFail: true,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005084 expectedError: error,
Adam Langleye9ada862015-05-11 17:20:37 -07005085 })
5086 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08005087
5088 testCases = append(testCases, testCase{
5089 protocol: protocol,
5090 name: "Resume-Client-NoResume" + suffix,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005091 resumeSession: true,
5092 config: Config{
5093 MaxVersion: sessionVers.version,
David Benjaminc895d6b2016-08-11 13:26:41 -04005094 CipherSuites: []uint16{cipher},
Adam Langleyd9e397b2015-01-22 14:27:53 -08005095 },
5096 expectedVersion: sessionVers.version,
5097 resumeConfig: &Config{
5098 MaxVersion: resumeVers.version,
David Benjaminc895d6b2016-08-11 13:26:41 -04005099 CipherSuites: []uint16{cipher},
Adam Langleyd9e397b2015-01-22 14:27:53 -08005100 },
5101 newSessionsOnResume: true,
Adam Langleyf4e42722015-06-04 17:45:09 -07005102 expectResumeRejected: true,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005103 expectedResumeVersion: resumeVers.version,
5104 })
5105
Adam Langleyd9e397b2015-01-22 14:27:53 -08005106 testCases = append(testCases, testCase{
5107 protocol: protocol,
5108 testType: serverTest,
5109 name: "Resume-Server" + suffix,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005110 resumeSession: true,
5111 config: Config{
5112 MaxVersion: sessionVers.version,
David Benjaminc895d6b2016-08-11 13:26:41 -04005113 CipherSuites: []uint16{cipher},
Adam Langleyd9e397b2015-01-22 14:27:53 -08005114 },
Adam Langleyf4e42722015-06-04 17:45:09 -07005115 expectedVersion: sessionVers.version,
5116 expectResumeRejected: sessionVers.version != resumeVers.version,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005117 resumeConfig: &Config{
5118 MaxVersion: resumeVers.version,
David Benjaminc895d6b2016-08-11 13:26:41 -04005119 CipherSuites: []uint16{cipher},
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005120 Bugs: ProtocolBugs{
5121 SendBothTickets: true,
5122 },
Adam Langleyd9e397b2015-01-22 14:27:53 -08005123 },
5124 expectedResumeVersion: resumeVers.version,
5125 })
5126 }
5127 }
5128 }
Adam Langleye9ada862015-05-11 17:20:37 -07005129
5130 testCases = append(testCases, testCase{
5131 name: "Resume-Client-CipherMismatch",
5132 resumeSession: true,
5133 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005134 MaxVersion: VersionTLS12,
Adam Langleye9ada862015-05-11 17:20:37 -07005135 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5136 },
5137 resumeConfig: &Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005138 MaxVersion: VersionTLS12,
Adam Langleye9ada862015-05-11 17:20:37 -07005139 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5140 Bugs: ProtocolBugs{
5141 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5142 },
5143 },
5144 shouldFail: true,
5145 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5146 })
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005147
5148 testCases = append(testCases, testCase{
5149 name: "Resume-Client-CipherMismatch-TLS13",
5150 resumeSession: true,
5151 config: Config{
5152 MaxVersion: VersionTLS13,
5153 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5154 },
5155 resumeConfig: &Config{
5156 MaxVersion: VersionTLS13,
5157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5158 Bugs: ProtocolBugs{
5159 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5160 },
5161 },
5162 shouldFail: true,
5163 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5164 })
Adam Langleyd9e397b2015-01-22 14:27:53 -08005165}
5166
5167func addRenegotiationTests() {
Adam Langleyf4e42722015-06-04 17:45:09 -07005168 // Servers cannot renegotiate.
Adam Langleye9ada862015-05-11 17:20:37 -07005169 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04005170 testType: serverTest,
5171 name: "Renegotiate-Server-Forbidden",
5172 config: Config{
5173 MaxVersion: VersionTLS12,
5174 },
Kenny Roote99801b2015-11-06 15:31:15 -08005175 renegotiate: 1,
Adam Langleye9ada862015-05-11 17:20:37 -07005176 shouldFail: true,
5177 expectedError: ":NO_RENEGOTIATION:",
5178 expectedLocalError: "remote error: no renegotiation",
5179 })
Kenny Rootb8494592015-09-25 02:29:14 +00005180 // The server shouldn't echo the renegotiation extension unless
5181 // requested by the client.
5182 testCases = append(testCases, testCase{
5183 testType: serverTest,
5184 name: "Renegotiate-Server-NoExt",
5185 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005186 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00005187 Bugs: ProtocolBugs{
5188 NoRenegotiationInfo: true,
5189 RequireRenegotiationInfo: true,
5190 },
5191 },
5192 shouldFail: true,
5193 expectedLocalError: "renegotiation extension missing",
5194 })
5195 // The renegotiation SCSV should be sufficient for the server to echo
5196 // the extension.
5197 testCases = append(testCases, testCase{
5198 testType: serverTest,
5199 name: "Renegotiate-Server-NoExt-SCSV",
5200 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005201 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00005202 Bugs: ProtocolBugs{
5203 NoRenegotiationInfo: true,
5204 SendRenegotiationSCSV: true,
5205 RequireRenegotiationInfo: true,
5206 },
5207 },
5208 })
Adam Langleyd9e397b2015-01-22 14:27:53 -08005209 testCases = append(testCases, testCase{
Adam Langleyf4e42722015-06-04 17:45:09 -07005210 name: "Renegotiate-Client",
Adam Langleye9ada862015-05-11 17:20:37 -07005211 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005212 MaxVersion: VersionTLS12,
Adam Langleye9ada862015-05-11 17:20:37 -07005213 Bugs: ProtocolBugs{
Adam Langleyf4e42722015-06-04 17:45:09 -07005214 FailIfResumeOnRenego: true,
Adam Langleye9ada862015-05-11 17:20:37 -07005215 },
5216 },
Kenny Roote99801b2015-11-06 15:31:15 -08005217 renegotiate: 1,
5218 flags: []string{
5219 "-renegotiate-freely",
5220 "-expect-total-renegotiations", "1",
5221 },
Adam Langleye9ada862015-05-11 17:20:37 -07005222 })
5223 testCases = append(testCases, testCase{
Adam Langleyd9e397b2015-01-22 14:27:53 -08005224 name: "Renegotiate-Client-EmptyExt",
Kenny Roote99801b2015-11-06 15:31:15 -08005225 renegotiate: 1,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005226 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005227 MaxVersion: VersionTLS12,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005228 Bugs: ProtocolBugs{
5229 EmptyRenegotiationInfo: true,
5230 },
5231 },
Kenny Roote99801b2015-11-06 15:31:15 -08005232 flags: []string{"-renegotiate-freely"},
Adam Langleyd9e397b2015-01-22 14:27:53 -08005233 shouldFail: true,
5234 expectedError: ":RENEGOTIATION_MISMATCH:",
5235 })
5236 testCases = append(testCases, testCase{
5237 name: "Renegotiate-Client-BadExt",
Kenny Roote99801b2015-11-06 15:31:15 -08005238 renegotiate: 1,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005239 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005240 MaxVersion: VersionTLS12,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005241 Bugs: ProtocolBugs{
5242 BadRenegotiationInfo: true,
5243 },
5244 },
Kenny Roote99801b2015-11-06 15:31:15 -08005245 flags: []string{"-renegotiate-freely"},
Adam Langleyd9e397b2015-01-22 14:27:53 -08005246 shouldFail: true,
5247 expectedError: ":RENEGOTIATION_MISMATCH:",
5248 })
5249 testCases = append(testCases, testCase{
Adam Langley4139edb2016-01-13 15:00:54 -08005250 name: "Renegotiate-Client-Downgrade",
5251 renegotiate: 1,
Adam Langleyf4e42722015-06-04 17:45:09 -07005252 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005253 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07005254 Bugs: ProtocolBugs{
Adam Langley4139edb2016-01-13 15:00:54 -08005255 NoRenegotiationInfoAfterInitial: true,
Adam Langleyf4e42722015-06-04 17:45:09 -07005256 },
5257 },
Adam Langley4139edb2016-01-13 15:00:54 -08005258 flags: []string{"-renegotiate-freely"},
Adam Langleyf4e42722015-06-04 17:45:09 -07005259 shouldFail: true,
Adam Langley4139edb2016-01-13 15:00:54 -08005260 expectedError: ":RENEGOTIATION_MISMATCH:",
5261 })
5262 testCases = append(testCases, testCase{
5263 name: "Renegotiate-Client-Upgrade",
5264 renegotiate: 1,
5265 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005266 MaxVersion: VersionTLS12,
Adam Langley4139edb2016-01-13 15:00:54 -08005267 Bugs: ProtocolBugs{
5268 NoRenegotiationInfoInInitial: true,
5269 },
5270 },
5271 flags: []string{"-renegotiate-freely"},
5272 shouldFail: true,
5273 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langleyf4e42722015-06-04 17:45:09 -07005274 })
5275 testCases = append(testCases, testCase{
5276 name: "Renegotiate-Client-NoExt-Allowed",
Kenny Roote99801b2015-11-06 15:31:15 -08005277 renegotiate: 1,
Adam Langleyf4e42722015-06-04 17:45:09 -07005278 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005279 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07005280 Bugs: ProtocolBugs{
5281 NoRenegotiationInfo: true,
5282 },
5283 },
Kenny Roote99801b2015-11-06 15:31:15 -08005284 flags: []string{
5285 "-renegotiate-freely",
5286 "-expect-total-renegotiations", "1",
5287 },
Adam Langleyf4e42722015-06-04 17:45:09 -07005288 })
David Benjaminc895d6b2016-08-11 13:26:41 -04005289
5290 // Test that the server may switch ciphers on renegotiation without
5291 // problems.
Adam Langleyf4e42722015-06-04 17:45:09 -07005292 testCases = append(testCases, testCase{
Adam Langleyd9e397b2015-01-22 14:27:53 -08005293 name: "Renegotiate-Client-SwitchCiphers",
Kenny Roote99801b2015-11-06 15:31:15 -08005294 renegotiate: 1,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005295 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005296 MaxVersion: VersionTLS12,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005297 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleyd9e397b2015-01-22 14:27:53 -08005298 },
5299 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Kenny Roote99801b2015-11-06 15:31:15 -08005300 flags: []string{
5301 "-renegotiate-freely",
5302 "-expect-total-renegotiations", "1",
5303 },
Adam Langleyd9e397b2015-01-22 14:27:53 -08005304 })
5305 testCases = append(testCases, testCase{
5306 name: "Renegotiate-Client-SwitchCiphers2",
Kenny Roote99801b2015-11-06 15:31:15 -08005307 renegotiate: 1,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005308 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005309 MaxVersion: VersionTLS12,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005310 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5311 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005312 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Kenny Roote99801b2015-11-06 15:31:15 -08005313 flags: []string{
5314 "-renegotiate-freely",
5315 "-expect-total-renegotiations", "1",
5316 },
Adam Langleye9ada862015-05-11 17:20:37 -07005317 })
David Benjaminc895d6b2016-08-11 13:26:41 -04005318
5319 // Test that the server may not switch versions on renegotiation.
5320 testCases = append(testCases, testCase{
5321 name: "Renegotiate-Client-SwitchVersion",
5322 config: Config{
5323 MaxVersion: VersionTLS12,
5324 // Pick a cipher which exists at both versions.
5325 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5326 Bugs: ProtocolBugs{
5327 NegotiateVersionOnRenego: VersionTLS11,
5328 },
5329 },
5330 renegotiate: 1,
5331 flags: []string{
5332 "-renegotiate-freely",
5333 "-expect-total-renegotiations", "1",
5334 },
5335 shouldFail: true,
5336 expectedError: ":WRONG_SSL_VERSION:",
5337 })
5338
Adam Langleye9ada862015-05-11 17:20:37 -07005339 testCases = append(testCases, testCase{
Adam Langleyd9e397b2015-01-22 14:27:53 -08005340 name: "Renegotiate-SameClientVersion",
Kenny Roote99801b2015-11-06 15:31:15 -08005341 renegotiate: 1,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005342 config: Config{
5343 MaxVersion: VersionTLS10,
5344 Bugs: ProtocolBugs{
5345 RequireSameRenegoClientVersion: true,
5346 },
5347 },
Kenny Roote99801b2015-11-06 15:31:15 -08005348 flags: []string{
5349 "-renegotiate-freely",
5350 "-expect-total-renegotiations", "1",
5351 },
Adam Langleyd9e397b2015-01-22 14:27:53 -08005352 })
Kenny Rootb8494592015-09-25 02:29:14 +00005353 testCases = append(testCases, testCase{
5354 name: "Renegotiate-FalseStart",
Kenny Roote99801b2015-11-06 15:31:15 -08005355 renegotiate: 1,
Kenny Rootb8494592015-09-25 02:29:14 +00005356 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005357 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00005358 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5359 NextProtos: []string{"foo"},
5360 },
5361 flags: []string{
5362 "-false-start",
5363 "-select-next-proto", "foo",
Kenny Roote99801b2015-11-06 15:31:15 -08005364 "-renegotiate-freely",
5365 "-expect-total-renegotiations", "1",
Kenny Rootb8494592015-09-25 02:29:14 +00005366 },
5367 shimWritesFirst: true,
5368 })
Kenny Roote99801b2015-11-06 15:31:15 -08005369
5370 // Client-side renegotiation controls.
5371 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04005372 name: "Renegotiate-Client-Forbidden-1",
5373 config: Config{
5374 MaxVersion: VersionTLS12,
5375 },
Kenny Roote99801b2015-11-06 15:31:15 -08005376 renegotiate: 1,
5377 shouldFail: true,
5378 expectedError: ":NO_RENEGOTIATION:",
5379 expectedLocalError: "remote error: no renegotiation",
5380 })
5381 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04005382 name: "Renegotiate-Client-Once-1",
5383 config: Config{
5384 MaxVersion: VersionTLS12,
5385 },
Kenny Roote99801b2015-11-06 15:31:15 -08005386 renegotiate: 1,
5387 flags: []string{
5388 "-renegotiate-once",
5389 "-expect-total-renegotiations", "1",
5390 },
5391 })
5392 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04005393 name: "Renegotiate-Client-Freely-1",
5394 config: Config{
5395 MaxVersion: VersionTLS12,
5396 },
Kenny Roote99801b2015-11-06 15:31:15 -08005397 renegotiate: 1,
5398 flags: []string{
5399 "-renegotiate-freely",
5400 "-expect-total-renegotiations", "1",
5401 },
5402 })
5403 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04005404 name: "Renegotiate-Client-Once-2",
5405 config: Config{
5406 MaxVersion: VersionTLS12,
5407 },
Kenny Roote99801b2015-11-06 15:31:15 -08005408 renegotiate: 2,
5409 flags: []string{"-renegotiate-once"},
5410 shouldFail: true,
5411 expectedError: ":NO_RENEGOTIATION:",
5412 expectedLocalError: "remote error: no renegotiation",
5413 })
5414 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04005415 name: "Renegotiate-Client-Freely-2",
5416 config: Config{
5417 MaxVersion: VersionTLS12,
5418 },
Kenny Roote99801b2015-11-06 15:31:15 -08005419 renegotiate: 2,
5420 flags: []string{
5421 "-renegotiate-freely",
5422 "-expect-total-renegotiations", "2",
5423 },
5424 })
Adam Langleyfad63272015-11-12 12:15:39 -08005425 testCases = append(testCases, testCase{
5426 name: "Renegotiate-Client-NoIgnore",
5427 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005428 MaxVersion: VersionTLS12,
Adam Langleyfad63272015-11-12 12:15:39 -08005429 Bugs: ProtocolBugs{
5430 SendHelloRequestBeforeEveryAppDataRecord: true,
5431 },
5432 },
5433 shouldFail: true,
5434 expectedError: ":NO_RENEGOTIATION:",
5435 })
5436 testCases = append(testCases, testCase{
5437 name: "Renegotiate-Client-Ignore",
5438 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005439 MaxVersion: VersionTLS12,
Adam Langleyfad63272015-11-12 12:15:39 -08005440 Bugs: ProtocolBugs{
5441 SendHelloRequestBeforeEveryAppDataRecord: true,
5442 },
5443 },
5444 flags: []string{
5445 "-renegotiate-ignore",
5446 "-expect-total-renegotiations", "0",
5447 },
5448 })
David Benjaminc895d6b2016-08-11 13:26:41 -04005449
5450 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
5451 testCases = append(testCases, testCase{
5452 name: "StrayHelloRequest",
5453 config: Config{
5454 MaxVersion: VersionTLS12,
5455 Bugs: ProtocolBugs{
5456 SendHelloRequestBeforeEveryHandshakeMessage: true,
5457 },
5458 },
5459 })
5460 testCases = append(testCases, testCase{
5461 name: "StrayHelloRequest-Packed",
5462 config: Config{
5463 MaxVersion: VersionTLS12,
5464 Bugs: ProtocolBugs{
5465 PackHandshakeFlight: true,
5466 SendHelloRequestBeforeEveryHandshakeMessage: true,
5467 },
5468 },
5469 })
5470
5471 // Test renegotiation works if HelloRequest and server Finished come in
5472 // the same record.
5473 testCases = append(testCases, testCase{
5474 name: "Renegotiate-Client-Packed",
5475 config: Config{
5476 MaxVersion: VersionTLS12,
5477 Bugs: ProtocolBugs{
5478 PackHandshakeFlight: true,
5479 PackHelloRequestWithFinished: true,
5480 },
5481 },
5482 renegotiate: 1,
5483 flags: []string{
5484 "-renegotiate-freely",
5485 "-expect-total-renegotiations", "1",
5486 },
5487 })
5488
5489 // Renegotiation is forbidden in TLS 1.3.
5490 testCases = append(testCases, testCase{
5491 name: "Renegotiate-Client-TLS13",
5492 config: Config{
5493 MaxVersion: VersionTLS13,
5494 Bugs: ProtocolBugs{
5495 SendHelloRequestBeforeEveryAppDataRecord: true,
5496 },
5497 },
5498 flags: []string{
5499 "-renegotiate-freely",
5500 },
5501 shouldFail: true,
5502 expectedError: ":UNEXPECTED_MESSAGE:",
5503 })
5504
5505 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5506 testCases = append(testCases, testCase{
5507 name: "StrayHelloRequest-TLS13",
5508 config: Config{
5509 MaxVersion: VersionTLS13,
5510 Bugs: ProtocolBugs{
5511 SendHelloRequestBeforeEveryHandshakeMessage: true,
5512 },
5513 },
5514 shouldFail: true,
5515 expectedError: ":UNEXPECTED_MESSAGE:",
5516 })
Adam Langleyd9e397b2015-01-22 14:27:53 -08005517}
5518
5519func addDTLSReplayTests() {
5520 // Test that sequence number replays are detected.
5521 testCases = append(testCases, testCase{
5522 protocol: dtls,
5523 name: "DTLS-Replay",
Kenny Rootb8494592015-09-25 02:29:14 +00005524 messageCount: 200,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005525 replayWrites: true,
5526 })
5527
Kenny Rootb8494592015-09-25 02:29:14 +00005528 // Test the incoming sequence number skipping by values larger
Adam Langleyd9e397b2015-01-22 14:27:53 -08005529 // than the retransmit window.
5530 testCases = append(testCases, testCase{
5531 protocol: dtls,
5532 name: "DTLS-Replay-LargeGaps",
5533 config: Config{
5534 Bugs: ProtocolBugs{
Kenny Rootb8494592015-09-25 02:29:14 +00005535 SequenceNumberMapping: func(in uint64) uint64 {
5536 return in * 127
5537 },
Adam Langleyd9e397b2015-01-22 14:27:53 -08005538 },
5539 },
Kenny Rootb8494592015-09-25 02:29:14 +00005540 messageCount: 200,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005541 replayWrites: true,
5542 })
Adam Langleyd9e397b2015-01-22 14:27:53 -08005543
Kenny Rootb8494592015-09-25 02:29:14 +00005544 // Test the incoming sequence number changing non-monotonically.
Kenny Roota04d78d2015-09-25 00:26:37 +00005545 testCases = append(testCases, testCase{
5546 protocol: dtls,
Kenny Rootb8494592015-09-25 02:29:14 +00005547 name: "DTLS-Replay-NonMonotonic",
Kenny Roota04d78d2015-09-25 00:26:37 +00005548 config: Config{
5549 Bugs: ProtocolBugs{
Kenny Rootb8494592015-09-25 02:29:14 +00005550 SequenceNumberMapping: func(in uint64) uint64 {
5551 return in ^ 31
5552 },
Kenny Roota04d78d2015-09-25 00:26:37 +00005553 },
5554 },
Kenny Rootb8494592015-09-25 02:29:14 +00005555 messageCount: 200,
5556 replayWrites: true,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005557 })
5558}
5559
David Benjaminc895d6b2016-08-11 13:26:41 -04005560var testSignatureAlgorithms = []struct {
Adam Langleyd9e397b2015-01-22 14:27:53 -08005561 name string
David Benjaminc895d6b2016-08-11 13:26:41 -04005562 id signatureAlgorithm
5563 cert testCert
Adam Langleyd9e397b2015-01-22 14:27:53 -08005564}{
David Benjaminc895d6b2016-08-11 13:26:41 -04005565 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5566 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5567 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5568 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
5569 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
5570 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5571 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5572 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
5573 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5574 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5575 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
5576 // Tests for key types prior to TLS 1.2.
5577 {"RSA", 0, testCertRSA},
5578 {"ECDSA", 0, testCertECDSAP256},
Adam Langleyd9e397b2015-01-22 14:27:53 -08005579}
5580
David Benjaminc895d6b2016-08-11 13:26:41 -04005581const fakeSigAlg1 signatureAlgorithm = 0x2a01
5582const fakeSigAlg2 signatureAlgorithm = 0xff01
Adam Langleyd9e397b2015-01-22 14:27:53 -08005583
David Benjaminc895d6b2016-08-11 13:26:41 -04005584func addSignatureAlgorithmTests() {
5585 // Not all ciphers involve a signature. Advertise a list which gives all
5586 // versions a signing cipher.
5587 signingCiphers := []uint16{
5588 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5589 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5590 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5591 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5592 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005593 }
5594
David Benjaminc895d6b2016-08-11 13:26:41 -04005595 var allAlgorithms []signatureAlgorithm
5596 for _, alg := range testSignatureAlgorithms {
5597 if alg.id != 0 {
5598 allAlgorithms = append(allAlgorithms, alg.id)
5599 }
5600 }
5601
5602 // Make sure each signature algorithm works. Include some fake values in
5603 // the list and ensure they're ignored.
5604 for _, alg := range testSignatureAlgorithms {
5605 for _, ver := range tlsVersions {
5606 if (ver.version < VersionTLS12) != (alg.id == 0) {
5607 continue
5608 }
5609
5610 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5611 // or remove it in C.
5612 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
5613 continue
5614 }
5615
5616 var shouldFail bool
5617 // ecdsa_sha1 does not exist in TLS 1.3.
5618 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5619 shouldFail = true
5620 }
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005621 // RSA-PKCS1 does not exist in TLS 1.3.
5622 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjaminc895d6b2016-08-11 13:26:41 -04005623 shouldFail = true
5624 }
5625
5626 var signError, verifyError string
5627 if shouldFail {
5628 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5629 verifyError = ":WRONG_SIGNATURE_TYPE:"
5630 }
5631
5632 suffix := "-" + alg.name + "-" + ver.name
5633
5634 testCases = append(testCases, testCase{
5635 name: "ClientAuth-Sign" + suffix,
5636 config: Config{
5637 MaxVersion: ver.version,
5638 ClientAuth: RequireAnyClientCert,
5639 VerifySignatureAlgorithms: []signatureAlgorithm{
5640 fakeSigAlg1,
5641 alg.id,
5642 fakeSigAlg2,
5643 },
5644 },
5645 flags: []string{
5646 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5647 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5648 "-enable-all-curves",
5649 },
5650 shouldFail: shouldFail,
5651 expectedError: signError,
5652 expectedPeerSignatureAlgorithm: alg.id,
5653 })
5654
5655 testCases = append(testCases, testCase{
5656 testType: serverTest,
5657 name: "ClientAuth-Verify" + suffix,
5658 config: Config{
5659 MaxVersion: ver.version,
5660 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5661 SignSignatureAlgorithms: []signatureAlgorithm{
5662 alg.id,
5663 },
5664 Bugs: ProtocolBugs{
5665 SkipECDSACurveCheck: shouldFail,
5666 IgnoreSignatureVersionChecks: shouldFail,
5667 // The client won't advertise 1.3-only algorithms after
5668 // version negotiation.
5669 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
5670 },
5671 },
5672 flags: []string{
5673 "-require-any-client-certificate",
5674 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5675 "-enable-all-curves",
5676 },
5677 shouldFail: shouldFail,
5678 expectedError: verifyError,
5679 })
5680
5681 testCases = append(testCases, testCase{
5682 testType: serverTest,
5683 name: "ServerAuth-Sign" + suffix,
5684 config: Config{
5685 MaxVersion: ver.version,
5686 CipherSuites: signingCiphers,
5687 VerifySignatureAlgorithms: []signatureAlgorithm{
5688 fakeSigAlg1,
5689 alg.id,
5690 fakeSigAlg2,
5691 },
5692 },
5693 flags: []string{
5694 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5695 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5696 "-enable-all-curves",
5697 },
5698 shouldFail: shouldFail,
5699 expectedError: signError,
5700 expectedPeerSignatureAlgorithm: alg.id,
5701 })
5702
5703 testCases = append(testCases, testCase{
5704 name: "ServerAuth-Verify" + suffix,
5705 config: Config{
5706 MaxVersion: ver.version,
5707 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5708 CipherSuites: signingCiphers,
5709 SignSignatureAlgorithms: []signatureAlgorithm{
5710 alg.id,
5711 },
5712 Bugs: ProtocolBugs{
5713 SkipECDSACurveCheck: shouldFail,
5714 IgnoreSignatureVersionChecks: shouldFail,
5715 },
5716 },
5717 flags: []string{
5718 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5719 "-enable-all-curves",
5720 },
5721 shouldFail: shouldFail,
5722 expectedError: verifyError,
5723 })
5724
5725 if !shouldFail {
5726 testCases = append(testCases, testCase{
5727 testType: serverTest,
5728 name: "ClientAuth-InvalidSignature" + suffix,
5729 config: Config{
5730 MaxVersion: ver.version,
5731 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5732 SignSignatureAlgorithms: []signatureAlgorithm{
5733 alg.id,
5734 },
5735 Bugs: ProtocolBugs{
5736 InvalidSignature: true,
5737 },
5738 },
5739 flags: []string{
5740 "-require-any-client-certificate",
5741 "-enable-all-curves",
5742 },
5743 shouldFail: true,
5744 expectedError: ":BAD_SIGNATURE:",
5745 })
5746
5747 testCases = append(testCases, testCase{
5748 name: "ServerAuth-InvalidSignature" + suffix,
5749 config: Config{
5750 MaxVersion: ver.version,
5751 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5752 CipherSuites: signingCiphers,
5753 SignSignatureAlgorithms: []signatureAlgorithm{
5754 alg.id,
5755 },
5756 Bugs: ProtocolBugs{
5757 InvalidSignature: true,
5758 },
5759 },
5760 flags: []string{"-enable-all-curves"},
5761 shouldFail: true,
5762 expectedError: ":BAD_SIGNATURE:",
5763 })
5764 }
5765
5766 if ver.version >= VersionTLS12 && !shouldFail {
5767 testCases = append(testCases, testCase{
5768 name: "ClientAuth-Sign-Negotiate" + suffix,
5769 config: Config{
5770 MaxVersion: ver.version,
5771 ClientAuth: RequireAnyClientCert,
5772 VerifySignatureAlgorithms: allAlgorithms,
5773 },
5774 flags: []string{
5775 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5776 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5777 "-enable-all-curves",
5778 "-signing-prefs", strconv.Itoa(int(alg.id)),
5779 },
5780 expectedPeerSignatureAlgorithm: alg.id,
5781 })
5782
5783 testCases = append(testCases, testCase{
5784 testType: serverTest,
5785 name: "ServerAuth-Sign-Negotiate" + suffix,
5786 config: Config{
5787 MaxVersion: ver.version,
5788 CipherSuites: signingCiphers,
5789 VerifySignatureAlgorithms: allAlgorithms,
5790 },
5791 flags: []string{
5792 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5793 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5794 "-enable-all-curves",
5795 "-signing-prefs", strconv.Itoa(int(alg.id)),
5796 },
5797 expectedPeerSignatureAlgorithm: alg.id,
5798 })
5799 }
5800 }
5801 }
5802
5803 // Test that algorithm selection takes the key type into account.
Adam Langleyd9e397b2015-01-22 14:27:53 -08005804 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04005805 name: "ClientAuth-SignatureType",
Adam Langleyd9e397b2015-01-22 14:27:53 -08005806 config: Config{
5807 ClientAuth: RequireAnyClientCert,
David Benjaminc895d6b2016-08-11 13:26:41 -04005808 MaxVersion: VersionTLS12,
5809 VerifySignatureAlgorithms: []signatureAlgorithm{
5810 signatureECDSAWithP521AndSHA512,
5811 signatureRSAPKCS1WithSHA384,
5812 signatureECDSAWithSHA1,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005813 },
5814 },
5815 flags: []string{
Kenny Rootb8494592015-09-25 02:29:14 +00005816 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5817 "-key-file", path.Join(*resourceDir, rsaKeyFile),
Adam Langleyd9e397b2015-01-22 14:27:53 -08005818 },
David Benjaminc895d6b2016-08-11 13:26:41 -04005819 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005820 })
5821
5822 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04005823 name: "ClientAuth-SignatureType-TLS13",
Adam Langleyd9e397b2015-01-22 14:27:53 -08005824 config: Config{
5825 ClientAuth: RequireAnyClientCert,
David Benjaminc895d6b2016-08-11 13:26:41 -04005826 MaxVersion: VersionTLS13,
5827 VerifySignatureAlgorithms: []signatureAlgorithm{
5828 signatureECDSAWithP521AndSHA512,
5829 signatureRSAPKCS1WithSHA384,
5830 signatureRSAPSSWithSHA384,
5831 signatureECDSAWithSHA1,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005832 },
5833 },
5834 flags: []string{
Kenny Rootb8494592015-09-25 02:29:14 +00005835 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5836 "-key-file", path.Join(*resourceDir, rsaKeyFile),
Adam Langleyd9e397b2015-01-22 14:27:53 -08005837 },
David Benjaminc895d6b2016-08-11 13:26:41 -04005838 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005839 })
5840
5841 testCases = append(testCases, testCase{
5842 testType: serverTest,
David Benjaminc895d6b2016-08-11 13:26:41 -04005843 name: "ServerAuth-SignatureType",
Adam Langleyd9e397b2015-01-22 14:27:53 -08005844 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005845 MaxVersion: VersionTLS12,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005846 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminc895d6b2016-08-11 13:26:41 -04005847 VerifySignatureAlgorithms: []signatureAlgorithm{
5848 signatureECDSAWithP521AndSHA512,
5849 signatureRSAPKCS1WithSHA384,
5850 signatureECDSAWithSHA1,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005851 },
5852 },
David Benjaminc895d6b2016-08-11 13:26:41 -04005853 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
Adam Langleyd9e397b2015-01-22 14:27:53 -08005854 })
Adam Langleye9ada862015-05-11 17:20:37 -07005855
Adam Langleye9ada862015-05-11 17:20:37 -07005856 testCases = append(testCases, testCase{
5857 testType: serverTest,
David Benjaminc895d6b2016-08-11 13:26:41 -04005858 name: "ServerAuth-SignatureType-TLS13",
Adam Langleye9ada862015-05-11 17:20:37 -07005859 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04005860 MaxVersion: VersionTLS13,
5861 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5862 VerifySignatureAlgorithms: []signatureAlgorithm{
5863 signatureECDSAWithP521AndSHA512,
5864 signatureRSAPKCS1WithSHA384,
5865 signatureRSAPSSWithSHA384,
5866 signatureECDSAWithSHA1,
5867 },
5868 },
5869 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5870 })
5871
5872 // Test that signature verification takes the key type into account.
5873 testCases = append(testCases, testCase{
5874 testType: serverTest,
5875 name: "Verify-ClientAuth-SignatureType",
5876 config: Config{
5877 MaxVersion: VersionTLS12,
Adam Langleye9ada862015-05-11 17:20:37 -07005878 Certificates: []Certificate{rsaCertificate},
David Benjaminc895d6b2016-08-11 13:26:41 -04005879 SignSignatureAlgorithms: []signatureAlgorithm{
5880 signatureRSAPKCS1WithSHA256,
5881 },
5882 Bugs: ProtocolBugs{
5883 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5884 },
5885 },
5886 flags: []string{
5887 "-require-any-client-certificate",
5888 },
5889 shouldFail: true,
5890 expectedError: ":WRONG_SIGNATURE_TYPE:",
5891 })
5892
5893 testCases = append(testCases, testCase{
5894 testType: serverTest,
5895 name: "Verify-ClientAuth-SignatureType-TLS13",
5896 config: Config{
5897 MaxVersion: VersionTLS13,
5898 Certificates: []Certificate{rsaCertificate},
5899 SignSignatureAlgorithms: []signatureAlgorithm{
5900 signatureRSAPSSWithSHA256,
5901 },
5902 Bugs: ProtocolBugs{
5903 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5904 },
5905 },
5906 flags: []string{
5907 "-require-any-client-certificate",
5908 },
5909 shouldFail: true,
5910 expectedError: ":WRONG_SIGNATURE_TYPE:",
5911 })
5912
5913 testCases = append(testCases, testCase{
5914 name: "Verify-ServerAuth-SignatureType",
5915 config: Config{
5916 MaxVersion: VersionTLS12,
5917 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5918 SignSignatureAlgorithms: []signatureAlgorithm{
5919 signatureRSAPKCS1WithSHA256,
5920 },
5921 Bugs: ProtocolBugs{
5922 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5923 },
5924 },
5925 shouldFail: true,
5926 expectedError: ":WRONG_SIGNATURE_TYPE:",
5927 })
5928
5929 testCases = append(testCases, testCase{
5930 name: "Verify-ServerAuth-SignatureType-TLS13",
5931 config: Config{
5932 MaxVersion: VersionTLS13,
5933 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5934 SignSignatureAlgorithms: []signatureAlgorithm{
5935 signatureRSAPSSWithSHA256,
5936 },
5937 Bugs: ProtocolBugs{
5938 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5939 },
5940 },
5941 shouldFail: true,
5942 expectedError: ":WRONG_SIGNATURE_TYPE:",
5943 })
5944
5945 // Test that, if the list is missing, the peer falls back to SHA-1 in
5946 // TLS 1.2, but not TLS 1.3.
5947 testCases = append(testCases, testCase{
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005948 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjaminc895d6b2016-08-11 13:26:41 -04005949 config: Config{
5950 MaxVersion: VersionTLS12,
5951 ClientAuth: RequireAnyClientCert,
5952 VerifySignatureAlgorithms: []signatureAlgorithm{
5953 signatureRSAPKCS1WithSHA1,
5954 },
5955 Bugs: ProtocolBugs{
5956 NoSignatureAlgorithms: true,
5957 },
5958 },
5959 flags: []string{
5960 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5961 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5962 },
5963 })
5964
5965 testCases = append(testCases, testCase{
5966 testType: serverTest,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005967 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjaminc895d6b2016-08-11 13:26:41 -04005968 config: Config{
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005969 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04005970 VerifySignatureAlgorithms: []signatureAlgorithm{
5971 signatureRSAPKCS1WithSHA1,
5972 },
5973 Bugs: ProtocolBugs{
5974 NoSignatureAlgorithms: true,
5975 },
5976 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04005977 flags: []string{
5978 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5979 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5980 },
5981 })
5982
5983 testCases = append(testCases, testCase{
5984 name: "ClientAuth-SHA1-Fallback-ECDSA",
5985 config: Config{
5986 MaxVersion: VersionTLS12,
5987 ClientAuth: RequireAnyClientCert,
5988 VerifySignatureAlgorithms: []signatureAlgorithm{
5989 signatureECDSAWithSHA1,
5990 },
5991 Bugs: ProtocolBugs{
5992 NoSignatureAlgorithms: true,
5993 },
5994 },
5995 flags: []string{
5996 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5997 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5998 },
5999 })
6000
6001 testCases = append(testCases, testCase{
6002 testType: serverTest,
6003 name: "ServerAuth-SHA1-Fallback-ECDSA",
6004 config: Config{
6005 MaxVersion: VersionTLS12,
6006 VerifySignatureAlgorithms: []signatureAlgorithm{
6007 signatureECDSAWithSHA1,
6008 },
6009 Bugs: ProtocolBugs{
6010 NoSignatureAlgorithms: true,
6011 },
6012 },
6013 flags: []string{
6014 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6015 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6016 },
David Benjaminc895d6b2016-08-11 13:26:41 -04006017 })
6018
6019 testCases = append(testCases, testCase{
6020 name: "ClientAuth-NoFallback-TLS13",
6021 config: Config{
6022 MaxVersion: VersionTLS13,
6023 ClientAuth: RequireAnyClientCert,
6024 VerifySignatureAlgorithms: []signatureAlgorithm{
6025 signatureRSAPKCS1WithSHA1,
6026 },
6027 Bugs: ProtocolBugs{
6028 NoSignatureAlgorithms: true,
6029 },
6030 },
6031 flags: []string{
6032 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6033 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6034 },
6035 shouldFail: true,
6036 // An empty CertificateRequest signature algorithm list is a
6037 // syntax error in TLS 1.3.
6038 expectedError: ":DECODE_ERROR:",
6039 expectedLocalError: "remote error: error decoding message",
6040 })
6041
6042 testCases = append(testCases, testCase{
6043 testType: serverTest,
6044 name: "ServerAuth-NoFallback-TLS13",
6045 config: Config{
6046 MaxVersion: VersionTLS13,
6047 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6048 VerifySignatureAlgorithms: []signatureAlgorithm{
6049 signatureRSAPKCS1WithSHA1,
6050 },
6051 Bugs: ProtocolBugs{
6052 NoSignatureAlgorithms: true,
6053 },
6054 },
6055 shouldFail: true,
6056 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6057 })
6058
6059 // Test that hash preferences are enforced. BoringSSL does not implement
6060 // MD5 signatures.
6061 testCases = append(testCases, testCase{
6062 testType: serverTest,
6063 name: "ClientAuth-Enforced",
6064 config: Config{
6065 MaxVersion: VersionTLS12,
6066 Certificates: []Certificate{rsaCertificate},
6067 SignSignatureAlgorithms: []signatureAlgorithm{
6068 signatureRSAPKCS1WithMD5,
Adam Langleye9ada862015-05-11 17:20:37 -07006069 },
6070 Bugs: ProtocolBugs{
6071 IgnorePeerSignatureAlgorithmPreferences: true,
6072 },
6073 },
6074 flags: []string{"-require-any-client-certificate"},
6075 shouldFail: true,
6076 expectedError: ":WRONG_SIGNATURE_TYPE:",
6077 })
6078
6079 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04006080 name: "ServerAuth-Enforced",
Adam Langleye9ada862015-05-11 17:20:37 -07006081 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006082 MaxVersion: VersionTLS12,
Adam Langleye9ada862015-05-11 17:20:37 -07006083 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminc895d6b2016-08-11 13:26:41 -04006084 SignSignatureAlgorithms: []signatureAlgorithm{
6085 signatureRSAPKCS1WithMD5,
Adam Langleye9ada862015-05-11 17:20:37 -07006086 },
6087 Bugs: ProtocolBugs{
6088 IgnorePeerSignatureAlgorithmPreferences: true,
6089 },
6090 },
6091 shouldFail: true,
6092 expectedError: ":WRONG_SIGNATURE_TYPE:",
6093 })
David Benjaminc895d6b2016-08-11 13:26:41 -04006094 testCases = append(testCases, testCase{
6095 testType: serverTest,
6096 name: "ClientAuth-Enforced-TLS13",
6097 config: Config{
6098 MaxVersion: VersionTLS13,
6099 Certificates: []Certificate{rsaCertificate},
6100 SignSignatureAlgorithms: []signatureAlgorithm{
6101 signatureRSAPKCS1WithMD5,
6102 },
6103 Bugs: ProtocolBugs{
6104 IgnorePeerSignatureAlgorithmPreferences: true,
6105 IgnoreSignatureVersionChecks: true,
6106 },
6107 },
6108 flags: []string{"-require-any-client-certificate"},
6109 shouldFail: true,
6110 expectedError: ":WRONG_SIGNATURE_TYPE:",
6111 })
6112
6113 testCases = append(testCases, testCase{
6114 name: "ServerAuth-Enforced-TLS13",
6115 config: Config{
6116 MaxVersion: VersionTLS13,
6117 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6118 SignSignatureAlgorithms: []signatureAlgorithm{
6119 signatureRSAPKCS1WithMD5,
6120 },
6121 Bugs: ProtocolBugs{
6122 IgnorePeerSignatureAlgorithmPreferences: true,
6123 IgnoreSignatureVersionChecks: true,
6124 },
6125 },
6126 shouldFail: true,
6127 expectedError: ":WRONG_SIGNATURE_TYPE:",
6128 })
Kenny Rootb8494592015-09-25 02:29:14 +00006129
6130 // Test that the agreed upon digest respects the client preferences and
6131 // the server digests.
6132 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04006133 name: "NoCommonAlgorithms-Digests",
Kenny Rootb8494592015-09-25 02:29:14 +00006134 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006135 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00006136 ClientAuth: RequireAnyClientCert,
David Benjaminc895d6b2016-08-11 13:26:41 -04006137 VerifySignatureAlgorithms: []signatureAlgorithm{
6138 signatureRSAPKCS1WithSHA512,
6139 signatureRSAPKCS1WithSHA1,
Kenny Rootb8494592015-09-25 02:29:14 +00006140 },
6141 },
6142 flags: []string{
6143 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6144 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminc895d6b2016-08-11 13:26:41 -04006145 "-digest-prefs", "SHA256",
Kenny Rootb8494592015-09-25 02:29:14 +00006146 },
David Benjaminc895d6b2016-08-11 13:26:41 -04006147 shouldFail: true,
6148 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6149 })
6150 testCases = append(testCases, testCase{
6151 name: "NoCommonAlgorithms",
6152 config: Config{
6153 MaxVersion: VersionTLS12,
6154 ClientAuth: RequireAnyClientCert,
6155 VerifySignatureAlgorithms: []signatureAlgorithm{
6156 signatureRSAPKCS1WithSHA512,
6157 signatureRSAPKCS1WithSHA1,
6158 },
6159 },
6160 flags: []string{
6161 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6162 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6163 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6164 },
6165 shouldFail: true,
6166 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6167 })
6168 testCases = append(testCases, testCase{
6169 name: "NoCommonAlgorithms-TLS13",
6170 config: Config{
6171 MaxVersion: VersionTLS13,
6172 ClientAuth: RequireAnyClientCert,
6173 VerifySignatureAlgorithms: []signatureAlgorithm{
6174 signatureRSAPSSWithSHA512,
6175 signatureRSAPSSWithSHA384,
6176 },
6177 },
6178 flags: []string{
6179 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6180 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6181 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6182 },
6183 shouldFail: true,
6184 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Kenny Rootb8494592015-09-25 02:29:14 +00006185 })
6186 testCases = append(testCases, testCase{
6187 name: "Agree-Digest-SHA256",
6188 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006189 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00006190 ClientAuth: RequireAnyClientCert,
David Benjaminc895d6b2016-08-11 13:26:41 -04006191 VerifySignatureAlgorithms: []signatureAlgorithm{
6192 signatureRSAPKCS1WithSHA1,
6193 signatureRSAPKCS1WithSHA256,
Kenny Rootb8494592015-09-25 02:29:14 +00006194 },
6195 },
6196 flags: []string{
6197 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6198 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminc895d6b2016-08-11 13:26:41 -04006199 "-digest-prefs", "SHA256,SHA1",
Kenny Rootb8494592015-09-25 02:29:14 +00006200 },
David Benjaminc895d6b2016-08-11 13:26:41 -04006201 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Kenny Rootb8494592015-09-25 02:29:14 +00006202 })
6203 testCases = append(testCases, testCase{
6204 name: "Agree-Digest-SHA1",
6205 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006206 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00006207 ClientAuth: RequireAnyClientCert,
David Benjaminc895d6b2016-08-11 13:26:41 -04006208 VerifySignatureAlgorithms: []signatureAlgorithm{
6209 signatureRSAPKCS1WithSHA1,
Kenny Rootb8494592015-09-25 02:29:14 +00006210 },
6211 },
6212 flags: []string{
6213 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6214 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminc895d6b2016-08-11 13:26:41 -04006215 "-digest-prefs", "SHA512,SHA256,SHA1",
Kenny Rootb8494592015-09-25 02:29:14 +00006216 },
David Benjaminc895d6b2016-08-11 13:26:41 -04006217 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Kenny Rootb8494592015-09-25 02:29:14 +00006218 })
6219 testCases = append(testCases, testCase{
6220 name: "Agree-Digest-Default",
6221 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006222 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00006223 ClientAuth: RequireAnyClientCert,
David Benjaminc895d6b2016-08-11 13:26:41 -04006224 VerifySignatureAlgorithms: []signatureAlgorithm{
6225 signatureRSAPKCS1WithSHA256,
6226 signatureECDSAWithP256AndSHA256,
6227 signatureRSAPKCS1WithSHA1,
6228 signatureECDSAWithSHA1,
Kenny Rootb8494592015-09-25 02:29:14 +00006229 },
6230 },
6231 flags: []string{
6232 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6233 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6234 },
David Benjaminc895d6b2016-08-11 13:26:41 -04006235 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6236 })
6237
6238 // Test that the signing preference list may include extra algorithms
6239 // without negotiation problems.
6240 testCases = append(testCases, testCase{
6241 testType: serverTest,
6242 name: "FilterExtraAlgorithms",
6243 config: Config{
6244 MaxVersion: VersionTLS12,
6245 VerifySignatureAlgorithms: []signatureAlgorithm{
6246 signatureRSAPKCS1WithSHA256,
6247 },
6248 },
6249 flags: []string{
6250 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6251 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6252 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6253 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6254 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6255 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6256 },
6257 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6258 })
6259
6260 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6261 // signature algorithms.
6262 testCases = append(testCases, testCase{
6263 name: "CheckLeafCurve",
6264 config: Config{
6265 MaxVersion: VersionTLS12,
6266 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6267 Certificates: []Certificate{ecdsaP256Certificate},
6268 },
6269 flags: []string{"-p384-only"},
6270 shouldFail: true,
6271 expectedError: ":BAD_ECC_CERT:",
6272 })
6273
6274 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6275 testCases = append(testCases, testCase{
6276 name: "CheckLeafCurve-TLS13",
6277 config: Config{
6278 MaxVersion: VersionTLS13,
6279 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6280 Certificates: []Certificate{ecdsaP256Certificate},
6281 },
6282 flags: []string{"-p384-only"},
6283 })
6284
6285 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6286 testCases = append(testCases, testCase{
6287 name: "ECDSACurveMismatch-Verify-TLS12",
6288 config: Config{
6289 MaxVersion: VersionTLS12,
6290 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6291 Certificates: []Certificate{ecdsaP256Certificate},
6292 SignSignatureAlgorithms: []signatureAlgorithm{
6293 signatureECDSAWithP384AndSHA384,
6294 },
6295 },
6296 })
6297
6298 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6299 testCases = append(testCases, testCase{
6300 name: "ECDSACurveMismatch-Verify-TLS13",
6301 config: Config{
6302 MaxVersion: VersionTLS13,
6303 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6304 Certificates: []Certificate{ecdsaP256Certificate},
6305 SignSignatureAlgorithms: []signatureAlgorithm{
6306 signatureECDSAWithP384AndSHA384,
6307 },
6308 Bugs: ProtocolBugs{
6309 SkipECDSACurveCheck: true,
6310 },
6311 },
6312 shouldFail: true,
6313 expectedError: ":WRONG_SIGNATURE_TYPE:",
6314 })
6315
6316 // Signature algorithm selection in TLS 1.3 should take the curve into
6317 // account.
6318 testCases = append(testCases, testCase{
6319 testType: serverTest,
6320 name: "ECDSACurveMismatch-Sign-TLS13",
6321 config: Config{
6322 MaxVersion: VersionTLS13,
6323 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6324 VerifySignatureAlgorithms: []signatureAlgorithm{
6325 signatureECDSAWithP384AndSHA384,
6326 signatureECDSAWithP256AndSHA256,
6327 },
6328 },
6329 flags: []string{
6330 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6331 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6332 },
6333 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6334 })
6335
6336 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6337 // server does not attempt to sign in that case.
6338 testCases = append(testCases, testCase{
6339 testType: serverTest,
6340 name: "RSA-PSS-Large",
6341 config: Config{
6342 MaxVersion: VersionTLS13,
6343 VerifySignatureAlgorithms: []signatureAlgorithm{
6344 signatureRSAPSSWithSHA512,
6345 },
6346 },
6347 flags: []string{
6348 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6349 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6350 },
6351 shouldFail: true,
6352 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Kenny Rootb8494592015-09-25 02:29:14 +00006353 })
David Benjaminf0c4a6c2016-08-11 13:26:41 -04006354
6355 // Test that RSA-PSS is enabled by default for TLS 1.2.
6356 testCases = append(testCases, testCase{
6357 testType: clientTest,
6358 name: "RSA-PSS-Default-Verify",
6359 config: Config{
6360 MaxVersion: VersionTLS12,
6361 SignSignatureAlgorithms: []signatureAlgorithm{
6362 signatureRSAPSSWithSHA256,
6363 },
6364 },
6365 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6366 })
6367
6368 testCases = append(testCases, testCase{
6369 testType: serverTest,
6370 name: "RSA-PSS-Default-Sign",
6371 config: Config{
6372 MaxVersion: VersionTLS12,
6373 VerifySignatureAlgorithms: []signatureAlgorithm{
6374 signatureRSAPSSWithSHA256,
6375 },
6376 },
6377 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6378 })
Adam Langleye9ada862015-05-11 17:20:37 -07006379}
6380
6381// timeouts is the retransmit schedule for BoringSSL. It doubles and
6382// caps at 60 seconds. On the 13th timeout, it gives up.
6383var timeouts = []time.Duration{
6384 1 * time.Second,
6385 2 * time.Second,
6386 4 * time.Second,
6387 8 * time.Second,
6388 16 * time.Second,
6389 32 * time.Second,
6390 60 * time.Second,
6391 60 * time.Second,
6392 60 * time.Second,
6393 60 * time.Second,
6394 60 * time.Second,
6395 60 * time.Second,
6396 60 * time.Second,
6397}
6398
David Benjamind316cba2016-06-02 16:17:39 -04006399// shortTimeouts is an alternate set of timeouts which would occur if the
6400// initial timeout duration was set to 250ms.
6401var shortTimeouts = []time.Duration{
6402 250 * time.Millisecond,
6403 500 * time.Millisecond,
6404 1 * time.Second,
6405 2 * time.Second,
6406 4 * time.Second,
6407 8 * time.Second,
6408 16 * time.Second,
6409 32 * time.Second,
6410 60 * time.Second,
6411 60 * time.Second,
6412 60 * time.Second,
6413 60 * time.Second,
6414 60 * time.Second,
6415}
6416
Adam Langleye9ada862015-05-11 17:20:37 -07006417func addDTLSRetransmitTests() {
David Benjamin6e899c72016-06-09 18:02:18 -04006418 // These tests work by coordinating some behavior on both the shim and
6419 // the runner.
6420 //
6421 // TimeoutSchedule configures the runner to send a series of timeout
6422 // opcodes to the shim (see packetAdaptor) immediately before reading
6423 // each peer handshake flight N. The timeout opcode both simulates a
6424 // timeout in the shim and acts as a synchronization point to help the
6425 // runner bracket each handshake flight.
6426 //
6427 // We assume the shim does not read from the channel eagerly. It must
6428 // first wait until it has sent flight N and is ready to receive
6429 // handshake flight N+1. At this point, it will process the timeout
6430 // opcode. It must then immediately respond with a timeout ACK and act
6431 // as if the shim was idle for the specified amount of time.
6432 //
6433 // The runner then drops all packets received before the ACK and
6434 // continues waiting for flight N. This ordering results in one attempt
6435 // at sending flight N to be dropped. For the test to complete, the
6436 // shim must send flight N again, testing that the shim implements DTLS
6437 // retransmit on a timeout.
6438
David Benjaminc895d6b2016-08-11 13:26:41 -04006439 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
6440 // likely be more epochs to cross and the final message's retransmit may
6441 // be more complex.
6442
David Benjamin6e899c72016-06-09 18:02:18 -04006443 for _, async := range []bool{true, false} {
6444 var tests []testCase
6445
6446 // Test that this is indeed the timeout schedule. Stress all
6447 // four patterns of handshake.
6448 for i := 1; i < len(timeouts); i++ {
6449 number := strconv.Itoa(i)
6450 tests = append(tests, testCase{
6451 protocol: dtls,
6452 name: "DTLS-Retransmit-Client-" + number,
6453 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006454 MaxVersion: VersionTLS12,
David Benjamin6e899c72016-06-09 18:02:18 -04006455 Bugs: ProtocolBugs{
6456 TimeoutSchedule: timeouts[:i],
6457 },
6458 },
6459 resumeSession: true,
6460 })
6461 tests = append(tests, testCase{
6462 protocol: dtls,
6463 testType: serverTest,
6464 name: "DTLS-Retransmit-Server-" + number,
6465 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006466 MaxVersion: VersionTLS12,
David Benjamin6e899c72016-06-09 18:02:18 -04006467 Bugs: ProtocolBugs{
6468 TimeoutSchedule: timeouts[:i],
6469 },
6470 },
6471 resumeSession: true,
6472 })
6473 }
6474
6475 // Test that exceeding the timeout schedule hits a read
6476 // timeout.
6477 tests = append(tests, testCase{
Adam Langleye9ada862015-05-11 17:20:37 -07006478 protocol: dtls,
David Benjamin6e899c72016-06-09 18:02:18 -04006479 name: "DTLS-Retransmit-Timeout",
Adam Langleye9ada862015-05-11 17:20:37 -07006480 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006481 MaxVersion: VersionTLS12,
Adam Langleye9ada862015-05-11 17:20:37 -07006482 Bugs: ProtocolBugs{
David Benjamin6e899c72016-06-09 18:02:18 -04006483 TimeoutSchedule: timeouts,
Adam Langleye9ada862015-05-11 17:20:37 -07006484 },
6485 },
6486 resumeSession: true,
David Benjamin6e899c72016-06-09 18:02:18 -04006487 shouldFail: true,
6488 expectedError: ":READ_TIMEOUT_EXPIRED:",
Adam Langleye9ada862015-05-11 17:20:37 -07006489 })
David Benjamin6e899c72016-06-09 18:02:18 -04006490
6491 if async {
6492 // Test that timeout handling has a fudge factor, due to API
6493 // problems.
6494 tests = append(tests, testCase{
6495 protocol: dtls,
6496 name: "DTLS-Retransmit-Fudge",
6497 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006498 MaxVersion: VersionTLS12,
David Benjamin6e899c72016-06-09 18:02:18 -04006499 Bugs: ProtocolBugs{
6500 TimeoutSchedule: []time.Duration{
6501 timeouts[0] - 10*time.Millisecond,
6502 },
6503 },
6504 },
6505 resumeSession: true,
6506 })
6507 }
6508
6509 // Test that the final Finished retransmitting isn't
6510 // duplicated if the peer badly fragments everything.
6511 tests = append(tests, testCase{
6512 testType: serverTest,
6513 protocol: dtls,
6514 name: "DTLS-Retransmit-Fragmented",
6515 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006516 MaxVersion: VersionTLS12,
David Benjamin6e899c72016-06-09 18:02:18 -04006517 Bugs: ProtocolBugs{
6518 TimeoutSchedule: []time.Duration{timeouts[0]},
6519 MaxHandshakeRecordLength: 2,
6520 },
6521 },
6522 })
6523
6524 // Test the timeout schedule when a shorter initial timeout duration is set.
6525 tests = append(tests, testCase{
6526 protocol: dtls,
6527 name: "DTLS-Retransmit-Short-Client",
6528 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006529 MaxVersion: VersionTLS12,
David Benjamin6e899c72016-06-09 18:02:18 -04006530 Bugs: ProtocolBugs{
6531 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6532 },
6533 },
6534 resumeSession: true,
6535 flags: []string{"-initial-timeout-duration-ms", "250"},
6536 })
6537 tests = append(tests, testCase{
Adam Langleye9ada862015-05-11 17:20:37 -07006538 protocol: dtls,
6539 testType: serverTest,
David Benjamin6e899c72016-06-09 18:02:18 -04006540 name: "DTLS-Retransmit-Short-Server",
Adam Langleye9ada862015-05-11 17:20:37 -07006541 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006542 MaxVersion: VersionTLS12,
Adam Langleye9ada862015-05-11 17:20:37 -07006543 Bugs: ProtocolBugs{
David Benjamin6e899c72016-06-09 18:02:18 -04006544 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
Adam Langleye9ada862015-05-11 17:20:37 -07006545 },
6546 },
6547 resumeSession: true,
David Benjamin6e899c72016-06-09 18:02:18 -04006548 flags: []string{"-initial-timeout-duration-ms", "250"},
Adam Langleye9ada862015-05-11 17:20:37 -07006549 })
David Benjamin6e899c72016-06-09 18:02:18 -04006550
6551 for _, test := range tests {
6552 if async {
6553 test.name += "-Async"
6554 test.flags = append(test.flags, "-async")
6555 }
6556
6557 testCases = append(testCases, test)
6558 }
Adam Langleye9ada862015-05-11 17:20:37 -07006559 }
Adam Langleye9ada862015-05-11 17:20:37 -07006560}
6561
6562func addExportKeyingMaterialTests() {
6563 for _, vers := range tlsVersions {
6564 if vers.version == VersionSSL30 {
6565 continue
6566 }
6567 testCases = append(testCases, testCase{
6568 name: "ExportKeyingMaterial-" + vers.name,
6569 config: Config{
6570 MaxVersion: vers.version,
6571 },
6572 exportKeyingMaterial: 1024,
6573 exportLabel: "label",
6574 exportContext: "context",
6575 useExportContext: true,
6576 })
6577 testCases = append(testCases, testCase{
6578 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6579 config: Config{
6580 MaxVersion: vers.version,
6581 },
6582 exportKeyingMaterial: 1024,
6583 })
6584 testCases = append(testCases, testCase{
6585 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6586 config: Config{
6587 MaxVersion: vers.version,
6588 },
6589 exportKeyingMaterial: 1024,
6590 useExportContext: true,
6591 })
6592 testCases = append(testCases, testCase{
6593 name: "ExportKeyingMaterial-Small-" + vers.name,
6594 config: Config{
6595 MaxVersion: vers.version,
6596 },
6597 exportKeyingMaterial: 1,
6598 exportLabel: "label",
6599 exportContext: "context",
6600 useExportContext: true,
6601 })
6602 }
6603 testCases = append(testCases, testCase{
6604 name: "ExportKeyingMaterial-SSL3",
6605 config: Config{
6606 MaxVersion: VersionSSL30,
6607 },
6608 exportKeyingMaterial: 1024,
6609 exportLabel: "label",
6610 exportContext: "context",
6611 useExportContext: true,
6612 shouldFail: true,
6613 expectedError: "failed to export keying material",
6614 })
Adam Langleyd9e397b2015-01-22 14:27:53 -08006615}
6616
Adam Langleyf4e42722015-06-04 17:45:09 -07006617func addTLSUniqueTests() {
6618 for _, isClient := range []bool{false, true} {
6619 for _, isResumption := range []bool{false, true} {
6620 for _, hasEMS := range []bool{false, true} {
6621 var suffix string
6622 if isResumption {
6623 suffix = "Resume-"
6624 } else {
6625 suffix = "Full-"
6626 }
6627
6628 if hasEMS {
6629 suffix += "EMS-"
6630 } else {
6631 suffix += "NoEMS-"
6632 }
6633
6634 if isClient {
6635 suffix += "Client"
6636 } else {
6637 suffix += "Server"
6638 }
6639
6640 test := testCase{
6641 name: "TLSUnique-" + suffix,
6642 testTLSUnique: true,
6643 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006644 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07006645 Bugs: ProtocolBugs{
6646 NoExtendedMasterSecret: !hasEMS,
6647 },
6648 },
6649 }
6650
6651 if isResumption {
6652 test.resumeSession = true
6653 test.resumeConfig = &Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006654 MaxVersion: VersionTLS12,
Adam Langleyf4e42722015-06-04 17:45:09 -07006655 Bugs: ProtocolBugs{
6656 NoExtendedMasterSecret: !hasEMS,
6657 },
6658 }
6659 }
6660
6661 if isResumption && !hasEMS {
6662 test.shouldFail = true
6663 test.expectedError = "failed to get tls-unique"
6664 }
6665
6666 testCases = append(testCases, test)
6667 }
6668 }
6669 }
6670}
6671
Kenny Rootb8494592015-09-25 02:29:14 +00006672func addCustomExtensionTests() {
6673 expectedContents := "custom extension"
6674 emptyString := ""
6675
6676 for _, isClient := range []bool{false, true} {
6677 suffix := "Server"
6678 flag := "-enable-server-custom-extension"
6679 testType := serverTest
6680 if isClient {
6681 suffix = "Client"
6682 flag = "-enable-client-custom-extension"
6683 testType = clientTest
6684 }
6685
6686 testCases = append(testCases, testCase{
6687 testType: testType,
6688 name: "CustomExtensions-" + suffix,
6689 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006690 MaxVersion: VersionTLS12,
6691 Bugs: ProtocolBugs{
6692 CustomExtension: expectedContents,
6693 ExpectedCustomExtension: &expectedContents,
6694 },
6695 },
6696 flags: []string{flag},
6697 })
6698 testCases = append(testCases, testCase{
6699 testType: testType,
6700 name: "CustomExtensions-" + suffix + "-TLS13",
6701 config: Config{
6702 MaxVersion: VersionTLS13,
Kenny Rootb8494592015-09-25 02:29:14 +00006703 Bugs: ProtocolBugs{
6704 CustomExtension: expectedContents,
6705 ExpectedCustomExtension: &expectedContents,
6706 },
6707 },
6708 flags: []string{flag},
6709 })
6710
6711 // If the parse callback fails, the handshake should also fail.
6712 testCases = append(testCases, testCase{
6713 testType: testType,
6714 name: "CustomExtensions-ParseError-" + suffix,
6715 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006716 MaxVersion: VersionTLS12,
6717 Bugs: ProtocolBugs{
6718 CustomExtension: expectedContents + "foo",
6719 ExpectedCustomExtension: &expectedContents,
6720 },
6721 },
6722 flags: []string{flag},
6723 shouldFail: true,
6724 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6725 })
6726 testCases = append(testCases, testCase{
6727 testType: testType,
6728 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6729 config: Config{
6730 MaxVersion: VersionTLS13,
Kenny Rootb8494592015-09-25 02:29:14 +00006731 Bugs: ProtocolBugs{
6732 CustomExtension: expectedContents + "foo",
6733 ExpectedCustomExtension: &expectedContents,
6734 },
6735 },
6736 flags: []string{flag},
6737 shouldFail: true,
6738 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6739 })
6740
6741 // If the add callback fails, the handshake should also fail.
6742 testCases = append(testCases, testCase{
6743 testType: testType,
6744 name: "CustomExtensions-FailAdd-" + suffix,
6745 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006746 MaxVersion: VersionTLS12,
6747 Bugs: ProtocolBugs{
6748 CustomExtension: expectedContents,
6749 ExpectedCustomExtension: &expectedContents,
6750 },
6751 },
6752 flags: []string{flag, "-custom-extension-fail-add"},
6753 shouldFail: true,
6754 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6755 })
6756 testCases = append(testCases, testCase{
6757 testType: testType,
6758 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6759 config: Config{
6760 MaxVersion: VersionTLS13,
Kenny Rootb8494592015-09-25 02:29:14 +00006761 Bugs: ProtocolBugs{
6762 CustomExtension: expectedContents,
6763 ExpectedCustomExtension: &expectedContents,
6764 },
6765 },
6766 flags: []string{flag, "-custom-extension-fail-add"},
6767 shouldFail: true,
6768 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6769 })
6770
6771 // If the add callback returns zero, no extension should be
6772 // added.
6773 skipCustomExtension := expectedContents
6774 if isClient {
6775 // For the case where the client skips sending the
6776 // custom extension, the server must not “echo” it.
6777 skipCustomExtension = ""
6778 }
6779 testCases = append(testCases, testCase{
6780 testType: testType,
6781 name: "CustomExtensions-Skip-" + suffix,
6782 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006783 MaxVersion: VersionTLS12,
6784 Bugs: ProtocolBugs{
6785 CustomExtension: skipCustomExtension,
6786 ExpectedCustomExtension: &emptyString,
6787 },
6788 },
6789 flags: []string{flag, "-custom-extension-skip"},
6790 })
6791 testCases = append(testCases, testCase{
6792 testType: testType,
6793 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6794 config: Config{
6795 MaxVersion: VersionTLS13,
Kenny Rootb8494592015-09-25 02:29:14 +00006796 Bugs: ProtocolBugs{
6797 CustomExtension: skipCustomExtension,
6798 ExpectedCustomExtension: &emptyString,
6799 },
6800 },
6801 flags: []string{flag, "-custom-extension-skip"},
6802 })
6803 }
6804
6805 // The custom extension add callback should not be called if the client
6806 // doesn't send the extension.
6807 testCases = append(testCases, testCase{
6808 testType: serverTest,
6809 name: "CustomExtensions-NotCalled-Server",
6810 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006811 MaxVersion: VersionTLS12,
6812 Bugs: ProtocolBugs{
6813 ExpectedCustomExtension: &emptyString,
6814 },
6815 },
6816 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6817 })
6818
6819 testCases = append(testCases, testCase{
6820 testType: serverTest,
6821 name: "CustomExtensions-NotCalled-Server-TLS13",
6822 config: Config{
6823 MaxVersion: VersionTLS13,
Kenny Rootb8494592015-09-25 02:29:14 +00006824 Bugs: ProtocolBugs{
6825 ExpectedCustomExtension: &emptyString,
6826 },
6827 },
6828 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6829 })
6830
6831 // Test an unknown extension from the server.
6832 testCases = append(testCases, testCase{
6833 testType: clientTest,
6834 name: "UnknownExtension-Client",
6835 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006836 MaxVersion: VersionTLS12,
Kenny Rootb8494592015-09-25 02:29:14 +00006837 Bugs: ProtocolBugs{
6838 CustomExtension: expectedContents,
6839 },
6840 },
David Benjaminc895d6b2016-08-11 13:26:41 -04006841 shouldFail: true,
6842 expectedError: ":UNEXPECTED_EXTENSION:",
6843 expectedLocalError: "remote error: unsupported extension",
6844 })
6845 testCases = append(testCases, testCase{
6846 testType: clientTest,
6847 name: "UnknownExtension-Client-TLS13",
6848 config: Config{
6849 MaxVersion: VersionTLS13,
6850 Bugs: ProtocolBugs{
6851 CustomExtension: expectedContents,
6852 },
6853 },
6854 shouldFail: true,
6855 expectedError: ":UNEXPECTED_EXTENSION:",
6856 expectedLocalError: "remote error: unsupported extension",
6857 })
6858
6859 // Test a known but unoffered extension from the server.
6860 testCases = append(testCases, testCase{
6861 testType: clientTest,
6862 name: "UnofferedExtension-Client",
6863 config: Config{
6864 MaxVersion: VersionTLS12,
6865 Bugs: ProtocolBugs{
6866 SendALPN: "alpn",
6867 },
6868 },
6869 shouldFail: true,
6870 expectedError: ":UNEXPECTED_EXTENSION:",
6871 expectedLocalError: "remote error: unsupported extension",
6872 })
6873 testCases = append(testCases, testCase{
6874 testType: clientTest,
6875 name: "UnofferedExtension-Client-TLS13",
6876 config: Config{
6877 MaxVersion: VersionTLS13,
6878 Bugs: ProtocolBugs{
6879 SendALPN: "alpn",
6880 },
6881 },
6882 shouldFail: true,
6883 expectedError: ":UNEXPECTED_EXTENSION:",
6884 expectedLocalError: "remote error: unsupported extension",
Kenny Rootb8494592015-09-25 02:29:14 +00006885 })
6886}
6887
Adam Langley4139edb2016-01-13 15:00:54 -08006888func addRSAClientKeyExchangeTests() {
6889 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6890 testCases = append(testCases, testCase{
6891 testType: serverTest,
6892 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6893 config: Config{
6894 // Ensure the ClientHello version and final
6895 // version are different, to detect if the
6896 // server uses the wrong one.
6897 MaxVersion: VersionTLS11,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04006898 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langley4139edb2016-01-13 15:00:54 -08006899 Bugs: ProtocolBugs{
6900 BadRSAClientKeyExchange: bad,
6901 },
6902 },
6903 shouldFail: true,
6904 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6905 })
6906 }
David Benjamin7c0d06c2016-08-11 13:26:41 -04006907
6908 // The server must compare whatever was in ClientHello.version for the
6909 // RSA premaster.
6910 testCases = append(testCases, testCase{
6911 testType: serverTest,
6912 name: "SendClientVersion-RSA",
6913 config: Config{
6914 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6915 Bugs: ProtocolBugs{
6916 SendClientVersion: 0x1234,
6917 },
6918 },
6919 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6920 })
Adam Langley4139edb2016-01-13 15:00:54 -08006921}
6922
6923var testCurves = []struct {
6924 name string
6925 id CurveID
6926}{
6927 {"P-256", CurveP256},
6928 {"P-384", CurveP384},
6929 {"P-521", CurveP521},
6930 {"X25519", CurveX25519},
6931}
6932
David Benjaminc895d6b2016-08-11 13:26:41 -04006933const bogusCurve = 0x1234
6934
Adam Langley4139edb2016-01-13 15:00:54 -08006935func addCurveTests() {
6936 for _, curve := range testCurves {
6937 testCases = append(testCases, testCase{
6938 name: "CurveTest-Client-" + curve.name,
6939 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006940 MaxVersion: VersionTLS12,
Adam Langley4139edb2016-01-13 15:00:54 -08006941 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6942 CurvePreferences: []CurveID{curve.id},
6943 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04006944 flags: []string{
6945 "-enable-all-curves",
6946 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6947 },
David Benjaminc895d6b2016-08-11 13:26:41 -04006948 expectedCurveID: curve.id,
6949 })
6950 testCases = append(testCases, testCase{
6951 name: "CurveTest-Client-" + curve.name + "-TLS13",
6952 config: Config{
6953 MaxVersion: VersionTLS13,
6954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6955 CurvePreferences: []CurveID{curve.id},
6956 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04006957 flags: []string{
6958 "-enable-all-curves",
6959 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6960 },
David Benjaminc895d6b2016-08-11 13:26:41 -04006961 expectedCurveID: curve.id,
Adam Langley4139edb2016-01-13 15:00:54 -08006962 })
6963 testCases = append(testCases, testCase{
6964 testType: serverTest,
6965 name: "CurveTest-Server-" + curve.name,
6966 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04006967 MaxVersion: VersionTLS12,
Adam Langley4139edb2016-01-13 15:00:54 -08006968 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6969 CurvePreferences: []CurveID{curve.id},
6970 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04006971 flags: []string{
6972 "-enable-all-curves",
6973 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6974 },
David Benjaminc895d6b2016-08-11 13:26:41 -04006975 expectedCurveID: curve.id,
6976 })
6977 testCases = append(testCases, testCase{
6978 testType: serverTest,
6979 name: "CurveTest-Server-" + curve.name + "-TLS13",
6980 config: Config{
6981 MaxVersion: VersionTLS13,
6982 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6983 CurvePreferences: []CurveID{curve.id},
6984 },
David Benjaminf0c4a6c2016-08-11 13:26:41 -04006985 flags: []string{
6986 "-enable-all-curves",
6987 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6988 },
David Benjaminc895d6b2016-08-11 13:26:41 -04006989 expectedCurveID: curve.id,
Adam Langley4139edb2016-01-13 15:00:54 -08006990 })
6991 }
David Benjamin4969cc92016-04-22 15:02:23 -04006992
6993 // The server must be tolerant to bogus curves.
David Benjamin4969cc92016-04-22 15:02:23 -04006994 testCases = append(testCases, testCase{
6995 testType: serverTest,
6996 name: "UnknownCurve",
6997 config: Config{
6998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6999 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7000 },
7001 })
David Benjaminc895d6b2016-08-11 13:26:41 -04007002
7003 // The server must not consider ECDHE ciphers when there are no
7004 // supported curves.
7005 testCases = append(testCases, testCase{
7006 testType: serverTest,
7007 name: "NoSupportedCurves",
7008 config: Config{
7009 MaxVersion: VersionTLS12,
7010 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7011 Bugs: ProtocolBugs{
7012 NoSupportedCurves: true,
7013 },
7014 },
7015 shouldFail: true,
7016 expectedError: ":NO_SHARED_CIPHER:",
7017 })
7018 testCases = append(testCases, testCase{
7019 testType: serverTest,
7020 name: "NoSupportedCurves-TLS13",
7021 config: Config{
7022 MaxVersion: VersionTLS13,
7023 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7024 Bugs: ProtocolBugs{
7025 NoSupportedCurves: true,
7026 },
7027 },
7028 shouldFail: true,
7029 expectedError: ":NO_SHARED_CIPHER:",
7030 })
7031
7032 // The server must fall back to another cipher when there are no
7033 // supported curves.
7034 testCases = append(testCases, testCase{
7035 testType: serverTest,
7036 name: "NoCommonCurves",
7037 config: Config{
7038 MaxVersion: VersionTLS12,
7039 CipherSuites: []uint16{
7040 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7041 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7042 },
7043 CurvePreferences: []CurveID{CurveP224},
7044 },
7045 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7046 })
7047
7048 // The client must reject bogus curves and disabled curves.
7049 testCases = append(testCases, testCase{
7050 name: "BadECDHECurve",
7051 config: Config{
7052 MaxVersion: VersionTLS12,
7053 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7054 Bugs: ProtocolBugs{
7055 SendCurve: bogusCurve,
7056 },
7057 },
7058 shouldFail: true,
7059 expectedError: ":WRONG_CURVE:",
7060 })
7061 testCases = append(testCases, testCase{
7062 name: "BadECDHECurve-TLS13",
7063 config: Config{
7064 MaxVersion: VersionTLS13,
7065 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7066 Bugs: ProtocolBugs{
7067 SendCurve: bogusCurve,
7068 },
7069 },
7070 shouldFail: true,
7071 expectedError: ":WRONG_CURVE:",
7072 })
7073
7074 testCases = append(testCases, testCase{
7075 name: "UnsupportedCurve",
7076 config: Config{
7077 MaxVersion: VersionTLS12,
7078 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7079 CurvePreferences: []CurveID{CurveP256},
7080 Bugs: ProtocolBugs{
7081 IgnorePeerCurvePreferences: true,
7082 },
7083 },
7084 flags: []string{"-p384-only"},
7085 shouldFail: true,
7086 expectedError: ":WRONG_CURVE:",
7087 })
7088
7089 testCases = append(testCases, testCase{
7090 // TODO(davidben): Add a TLS 1.3 version where
7091 // HelloRetryRequest requests an unsupported curve.
7092 name: "UnsupportedCurve-ServerHello-TLS13",
7093 config: Config{
7094 MaxVersion: VersionTLS12,
7095 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7096 CurvePreferences: []CurveID{CurveP384},
7097 Bugs: ProtocolBugs{
7098 SendCurve: CurveP256,
7099 },
7100 },
7101 flags: []string{"-p384-only"},
7102 shouldFail: true,
7103 expectedError: ":WRONG_CURVE:",
7104 })
7105
7106 // Test invalid curve points.
7107 testCases = append(testCases, testCase{
7108 name: "InvalidECDHPoint-Client",
7109 config: Config{
7110 MaxVersion: VersionTLS12,
7111 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7112 CurvePreferences: []CurveID{CurveP256},
7113 Bugs: ProtocolBugs{
7114 InvalidECDHPoint: true,
7115 },
7116 },
7117 shouldFail: true,
7118 expectedError: ":INVALID_ENCODING:",
7119 })
7120 testCases = append(testCases, testCase{
7121 name: "InvalidECDHPoint-Client-TLS13",
7122 config: Config{
7123 MaxVersion: VersionTLS13,
7124 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7125 CurvePreferences: []CurveID{CurveP256},
7126 Bugs: ProtocolBugs{
7127 InvalidECDHPoint: true,
7128 },
7129 },
7130 shouldFail: true,
7131 expectedError: ":INVALID_ENCODING:",
7132 })
7133 testCases = append(testCases, testCase{
7134 testType: serverTest,
7135 name: "InvalidECDHPoint-Server",
7136 config: Config{
7137 MaxVersion: VersionTLS12,
7138 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7139 CurvePreferences: []CurveID{CurveP256},
7140 Bugs: ProtocolBugs{
7141 InvalidECDHPoint: true,
7142 },
7143 },
7144 shouldFail: true,
7145 expectedError: ":INVALID_ENCODING:",
7146 })
7147 testCases = append(testCases, testCase{
7148 testType: serverTest,
7149 name: "InvalidECDHPoint-Server-TLS13",
7150 config: Config{
7151 MaxVersion: VersionTLS13,
7152 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7153 CurvePreferences: []CurveID{CurveP256},
7154 Bugs: ProtocolBugs{
7155 InvalidECDHPoint: true,
7156 },
7157 },
7158 shouldFail: true,
7159 expectedError: ":INVALID_ENCODING:",
7160 })
7161}
7162
7163func addCECPQ1Tests() {
7164 testCases = append(testCases, testCase{
7165 testType: clientTest,
7166 name: "CECPQ1-Client-BadX25519Part",
7167 config: Config{
7168 MaxVersion: VersionTLS12,
7169 MinVersion: VersionTLS12,
7170 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7171 Bugs: ProtocolBugs{
7172 CECPQ1BadX25519Part: true,
7173 },
7174 },
7175 flags: []string{"-cipher", "kCECPQ1"},
7176 shouldFail: true,
7177 expectedLocalError: "local error: bad record MAC",
7178 })
7179 testCases = append(testCases, testCase{
7180 testType: clientTest,
7181 name: "CECPQ1-Client-BadNewhopePart",
7182 config: Config{
7183 MaxVersion: VersionTLS12,
7184 MinVersion: VersionTLS12,
7185 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7186 Bugs: ProtocolBugs{
7187 CECPQ1BadNewhopePart: true,
7188 },
7189 },
7190 flags: []string{"-cipher", "kCECPQ1"},
7191 shouldFail: true,
7192 expectedLocalError: "local error: bad record MAC",
7193 })
7194 testCases = append(testCases, testCase{
7195 testType: serverTest,
7196 name: "CECPQ1-Server-BadX25519Part",
7197 config: Config{
7198 MaxVersion: VersionTLS12,
7199 MinVersion: VersionTLS12,
7200 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7201 Bugs: ProtocolBugs{
7202 CECPQ1BadX25519Part: true,
7203 },
7204 },
7205 flags: []string{"-cipher", "kCECPQ1"},
7206 shouldFail: true,
7207 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7208 })
7209 testCases = append(testCases, testCase{
7210 testType: serverTest,
7211 name: "CECPQ1-Server-BadNewhopePart",
7212 config: Config{
7213 MaxVersion: VersionTLS12,
7214 MinVersion: VersionTLS12,
7215 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7216 Bugs: ProtocolBugs{
7217 CECPQ1BadNewhopePart: true,
7218 },
7219 },
7220 flags: []string{"-cipher", "kCECPQ1"},
7221 shouldFail: true,
7222 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7223 })
Adam Langley4139edb2016-01-13 15:00:54 -08007224}
7225
David Benjaminf0c4a6c2016-08-11 13:26:41 -04007226func addDHEGroupSizeTests() {
Adam Langley4139edb2016-01-13 15:00:54 -08007227 testCases = append(testCases, testCase{
David Benjaminf0c4a6c2016-08-11 13:26:41 -04007228 name: "DHEGroupSize-Client",
Adam Langley4139edb2016-01-13 15:00:54 -08007229 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04007230 MaxVersion: VersionTLS12,
Adam Langley4139edb2016-01-13 15:00:54 -08007231 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7232 Bugs: ProtocolBugs{
7233 // This is a 1234-bit prime number, generated
7234 // with:
7235 // openssl gendh 1234 | openssl asn1parse -i
7236 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7237 },
7238 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007239 flags: []string{"-expect-dhe-group-size", "1234"},
Adam Langley4139edb2016-01-13 15:00:54 -08007240 })
7241 testCases = append(testCases, testCase{
7242 testType: serverTest,
David Benjaminf0c4a6c2016-08-11 13:26:41 -04007243 name: "DHEGroupSize-Server",
Adam Langley4139edb2016-01-13 15:00:54 -08007244 config: Config{
David Benjaminc895d6b2016-08-11 13:26:41 -04007245 MaxVersion: VersionTLS12,
Adam Langley4139edb2016-01-13 15:00:54 -08007246 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7247 },
7248 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjaminc895d6b2016-08-11 13:26:41 -04007249 flags: []string{"-expect-dhe-group-size", "2048"},
Adam Langley4139edb2016-01-13 15:00:54 -08007250 })
David Benjaminc895d6b2016-08-11 13:26:41 -04007251}
7252
7253func addTLS13RecordTests() {
7254 testCases = append(testCases, testCase{
7255 name: "TLS13-RecordPadding",
7256 config: Config{
7257 MaxVersion: VersionTLS13,
7258 MinVersion: VersionTLS13,
7259 Bugs: ProtocolBugs{
7260 RecordPadding: 10,
7261 },
7262 },
7263 })
7264
7265 testCases = append(testCases, testCase{
7266 name: "TLS13-EmptyRecords",
7267 config: Config{
7268 MaxVersion: VersionTLS13,
7269 MinVersion: VersionTLS13,
7270 Bugs: ProtocolBugs{
7271 OmitRecordContents: true,
7272 },
7273 },
7274 shouldFail: true,
7275 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7276 })
7277
7278 testCases = append(testCases, testCase{
7279 name: "TLS13-OnlyPadding",
7280 config: Config{
7281 MaxVersion: VersionTLS13,
7282 MinVersion: VersionTLS13,
7283 Bugs: ProtocolBugs{
7284 OmitRecordContents: true,
7285 RecordPadding: 10,
7286 },
7287 },
7288 shouldFail: true,
7289 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7290 })
7291
7292 testCases = append(testCases, testCase{
7293 name: "TLS13-WrongOuterRecord",
7294 config: Config{
7295 MaxVersion: VersionTLS13,
7296 MinVersion: VersionTLS13,
7297 Bugs: ProtocolBugs{
7298 OuterRecordType: recordTypeHandshake,
7299 },
7300 },
7301 shouldFail: true,
7302 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7303 })
7304}
7305
7306func addChangeCipherSpecTests() {
7307 // Test missing ChangeCipherSpecs.
7308 testCases = append(testCases, testCase{
7309 name: "SkipChangeCipherSpec-Client",
7310 config: Config{
7311 MaxVersion: VersionTLS12,
7312 Bugs: ProtocolBugs{
7313 SkipChangeCipherSpec: true,
7314 },
7315 },
7316 shouldFail: true,
7317 expectedError: ":UNEXPECTED_RECORD:",
7318 })
7319 testCases = append(testCases, testCase{
7320 testType: serverTest,
7321 name: "SkipChangeCipherSpec-Server",
7322 config: Config{
7323 MaxVersion: VersionTLS12,
7324 Bugs: ProtocolBugs{
7325 SkipChangeCipherSpec: true,
7326 },
7327 },
7328 shouldFail: true,
7329 expectedError: ":UNEXPECTED_RECORD:",
7330 })
7331 testCases = append(testCases, testCase{
7332 testType: serverTest,
7333 name: "SkipChangeCipherSpec-Server-NPN",
7334 config: Config{
7335 MaxVersion: VersionTLS12,
7336 NextProtos: []string{"bar"},
7337 Bugs: ProtocolBugs{
7338 SkipChangeCipherSpec: true,
7339 },
7340 },
7341 flags: []string{
7342 "-advertise-npn", "\x03foo\x03bar\x03baz",
7343 },
7344 shouldFail: true,
7345 expectedError: ":UNEXPECTED_RECORD:",
7346 })
7347
7348 // Test synchronization between the handshake and ChangeCipherSpec.
7349 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7350 // rejected. Test both with and without handshake packing to handle both
7351 // when the partial post-CCS message is in its own record and when it is
7352 // attached to the pre-CCS message.
7353 for _, packed := range []bool{false, true} {
7354 var suffix string
7355 if packed {
7356 suffix = "-Packed"
7357 }
7358
7359 testCases = append(testCases, testCase{
7360 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7361 config: Config{
7362 MaxVersion: VersionTLS12,
7363 Bugs: ProtocolBugs{
7364 FragmentAcrossChangeCipherSpec: true,
7365 PackHandshakeFlight: packed,
7366 },
7367 },
7368 shouldFail: true,
7369 expectedError: ":UNEXPECTED_RECORD:",
7370 })
7371 testCases = append(testCases, testCase{
7372 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7373 config: Config{
7374 MaxVersion: VersionTLS12,
7375 },
7376 resumeSession: true,
7377 resumeConfig: &Config{
7378 MaxVersion: VersionTLS12,
7379 Bugs: ProtocolBugs{
7380 FragmentAcrossChangeCipherSpec: true,
7381 PackHandshakeFlight: packed,
7382 },
7383 },
7384 shouldFail: true,
7385 expectedError: ":UNEXPECTED_RECORD:",
7386 })
7387 testCases = append(testCases, testCase{
7388 testType: serverTest,
7389 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7390 config: Config{
7391 MaxVersion: VersionTLS12,
7392 Bugs: ProtocolBugs{
7393 FragmentAcrossChangeCipherSpec: true,
7394 PackHandshakeFlight: packed,
7395 },
7396 },
7397 shouldFail: true,
7398 expectedError: ":UNEXPECTED_RECORD:",
7399 })
7400 testCases = append(testCases, testCase{
7401 testType: serverTest,
7402 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7403 config: Config{
7404 MaxVersion: VersionTLS12,
7405 },
7406 resumeSession: true,
7407 resumeConfig: &Config{
7408 MaxVersion: VersionTLS12,
7409 Bugs: ProtocolBugs{
7410 FragmentAcrossChangeCipherSpec: true,
7411 PackHandshakeFlight: packed,
7412 },
7413 },
7414 shouldFail: true,
7415 expectedError: ":UNEXPECTED_RECORD:",
7416 })
7417 testCases = append(testCases, testCase{
7418 testType: serverTest,
7419 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7420 config: Config{
7421 MaxVersion: VersionTLS12,
7422 NextProtos: []string{"bar"},
7423 Bugs: ProtocolBugs{
7424 FragmentAcrossChangeCipherSpec: true,
7425 PackHandshakeFlight: packed,
7426 },
7427 },
7428 flags: []string{
7429 "-advertise-npn", "\x03foo\x03bar\x03baz",
7430 },
7431 shouldFail: true,
7432 expectedError: ":UNEXPECTED_RECORD:",
7433 })
7434 }
7435
7436 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7437 // messages in the handshake queue. Do this by testing the server
7438 // reading the client Finished, reversing the flight so Finished comes
7439 // first.
7440 testCases = append(testCases, testCase{
7441 protocol: dtls,
7442 testType: serverTest,
7443 name: "SendUnencryptedFinished-DTLS",
7444 config: Config{
7445 MaxVersion: VersionTLS12,
7446 Bugs: ProtocolBugs{
7447 SendUnencryptedFinished: true,
7448 ReverseHandshakeFragments: true,
7449 },
7450 },
7451 shouldFail: true,
7452 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7453 })
7454
7455 // Test synchronization between encryption changes and the handshake in
7456 // TLS 1.3, where ChangeCipherSpec is implicit.
7457 testCases = append(testCases, testCase{
7458 name: "PartialEncryptedExtensionsWithServerHello",
7459 config: Config{
7460 MaxVersion: VersionTLS13,
7461 Bugs: ProtocolBugs{
7462 PartialEncryptedExtensionsWithServerHello: true,
7463 },
7464 },
7465 shouldFail: true,
7466 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7467 })
7468 testCases = append(testCases, testCase{
7469 testType: serverTest,
7470 name: "PartialClientFinishedWithClientHello",
7471 config: Config{
7472 MaxVersion: VersionTLS13,
7473 Bugs: ProtocolBugs{
7474 PartialClientFinishedWithClientHello: true,
7475 },
7476 },
7477 shouldFail: true,
7478 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7479 })
7480
7481 // Test that early ChangeCipherSpecs are handled correctly.
7482 testCases = append(testCases, testCase{
7483 testType: serverTest,
7484 name: "EarlyChangeCipherSpec-server-1",
7485 config: Config{
7486 MaxVersion: VersionTLS12,
7487 Bugs: ProtocolBugs{
7488 EarlyChangeCipherSpec: 1,
7489 },
7490 },
7491 shouldFail: true,
7492 expectedError: ":UNEXPECTED_RECORD:",
7493 })
7494 testCases = append(testCases, testCase{
7495 testType: serverTest,
7496 name: "EarlyChangeCipherSpec-server-2",
7497 config: Config{
7498 MaxVersion: VersionTLS12,
7499 Bugs: ProtocolBugs{
7500 EarlyChangeCipherSpec: 2,
7501 },
7502 },
7503 shouldFail: true,
7504 expectedError: ":UNEXPECTED_RECORD:",
7505 })
7506 testCases = append(testCases, testCase{
7507 protocol: dtls,
7508 name: "StrayChangeCipherSpec",
7509 config: Config{
7510 // TODO(davidben): Once DTLS 1.3 exists, test
7511 // that stray ChangeCipherSpec messages are
7512 // rejected.
7513 MaxVersion: VersionTLS12,
7514 Bugs: ProtocolBugs{
7515 StrayChangeCipherSpec: true,
7516 },
7517 },
7518 })
7519
7520 // Test that the contents of ChangeCipherSpec are checked.
7521 testCases = append(testCases, testCase{
7522 name: "BadChangeCipherSpec-1",
7523 config: Config{
7524 MaxVersion: VersionTLS12,
7525 Bugs: ProtocolBugs{
7526 BadChangeCipherSpec: []byte{2},
7527 },
7528 },
7529 shouldFail: true,
7530 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7531 })
7532 testCases = append(testCases, testCase{
7533 name: "BadChangeCipherSpec-2",
7534 config: Config{
7535 MaxVersion: VersionTLS12,
7536 Bugs: ProtocolBugs{
7537 BadChangeCipherSpec: []byte{1, 1},
7538 },
7539 },
7540 shouldFail: true,
7541 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7542 })
7543 testCases = append(testCases, testCase{
7544 protocol: dtls,
7545 name: "BadChangeCipherSpec-DTLS-1",
7546 config: Config{
7547 MaxVersion: VersionTLS12,
7548 Bugs: ProtocolBugs{
7549 BadChangeCipherSpec: []byte{2},
7550 },
7551 },
7552 shouldFail: true,
7553 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7554 })
7555 testCases = append(testCases, testCase{
7556 protocol: dtls,
7557 name: "BadChangeCipherSpec-DTLS-2",
7558 config: Config{
7559 MaxVersion: VersionTLS12,
7560 Bugs: ProtocolBugs{
7561 BadChangeCipherSpec: []byte{1, 1},
7562 },
7563 },
7564 shouldFail: true,
7565 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7566 })
7567}
7568
David Benjamin7c0d06c2016-08-11 13:26:41 -04007569type perMessageTest struct {
7570 messageType uint8
7571 test testCase
7572}
7573
7574// makePerMessageTests returns a series of test templates which cover each
7575// message in the TLS handshake. These may be used with bugs like
7576// WrongMessageType to fully test a per-message bug.
7577func makePerMessageTests() []perMessageTest {
7578 var ret []perMessageTest
David Benjaminc895d6b2016-08-11 13:26:41 -04007579 for _, protocol := range []protocol{tls, dtls} {
7580 var suffix string
7581 if protocol == dtls {
7582 suffix = "-DTLS"
7583 }
7584
David Benjamin7c0d06c2016-08-11 13:26:41 -04007585 ret = append(ret, perMessageTest{
7586 messageType: typeClientHello,
7587 test: testCase{
7588 protocol: protocol,
7589 testType: serverTest,
7590 name: "ClientHello" + suffix,
7591 config: Config{
7592 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007593 },
7594 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007595 })
7596
7597 if protocol == dtls {
David Benjamin7c0d06c2016-08-11 13:26:41 -04007598 ret = append(ret, perMessageTest{
7599 messageType: typeHelloVerifyRequest,
7600 test: testCase{
7601 protocol: protocol,
7602 name: "HelloVerifyRequest" + suffix,
7603 config: Config{
7604 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007605 },
7606 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007607 })
7608 }
7609
David Benjamin7c0d06c2016-08-11 13:26:41 -04007610 ret = append(ret, perMessageTest{
7611 messageType: typeServerHello,
7612 test: testCase{
7613 protocol: protocol,
7614 name: "ServerHello" + suffix,
7615 config: Config{
7616 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007617 },
7618 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007619 })
7620
David Benjamin7c0d06c2016-08-11 13:26:41 -04007621 ret = append(ret, perMessageTest{
7622 messageType: typeCertificate,
7623 test: testCase{
7624 protocol: protocol,
7625 name: "ServerCertificate" + suffix,
7626 config: Config{
7627 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007628 },
7629 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007630 })
7631
David Benjamin7c0d06c2016-08-11 13:26:41 -04007632 ret = append(ret, perMessageTest{
7633 messageType: typeCertificateStatus,
7634 test: testCase{
7635 protocol: protocol,
7636 name: "CertificateStatus" + suffix,
7637 config: Config{
7638 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007639 },
David Benjamin7c0d06c2016-08-11 13:26:41 -04007640 flags: []string{"-enable-ocsp-stapling"},
David Benjaminc895d6b2016-08-11 13:26:41 -04007641 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007642 })
7643
David Benjamin7c0d06c2016-08-11 13:26:41 -04007644 ret = append(ret, perMessageTest{
7645 messageType: typeServerKeyExchange,
7646 test: testCase{
7647 protocol: protocol,
7648 name: "ServerKeyExchange" + suffix,
7649 config: Config{
7650 MaxVersion: VersionTLS12,
7651 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminc895d6b2016-08-11 13:26:41 -04007652 },
7653 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007654 })
7655
David Benjamin7c0d06c2016-08-11 13:26:41 -04007656 ret = append(ret, perMessageTest{
7657 messageType: typeCertificateRequest,
7658 test: testCase{
7659 protocol: protocol,
7660 name: "CertificateRequest" + suffix,
7661 config: Config{
7662 MaxVersion: VersionTLS12,
7663 ClientAuth: RequireAnyClientCert,
David Benjaminc895d6b2016-08-11 13:26:41 -04007664 },
7665 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007666 })
7667
David Benjamin7c0d06c2016-08-11 13:26:41 -04007668 ret = append(ret, perMessageTest{
7669 messageType: typeServerHelloDone,
7670 test: testCase{
7671 protocol: protocol,
7672 name: "ServerHelloDone" + suffix,
7673 config: Config{
7674 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007675 },
7676 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007677 })
7678
David Benjamin7c0d06c2016-08-11 13:26:41 -04007679 ret = append(ret, perMessageTest{
7680 messageType: typeCertificate,
7681 test: testCase{
7682 testType: serverTest,
7683 protocol: protocol,
7684 name: "ClientCertificate" + suffix,
7685 config: Config{
7686 Certificates: []Certificate{rsaCertificate},
7687 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007688 },
David Benjamin7c0d06c2016-08-11 13:26:41 -04007689 flags: []string{"-require-any-client-certificate"},
David Benjaminc895d6b2016-08-11 13:26:41 -04007690 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007691 })
7692
David Benjamin7c0d06c2016-08-11 13:26:41 -04007693 ret = append(ret, perMessageTest{
7694 messageType: typeCertificateVerify,
7695 test: testCase{
7696 testType: serverTest,
7697 protocol: protocol,
7698 name: "CertificateVerify" + suffix,
7699 config: Config{
7700 Certificates: []Certificate{rsaCertificate},
7701 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007702 },
David Benjamin7c0d06c2016-08-11 13:26:41 -04007703 flags: []string{"-require-any-client-certificate"},
David Benjaminc895d6b2016-08-11 13:26:41 -04007704 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007705 })
7706
David Benjamin7c0d06c2016-08-11 13:26:41 -04007707 ret = append(ret, perMessageTest{
7708 messageType: typeClientKeyExchange,
7709 test: testCase{
7710 testType: serverTest,
7711 protocol: protocol,
7712 name: "ClientKeyExchange" + suffix,
7713 config: Config{
7714 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007715 },
7716 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007717 })
7718
7719 if protocol != dtls {
David Benjamin7c0d06c2016-08-11 13:26:41 -04007720 ret = append(ret, perMessageTest{
7721 messageType: typeNextProtocol,
7722 test: testCase{
7723 testType: serverTest,
7724 protocol: protocol,
7725 name: "NextProtocol" + suffix,
7726 config: Config{
7727 MaxVersion: VersionTLS12,
7728 NextProtos: []string{"bar"},
David Benjaminc895d6b2016-08-11 13:26:41 -04007729 },
David Benjamin7c0d06c2016-08-11 13:26:41 -04007730 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjaminc895d6b2016-08-11 13:26:41 -04007731 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007732 })
7733
David Benjamin7c0d06c2016-08-11 13:26:41 -04007734 ret = append(ret, perMessageTest{
7735 messageType: typeChannelID,
7736 test: testCase{
7737 testType: serverTest,
7738 protocol: protocol,
7739 name: "ChannelID" + suffix,
7740 config: Config{
7741 MaxVersion: VersionTLS12,
7742 ChannelID: channelIDKey,
7743 },
7744 flags: []string{
7745 "-expect-channel-id",
7746 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjaminc895d6b2016-08-11 13:26:41 -04007747 },
7748 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007749 })
7750 }
7751
David Benjamin7c0d06c2016-08-11 13:26:41 -04007752 ret = append(ret, perMessageTest{
7753 messageType: typeFinished,
7754 test: testCase{
7755 testType: serverTest,
7756 protocol: protocol,
7757 name: "ClientFinished" + suffix,
7758 config: Config{
7759 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007760 },
7761 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007762 })
7763
David Benjamin7c0d06c2016-08-11 13:26:41 -04007764 ret = append(ret, perMessageTest{
7765 messageType: typeNewSessionTicket,
7766 test: testCase{
7767 protocol: protocol,
7768 name: "NewSessionTicket" + suffix,
7769 config: Config{
7770 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007771 },
7772 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007773 })
7774
David Benjamin7c0d06c2016-08-11 13:26:41 -04007775 ret = append(ret, perMessageTest{
7776 messageType: typeFinished,
7777 test: testCase{
7778 protocol: protocol,
7779 name: "ServerFinished" + suffix,
7780 config: Config{
7781 MaxVersion: VersionTLS12,
David Benjaminc895d6b2016-08-11 13:26:41 -04007782 },
7783 },
David Benjaminc895d6b2016-08-11 13:26:41 -04007784 })
7785
7786 }
David Benjamin7c0d06c2016-08-11 13:26:41 -04007787
7788 ret = append(ret, perMessageTest{
7789 messageType: typeClientHello,
7790 test: testCase{
7791 testType: serverTest,
7792 name: "TLS13-ClientHello",
7793 config: Config{
7794 MaxVersion: VersionTLS13,
7795 },
7796 },
7797 })
7798
7799 ret = append(ret, perMessageTest{
7800 messageType: typeServerHello,
7801 test: testCase{
7802 name: "TLS13-ServerHello",
7803 config: Config{
7804 MaxVersion: VersionTLS13,
7805 },
7806 },
7807 })
7808
7809 ret = append(ret, perMessageTest{
7810 messageType: typeEncryptedExtensions,
7811 test: testCase{
7812 name: "TLS13-EncryptedExtensions",
7813 config: Config{
7814 MaxVersion: VersionTLS13,
7815 },
7816 },
7817 })
7818
7819 ret = append(ret, perMessageTest{
7820 messageType: typeCertificateRequest,
7821 test: testCase{
7822 name: "TLS13-CertificateRequest",
7823 config: Config{
7824 MaxVersion: VersionTLS13,
7825 ClientAuth: RequireAnyClientCert,
7826 },
7827 },
7828 })
7829
7830 ret = append(ret, perMessageTest{
7831 messageType: typeCertificate,
7832 test: testCase{
7833 name: "TLS13-ServerCertificate",
7834 config: Config{
7835 MaxVersion: VersionTLS13,
7836 },
7837 },
7838 })
7839
7840 ret = append(ret, perMessageTest{
7841 messageType: typeCertificateVerify,
7842 test: testCase{
7843 name: "TLS13-ServerCertificateVerify",
7844 config: Config{
7845 MaxVersion: VersionTLS13,
7846 },
7847 },
7848 })
7849
7850 ret = append(ret, perMessageTest{
7851 messageType: typeFinished,
7852 test: testCase{
7853 name: "TLS13-ServerFinished",
7854 config: Config{
7855 MaxVersion: VersionTLS13,
7856 },
7857 },
7858 })
7859
7860 ret = append(ret, perMessageTest{
7861 messageType: typeCertificate,
7862 test: testCase{
7863 testType: serverTest,
7864 name: "TLS13-ClientCertificate",
7865 config: Config{
7866 Certificates: []Certificate{rsaCertificate},
7867 MaxVersion: VersionTLS13,
7868 },
7869 flags: []string{"-require-any-client-certificate"},
7870 },
7871 })
7872
7873 ret = append(ret, perMessageTest{
7874 messageType: typeCertificateVerify,
7875 test: testCase{
7876 testType: serverTest,
7877 name: "TLS13-ClientCertificateVerify",
7878 config: Config{
7879 Certificates: []Certificate{rsaCertificate},
7880 MaxVersion: VersionTLS13,
7881 },
7882 flags: []string{"-require-any-client-certificate"},
7883 },
7884 })
7885
7886 ret = append(ret, perMessageTest{
7887 messageType: typeFinished,
7888 test: testCase{
7889 testType: serverTest,
7890 name: "TLS13-ClientFinished",
7891 config: Config{
7892 MaxVersion: VersionTLS13,
7893 },
7894 },
7895 })
7896
7897 return ret
David Benjaminc895d6b2016-08-11 13:26:41 -04007898}
7899
David Benjamin7c0d06c2016-08-11 13:26:41 -04007900func addWrongMessageTypeTests() {
7901 for _, t := range makePerMessageTests() {
7902 t.test.name = "WrongMessageType-" + t.test.name
7903 t.test.config.Bugs.SendWrongMessageType = t.messageType
7904 t.test.shouldFail = true
7905 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
7906 t.test.expectedLocalError = "remote error: unexpected message"
David Benjaminc895d6b2016-08-11 13:26:41 -04007907
David Benjamin7c0d06c2016-08-11 13:26:41 -04007908 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7909 // In TLS 1.3, a bad ServerHello means the client sends
7910 // an unencrypted alert while the server expects
7911 // encryption, so the alert is not readable by runner.
7912 t.test.expectedLocalError = "local error: bad record MAC"
7913 }
David Benjaminc895d6b2016-08-11 13:26:41 -04007914
David Benjamin7c0d06c2016-08-11 13:26:41 -04007915 testCases = append(testCases, t.test)
7916 }
7917}
David Benjaminc895d6b2016-08-11 13:26:41 -04007918
David Benjamin7c0d06c2016-08-11 13:26:41 -04007919func addTrailingMessageDataTests() {
7920 for _, t := range makePerMessageTests() {
7921 t.test.name = "TrailingMessageData-" + t.test.name
7922 t.test.config.Bugs.SendTrailingMessageData = t.messageType
7923 t.test.shouldFail = true
7924 t.test.expectedError = ":DECODE_ERROR:"
7925 t.test.expectedLocalError = "remote error: error decoding message"
David Benjaminc895d6b2016-08-11 13:26:41 -04007926
David Benjamin7c0d06c2016-08-11 13:26:41 -04007927 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7928 // In TLS 1.3, a bad ServerHello means the client sends
7929 // an unencrypted alert while the server expects
7930 // encryption, so the alert is not readable by runner.
7931 t.test.expectedLocalError = "local error: bad record MAC"
7932 }
David Benjaminc895d6b2016-08-11 13:26:41 -04007933
David Benjamin7c0d06c2016-08-11 13:26:41 -04007934 if t.messageType == typeFinished {
7935 // Bad Finished messages read as the verify data having
7936 // the wrong length.
7937 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
7938 t.test.expectedLocalError = "remote error: error decrypting message"
7939 }
David Benjaminc895d6b2016-08-11 13:26:41 -04007940
David Benjamin7c0d06c2016-08-11 13:26:41 -04007941 testCases = append(testCases, t.test)
7942 }
David Benjaminc895d6b2016-08-11 13:26:41 -04007943}
7944
7945func addTLS13HandshakeTests() {
7946 testCases = append(testCases, testCase{
7947 testType: clientTest,
7948 name: "MissingKeyShare-Client",
7949 config: Config{
7950 MaxVersion: VersionTLS13,
7951 Bugs: ProtocolBugs{
7952 MissingKeyShare: true,
7953 },
7954 },
7955 shouldFail: true,
7956 expectedError: ":MISSING_KEY_SHARE:",
7957 })
7958
7959 testCases = append(testCases, testCase{
7960 testType: serverTest,
7961 name: "MissingKeyShare-Server",
7962 config: Config{
7963 MaxVersion: VersionTLS13,
7964 Bugs: ProtocolBugs{
7965 MissingKeyShare: true,
7966 },
7967 },
7968 shouldFail: true,
7969 expectedError: ":MISSING_KEY_SHARE:",
7970 })
7971
7972 testCases = append(testCases, testCase{
David Benjaminc895d6b2016-08-11 13:26:41 -04007973 testType: serverTest,
7974 name: "DuplicateKeyShares",
7975 config: Config{
7976 MaxVersion: VersionTLS13,
7977 Bugs: ProtocolBugs{
7978 DuplicateKeyShares: true,
7979 },
7980 },
David Benjamin7c0d06c2016-08-11 13:26:41 -04007981 shouldFail: true,
7982 expectedError: ":DUPLICATE_KEY_SHARE:",
David Benjaminc895d6b2016-08-11 13:26:41 -04007983 })
7984
7985 testCases = append(testCases, testCase{
7986 testType: clientTest,
7987 name: "EmptyEncryptedExtensions",
7988 config: Config{
7989 MaxVersion: VersionTLS13,
7990 Bugs: ProtocolBugs{
7991 EmptyEncryptedExtensions: true,
7992 },
7993 },
7994 shouldFail: true,
7995 expectedLocalError: "remote error: error decoding message",
7996 })
7997
7998 testCases = append(testCases, testCase{
7999 testType: clientTest,
8000 name: "EncryptedExtensionsWithKeyShare",
8001 config: Config{
8002 MaxVersion: VersionTLS13,
8003 Bugs: ProtocolBugs{
8004 EncryptedExtensionsWithKeyShare: true,
8005 },
8006 },
8007 shouldFail: true,
8008 expectedLocalError: "remote error: unsupported extension",
8009 })
8010
8011 testCases = append(testCases, testCase{
8012 testType: serverTest,
8013 name: "SendHelloRetryRequest",
8014 config: Config{
8015 MaxVersion: VersionTLS13,
8016 // Require a HelloRetryRequest for every curve.
8017 DefaultCurves: []CurveID{},
8018 },
8019 expectedCurveID: CurveX25519,
8020 })
8021
8022 testCases = append(testCases, testCase{
8023 testType: serverTest,
8024 name: "SendHelloRetryRequest-2",
8025 config: Config{
8026 MaxVersion: VersionTLS13,
8027 DefaultCurves: []CurveID{CurveP384},
8028 },
8029 // Although the ClientHello did not predict our preferred curve,
8030 // we always select it whether it is predicted or not.
8031 expectedCurveID: CurveX25519,
8032 })
8033
8034 testCases = append(testCases, testCase{
8035 name: "UnknownCurve-HelloRetryRequest",
8036 config: Config{
8037 MaxVersion: VersionTLS13,
8038 // P-384 requires HelloRetryRequest in BoringSSL.
8039 CurvePreferences: []CurveID{CurveP384},
8040 Bugs: ProtocolBugs{
8041 SendHelloRetryRequestCurve: bogusCurve,
8042 },
8043 },
8044 shouldFail: true,
8045 expectedError: ":WRONG_CURVE:",
8046 })
8047
8048 testCases = append(testCases, testCase{
8049 name: "DisabledCurve-HelloRetryRequest",
8050 config: Config{
8051 MaxVersion: VersionTLS13,
8052 CurvePreferences: []CurveID{CurveP256},
8053 Bugs: ProtocolBugs{
8054 IgnorePeerCurvePreferences: true,
8055 },
8056 },
8057 flags: []string{"-p384-only"},
8058 shouldFail: true,
8059 expectedError: ":WRONG_CURVE:",
8060 })
8061
8062 testCases = append(testCases, testCase{
8063 name: "UnnecessaryHelloRetryRequest",
8064 config: Config{
8065 MaxVersion: VersionTLS13,
8066 Bugs: ProtocolBugs{
8067 UnnecessaryHelloRetryRequest: true,
8068 },
8069 },
8070 shouldFail: true,
8071 expectedError: ":WRONG_CURVE:",
8072 })
8073
8074 testCases = append(testCases, testCase{
8075 name: "SecondHelloRetryRequest",
8076 config: Config{
8077 MaxVersion: VersionTLS13,
8078 // P-384 requires HelloRetryRequest in BoringSSL.
8079 CurvePreferences: []CurveID{CurveP384},
8080 Bugs: ProtocolBugs{
8081 SecondHelloRetryRequest: true,
8082 },
8083 },
8084 shouldFail: true,
8085 expectedError: ":UNEXPECTED_MESSAGE:",
8086 })
8087
8088 testCases = append(testCases, testCase{
8089 testType: serverTest,
8090 name: "SecondClientHelloMissingKeyShare",
8091 config: Config{
8092 MaxVersion: VersionTLS13,
8093 DefaultCurves: []CurveID{},
8094 Bugs: ProtocolBugs{
8095 SecondClientHelloMissingKeyShare: true,
8096 },
8097 },
8098 shouldFail: true,
8099 expectedError: ":MISSING_KEY_SHARE:",
8100 })
8101
8102 testCases = append(testCases, testCase{
8103 testType: serverTest,
8104 name: "SecondClientHelloWrongCurve",
8105 config: Config{
8106 MaxVersion: VersionTLS13,
8107 DefaultCurves: []CurveID{},
8108 Bugs: ProtocolBugs{
8109 MisinterpretHelloRetryRequestCurve: CurveP521,
8110 },
8111 },
8112 shouldFail: true,
8113 expectedError: ":WRONG_CURVE:",
8114 })
8115
8116 testCases = append(testCases, testCase{
8117 name: "HelloRetryRequestVersionMismatch",
8118 config: Config{
8119 MaxVersion: VersionTLS13,
8120 // P-384 requires HelloRetryRequest in BoringSSL.
8121 CurvePreferences: []CurveID{CurveP384},
8122 Bugs: ProtocolBugs{
8123 SendServerHelloVersion: 0x0305,
8124 },
8125 },
8126 shouldFail: true,
8127 expectedError: ":WRONG_VERSION_NUMBER:",
8128 })
8129
8130 testCases = append(testCases, testCase{
8131 name: "HelloRetryRequestCurveMismatch",
8132 config: Config{
8133 MaxVersion: VersionTLS13,
8134 // P-384 requires HelloRetryRequest in BoringSSL.
8135 CurvePreferences: []CurveID{CurveP384},
8136 Bugs: ProtocolBugs{
8137 // Send P-384 (correct) in the HelloRetryRequest.
8138 SendHelloRetryRequestCurve: CurveP384,
8139 // But send P-256 in the ServerHello.
8140 SendCurve: CurveP256,
8141 },
8142 },
8143 shouldFail: true,
8144 expectedError: ":WRONG_CURVE:",
8145 })
8146
8147 // Test the server selecting a curve that requires a HelloRetryRequest
8148 // without sending it.
8149 testCases = append(testCases, testCase{
8150 name: "SkipHelloRetryRequest",
8151 config: Config{
8152 MaxVersion: VersionTLS13,
8153 // P-384 requires HelloRetryRequest in BoringSSL.
8154 CurvePreferences: []CurveID{CurveP384},
8155 Bugs: ProtocolBugs{
8156 SkipHelloRetryRequest: true,
8157 },
8158 },
8159 shouldFail: true,
8160 expectedError: ":WRONG_CURVE:",
Adam Langley4139edb2016-01-13 15:00:54 -08008161 })
David Benjaminf0c4a6c2016-08-11 13:26:41 -04008162
8163 testCases = append(testCases, testCase{
8164 name: "TLS13-RequestContextInHandshake",
8165 config: Config{
8166 MaxVersion: VersionTLS13,
8167 MinVersion: VersionTLS13,
8168 ClientAuth: RequireAnyClientCert,
8169 Bugs: ProtocolBugs{
8170 SendRequestContext: []byte("request context"),
8171 },
8172 },
8173 flags: []string{
8174 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8175 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8176 },
8177 shouldFail: true,
8178 expectedError: ":DECODE_ERROR:",
8179 })
David Benjamin7c0d06c2016-08-11 13:26:41 -04008180
8181 testCases = append(testCases, testCase{
8182 testType: serverTest,
8183 name: "TLS13-TrailingKeyShareData",
8184 config: Config{
8185 MaxVersion: VersionTLS13,
8186 Bugs: ProtocolBugs{
8187 TrailingKeyShareData: true,
8188 },
8189 },
8190 shouldFail: true,
8191 expectedError: ":DECODE_ERROR:",
8192 })
Adam Langley4139edb2016-01-13 15:00:54 -08008193}
8194
Kenny Rootb8494592015-09-25 02:29:14 +00008195func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langleyd9e397b2015-01-22 14:27:53 -08008196 defer wg.Done()
8197
8198 for test := range c {
8199 var err error
8200
8201 if *mallocTest < 0 {
8202 statusChan <- statusMsg{test: test, started: true}
Kenny Rootb8494592015-09-25 02:29:14 +00008203 err = runTest(test, shimPath, -1)
Adam Langleyd9e397b2015-01-22 14:27:53 -08008204 } else {
8205 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8206 statusChan <- statusMsg{test: test, started: true}
Kenny Rootb8494592015-09-25 02:29:14 +00008207 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langleyd9e397b2015-01-22 14:27:53 -08008208 if err != nil {
8209 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8210 }
8211 break
8212 }
8213 }
8214 }
8215 statusChan <- statusMsg{test: test, err: err}
8216 }
8217}
8218
8219type statusMsg struct {
8220 test *testCase
8221 started bool
8222 err error
8223}
8224
Adam Langleye9ada862015-05-11 17:20:37 -07008225func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
David Benjaminc895d6b2016-08-11 13:26:41 -04008226 var started, done, failed, unimplemented, lineLen int
Adam Langleyd9e397b2015-01-22 14:27:53 -08008227
Adam Langleye9ada862015-05-11 17:20:37 -07008228 testOutput := newTestOutput()
Adam Langleyd9e397b2015-01-22 14:27:53 -08008229 for msg := range statusChan {
Adam Langleye9ada862015-05-11 17:20:37 -07008230 if !*pipe {
8231 // Erase the previous status line.
8232 var erase string
8233 for i := 0; i < lineLen; i++ {
8234 erase += "\b \b"
8235 }
8236 fmt.Print(erase)
8237 }
8238
Adam Langleyd9e397b2015-01-22 14:27:53 -08008239 if msg.started {
8240 started++
8241 } else {
8242 done++
Adam Langleye9ada862015-05-11 17:20:37 -07008243
8244 if msg.err != nil {
David Benjaminc895d6b2016-08-11 13:26:41 -04008245 if msg.err == errUnimplemented {
8246 if *pipe {
8247 // Print each test instead of a status line.
8248 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8249 }
8250 unimplemented++
8251 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8252 } else {
8253 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8254 failed++
8255 testOutput.addResult(msg.test.name, "FAIL")
8256 }
Adam Langleye9ada862015-05-11 17:20:37 -07008257 } else {
8258 if *pipe {
8259 // Print each test instead of a status line.
8260 fmt.Printf("PASSED (%s)\n", msg.test.name)
8261 }
8262 testOutput.addResult(msg.test.name, "PASS")
8263 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08008264 }
8265
Adam Langleye9ada862015-05-11 17:20:37 -07008266 if !*pipe {
8267 // Print a new status line.
David Benjaminc895d6b2016-08-11 13:26:41 -04008268 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
Adam Langleye9ada862015-05-11 17:20:37 -07008269 lineLen = len(line)
8270 os.Stdout.WriteString(line)
Adam Langleyd9e397b2015-01-22 14:27:53 -08008271 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08008272 }
Adam Langleye9ada862015-05-11 17:20:37 -07008273
8274 doneChan <- testOutput
Adam Langleyd9e397b2015-01-22 14:27:53 -08008275}
8276
8277func main() {
Kenny Roota04d78d2015-09-25 00:26:37 +00008278 flag.Parse()
Kenny Rootb8494592015-09-25 02:29:14 +00008279 *resourceDir = path.Clean(*resourceDir)
David Benjaminc895d6b2016-08-11 13:26:41 -04008280 initCertificates()
Kenny Roota04d78d2015-09-25 00:26:37 +00008281
Kenny Rootb8494592015-09-25 02:29:14 +00008282 addBasicTests()
Adam Langleyd9e397b2015-01-22 14:27:53 -08008283 addCipherSuiteTests()
8284 addBadECDSASignatureTests()
8285 addCBCPaddingTests()
8286 addCBCSplittingTests()
8287 addClientAuthTests()
Adam Langleye9ada862015-05-11 17:20:37 -07008288 addDDoSCallbackTests()
Adam Langleyd9e397b2015-01-22 14:27:53 -08008289 addVersionNegotiationTests()
8290 addMinimumVersionTests()
Adam Langleyd9e397b2015-01-22 14:27:53 -08008291 addExtensionTests()
8292 addResumptionVersionTests()
8293 addExtendedMasterSecretTests()
8294 addRenegotiationTests()
8295 addDTLSReplayTests()
David Benjaminc895d6b2016-08-11 13:26:41 -04008296 addSignatureAlgorithmTests()
Adam Langleye9ada862015-05-11 17:20:37 -07008297 addDTLSRetransmitTests()
8298 addExportKeyingMaterialTests()
Adam Langleyf4e42722015-06-04 17:45:09 -07008299 addTLSUniqueTests()
Kenny Rootb8494592015-09-25 02:29:14 +00008300 addCustomExtensionTests()
Adam Langley4139edb2016-01-13 15:00:54 -08008301 addRSAClientKeyExchangeTests()
8302 addCurveTests()
David Benjaminc895d6b2016-08-11 13:26:41 -04008303 addCECPQ1Tests()
David Benjaminf0c4a6c2016-08-11 13:26:41 -04008304 addDHEGroupSizeTests()
David Benjaminc895d6b2016-08-11 13:26:41 -04008305 addTLS13RecordTests()
8306 addAllStateMachineCoverageTests()
8307 addChangeCipherSpecTests()
8308 addWrongMessageTypeTests()
David Benjamin7c0d06c2016-08-11 13:26:41 -04008309 addTrailingMessageDataTests()
David Benjaminc895d6b2016-08-11 13:26:41 -04008310 addTLS13HandshakeTests()
Adam Langleyd9e397b2015-01-22 14:27:53 -08008311
8312 var wg sync.WaitGroup
8313
Kenny Rootb8494592015-09-25 02:29:14 +00008314 statusChan := make(chan statusMsg, *numWorkers)
8315 testChan := make(chan *testCase, *numWorkers)
Adam Langleye9ada862015-05-11 17:20:37 -07008316 doneChan := make(chan *testOutput)
Adam Langleyd9e397b2015-01-22 14:27:53 -08008317
David Benjaminc895d6b2016-08-11 13:26:41 -04008318 if len(*shimConfigFile) != 0 {
8319 encoded, err := ioutil.ReadFile(*shimConfigFile)
8320 if err != nil {
8321 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8322 os.Exit(1)
8323 }
8324
8325 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8326 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8327 os.Exit(1)
8328 }
8329 }
8330
Adam Langleyd9e397b2015-01-22 14:27:53 -08008331 go statusPrinter(doneChan, statusChan, len(testCases))
8332
Kenny Rootb8494592015-09-25 02:29:14 +00008333 for i := 0; i < *numWorkers; i++ {
Adam Langleyd9e397b2015-01-22 14:27:53 -08008334 wg.Add(1)
Kenny Rootb8494592015-09-25 02:29:14 +00008335 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langleyd9e397b2015-01-22 14:27:53 -08008336 }
8337
David Benjamin4969cc92016-04-22 15:02:23 -04008338 var foundTest bool
Adam Langleyd9e397b2015-01-22 14:27:53 -08008339 for i := range testCases {
David Benjaminc895d6b2016-08-11 13:26:41 -04008340 matched := true
8341 if len(*testToRun) != 0 {
8342 var err error
8343 matched, err = filepath.Match(*testToRun, testCases[i].name)
8344 if err != nil {
8345 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8346 os.Exit(1)
8347 }
8348 }
8349
8350 if !*includeDisabled {
8351 for pattern := range shimConfig.DisabledTests {
8352 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8353 if err != nil {
8354 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8355 os.Exit(1)
8356 }
8357
8358 if isDisabled {
8359 matched = false
8360 break
8361 }
8362 }
8363 }
8364
8365 if matched {
David Benjamin4969cc92016-04-22 15:02:23 -04008366 foundTest = true
Adam Langleyd9e397b2015-01-22 14:27:53 -08008367 testChan <- &testCases[i]
8368 }
8369 }
David Benjaminc895d6b2016-08-11 13:26:41 -04008370
David Benjamin4969cc92016-04-22 15:02:23 -04008371 if !foundTest {
David Benjaminc895d6b2016-08-11 13:26:41 -04008372 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin4969cc92016-04-22 15:02:23 -04008373 os.Exit(1)
8374 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08008375
8376 close(testChan)
8377 wg.Wait()
8378 close(statusChan)
Adam Langleye9ada862015-05-11 17:20:37 -07008379 testOutput := <-doneChan
Adam Langleyd9e397b2015-01-22 14:27:53 -08008380
8381 fmt.Printf("\n")
Adam Langleye9ada862015-05-11 17:20:37 -07008382
8383 if *jsonOutput != "" {
8384 if err := testOutput.writeTo(*jsonOutput); err != nil {
8385 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8386 }
8387 }
8388
David Benjaminc895d6b2016-08-11 13:26:41 -04008389 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8390 os.Exit(1)
8391 }
8392
8393 if !testOutput.noneFailed {
Adam Langleye9ada862015-05-11 17:20:37 -07008394 os.Exit(1)
8395 }
Adam Langleyd9e397b2015-01-22 14:27:53 -08008396}