blob: b328c156bc314ea7ca00e93c539ae2fe477537d7 [file] [log] [blame]
Adam Langley95c29f32014-06-20 12:00:00 -07001package main
2
3import (
4 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -04005 "crypto/ecdsa"
6 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -04007 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -04008 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -04009 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070010 "flag"
11 "fmt"
12 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070013 "io/ioutil"
Adam Langley95c29f32014-06-20 12:00:00 -070014 "net"
15 "os"
16 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040017 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040018 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080019 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070020 "strings"
21 "sync"
22 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050023 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070024)
25
Adam Langley69a01602014-11-17 17:26:55 -080026var (
David Benjamin5f237bc2015-02-11 17:14:15 -050027 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
28 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
29 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
30 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
31 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.")
32 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
33 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley69a01602014-11-17 17:26:55 -080034)
Adam Langley95c29f32014-06-20 12:00:00 -070035
David Benjamin025b3d32014-07-01 19:53:04 -040036const (
37 rsaCertificateFile = "cert.pem"
38 ecdsaCertificateFile = "ecdsa_cert.pem"
39)
40
41const (
David Benjamina08e49d2014-08-24 01:46:07 -040042 rsaKeyFile = "key.pem"
43 ecdsaKeyFile = "ecdsa_key.pem"
44 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040045)
46
Adam Langley95c29f32014-06-20 12:00:00 -070047var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040048var channelIDKey *ecdsa.PrivateKey
49var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070050
David Benjamin61f95272014-11-25 01:55:35 -050051var testOCSPResponse = []byte{1, 2, 3, 4}
52var testSCTList = []byte{5, 6, 7, 8}
53
Adam Langley95c29f32014-06-20 12:00:00 -070054func initCertificates() {
55 var err error
David Benjamin025b3d32014-07-01 19:53:04 -040056 rsaCertificate, err = LoadX509KeyPair(rsaCertificateFile, rsaKeyFile)
Adam Langley95c29f32014-06-20 12:00:00 -070057 if err != nil {
58 panic(err)
59 }
David Benjamin61f95272014-11-25 01:55:35 -050060 rsaCertificate.OCSPStaple = testOCSPResponse
61 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070062
David Benjamin025b3d32014-07-01 19:53:04 -040063 ecdsaCertificate, err = LoadX509KeyPair(ecdsaCertificateFile, ecdsaKeyFile)
Adam Langley95c29f32014-06-20 12:00:00 -070064 if err != nil {
65 panic(err)
66 }
David Benjamin61f95272014-11-25 01:55:35 -050067 ecdsaCertificate.OCSPStaple = testOCSPResponse
68 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040069
70 channelIDPEMBlock, err := ioutil.ReadFile(channelIDKeyFile)
71 if err != nil {
72 panic(err)
73 }
74 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
75 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
76 panic("bad key type")
77 }
78 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
79 if err != nil {
80 panic(err)
81 }
82 if channelIDKey.Curve != elliptic.P256() {
83 panic("bad curve")
84 }
85
86 channelIDBytes = make([]byte, 64)
87 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
88 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -070089}
90
91var certificateOnce sync.Once
92
93func getRSACertificate() Certificate {
94 certificateOnce.Do(initCertificates)
95 return rsaCertificate
96}
97
98func getECDSACertificate() Certificate {
99 certificateOnce.Do(initCertificates)
100 return ecdsaCertificate
101}
102
David Benjamin025b3d32014-07-01 19:53:04 -0400103type testType int
104
105const (
106 clientTest testType = iota
107 serverTest
108)
109
David Benjamin6fd297b2014-08-11 18:43:38 -0400110type protocol int
111
112const (
113 tls protocol = iota
114 dtls
115)
116
David Benjaminfc7b0862014-09-06 13:21:53 -0400117const (
118 alpn = 1
119 npn = 2
120)
121
Adam Langley95c29f32014-06-20 12:00:00 -0700122type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400123 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400124 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700125 name string
126 config Config
127 shouldFail bool
128 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700129 // expectedLocalError, if not empty, contains a substring that must be
130 // found in the local error.
131 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400132 // expectedVersion, if non-zero, specifies the TLS version that must be
133 // negotiated.
134 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400135 // expectedResumeVersion, if non-zero, specifies the TLS version that
136 // must be negotiated on resumption. If zero, expectedVersion is used.
137 expectedResumeVersion uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400138 // expectChannelID controls whether the connection should have
139 // negotiated a Channel ID with channelIDKey.
140 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400141 // expectedNextProto controls whether the connection should
142 // negotiate a next protocol via NPN or ALPN.
143 expectedNextProto string
David Benjaminfc7b0862014-09-06 13:21:53 -0400144 // expectedNextProtoType, if non-zero, is the expected next
145 // protocol negotiation mechanism.
146 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500147 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
148 // should be negotiated. If zero, none should be negotiated.
149 expectedSRTPProtectionProfile uint16
Adam Langley80842bd2014-06-20 12:00:00 -0700150 // messageLen is the length, in bytes, of the test message that will be
151 // sent.
152 messageLen int
David Benjamin025b3d32014-07-01 19:53:04 -0400153 // certFile is the path to the certificate to use for the server.
154 certFile string
155 // keyFile is the path to the private key to use for the server.
156 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400157 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400158 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400159 resumeSession bool
David Benjamin01fe8202014-09-24 15:21:44 -0400160 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500161 // resumption. Unless newSessionsOnResume is set,
162 // SessionTicketKey, ServerSessionCache, and
163 // ClientSessionCache are copied from the initial connection's
164 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400165 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500166 // newSessionsOnResume, if true, will cause resumeConfig to
167 // use a different session resumption context.
168 newSessionsOnResume bool
David Benjamin98e882e2014-08-08 13:24:34 -0400169 // sendPrefix sends a prefix on the socket before actually performing a
170 // handshake.
171 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400172 // shimWritesFirst controls whether the shim sends an initial "hello"
173 // message before doing a roundtrip with the runner.
174 shimWritesFirst bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700175 // renegotiate indicates the the connection should be renegotiated
176 // during the exchange.
177 renegotiate bool
178 // renegotiateCiphers is a list of ciphersuite ids that will be
179 // switched in just before renegotiation.
180 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500181 // replayWrites, if true, configures the underlying transport
182 // to replay every write it makes in DTLS tests.
183 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500184 // damageFirstWrite, if true, configures the underlying transport to
185 // damage the final byte of the first application data write.
186 damageFirstWrite bool
David Benjamin325b5c32014-07-01 19:40:31 -0400187 // flags, if not empty, contains a list of command-line flags that will
188 // be passed to the shim program.
189 flags []string
Adam Langley95c29f32014-06-20 12:00:00 -0700190}
191
David Benjamin025b3d32014-07-01 19:53:04 -0400192var testCases = []testCase{
Adam Langley95c29f32014-06-20 12:00:00 -0700193 {
194 name: "BadRSASignature",
195 config: Config{
196 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
197 Bugs: ProtocolBugs{
198 InvalidSKXSignature: true,
199 },
200 },
201 shouldFail: true,
202 expectedError: ":BAD_SIGNATURE:",
203 },
204 {
205 name: "BadECDSASignature",
206 config: Config{
207 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
208 Bugs: ProtocolBugs{
209 InvalidSKXSignature: true,
210 },
211 Certificates: []Certificate{getECDSACertificate()},
212 },
213 shouldFail: true,
214 expectedError: ":BAD_SIGNATURE:",
215 },
216 {
217 name: "BadECDSACurve",
218 config: Config{
219 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
220 Bugs: ProtocolBugs{
221 InvalidSKXCurve: true,
222 },
223 Certificates: []Certificate{getECDSACertificate()},
224 },
225 shouldFail: true,
226 expectedError: ":WRONG_CURVE:",
227 },
Adam Langleyac61fa32014-06-23 12:03:11 -0700228 {
David Benjamina8e3e0e2014-08-06 22:11:10 -0400229 testType: serverTest,
230 name: "BadRSAVersion",
231 config: Config{
232 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
233 Bugs: ProtocolBugs{
234 RsaClientKeyExchangeVersion: VersionTLS11,
235 },
236 },
237 shouldFail: true,
238 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
239 },
240 {
David Benjamin325b5c32014-07-01 19:40:31 -0400241 name: "NoFallbackSCSV",
Adam Langleyac61fa32014-06-23 12:03:11 -0700242 config: Config{
243 Bugs: ProtocolBugs{
244 FailIfNotFallbackSCSV: true,
245 },
246 },
247 shouldFail: true,
248 expectedLocalError: "no fallback SCSV found",
249 },
David Benjamin325b5c32014-07-01 19:40:31 -0400250 {
David Benjamin2a0c4962014-08-22 23:46:35 -0400251 name: "SendFallbackSCSV",
David Benjamin325b5c32014-07-01 19:40:31 -0400252 config: Config{
253 Bugs: ProtocolBugs{
254 FailIfNotFallbackSCSV: true,
255 },
256 },
257 flags: []string{"-fallback-scsv"},
258 },
David Benjamin197b3ab2014-07-02 18:37:33 -0400259 {
David Benjamin7b030512014-07-08 17:30:11 -0400260 name: "ClientCertificateTypes",
261 config: Config{
262 ClientAuth: RequestClientCert,
263 ClientCertificateTypes: []byte{
264 CertTypeDSSSign,
265 CertTypeRSASign,
266 CertTypeECDSASign,
267 },
268 },
David Benjamin2561dc32014-08-24 01:25:27 -0400269 flags: []string{
270 "-expect-certificate-types",
271 base64.StdEncoding.EncodeToString([]byte{
272 CertTypeDSSSign,
273 CertTypeRSASign,
274 CertTypeECDSASign,
275 }),
276 },
David Benjamin7b030512014-07-08 17:30:11 -0400277 },
David Benjamin636293b2014-07-08 17:59:18 -0400278 {
279 name: "NoClientCertificate",
280 config: Config{
281 ClientAuth: RequireAnyClientCert,
282 },
283 shouldFail: true,
284 expectedLocalError: "client didn't provide a certificate",
285 },
David Benjamin1c375dd2014-07-12 00:48:23 -0400286 {
287 name: "UnauthenticatedECDH",
288 config: Config{
289 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
290 Bugs: ProtocolBugs{
291 UnauthenticatedECDH: true,
292 },
293 },
294 shouldFail: true,
David Benjamine8f3d662014-07-12 01:10:19 -0400295 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin1c375dd2014-07-12 00:48:23 -0400296 },
David Benjamin9c651c92014-07-12 13:27:45 -0400297 {
298 name: "SkipServerKeyExchange",
299 config: Config{
300 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
301 Bugs: ProtocolBugs{
302 SkipServerKeyExchange: true,
303 },
304 },
305 shouldFail: true,
306 expectedError: ":UNEXPECTED_MESSAGE:",
307 },
David Benjamin1f5f62b2014-07-12 16:18:02 -0400308 {
David Benjamina0e52232014-07-19 17:39:58 -0400309 name: "SkipChangeCipherSpec-Client",
310 config: Config{
311 Bugs: ProtocolBugs{
312 SkipChangeCipherSpec: true,
313 },
314 },
315 shouldFail: true,
David Benjamin86271ee2014-07-21 16:14:03 -0400316 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
David Benjamina0e52232014-07-19 17:39:58 -0400317 },
318 {
319 testType: serverTest,
320 name: "SkipChangeCipherSpec-Server",
321 config: Config{
322 Bugs: ProtocolBugs{
323 SkipChangeCipherSpec: true,
324 },
325 },
326 shouldFail: true,
David Benjamin86271ee2014-07-21 16:14:03 -0400327 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
David Benjamina0e52232014-07-19 17:39:58 -0400328 },
David Benjamin42be6452014-07-21 14:50:23 -0400329 {
330 testType: serverTest,
331 name: "SkipChangeCipherSpec-Server-NPN",
332 config: Config{
333 NextProtos: []string{"bar"},
334 Bugs: ProtocolBugs{
335 SkipChangeCipherSpec: true,
336 },
337 },
338 flags: []string{
339 "-advertise-npn", "\x03foo\x03bar\x03baz",
340 },
341 shouldFail: true,
David Benjamin86271ee2014-07-21 16:14:03 -0400342 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
343 },
344 {
345 name: "FragmentAcrossChangeCipherSpec-Client",
346 config: Config{
347 Bugs: ProtocolBugs{
348 FragmentAcrossChangeCipherSpec: true,
349 },
350 },
351 shouldFail: true,
352 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
353 },
354 {
355 testType: serverTest,
356 name: "FragmentAcrossChangeCipherSpec-Server",
357 config: Config{
358 Bugs: ProtocolBugs{
359 FragmentAcrossChangeCipherSpec: true,
360 },
361 },
362 shouldFail: true,
363 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
364 },
365 {
366 testType: serverTest,
367 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
368 config: Config{
369 NextProtos: []string{"bar"},
370 Bugs: ProtocolBugs{
371 FragmentAcrossChangeCipherSpec: true,
372 },
373 },
374 flags: []string{
375 "-advertise-npn", "\x03foo\x03bar\x03baz",
376 },
377 shouldFail: true,
378 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
David Benjamin42be6452014-07-21 14:50:23 -0400379 },
David Benjaminf3ec83d2014-07-21 22:42:34 -0400380 {
381 testType: serverTest,
David Benjamin3fd1fbd2015-02-03 16:07:32 -0500382 name: "Alert",
383 config: Config{
384 Bugs: ProtocolBugs{
385 SendSpuriousAlert: alertRecordOverflow,
386 },
387 },
388 shouldFail: true,
389 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
390 },
391 {
392 protocol: dtls,
393 testType: serverTest,
394 name: "Alert-DTLS",
395 config: Config{
396 Bugs: ProtocolBugs{
397 SendSpuriousAlert: alertRecordOverflow,
398 },
399 },
400 shouldFail: true,
401 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
402 },
403 {
404 testType: serverTest,
Alex Chernyakhovsky4cd8c432014-11-01 19:39:08 -0400405 name: "FragmentAlert",
406 config: Config{
407 Bugs: ProtocolBugs{
David Benjaminca6c8262014-11-15 19:06:08 -0500408 FragmentAlert: true,
David Benjamin3fd1fbd2015-02-03 16:07:32 -0500409 SendSpuriousAlert: alertRecordOverflow,
Alex Chernyakhovsky4cd8c432014-11-01 19:39:08 -0400410 },
411 },
412 shouldFail: true,
413 expectedError: ":BAD_ALERT:",
414 },
415 {
David Benjamin0ea8dda2015-01-31 20:33:40 -0500416 protocol: dtls,
417 testType: serverTest,
418 name: "FragmentAlert-DTLS",
419 config: Config{
420 Bugs: ProtocolBugs{
421 FragmentAlert: true,
David Benjamin3fd1fbd2015-02-03 16:07:32 -0500422 SendSpuriousAlert: alertRecordOverflow,
David Benjamin0ea8dda2015-01-31 20:33:40 -0500423 },
424 },
425 shouldFail: true,
426 expectedError: ":BAD_ALERT:",
427 },
428 {
Alex Chernyakhovsky4cd8c432014-11-01 19:39:08 -0400429 testType: serverTest,
David Benjaminf3ec83d2014-07-21 22:42:34 -0400430 name: "EarlyChangeCipherSpec-server-1",
431 config: Config{
432 Bugs: ProtocolBugs{
433 EarlyChangeCipherSpec: 1,
434 },
435 },
436 shouldFail: true,
437 expectedError: ":CCS_RECEIVED_EARLY:",
438 },
439 {
440 testType: serverTest,
441 name: "EarlyChangeCipherSpec-server-2",
442 config: Config{
443 Bugs: ProtocolBugs{
444 EarlyChangeCipherSpec: 2,
445 },
446 },
447 shouldFail: true,
448 expectedError: ":CCS_RECEIVED_EARLY:",
449 },
David Benjamind23f4122014-07-23 15:09:48 -0400450 {
David Benjamind23f4122014-07-23 15:09:48 -0400451 name: "SkipNewSessionTicket",
452 config: Config{
453 Bugs: ProtocolBugs{
454 SkipNewSessionTicket: true,
455 },
456 },
457 shouldFail: true,
458 expectedError: ":CCS_RECEIVED_EARLY:",
459 },
David Benjamin7e3305e2014-07-28 14:52:32 -0400460 {
David Benjamind86c7672014-08-02 04:07:12 -0400461 testType: serverTest,
David Benjaminbef270a2014-08-02 04:22:02 -0400462 name: "FallbackSCSV",
463 config: Config{
464 MaxVersion: VersionTLS11,
465 Bugs: ProtocolBugs{
466 SendFallbackSCSV: true,
467 },
468 },
469 shouldFail: true,
470 expectedError: ":INAPPROPRIATE_FALLBACK:",
471 },
472 {
473 testType: serverTest,
474 name: "FallbackSCSV-VersionMatch",
475 config: Config{
476 Bugs: ProtocolBugs{
477 SendFallbackSCSV: true,
478 },
479 },
480 },
David Benjamin98214542014-08-07 18:02:39 -0400481 {
482 testType: serverTest,
483 name: "FragmentedClientVersion",
484 config: Config{
485 Bugs: ProtocolBugs{
486 MaxHandshakeRecordLength: 1,
487 FragmentClientVersion: true,
488 },
489 },
David Benjamin82c9e902014-12-12 15:55:27 -0500490 expectedVersion: VersionTLS12,
David Benjamin98214542014-08-07 18:02:39 -0400491 },
David Benjamin98e882e2014-08-08 13:24:34 -0400492 {
493 testType: serverTest,
494 name: "MinorVersionTolerance",
495 config: Config{
496 Bugs: ProtocolBugs{
497 SendClientVersion: 0x03ff,
498 },
499 },
500 expectedVersion: VersionTLS12,
501 },
502 {
503 testType: serverTest,
504 name: "MajorVersionTolerance",
505 config: Config{
506 Bugs: ProtocolBugs{
507 SendClientVersion: 0x0400,
508 },
509 },
510 expectedVersion: VersionTLS12,
511 },
512 {
513 testType: serverTest,
514 name: "VersionTooLow",
515 config: Config{
516 Bugs: ProtocolBugs{
517 SendClientVersion: 0x0200,
518 },
519 },
520 shouldFail: true,
521 expectedError: ":UNSUPPORTED_PROTOCOL:",
522 },
523 {
524 testType: serverTest,
525 name: "HttpGET",
526 sendPrefix: "GET / HTTP/1.0\n",
527 shouldFail: true,
528 expectedError: ":HTTP_REQUEST:",
529 },
530 {
531 testType: serverTest,
532 name: "HttpPOST",
533 sendPrefix: "POST / HTTP/1.0\n",
534 shouldFail: true,
535 expectedError: ":HTTP_REQUEST:",
536 },
537 {
538 testType: serverTest,
539 name: "HttpHEAD",
540 sendPrefix: "HEAD / HTTP/1.0\n",
541 shouldFail: true,
542 expectedError: ":HTTP_REQUEST:",
543 },
544 {
545 testType: serverTest,
546 name: "HttpPUT",
547 sendPrefix: "PUT / HTTP/1.0\n",
548 shouldFail: true,
549 expectedError: ":HTTP_REQUEST:",
550 },
551 {
552 testType: serverTest,
553 name: "HttpCONNECT",
554 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
555 shouldFail: true,
556 expectedError: ":HTTPS_PROXY_REQUEST:",
557 },
David Benjamin39ebf532014-08-31 02:23:49 -0400558 {
David Benjaminf080ecd2014-12-11 18:48:59 -0500559 testType: serverTest,
560 name: "Garbage",
561 sendPrefix: "blah",
562 shouldFail: true,
563 expectedError: ":UNKNOWN_PROTOCOL:",
564 },
565 {
David Benjamin39ebf532014-08-31 02:23:49 -0400566 name: "SkipCipherVersionCheck",
567 config: Config{
568 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
569 MaxVersion: VersionTLS11,
570 Bugs: ProtocolBugs{
571 SkipCipherVersionCheck: true,
572 },
573 },
574 shouldFail: true,
575 expectedError: ":WRONG_CIPHER_RETURNED:",
576 },
David Benjamin9114fae2014-11-08 11:41:14 -0500577 {
David Benjamina3e89492015-02-26 15:16:22 -0500578 name: "RSAEphemeralKey",
David Benjamin9114fae2014-11-08 11:41:14 -0500579 config: Config{
580 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
581 Bugs: ProtocolBugs{
David Benjamina3e89492015-02-26 15:16:22 -0500582 RSAEphemeralKey: true,
David Benjamin9114fae2014-11-08 11:41:14 -0500583 },
584 },
585 shouldFail: true,
586 expectedError: ":UNEXPECTED_MESSAGE:",
587 },
David Benjamin128dbc32014-12-01 01:27:42 -0500588 {
589 name: "DisableEverything",
590 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
591 shouldFail: true,
592 expectedError: ":WRONG_SSL_VERSION:",
593 },
594 {
595 protocol: dtls,
596 name: "DisableEverything-DTLS",
597 flags: []string{"-no-tls12", "-no-tls1"},
598 shouldFail: true,
599 expectedError: ":WRONG_SSL_VERSION:",
600 },
David Benjamin780d6dd2015-01-06 12:03:19 -0500601 {
602 name: "NoSharedCipher",
603 config: Config{
604 CipherSuites: []uint16{},
605 },
606 shouldFail: true,
607 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
608 },
David Benjamin13be1de2015-01-11 16:29:36 -0500609 {
610 protocol: dtls,
611 testType: serverTest,
612 name: "MTU",
613 config: Config{
614 Bugs: ProtocolBugs{
615 MaxPacketLength: 256,
616 },
617 },
618 flags: []string{"-mtu", "256"},
619 },
620 {
621 protocol: dtls,
622 testType: serverTest,
623 name: "MTUExceeded",
624 config: Config{
625 Bugs: ProtocolBugs{
626 MaxPacketLength: 255,
627 },
628 },
629 flags: []string{"-mtu", "256"},
630 shouldFail: true,
631 expectedLocalError: "dtls: exceeded maximum packet length",
632 },
David Benjamin6095de82014-12-27 01:50:38 -0500633 {
634 name: "CertMismatchRSA",
635 config: Config{
636 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
637 Certificates: []Certificate{getECDSACertificate()},
638 Bugs: ProtocolBugs{
639 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
640 },
641 },
642 shouldFail: true,
643 expectedError: ":WRONG_CERTIFICATE_TYPE:",
644 },
645 {
646 name: "CertMismatchECDSA",
647 config: Config{
648 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
649 Certificates: []Certificate{getRSACertificate()},
650 Bugs: ProtocolBugs{
651 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
652 },
653 },
654 shouldFail: true,
655 expectedError: ":WRONG_CERTIFICATE_TYPE:",
656 },
David Benjamin5fa3eba2015-01-22 16:35:40 -0500657 {
658 name: "TLSFatalBadPackets",
659 damageFirstWrite: true,
660 shouldFail: true,
661 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
662 },
663 {
664 protocol: dtls,
665 name: "DTLSIgnoreBadPackets",
666 damageFirstWrite: true,
667 },
668 {
669 protocol: dtls,
670 name: "DTLSIgnoreBadPackets-Async",
671 damageFirstWrite: true,
672 flags: []string{"-async"},
673 },
David Benjamin4189bd92015-01-25 23:52:39 -0500674 {
675 name: "AppDataAfterChangeCipherSpec",
676 config: Config{
677 Bugs: ProtocolBugs{
678 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
679 },
680 },
681 shouldFail: true,
682 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
683 },
684 {
685 protocol: dtls,
686 name: "AppDataAfterChangeCipherSpec-DTLS",
687 config: Config{
688 Bugs: ProtocolBugs{
689 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
690 },
691 },
692 },
David Benjaminb3774b92015-01-31 17:16:01 -0500693 {
David Benjamindc3da932015-03-12 15:09:02 -0400694 name: "AlertAfterChangeCipherSpec",
695 config: Config{
696 Bugs: ProtocolBugs{
697 AlertAfterChangeCipherSpec: alertRecordOverflow,
698 },
699 },
700 shouldFail: true,
701 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
702 },
703 {
704 protocol: dtls,
705 name: "AlertAfterChangeCipherSpec-DTLS",
706 config: Config{
707 Bugs: ProtocolBugs{
708 AlertAfterChangeCipherSpec: alertRecordOverflow,
709 },
710 },
711 shouldFail: true,
712 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
713 },
714 {
David Benjaminb3774b92015-01-31 17:16:01 -0500715 protocol: dtls,
716 name: "ReorderHandshakeFragments-Small-DTLS",
717 config: Config{
718 Bugs: ProtocolBugs{
719 ReorderHandshakeFragments: true,
720 // Small enough that every handshake message is
721 // fragmented.
722 MaxHandshakeRecordLength: 2,
723 },
724 },
725 },
726 {
727 protocol: dtls,
728 name: "ReorderHandshakeFragments-Large-DTLS",
729 config: Config{
730 Bugs: ProtocolBugs{
731 ReorderHandshakeFragments: true,
732 // Large enough that no handshake message is
733 // fragmented.
David Benjaminb3774b92015-01-31 17:16:01 -0500734 MaxHandshakeRecordLength: 2048,
735 },
736 },
737 },
David Benjaminddb9f152015-02-03 15:44:39 -0500738 {
David Benjamin75381222015-03-02 19:30:30 -0500739 protocol: dtls,
740 name: "MixCompleteMessageWithFragments-DTLS",
741 config: Config{
742 Bugs: ProtocolBugs{
743 ReorderHandshakeFragments: true,
744 MixCompleteMessageWithFragments: true,
745 MaxHandshakeRecordLength: 2,
746 },
747 },
748 },
749 {
David Benjaminddb9f152015-02-03 15:44:39 -0500750 name: "SendInvalidRecordType",
751 config: Config{
752 Bugs: ProtocolBugs{
753 SendInvalidRecordType: true,
754 },
755 },
756 shouldFail: true,
757 expectedError: ":UNEXPECTED_RECORD:",
758 },
759 {
760 protocol: dtls,
761 name: "SendInvalidRecordType-DTLS",
762 config: Config{
763 Bugs: ProtocolBugs{
764 SendInvalidRecordType: true,
765 },
766 },
767 shouldFail: true,
768 expectedError: ":UNEXPECTED_RECORD:",
769 },
David Benjaminb80168e2015-02-08 18:30:14 -0500770 {
771 name: "FalseStart-SkipServerSecondLeg",
772 config: Config{
773 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
774 NextProtos: []string{"foo"},
775 Bugs: ProtocolBugs{
776 SkipNewSessionTicket: true,
777 SkipChangeCipherSpec: true,
778 SkipFinished: true,
779 ExpectFalseStart: true,
780 },
781 },
782 flags: []string{
783 "-false-start",
David Benjamin87e4acd2015-04-02 19:57:35 -0400784 "-handshake-never-done",
David Benjaminb80168e2015-02-08 18:30:14 -0500785 "-advertise-alpn", "\x03foo",
786 },
787 shimWritesFirst: true,
788 shouldFail: true,
789 expectedError: ":UNEXPECTED_RECORD:",
790 },
David Benjamin931ab342015-02-08 19:46:57 -0500791 {
792 name: "FalseStart-SkipServerSecondLeg-Implicit",
793 config: Config{
794 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
795 NextProtos: []string{"foo"},
796 Bugs: ProtocolBugs{
797 SkipNewSessionTicket: true,
798 SkipChangeCipherSpec: true,
799 SkipFinished: true,
800 },
801 },
802 flags: []string{
803 "-implicit-handshake",
804 "-false-start",
David Benjamin87e4acd2015-04-02 19:57:35 -0400805 "-handshake-never-done",
David Benjamin931ab342015-02-08 19:46:57 -0500806 "-advertise-alpn", "\x03foo",
807 },
808 shouldFail: true,
809 expectedError: ":UNEXPECTED_RECORD:",
810 },
David Benjamin6f5c0f42015-02-24 01:23:21 -0500811 {
812 testType: serverTest,
813 name: "FailEarlyCallback",
814 flags: []string{"-fail-early-callback"},
815 shouldFail: true,
816 expectedError: ":CONNECTION_REJECTED:",
817 expectedLocalError: "remote error: access denied",
818 },
David Benjaminbcb2d912015-02-24 23:45:43 -0500819 {
820 name: "WrongMessageType",
821 config: Config{
822 Bugs: ProtocolBugs{
823 WrongCertificateMessageType: true,
824 },
825 },
826 shouldFail: true,
827 expectedError: ":UNEXPECTED_MESSAGE:",
828 expectedLocalError: "remote error: unexpected message",
829 },
830 {
831 protocol: dtls,
832 name: "WrongMessageType-DTLS",
833 config: Config{
834 Bugs: ProtocolBugs{
835 WrongCertificateMessageType: true,
836 },
837 },
838 shouldFail: true,
839 expectedError: ":UNEXPECTED_MESSAGE:",
840 expectedLocalError: "remote error: unexpected message",
841 },
David Benjamin75381222015-03-02 19:30:30 -0500842 {
843 protocol: dtls,
844 name: "FragmentMessageTypeMismatch-DTLS",
845 config: Config{
846 Bugs: ProtocolBugs{
847 MaxHandshakeRecordLength: 2,
848 FragmentMessageTypeMismatch: true,
849 },
850 },
851 shouldFail: true,
852 expectedError: ":FRAGMENT_MISMATCH:",
853 },
854 {
855 protocol: dtls,
856 name: "FragmentMessageLengthMismatch-DTLS",
857 config: Config{
858 Bugs: ProtocolBugs{
859 MaxHandshakeRecordLength: 2,
860 FragmentMessageLengthMismatch: true,
861 },
862 },
863 shouldFail: true,
864 expectedError: ":FRAGMENT_MISMATCH:",
865 },
866 {
867 protocol: dtls,
868 name: "SplitFragmentHeader-DTLS",
869 config: Config{
870 Bugs: ProtocolBugs{
871 SplitFragmentHeader: true,
872 },
873 },
874 shouldFail: true,
875 expectedError: ":UNEXPECTED_MESSAGE:",
876 },
877 {
878 protocol: dtls,
879 name: "SplitFragmentBody-DTLS",
880 config: Config{
881 Bugs: ProtocolBugs{
882 SplitFragmentBody: true,
883 },
884 },
885 shouldFail: true,
886 expectedError: ":UNEXPECTED_MESSAGE:",
887 },
888 {
889 protocol: dtls,
890 name: "SendEmptyFragments-DTLS",
891 config: Config{
892 Bugs: ProtocolBugs{
893 SendEmptyFragments: true,
894 },
895 },
896 },
David Benjamin67d1fb52015-03-16 15:16:23 -0400897 {
898 name: "UnsupportedCipherSuite",
899 config: Config{
900 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
901 Bugs: ProtocolBugs{
902 IgnorePeerCipherPreferences: true,
903 },
904 },
905 flags: []string{"-cipher", "DEFAULT:!RC4"},
906 shouldFail: true,
907 expectedError: ":WRONG_CIPHER_RETURNED:",
908 },
David Benjamin340d5ed2015-03-21 02:21:37 -0400909 {
910 name: "SendWarningAlerts",
911 config: Config{
912 Bugs: ProtocolBugs{
913 SendWarningAlerts: alertAccessDenied,
914 },
915 },
916 },
917 {
918 protocol: dtls,
919 name: "SendWarningAlerts-DTLS",
920 config: Config{
921 Bugs: ProtocolBugs{
922 SendWarningAlerts: alertAccessDenied,
923 },
924 },
925 },
David Benjamin513f0ea2015-04-02 19:33:31 -0400926 {
927 name: "BadFinished",
928 config: Config{
929 Bugs: ProtocolBugs{
930 BadFinished: true,
931 },
932 },
933 shouldFail: true,
934 expectedError: ":DIGEST_CHECK_FAILED:",
935 },
936 {
937 name: "FalseStart-BadFinished",
938 config: Config{
939 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
940 NextProtos: []string{"foo"},
941 Bugs: ProtocolBugs{
942 BadFinished: true,
943 ExpectFalseStart: true,
944 },
945 },
946 flags: []string{
947 "-false-start",
David Benjamin87e4acd2015-04-02 19:57:35 -0400948 "-handshake-never-done",
David Benjamin513f0ea2015-04-02 19:33:31 -0400949 "-advertise-alpn", "\x03foo",
950 },
951 shimWritesFirst: true,
952 shouldFail: true,
953 expectedError: ":DIGEST_CHECK_FAILED:",
954 },
David Benjamin1c633152015-04-02 20:19:11 -0400955 {
956 name: "NoFalseStart-NoALPN",
957 config: Config{
958 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
959 Bugs: ProtocolBugs{
960 ExpectFalseStart: true,
961 AlertBeforeFalseStartTest: alertAccessDenied,
962 },
963 },
964 flags: []string{
965 "-false-start",
966 },
967 shimWritesFirst: true,
968 shouldFail: true,
969 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
970 expectedLocalError: "tls: peer did not false start: EOF",
971 },
972 {
973 name: "NoFalseStart-NoAEAD",
974 config: Config{
975 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
976 NextProtos: []string{"foo"},
977 Bugs: ProtocolBugs{
978 ExpectFalseStart: true,
979 AlertBeforeFalseStartTest: alertAccessDenied,
980 },
981 },
982 flags: []string{
983 "-false-start",
984 "-advertise-alpn", "\x03foo",
985 },
986 shimWritesFirst: true,
987 shouldFail: true,
988 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
989 expectedLocalError: "tls: peer did not false start: EOF",
990 },
991 {
992 name: "NoFalseStart-RSA",
993 config: Config{
994 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
995 NextProtos: []string{"foo"},
996 Bugs: ProtocolBugs{
997 ExpectFalseStart: true,
998 AlertBeforeFalseStartTest: alertAccessDenied,
999 },
1000 },
1001 flags: []string{
1002 "-false-start",
1003 "-advertise-alpn", "\x03foo",
1004 },
1005 shimWritesFirst: true,
1006 shouldFail: true,
1007 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1008 expectedLocalError: "tls: peer did not false start: EOF",
1009 },
1010 {
1011 name: "NoFalseStart-DHE_RSA",
1012 config: Config{
1013 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1014 NextProtos: []string{"foo"},
1015 Bugs: ProtocolBugs{
1016 ExpectFalseStart: true,
1017 AlertBeforeFalseStartTest: alertAccessDenied,
1018 },
1019 },
1020 flags: []string{
1021 "-false-start",
1022 "-advertise-alpn", "\x03foo",
1023 },
1024 shimWritesFirst: true,
1025 shouldFail: true,
1026 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1027 expectedLocalError: "tls: peer did not false start: EOF",
1028 },
Adam Langley95c29f32014-06-20 12:00:00 -07001029}
1030
David Benjamin01fe8202014-09-24 15:21:44 -04001031func doExchange(test *testCase, config *Config, conn net.Conn, messageLen int, isResume bool) error {
David Benjamin65ea8ff2014-11-23 03:01:00 -05001032 var connDebug *recordingConn
David Benjamin5fa3eba2015-01-22 16:35:40 -05001033 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -05001034 if *flagDebug {
1035 connDebug = &recordingConn{Conn: conn}
1036 conn = connDebug
1037 defer func() {
1038 connDebug.WriteTo(os.Stdout)
1039 }()
1040 }
1041
David Benjamin6fd297b2014-08-11 18:43:38 -04001042 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -05001043 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
1044 conn = config.Bugs.PacketAdaptor
David Benjamin5e961c12014-11-07 01:48:35 -05001045 if test.replayWrites {
1046 conn = newReplayAdaptor(conn)
1047 }
David Benjamin6fd297b2014-08-11 18:43:38 -04001048 }
1049
David Benjamin5fa3eba2015-01-22 16:35:40 -05001050 if test.damageFirstWrite {
1051 connDamage = newDamageAdaptor(conn)
1052 conn = connDamage
1053 }
1054
David Benjamin6fd297b2014-08-11 18:43:38 -04001055 if test.sendPrefix != "" {
1056 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
1057 return err
1058 }
David Benjamin98e882e2014-08-08 13:24:34 -04001059 }
1060
David Benjamin1d5c83e2014-07-22 19:20:02 -04001061 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001062 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -04001063 if test.protocol == dtls {
1064 tlsConn = DTLSServer(conn, config)
1065 } else {
1066 tlsConn = Server(conn, config)
1067 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001068 } else {
1069 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -04001070 if test.protocol == dtls {
1071 tlsConn = DTLSClient(conn, config)
1072 } else {
1073 tlsConn = Client(conn, config)
1074 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001075 }
1076
Adam Langley95c29f32014-06-20 12:00:00 -07001077 if err := tlsConn.Handshake(); err != nil {
1078 return err
1079 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07001080
David Benjamin01fe8202014-09-24 15:21:44 -04001081 // TODO(davidben): move all per-connection expectations into a dedicated
1082 // expectations struct that can be specified separately for the two
1083 // legs.
1084 expectedVersion := test.expectedVersion
1085 if isResume && test.expectedResumeVersion != 0 {
1086 expectedVersion = test.expectedResumeVersion
1087 }
1088 if vers := tlsConn.ConnectionState().Version; expectedVersion != 0 && vers != expectedVersion {
1089 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001090 }
1091
David Benjamina08e49d2014-08-24 01:46:07 -04001092 if test.expectChannelID {
1093 channelID := tlsConn.ConnectionState().ChannelID
1094 if channelID == nil {
1095 return fmt.Errorf("no channel ID negotiated")
1096 }
1097 if channelID.Curve != channelIDKey.Curve ||
1098 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
1099 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
1100 return fmt.Errorf("incorrect channel ID")
1101 }
1102 }
1103
David Benjaminae2888f2014-09-06 12:58:58 -04001104 if expected := test.expectedNextProto; expected != "" {
1105 if actual := tlsConn.ConnectionState().NegotiatedProtocol; actual != expected {
1106 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
1107 }
1108 }
1109
David Benjaminfc7b0862014-09-06 13:21:53 -04001110 if test.expectedNextProtoType != 0 {
1111 if (test.expectedNextProtoType == alpn) != tlsConn.ConnectionState().NegotiatedProtocolFromALPN {
1112 return fmt.Errorf("next proto type mismatch")
1113 }
1114 }
1115
David Benjaminca6c8262014-11-15 19:06:08 -05001116 if p := tlsConn.ConnectionState().SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
1117 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
1118 }
1119
David Benjamine58c4f52014-08-24 03:47:07 -04001120 if test.shimWritesFirst {
1121 var buf [5]byte
1122 _, err := io.ReadFull(tlsConn, buf[:])
1123 if err != nil {
1124 return err
1125 }
1126 if string(buf[:]) != "hello" {
1127 return fmt.Errorf("bad initial message")
1128 }
1129 }
1130
Adam Langleycf2d4f42014-10-28 19:06:14 -07001131 if test.renegotiate {
1132 if test.renegotiateCiphers != nil {
1133 config.CipherSuites = test.renegotiateCiphers
1134 }
1135 if err := tlsConn.Renegotiate(); err != nil {
1136 return err
1137 }
1138 } else if test.renegotiateCiphers != nil {
1139 panic("renegotiateCiphers without renegotiate")
1140 }
1141
David Benjamin5fa3eba2015-01-22 16:35:40 -05001142 if test.damageFirstWrite {
1143 connDamage.setDamage(true)
1144 tlsConn.Write([]byte("DAMAGED WRITE"))
1145 connDamage.setDamage(false)
1146 }
1147
Kenny Root7fdeaf12014-08-05 15:23:37 -07001148 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -04001149 if test.protocol == dtls {
1150 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
1151 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07001152 // Read until EOF.
1153 _, err := io.Copy(ioutil.Discard, tlsConn)
1154 return err
1155 }
1156
David Benjamin4189bd92015-01-25 23:52:39 -05001157 var testMessage []byte
1158 if config.Bugs.AppDataAfterChangeCipherSpec != nil {
1159 // We've already sent a message. Expect the shim to echo it
1160 // back.
1161 testMessage = config.Bugs.AppDataAfterChangeCipherSpec
1162 } else {
1163 if messageLen == 0 {
1164 messageLen = 32
1165 }
1166 testMessage = make([]byte, messageLen)
1167 for i := range testMessage {
1168 testMessage[i] = 0x42
1169 }
1170 tlsConn.Write(testMessage)
Adam Langley80842bd2014-06-20 12:00:00 -07001171 }
Adam Langley95c29f32014-06-20 12:00:00 -07001172
1173 buf := make([]byte, len(testMessage))
David Benjamin6fd297b2014-08-11 18:43:38 -04001174 if test.protocol == dtls {
1175 bufTmp := make([]byte, len(buf)+1)
1176 n, err := tlsConn.Read(bufTmp)
1177 if err != nil {
1178 return err
1179 }
1180 if n != len(buf) {
1181 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
1182 }
1183 copy(buf, bufTmp)
1184 } else {
1185 _, err := io.ReadFull(tlsConn, buf)
1186 if err != nil {
1187 return err
1188 }
Adam Langley95c29f32014-06-20 12:00:00 -07001189 }
1190
1191 for i, v := range buf {
1192 if v != testMessage[i]^0xff {
1193 return fmt.Errorf("bad reply contents at byte %d", i)
1194 }
1195 }
1196
1197 return nil
1198}
1199
David Benjamin325b5c32014-07-01 19:40:31 -04001200func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
1201 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -07001202 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -04001203 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -07001204 }
David Benjamin325b5c32014-07-01 19:40:31 -04001205 valgrindArgs = append(valgrindArgs, path)
1206 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -07001207
David Benjamin325b5c32014-07-01 19:40:31 -04001208 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -07001209}
1210
David Benjamin325b5c32014-07-01 19:40:31 -04001211func gdbOf(path string, args ...string) *exec.Cmd {
1212 xtermArgs := []string{"-e", "gdb", "--args"}
1213 xtermArgs = append(xtermArgs, path)
1214 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -07001215
David Benjamin325b5c32014-07-01 19:40:31 -04001216 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -07001217}
1218
Adam Langley69a01602014-11-17 17:26:55 -08001219type moreMallocsError struct{}
1220
1221func (moreMallocsError) Error() string {
1222 return "child process did not exhaust all allocation calls"
1223}
1224
1225var errMoreMallocs = moreMallocsError{}
1226
David Benjamin87c8a642015-02-21 01:54:29 -05001227// accept accepts a connection from listener, unless waitChan signals a process
1228// exit first.
1229func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
1230 type connOrError struct {
1231 conn net.Conn
1232 err error
1233 }
1234 connChan := make(chan connOrError, 1)
1235 go func() {
1236 conn, err := listener.Accept()
1237 connChan <- connOrError{conn, err}
1238 close(connChan)
1239 }()
1240 select {
1241 case result := <-connChan:
1242 return result.conn, result.err
1243 case childErr := <-waitChan:
1244 waitChan <- childErr
1245 return nil, fmt.Errorf("child exited early: %s", childErr)
1246 }
1247}
1248
Adam Langley69a01602014-11-17 17:26:55 -08001249func runTest(test *testCase, buildDir string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -07001250 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
1251 panic("Error expected without shouldFail in " + test.name)
1252 }
1253
David Benjamin87c8a642015-02-21 01:54:29 -05001254 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
1255 if err != nil {
1256 panic(err)
1257 }
1258 defer func() {
1259 if listener != nil {
1260 listener.Close()
1261 }
1262 }()
Adam Langley95c29f32014-06-20 12:00:00 -07001263
David Benjamin884fdf12014-08-02 15:28:23 -04001264 shim_path := path.Join(buildDir, "ssl/test/bssl_shim")
David Benjamin87c8a642015-02-21 01:54:29 -05001265 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -04001266 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -04001267 flags = append(flags, "-server")
1268
David Benjamin025b3d32014-07-01 19:53:04 -04001269 flags = append(flags, "-key-file")
1270 if test.keyFile == "" {
1271 flags = append(flags, rsaKeyFile)
1272 } else {
1273 flags = append(flags, test.keyFile)
1274 }
1275
1276 flags = append(flags, "-cert-file")
1277 if test.certFile == "" {
1278 flags = append(flags, rsaCertificateFile)
1279 } else {
1280 flags = append(flags, test.certFile)
1281 }
1282 }
David Benjamin5a593af2014-08-11 19:51:50 -04001283
David Benjamin6fd297b2014-08-11 18:43:38 -04001284 if test.protocol == dtls {
1285 flags = append(flags, "-dtls")
1286 }
1287
David Benjamin5a593af2014-08-11 19:51:50 -04001288 if test.resumeSession {
1289 flags = append(flags, "-resume")
1290 }
1291
David Benjamine58c4f52014-08-24 03:47:07 -04001292 if test.shimWritesFirst {
1293 flags = append(flags, "-shim-writes-first")
1294 }
1295
David Benjamin025b3d32014-07-01 19:53:04 -04001296 flags = append(flags, test.flags...)
1297
1298 var shim *exec.Cmd
1299 if *useValgrind {
1300 shim = valgrindOf(false, shim_path, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001301 } else if *useGDB {
1302 shim = gdbOf(shim_path, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001303 } else {
1304 shim = exec.Command(shim_path, flags...)
1305 }
David Benjamin025b3d32014-07-01 19:53:04 -04001306 shim.Stdin = os.Stdin
1307 var stdoutBuf, stderrBuf bytes.Buffer
1308 shim.Stdout = &stdoutBuf
1309 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001310 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001311 shim.Env = os.Environ()
1312 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001313 if *mallocTestDebug {
1314 shim.Env = append(shim.Env, "MALLOC_ABORT_ON_FAIL=1")
1315 }
1316 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1317 }
David Benjamin025b3d32014-07-01 19:53:04 -04001318
1319 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001320 panic(err)
1321 }
David Benjamin87c8a642015-02-21 01:54:29 -05001322 waitChan := make(chan error, 1)
1323 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001324
1325 config := test.config
David Benjamin1d5c83e2014-07-22 19:20:02 -04001326 config.ClientSessionCache = NewLRUClientSessionCache(1)
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001327 config.ServerSessionCache = NewLRUServerSessionCache(1)
David Benjamin025b3d32014-07-01 19:53:04 -04001328 if test.testType == clientTest {
1329 if len(config.Certificates) == 0 {
1330 config.Certificates = []Certificate{getRSACertificate()}
1331 }
David Benjamin87c8a642015-02-21 01:54:29 -05001332 } else {
1333 // Supply a ServerName to ensure a constant session cache key,
1334 // rather than falling back to net.Conn.RemoteAddr.
1335 if len(config.ServerName) == 0 {
1336 config.ServerName = "test"
1337 }
David Benjamin025b3d32014-07-01 19:53:04 -04001338 }
Adam Langley95c29f32014-06-20 12:00:00 -07001339
David Benjamin87c8a642015-02-21 01:54:29 -05001340 conn, err := acceptOrWait(listener, waitChan)
1341 if err == nil {
1342 err = doExchange(test, &config, conn, test.messageLen, false /* not a resumption */)
1343 conn.Close()
1344 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001345
David Benjamin1d5c83e2014-07-22 19:20:02 -04001346 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -04001347 var resumeConfig Config
1348 if test.resumeConfig != nil {
1349 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -05001350 if len(resumeConfig.ServerName) == 0 {
1351 resumeConfig.ServerName = config.ServerName
1352 }
David Benjamin01fe8202014-09-24 15:21:44 -04001353 if len(resumeConfig.Certificates) == 0 {
1354 resumeConfig.Certificates = []Certificate{getRSACertificate()}
1355 }
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001356 if !test.newSessionsOnResume {
1357 resumeConfig.SessionTicketKey = config.SessionTicketKey
1358 resumeConfig.ClientSessionCache = config.ClientSessionCache
1359 resumeConfig.ServerSessionCache = config.ServerSessionCache
1360 }
David Benjamin01fe8202014-09-24 15:21:44 -04001361 } else {
1362 resumeConfig = config
1363 }
David Benjamin87c8a642015-02-21 01:54:29 -05001364 var connResume net.Conn
1365 connResume, err = acceptOrWait(listener, waitChan)
1366 if err == nil {
1367 err = doExchange(test, &resumeConfig, connResume, test.messageLen, true /* resumption */)
1368 connResume.Close()
1369 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001370 }
1371
David Benjamin87c8a642015-02-21 01:54:29 -05001372 // Close the listener now. This is to avoid hangs should the shim try to
1373 // open more connections than expected.
1374 listener.Close()
1375 listener = nil
1376
1377 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -08001378 if exitError, ok := childErr.(*exec.ExitError); ok {
1379 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
1380 return errMoreMallocs
1381 }
1382 }
Adam Langley95c29f32014-06-20 12:00:00 -07001383
1384 stdout := string(stdoutBuf.Bytes())
1385 stderr := string(stderrBuf.Bytes())
1386 failed := err != nil || childErr != nil
1387 correctFailure := len(test.expectedError) == 0 || strings.Contains(stdout, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -07001388 localError := "none"
1389 if err != nil {
1390 localError = err.Error()
1391 }
1392 if len(test.expectedLocalError) != 0 {
1393 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1394 }
Adam Langley95c29f32014-06-20 12:00:00 -07001395
1396 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001397 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001398 if childErr != nil {
1399 childError = childErr.Error()
1400 }
1401
1402 var msg string
1403 switch {
1404 case failed && !test.shouldFail:
1405 msg = "unexpected failure"
1406 case !failed && test.shouldFail:
1407 msg = "unexpected success"
1408 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -07001409 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001410 default:
1411 panic("internal error")
1412 }
1413
1414 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, string(stdoutBuf.Bytes()), stderr)
1415 }
1416
1417 if !*useValgrind && len(stderr) > 0 {
1418 println(stderr)
1419 }
1420
1421 return nil
1422}
1423
1424var tlsVersions = []struct {
1425 name string
1426 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001427 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001428 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001429}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001430 {"SSL3", VersionSSL30, "-no-ssl3", false},
1431 {"TLS1", VersionTLS10, "-no-tls1", true},
1432 {"TLS11", VersionTLS11, "-no-tls11", false},
1433 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -07001434}
1435
1436var testCipherSuites = []struct {
1437 name string
1438 id uint16
1439}{
1440 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001441 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001442 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001443 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001444 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001445 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001446 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001447 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1448 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001449 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001450 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1451 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001452 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001453 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1454 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001455 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1456 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001457 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001458 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001459 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
David Benjamin2af684f2014-10-27 02:23:15 -04001460 {"ECDHE-PSK-WITH-AES-128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001461 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001462 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001463 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001464 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001465 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001466 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001467 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -04001468 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1469 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
1470 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001471 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001472 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001473}
1474
David Benjamin8b8c0062014-11-23 02:47:52 -05001475func hasComponent(suiteName, component string) bool {
1476 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1477}
1478
David Benjaminf7768e42014-08-31 02:06:47 -04001479func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001480 return hasComponent(suiteName, "GCM") ||
1481 hasComponent(suiteName, "SHA256") ||
1482 hasComponent(suiteName, "SHA384")
1483}
1484
1485func isDTLSCipher(suiteName string) bool {
David Benjamine95d20d2014-12-23 11:16:01 -05001486 return !hasComponent(suiteName, "RC4")
David Benjaminf7768e42014-08-31 02:06:47 -04001487}
1488
Adam Langley95c29f32014-06-20 12:00:00 -07001489func addCipherSuiteTests() {
1490 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04001491 const psk = "12345"
1492 const pskIdentity = "luggage combo"
1493
Adam Langley95c29f32014-06-20 12:00:00 -07001494 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04001495 var certFile string
1496 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05001497 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07001498 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001499 certFile = ecdsaCertificateFile
1500 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001501 } else {
1502 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001503 certFile = rsaCertificateFile
1504 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001505 }
1506
David Benjamin48cae082014-10-27 01:06:24 -04001507 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05001508 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04001509 flags = append(flags,
1510 "-psk", psk,
1511 "-psk-identity", pskIdentity)
1512 }
1513
Adam Langley95c29f32014-06-20 12:00:00 -07001514 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04001515 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07001516 continue
1517 }
1518
David Benjamin025b3d32014-07-01 19:53:04 -04001519 testCases = append(testCases, testCase{
1520 testType: clientTest,
1521 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07001522 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001523 MinVersion: ver.version,
1524 MaxVersion: ver.version,
1525 CipherSuites: []uint16{suite.id},
1526 Certificates: []Certificate{cert},
1527 PreSharedKey: []byte(psk),
1528 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07001529 },
David Benjamin48cae082014-10-27 01:06:24 -04001530 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001531 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07001532 })
David Benjamin025b3d32014-07-01 19:53:04 -04001533
David Benjamin76d8abe2014-08-14 16:25:34 -04001534 testCases = append(testCases, testCase{
1535 testType: serverTest,
1536 name: ver.name + "-" + suite.name + "-server",
1537 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001538 MinVersion: ver.version,
1539 MaxVersion: ver.version,
1540 CipherSuites: []uint16{suite.id},
1541 Certificates: []Certificate{cert},
1542 PreSharedKey: []byte(psk),
1543 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04001544 },
1545 certFile: certFile,
1546 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04001547 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001548 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04001549 })
David Benjamin6fd297b2014-08-11 18:43:38 -04001550
David Benjamin8b8c0062014-11-23 02:47:52 -05001551 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04001552 testCases = append(testCases, testCase{
1553 testType: clientTest,
1554 protocol: dtls,
1555 name: "D" + ver.name + "-" + suite.name + "-client",
1556 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001557 MinVersion: ver.version,
1558 MaxVersion: ver.version,
1559 CipherSuites: []uint16{suite.id},
1560 Certificates: []Certificate{cert},
1561 PreSharedKey: []byte(psk),
1562 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04001563 },
David Benjamin48cae082014-10-27 01:06:24 -04001564 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001565 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04001566 })
1567 testCases = append(testCases, testCase{
1568 testType: serverTest,
1569 protocol: dtls,
1570 name: "D" + ver.name + "-" + suite.name + "-server",
1571 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001572 MinVersion: ver.version,
1573 MaxVersion: ver.version,
1574 CipherSuites: []uint16{suite.id},
1575 Certificates: []Certificate{cert},
1576 PreSharedKey: []byte(psk),
1577 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04001578 },
1579 certFile: certFile,
1580 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04001581 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001582 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04001583 })
1584 }
Adam Langley95c29f32014-06-20 12:00:00 -07001585 }
1586 }
1587}
1588
1589func addBadECDSASignatureTests() {
1590 for badR := BadValue(1); badR < NumBadValues; badR++ {
1591 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04001592 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07001593 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
1594 config: Config{
1595 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1596 Certificates: []Certificate{getECDSACertificate()},
1597 Bugs: ProtocolBugs{
1598 BadECDSAR: badR,
1599 BadECDSAS: badS,
1600 },
1601 },
1602 shouldFail: true,
1603 expectedError: "SIGNATURE",
1604 })
1605 }
1606 }
1607}
1608
Adam Langley80842bd2014-06-20 12:00:00 -07001609func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04001610 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001611 name: "MaxCBCPadding",
1612 config: Config{
1613 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1614 Bugs: ProtocolBugs{
1615 MaxPadding: true,
1616 },
1617 },
1618 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
1619 })
David Benjamin025b3d32014-07-01 19:53:04 -04001620 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001621 name: "BadCBCPadding",
1622 config: Config{
1623 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1624 Bugs: ProtocolBugs{
1625 PaddingFirstByteBad: true,
1626 },
1627 },
1628 shouldFail: true,
1629 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
1630 })
1631 // OpenSSL previously had an issue where the first byte of padding in
1632 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04001633 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001634 name: "BadCBCPadding255",
1635 config: Config{
1636 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1637 Bugs: ProtocolBugs{
1638 MaxPadding: true,
1639 PaddingFirstByteBadIf255: true,
1640 },
1641 },
1642 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
1643 shouldFail: true,
1644 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
1645 })
1646}
1647
Kenny Root7fdeaf12014-08-05 15:23:37 -07001648func addCBCSplittingTests() {
1649 testCases = append(testCases, testCase{
1650 name: "CBCRecordSplitting",
1651 config: Config{
1652 MaxVersion: VersionTLS10,
1653 MinVersion: VersionTLS10,
1654 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1655 },
1656 messageLen: -1, // read until EOF
1657 flags: []string{
1658 "-async",
1659 "-write-different-record-sizes",
1660 "-cbc-record-splitting",
1661 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04001662 })
1663 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07001664 name: "CBCRecordSplittingPartialWrite",
1665 config: Config{
1666 MaxVersion: VersionTLS10,
1667 MinVersion: VersionTLS10,
1668 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1669 },
1670 messageLen: -1, // read until EOF
1671 flags: []string{
1672 "-async",
1673 "-write-different-record-sizes",
1674 "-cbc-record-splitting",
1675 "-partial-write",
1676 },
1677 })
1678}
1679
David Benjamin636293b2014-07-08 17:59:18 -04001680func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04001681 // Add a dummy cert pool to stress certificate authority parsing.
1682 // TODO(davidben): Add tests that those values parse out correctly.
1683 certPool := x509.NewCertPool()
1684 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
1685 if err != nil {
1686 panic(err)
1687 }
1688 certPool.AddCert(cert)
1689
David Benjamin636293b2014-07-08 17:59:18 -04001690 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04001691 testCases = append(testCases, testCase{
1692 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04001693 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04001694 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04001695 MinVersion: ver.version,
1696 MaxVersion: ver.version,
1697 ClientAuth: RequireAnyClientCert,
1698 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04001699 },
1700 flags: []string{
1701 "-cert-file", rsaCertificateFile,
1702 "-key-file", rsaKeyFile,
1703 },
1704 })
1705 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04001706 testType: serverTest,
1707 name: ver.name + "-Server-ClientAuth-RSA",
1708 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04001709 MinVersion: ver.version,
1710 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04001711 Certificates: []Certificate{rsaCertificate},
1712 },
1713 flags: []string{"-require-any-client-certificate"},
1714 })
David Benjamine098ec22014-08-27 23:13:20 -04001715 if ver.version != VersionSSL30 {
1716 testCases = append(testCases, testCase{
1717 testType: serverTest,
1718 name: ver.name + "-Server-ClientAuth-ECDSA",
1719 config: Config{
1720 MinVersion: ver.version,
1721 MaxVersion: ver.version,
1722 Certificates: []Certificate{ecdsaCertificate},
1723 },
1724 flags: []string{"-require-any-client-certificate"},
1725 })
1726 testCases = append(testCases, testCase{
1727 testType: clientTest,
1728 name: ver.name + "-Client-ClientAuth-ECDSA",
1729 config: Config{
1730 MinVersion: ver.version,
1731 MaxVersion: ver.version,
1732 ClientAuth: RequireAnyClientCert,
1733 ClientCAs: certPool,
1734 },
1735 flags: []string{
1736 "-cert-file", ecdsaCertificateFile,
1737 "-key-file", ecdsaKeyFile,
1738 },
1739 })
1740 }
David Benjamin636293b2014-07-08 17:59:18 -04001741 }
1742}
1743
Adam Langley75712922014-10-10 16:23:43 -07001744func addExtendedMasterSecretTests() {
1745 const expectEMSFlag = "-expect-extended-master-secret"
1746
1747 for _, with := range []bool{false, true} {
1748 prefix := "No"
1749 var flags []string
1750 if with {
1751 prefix = ""
1752 flags = []string{expectEMSFlag}
1753 }
1754
1755 for _, isClient := range []bool{false, true} {
1756 suffix := "-Server"
1757 testType := serverTest
1758 if isClient {
1759 suffix = "-Client"
1760 testType = clientTest
1761 }
1762
1763 for _, ver := range tlsVersions {
1764 test := testCase{
1765 testType: testType,
1766 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
1767 config: Config{
1768 MinVersion: ver.version,
1769 MaxVersion: ver.version,
1770 Bugs: ProtocolBugs{
1771 NoExtendedMasterSecret: !with,
1772 RequireExtendedMasterSecret: with,
1773 },
1774 },
David Benjamin48cae082014-10-27 01:06:24 -04001775 flags: flags,
1776 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07001777 }
1778 if test.shouldFail {
1779 test.expectedLocalError = "extended master secret required but not supported by peer"
1780 }
1781 testCases = append(testCases, test)
1782 }
1783 }
1784 }
1785
1786 // When a session is resumed, it should still be aware that its master
1787 // secret was generated via EMS and thus it's safe to use tls-unique.
1788 testCases = append(testCases, testCase{
1789 name: "ExtendedMasterSecret-Resume",
1790 config: Config{
1791 Bugs: ProtocolBugs{
1792 RequireExtendedMasterSecret: true,
1793 },
1794 },
1795 flags: []string{expectEMSFlag},
1796 resumeSession: true,
1797 })
1798}
1799
David Benjamin43ec06f2014-08-05 02:28:57 -04001800// Adds tests that try to cover the range of the handshake state machine, under
1801// various conditions. Some of these are redundant with other tests, but they
1802// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04001803func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin43ec06f2014-08-05 02:28:57 -04001804 var suffix string
1805 var flags []string
1806 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04001807 if protocol == dtls {
1808 suffix = "-DTLS"
1809 }
David Benjamin43ec06f2014-08-05 02:28:57 -04001810 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04001811 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04001812 flags = append(flags, "-async")
1813 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04001814 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04001815 }
1816 if splitHandshake {
1817 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04001818 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04001819 }
1820
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001821 // Basic handshake, with resumption. Client and server,
1822 // session ID and session ticket.
David Benjamin43ec06f2014-08-05 02:28:57 -04001823 testCases = append(testCases, testCase{
David Benjamin6fd297b2014-08-11 18:43:38 -04001824 protocol: protocol,
1825 name: "Basic-Client" + suffix,
David Benjamin43ec06f2014-08-05 02:28:57 -04001826 config: Config{
1827 Bugs: ProtocolBugs{
1828 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1829 },
1830 },
David Benjaminbed9aae2014-08-07 19:13:38 -04001831 flags: flags,
1832 resumeSession: true,
1833 })
1834 testCases = append(testCases, testCase{
David Benjamin6fd297b2014-08-11 18:43:38 -04001835 protocol: protocol,
1836 name: "Basic-Client-RenewTicket" + suffix,
David Benjaminbed9aae2014-08-07 19:13:38 -04001837 config: Config{
1838 Bugs: ProtocolBugs{
1839 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1840 RenewTicketOnResume: true,
1841 },
1842 },
1843 flags: flags,
1844 resumeSession: true,
David Benjamin43ec06f2014-08-05 02:28:57 -04001845 })
1846 testCases = append(testCases, testCase{
David Benjamin6fd297b2014-08-11 18:43:38 -04001847 protocol: protocol,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001848 name: "Basic-Client-NoTicket" + suffix,
1849 config: Config{
1850 SessionTicketsDisabled: true,
1851 Bugs: ProtocolBugs{
1852 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1853 },
1854 },
1855 flags: flags,
1856 resumeSession: true,
1857 })
1858 testCases = append(testCases, testCase{
1859 protocol: protocol,
David Benjamine0e7d0d2015-02-08 19:33:25 -05001860 name: "Basic-Client-Implicit" + suffix,
1861 config: Config{
1862 Bugs: ProtocolBugs{
1863 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1864 },
1865 },
1866 flags: append(flags, "-implicit-handshake"),
1867 resumeSession: true,
1868 })
1869 testCases = append(testCases, testCase{
1870 protocol: protocol,
David Benjamin43ec06f2014-08-05 02:28:57 -04001871 testType: serverTest,
1872 name: "Basic-Server" + suffix,
1873 config: Config{
1874 Bugs: ProtocolBugs{
1875 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1876 },
1877 },
David Benjaminbed9aae2014-08-07 19:13:38 -04001878 flags: flags,
1879 resumeSession: true,
David Benjamin43ec06f2014-08-05 02:28:57 -04001880 })
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001881 testCases = append(testCases, testCase{
1882 protocol: protocol,
1883 testType: serverTest,
1884 name: "Basic-Server-NoTickets" + suffix,
1885 config: Config{
1886 SessionTicketsDisabled: true,
1887 Bugs: ProtocolBugs{
1888 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1889 },
1890 },
1891 flags: flags,
1892 resumeSession: true,
1893 })
David Benjamine0e7d0d2015-02-08 19:33:25 -05001894 testCases = append(testCases, testCase{
1895 protocol: protocol,
1896 testType: serverTest,
1897 name: "Basic-Server-Implicit" + suffix,
1898 config: Config{
1899 Bugs: ProtocolBugs{
1900 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1901 },
1902 },
1903 flags: append(flags, "-implicit-handshake"),
1904 resumeSession: true,
1905 })
David Benjamin6f5c0f42015-02-24 01:23:21 -05001906 testCases = append(testCases, testCase{
1907 protocol: protocol,
1908 testType: serverTest,
1909 name: "Basic-Server-EarlyCallback" + suffix,
1910 config: Config{
1911 Bugs: ProtocolBugs{
1912 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1913 },
1914 },
1915 flags: append(flags, "-use-early-callback"),
1916 resumeSession: true,
1917 })
David Benjamin43ec06f2014-08-05 02:28:57 -04001918
David Benjamin6fd297b2014-08-11 18:43:38 -04001919 // TLS client auth.
1920 testCases = append(testCases, testCase{
1921 protocol: protocol,
1922 testType: clientTest,
1923 name: "ClientAuth-Client" + suffix,
1924 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04001925 ClientAuth: RequireAnyClientCert,
David Benjamin6fd297b2014-08-11 18:43:38 -04001926 Bugs: ProtocolBugs{
1927 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1928 },
1929 },
1930 flags: append(flags,
1931 "-cert-file", rsaCertificateFile,
1932 "-key-file", rsaKeyFile),
1933 })
1934 testCases = append(testCases, testCase{
1935 protocol: protocol,
1936 testType: serverTest,
1937 name: "ClientAuth-Server" + suffix,
1938 config: Config{
1939 Certificates: []Certificate{rsaCertificate},
1940 },
1941 flags: append(flags, "-require-any-client-certificate"),
1942 })
1943
David Benjamin43ec06f2014-08-05 02:28:57 -04001944 // No session ticket support; server doesn't send NewSessionTicket.
1945 testCases = append(testCases, testCase{
David Benjamin6fd297b2014-08-11 18:43:38 -04001946 protocol: protocol,
1947 name: "SessionTicketsDisabled-Client" + suffix,
David Benjamin43ec06f2014-08-05 02:28:57 -04001948 config: Config{
1949 SessionTicketsDisabled: true,
1950 Bugs: ProtocolBugs{
1951 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1952 },
1953 },
1954 flags: flags,
1955 })
1956 testCases = append(testCases, testCase{
David Benjamin6fd297b2014-08-11 18:43:38 -04001957 protocol: protocol,
David Benjamin43ec06f2014-08-05 02:28:57 -04001958 testType: serverTest,
1959 name: "SessionTicketsDisabled-Server" + suffix,
1960 config: Config{
1961 SessionTicketsDisabled: true,
1962 Bugs: ProtocolBugs{
1963 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1964 },
1965 },
1966 flags: flags,
1967 })
1968
David Benjamin48cae082014-10-27 01:06:24 -04001969 // Skip ServerKeyExchange in PSK key exchange if there's no
1970 // identity hint.
1971 testCases = append(testCases, testCase{
1972 protocol: protocol,
1973 name: "EmptyPSKHint-Client" + suffix,
1974 config: Config{
1975 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
1976 PreSharedKey: []byte("secret"),
1977 Bugs: ProtocolBugs{
1978 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1979 },
1980 },
1981 flags: append(flags, "-psk", "secret"),
1982 })
1983 testCases = append(testCases, testCase{
1984 protocol: protocol,
1985 testType: serverTest,
1986 name: "EmptyPSKHint-Server" + suffix,
1987 config: Config{
1988 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
1989 PreSharedKey: []byte("secret"),
1990 Bugs: ProtocolBugs{
1991 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1992 },
1993 },
1994 flags: append(flags, "-psk", "secret"),
1995 })
1996
David Benjamin6fd297b2014-08-11 18:43:38 -04001997 if protocol == tls {
1998 // NPN on client and server; results in post-handshake message.
1999 testCases = append(testCases, testCase{
2000 protocol: protocol,
2001 name: "NPN-Client" + suffix,
2002 config: Config{
David Benjaminae2888f2014-09-06 12:58:58 -04002003 NextProtos: []string{"foo"},
David Benjamin6fd297b2014-08-11 18:43:38 -04002004 Bugs: ProtocolBugs{
2005 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2006 },
David Benjamin43ec06f2014-08-05 02:28:57 -04002007 },
David Benjaminfc7b0862014-09-06 13:21:53 -04002008 flags: append(flags, "-select-next-proto", "foo"),
2009 expectedNextProto: "foo",
2010 expectedNextProtoType: npn,
David Benjamin6fd297b2014-08-11 18:43:38 -04002011 })
2012 testCases = append(testCases, testCase{
2013 protocol: protocol,
2014 testType: serverTest,
2015 name: "NPN-Server" + suffix,
2016 config: Config{
2017 NextProtos: []string{"bar"},
2018 Bugs: ProtocolBugs{
2019 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2020 },
David Benjamin43ec06f2014-08-05 02:28:57 -04002021 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002022 flags: append(flags,
2023 "-advertise-npn", "\x03foo\x03bar\x03baz",
2024 "-expect-next-proto", "bar"),
David Benjaminfc7b0862014-09-06 13:21:53 -04002025 expectedNextProto: "bar",
2026 expectedNextProtoType: npn,
David Benjamin6fd297b2014-08-11 18:43:38 -04002027 })
David Benjamin43ec06f2014-08-05 02:28:57 -04002028
David Benjamin195dc782015-02-19 13:27:05 -05002029 // TODO(davidben): Add tests for when False Start doesn't trigger.
2030
David Benjamin6fd297b2014-08-11 18:43:38 -04002031 // Client does False Start and negotiates NPN.
2032 testCases = append(testCases, testCase{
2033 protocol: protocol,
2034 name: "FalseStart" + suffix,
2035 config: Config{
2036 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2037 NextProtos: []string{"foo"},
2038 Bugs: ProtocolBugs{
David Benjamine58c4f52014-08-24 03:47:07 -04002039 ExpectFalseStart: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002040 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2041 },
David Benjamin43ec06f2014-08-05 02:28:57 -04002042 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002043 flags: append(flags,
2044 "-false-start",
2045 "-select-next-proto", "foo"),
David Benjamine58c4f52014-08-24 03:47:07 -04002046 shimWritesFirst: true,
2047 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002048 })
David Benjamin43ec06f2014-08-05 02:28:57 -04002049
David Benjaminae2888f2014-09-06 12:58:58 -04002050 // Client does False Start and negotiates ALPN.
2051 testCases = append(testCases, testCase{
2052 protocol: protocol,
2053 name: "FalseStart-ALPN" + suffix,
2054 config: Config{
2055 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2056 NextProtos: []string{"foo"},
2057 Bugs: ProtocolBugs{
2058 ExpectFalseStart: true,
2059 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2060 },
2061 },
2062 flags: append(flags,
2063 "-false-start",
2064 "-advertise-alpn", "\x03foo"),
2065 shimWritesFirst: true,
2066 resumeSession: true,
2067 })
2068
David Benjamin931ab342015-02-08 19:46:57 -05002069 // Client does False Start but doesn't explicitly call
2070 // SSL_connect.
2071 testCases = append(testCases, testCase{
2072 protocol: protocol,
2073 name: "FalseStart-Implicit" + suffix,
2074 config: Config{
2075 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2076 NextProtos: []string{"foo"},
2077 Bugs: ProtocolBugs{
2078 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2079 },
2080 },
2081 flags: append(flags,
2082 "-implicit-handshake",
2083 "-false-start",
2084 "-advertise-alpn", "\x03foo"),
2085 })
2086
David Benjamin6fd297b2014-08-11 18:43:38 -04002087 // False Start without session tickets.
2088 testCases = append(testCases, testCase{
David Benjamin5f237bc2015-02-11 17:14:15 -05002089 name: "FalseStart-SessionTicketsDisabled" + suffix,
David Benjamin6fd297b2014-08-11 18:43:38 -04002090 config: Config{
2091 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2092 NextProtos: []string{"foo"},
2093 SessionTicketsDisabled: true,
David Benjamin4e99c522014-08-24 01:45:30 -04002094 Bugs: ProtocolBugs{
David Benjamine58c4f52014-08-24 03:47:07 -04002095 ExpectFalseStart: true,
David Benjamin4e99c522014-08-24 01:45:30 -04002096 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2097 },
David Benjamin43ec06f2014-08-05 02:28:57 -04002098 },
David Benjamin4e99c522014-08-24 01:45:30 -04002099 flags: append(flags,
David Benjamin6fd297b2014-08-11 18:43:38 -04002100 "-false-start",
2101 "-select-next-proto", "foo",
David Benjamin4e99c522014-08-24 01:45:30 -04002102 ),
David Benjamine58c4f52014-08-24 03:47:07 -04002103 shimWritesFirst: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002104 })
David Benjamin1e7f8d72014-08-08 12:27:04 -04002105
David Benjamina08e49d2014-08-24 01:46:07 -04002106 // Server parses a V2ClientHello.
David Benjamin6fd297b2014-08-11 18:43:38 -04002107 testCases = append(testCases, testCase{
2108 protocol: protocol,
2109 testType: serverTest,
2110 name: "SendV2ClientHello" + suffix,
2111 config: Config{
2112 // Choose a cipher suite that does not involve
2113 // elliptic curves, so no extensions are
2114 // involved.
2115 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2116 Bugs: ProtocolBugs{
2117 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2118 SendV2ClientHello: true,
2119 },
David Benjamin1e7f8d72014-08-08 12:27:04 -04002120 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002121 flags: flags,
2122 })
David Benjamina08e49d2014-08-24 01:46:07 -04002123
2124 // Client sends a Channel ID.
2125 testCases = append(testCases, testCase{
2126 protocol: protocol,
2127 name: "ChannelID-Client" + suffix,
2128 config: Config{
2129 RequestChannelID: true,
2130 Bugs: ProtocolBugs{
2131 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2132 },
2133 },
2134 flags: append(flags,
2135 "-send-channel-id", channelIDKeyFile,
2136 ),
2137 resumeSession: true,
2138 expectChannelID: true,
2139 })
2140
2141 // Server accepts a Channel ID.
2142 testCases = append(testCases, testCase{
2143 protocol: protocol,
2144 testType: serverTest,
2145 name: "ChannelID-Server" + suffix,
2146 config: Config{
2147 ChannelID: channelIDKey,
2148 Bugs: ProtocolBugs{
2149 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2150 },
2151 },
2152 flags: append(flags,
2153 "-expect-channel-id",
2154 base64.StdEncoding.EncodeToString(channelIDBytes),
2155 ),
2156 resumeSession: true,
2157 expectChannelID: true,
2158 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002159 } else {
2160 testCases = append(testCases, testCase{
2161 protocol: protocol,
2162 name: "SkipHelloVerifyRequest" + suffix,
2163 config: Config{
2164 Bugs: ProtocolBugs{
2165 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2166 SkipHelloVerifyRequest: true,
2167 },
2168 },
2169 flags: flags,
2170 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002171 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002172}
2173
Adam Langley524e7172015-02-20 16:04:00 -08002174func addDDoSCallbackTests() {
2175 // DDoS callback.
2176
2177 for _, resume := range []bool{false, true} {
2178 suffix := "Resume"
2179 if resume {
2180 suffix = "No" + suffix
2181 }
2182
2183 testCases = append(testCases, testCase{
2184 testType: serverTest,
2185 name: "Server-DDoS-OK-" + suffix,
2186 flags: []string{"-install-ddos-callback"},
2187 resumeSession: resume,
2188 })
2189
2190 failFlag := "-fail-ddos-callback"
2191 if resume {
2192 failFlag = "-fail-second-ddos-callback"
2193 }
2194 testCases = append(testCases, testCase{
2195 testType: serverTest,
2196 name: "Server-DDoS-Reject-" + suffix,
2197 flags: []string{"-install-ddos-callback", failFlag},
2198 resumeSession: resume,
2199 shouldFail: true,
2200 expectedError: ":CONNECTION_REJECTED:",
2201 })
2202 }
2203}
2204
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002205func addVersionNegotiationTests() {
2206 for i, shimVers := range tlsVersions {
2207 // Assemble flags to disable all newer versions on the shim.
2208 var flags []string
2209 for _, vers := range tlsVersions[i+1:] {
2210 flags = append(flags, vers.flag)
2211 }
2212
2213 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002214 protocols := []protocol{tls}
2215 if runnerVers.hasDTLS && shimVers.hasDTLS {
2216 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002217 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002218 for _, protocol := range protocols {
2219 expectedVersion := shimVers.version
2220 if runnerVers.version < shimVers.version {
2221 expectedVersion = runnerVers.version
2222 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002223
David Benjamin8b8c0062014-11-23 02:47:52 -05002224 suffix := shimVers.name + "-" + runnerVers.name
2225 if protocol == dtls {
2226 suffix += "-DTLS"
2227 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002228
David Benjamin1eb367c2014-12-12 18:17:51 -05002229 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2230
David Benjamin1e29a6b2014-12-10 02:27:24 -05002231 clientVers := shimVers.version
2232 if clientVers > VersionTLS10 {
2233 clientVers = VersionTLS10
2234 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002235 testCases = append(testCases, testCase{
2236 protocol: protocol,
2237 testType: clientTest,
2238 name: "VersionNegotiation-Client-" + suffix,
2239 config: Config{
2240 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002241 Bugs: ProtocolBugs{
2242 ExpectInitialRecordVersion: clientVers,
2243 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002244 },
2245 flags: flags,
2246 expectedVersion: expectedVersion,
2247 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002248 testCases = append(testCases, testCase{
2249 protocol: protocol,
2250 testType: clientTest,
2251 name: "VersionNegotiation-Client2-" + suffix,
2252 config: Config{
2253 MaxVersion: runnerVers.version,
2254 Bugs: ProtocolBugs{
2255 ExpectInitialRecordVersion: clientVers,
2256 },
2257 },
2258 flags: []string{"-max-version", shimVersFlag},
2259 expectedVersion: expectedVersion,
2260 })
David Benjamin8b8c0062014-11-23 02:47:52 -05002261
2262 testCases = append(testCases, testCase{
2263 protocol: protocol,
2264 testType: serverTest,
2265 name: "VersionNegotiation-Server-" + suffix,
2266 config: Config{
2267 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002268 Bugs: ProtocolBugs{
2269 ExpectInitialRecordVersion: expectedVersion,
2270 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002271 },
2272 flags: flags,
2273 expectedVersion: expectedVersion,
2274 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002275 testCases = append(testCases, testCase{
2276 protocol: protocol,
2277 testType: serverTest,
2278 name: "VersionNegotiation-Server2-" + suffix,
2279 config: Config{
2280 MaxVersion: runnerVers.version,
2281 Bugs: ProtocolBugs{
2282 ExpectInitialRecordVersion: expectedVersion,
2283 },
2284 },
2285 flags: []string{"-max-version", shimVersFlag},
2286 expectedVersion: expectedVersion,
2287 })
David Benjamin8b8c0062014-11-23 02:47:52 -05002288 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002289 }
2290 }
2291}
2292
David Benjaminaccb4542014-12-12 23:44:33 -05002293func addMinimumVersionTests() {
2294 for i, shimVers := range tlsVersions {
2295 // Assemble flags to disable all older versions on the shim.
2296 var flags []string
2297 for _, vers := range tlsVersions[:i] {
2298 flags = append(flags, vers.flag)
2299 }
2300
2301 for _, runnerVers := range tlsVersions {
2302 protocols := []protocol{tls}
2303 if runnerVers.hasDTLS && shimVers.hasDTLS {
2304 protocols = append(protocols, dtls)
2305 }
2306 for _, protocol := range protocols {
2307 suffix := shimVers.name + "-" + runnerVers.name
2308 if protocol == dtls {
2309 suffix += "-DTLS"
2310 }
2311 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2312
David Benjaminaccb4542014-12-12 23:44:33 -05002313 var expectedVersion uint16
2314 var shouldFail bool
2315 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05002316 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05002317 if runnerVers.version >= shimVers.version {
2318 expectedVersion = runnerVers.version
2319 } else {
2320 shouldFail = true
2321 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05002322 if runnerVers.version > VersionSSL30 {
2323 expectedLocalError = "remote error: protocol version not supported"
2324 } else {
2325 expectedLocalError = "remote error: handshake failure"
2326 }
David Benjaminaccb4542014-12-12 23:44:33 -05002327 }
2328
2329 testCases = append(testCases, testCase{
2330 protocol: protocol,
2331 testType: clientTest,
2332 name: "MinimumVersion-Client-" + suffix,
2333 config: Config{
2334 MaxVersion: runnerVers.version,
2335 },
David Benjamin87909c02014-12-13 01:55:01 -05002336 flags: flags,
2337 expectedVersion: expectedVersion,
2338 shouldFail: shouldFail,
2339 expectedError: expectedError,
2340 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002341 })
2342 testCases = append(testCases, testCase{
2343 protocol: protocol,
2344 testType: clientTest,
2345 name: "MinimumVersion-Client2-" + suffix,
2346 config: Config{
2347 MaxVersion: runnerVers.version,
2348 },
David Benjamin87909c02014-12-13 01:55:01 -05002349 flags: []string{"-min-version", shimVersFlag},
2350 expectedVersion: expectedVersion,
2351 shouldFail: shouldFail,
2352 expectedError: expectedError,
2353 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002354 })
2355
2356 testCases = append(testCases, testCase{
2357 protocol: protocol,
2358 testType: serverTest,
2359 name: "MinimumVersion-Server-" + suffix,
2360 config: Config{
2361 MaxVersion: runnerVers.version,
2362 },
David Benjamin87909c02014-12-13 01:55:01 -05002363 flags: flags,
2364 expectedVersion: expectedVersion,
2365 shouldFail: shouldFail,
2366 expectedError: expectedError,
2367 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002368 })
2369 testCases = append(testCases, testCase{
2370 protocol: protocol,
2371 testType: serverTest,
2372 name: "MinimumVersion-Server2-" + suffix,
2373 config: Config{
2374 MaxVersion: runnerVers.version,
2375 },
David Benjamin87909c02014-12-13 01:55:01 -05002376 flags: []string{"-min-version", shimVersFlag},
2377 expectedVersion: expectedVersion,
2378 shouldFail: shouldFail,
2379 expectedError: expectedError,
2380 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002381 })
2382 }
2383 }
2384 }
2385}
2386
David Benjamin5c24a1d2014-08-31 00:59:27 -04002387func addD5BugTests() {
2388 testCases = append(testCases, testCase{
2389 testType: serverTest,
2390 name: "D5Bug-NoQuirk-Reject",
2391 config: Config{
2392 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2393 Bugs: ProtocolBugs{
2394 SSL3RSAKeyExchange: true,
2395 },
2396 },
2397 shouldFail: true,
2398 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
2399 })
2400 testCases = append(testCases, testCase{
2401 testType: serverTest,
2402 name: "D5Bug-Quirk-Normal",
2403 config: Config{
2404 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2405 },
2406 flags: []string{"-tls-d5-bug"},
2407 })
2408 testCases = append(testCases, testCase{
2409 testType: serverTest,
2410 name: "D5Bug-Quirk-Bug",
2411 config: Config{
2412 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2413 Bugs: ProtocolBugs{
2414 SSL3RSAKeyExchange: true,
2415 },
2416 },
2417 flags: []string{"-tls-d5-bug"},
2418 })
2419}
2420
David Benjamine78bfde2014-09-06 12:45:15 -04002421func addExtensionTests() {
2422 testCases = append(testCases, testCase{
2423 testType: clientTest,
2424 name: "DuplicateExtensionClient",
2425 config: Config{
2426 Bugs: ProtocolBugs{
2427 DuplicateExtension: true,
2428 },
2429 },
2430 shouldFail: true,
2431 expectedLocalError: "remote error: error decoding message",
2432 })
2433 testCases = append(testCases, testCase{
2434 testType: serverTest,
2435 name: "DuplicateExtensionServer",
2436 config: Config{
2437 Bugs: ProtocolBugs{
2438 DuplicateExtension: true,
2439 },
2440 },
2441 shouldFail: true,
2442 expectedLocalError: "remote error: error decoding message",
2443 })
2444 testCases = append(testCases, testCase{
2445 testType: clientTest,
2446 name: "ServerNameExtensionClient",
2447 config: Config{
2448 Bugs: ProtocolBugs{
2449 ExpectServerName: "example.com",
2450 },
2451 },
2452 flags: []string{"-host-name", "example.com"},
2453 })
2454 testCases = append(testCases, testCase{
2455 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05002456 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04002457 config: Config{
2458 Bugs: ProtocolBugs{
2459 ExpectServerName: "mismatch.com",
2460 },
2461 },
2462 flags: []string{"-host-name", "example.com"},
2463 shouldFail: true,
2464 expectedLocalError: "tls: unexpected server name",
2465 })
2466 testCases = append(testCases, testCase{
2467 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05002468 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04002469 config: Config{
2470 Bugs: ProtocolBugs{
2471 ExpectServerName: "missing.com",
2472 },
2473 },
2474 shouldFail: true,
2475 expectedLocalError: "tls: unexpected server name",
2476 })
2477 testCases = append(testCases, testCase{
2478 testType: serverTest,
2479 name: "ServerNameExtensionServer",
2480 config: Config{
2481 ServerName: "example.com",
2482 },
2483 flags: []string{"-expect-server-name", "example.com"},
2484 resumeSession: true,
2485 })
David Benjaminae2888f2014-09-06 12:58:58 -04002486 testCases = append(testCases, testCase{
2487 testType: clientTest,
2488 name: "ALPNClient",
2489 config: Config{
2490 NextProtos: []string{"foo"},
2491 },
2492 flags: []string{
2493 "-advertise-alpn", "\x03foo\x03bar\x03baz",
2494 "-expect-alpn", "foo",
2495 },
David Benjaminfc7b0862014-09-06 13:21:53 -04002496 expectedNextProto: "foo",
2497 expectedNextProtoType: alpn,
2498 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04002499 })
2500 testCases = append(testCases, testCase{
2501 testType: serverTest,
2502 name: "ALPNServer",
2503 config: Config{
2504 NextProtos: []string{"foo", "bar", "baz"},
2505 },
2506 flags: []string{
2507 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2508 "-select-alpn", "foo",
2509 },
David Benjaminfc7b0862014-09-06 13:21:53 -04002510 expectedNextProto: "foo",
2511 expectedNextProtoType: alpn,
2512 resumeSession: true,
2513 })
2514 // Test that the server prefers ALPN over NPN.
2515 testCases = append(testCases, testCase{
2516 testType: serverTest,
2517 name: "ALPNServer-Preferred",
2518 config: Config{
2519 NextProtos: []string{"foo", "bar", "baz"},
2520 },
2521 flags: []string{
2522 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2523 "-select-alpn", "foo",
2524 "-advertise-npn", "\x03foo\x03bar\x03baz",
2525 },
2526 expectedNextProto: "foo",
2527 expectedNextProtoType: alpn,
2528 resumeSession: true,
2529 })
2530 testCases = append(testCases, testCase{
2531 testType: serverTest,
2532 name: "ALPNServer-Preferred-Swapped",
2533 config: Config{
2534 NextProtos: []string{"foo", "bar", "baz"},
2535 Bugs: ProtocolBugs{
2536 SwapNPNAndALPN: true,
2537 },
2538 },
2539 flags: []string{
2540 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2541 "-select-alpn", "foo",
2542 "-advertise-npn", "\x03foo\x03bar\x03baz",
2543 },
2544 expectedNextProto: "foo",
2545 expectedNextProtoType: alpn,
2546 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04002547 })
Adam Langley38311732014-10-16 19:04:35 -07002548 // Resume with a corrupt ticket.
2549 testCases = append(testCases, testCase{
2550 testType: serverTest,
2551 name: "CorruptTicket",
2552 config: Config{
2553 Bugs: ProtocolBugs{
2554 CorruptTicket: true,
2555 },
2556 },
2557 resumeSession: true,
2558 flags: []string{"-expect-session-miss"},
2559 })
2560 // Resume with an oversized session id.
2561 testCases = append(testCases, testCase{
2562 testType: serverTest,
2563 name: "OversizedSessionId",
2564 config: Config{
2565 Bugs: ProtocolBugs{
2566 OversizedSessionId: true,
2567 },
2568 },
2569 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07002570 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07002571 expectedError: ":DECODE_ERROR:",
2572 })
David Benjaminca6c8262014-11-15 19:06:08 -05002573 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
2574 // are ignored.
2575 testCases = append(testCases, testCase{
2576 protocol: dtls,
2577 name: "SRTP-Client",
2578 config: Config{
2579 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
2580 },
2581 flags: []string{
2582 "-srtp-profiles",
2583 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2584 },
2585 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
2586 })
2587 testCases = append(testCases, testCase{
2588 protocol: dtls,
2589 testType: serverTest,
2590 name: "SRTP-Server",
2591 config: Config{
2592 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
2593 },
2594 flags: []string{
2595 "-srtp-profiles",
2596 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2597 },
2598 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
2599 })
2600 // Test that the MKI is ignored.
2601 testCases = append(testCases, testCase{
2602 protocol: dtls,
2603 testType: serverTest,
2604 name: "SRTP-Server-IgnoreMKI",
2605 config: Config{
2606 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
2607 Bugs: ProtocolBugs{
2608 SRTPMasterKeyIdentifer: "bogus",
2609 },
2610 },
2611 flags: []string{
2612 "-srtp-profiles",
2613 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2614 },
2615 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
2616 })
2617 // Test that SRTP isn't negotiated on the server if there were
2618 // no matching profiles.
2619 testCases = append(testCases, testCase{
2620 protocol: dtls,
2621 testType: serverTest,
2622 name: "SRTP-Server-NoMatch",
2623 config: Config{
2624 SRTPProtectionProfiles: []uint16{100, 101, 102},
2625 },
2626 flags: []string{
2627 "-srtp-profiles",
2628 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2629 },
2630 expectedSRTPProtectionProfile: 0,
2631 })
2632 // Test that the server returning an invalid SRTP profile is
2633 // flagged as an error by the client.
2634 testCases = append(testCases, testCase{
2635 protocol: dtls,
2636 name: "SRTP-Client-NoMatch",
2637 config: Config{
2638 Bugs: ProtocolBugs{
2639 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
2640 },
2641 },
2642 flags: []string{
2643 "-srtp-profiles",
2644 "SRTP_AES128_CM_SHA1_80",
2645 },
2646 shouldFail: true,
2647 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
2648 })
David Benjamin61f95272014-11-25 01:55:35 -05002649 // Test OCSP stapling and SCT list.
2650 testCases = append(testCases, testCase{
2651 name: "OCSPStapling",
2652 flags: []string{
2653 "-enable-ocsp-stapling",
2654 "-expect-ocsp-response",
2655 base64.StdEncoding.EncodeToString(testOCSPResponse),
2656 },
2657 })
2658 testCases = append(testCases, testCase{
2659 name: "SignedCertificateTimestampList",
2660 flags: []string{
2661 "-enable-signed-cert-timestamps",
2662 "-expect-signed-cert-timestamps",
2663 base64.StdEncoding.EncodeToString(testSCTList),
2664 },
2665 })
David Benjamine78bfde2014-09-06 12:45:15 -04002666}
2667
David Benjamin01fe8202014-09-24 15:21:44 -04002668func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04002669 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04002670 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002671 protocols := []protocol{tls}
2672 if sessionVers.hasDTLS && resumeVers.hasDTLS {
2673 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05002674 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002675 for _, protocol := range protocols {
2676 suffix := "-" + sessionVers.name + "-" + resumeVers.name
2677 if protocol == dtls {
2678 suffix += "-DTLS"
2679 }
2680
2681 testCases = append(testCases, testCase{
2682 protocol: protocol,
2683 name: "Resume-Client" + suffix,
2684 resumeSession: true,
2685 config: Config{
2686 MaxVersion: sessionVers.version,
2687 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2688 Bugs: ProtocolBugs{
2689 AllowSessionVersionMismatch: true,
2690 },
2691 },
2692 expectedVersion: sessionVers.version,
2693 resumeConfig: &Config{
2694 MaxVersion: resumeVers.version,
2695 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2696 Bugs: ProtocolBugs{
2697 AllowSessionVersionMismatch: true,
2698 },
2699 },
2700 expectedResumeVersion: resumeVers.version,
2701 })
2702
2703 testCases = append(testCases, testCase{
2704 protocol: protocol,
2705 name: "Resume-Client-NoResume" + suffix,
2706 flags: []string{"-expect-session-miss"},
2707 resumeSession: true,
2708 config: Config{
2709 MaxVersion: sessionVers.version,
2710 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2711 },
2712 expectedVersion: sessionVers.version,
2713 resumeConfig: &Config{
2714 MaxVersion: resumeVers.version,
2715 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2716 },
2717 newSessionsOnResume: true,
2718 expectedResumeVersion: resumeVers.version,
2719 })
2720
2721 var flags []string
2722 if sessionVers.version != resumeVers.version {
2723 flags = append(flags, "-expect-session-miss")
2724 }
2725 testCases = append(testCases, testCase{
2726 protocol: protocol,
2727 testType: serverTest,
2728 name: "Resume-Server" + suffix,
2729 flags: flags,
2730 resumeSession: true,
2731 config: Config{
2732 MaxVersion: sessionVers.version,
2733 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2734 },
2735 expectedVersion: sessionVers.version,
2736 resumeConfig: &Config{
2737 MaxVersion: resumeVers.version,
2738 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2739 },
2740 expectedResumeVersion: resumeVers.version,
2741 })
2742 }
David Benjamin01fe8202014-09-24 15:21:44 -04002743 }
2744 }
2745}
2746
Adam Langley2ae77d22014-10-28 17:29:33 -07002747func addRenegotiationTests() {
2748 testCases = append(testCases, testCase{
2749 testType: serverTest,
2750 name: "Renegotiate-Server",
2751 flags: []string{"-renegotiate"},
2752 shimWritesFirst: true,
2753 })
2754 testCases = append(testCases, testCase{
2755 testType: serverTest,
David Benjamincdea40c2015-03-19 14:09:43 -04002756 name: "Renegotiate-Server-Full",
2757 config: Config{
2758 Bugs: ProtocolBugs{
2759 NeverResumeOnRenego: true,
2760 },
2761 },
2762 flags: []string{"-renegotiate"},
2763 shimWritesFirst: true,
2764 })
2765 testCases = append(testCases, testCase{
2766 testType: serverTest,
Adam Langley2ae77d22014-10-28 17:29:33 -07002767 name: "Renegotiate-Server-EmptyExt",
2768 config: Config{
2769 Bugs: ProtocolBugs{
2770 EmptyRenegotiationInfo: true,
2771 },
2772 },
2773 flags: []string{"-renegotiate"},
2774 shimWritesFirst: true,
2775 shouldFail: true,
2776 expectedError: ":RENEGOTIATION_MISMATCH:",
2777 })
2778 testCases = append(testCases, testCase{
2779 testType: serverTest,
2780 name: "Renegotiate-Server-BadExt",
2781 config: Config{
2782 Bugs: ProtocolBugs{
2783 BadRenegotiationInfo: true,
2784 },
2785 },
2786 flags: []string{"-renegotiate"},
2787 shimWritesFirst: true,
2788 shouldFail: true,
2789 expectedError: ":RENEGOTIATION_MISMATCH:",
2790 })
David Benjaminca6554b2014-11-08 12:31:52 -05002791 testCases = append(testCases, testCase{
2792 testType: serverTest,
2793 name: "Renegotiate-Server-ClientInitiated",
2794 renegotiate: true,
2795 })
2796 testCases = append(testCases, testCase{
2797 testType: serverTest,
2798 name: "Renegotiate-Server-ClientInitiated-NoExt",
2799 renegotiate: true,
2800 config: Config{
2801 Bugs: ProtocolBugs{
2802 NoRenegotiationInfo: true,
2803 },
2804 },
2805 shouldFail: true,
2806 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
2807 })
2808 testCases = append(testCases, testCase{
2809 testType: serverTest,
2810 name: "Renegotiate-Server-ClientInitiated-NoExt-Allowed",
2811 renegotiate: true,
2812 config: Config{
2813 Bugs: ProtocolBugs{
2814 NoRenegotiationInfo: true,
2815 },
2816 },
2817 flags: []string{"-allow-unsafe-legacy-renegotiation"},
2818 })
David Benjamin3c9746a2015-03-19 15:00:10 -04002819 // Regression test for CVE-2015-0291.
2820 testCases = append(testCases, testCase{
2821 testType: serverTest,
2822 name: "Renegotiate-Server-NoSignatureAlgorithms",
2823 config: Config{
2824 Bugs: ProtocolBugs{
2825 NeverResumeOnRenego: true,
2826 NoSignatureAlgorithmsOnRenego: true,
2827 },
2828 },
2829 flags: []string{"-renegotiate"},
2830 shimWritesFirst: true,
2831 })
Adam Langley2ae77d22014-10-28 17:29:33 -07002832 // TODO(agl): test the renegotiation info SCSV.
Adam Langleycf2d4f42014-10-28 19:06:14 -07002833 testCases = append(testCases, testCase{
2834 name: "Renegotiate-Client",
2835 renegotiate: true,
2836 })
2837 testCases = append(testCases, testCase{
David Benjamincdea40c2015-03-19 14:09:43 -04002838 name: "Renegotiate-Client-Full",
2839 config: Config{
2840 Bugs: ProtocolBugs{
2841 NeverResumeOnRenego: true,
2842 },
2843 },
2844 renegotiate: true,
2845 })
2846 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07002847 name: "Renegotiate-Client-EmptyExt",
2848 renegotiate: true,
2849 config: Config{
2850 Bugs: ProtocolBugs{
2851 EmptyRenegotiationInfo: true,
2852 },
2853 },
2854 shouldFail: true,
2855 expectedError: ":RENEGOTIATION_MISMATCH:",
2856 })
2857 testCases = append(testCases, testCase{
2858 name: "Renegotiate-Client-BadExt",
2859 renegotiate: true,
2860 config: Config{
2861 Bugs: ProtocolBugs{
2862 BadRenegotiationInfo: true,
2863 },
2864 },
2865 shouldFail: true,
2866 expectedError: ":RENEGOTIATION_MISMATCH:",
2867 })
2868 testCases = append(testCases, testCase{
2869 name: "Renegotiate-Client-SwitchCiphers",
2870 renegotiate: true,
2871 config: Config{
2872 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2873 },
2874 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2875 })
2876 testCases = append(testCases, testCase{
2877 name: "Renegotiate-Client-SwitchCiphers2",
2878 renegotiate: true,
2879 config: Config{
2880 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2881 },
2882 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2883 })
David Benjaminc44b1df2014-11-23 12:11:01 -05002884 testCases = append(testCases, testCase{
2885 name: "Renegotiate-SameClientVersion",
2886 renegotiate: true,
2887 config: Config{
2888 MaxVersion: VersionTLS10,
2889 Bugs: ProtocolBugs{
2890 RequireSameRenegoClientVersion: true,
2891 },
2892 },
2893 })
Adam Langley2ae77d22014-10-28 17:29:33 -07002894}
2895
David Benjamin5e961c12014-11-07 01:48:35 -05002896func addDTLSReplayTests() {
2897 // Test that sequence number replays are detected.
2898 testCases = append(testCases, testCase{
2899 protocol: dtls,
2900 name: "DTLS-Replay",
2901 replayWrites: true,
2902 })
2903
2904 // Test the outgoing sequence number skipping by values larger
2905 // than the retransmit window.
2906 testCases = append(testCases, testCase{
2907 protocol: dtls,
2908 name: "DTLS-Replay-LargeGaps",
2909 config: Config{
2910 Bugs: ProtocolBugs{
2911 SequenceNumberIncrement: 127,
2912 },
2913 },
2914 replayWrites: true,
2915 })
2916}
2917
Feng Lu41aa3252014-11-21 22:47:56 -08002918func addFastRadioPaddingTests() {
David Benjamin1e29a6b2014-12-10 02:27:24 -05002919 testCases = append(testCases, testCase{
2920 protocol: tls,
2921 name: "FastRadio-Padding",
Feng Lu41aa3252014-11-21 22:47:56 -08002922 config: Config{
2923 Bugs: ProtocolBugs{
2924 RequireFastradioPadding: true,
2925 },
2926 },
David Benjamin1e29a6b2014-12-10 02:27:24 -05002927 flags: []string{"-fastradio-padding"},
Feng Lu41aa3252014-11-21 22:47:56 -08002928 })
David Benjamin1e29a6b2014-12-10 02:27:24 -05002929 testCases = append(testCases, testCase{
2930 protocol: dtls,
David Benjamin5f237bc2015-02-11 17:14:15 -05002931 name: "FastRadio-Padding-DTLS",
Feng Lu41aa3252014-11-21 22:47:56 -08002932 config: Config{
2933 Bugs: ProtocolBugs{
2934 RequireFastradioPadding: true,
2935 },
2936 },
David Benjamin1e29a6b2014-12-10 02:27:24 -05002937 flags: []string{"-fastradio-padding"},
Feng Lu41aa3252014-11-21 22:47:56 -08002938 })
2939}
2940
David Benjamin000800a2014-11-14 01:43:59 -05002941var testHashes = []struct {
2942 name string
2943 id uint8
2944}{
2945 {"SHA1", hashSHA1},
2946 {"SHA224", hashSHA224},
2947 {"SHA256", hashSHA256},
2948 {"SHA384", hashSHA384},
2949 {"SHA512", hashSHA512},
2950}
2951
2952func addSigningHashTests() {
2953 // Make sure each hash works. Include some fake hashes in the list and
2954 // ensure they're ignored.
2955 for _, hash := range testHashes {
2956 testCases = append(testCases, testCase{
2957 name: "SigningHash-ClientAuth-" + hash.name,
2958 config: Config{
2959 ClientAuth: RequireAnyClientCert,
2960 SignatureAndHashes: []signatureAndHash{
2961 {signatureRSA, 42},
2962 {signatureRSA, hash.id},
2963 {signatureRSA, 255},
2964 },
2965 },
2966 flags: []string{
2967 "-cert-file", rsaCertificateFile,
2968 "-key-file", rsaKeyFile,
2969 },
2970 })
2971
2972 testCases = append(testCases, testCase{
2973 testType: serverTest,
2974 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
2975 config: Config{
2976 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2977 SignatureAndHashes: []signatureAndHash{
2978 {signatureRSA, 42},
2979 {signatureRSA, hash.id},
2980 {signatureRSA, 255},
2981 },
2982 },
2983 })
2984 }
2985
2986 // Test that hash resolution takes the signature type into account.
2987 testCases = append(testCases, testCase{
2988 name: "SigningHash-ClientAuth-SignatureType",
2989 config: Config{
2990 ClientAuth: RequireAnyClientCert,
2991 SignatureAndHashes: []signatureAndHash{
2992 {signatureECDSA, hashSHA512},
2993 {signatureRSA, hashSHA384},
2994 {signatureECDSA, hashSHA1},
2995 },
2996 },
2997 flags: []string{
2998 "-cert-file", rsaCertificateFile,
2999 "-key-file", rsaKeyFile,
3000 },
3001 })
3002
3003 testCases = append(testCases, testCase{
3004 testType: serverTest,
3005 name: "SigningHash-ServerKeyExchange-SignatureType",
3006 config: Config{
3007 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3008 SignatureAndHashes: []signatureAndHash{
3009 {signatureECDSA, hashSHA512},
3010 {signatureRSA, hashSHA384},
3011 {signatureECDSA, hashSHA1},
3012 },
3013 },
3014 })
3015
3016 // Test that, if the list is missing, the peer falls back to SHA-1.
3017 testCases = append(testCases, testCase{
3018 name: "SigningHash-ClientAuth-Fallback",
3019 config: Config{
3020 ClientAuth: RequireAnyClientCert,
3021 SignatureAndHashes: []signatureAndHash{
3022 {signatureRSA, hashSHA1},
3023 },
3024 Bugs: ProtocolBugs{
3025 NoSignatureAndHashes: true,
3026 },
3027 },
3028 flags: []string{
3029 "-cert-file", rsaCertificateFile,
3030 "-key-file", rsaKeyFile,
3031 },
3032 })
3033
3034 testCases = append(testCases, testCase{
3035 testType: serverTest,
3036 name: "SigningHash-ServerKeyExchange-Fallback",
3037 config: Config{
3038 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3039 SignatureAndHashes: []signatureAndHash{
3040 {signatureRSA, hashSHA1},
3041 },
3042 Bugs: ProtocolBugs{
3043 NoSignatureAndHashes: true,
3044 },
3045 },
3046 })
David Benjamin72dc7832015-03-16 17:49:43 -04003047
3048 // Test that hash preferences are enforced. BoringSSL defaults to
3049 // rejecting MD5 signatures.
3050 testCases = append(testCases, testCase{
3051 testType: serverTest,
3052 name: "SigningHash-ClientAuth-Enforced",
3053 config: Config{
3054 Certificates: []Certificate{rsaCertificate},
3055 SignatureAndHashes: []signatureAndHash{
3056 {signatureRSA, hashMD5},
3057 // Advertise SHA-1 so the handshake will
3058 // proceed, but the shim's preferences will be
3059 // ignored in CertificateVerify generation, so
3060 // MD5 will be chosen.
3061 {signatureRSA, hashSHA1},
3062 },
3063 Bugs: ProtocolBugs{
3064 IgnorePeerSignatureAlgorithmPreferences: true,
3065 },
3066 },
3067 flags: []string{"-require-any-client-certificate"},
3068 shouldFail: true,
3069 expectedError: ":WRONG_SIGNATURE_TYPE:",
3070 })
3071
3072 testCases = append(testCases, testCase{
3073 name: "SigningHash-ServerKeyExchange-Enforced",
3074 config: Config{
3075 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3076 SignatureAndHashes: []signatureAndHash{
3077 {signatureRSA, hashMD5},
3078 },
3079 Bugs: ProtocolBugs{
3080 IgnorePeerSignatureAlgorithmPreferences: true,
3081 },
3082 },
3083 shouldFail: true,
3084 expectedError: ":WRONG_SIGNATURE_TYPE:",
3085 })
David Benjamin000800a2014-11-14 01:43:59 -05003086}
3087
David Benjamin83f90402015-01-27 01:09:43 -05003088// timeouts is the retransmit schedule for BoringSSL. It doubles and
3089// caps at 60 seconds. On the 13th timeout, it gives up.
3090var timeouts = []time.Duration{
3091 1 * time.Second,
3092 2 * time.Second,
3093 4 * time.Second,
3094 8 * time.Second,
3095 16 * time.Second,
3096 32 * time.Second,
3097 60 * time.Second,
3098 60 * time.Second,
3099 60 * time.Second,
3100 60 * time.Second,
3101 60 * time.Second,
3102 60 * time.Second,
3103 60 * time.Second,
3104}
3105
3106func addDTLSRetransmitTests() {
3107 // Test that this is indeed the timeout schedule. Stress all
3108 // four patterns of handshake.
3109 for i := 1; i < len(timeouts); i++ {
3110 number := strconv.Itoa(i)
3111 testCases = append(testCases, testCase{
3112 protocol: dtls,
3113 name: "DTLS-Retransmit-Client-" + number,
3114 config: Config{
3115 Bugs: ProtocolBugs{
3116 TimeoutSchedule: timeouts[:i],
3117 },
3118 },
3119 resumeSession: true,
3120 flags: []string{"-async"},
3121 })
3122 testCases = append(testCases, testCase{
3123 protocol: dtls,
3124 testType: serverTest,
3125 name: "DTLS-Retransmit-Server-" + number,
3126 config: Config{
3127 Bugs: ProtocolBugs{
3128 TimeoutSchedule: timeouts[:i],
3129 },
3130 },
3131 resumeSession: true,
3132 flags: []string{"-async"},
3133 })
3134 }
3135
3136 // Test that exceeding the timeout schedule hits a read
3137 // timeout.
3138 testCases = append(testCases, testCase{
3139 protocol: dtls,
3140 name: "DTLS-Retransmit-Timeout",
3141 config: Config{
3142 Bugs: ProtocolBugs{
3143 TimeoutSchedule: timeouts,
3144 },
3145 },
3146 resumeSession: true,
3147 flags: []string{"-async"},
3148 shouldFail: true,
3149 expectedError: ":READ_TIMEOUT_EXPIRED:",
3150 })
3151
3152 // Test that timeout handling has a fudge factor, due to API
3153 // problems.
3154 testCases = append(testCases, testCase{
3155 protocol: dtls,
3156 name: "DTLS-Retransmit-Fudge",
3157 config: Config{
3158 Bugs: ProtocolBugs{
3159 TimeoutSchedule: []time.Duration{
3160 timeouts[0] - 10*time.Millisecond,
3161 },
3162 },
3163 },
3164 resumeSession: true,
3165 flags: []string{"-async"},
3166 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05003167
3168 // Test that the final Finished retransmitting isn't
3169 // duplicated if the peer badly fragments everything.
3170 testCases = append(testCases, testCase{
3171 testType: serverTest,
3172 protocol: dtls,
3173 name: "DTLS-Retransmit-Fragmented",
3174 config: Config{
3175 Bugs: ProtocolBugs{
3176 TimeoutSchedule: []time.Duration{timeouts[0]},
3177 MaxHandshakeRecordLength: 2,
3178 },
3179 },
3180 flags: []string{"-async"},
3181 })
David Benjamin83f90402015-01-27 01:09:43 -05003182}
3183
David Benjamin884fdf12014-08-02 15:28:23 -04003184func worker(statusChan chan statusMsg, c chan *testCase, buildDir string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07003185 defer wg.Done()
3186
3187 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08003188 var err error
3189
3190 if *mallocTest < 0 {
3191 statusChan <- statusMsg{test: test, started: true}
3192 err = runTest(test, buildDir, -1)
3193 } else {
3194 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
3195 statusChan <- statusMsg{test: test, started: true}
3196 if err = runTest(test, buildDir, mallocNumToFail); err != errMoreMallocs {
3197 if err != nil {
3198 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
3199 }
3200 break
3201 }
3202 }
3203 }
Adam Langley95c29f32014-06-20 12:00:00 -07003204 statusChan <- statusMsg{test: test, err: err}
3205 }
3206}
3207
3208type statusMsg struct {
3209 test *testCase
3210 started bool
3211 err error
3212}
3213
David Benjamin5f237bc2015-02-11 17:14:15 -05003214func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07003215 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07003216
David Benjamin5f237bc2015-02-11 17:14:15 -05003217 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07003218 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05003219 if !*pipe {
3220 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05003221 var erase string
3222 for i := 0; i < lineLen; i++ {
3223 erase += "\b \b"
3224 }
3225 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05003226 }
3227
Adam Langley95c29f32014-06-20 12:00:00 -07003228 if msg.started {
3229 started++
3230 } else {
3231 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05003232
3233 if msg.err != nil {
3234 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
3235 failed++
3236 testOutput.addResult(msg.test.name, "FAIL")
3237 } else {
3238 if *pipe {
3239 // Print each test instead of a status line.
3240 fmt.Printf("PASSED (%s)\n", msg.test.name)
3241 }
3242 testOutput.addResult(msg.test.name, "PASS")
3243 }
Adam Langley95c29f32014-06-20 12:00:00 -07003244 }
3245
David Benjamin5f237bc2015-02-11 17:14:15 -05003246 if !*pipe {
3247 // Print a new status line.
3248 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
3249 lineLen = len(line)
3250 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07003251 }
Adam Langley95c29f32014-06-20 12:00:00 -07003252 }
David Benjamin5f237bc2015-02-11 17:14:15 -05003253
3254 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07003255}
3256
3257func main() {
3258 var flagTest *string = flag.String("test", "", "The name of a test to run, or empty to run all tests")
David Benjamin2bc8e6f2014-08-02 15:22:37 -04003259 var flagNumWorkers *int = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
David Benjamin884fdf12014-08-02 15:28:23 -04003260 var flagBuildDir *string = flag.String("build-dir", "../../../build", "The build directory to run the shim from.")
Adam Langley95c29f32014-06-20 12:00:00 -07003261
3262 flag.Parse()
3263
3264 addCipherSuiteTests()
3265 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07003266 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07003267 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04003268 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08003269 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003270 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05003271 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04003272 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04003273 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04003274 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07003275 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07003276 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05003277 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05003278 addSigningHashTests()
Feng Lu41aa3252014-11-21 22:47:56 -08003279 addFastRadioPaddingTests()
David Benjamin83f90402015-01-27 01:09:43 -05003280 addDTLSRetransmitTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04003281 for _, async := range []bool{false, true} {
3282 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04003283 for _, protocol := range []protocol{tls, dtls} {
3284 addStateMachineCoverageTests(async, splitHandshake, protocol)
3285 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003286 }
3287 }
Adam Langley95c29f32014-06-20 12:00:00 -07003288
3289 var wg sync.WaitGroup
3290
David Benjamin2bc8e6f2014-08-02 15:22:37 -04003291 numWorkers := *flagNumWorkers
Adam Langley95c29f32014-06-20 12:00:00 -07003292
3293 statusChan := make(chan statusMsg, numWorkers)
3294 testChan := make(chan *testCase, numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05003295 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07003296
David Benjamin025b3d32014-07-01 19:53:04 -04003297 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07003298
3299 for i := 0; i < numWorkers; i++ {
3300 wg.Add(1)
David Benjamin884fdf12014-08-02 15:28:23 -04003301 go worker(statusChan, testChan, *flagBuildDir, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07003302 }
3303
David Benjamin025b3d32014-07-01 19:53:04 -04003304 for i := range testCases {
3305 if len(*flagTest) == 0 || *flagTest == testCases[i].name {
3306 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07003307 }
3308 }
3309
3310 close(testChan)
3311 wg.Wait()
3312 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05003313 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07003314
3315 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05003316
3317 if *jsonOutput != "" {
3318 if err := testOutput.writeTo(*jsonOutput); err != nil {
3319 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
3320 }
3321 }
Adam Langley95c29f32014-06-20 12:00:00 -07003322}