blob: cdeacee03c981aae4a2e1ef29d268737b53c1e95 [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",
784 "-advertise-alpn", "\x03foo",
785 },
786 shimWritesFirst: true,
787 shouldFail: true,
788 expectedError: ":UNEXPECTED_RECORD:",
789 },
David Benjamin931ab342015-02-08 19:46:57 -0500790 {
791 name: "FalseStart-SkipServerSecondLeg-Implicit",
792 config: Config{
793 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
794 NextProtos: []string{"foo"},
795 Bugs: ProtocolBugs{
796 SkipNewSessionTicket: true,
797 SkipChangeCipherSpec: true,
798 SkipFinished: true,
799 },
800 },
801 flags: []string{
802 "-implicit-handshake",
803 "-false-start",
804 "-advertise-alpn", "\x03foo",
805 },
806 shouldFail: true,
807 expectedError: ":UNEXPECTED_RECORD:",
808 },
David Benjamin6f5c0f42015-02-24 01:23:21 -0500809 {
810 testType: serverTest,
811 name: "FailEarlyCallback",
812 flags: []string{"-fail-early-callback"},
813 shouldFail: true,
814 expectedError: ":CONNECTION_REJECTED:",
815 expectedLocalError: "remote error: access denied",
816 },
David Benjaminbcb2d912015-02-24 23:45:43 -0500817 {
818 name: "WrongMessageType",
819 config: Config{
820 Bugs: ProtocolBugs{
821 WrongCertificateMessageType: true,
822 },
823 },
824 shouldFail: true,
825 expectedError: ":UNEXPECTED_MESSAGE:",
826 expectedLocalError: "remote error: unexpected message",
827 },
828 {
829 protocol: dtls,
830 name: "WrongMessageType-DTLS",
831 config: Config{
832 Bugs: ProtocolBugs{
833 WrongCertificateMessageType: true,
834 },
835 },
836 shouldFail: true,
837 expectedError: ":UNEXPECTED_MESSAGE:",
838 expectedLocalError: "remote error: unexpected message",
839 },
David Benjamin75381222015-03-02 19:30:30 -0500840 {
841 protocol: dtls,
842 name: "FragmentMessageTypeMismatch-DTLS",
843 config: Config{
844 Bugs: ProtocolBugs{
845 MaxHandshakeRecordLength: 2,
846 FragmentMessageTypeMismatch: true,
847 },
848 },
849 shouldFail: true,
850 expectedError: ":FRAGMENT_MISMATCH:",
851 },
852 {
853 protocol: dtls,
854 name: "FragmentMessageLengthMismatch-DTLS",
855 config: Config{
856 Bugs: ProtocolBugs{
857 MaxHandshakeRecordLength: 2,
858 FragmentMessageLengthMismatch: true,
859 },
860 },
861 shouldFail: true,
862 expectedError: ":FRAGMENT_MISMATCH:",
863 },
864 {
865 protocol: dtls,
866 name: "SplitFragmentHeader-DTLS",
867 config: Config{
868 Bugs: ProtocolBugs{
869 SplitFragmentHeader: true,
870 },
871 },
872 shouldFail: true,
873 expectedError: ":UNEXPECTED_MESSAGE:",
874 },
875 {
876 protocol: dtls,
877 name: "SplitFragmentBody-DTLS",
878 config: Config{
879 Bugs: ProtocolBugs{
880 SplitFragmentBody: true,
881 },
882 },
883 shouldFail: true,
884 expectedError: ":UNEXPECTED_MESSAGE:",
885 },
886 {
887 protocol: dtls,
888 name: "SendEmptyFragments-DTLS",
889 config: Config{
890 Bugs: ProtocolBugs{
891 SendEmptyFragments: true,
892 },
893 },
894 },
David Benjamin67d1fb52015-03-16 15:16:23 -0400895 {
896 name: "UnsupportedCipherSuite",
897 config: Config{
898 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
899 Bugs: ProtocolBugs{
900 IgnorePeerCipherPreferences: true,
901 },
902 },
903 flags: []string{"-cipher", "DEFAULT:!RC4"},
904 shouldFail: true,
905 expectedError: ":WRONG_CIPHER_RETURNED:",
906 },
David Benjamin340d5ed2015-03-21 02:21:37 -0400907 {
908 name: "SendWarningAlerts",
909 config: Config{
910 Bugs: ProtocolBugs{
911 SendWarningAlerts: alertAccessDenied,
912 },
913 },
914 },
915 {
916 protocol: dtls,
917 name: "SendWarningAlerts-DTLS",
918 config: Config{
919 Bugs: ProtocolBugs{
920 SendWarningAlerts: alertAccessDenied,
921 },
922 },
923 },
David Benjamin513f0ea2015-04-02 19:33:31 -0400924 {
925 name: "BadFinished",
926 config: Config{
927 Bugs: ProtocolBugs{
928 BadFinished: true,
929 },
930 },
931 shouldFail: true,
932 expectedError: ":DIGEST_CHECK_FAILED:",
933 },
934 {
935 name: "FalseStart-BadFinished",
936 config: Config{
937 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
938 NextProtos: []string{"foo"},
939 Bugs: ProtocolBugs{
940 BadFinished: true,
941 ExpectFalseStart: true,
942 },
943 },
944 flags: []string{
945 "-false-start",
946 "-advertise-alpn", "\x03foo",
947 },
948 shimWritesFirst: true,
949 shouldFail: true,
950 expectedError: ":DIGEST_CHECK_FAILED:",
951 },
Adam Langley95c29f32014-06-20 12:00:00 -0700952}
953
David Benjamin01fe8202014-09-24 15:21:44 -0400954func doExchange(test *testCase, config *Config, conn net.Conn, messageLen int, isResume bool) error {
David Benjamin65ea8ff2014-11-23 03:01:00 -0500955 var connDebug *recordingConn
David Benjamin5fa3eba2015-01-22 16:35:40 -0500956 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -0500957 if *flagDebug {
958 connDebug = &recordingConn{Conn: conn}
959 conn = connDebug
960 defer func() {
961 connDebug.WriteTo(os.Stdout)
962 }()
963 }
964
David Benjamin6fd297b2014-08-11 18:43:38 -0400965 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500966 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
967 conn = config.Bugs.PacketAdaptor
David Benjamin5e961c12014-11-07 01:48:35 -0500968 if test.replayWrites {
969 conn = newReplayAdaptor(conn)
970 }
David Benjamin6fd297b2014-08-11 18:43:38 -0400971 }
972
David Benjamin5fa3eba2015-01-22 16:35:40 -0500973 if test.damageFirstWrite {
974 connDamage = newDamageAdaptor(conn)
975 conn = connDamage
976 }
977
David Benjamin6fd297b2014-08-11 18:43:38 -0400978 if test.sendPrefix != "" {
979 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
980 return err
981 }
David Benjamin98e882e2014-08-08 13:24:34 -0400982 }
983
David Benjamin1d5c83e2014-07-22 19:20:02 -0400984 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400985 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400986 if test.protocol == dtls {
987 tlsConn = DTLSServer(conn, config)
988 } else {
989 tlsConn = Server(conn, config)
990 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400991 } else {
992 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400993 if test.protocol == dtls {
994 tlsConn = DTLSClient(conn, config)
995 } else {
996 tlsConn = Client(conn, config)
997 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400998 }
999
Adam Langley95c29f32014-06-20 12:00:00 -07001000 if err := tlsConn.Handshake(); err != nil {
1001 return err
1002 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07001003
David Benjamin01fe8202014-09-24 15:21:44 -04001004 // TODO(davidben): move all per-connection expectations into a dedicated
1005 // expectations struct that can be specified separately for the two
1006 // legs.
1007 expectedVersion := test.expectedVersion
1008 if isResume && test.expectedResumeVersion != 0 {
1009 expectedVersion = test.expectedResumeVersion
1010 }
1011 if vers := tlsConn.ConnectionState().Version; expectedVersion != 0 && vers != expectedVersion {
1012 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001013 }
1014
David Benjamina08e49d2014-08-24 01:46:07 -04001015 if test.expectChannelID {
1016 channelID := tlsConn.ConnectionState().ChannelID
1017 if channelID == nil {
1018 return fmt.Errorf("no channel ID negotiated")
1019 }
1020 if channelID.Curve != channelIDKey.Curve ||
1021 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
1022 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
1023 return fmt.Errorf("incorrect channel ID")
1024 }
1025 }
1026
David Benjaminae2888f2014-09-06 12:58:58 -04001027 if expected := test.expectedNextProto; expected != "" {
1028 if actual := tlsConn.ConnectionState().NegotiatedProtocol; actual != expected {
1029 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
1030 }
1031 }
1032
David Benjaminfc7b0862014-09-06 13:21:53 -04001033 if test.expectedNextProtoType != 0 {
1034 if (test.expectedNextProtoType == alpn) != tlsConn.ConnectionState().NegotiatedProtocolFromALPN {
1035 return fmt.Errorf("next proto type mismatch")
1036 }
1037 }
1038
David Benjaminca6c8262014-11-15 19:06:08 -05001039 if p := tlsConn.ConnectionState().SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
1040 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
1041 }
1042
David Benjamine58c4f52014-08-24 03:47:07 -04001043 if test.shimWritesFirst {
1044 var buf [5]byte
1045 _, err := io.ReadFull(tlsConn, buf[:])
1046 if err != nil {
1047 return err
1048 }
1049 if string(buf[:]) != "hello" {
1050 return fmt.Errorf("bad initial message")
1051 }
1052 }
1053
Adam Langleycf2d4f42014-10-28 19:06:14 -07001054 if test.renegotiate {
1055 if test.renegotiateCiphers != nil {
1056 config.CipherSuites = test.renegotiateCiphers
1057 }
1058 if err := tlsConn.Renegotiate(); err != nil {
1059 return err
1060 }
1061 } else if test.renegotiateCiphers != nil {
1062 panic("renegotiateCiphers without renegotiate")
1063 }
1064
David Benjamin5fa3eba2015-01-22 16:35:40 -05001065 if test.damageFirstWrite {
1066 connDamage.setDamage(true)
1067 tlsConn.Write([]byte("DAMAGED WRITE"))
1068 connDamage.setDamage(false)
1069 }
1070
Kenny Root7fdeaf12014-08-05 15:23:37 -07001071 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -04001072 if test.protocol == dtls {
1073 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
1074 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07001075 // Read until EOF.
1076 _, err := io.Copy(ioutil.Discard, tlsConn)
1077 return err
1078 }
1079
David Benjamin4189bd92015-01-25 23:52:39 -05001080 var testMessage []byte
1081 if config.Bugs.AppDataAfterChangeCipherSpec != nil {
1082 // We've already sent a message. Expect the shim to echo it
1083 // back.
1084 testMessage = config.Bugs.AppDataAfterChangeCipherSpec
1085 } else {
1086 if messageLen == 0 {
1087 messageLen = 32
1088 }
1089 testMessage = make([]byte, messageLen)
1090 for i := range testMessage {
1091 testMessage[i] = 0x42
1092 }
1093 tlsConn.Write(testMessage)
Adam Langley80842bd2014-06-20 12:00:00 -07001094 }
Adam Langley95c29f32014-06-20 12:00:00 -07001095
1096 buf := make([]byte, len(testMessage))
David Benjamin6fd297b2014-08-11 18:43:38 -04001097 if test.protocol == dtls {
1098 bufTmp := make([]byte, len(buf)+1)
1099 n, err := tlsConn.Read(bufTmp)
1100 if err != nil {
1101 return err
1102 }
1103 if n != len(buf) {
1104 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
1105 }
1106 copy(buf, bufTmp)
1107 } else {
1108 _, err := io.ReadFull(tlsConn, buf)
1109 if err != nil {
1110 return err
1111 }
Adam Langley95c29f32014-06-20 12:00:00 -07001112 }
1113
1114 for i, v := range buf {
1115 if v != testMessage[i]^0xff {
1116 return fmt.Errorf("bad reply contents at byte %d", i)
1117 }
1118 }
1119
1120 return nil
1121}
1122
David Benjamin325b5c32014-07-01 19:40:31 -04001123func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
1124 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -07001125 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -04001126 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -07001127 }
David Benjamin325b5c32014-07-01 19:40:31 -04001128 valgrindArgs = append(valgrindArgs, path)
1129 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -07001130
David Benjamin325b5c32014-07-01 19:40:31 -04001131 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -07001132}
1133
David Benjamin325b5c32014-07-01 19:40:31 -04001134func gdbOf(path string, args ...string) *exec.Cmd {
1135 xtermArgs := []string{"-e", "gdb", "--args"}
1136 xtermArgs = append(xtermArgs, path)
1137 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -07001138
David Benjamin325b5c32014-07-01 19:40:31 -04001139 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -07001140}
1141
Adam Langley69a01602014-11-17 17:26:55 -08001142type moreMallocsError struct{}
1143
1144func (moreMallocsError) Error() string {
1145 return "child process did not exhaust all allocation calls"
1146}
1147
1148var errMoreMallocs = moreMallocsError{}
1149
David Benjamin87c8a642015-02-21 01:54:29 -05001150// accept accepts a connection from listener, unless waitChan signals a process
1151// exit first.
1152func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
1153 type connOrError struct {
1154 conn net.Conn
1155 err error
1156 }
1157 connChan := make(chan connOrError, 1)
1158 go func() {
1159 conn, err := listener.Accept()
1160 connChan <- connOrError{conn, err}
1161 close(connChan)
1162 }()
1163 select {
1164 case result := <-connChan:
1165 return result.conn, result.err
1166 case childErr := <-waitChan:
1167 waitChan <- childErr
1168 return nil, fmt.Errorf("child exited early: %s", childErr)
1169 }
1170}
1171
Adam Langley69a01602014-11-17 17:26:55 -08001172func runTest(test *testCase, buildDir string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -07001173 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
1174 panic("Error expected without shouldFail in " + test.name)
1175 }
1176
David Benjamin87c8a642015-02-21 01:54:29 -05001177 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
1178 if err != nil {
1179 panic(err)
1180 }
1181 defer func() {
1182 if listener != nil {
1183 listener.Close()
1184 }
1185 }()
Adam Langley95c29f32014-06-20 12:00:00 -07001186
David Benjamin884fdf12014-08-02 15:28:23 -04001187 shim_path := path.Join(buildDir, "ssl/test/bssl_shim")
David Benjamin87c8a642015-02-21 01:54:29 -05001188 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -04001189 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -04001190 flags = append(flags, "-server")
1191
David Benjamin025b3d32014-07-01 19:53:04 -04001192 flags = append(flags, "-key-file")
1193 if test.keyFile == "" {
1194 flags = append(flags, rsaKeyFile)
1195 } else {
1196 flags = append(flags, test.keyFile)
1197 }
1198
1199 flags = append(flags, "-cert-file")
1200 if test.certFile == "" {
1201 flags = append(flags, rsaCertificateFile)
1202 } else {
1203 flags = append(flags, test.certFile)
1204 }
1205 }
David Benjamin5a593af2014-08-11 19:51:50 -04001206
David Benjamin6fd297b2014-08-11 18:43:38 -04001207 if test.protocol == dtls {
1208 flags = append(flags, "-dtls")
1209 }
1210
David Benjamin5a593af2014-08-11 19:51:50 -04001211 if test.resumeSession {
1212 flags = append(flags, "-resume")
1213 }
1214
David Benjamine58c4f52014-08-24 03:47:07 -04001215 if test.shimWritesFirst {
1216 flags = append(flags, "-shim-writes-first")
1217 }
1218
David Benjamin025b3d32014-07-01 19:53:04 -04001219 flags = append(flags, test.flags...)
1220
1221 var shim *exec.Cmd
1222 if *useValgrind {
1223 shim = valgrindOf(false, shim_path, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001224 } else if *useGDB {
1225 shim = gdbOf(shim_path, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001226 } else {
1227 shim = exec.Command(shim_path, flags...)
1228 }
David Benjamin025b3d32014-07-01 19:53:04 -04001229 shim.Stdin = os.Stdin
1230 var stdoutBuf, stderrBuf bytes.Buffer
1231 shim.Stdout = &stdoutBuf
1232 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001233 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001234 shim.Env = os.Environ()
1235 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001236 if *mallocTestDebug {
1237 shim.Env = append(shim.Env, "MALLOC_ABORT_ON_FAIL=1")
1238 }
1239 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1240 }
David Benjamin025b3d32014-07-01 19:53:04 -04001241
1242 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001243 panic(err)
1244 }
David Benjamin87c8a642015-02-21 01:54:29 -05001245 waitChan := make(chan error, 1)
1246 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001247
1248 config := test.config
David Benjamin1d5c83e2014-07-22 19:20:02 -04001249 config.ClientSessionCache = NewLRUClientSessionCache(1)
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001250 config.ServerSessionCache = NewLRUServerSessionCache(1)
David Benjamin025b3d32014-07-01 19:53:04 -04001251 if test.testType == clientTest {
1252 if len(config.Certificates) == 0 {
1253 config.Certificates = []Certificate{getRSACertificate()}
1254 }
David Benjamin87c8a642015-02-21 01:54:29 -05001255 } else {
1256 // Supply a ServerName to ensure a constant session cache key,
1257 // rather than falling back to net.Conn.RemoteAddr.
1258 if len(config.ServerName) == 0 {
1259 config.ServerName = "test"
1260 }
David Benjamin025b3d32014-07-01 19:53:04 -04001261 }
Adam Langley95c29f32014-06-20 12:00:00 -07001262
David Benjamin87c8a642015-02-21 01:54:29 -05001263 conn, err := acceptOrWait(listener, waitChan)
1264 if err == nil {
1265 err = doExchange(test, &config, conn, test.messageLen, false /* not a resumption */)
1266 conn.Close()
1267 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001268
David Benjamin1d5c83e2014-07-22 19:20:02 -04001269 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -04001270 var resumeConfig Config
1271 if test.resumeConfig != nil {
1272 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -05001273 if len(resumeConfig.ServerName) == 0 {
1274 resumeConfig.ServerName = config.ServerName
1275 }
David Benjamin01fe8202014-09-24 15:21:44 -04001276 if len(resumeConfig.Certificates) == 0 {
1277 resumeConfig.Certificates = []Certificate{getRSACertificate()}
1278 }
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001279 if !test.newSessionsOnResume {
1280 resumeConfig.SessionTicketKey = config.SessionTicketKey
1281 resumeConfig.ClientSessionCache = config.ClientSessionCache
1282 resumeConfig.ServerSessionCache = config.ServerSessionCache
1283 }
David Benjamin01fe8202014-09-24 15:21:44 -04001284 } else {
1285 resumeConfig = config
1286 }
David Benjamin87c8a642015-02-21 01:54:29 -05001287 var connResume net.Conn
1288 connResume, err = acceptOrWait(listener, waitChan)
1289 if err == nil {
1290 err = doExchange(test, &resumeConfig, connResume, test.messageLen, true /* resumption */)
1291 connResume.Close()
1292 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001293 }
1294
David Benjamin87c8a642015-02-21 01:54:29 -05001295 // Close the listener now. This is to avoid hangs should the shim try to
1296 // open more connections than expected.
1297 listener.Close()
1298 listener = nil
1299
1300 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -08001301 if exitError, ok := childErr.(*exec.ExitError); ok {
1302 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
1303 return errMoreMallocs
1304 }
1305 }
Adam Langley95c29f32014-06-20 12:00:00 -07001306
1307 stdout := string(stdoutBuf.Bytes())
1308 stderr := string(stderrBuf.Bytes())
1309 failed := err != nil || childErr != nil
1310 correctFailure := len(test.expectedError) == 0 || strings.Contains(stdout, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -07001311 localError := "none"
1312 if err != nil {
1313 localError = err.Error()
1314 }
1315 if len(test.expectedLocalError) != 0 {
1316 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1317 }
Adam Langley95c29f32014-06-20 12:00:00 -07001318
1319 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001320 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001321 if childErr != nil {
1322 childError = childErr.Error()
1323 }
1324
1325 var msg string
1326 switch {
1327 case failed && !test.shouldFail:
1328 msg = "unexpected failure"
1329 case !failed && test.shouldFail:
1330 msg = "unexpected success"
1331 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -07001332 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001333 default:
1334 panic("internal error")
1335 }
1336
1337 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, string(stdoutBuf.Bytes()), stderr)
1338 }
1339
1340 if !*useValgrind && len(stderr) > 0 {
1341 println(stderr)
1342 }
1343
1344 return nil
1345}
1346
1347var tlsVersions = []struct {
1348 name string
1349 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001350 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001351 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001352}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001353 {"SSL3", VersionSSL30, "-no-ssl3", false},
1354 {"TLS1", VersionTLS10, "-no-tls1", true},
1355 {"TLS11", VersionTLS11, "-no-tls11", false},
1356 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -07001357}
1358
1359var testCipherSuites = []struct {
1360 name string
1361 id uint16
1362}{
1363 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001364 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001365 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001366 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001367 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001368 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001369 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001370 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1371 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001372 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001373 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1374 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001375 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001376 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1377 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001378 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1379 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001380 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001381 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001382 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
David Benjamin2af684f2014-10-27 02:23:15 -04001383 {"ECDHE-PSK-WITH-AES-128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001384 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001385 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001386 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001387 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001388 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001389 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001390 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -04001391 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1392 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
1393 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001394 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001395 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001396}
1397
David Benjamin8b8c0062014-11-23 02:47:52 -05001398func hasComponent(suiteName, component string) bool {
1399 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1400}
1401
David Benjaminf7768e42014-08-31 02:06:47 -04001402func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001403 return hasComponent(suiteName, "GCM") ||
1404 hasComponent(suiteName, "SHA256") ||
1405 hasComponent(suiteName, "SHA384")
1406}
1407
1408func isDTLSCipher(suiteName string) bool {
David Benjamine95d20d2014-12-23 11:16:01 -05001409 return !hasComponent(suiteName, "RC4")
David Benjaminf7768e42014-08-31 02:06:47 -04001410}
1411
Adam Langley95c29f32014-06-20 12:00:00 -07001412func addCipherSuiteTests() {
1413 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04001414 const psk = "12345"
1415 const pskIdentity = "luggage combo"
1416
Adam Langley95c29f32014-06-20 12:00:00 -07001417 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04001418 var certFile string
1419 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05001420 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07001421 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001422 certFile = ecdsaCertificateFile
1423 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001424 } else {
1425 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001426 certFile = rsaCertificateFile
1427 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001428 }
1429
David Benjamin48cae082014-10-27 01:06:24 -04001430 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05001431 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04001432 flags = append(flags,
1433 "-psk", psk,
1434 "-psk-identity", pskIdentity)
1435 }
1436
Adam Langley95c29f32014-06-20 12:00:00 -07001437 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04001438 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07001439 continue
1440 }
1441
David Benjamin025b3d32014-07-01 19:53:04 -04001442 testCases = append(testCases, testCase{
1443 testType: clientTest,
1444 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07001445 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001446 MinVersion: ver.version,
1447 MaxVersion: ver.version,
1448 CipherSuites: []uint16{suite.id},
1449 Certificates: []Certificate{cert},
1450 PreSharedKey: []byte(psk),
1451 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07001452 },
David Benjamin48cae082014-10-27 01:06:24 -04001453 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001454 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07001455 })
David Benjamin025b3d32014-07-01 19:53:04 -04001456
David Benjamin76d8abe2014-08-14 16:25:34 -04001457 testCases = append(testCases, testCase{
1458 testType: serverTest,
1459 name: ver.name + "-" + suite.name + "-server",
1460 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001461 MinVersion: ver.version,
1462 MaxVersion: ver.version,
1463 CipherSuites: []uint16{suite.id},
1464 Certificates: []Certificate{cert},
1465 PreSharedKey: []byte(psk),
1466 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04001467 },
1468 certFile: certFile,
1469 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04001470 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001471 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04001472 })
David Benjamin6fd297b2014-08-11 18:43:38 -04001473
David Benjamin8b8c0062014-11-23 02:47:52 -05001474 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04001475 testCases = append(testCases, testCase{
1476 testType: clientTest,
1477 protocol: dtls,
1478 name: "D" + ver.name + "-" + suite.name + "-client",
1479 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001480 MinVersion: ver.version,
1481 MaxVersion: ver.version,
1482 CipherSuites: []uint16{suite.id},
1483 Certificates: []Certificate{cert},
1484 PreSharedKey: []byte(psk),
1485 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04001486 },
David Benjamin48cae082014-10-27 01:06:24 -04001487 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001488 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04001489 })
1490 testCases = append(testCases, testCase{
1491 testType: serverTest,
1492 protocol: dtls,
1493 name: "D" + ver.name + "-" + suite.name + "-server",
1494 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001495 MinVersion: ver.version,
1496 MaxVersion: ver.version,
1497 CipherSuites: []uint16{suite.id},
1498 Certificates: []Certificate{cert},
1499 PreSharedKey: []byte(psk),
1500 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04001501 },
1502 certFile: certFile,
1503 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04001504 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001505 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04001506 })
1507 }
Adam Langley95c29f32014-06-20 12:00:00 -07001508 }
1509 }
1510}
1511
1512func addBadECDSASignatureTests() {
1513 for badR := BadValue(1); badR < NumBadValues; badR++ {
1514 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04001515 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07001516 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
1517 config: Config{
1518 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1519 Certificates: []Certificate{getECDSACertificate()},
1520 Bugs: ProtocolBugs{
1521 BadECDSAR: badR,
1522 BadECDSAS: badS,
1523 },
1524 },
1525 shouldFail: true,
1526 expectedError: "SIGNATURE",
1527 })
1528 }
1529 }
1530}
1531
Adam Langley80842bd2014-06-20 12:00:00 -07001532func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04001533 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001534 name: "MaxCBCPadding",
1535 config: Config{
1536 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1537 Bugs: ProtocolBugs{
1538 MaxPadding: true,
1539 },
1540 },
1541 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
1542 })
David Benjamin025b3d32014-07-01 19:53:04 -04001543 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001544 name: "BadCBCPadding",
1545 config: Config{
1546 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1547 Bugs: ProtocolBugs{
1548 PaddingFirstByteBad: true,
1549 },
1550 },
1551 shouldFail: true,
1552 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
1553 })
1554 // OpenSSL previously had an issue where the first byte of padding in
1555 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04001556 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001557 name: "BadCBCPadding255",
1558 config: Config{
1559 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1560 Bugs: ProtocolBugs{
1561 MaxPadding: true,
1562 PaddingFirstByteBadIf255: true,
1563 },
1564 },
1565 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
1566 shouldFail: true,
1567 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
1568 })
1569}
1570
Kenny Root7fdeaf12014-08-05 15:23:37 -07001571func addCBCSplittingTests() {
1572 testCases = append(testCases, testCase{
1573 name: "CBCRecordSplitting",
1574 config: Config{
1575 MaxVersion: VersionTLS10,
1576 MinVersion: VersionTLS10,
1577 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1578 },
1579 messageLen: -1, // read until EOF
1580 flags: []string{
1581 "-async",
1582 "-write-different-record-sizes",
1583 "-cbc-record-splitting",
1584 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04001585 })
1586 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07001587 name: "CBCRecordSplittingPartialWrite",
1588 config: Config{
1589 MaxVersion: VersionTLS10,
1590 MinVersion: VersionTLS10,
1591 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1592 },
1593 messageLen: -1, // read until EOF
1594 flags: []string{
1595 "-async",
1596 "-write-different-record-sizes",
1597 "-cbc-record-splitting",
1598 "-partial-write",
1599 },
1600 })
1601}
1602
David Benjamin636293b2014-07-08 17:59:18 -04001603func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04001604 // Add a dummy cert pool to stress certificate authority parsing.
1605 // TODO(davidben): Add tests that those values parse out correctly.
1606 certPool := x509.NewCertPool()
1607 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
1608 if err != nil {
1609 panic(err)
1610 }
1611 certPool.AddCert(cert)
1612
David Benjamin636293b2014-07-08 17:59:18 -04001613 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04001614 testCases = append(testCases, testCase{
1615 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04001616 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04001617 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04001618 MinVersion: ver.version,
1619 MaxVersion: ver.version,
1620 ClientAuth: RequireAnyClientCert,
1621 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04001622 },
1623 flags: []string{
1624 "-cert-file", rsaCertificateFile,
1625 "-key-file", rsaKeyFile,
1626 },
1627 })
1628 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04001629 testType: serverTest,
1630 name: ver.name + "-Server-ClientAuth-RSA",
1631 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04001632 MinVersion: ver.version,
1633 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04001634 Certificates: []Certificate{rsaCertificate},
1635 },
1636 flags: []string{"-require-any-client-certificate"},
1637 })
David Benjamine098ec22014-08-27 23:13:20 -04001638 if ver.version != VersionSSL30 {
1639 testCases = append(testCases, testCase{
1640 testType: serverTest,
1641 name: ver.name + "-Server-ClientAuth-ECDSA",
1642 config: Config{
1643 MinVersion: ver.version,
1644 MaxVersion: ver.version,
1645 Certificates: []Certificate{ecdsaCertificate},
1646 },
1647 flags: []string{"-require-any-client-certificate"},
1648 })
1649 testCases = append(testCases, testCase{
1650 testType: clientTest,
1651 name: ver.name + "-Client-ClientAuth-ECDSA",
1652 config: Config{
1653 MinVersion: ver.version,
1654 MaxVersion: ver.version,
1655 ClientAuth: RequireAnyClientCert,
1656 ClientCAs: certPool,
1657 },
1658 flags: []string{
1659 "-cert-file", ecdsaCertificateFile,
1660 "-key-file", ecdsaKeyFile,
1661 },
1662 })
1663 }
David Benjamin636293b2014-07-08 17:59:18 -04001664 }
1665}
1666
Adam Langley75712922014-10-10 16:23:43 -07001667func addExtendedMasterSecretTests() {
1668 const expectEMSFlag = "-expect-extended-master-secret"
1669
1670 for _, with := range []bool{false, true} {
1671 prefix := "No"
1672 var flags []string
1673 if with {
1674 prefix = ""
1675 flags = []string{expectEMSFlag}
1676 }
1677
1678 for _, isClient := range []bool{false, true} {
1679 suffix := "-Server"
1680 testType := serverTest
1681 if isClient {
1682 suffix = "-Client"
1683 testType = clientTest
1684 }
1685
1686 for _, ver := range tlsVersions {
1687 test := testCase{
1688 testType: testType,
1689 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
1690 config: Config{
1691 MinVersion: ver.version,
1692 MaxVersion: ver.version,
1693 Bugs: ProtocolBugs{
1694 NoExtendedMasterSecret: !with,
1695 RequireExtendedMasterSecret: with,
1696 },
1697 },
David Benjamin48cae082014-10-27 01:06:24 -04001698 flags: flags,
1699 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07001700 }
1701 if test.shouldFail {
1702 test.expectedLocalError = "extended master secret required but not supported by peer"
1703 }
1704 testCases = append(testCases, test)
1705 }
1706 }
1707 }
1708
1709 // When a session is resumed, it should still be aware that its master
1710 // secret was generated via EMS and thus it's safe to use tls-unique.
1711 testCases = append(testCases, testCase{
1712 name: "ExtendedMasterSecret-Resume",
1713 config: Config{
1714 Bugs: ProtocolBugs{
1715 RequireExtendedMasterSecret: true,
1716 },
1717 },
1718 flags: []string{expectEMSFlag},
1719 resumeSession: true,
1720 })
1721}
1722
David Benjamin43ec06f2014-08-05 02:28:57 -04001723// Adds tests that try to cover the range of the handshake state machine, under
1724// various conditions. Some of these are redundant with other tests, but they
1725// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04001726func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin43ec06f2014-08-05 02:28:57 -04001727 var suffix string
1728 var flags []string
1729 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04001730 if protocol == dtls {
1731 suffix = "-DTLS"
1732 }
David Benjamin43ec06f2014-08-05 02:28:57 -04001733 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04001734 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04001735 flags = append(flags, "-async")
1736 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04001737 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04001738 }
1739 if splitHandshake {
1740 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04001741 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04001742 }
1743
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001744 // Basic handshake, with resumption. Client and server,
1745 // session ID and session ticket.
David Benjamin43ec06f2014-08-05 02:28:57 -04001746 testCases = append(testCases, testCase{
David Benjamin6fd297b2014-08-11 18:43:38 -04001747 protocol: protocol,
1748 name: "Basic-Client" + suffix,
David Benjamin43ec06f2014-08-05 02:28:57 -04001749 config: Config{
1750 Bugs: ProtocolBugs{
1751 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1752 },
1753 },
David Benjaminbed9aae2014-08-07 19:13:38 -04001754 flags: flags,
1755 resumeSession: true,
1756 })
1757 testCases = append(testCases, testCase{
David Benjamin6fd297b2014-08-11 18:43:38 -04001758 protocol: protocol,
1759 name: "Basic-Client-RenewTicket" + suffix,
David Benjaminbed9aae2014-08-07 19:13:38 -04001760 config: Config{
1761 Bugs: ProtocolBugs{
1762 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1763 RenewTicketOnResume: true,
1764 },
1765 },
1766 flags: flags,
1767 resumeSession: true,
David Benjamin43ec06f2014-08-05 02:28:57 -04001768 })
1769 testCases = append(testCases, testCase{
David Benjamin6fd297b2014-08-11 18:43:38 -04001770 protocol: protocol,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001771 name: "Basic-Client-NoTicket" + suffix,
1772 config: Config{
1773 SessionTicketsDisabled: true,
1774 Bugs: ProtocolBugs{
1775 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1776 },
1777 },
1778 flags: flags,
1779 resumeSession: true,
1780 })
1781 testCases = append(testCases, testCase{
1782 protocol: protocol,
David Benjamine0e7d0d2015-02-08 19:33:25 -05001783 name: "Basic-Client-Implicit" + suffix,
1784 config: Config{
1785 Bugs: ProtocolBugs{
1786 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1787 },
1788 },
1789 flags: append(flags, "-implicit-handshake"),
1790 resumeSession: true,
1791 })
1792 testCases = append(testCases, testCase{
1793 protocol: protocol,
David Benjamin43ec06f2014-08-05 02:28:57 -04001794 testType: serverTest,
1795 name: "Basic-Server" + suffix,
1796 config: Config{
1797 Bugs: ProtocolBugs{
1798 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1799 },
1800 },
David Benjaminbed9aae2014-08-07 19:13:38 -04001801 flags: flags,
1802 resumeSession: true,
David Benjamin43ec06f2014-08-05 02:28:57 -04001803 })
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001804 testCases = append(testCases, testCase{
1805 protocol: protocol,
1806 testType: serverTest,
1807 name: "Basic-Server-NoTickets" + suffix,
1808 config: Config{
1809 SessionTicketsDisabled: true,
1810 Bugs: ProtocolBugs{
1811 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1812 },
1813 },
1814 flags: flags,
1815 resumeSession: true,
1816 })
David Benjamine0e7d0d2015-02-08 19:33:25 -05001817 testCases = append(testCases, testCase{
1818 protocol: protocol,
1819 testType: serverTest,
1820 name: "Basic-Server-Implicit" + suffix,
1821 config: Config{
1822 Bugs: ProtocolBugs{
1823 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1824 },
1825 },
1826 flags: append(flags, "-implicit-handshake"),
1827 resumeSession: true,
1828 })
David Benjamin6f5c0f42015-02-24 01:23:21 -05001829 testCases = append(testCases, testCase{
1830 protocol: protocol,
1831 testType: serverTest,
1832 name: "Basic-Server-EarlyCallback" + suffix,
1833 config: Config{
1834 Bugs: ProtocolBugs{
1835 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1836 },
1837 },
1838 flags: append(flags, "-use-early-callback"),
1839 resumeSession: true,
1840 })
David Benjamin43ec06f2014-08-05 02:28:57 -04001841
David Benjamin6fd297b2014-08-11 18:43:38 -04001842 // TLS client auth.
1843 testCases = append(testCases, testCase{
1844 protocol: protocol,
1845 testType: clientTest,
1846 name: "ClientAuth-Client" + suffix,
1847 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04001848 ClientAuth: RequireAnyClientCert,
David Benjamin6fd297b2014-08-11 18:43:38 -04001849 Bugs: ProtocolBugs{
1850 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1851 },
1852 },
1853 flags: append(flags,
1854 "-cert-file", rsaCertificateFile,
1855 "-key-file", rsaKeyFile),
1856 })
1857 testCases = append(testCases, testCase{
1858 protocol: protocol,
1859 testType: serverTest,
1860 name: "ClientAuth-Server" + suffix,
1861 config: Config{
1862 Certificates: []Certificate{rsaCertificate},
1863 },
1864 flags: append(flags, "-require-any-client-certificate"),
1865 })
1866
David Benjamin43ec06f2014-08-05 02:28:57 -04001867 // No session ticket support; server doesn't send NewSessionTicket.
1868 testCases = append(testCases, testCase{
David Benjamin6fd297b2014-08-11 18:43:38 -04001869 protocol: protocol,
1870 name: "SessionTicketsDisabled-Client" + suffix,
David Benjamin43ec06f2014-08-05 02:28:57 -04001871 config: Config{
1872 SessionTicketsDisabled: true,
1873 Bugs: ProtocolBugs{
1874 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1875 },
1876 },
1877 flags: flags,
1878 })
1879 testCases = append(testCases, testCase{
David Benjamin6fd297b2014-08-11 18:43:38 -04001880 protocol: protocol,
David Benjamin43ec06f2014-08-05 02:28:57 -04001881 testType: serverTest,
1882 name: "SessionTicketsDisabled-Server" + suffix,
1883 config: Config{
1884 SessionTicketsDisabled: true,
1885 Bugs: ProtocolBugs{
1886 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1887 },
1888 },
1889 flags: flags,
1890 })
1891
David Benjamin48cae082014-10-27 01:06:24 -04001892 // Skip ServerKeyExchange in PSK key exchange if there's no
1893 // identity hint.
1894 testCases = append(testCases, testCase{
1895 protocol: protocol,
1896 name: "EmptyPSKHint-Client" + suffix,
1897 config: Config{
1898 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
1899 PreSharedKey: []byte("secret"),
1900 Bugs: ProtocolBugs{
1901 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1902 },
1903 },
1904 flags: append(flags, "-psk", "secret"),
1905 })
1906 testCases = append(testCases, testCase{
1907 protocol: protocol,
1908 testType: serverTest,
1909 name: "EmptyPSKHint-Server" + suffix,
1910 config: Config{
1911 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
1912 PreSharedKey: []byte("secret"),
1913 Bugs: ProtocolBugs{
1914 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1915 },
1916 },
1917 flags: append(flags, "-psk", "secret"),
1918 })
1919
David Benjamin6fd297b2014-08-11 18:43:38 -04001920 if protocol == tls {
1921 // NPN on client and server; results in post-handshake message.
1922 testCases = append(testCases, testCase{
1923 protocol: protocol,
1924 name: "NPN-Client" + suffix,
1925 config: Config{
David Benjaminae2888f2014-09-06 12:58:58 -04001926 NextProtos: []string{"foo"},
David Benjamin6fd297b2014-08-11 18:43:38 -04001927 Bugs: ProtocolBugs{
1928 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1929 },
David Benjamin43ec06f2014-08-05 02:28:57 -04001930 },
David Benjaminfc7b0862014-09-06 13:21:53 -04001931 flags: append(flags, "-select-next-proto", "foo"),
1932 expectedNextProto: "foo",
1933 expectedNextProtoType: npn,
David Benjamin6fd297b2014-08-11 18:43:38 -04001934 })
1935 testCases = append(testCases, testCase{
1936 protocol: protocol,
1937 testType: serverTest,
1938 name: "NPN-Server" + suffix,
1939 config: Config{
1940 NextProtos: []string{"bar"},
1941 Bugs: ProtocolBugs{
1942 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1943 },
David Benjamin43ec06f2014-08-05 02:28:57 -04001944 },
David Benjamin6fd297b2014-08-11 18:43:38 -04001945 flags: append(flags,
1946 "-advertise-npn", "\x03foo\x03bar\x03baz",
1947 "-expect-next-proto", "bar"),
David Benjaminfc7b0862014-09-06 13:21:53 -04001948 expectedNextProto: "bar",
1949 expectedNextProtoType: npn,
David Benjamin6fd297b2014-08-11 18:43:38 -04001950 })
David Benjamin43ec06f2014-08-05 02:28:57 -04001951
David Benjamin195dc782015-02-19 13:27:05 -05001952 // TODO(davidben): Add tests for when False Start doesn't trigger.
1953
David Benjamin6fd297b2014-08-11 18:43:38 -04001954 // Client does False Start and negotiates NPN.
1955 testCases = append(testCases, testCase{
1956 protocol: protocol,
1957 name: "FalseStart" + suffix,
1958 config: Config{
1959 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1960 NextProtos: []string{"foo"},
1961 Bugs: ProtocolBugs{
David Benjamine58c4f52014-08-24 03:47:07 -04001962 ExpectFalseStart: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04001963 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1964 },
David Benjamin43ec06f2014-08-05 02:28:57 -04001965 },
David Benjamin6fd297b2014-08-11 18:43:38 -04001966 flags: append(flags,
1967 "-false-start",
1968 "-select-next-proto", "foo"),
David Benjamine58c4f52014-08-24 03:47:07 -04001969 shimWritesFirst: true,
1970 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04001971 })
David Benjamin43ec06f2014-08-05 02:28:57 -04001972
David Benjaminae2888f2014-09-06 12:58:58 -04001973 // Client does False Start and negotiates ALPN.
1974 testCases = append(testCases, testCase{
1975 protocol: protocol,
1976 name: "FalseStart-ALPN" + suffix,
1977 config: Config{
1978 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1979 NextProtos: []string{"foo"},
1980 Bugs: ProtocolBugs{
1981 ExpectFalseStart: true,
1982 MaxHandshakeRecordLength: maxHandshakeRecordLength,
1983 },
1984 },
1985 flags: append(flags,
1986 "-false-start",
1987 "-advertise-alpn", "\x03foo"),
1988 shimWritesFirst: true,
1989 resumeSession: true,
1990 })
1991
David Benjamin931ab342015-02-08 19:46:57 -05001992 // Client does False Start but doesn't explicitly call
1993 // SSL_connect.
1994 testCases = append(testCases, testCase{
1995 protocol: protocol,
1996 name: "FalseStart-Implicit" + suffix,
1997 config: Config{
1998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1999 NextProtos: []string{"foo"},
2000 Bugs: ProtocolBugs{
2001 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2002 },
2003 },
2004 flags: append(flags,
2005 "-implicit-handshake",
2006 "-false-start",
2007 "-advertise-alpn", "\x03foo"),
2008 })
2009
David Benjamin6fd297b2014-08-11 18:43:38 -04002010 // False Start without session tickets.
2011 testCases = append(testCases, testCase{
David Benjamin5f237bc2015-02-11 17:14:15 -05002012 name: "FalseStart-SessionTicketsDisabled" + suffix,
David Benjamin6fd297b2014-08-11 18:43:38 -04002013 config: Config{
2014 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2015 NextProtos: []string{"foo"},
2016 SessionTicketsDisabled: true,
David Benjamin4e99c522014-08-24 01:45:30 -04002017 Bugs: ProtocolBugs{
David Benjamine58c4f52014-08-24 03:47:07 -04002018 ExpectFalseStart: true,
David Benjamin4e99c522014-08-24 01:45:30 -04002019 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2020 },
David Benjamin43ec06f2014-08-05 02:28:57 -04002021 },
David Benjamin4e99c522014-08-24 01:45:30 -04002022 flags: append(flags,
David Benjamin6fd297b2014-08-11 18:43:38 -04002023 "-false-start",
2024 "-select-next-proto", "foo",
David Benjamin4e99c522014-08-24 01:45:30 -04002025 ),
David Benjamine58c4f52014-08-24 03:47:07 -04002026 shimWritesFirst: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002027 })
David Benjamin1e7f8d72014-08-08 12:27:04 -04002028
David Benjamina08e49d2014-08-24 01:46:07 -04002029 // Server parses a V2ClientHello.
David Benjamin6fd297b2014-08-11 18:43:38 -04002030 testCases = append(testCases, testCase{
2031 protocol: protocol,
2032 testType: serverTest,
2033 name: "SendV2ClientHello" + suffix,
2034 config: Config{
2035 // Choose a cipher suite that does not involve
2036 // elliptic curves, so no extensions are
2037 // involved.
2038 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2039 Bugs: ProtocolBugs{
2040 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2041 SendV2ClientHello: true,
2042 },
David Benjamin1e7f8d72014-08-08 12:27:04 -04002043 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002044 flags: flags,
2045 })
David Benjamina08e49d2014-08-24 01:46:07 -04002046
2047 // Client sends a Channel ID.
2048 testCases = append(testCases, testCase{
2049 protocol: protocol,
2050 name: "ChannelID-Client" + suffix,
2051 config: Config{
2052 RequestChannelID: true,
2053 Bugs: ProtocolBugs{
2054 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2055 },
2056 },
2057 flags: append(flags,
2058 "-send-channel-id", channelIDKeyFile,
2059 ),
2060 resumeSession: true,
2061 expectChannelID: true,
2062 })
2063
2064 // Server accepts a Channel ID.
2065 testCases = append(testCases, testCase{
2066 protocol: protocol,
2067 testType: serverTest,
2068 name: "ChannelID-Server" + suffix,
2069 config: Config{
2070 ChannelID: channelIDKey,
2071 Bugs: ProtocolBugs{
2072 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2073 },
2074 },
2075 flags: append(flags,
2076 "-expect-channel-id",
2077 base64.StdEncoding.EncodeToString(channelIDBytes),
2078 ),
2079 resumeSession: true,
2080 expectChannelID: true,
2081 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002082 } else {
2083 testCases = append(testCases, testCase{
2084 protocol: protocol,
2085 name: "SkipHelloVerifyRequest" + suffix,
2086 config: Config{
2087 Bugs: ProtocolBugs{
2088 MaxHandshakeRecordLength: maxHandshakeRecordLength,
2089 SkipHelloVerifyRequest: true,
2090 },
2091 },
2092 flags: flags,
2093 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002094 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002095}
2096
Adam Langley524e7172015-02-20 16:04:00 -08002097func addDDoSCallbackTests() {
2098 // DDoS callback.
2099
2100 for _, resume := range []bool{false, true} {
2101 suffix := "Resume"
2102 if resume {
2103 suffix = "No" + suffix
2104 }
2105
2106 testCases = append(testCases, testCase{
2107 testType: serverTest,
2108 name: "Server-DDoS-OK-" + suffix,
2109 flags: []string{"-install-ddos-callback"},
2110 resumeSession: resume,
2111 })
2112
2113 failFlag := "-fail-ddos-callback"
2114 if resume {
2115 failFlag = "-fail-second-ddos-callback"
2116 }
2117 testCases = append(testCases, testCase{
2118 testType: serverTest,
2119 name: "Server-DDoS-Reject-" + suffix,
2120 flags: []string{"-install-ddos-callback", failFlag},
2121 resumeSession: resume,
2122 shouldFail: true,
2123 expectedError: ":CONNECTION_REJECTED:",
2124 })
2125 }
2126}
2127
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002128func addVersionNegotiationTests() {
2129 for i, shimVers := range tlsVersions {
2130 // Assemble flags to disable all newer versions on the shim.
2131 var flags []string
2132 for _, vers := range tlsVersions[i+1:] {
2133 flags = append(flags, vers.flag)
2134 }
2135
2136 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002137 protocols := []protocol{tls}
2138 if runnerVers.hasDTLS && shimVers.hasDTLS {
2139 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002140 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002141 for _, protocol := range protocols {
2142 expectedVersion := shimVers.version
2143 if runnerVers.version < shimVers.version {
2144 expectedVersion = runnerVers.version
2145 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002146
David Benjamin8b8c0062014-11-23 02:47:52 -05002147 suffix := shimVers.name + "-" + runnerVers.name
2148 if protocol == dtls {
2149 suffix += "-DTLS"
2150 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002151
David Benjamin1eb367c2014-12-12 18:17:51 -05002152 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2153
David Benjamin1e29a6b2014-12-10 02:27:24 -05002154 clientVers := shimVers.version
2155 if clientVers > VersionTLS10 {
2156 clientVers = VersionTLS10
2157 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002158 testCases = append(testCases, testCase{
2159 protocol: protocol,
2160 testType: clientTest,
2161 name: "VersionNegotiation-Client-" + suffix,
2162 config: Config{
2163 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002164 Bugs: ProtocolBugs{
2165 ExpectInitialRecordVersion: clientVers,
2166 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002167 },
2168 flags: flags,
2169 expectedVersion: expectedVersion,
2170 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002171 testCases = append(testCases, testCase{
2172 protocol: protocol,
2173 testType: clientTest,
2174 name: "VersionNegotiation-Client2-" + suffix,
2175 config: Config{
2176 MaxVersion: runnerVers.version,
2177 Bugs: ProtocolBugs{
2178 ExpectInitialRecordVersion: clientVers,
2179 },
2180 },
2181 flags: []string{"-max-version", shimVersFlag},
2182 expectedVersion: expectedVersion,
2183 })
David Benjamin8b8c0062014-11-23 02:47:52 -05002184
2185 testCases = append(testCases, testCase{
2186 protocol: protocol,
2187 testType: serverTest,
2188 name: "VersionNegotiation-Server-" + suffix,
2189 config: Config{
2190 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002191 Bugs: ProtocolBugs{
2192 ExpectInitialRecordVersion: expectedVersion,
2193 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002194 },
2195 flags: flags,
2196 expectedVersion: expectedVersion,
2197 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002198 testCases = append(testCases, testCase{
2199 protocol: protocol,
2200 testType: serverTest,
2201 name: "VersionNegotiation-Server2-" + suffix,
2202 config: Config{
2203 MaxVersion: runnerVers.version,
2204 Bugs: ProtocolBugs{
2205 ExpectInitialRecordVersion: expectedVersion,
2206 },
2207 },
2208 flags: []string{"-max-version", shimVersFlag},
2209 expectedVersion: expectedVersion,
2210 })
David Benjamin8b8c0062014-11-23 02:47:52 -05002211 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002212 }
2213 }
2214}
2215
David Benjaminaccb4542014-12-12 23:44:33 -05002216func addMinimumVersionTests() {
2217 for i, shimVers := range tlsVersions {
2218 // Assemble flags to disable all older versions on the shim.
2219 var flags []string
2220 for _, vers := range tlsVersions[:i] {
2221 flags = append(flags, vers.flag)
2222 }
2223
2224 for _, runnerVers := range tlsVersions {
2225 protocols := []protocol{tls}
2226 if runnerVers.hasDTLS && shimVers.hasDTLS {
2227 protocols = append(protocols, dtls)
2228 }
2229 for _, protocol := range protocols {
2230 suffix := shimVers.name + "-" + runnerVers.name
2231 if protocol == dtls {
2232 suffix += "-DTLS"
2233 }
2234 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2235
David Benjaminaccb4542014-12-12 23:44:33 -05002236 var expectedVersion uint16
2237 var shouldFail bool
2238 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05002239 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05002240 if runnerVers.version >= shimVers.version {
2241 expectedVersion = runnerVers.version
2242 } else {
2243 shouldFail = true
2244 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05002245 if runnerVers.version > VersionSSL30 {
2246 expectedLocalError = "remote error: protocol version not supported"
2247 } else {
2248 expectedLocalError = "remote error: handshake failure"
2249 }
David Benjaminaccb4542014-12-12 23:44:33 -05002250 }
2251
2252 testCases = append(testCases, testCase{
2253 protocol: protocol,
2254 testType: clientTest,
2255 name: "MinimumVersion-Client-" + suffix,
2256 config: Config{
2257 MaxVersion: runnerVers.version,
2258 },
David Benjamin87909c02014-12-13 01:55:01 -05002259 flags: flags,
2260 expectedVersion: expectedVersion,
2261 shouldFail: shouldFail,
2262 expectedError: expectedError,
2263 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002264 })
2265 testCases = append(testCases, testCase{
2266 protocol: protocol,
2267 testType: clientTest,
2268 name: "MinimumVersion-Client2-" + suffix,
2269 config: Config{
2270 MaxVersion: runnerVers.version,
2271 },
David Benjamin87909c02014-12-13 01:55:01 -05002272 flags: []string{"-min-version", shimVersFlag},
2273 expectedVersion: expectedVersion,
2274 shouldFail: shouldFail,
2275 expectedError: expectedError,
2276 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002277 })
2278
2279 testCases = append(testCases, testCase{
2280 protocol: protocol,
2281 testType: serverTest,
2282 name: "MinimumVersion-Server-" + suffix,
2283 config: Config{
2284 MaxVersion: runnerVers.version,
2285 },
David Benjamin87909c02014-12-13 01:55:01 -05002286 flags: flags,
2287 expectedVersion: expectedVersion,
2288 shouldFail: shouldFail,
2289 expectedError: expectedError,
2290 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002291 })
2292 testCases = append(testCases, testCase{
2293 protocol: protocol,
2294 testType: serverTest,
2295 name: "MinimumVersion-Server2-" + suffix,
2296 config: Config{
2297 MaxVersion: runnerVers.version,
2298 },
David Benjamin87909c02014-12-13 01:55:01 -05002299 flags: []string{"-min-version", shimVersFlag},
2300 expectedVersion: expectedVersion,
2301 shouldFail: shouldFail,
2302 expectedError: expectedError,
2303 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002304 })
2305 }
2306 }
2307 }
2308}
2309
David Benjamin5c24a1d2014-08-31 00:59:27 -04002310func addD5BugTests() {
2311 testCases = append(testCases, testCase{
2312 testType: serverTest,
2313 name: "D5Bug-NoQuirk-Reject",
2314 config: Config{
2315 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2316 Bugs: ProtocolBugs{
2317 SSL3RSAKeyExchange: true,
2318 },
2319 },
2320 shouldFail: true,
2321 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
2322 })
2323 testCases = append(testCases, testCase{
2324 testType: serverTest,
2325 name: "D5Bug-Quirk-Normal",
2326 config: Config{
2327 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2328 },
2329 flags: []string{"-tls-d5-bug"},
2330 })
2331 testCases = append(testCases, testCase{
2332 testType: serverTest,
2333 name: "D5Bug-Quirk-Bug",
2334 config: Config{
2335 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2336 Bugs: ProtocolBugs{
2337 SSL3RSAKeyExchange: true,
2338 },
2339 },
2340 flags: []string{"-tls-d5-bug"},
2341 })
2342}
2343
David Benjamine78bfde2014-09-06 12:45:15 -04002344func addExtensionTests() {
2345 testCases = append(testCases, testCase{
2346 testType: clientTest,
2347 name: "DuplicateExtensionClient",
2348 config: Config{
2349 Bugs: ProtocolBugs{
2350 DuplicateExtension: true,
2351 },
2352 },
2353 shouldFail: true,
2354 expectedLocalError: "remote error: error decoding message",
2355 })
2356 testCases = append(testCases, testCase{
2357 testType: serverTest,
2358 name: "DuplicateExtensionServer",
2359 config: Config{
2360 Bugs: ProtocolBugs{
2361 DuplicateExtension: true,
2362 },
2363 },
2364 shouldFail: true,
2365 expectedLocalError: "remote error: error decoding message",
2366 })
2367 testCases = append(testCases, testCase{
2368 testType: clientTest,
2369 name: "ServerNameExtensionClient",
2370 config: Config{
2371 Bugs: ProtocolBugs{
2372 ExpectServerName: "example.com",
2373 },
2374 },
2375 flags: []string{"-host-name", "example.com"},
2376 })
2377 testCases = append(testCases, testCase{
2378 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05002379 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04002380 config: Config{
2381 Bugs: ProtocolBugs{
2382 ExpectServerName: "mismatch.com",
2383 },
2384 },
2385 flags: []string{"-host-name", "example.com"},
2386 shouldFail: true,
2387 expectedLocalError: "tls: unexpected server name",
2388 })
2389 testCases = append(testCases, testCase{
2390 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05002391 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04002392 config: Config{
2393 Bugs: ProtocolBugs{
2394 ExpectServerName: "missing.com",
2395 },
2396 },
2397 shouldFail: true,
2398 expectedLocalError: "tls: unexpected server name",
2399 })
2400 testCases = append(testCases, testCase{
2401 testType: serverTest,
2402 name: "ServerNameExtensionServer",
2403 config: Config{
2404 ServerName: "example.com",
2405 },
2406 flags: []string{"-expect-server-name", "example.com"},
2407 resumeSession: true,
2408 })
David Benjaminae2888f2014-09-06 12:58:58 -04002409 testCases = append(testCases, testCase{
2410 testType: clientTest,
2411 name: "ALPNClient",
2412 config: Config{
2413 NextProtos: []string{"foo"},
2414 },
2415 flags: []string{
2416 "-advertise-alpn", "\x03foo\x03bar\x03baz",
2417 "-expect-alpn", "foo",
2418 },
David Benjaminfc7b0862014-09-06 13:21:53 -04002419 expectedNextProto: "foo",
2420 expectedNextProtoType: alpn,
2421 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04002422 })
2423 testCases = append(testCases, testCase{
2424 testType: serverTest,
2425 name: "ALPNServer",
2426 config: Config{
2427 NextProtos: []string{"foo", "bar", "baz"},
2428 },
2429 flags: []string{
2430 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2431 "-select-alpn", "foo",
2432 },
David Benjaminfc7b0862014-09-06 13:21:53 -04002433 expectedNextProto: "foo",
2434 expectedNextProtoType: alpn,
2435 resumeSession: true,
2436 })
2437 // Test that the server prefers ALPN over NPN.
2438 testCases = append(testCases, testCase{
2439 testType: serverTest,
2440 name: "ALPNServer-Preferred",
2441 config: Config{
2442 NextProtos: []string{"foo", "bar", "baz"},
2443 },
2444 flags: []string{
2445 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2446 "-select-alpn", "foo",
2447 "-advertise-npn", "\x03foo\x03bar\x03baz",
2448 },
2449 expectedNextProto: "foo",
2450 expectedNextProtoType: alpn,
2451 resumeSession: true,
2452 })
2453 testCases = append(testCases, testCase{
2454 testType: serverTest,
2455 name: "ALPNServer-Preferred-Swapped",
2456 config: Config{
2457 NextProtos: []string{"foo", "bar", "baz"},
2458 Bugs: ProtocolBugs{
2459 SwapNPNAndALPN: true,
2460 },
2461 },
2462 flags: []string{
2463 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2464 "-select-alpn", "foo",
2465 "-advertise-npn", "\x03foo\x03bar\x03baz",
2466 },
2467 expectedNextProto: "foo",
2468 expectedNextProtoType: alpn,
2469 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04002470 })
Adam Langley38311732014-10-16 19:04:35 -07002471 // Resume with a corrupt ticket.
2472 testCases = append(testCases, testCase{
2473 testType: serverTest,
2474 name: "CorruptTicket",
2475 config: Config{
2476 Bugs: ProtocolBugs{
2477 CorruptTicket: true,
2478 },
2479 },
2480 resumeSession: true,
2481 flags: []string{"-expect-session-miss"},
2482 })
2483 // Resume with an oversized session id.
2484 testCases = append(testCases, testCase{
2485 testType: serverTest,
2486 name: "OversizedSessionId",
2487 config: Config{
2488 Bugs: ProtocolBugs{
2489 OversizedSessionId: true,
2490 },
2491 },
2492 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07002493 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07002494 expectedError: ":DECODE_ERROR:",
2495 })
David Benjaminca6c8262014-11-15 19:06:08 -05002496 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
2497 // are ignored.
2498 testCases = append(testCases, testCase{
2499 protocol: dtls,
2500 name: "SRTP-Client",
2501 config: Config{
2502 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
2503 },
2504 flags: []string{
2505 "-srtp-profiles",
2506 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2507 },
2508 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
2509 })
2510 testCases = append(testCases, testCase{
2511 protocol: dtls,
2512 testType: serverTest,
2513 name: "SRTP-Server",
2514 config: Config{
2515 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
2516 },
2517 flags: []string{
2518 "-srtp-profiles",
2519 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2520 },
2521 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
2522 })
2523 // Test that the MKI is ignored.
2524 testCases = append(testCases, testCase{
2525 protocol: dtls,
2526 testType: serverTest,
2527 name: "SRTP-Server-IgnoreMKI",
2528 config: Config{
2529 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
2530 Bugs: ProtocolBugs{
2531 SRTPMasterKeyIdentifer: "bogus",
2532 },
2533 },
2534 flags: []string{
2535 "-srtp-profiles",
2536 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2537 },
2538 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
2539 })
2540 // Test that SRTP isn't negotiated on the server if there were
2541 // no matching profiles.
2542 testCases = append(testCases, testCase{
2543 protocol: dtls,
2544 testType: serverTest,
2545 name: "SRTP-Server-NoMatch",
2546 config: Config{
2547 SRTPProtectionProfiles: []uint16{100, 101, 102},
2548 },
2549 flags: []string{
2550 "-srtp-profiles",
2551 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2552 },
2553 expectedSRTPProtectionProfile: 0,
2554 })
2555 // Test that the server returning an invalid SRTP profile is
2556 // flagged as an error by the client.
2557 testCases = append(testCases, testCase{
2558 protocol: dtls,
2559 name: "SRTP-Client-NoMatch",
2560 config: Config{
2561 Bugs: ProtocolBugs{
2562 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
2563 },
2564 },
2565 flags: []string{
2566 "-srtp-profiles",
2567 "SRTP_AES128_CM_SHA1_80",
2568 },
2569 shouldFail: true,
2570 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
2571 })
David Benjamin61f95272014-11-25 01:55:35 -05002572 // Test OCSP stapling and SCT list.
2573 testCases = append(testCases, testCase{
2574 name: "OCSPStapling",
2575 flags: []string{
2576 "-enable-ocsp-stapling",
2577 "-expect-ocsp-response",
2578 base64.StdEncoding.EncodeToString(testOCSPResponse),
2579 },
2580 })
2581 testCases = append(testCases, testCase{
2582 name: "SignedCertificateTimestampList",
2583 flags: []string{
2584 "-enable-signed-cert-timestamps",
2585 "-expect-signed-cert-timestamps",
2586 base64.StdEncoding.EncodeToString(testSCTList),
2587 },
2588 })
David Benjamine78bfde2014-09-06 12:45:15 -04002589}
2590
David Benjamin01fe8202014-09-24 15:21:44 -04002591func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04002592 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04002593 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002594 protocols := []protocol{tls}
2595 if sessionVers.hasDTLS && resumeVers.hasDTLS {
2596 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05002597 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002598 for _, protocol := range protocols {
2599 suffix := "-" + sessionVers.name + "-" + resumeVers.name
2600 if protocol == dtls {
2601 suffix += "-DTLS"
2602 }
2603
2604 testCases = append(testCases, testCase{
2605 protocol: protocol,
2606 name: "Resume-Client" + suffix,
2607 resumeSession: true,
2608 config: Config{
2609 MaxVersion: sessionVers.version,
2610 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2611 Bugs: ProtocolBugs{
2612 AllowSessionVersionMismatch: true,
2613 },
2614 },
2615 expectedVersion: sessionVers.version,
2616 resumeConfig: &Config{
2617 MaxVersion: resumeVers.version,
2618 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2619 Bugs: ProtocolBugs{
2620 AllowSessionVersionMismatch: true,
2621 },
2622 },
2623 expectedResumeVersion: resumeVers.version,
2624 })
2625
2626 testCases = append(testCases, testCase{
2627 protocol: protocol,
2628 name: "Resume-Client-NoResume" + suffix,
2629 flags: []string{"-expect-session-miss"},
2630 resumeSession: true,
2631 config: Config{
2632 MaxVersion: sessionVers.version,
2633 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2634 },
2635 expectedVersion: sessionVers.version,
2636 resumeConfig: &Config{
2637 MaxVersion: resumeVers.version,
2638 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2639 },
2640 newSessionsOnResume: true,
2641 expectedResumeVersion: resumeVers.version,
2642 })
2643
2644 var flags []string
2645 if sessionVers.version != resumeVers.version {
2646 flags = append(flags, "-expect-session-miss")
2647 }
2648 testCases = append(testCases, testCase{
2649 protocol: protocol,
2650 testType: serverTest,
2651 name: "Resume-Server" + suffix,
2652 flags: flags,
2653 resumeSession: true,
2654 config: Config{
2655 MaxVersion: sessionVers.version,
2656 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2657 },
2658 expectedVersion: sessionVers.version,
2659 resumeConfig: &Config{
2660 MaxVersion: resumeVers.version,
2661 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2662 },
2663 expectedResumeVersion: resumeVers.version,
2664 })
2665 }
David Benjamin01fe8202014-09-24 15:21:44 -04002666 }
2667 }
2668}
2669
Adam Langley2ae77d22014-10-28 17:29:33 -07002670func addRenegotiationTests() {
2671 testCases = append(testCases, testCase{
2672 testType: serverTest,
2673 name: "Renegotiate-Server",
2674 flags: []string{"-renegotiate"},
2675 shimWritesFirst: true,
2676 })
2677 testCases = append(testCases, testCase{
2678 testType: serverTest,
David Benjamincdea40c2015-03-19 14:09:43 -04002679 name: "Renegotiate-Server-Full",
2680 config: Config{
2681 Bugs: ProtocolBugs{
2682 NeverResumeOnRenego: true,
2683 },
2684 },
2685 flags: []string{"-renegotiate"},
2686 shimWritesFirst: true,
2687 })
2688 testCases = append(testCases, testCase{
2689 testType: serverTest,
Adam Langley2ae77d22014-10-28 17:29:33 -07002690 name: "Renegotiate-Server-EmptyExt",
2691 config: Config{
2692 Bugs: ProtocolBugs{
2693 EmptyRenegotiationInfo: true,
2694 },
2695 },
2696 flags: []string{"-renegotiate"},
2697 shimWritesFirst: true,
2698 shouldFail: true,
2699 expectedError: ":RENEGOTIATION_MISMATCH:",
2700 })
2701 testCases = append(testCases, testCase{
2702 testType: serverTest,
2703 name: "Renegotiate-Server-BadExt",
2704 config: Config{
2705 Bugs: ProtocolBugs{
2706 BadRenegotiationInfo: true,
2707 },
2708 },
2709 flags: []string{"-renegotiate"},
2710 shimWritesFirst: true,
2711 shouldFail: true,
2712 expectedError: ":RENEGOTIATION_MISMATCH:",
2713 })
David Benjaminca6554b2014-11-08 12:31:52 -05002714 testCases = append(testCases, testCase{
2715 testType: serverTest,
2716 name: "Renegotiate-Server-ClientInitiated",
2717 renegotiate: true,
2718 })
2719 testCases = append(testCases, testCase{
2720 testType: serverTest,
2721 name: "Renegotiate-Server-ClientInitiated-NoExt",
2722 renegotiate: true,
2723 config: Config{
2724 Bugs: ProtocolBugs{
2725 NoRenegotiationInfo: true,
2726 },
2727 },
2728 shouldFail: true,
2729 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
2730 })
2731 testCases = append(testCases, testCase{
2732 testType: serverTest,
2733 name: "Renegotiate-Server-ClientInitiated-NoExt-Allowed",
2734 renegotiate: true,
2735 config: Config{
2736 Bugs: ProtocolBugs{
2737 NoRenegotiationInfo: true,
2738 },
2739 },
2740 flags: []string{"-allow-unsafe-legacy-renegotiation"},
2741 })
David Benjamin3c9746a2015-03-19 15:00:10 -04002742 // Regression test for CVE-2015-0291.
2743 testCases = append(testCases, testCase{
2744 testType: serverTest,
2745 name: "Renegotiate-Server-NoSignatureAlgorithms",
2746 config: Config{
2747 Bugs: ProtocolBugs{
2748 NeverResumeOnRenego: true,
2749 NoSignatureAlgorithmsOnRenego: true,
2750 },
2751 },
2752 flags: []string{"-renegotiate"},
2753 shimWritesFirst: true,
2754 })
Adam Langley2ae77d22014-10-28 17:29:33 -07002755 // TODO(agl): test the renegotiation info SCSV.
Adam Langleycf2d4f42014-10-28 19:06:14 -07002756 testCases = append(testCases, testCase{
2757 name: "Renegotiate-Client",
2758 renegotiate: true,
2759 })
2760 testCases = append(testCases, testCase{
David Benjamincdea40c2015-03-19 14:09:43 -04002761 name: "Renegotiate-Client-Full",
2762 config: Config{
2763 Bugs: ProtocolBugs{
2764 NeverResumeOnRenego: true,
2765 },
2766 },
2767 renegotiate: true,
2768 })
2769 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07002770 name: "Renegotiate-Client-EmptyExt",
2771 renegotiate: true,
2772 config: Config{
2773 Bugs: ProtocolBugs{
2774 EmptyRenegotiationInfo: true,
2775 },
2776 },
2777 shouldFail: true,
2778 expectedError: ":RENEGOTIATION_MISMATCH:",
2779 })
2780 testCases = append(testCases, testCase{
2781 name: "Renegotiate-Client-BadExt",
2782 renegotiate: true,
2783 config: Config{
2784 Bugs: ProtocolBugs{
2785 BadRenegotiationInfo: true,
2786 },
2787 },
2788 shouldFail: true,
2789 expectedError: ":RENEGOTIATION_MISMATCH:",
2790 })
2791 testCases = append(testCases, testCase{
2792 name: "Renegotiate-Client-SwitchCiphers",
2793 renegotiate: true,
2794 config: Config{
2795 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2796 },
2797 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2798 })
2799 testCases = append(testCases, testCase{
2800 name: "Renegotiate-Client-SwitchCiphers2",
2801 renegotiate: true,
2802 config: Config{
2803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2804 },
2805 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2806 })
David Benjaminc44b1df2014-11-23 12:11:01 -05002807 testCases = append(testCases, testCase{
2808 name: "Renegotiate-SameClientVersion",
2809 renegotiate: true,
2810 config: Config{
2811 MaxVersion: VersionTLS10,
2812 Bugs: ProtocolBugs{
2813 RequireSameRenegoClientVersion: true,
2814 },
2815 },
2816 })
Adam Langley2ae77d22014-10-28 17:29:33 -07002817}
2818
David Benjamin5e961c12014-11-07 01:48:35 -05002819func addDTLSReplayTests() {
2820 // Test that sequence number replays are detected.
2821 testCases = append(testCases, testCase{
2822 protocol: dtls,
2823 name: "DTLS-Replay",
2824 replayWrites: true,
2825 })
2826
2827 // Test the outgoing sequence number skipping by values larger
2828 // than the retransmit window.
2829 testCases = append(testCases, testCase{
2830 protocol: dtls,
2831 name: "DTLS-Replay-LargeGaps",
2832 config: Config{
2833 Bugs: ProtocolBugs{
2834 SequenceNumberIncrement: 127,
2835 },
2836 },
2837 replayWrites: true,
2838 })
2839}
2840
Feng Lu41aa3252014-11-21 22:47:56 -08002841func addFastRadioPaddingTests() {
David Benjamin1e29a6b2014-12-10 02:27:24 -05002842 testCases = append(testCases, testCase{
2843 protocol: tls,
2844 name: "FastRadio-Padding",
Feng Lu41aa3252014-11-21 22:47:56 -08002845 config: Config{
2846 Bugs: ProtocolBugs{
2847 RequireFastradioPadding: true,
2848 },
2849 },
David Benjamin1e29a6b2014-12-10 02:27:24 -05002850 flags: []string{"-fastradio-padding"},
Feng Lu41aa3252014-11-21 22:47:56 -08002851 })
David Benjamin1e29a6b2014-12-10 02:27:24 -05002852 testCases = append(testCases, testCase{
2853 protocol: dtls,
David Benjamin5f237bc2015-02-11 17:14:15 -05002854 name: "FastRadio-Padding-DTLS",
Feng Lu41aa3252014-11-21 22:47:56 -08002855 config: Config{
2856 Bugs: ProtocolBugs{
2857 RequireFastradioPadding: true,
2858 },
2859 },
David Benjamin1e29a6b2014-12-10 02:27:24 -05002860 flags: []string{"-fastradio-padding"},
Feng Lu41aa3252014-11-21 22:47:56 -08002861 })
2862}
2863
David Benjamin000800a2014-11-14 01:43:59 -05002864var testHashes = []struct {
2865 name string
2866 id uint8
2867}{
2868 {"SHA1", hashSHA1},
2869 {"SHA224", hashSHA224},
2870 {"SHA256", hashSHA256},
2871 {"SHA384", hashSHA384},
2872 {"SHA512", hashSHA512},
2873}
2874
2875func addSigningHashTests() {
2876 // Make sure each hash works. Include some fake hashes in the list and
2877 // ensure they're ignored.
2878 for _, hash := range testHashes {
2879 testCases = append(testCases, testCase{
2880 name: "SigningHash-ClientAuth-" + hash.name,
2881 config: Config{
2882 ClientAuth: RequireAnyClientCert,
2883 SignatureAndHashes: []signatureAndHash{
2884 {signatureRSA, 42},
2885 {signatureRSA, hash.id},
2886 {signatureRSA, 255},
2887 },
2888 },
2889 flags: []string{
2890 "-cert-file", rsaCertificateFile,
2891 "-key-file", rsaKeyFile,
2892 },
2893 })
2894
2895 testCases = append(testCases, testCase{
2896 testType: serverTest,
2897 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
2898 config: Config{
2899 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2900 SignatureAndHashes: []signatureAndHash{
2901 {signatureRSA, 42},
2902 {signatureRSA, hash.id},
2903 {signatureRSA, 255},
2904 },
2905 },
2906 })
2907 }
2908
2909 // Test that hash resolution takes the signature type into account.
2910 testCases = append(testCases, testCase{
2911 name: "SigningHash-ClientAuth-SignatureType",
2912 config: Config{
2913 ClientAuth: RequireAnyClientCert,
2914 SignatureAndHashes: []signatureAndHash{
2915 {signatureECDSA, hashSHA512},
2916 {signatureRSA, hashSHA384},
2917 {signatureECDSA, hashSHA1},
2918 },
2919 },
2920 flags: []string{
2921 "-cert-file", rsaCertificateFile,
2922 "-key-file", rsaKeyFile,
2923 },
2924 })
2925
2926 testCases = append(testCases, testCase{
2927 testType: serverTest,
2928 name: "SigningHash-ServerKeyExchange-SignatureType",
2929 config: Config{
2930 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2931 SignatureAndHashes: []signatureAndHash{
2932 {signatureECDSA, hashSHA512},
2933 {signatureRSA, hashSHA384},
2934 {signatureECDSA, hashSHA1},
2935 },
2936 },
2937 })
2938
2939 // Test that, if the list is missing, the peer falls back to SHA-1.
2940 testCases = append(testCases, testCase{
2941 name: "SigningHash-ClientAuth-Fallback",
2942 config: Config{
2943 ClientAuth: RequireAnyClientCert,
2944 SignatureAndHashes: []signatureAndHash{
2945 {signatureRSA, hashSHA1},
2946 },
2947 Bugs: ProtocolBugs{
2948 NoSignatureAndHashes: true,
2949 },
2950 },
2951 flags: []string{
2952 "-cert-file", rsaCertificateFile,
2953 "-key-file", rsaKeyFile,
2954 },
2955 })
2956
2957 testCases = append(testCases, testCase{
2958 testType: serverTest,
2959 name: "SigningHash-ServerKeyExchange-Fallback",
2960 config: Config{
2961 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2962 SignatureAndHashes: []signatureAndHash{
2963 {signatureRSA, hashSHA1},
2964 },
2965 Bugs: ProtocolBugs{
2966 NoSignatureAndHashes: true,
2967 },
2968 },
2969 })
David Benjamin72dc7832015-03-16 17:49:43 -04002970
2971 // Test that hash preferences are enforced. BoringSSL defaults to
2972 // rejecting MD5 signatures.
2973 testCases = append(testCases, testCase{
2974 testType: serverTest,
2975 name: "SigningHash-ClientAuth-Enforced",
2976 config: Config{
2977 Certificates: []Certificate{rsaCertificate},
2978 SignatureAndHashes: []signatureAndHash{
2979 {signatureRSA, hashMD5},
2980 // Advertise SHA-1 so the handshake will
2981 // proceed, but the shim's preferences will be
2982 // ignored in CertificateVerify generation, so
2983 // MD5 will be chosen.
2984 {signatureRSA, hashSHA1},
2985 },
2986 Bugs: ProtocolBugs{
2987 IgnorePeerSignatureAlgorithmPreferences: true,
2988 },
2989 },
2990 flags: []string{"-require-any-client-certificate"},
2991 shouldFail: true,
2992 expectedError: ":WRONG_SIGNATURE_TYPE:",
2993 })
2994
2995 testCases = append(testCases, testCase{
2996 name: "SigningHash-ServerKeyExchange-Enforced",
2997 config: Config{
2998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2999 SignatureAndHashes: []signatureAndHash{
3000 {signatureRSA, hashMD5},
3001 },
3002 Bugs: ProtocolBugs{
3003 IgnorePeerSignatureAlgorithmPreferences: true,
3004 },
3005 },
3006 shouldFail: true,
3007 expectedError: ":WRONG_SIGNATURE_TYPE:",
3008 })
David Benjamin000800a2014-11-14 01:43:59 -05003009}
3010
David Benjamin83f90402015-01-27 01:09:43 -05003011// timeouts is the retransmit schedule for BoringSSL. It doubles and
3012// caps at 60 seconds. On the 13th timeout, it gives up.
3013var timeouts = []time.Duration{
3014 1 * time.Second,
3015 2 * time.Second,
3016 4 * time.Second,
3017 8 * time.Second,
3018 16 * time.Second,
3019 32 * time.Second,
3020 60 * time.Second,
3021 60 * time.Second,
3022 60 * time.Second,
3023 60 * time.Second,
3024 60 * time.Second,
3025 60 * time.Second,
3026 60 * time.Second,
3027}
3028
3029func addDTLSRetransmitTests() {
3030 // Test that this is indeed the timeout schedule. Stress all
3031 // four patterns of handshake.
3032 for i := 1; i < len(timeouts); i++ {
3033 number := strconv.Itoa(i)
3034 testCases = append(testCases, testCase{
3035 protocol: dtls,
3036 name: "DTLS-Retransmit-Client-" + number,
3037 config: Config{
3038 Bugs: ProtocolBugs{
3039 TimeoutSchedule: timeouts[:i],
3040 },
3041 },
3042 resumeSession: true,
3043 flags: []string{"-async"},
3044 })
3045 testCases = append(testCases, testCase{
3046 protocol: dtls,
3047 testType: serverTest,
3048 name: "DTLS-Retransmit-Server-" + number,
3049 config: Config{
3050 Bugs: ProtocolBugs{
3051 TimeoutSchedule: timeouts[:i],
3052 },
3053 },
3054 resumeSession: true,
3055 flags: []string{"-async"},
3056 })
3057 }
3058
3059 // Test that exceeding the timeout schedule hits a read
3060 // timeout.
3061 testCases = append(testCases, testCase{
3062 protocol: dtls,
3063 name: "DTLS-Retransmit-Timeout",
3064 config: Config{
3065 Bugs: ProtocolBugs{
3066 TimeoutSchedule: timeouts,
3067 },
3068 },
3069 resumeSession: true,
3070 flags: []string{"-async"},
3071 shouldFail: true,
3072 expectedError: ":READ_TIMEOUT_EXPIRED:",
3073 })
3074
3075 // Test that timeout handling has a fudge factor, due to API
3076 // problems.
3077 testCases = append(testCases, testCase{
3078 protocol: dtls,
3079 name: "DTLS-Retransmit-Fudge",
3080 config: Config{
3081 Bugs: ProtocolBugs{
3082 TimeoutSchedule: []time.Duration{
3083 timeouts[0] - 10*time.Millisecond,
3084 },
3085 },
3086 },
3087 resumeSession: true,
3088 flags: []string{"-async"},
3089 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05003090
3091 // Test that the final Finished retransmitting isn't
3092 // duplicated if the peer badly fragments everything.
3093 testCases = append(testCases, testCase{
3094 testType: serverTest,
3095 protocol: dtls,
3096 name: "DTLS-Retransmit-Fragmented",
3097 config: Config{
3098 Bugs: ProtocolBugs{
3099 TimeoutSchedule: []time.Duration{timeouts[0]},
3100 MaxHandshakeRecordLength: 2,
3101 },
3102 },
3103 flags: []string{"-async"},
3104 })
David Benjamin83f90402015-01-27 01:09:43 -05003105}
3106
David Benjamin884fdf12014-08-02 15:28:23 -04003107func worker(statusChan chan statusMsg, c chan *testCase, buildDir string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07003108 defer wg.Done()
3109
3110 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08003111 var err error
3112
3113 if *mallocTest < 0 {
3114 statusChan <- statusMsg{test: test, started: true}
3115 err = runTest(test, buildDir, -1)
3116 } else {
3117 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
3118 statusChan <- statusMsg{test: test, started: true}
3119 if err = runTest(test, buildDir, mallocNumToFail); err != errMoreMallocs {
3120 if err != nil {
3121 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
3122 }
3123 break
3124 }
3125 }
3126 }
Adam Langley95c29f32014-06-20 12:00:00 -07003127 statusChan <- statusMsg{test: test, err: err}
3128 }
3129}
3130
3131type statusMsg struct {
3132 test *testCase
3133 started bool
3134 err error
3135}
3136
David Benjamin5f237bc2015-02-11 17:14:15 -05003137func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07003138 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07003139
David Benjamin5f237bc2015-02-11 17:14:15 -05003140 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07003141 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05003142 if !*pipe {
3143 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05003144 var erase string
3145 for i := 0; i < lineLen; i++ {
3146 erase += "\b \b"
3147 }
3148 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05003149 }
3150
Adam Langley95c29f32014-06-20 12:00:00 -07003151 if msg.started {
3152 started++
3153 } else {
3154 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05003155
3156 if msg.err != nil {
3157 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
3158 failed++
3159 testOutput.addResult(msg.test.name, "FAIL")
3160 } else {
3161 if *pipe {
3162 // Print each test instead of a status line.
3163 fmt.Printf("PASSED (%s)\n", msg.test.name)
3164 }
3165 testOutput.addResult(msg.test.name, "PASS")
3166 }
Adam Langley95c29f32014-06-20 12:00:00 -07003167 }
3168
David Benjamin5f237bc2015-02-11 17:14:15 -05003169 if !*pipe {
3170 // Print a new status line.
3171 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
3172 lineLen = len(line)
3173 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07003174 }
Adam Langley95c29f32014-06-20 12:00:00 -07003175 }
David Benjamin5f237bc2015-02-11 17:14:15 -05003176
3177 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07003178}
3179
3180func main() {
3181 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 -04003182 var flagNumWorkers *int = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
David Benjamin884fdf12014-08-02 15:28:23 -04003183 var flagBuildDir *string = flag.String("build-dir", "../../../build", "The build directory to run the shim from.")
Adam Langley95c29f32014-06-20 12:00:00 -07003184
3185 flag.Parse()
3186
3187 addCipherSuiteTests()
3188 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07003189 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07003190 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04003191 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08003192 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003193 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05003194 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04003195 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04003196 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04003197 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07003198 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07003199 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05003200 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05003201 addSigningHashTests()
Feng Lu41aa3252014-11-21 22:47:56 -08003202 addFastRadioPaddingTests()
David Benjamin83f90402015-01-27 01:09:43 -05003203 addDTLSRetransmitTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04003204 for _, async := range []bool{false, true} {
3205 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04003206 for _, protocol := range []protocol{tls, dtls} {
3207 addStateMachineCoverageTests(async, splitHandshake, protocol)
3208 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003209 }
3210 }
Adam Langley95c29f32014-06-20 12:00:00 -07003211
3212 var wg sync.WaitGroup
3213
David Benjamin2bc8e6f2014-08-02 15:22:37 -04003214 numWorkers := *flagNumWorkers
Adam Langley95c29f32014-06-20 12:00:00 -07003215
3216 statusChan := make(chan statusMsg, numWorkers)
3217 testChan := make(chan *testCase, numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05003218 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07003219
David Benjamin025b3d32014-07-01 19:53:04 -04003220 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07003221
3222 for i := 0; i < numWorkers; i++ {
3223 wg.Add(1)
David Benjamin884fdf12014-08-02 15:28:23 -04003224 go worker(statusChan, testChan, *flagBuildDir, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07003225 }
3226
David Benjamin025b3d32014-07-01 19:53:04 -04003227 for i := range testCases {
3228 if len(*flagTest) == 0 || *flagTest == testCases[i].name {
3229 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07003230 }
3231 }
3232
3233 close(testChan)
3234 wg.Wait()
3235 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05003236 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07003237
3238 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05003239
3240 if *jsonOutput != "" {
3241 if err := testOutput.writeTo(*jsonOutput); err != nil {
3242 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
3243 }
3244 }
Adam Langley95c29f32014-06-20 12:00:00 -07003245}