blob: f02a2218f279d44bc592fb6ccd7ffb21d8b6f069 [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 Langleya7997f12015-05-14 17:38:50 -070014 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070015 "net"
16 "os"
17 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040018 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040019 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080020 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070021 "strings"
22 "sync"
23 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050024 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070025)
26
Adam Langley69a01602014-11-17 17:26:55 -080027var (
David Benjamin5f237bc2015-02-11 17:14:15 -050028 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
29 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
30 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
31 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
32 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.")
33 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
34 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley69a01602014-11-17 17:26:55 -080035)
Adam Langley95c29f32014-06-20 12:00:00 -070036
David Benjamin025b3d32014-07-01 19:53:04 -040037const (
38 rsaCertificateFile = "cert.pem"
39 ecdsaCertificateFile = "ecdsa_cert.pem"
40)
41
42const (
David Benjamina08e49d2014-08-24 01:46:07 -040043 rsaKeyFile = "key.pem"
44 ecdsaKeyFile = "ecdsa_key.pem"
45 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040046)
47
Adam Langley95c29f32014-06-20 12:00:00 -070048var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040049var channelIDKey *ecdsa.PrivateKey
50var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070051
David Benjamin61f95272014-11-25 01:55:35 -050052var testOCSPResponse = []byte{1, 2, 3, 4}
53var testSCTList = []byte{5, 6, 7, 8}
54
Adam Langley95c29f32014-06-20 12:00:00 -070055func initCertificates() {
56 var err error
David Benjamin025b3d32014-07-01 19:53:04 -040057 rsaCertificate, err = LoadX509KeyPair(rsaCertificateFile, rsaKeyFile)
Adam Langley95c29f32014-06-20 12:00:00 -070058 if err != nil {
59 panic(err)
60 }
David Benjamin61f95272014-11-25 01:55:35 -050061 rsaCertificate.OCSPStaple = testOCSPResponse
62 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070063
David Benjamin025b3d32014-07-01 19:53:04 -040064 ecdsaCertificate, err = LoadX509KeyPair(ecdsaCertificateFile, ecdsaKeyFile)
Adam Langley95c29f32014-06-20 12:00:00 -070065 if err != nil {
66 panic(err)
67 }
David Benjamin61f95272014-11-25 01:55:35 -050068 ecdsaCertificate.OCSPStaple = testOCSPResponse
69 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040070
71 channelIDPEMBlock, err := ioutil.ReadFile(channelIDKeyFile)
72 if err != nil {
73 panic(err)
74 }
75 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
76 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
77 panic("bad key type")
78 }
79 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
80 if err != nil {
81 panic(err)
82 }
83 if channelIDKey.Curve != elliptic.P256() {
84 panic("bad curve")
85 }
86
87 channelIDBytes = make([]byte, 64)
88 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
89 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -070090}
91
92var certificateOnce sync.Once
93
94func getRSACertificate() Certificate {
95 certificateOnce.Do(initCertificates)
96 return rsaCertificate
97}
98
99func getECDSACertificate() Certificate {
100 certificateOnce.Do(initCertificates)
101 return ecdsaCertificate
102}
103
David Benjamin025b3d32014-07-01 19:53:04 -0400104type testType int
105
106const (
107 clientTest testType = iota
108 serverTest
109)
110
David Benjamin6fd297b2014-08-11 18:43:38 -0400111type protocol int
112
113const (
114 tls protocol = iota
115 dtls
116)
117
David Benjaminfc7b0862014-09-06 13:21:53 -0400118const (
119 alpn = 1
120 npn = 2
121)
122
Adam Langley95c29f32014-06-20 12:00:00 -0700123type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400124 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400125 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700126 name string
127 config Config
128 shouldFail bool
129 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700130 // expectedLocalError, if not empty, contains a substring that must be
131 // found in the local error.
132 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400133 // expectedVersion, if non-zero, specifies the TLS version that must be
134 // negotiated.
135 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400136 // expectedResumeVersion, if non-zero, specifies the TLS version that
137 // must be negotiated on resumption. If zero, expectedVersion is used.
138 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400139 // expectedCipher, if non-zero, specifies the TLS cipher suite that
140 // should be negotiated.
141 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400142 // expectChannelID controls whether the connection should have
143 // negotiated a Channel ID with channelIDKey.
144 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400145 // expectedNextProto controls whether the connection should
146 // negotiate a next protocol via NPN or ALPN.
147 expectedNextProto string
David Benjaminfc7b0862014-09-06 13:21:53 -0400148 // expectedNextProtoType, if non-zero, is the expected next
149 // protocol negotiation mechanism.
150 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500151 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
152 // should be negotiated. If zero, none should be negotiated.
153 expectedSRTPProtectionProfile uint16
Adam Langley80842bd2014-06-20 12:00:00 -0700154 // messageLen is the length, in bytes, of the test message that will be
155 // sent.
156 messageLen int
David Benjamin025b3d32014-07-01 19:53:04 -0400157 // certFile is the path to the certificate to use for the server.
158 certFile string
159 // keyFile is the path to the private key to use for the server.
160 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400161 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400162 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400163 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700164 // expectResumeRejected, if true, specifies that the attempted
165 // resumption must be rejected by the client. This is only valid for a
166 // serverTest.
167 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400168 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500169 // resumption. Unless newSessionsOnResume is set,
170 // SessionTicketKey, ServerSessionCache, and
171 // ClientSessionCache are copied from the initial connection's
172 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400173 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500174 // newSessionsOnResume, if true, will cause resumeConfig to
175 // use a different session resumption context.
176 newSessionsOnResume bool
David Benjamin98e882e2014-08-08 13:24:34 -0400177 // sendPrefix sends a prefix on the socket before actually performing a
178 // handshake.
179 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400180 // shimWritesFirst controls whether the shim sends an initial "hello"
181 // message before doing a roundtrip with the runner.
182 shimWritesFirst bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700183 // renegotiate indicates the the connection should be renegotiated
184 // during the exchange.
185 renegotiate bool
186 // renegotiateCiphers is a list of ciphersuite ids that will be
187 // switched in just before renegotiation.
188 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500189 // replayWrites, if true, configures the underlying transport
190 // to replay every write it makes in DTLS tests.
191 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500192 // damageFirstWrite, if true, configures the underlying transport to
193 // damage the final byte of the first application data write.
194 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400195 // exportKeyingMaterial, if non-zero, configures the test to exchange
196 // keying material and verify they match.
197 exportKeyingMaterial int
198 exportLabel string
199 exportContext string
200 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400201 // flags, if not empty, contains a list of command-line flags that will
202 // be passed to the shim program.
203 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700204 // testTLSUnique, if true, causes the shim to send the tls-unique value
205 // which will be compared against the expected value.
206 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400207 // sendEmptyRecords is the number of consecutive empty records to send
208 // before and after the test message.
209 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400210 // sendWarningAlerts is the number of consecutive warning alerts to send
211 // before and after the test message.
212 sendWarningAlerts int
Adam Langley95c29f32014-06-20 12:00:00 -0700213}
214
David Benjamin025b3d32014-07-01 19:53:04 -0400215var testCases = []testCase{
Adam Langley95c29f32014-06-20 12:00:00 -0700216 {
217 name: "BadRSASignature",
218 config: Config{
219 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
220 Bugs: ProtocolBugs{
221 InvalidSKXSignature: true,
222 },
223 },
224 shouldFail: true,
David Benjamin25f08462015-04-15 16:13:49 -0400225 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -0700226 },
227 {
228 name: "BadECDSASignature",
229 config: Config{
230 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
231 Bugs: ProtocolBugs{
232 InvalidSKXSignature: true,
233 },
234 Certificates: []Certificate{getECDSACertificate()},
235 },
236 shouldFail: true,
237 expectedError: ":BAD_SIGNATURE:",
238 },
239 {
240 name: "BadECDSACurve",
241 config: Config{
242 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
243 Bugs: ProtocolBugs{
244 InvalidSKXCurve: true,
245 },
246 Certificates: []Certificate{getECDSACertificate()},
247 },
248 shouldFail: true,
249 expectedError: ":WRONG_CURVE:",
250 },
Adam Langleyac61fa32014-06-23 12:03:11 -0700251 {
David Benjamina8e3e0e2014-08-06 22:11:10 -0400252 testType: serverTest,
253 name: "BadRSAVersion",
254 config: Config{
255 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
256 Bugs: ProtocolBugs{
257 RsaClientKeyExchangeVersion: VersionTLS11,
258 },
259 },
260 shouldFail: true,
261 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
262 },
263 {
David Benjamin325b5c32014-07-01 19:40:31 -0400264 name: "NoFallbackSCSV",
Adam Langleyac61fa32014-06-23 12:03:11 -0700265 config: Config{
266 Bugs: ProtocolBugs{
267 FailIfNotFallbackSCSV: true,
268 },
269 },
270 shouldFail: true,
271 expectedLocalError: "no fallback SCSV found",
272 },
David Benjamin325b5c32014-07-01 19:40:31 -0400273 {
David Benjamin2a0c4962014-08-22 23:46:35 -0400274 name: "SendFallbackSCSV",
David Benjamin325b5c32014-07-01 19:40:31 -0400275 config: Config{
276 Bugs: ProtocolBugs{
277 FailIfNotFallbackSCSV: true,
278 },
279 },
280 flags: []string{"-fallback-scsv"},
281 },
David Benjamin197b3ab2014-07-02 18:37:33 -0400282 {
David Benjamin7b030512014-07-08 17:30:11 -0400283 name: "ClientCertificateTypes",
284 config: Config{
285 ClientAuth: RequestClientCert,
286 ClientCertificateTypes: []byte{
287 CertTypeDSSSign,
288 CertTypeRSASign,
289 CertTypeECDSASign,
290 },
291 },
David Benjamin2561dc32014-08-24 01:25:27 -0400292 flags: []string{
293 "-expect-certificate-types",
294 base64.StdEncoding.EncodeToString([]byte{
295 CertTypeDSSSign,
296 CertTypeRSASign,
297 CertTypeECDSASign,
298 }),
299 },
David Benjamin7b030512014-07-08 17:30:11 -0400300 },
David Benjamin636293b2014-07-08 17:59:18 -0400301 {
302 name: "NoClientCertificate",
303 config: Config{
304 ClientAuth: RequireAnyClientCert,
305 },
306 shouldFail: true,
307 expectedLocalError: "client didn't provide a certificate",
308 },
David Benjamin1c375dd2014-07-12 00:48:23 -0400309 {
310 name: "UnauthenticatedECDH",
311 config: Config{
312 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
313 Bugs: ProtocolBugs{
314 UnauthenticatedECDH: true,
315 },
316 },
317 shouldFail: true,
David Benjamine8f3d662014-07-12 01:10:19 -0400318 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin1c375dd2014-07-12 00:48:23 -0400319 },
David Benjamin9c651c92014-07-12 13:27:45 -0400320 {
David Benjamindcd979f2015-04-20 18:26:52 -0400321 name: "SkipCertificateStatus",
322 config: Config{
323 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
324 Bugs: ProtocolBugs{
325 SkipCertificateStatus: true,
326 },
327 },
328 flags: []string{
329 "-enable-ocsp-stapling",
330 },
331 },
332 {
David Benjamin9c651c92014-07-12 13:27:45 -0400333 name: "SkipServerKeyExchange",
334 config: Config{
335 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
336 Bugs: ProtocolBugs{
337 SkipServerKeyExchange: true,
338 },
339 },
340 shouldFail: true,
341 expectedError: ":UNEXPECTED_MESSAGE:",
342 },
David Benjamin1f5f62b2014-07-12 16:18:02 -0400343 {
David Benjamina0e52232014-07-19 17:39:58 -0400344 name: "SkipChangeCipherSpec-Client",
345 config: Config{
346 Bugs: ProtocolBugs{
347 SkipChangeCipherSpec: true,
348 },
349 },
350 shouldFail: true,
David Benjamin86271ee2014-07-21 16:14:03 -0400351 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
David Benjamina0e52232014-07-19 17:39:58 -0400352 },
353 {
354 testType: serverTest,
355 name: "SkipChangeCipherSpec-Server",
356 config: Config{
357 Bugs: ProtocolBugs{
358 SkipChangeCipherSpec: true,
359 },
360 },
361 shouldFail: true,
David Benjamin86271ee2014-07-21 16:14:03 -0400362 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
David Benjamina0e52232014-07-19 17:39:58 -0400363 },
David Benjamin42be6452014-07-21 14:50:23 -0400364 {
365 testType: serverTest,
366 name: "SkipChangeCipherSpec-Server-NPN",
367 config: Config{
368 NextProtos: []string{"bar"},
369 Bugs: ProtocolBugs{
370 SkipChangeCipherSpec: true,
371 },
372 },
373 flags: []string{
374 "-advertise-npn", "\x03foo\x03bar\x03baz",
375 },
376 shouldFail: true,
David Benjamin86271ee2014-07-21 16:14:03 -0400377 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
378 },
379 {
380 name: "FragmentAcrossChangeCipherSpec-Client",
381 config: Config{
382 Bugs: ProtocolBugs{
383 FragmentAcrossChangeCipherSpec: true,
384 },
385 },
386 shouldFail: true,
387 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
388 },
389 {
390 testType: serverTest,
391 name: "FragmentAcrossChangeCipherSpec-Server",
392 config: Config{
393 Bugs: ProtocolBugs{
394 FragmentAcrossChangeCipherSpec: true,
395 },
396 },
397 shouldFail: true,
398 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
399 },
400 {
401 testType: serverTest,
402 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
403 config: Config{
404 NextProtos: []string{"bar"},
405 Bugs: ProtocolBugs{
406 FragmentAcrossChangeCipherSpec: true,
407 },
408 },
409 flags: []string{
410 "-advertise-npn", "\x03foo\x03bar\x03baz",
411 },
412 shouldFail: true,
413 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
David Benjamin42be6452014-07-21 14:50:23 -0400414 },
David Benjaminf3ec83d2014-07-21 22:42:34 -0400415 {
416 testType: serverTest,
David Benjamin3fd1fbd2015-02-03 16:07:32 -0500417 name: "Alert",
418 config: Config{
419 Bugs: ProtocolBugs{
420 SendSpuriousAlert: alertRecordOverflow,
421 },
422 },
423 shouldFail: true,
424 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
425 },
426 {
427 protocol: dtls,
428 testType: serverTest,
429 name: "Alert-DTLS",
430 config: Config{
431 Bugs: ProtocolBugs{
432 SendSpuriousAlert: alertRecordOverflow,
433 },
434 },
435 shouldFail: true,
436 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
437 },
438 {
439 testType: serverTest,
Alex Chernyakhovsky4cd8c432014-11-01 19:39:08 -0400440 name: "FragmentAlert",
441 config: Config{
442 Bugs: ProtocolBugs{
David Benjaminca6c8262014-11-15 19:06:08 -0500443 FragmentAlert: true,
David Benjamin3fd1fbd2015-02-03 16:07:32 -0500444 SendSpuriousAlert: alertRecordOverflow,
Alex Chernyakhovsky4cd8c432014-11-01 19:39:08 -0400445 },
446 },
447 shouldFail: true,
448 expectedError: ":BAD_ALERT:",
449 },
450 {
David Benjamin0ea8dda2015-01-31 20:33:40 -0500451 protocol: dtls,
452 testType: serverTest,
453 name: "FragmentAlert-DTLS",
454 config: Config{
455 Bugs: ProtocolBugs{
456 FragmentAlert: true,
David Benjamin3fd1fbd2015-02-03 16:07:32 -0500457 SendSpuriousAlert: alertRecordOverflow,
David Benjamin0ea8dda2015-01-31 20:33:40 -0500458 },
459 },
460 shouldFail: true,
461 expectedError: ":BAD_ALERT:",
462 },
463 {
Alex Chernyakhovsky4cd8c432014-11-01 19:39:08 -0400464 testType: serverTest,
David Benjaminf3ec83d2014-07-21 22:42:34 -0400465 name: "EarlyChangeCipherSpec-server-1",
466 config: Config{
467 Bugs: ProtocolBugs{
468 EarlyChangeCipherSpec: 1,
469 },
470 },
471 shouldFail: true,
472 expectedError: ":CCS_RECEIVED_EARLY:",
473 },
474 {
475 testType: serverTest,
476 name: "EarlyChangeCipherSpec-server-2",
477 config: Config{
478 Bugs: ProtocolBugs{
479 EarlyChangeCipherSpec: 2,
480 },
481 },
482 shouldFail: true,
483 expectedError: ":CCS_RECEIVED_EARLY:",
484 },
David Benjamind23f4122014-07-23 15:09:48 -0400485 {
David Benjamind23f4122014-07-23 15:09:48 -0400486 name: "SkipNewSessionTicket",
487 config: Config{
488 Bugs: ProtocolBugs{
489 SkipNewSessionTicket: true,
490 },
491 },
492 shouldFail: true,
493 expectedError: ":CCS_RECEIVED_EARLY:",
494 },
David Benjamin7e3305e2014-07-28 14:52:32 -0400495 {
David Benjamind86c7672014-08-02 04:07:12 -0400496 testType: serverTest,
David Benjaminbef270a2014-08-02 04:22:02 -0400497 name: "FallbackSCSV",
498 config: Config{
499 MaxVersion: VersionTLS11,
500 Bugs: ProtocolBugs{
501 SendFallbackSCSV: true,
502 },
503 },
504 shouldFail: true,
505 expectedError: ":INAPPROPRIATE_FALLBACK:",
506 },
507 {
508 testType: serverTest,
509 name: "FallbackSCSV-VersionMatch",
510 config: Config{
511 Bugs: ProtocolBugs{
512 SendFallbackSCSV: true,
513 },
514 },
515 },
David Benjamin98214542014-08-07 18:02:39 -0400516 {
517 testType: serverTest,
518 name: "FragmentedClientVersion",
519 config: Config{
520 Bugs: ProtocolBugs{
521 MaxHandshakeRecordLength: 1,
522 FragmentClientVersion: true,
523 },
524 },
David Benjamin82c9e902014-12-12 15:55:27 -0500525 expectedVersion: VersionTLS12,
David Benjamin98214542014-08-07 18:02:39 -0400526 },
David Benjamin98e882e2014-08-08 13:24:34 -0400527 {
528 testType: serverTest,
529 name: "MinorVersionTolerance",
530 config: Config{
531 Bugs: ProtocolBugs{
532 SendClientVersion: 0x03ff,
533 },
534 },
535 expectedVersion: VersionTLS12,
536 },
537 {
538 testType: serverTest,
539 name: "MajorVersionTolerance",
540 config: Config{
541 Bugs: ProtocolBugs{
542 SendClientVersion: 0x0400,
543 },
544 },
545 expectedVersion: VersionTLS12,
546 },
547 {
548 testType: serverTest,
549 name: "VersionTooLow",
550 config: Config{
551 Bugs: ProtocolBugs{
552 SendClientVersion: 0x0200,
553 },
554 },
555 shouldFail: true,
556 expectedError: ":UNSUPPORTED_PROTOCOL:",
557 },
558 {
559 testType: serverTest,
560 name: "HttpGET",
561 sendPrefix: "GET / HTTP/1.0\n",
562 shouldFail: true,
563 expectedError: ":HTTP_REQUEST:",
564 },
565 {
566 testType: serverTest,
567 name: "HttpPOST",
568 sendPrefix: "POST / HTTP/1.0\n",
569 shouldFail: true,
570 expectedError: ":HTTP_REQUEST:",
571 },
572 {
573 testType: serverTest,
574 name: "HttpHEAD",
575 sendPrefix: "HEAD / HTTP/1.0\n",
576 shouldFail: true,
577 expectedError: ":HTTP_REQUEST:",
578 },
579 {
580 testType: serverTest,
581 name: "HttpPUT",
582 sendPrefix: "PUT / HTTP/1.0\n",
583 shouldFail: true,
584 expectedError: ":HTTP_REQUEST:",
585 },
586 {
587 testType: serverTest,
588 name: "HttpCONNECT",
589 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
590 shouldFail: true,
591 expectedError: ":HTTPS_PROXY_REQUEST:",
592 },
David Benjamin39ebf532014-08-31 02:23:49 -0400593 {
David Benjaminf080ecd2014-12-11 18:48:59 -0500594 testType: serverTest,
595 name: "Garbage",
596 sendPrefix: "blah",
597 shouldFail: true,
598 expectedError: ":UNKNOWN_PROTOCOL:",
599 },
600 {
David Benjamin39ebf532014-08-31 02:23:49 -0400601 name: "SkipCipherVersionCheck",
602 config: Config{
603 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
604 MaxVersion: VersionTLS11,
605 Bugs: ProtocolBugs{
606 SkipCipherVersionCheck: true,
607 },
608 },
609 shouldFail: true,
610 expectedError: ":WRONG_CIPHER_RETURNED:",
611 },
David Benjamin9114fae2014-11-08 11:41:14 -0500612 {
David Benjamina3e89492015-02-26 15:16:22 -0500613 name: "RSAEphemeralKey",
David Benjamin9114fae2014-11-08 11:41:14 -0500614 config: Config{
615 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
616 Bugs: ProtocolBugs{
David Benjamina3e89492015-02-26 15:16:22 -0500617 RSAEphemeralKey: true,
David Benjamin9114fae2014-11-08 11:41:14 -0500618 },
619 },
620 shouldFail: true,
621 expectedError: ":UNEXPECTED_MESSAGE:",
622 },
David Benjamin128dbc32014-12-01 01:27:42 -0500623 {
624 name: "DisableEverything",
625 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
626 shouldFail: true,
627 expectedError: ":WRONG_SSL_VERSION:",
628 },
629 {
630 protocol: dtls,
631 name: "DisableEverything-DTLS",
632 flags: []string{"-no-tls12", "-no-tls1"},
633 shouldFail: true,
634 expectedError: ":WRONG_SSL_VERSION:",
635 },
David Benjamin780d6dd2015-01-06 12:03:19 -0500636 {
637 name: "NoSharedCipher",
638 config: Config{
639 CipherSuites: []uint16{},
640 },
641 shouldFail: true,
642 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
643 },
David Benjamin13be1de2015-01-11 16:29:36 -0500644 {
645 protocol: dtls,
646 testType: serverTest,
647 name: "MTU",
648 config: Config{
649 Bugs: ProtocolBugs{
650 MaxPacketLength: 256,
651 },
652 },
653 flags: []string{"-mtu", "256"},
654 },
655 {
656 protocol: dtls,
657 testType: serverTest,
658 name: "MTUExceeded",
659 config: Config{
660 Bugs: ProtocolBugs{
661 MaxPacketLength: 255,
662 },
663 },
664 flags: []string{"-mtu", "256"},
665 shouldFail: true,
666 expectedLocalError: "dtls: exceeded maximum packet length",
667 },
David Benjamin6095de82014-12-27 01:50:38 -0500668 {
669 name: "CertMismatchRSA",
670 config: Config{
671 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
672 Certificates: []Certificate{getECDSACertificate()},
673 Bugs: ProtocolBugs{
674 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
675 },
676 },
677 shouldFail: true,
678 expectedError: ":WRONG_CERTIFICATE_TYPE:",
679 },
680 {
681 name: "CertMismatchECDSA",
682 config: Config{
683 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
684 Certificates: []Certificate{getRSACertificate()},
685 Bugs: ProtocolBugs{
686 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
687 },
688 },
689 shouldFail: true,
690 expectedError: ":WRONG_CERTIFICATE_TYPE:",
691 },
David Benjamin5fa3eba2015-01-22 16:35:40 -0500692 {
David Benjamin8923c0b2015-06-07 11:42:34 -0400693 name: "EmptyCertificateList",
694 config: Config{
695 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
696 Bugs: ProtocolBugs{
697 EmptyCertificateList: true,
698 },
699 },
700 shouldFail: true,
701 expectedError: ":DECODE_ERROR:",
702 },
703 {
David Benjamin5fa3eba2015-01-22 16:35:40 -0500704 name: "TLSFatalBadPackets",
705 damageFirstWrite: true,
706 shouldFail: true,
707 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
708 },
709 {
710 protocol: dtls,
711 name: "DTLSIgnoreBadPackets",
712 damageFirstWrite: true,
713 },
714 {
715 protocol: dtls,
716 name: "DTLSIgnoreBadPackets-Async",
717 damageFirstWrite: true,
718 flags: []string{"-async"},
719 },
David Benjamin4189bd92015-01-25 23:52:39 -0500720 {
721 name: "AppDataAfterChangeCipherSpec",
722 config: Config{
723 Bugs: ProtocolBugs{
724 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
725 },
726 },
727 shouldFail: true,
728 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
729 },
730 {
731 protocol: dtls,
732 name: "AppDataAfterChangeCipherSpec-DTLS",
733 config: Config{
734 Bugs: ProtocolBugs{
735 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
736 },
737 },
David Benjamin4417d052015-04-05 04:17:25 -0400738 // BoringSSL's DTLS implementation will drop the out-of-order
739 // application data.
David Benjamin4189bd92015-01-25 23:52:39 -0500740 },
David Benjaminb3774b92015-01-31 17:16:01 -0500741 {
David Benjamindc3da932015-03-12 15:09:02 -0400742 name: "AlertAfterChangeCipherSpec",
743 config: Config{
744 Bugs: ProtocolBugs{
745 AlertAfterChangeCipherSpec: alertRecordOverflow,
746 },
747 },
748 shouldFail: true,
749 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
750 },
751 {
752 protocol: dtls,
753 name: "AlertAfterChangeCipherSpec-DTLS",
754 config: Config{
755 Bugs: ProtocolBugs{
756 AlertAfterChangeCipherSpec: alertRecordOverflow,
757 },
758 },
759 shouldFail: true,
760 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
761 },
762 {
David Benjaminb3774b92015-01-31 17:16:01 -0500763 protocol: dtls,
764 name: "ReorderHandshakeFragments-Small-DTLS",
765 config: Config{
766 Bugs: ProtocolBugs{
767 ReorderHandshakeFragments: true,
768 // Small enough that every handshake message is
769 // fragmented.
770 MaxHandshakeRecordLength: 2,
771 },
772 },
773 },
774 {
775 protocol: dtls,
776 name: "ReorderHandshakeFragments-Large-DTLS",
777 config: Config{
778 Bugs: ProtocolBugs{
779 ReorderHandshakeFragments: true,
780 // Large enough that no handshake message is
781 // fragmented.
David Benjaminb3774b92015-01-31 17:16:01 -0500782 MaxHandshakeRecordLength: 2048,
783 },
784 },
785 },
David Benjaminddb9f152015-02-03 15:44:39 -0500786 {
David Benjamin75381222015-03-02 19:30:30 -0500787 protocol: dtls,
788 name: "MixCompleteMessageWithFragments-DTLS",
789 config: Config{
790 Bugs: ProtocolBugs{
791 ReorderHandshakeFragments: true,
792 MixCompleteMessageWithFragments: true,
793 MaxHandshakeRecordLength: 2,
794 },
795 },
796 },
797 {
David Benjaminddb9f152015-02-03 15:44:39 -0500798 name: "SendInvalidRecordType",
799 config: Config{
800 Bugs: ProtocolBugs{
801 SendInvalidRecordType: true,
802 },
803 },
804 shouldFail: true,
805 expectedError: ":UNEXPECTED_RECORD:",
806 },
807 {
808 protocol: dtls,
809 name: "SendInvalidRecordType-DTLS",
810 config: Config{
811 Bugs: ProtocolBugs{
812 SendInvalidRecordType: true,
813 },
814 },
815 shouldFail: true,
816 expectedError: ":UNEXPECTED_RECORD:",
817 },
David Benjaminb80168e2015-02-08 18:30:14 -0500818 {
819 name: "FalseStart-SkipServerSecondLeg",
820 config: Config{
821 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
822 NextProtos: []string{"foo"},
823 Bugs: ProtocolBugs{
824 SkipNewSessionTicket: true,
825 SkipChangeCipherSpec: true,
826 SkipFinished: true,
827 ExpectFalseStart: true,
828 },
829 },
830 flags: []string{
831 "-false-start",
David Benjamin87e4acd2015-04-02 19:57:35 -0400832 "-handshake-never-done",
David Benjaminb80168e2015-02-08 18:30:14 -0500833 "-advertise-alpn", "\x03foo",
834 },
835 shimWritesFirst: true,
836 shouldFail: true,
837 expectedError: ":UNEXPECTED_RECORD:",
838 },
David Benjamin931ab342015-02-08 19:46:57 -0500839 {
840 name: "FalseStart-SkipServerSecondLeg-Implicit",
841 config: Config{
842 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
843 NextProtos: []string{"foo"},
844 Bugs: ProtocolBugs{
845 SkipNewSessionTicket: true,
846 SkipChangeCipherSpec: true,
847 SkipFinished: true,
848 },
849 },
850 flags: []string{
851 "-implicit-handshake",
852 "-false-start",
David Benjamin87e4acd2015-04-02 19:57:35 -0400853 "-handshake-never-done",
David Benjamin931ab342015-02-08 19:46:57 -0500854 "-advertise-alpn", "\x03foo",
855 },
856 shouldFail: true,
857 expectedError: ":UNEXPECTED_RECORD:",
858 },
David Benjamin6f5c0f42015-02-24 01:23:21 -0500859 {
860 testType: serverTest,
861 name: "FailEarlyCallback",
862 flags: []string{"-fail-early-callback"},
863 shouldFail: true,
864 expectedError: ":CONNECTION_REJECTED:",
865 expectedLocalError: "remote error: access denied",
866 },
David Benjaminbcb2d912015-02-24 23:45:43 -0500867 {
868 name: "WrongMessageType",
869 config: Config{
870 Bugs: ProtocolBugs{
871 WrongCertificateMessageType: true,
872 },
873 },
874 shouldFail: true,
875 expectedError: ":UNEXPECTED_MESSAGE:",
876 expectedLocalError: "remote error: unexpected message",
877 },
878 {
879 protocol: dtls,
880 name: "WrongMessageType-DTLS",
881 config: Config{
882 Bugs: ProtocolBugs{
883 WrongCertificateMessageType: true,
884 },
885 },
886 shouldFail: true,
887 expectedError: ":UNEXPECTED_MESSAGE:",
888 expectedLocalError: "remote error: unexpected message",
889 },
David Benjamin75381222015-03-02 19:30:30 -0500890 {
891 protocol: dtls,
892 name: "FragmentMessageTypeMismatch-DTLS",
893 config: Config{
894 Bugs: ProtocolBugs{
895 MaxHandshakeRecordLength: 2,
896 FragmentMessageTypeMismatch: true,
897 },
898 },
899 shouldFail: true,
900 expectedError: ":FRAGMENT_MISMATCH:",
901 },
902 {
903 protocol: dtls,
904 name: "FragmentMessageLengthMismatch-DTLS",
905 config: Config{
906 Bugs: ProtocolBugs{
907 MaxHandshakeRecordLength: 2,
908 FragmentMessageLengthMismatch: true,
909 },
910 },
911 shouldFail: true,
912 expectedError: ":FRAGMENT_MISMATCH:",
913 },
914 {
915 protocol: dtls,
David Benjamin11fc66a2015-06-16 11:40:24 -0400916 name: "SplitFragments-Header-DTLS",
David Benjamin75381222015-03-02 19:30:30 -0500917 config: Config{
918 Bugs: ProtocolBugs{
David Benjamin11fc66a2015-06-16 11:40:24 -0400919 SplitFragments: 2,
David Benjamin75381222015-03-02 19:30:30 -0500920 },
921 },
922 shouldFail: true,
923 expectedError: ":UNEXPECTED_MESSAGE:",
924 },
925 {
926 protocol: dtls,
David Benjamin11fc66a2015-06-16 11:40:24 -0400927 name: "SplitFragments-Boundary-DTLS",
David Benjamin75381222015-03-02 19:30:30 -0500928 config: Config{
929 Bugs: ProtocolBugs{
David Benjamin11fc66a2015-06-16 11:40:24 -0400930 SplitFragments: dtlsRecordHeaderLen,
David Benjamin75381222015-03-02 19:30:30 -0500931 },
932 },
933 shouldFail: true,
David Benjamin11fc66a2015-06-16 11:40:24 -0400934 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
935 },
936 {
937 protocol: dtls,
938 name: "SplitFragments-Body-DTLS",
939 config: Config{
940 Bugs: ProtocolBugs{
941 SplitFragments: dtlsRecordHeaderLen + 1,
942 },
943 },
944 shouldFail: true,
945 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjamin75381222015-03-02 19:30:30 -0500946 },
947 {
948 protocol: dtls,
949 name: "SendEmptyFragments-DTLS",
950 config: Config{
951 Bugs: ProtocolBugs{
952 SendEmptyFragments: true,
953 },
954 },
955 },
David Benjamin67d1fb52015-03-16 15:16:23 -0400956 {
957 name: "UnsupportedCipherSuite",
958 config: Config{
959 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
960 Bugs: ProtocolBugs{
961 IgnorePeerCipherPreferences: true,
962 },
963 },
964 flags: []string{"-cipher", "DEFAULT:!RC4"},
965 shouldFail: true,
966 expectedError: ":WRONG_CIPHER_RETURNED:",
967 },
David Benjamin340d5ed2015-03-21 02:21:37 -0400968 {
David Benjaminc574f412015-04-20 11:13:01 -0400969 name: "UnsupportedCurve",
970 config: Config{
971 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
972 // BoringSSL implements P-224 but doesn't enable it by
973 // default.
974 CurvePreferences: []CurveID{CurveP224},
975 Bugs: ProtocolBugs{
976 IgnorePeerCurvePreferences: true,
977 },
978 },
979 shouldFail: true,
980 expectedError: ":WRONG_CURVE:",
981 },
982 {
David Benjamin513f0ea2015-04-02 19:33:31 -0400983 name: "BadFinished",
984 config: Config{
985 Bugs: ProtocolBugs{
986 BadFinished: true,
987 },
988 },
989 shouldFail: true,
990 expectedError: ":DIGEST_CHECK_FAILED:",
991 },
992 {
993 name: "FalseStart-BadFinished",
994 config: Config{
995 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
996 NextProtos: []string{"foo"},
997 Bugs: ProtocolBugs{
998 BadFinished: true,
999 ExpectFalseStart: true,
1000 },
1001 },
1002 flags: []string{
1003 "-false-start",
David Benjamin87e4acd2015-04-02 19:57:35 -04001004 "-handshake-never-done",
David Benjamin513f0ea2015-04-02 19:33:31 -04001005 "-advertise-alpn", "\x03foo",
1006 },
1007 shimWritesFirst: true,
1008 shouldFail: true,
1009 expectedError: ":DIGEST_CHECK_FAILED:",
1010 },
David Benjamin1c633152015-04-02 20:19:11 -04001011 {
1012 name: "NoFalseStart-NoALPN",
1013 config: Config{
1014 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1015 Bugs: ProtocolBugs{
1016 ExpectFalseStart: true,
1017 AlertBeforeFalseStartTest: alertAccessDenied,
1018 },
1019 },
1020 flags: []string{
1021 "-false-start",
1022 },
1023 shimWritesFirst: true,
1024 shouldFail: true,
1025 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1026 expectedLocalError: "tls: peer did not false start: EOF",
1027 },
1028 {
1029 name: "NoFalseStart-NoAEAD",
1030 config: Config{
1031 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1032 NextProtos: []string{"foo"},
1033 Bugs: ProtocolBugs{
1034 ExpectFalseStart: true,
1035 AlertBeforeFalseStartTest: alertAccessDenied,
1036 },
1037 },
1038 flags: []string{
1039 "-false-start",
1040 "-advertise-alpn", "\x03foo",
1041 },
1042 shimWritesFirst: true,
1043 shouldFail: true,
1044 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1045 expectedLocalError: "tls: peer did not false start: EOF",
1046 },
1047 {
1048 name: "NoFalseStart-RSA",
1049 config: Config{
1050 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1051 NextProtos: []string{"foo"},
1052 Bugs: ProtocolBugs{
1053 ExpectFalseStart: true,
1054 AlertBeforeFalseStartTest: alertAccessDenied,
1055 },
1056 },
1057 flags: []string{
1058 "-false-start",
1059 "-advertise-alpn", "\x03foo",
1060 },
1061 shimWritesFirst: true,
1062 shouldFail: true,
1063 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1064 expectedLocalError: "tls: peer did not false start: EOF",
1065 },
1066 {
1067 name: "NoFalseStart-DHE_RSA",
1068 config: Config{
1069 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1070 NextProtos: []string{"foo"},
1071 Bugs: ProtocolBugs{
1072 ExpectFalseStart: true,
1073 AlertBeforeFalseStartTest: alertAccessDenied,
1074 },
1075 },
1076 flags: []string{
1077 "-false-start",
1078 "-advertise-alpn", "\x03foo",
1079 },
1080 shimWritesFirst: true,
1081 shouldFail: true,
1082 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1083 expectedLocalError: "tls: peer did not false start: EOF",
1084 },
David Benjamin55a43642015-04-20 14:45:55 -04001085 {
1086 testType: serverTest,
1087 name: "NoSupportedCurves",
1088 config: Config{
1089 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1090 Bugs: ProtocolBugs{
1091 NoSupportedCurves: true,
1092 },
1093 },
1094 },
David Benjamin90da8c82015-04-20 14:57:57 -04001095 {
1096 testType: serverTest,
1097 name: "NoCommonCurves",
1098 config: Config{
1099 CipherSuites: []uint16{
1100 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1101 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1102 },
1103 CurvePreferences: []CurveID{CurveP224},
1104 },
1105 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1106 },
David Benjamin9a41d1b2015-05-16 01:30:09 -04001107 {
1108 protocol: dtls,
1109 name: "SendSplitAlert-Sync",
1110 config: Config{
1111 Bugs: ProtocolBugs{
1112 SendSplitAlert: true,
1113 },
1114 },
1115 },
1116 {
1117 protocol: dtls,
1118 name: "SendSplitAlert-Async",
1119 config: Config{
1120 Bugs: ProtocolBugs{
1121 SendSplitAlert: true,
1122 },
1123 },
1124 flags: []string{"-async"},
1125 },
David Benjaminbd15a8e2015-05-29 18:48:16 -04001126 {
1127 protocol: dtls,
1128 name: "PackDTLSHandshake",
1129 config: Config{
1130 Bugs: ProtocolBugs{
1131 MaxHandshakeRecordLength: 2,
1132 PackHandshakeFragments: 20,
1133 PackHandshakeRecords: 200,
1134 },
1135 },
1136 },
David Benjamin0fa40122015-05-30 17:13:12 -04001137 {
1138 testType: serverTest,
1139 protocol: dtls,
1140 name: "NoRC4-DTLS",
1141 config: Config{
1142 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1143 Bugs: ProtocolBugs{
1144 EnableAllCiphersInDTLS: true,
1145 },
1146 },
1147 shouldFail: true,
1148 expectedError: ":NO_SHARED_CIPHER:",
1149 },
David Benjamina8ebe222015-06-06 03:04:39 -04001150 {
1151 name: "SendEmptyRecords-Pass",
1152 sendEmptyRecords: 32,
1153 },
1154 {
1155 name: "SendEmptyRecords",
1156 sendEmptyRecords: 33,
1157 shouldFail: true,
1158 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1159 },
1160 {
1161 name: "SendEmptyRecords-Async",
1162 sendEmptyRecords: 33,
1163 flags: []string{"-async"},
1164 shouldFail: true,
1165 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1166 },
David Benjamin24f346d2015-06-06 03:28:08 -04001167 {
1168 name: "SendWarningAlerts-Pass",
1169 sendWarningAlerts: 4,
1170 },
1171 {
1172 protocol: dtls,
1173 name: "SendWarningAlerts-DTLS-Pass",
1174 sendWarningAlerts: 4,
1175 },
1176 {
1177 name: "SendWarningAlerts",
1178 sendWarningAlerts: 5,
1179 shouldFail: true,
1180 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1181 },
1182 {
1183 name: "SendWarningAlerts-Async",
1184 sendWarningAlerts: 5,
1185 flags: []string{"-async"},
1186 shouldFail: true,
1187 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1188 },
Adam Langley95c29f32014-06-20 12:00:00 -07001189}
1190
David Benjamin01fe8202014-09-24 15:21:44 -04001191func doExchange(test *testCase, config *Config, conn net.Conn, messageLen int, isResume bool) error {
David Benjamin65ea8ff2014-11-23 03:01:00 -05001192 var connDebug *recordingConn
David Benjamin5fa3eba2015-01-22 16:35:40 -05001193 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -05001194 if *flagDebug {
1195 connDebug = &recordingConn{Conn: conn}
1196 conn = connDebug
1197 defer func() {
1198 connDebug.WriteTo(os.Stdout)
1199 }()
1200 }
1201
David Benjamin6fd297b2014-08-11 18:43:38 -04001202 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -05001203 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
1204 conn = config.Bugs.PacketAdaptor
David Benjamin5e961c12014-11-07 01:48:35 -05001205 if test.replayWrites {
1206 conn = newReplayAdaptor(conn)
1207 }
David Benjamin6fd297b2014-08-11 18:43:38 -04001208 }
1209
David Benjamin5fa3eba2015-01-22 16:35:40 -05001210 if test.damageFirstWrite {
1211 connDamage = newDamageAdaptor(conn)
1212 conn = connDamage
1213 }
1214
David Benjamin6fd297b2014-08-11 18:43:38 -04001215 if test.sendPrefix != "" {
1216 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
1217 return err
1218 }
David Benjamin98e882e2014-08-08 13:24:34 -04001219 }
1220
David Benjamin1d5c83e2014-07-22 19:20:02 -04001221 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001222 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -04001223 if test.protocol == dtls {
1224 tlsConn = DTLSServer(conn, config)
1225 } else {
1226 tlsConn = Server(conn, config)
1227 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001228 } else {
1229 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -04001230 if test.protocol == dtls {
1231 tlsConn = DTLSClient(conn, config)
1232 } else {
1233 tlsConn = Client(conn, config)
1234 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001235 }
1236
Adam Langley95c29f32014-06-20 12:00:00 -07001237 if err := tlsConn.Handshake(); err != nil {
1238 return err
1239 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07001240
David Benjamin01fe8202014-09-24 15:21:44 -04001241 // TODO(davidben): move all per-connection expectations into a dedicated
1242 // expectations struct that can be specified separately for the two
1243 // legs.
1244 expectedVersion := test.expectedVersion
1245 if isResume && test.expectedResumeVersion != 0 {
1246 expectedVersion = test.expectedResumeVersion
1247 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001248 connState := tlsConn.ConnectionState()
1249 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -04001250 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001251 }
1252
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001253 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -04001254 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
1255 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001256 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
1257 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
1258 }
David Benjamin90da8c82015-04-20 14:57:57 -04001259
David Benjamina08e49d2014-08-24 01:46:07 -04001260 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001261 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -04001262 if channelID == nil {
1263 return fmt.Errorf("no channel ID negotiated")
1264 }
1265 if channelID.Curve != channelIDKey.Curve ||
1266 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
1267 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
1268 return fmt.Errorf("incorrect channel ID")
1269 }
1270 }
1271
David Benjaminae2888f2014-09-06 12:58:58 -04001272 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001273 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -04001274 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
1275 }
1276 }
1277
David Benjaminfc7b0862014-09-06 13:21:53 -04001278 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001279 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -04001280 return fmt.Errorf("next proto type mismatch")
1281 }
1282 }
1283
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001284 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -05001285 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
1286 }
1287
David Benjaminc565ebb2015-04-03 04:06:36 -04001288 if test.exportKeyingMaterial > 0 {
1289 actual := make([]byte, test.exportKeyingMaterial)
1290 if _, err := io.ReadFull(tlsConn, actual); err != nil {
1291 return err
1292 }
1293 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
1294 if err != nil {
1295 return err
1296 }
1297 if !bytes.Equal(actual, expected) {
1298 return fmt.Errorf("keying material mismatch")
1299 }
1300 }
1301
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001302 if test.testTLSUnique {
1303 var peersValue [12]byte
1304 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
1305 return err
1306 }
1307 expected := tlsConn.ConnectionState().TLSUnique
1308 if !bytes.Equal(peersValue[:], expected) {
1309 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
1310 }
1311 }
1312
David Benjamine58c4f52014-08-24 03:47:07 -04001313 if test.shimWritesFirst {
1314 var buf [5]byte
1315 _, err := io.ReadFull(tlsConn, buf[:])
1316 if err != nil {
1317 return err
1318 }
1319 if string(buf[:]) != "hello" {
1320 return fmt.Errorf("bad initial message")
1321 }
1322 }
1323
David Benjamina8ebe222015-06-06 03:04:39 -04001324 for i := 0; i < test.sendEmptyRecords; i++ {
1325 tlsConn.Write(nil)
1326 }
1327
David Benjamin24f346d2015-06-06 03:28:08 -04001328 for i := 0; i < test.sendWarningAlerts; i++ {
1329 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
1330 }
1331
Adam Langleycf2d4f42014-10-28 19:06:14 -07001332 if test.renegotiate {
1333 if test.renegotiateCiphers != nil {
1334 config.CipherSuites = test.renegotiateCiphers
1335 }
1336 if err := tlsConn.Renegotiate(); err != nil {
1337 return err
1338 }
1339 } else if test.renegotiateCiphers != nil {
1340 panic("renegotiateCiphers without renegotiate")
1341 }
1342
David Benjamin5fa3eba2015-01-22 16:35:40 -05001343 if test.damageFirstWrite {
1344 connDamage.setDamage(true)
1345 tlsConn.Write([]byte("DAMAGED WRITE"))
1346 connDamage.setDamage(false)
1347 }
1348
Kenny Root7fdeaf12014-08-05 15:23:37 -07001349 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -04001350 if test.protocol == dtls {
1351 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
1352 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07001353 // Read until EOF.
1354 _, err := io.Copy(ioutil.Discard, tlsConn)
1355 return err
1356 }
1357
David Benjamin4417d052015-04-05 04:17:25 -04001358 if messageLen == 0 {
1359 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -07001360 }
David Benjamin4417d052015-04-05 04:17:25 -04001361 testMessage := make([]byte, messageLen)
1362 for i := range testMessage {
1363 testMessage[i] = 0x42
1364 }
1365 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -07001366
David Benjamina8ebe222015-06-06 03:04:39 -04001367 for i := 0; i < test.sendEmptyRecords; i++ {
1368 tlsConn.Write(nil)
1369 }
1370
David Benjamin24f346d2015-06-06 03:28:08 -04001371 for i := 0; i < test.sendWarningAlerts; i++ {
1372 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
1373 }
1374
Adam Langley95c29f32014-06-20 12:00:00 -07001375 buf := make([]byte, len(testMessage))
David Benjamin6fd297b2014-08-11 18:43:38 -04001376 if test.protocol == dtls {
1377 bufTmp := make([]byte, len(buf)+1)
1378 n, err := tlsConn.Read(bufTmp)
1379 if err != nil {
1380 return err
1381 }
1382 if n != len(buf) {
1383 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
1384 }
1385 copy(buf, bufTmp)
1386 } else {
1387 _, err := io.ReadFull(tlsConn, buf)
1388 if err != nil {
1389 return err
1390 }
Adam Langley95c29f32014-06-20 12:00:00 -07001391 }
1392
1393 for i, v := range buf {
1394 if v != testMessage[i]^0xff {
1395 return fmt.Errorf("bad reply contents at byte %d", i)
1396 }
1397 }
1398
1399 return nil
1400}
1401
David Benjamin325b5c32014-07-01 19:40:31 -04001402func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
1403 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -07001404 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -04001405 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -07001406 }
David Benjamin325b5c32014-07-01 19:40:31 -04001407 valgrindArgs = append(valgrindArgs, path)
1408 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -07001409
David Benjamin325b5c32014-07-01 19:40:31 -04001410 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -07001411}
1412
David Benjamin325b5c32014-07-01 19:40:31 -04001413func gdbOf(path string, args ...string) *exec.Cmd {
1414 xtermArgs := []string{"-e", "gdb", "--args"}
1415 xtermArgs = append(xtermArgs, path)
1416 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -07001417
David Benjamin325b5c32014-07-01 19:40:31 -04001418 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -07001419}
1420
Adam Langley69a01602014-11-17 17:26:55 -08001421type moreMallocsError struct{}
1422
1423func (moreMallocsError) Error() string {
1424 return "child process did not exhaust all allocation calls"
1425}
1426
1427var errMoreMallocs = moreMallocsError{}
1428
David Benjamin87c8a642015-02-21 01:54:29 -05001429// accept accepts a connection from listener, unless waitChan signals a process
1430// exit first.
1431func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
1432 type connOrError struct {
1433 conn net.Conn
1434 err error
1435 }
1436 connChan := make(chan connOrError, 1)
1437 go func() {
1438 conn, err := listener.Accept()
1439 connChan <- connOrError{conn, err}
1440 close(connChan)
1441 }()
1442 select {
1443 case result := <-connChan:
1444 return result.conn, result.err
1445 case childErr := <-waitChan:
1446 waitChan <- childErr
1447 return nil, fmt.Errorf("child exited early: %s", childErr)
1448 }
1449}
1450
Adam Langley69a01602014-11-17 17:26:55 -08001451func runTest(test *testCase, buildDir string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -07001452 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
1453 panic("Error expected without shouldFail in " + test.name)
1454 }
1455
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001456 if test.expectResumeRejected && !test.resumeSession {
1457 panic("expectResumeRejected without resumeSession in " + test.name)
1458 }
1459
David Benjamin87c8a642015-02-21 01:54:29 -05001460 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
1461 if err != nil {
1462 panic(err)
1463 }
1464 defer func() {
1465 if listener != nil {
1466 listener.Close()
1467 }
1468 }()
Adam Langley95c29f32014-06-20 12:00:00 -07001469
David Benjamin884fdf12014-08-02 15:28:23 -04001470 shim_path := path.Join(buildDir, "ssl/test/bssl_shim")
David Benjamin87c8a642015-02-21 01:54:29 -05001471 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -04001472 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -04001473 flags = append(flags, "-server")
1474
David Benjamin025b3d32014-07-01 19:53:04 -04001475 flags = append(flags, "-key-file")
1476 if test.keyFile == "" {
1477 flags = append(flags, rsaKeyFile)
1478 } else {
1479 flags = append(flags, test.keyFile)
1480 }
1481
1482 flags = append(flags, "-cert-file")
1483 if test.certFile == "" {
1484 flags = append(flags, rsaCertificateFile)
1485 } else {
1486 flags = append(flags, test.certFile)
1487 }
1488 }
David Benjamin5a593af2014-08-11 19:51:50 -04001489
David Benjamin6fd297b2014-08-11 18:43:38 -04001490 if test.protocol == dtls {
1491 flags = append(flags, "-dtls")
1492 }
1493
David Benjamin5a593af2014-08-11 19:51:50 -04001494 if test.resumeSession {
1495 flags = append(flags, "-resume")
1496 }
1497
David Benjamine58c4f52014-08-24 03:47:07 -04001498 if test.shimWritesFirst {
1499 flags = append(flags, "-shim-writes-first")
1500 }
1501
David Benjaminc565ebb2015-04-03 04:06:36 -04001502 if test.exportKeyingMaterial > 0 {
1503 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1504 flags = append(flags, "-export-label", test.exportLabel)
1505 flags = append(flags, "-export-context", test.exportContext)
1506 if test.useExportContext {
1507 flags = append(flags, "-use-export-context")
1508 }
1509 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001510 if test.expectResumeRejected {
1511 flags = append(flags, "-expect-session-miss")
1512 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001513
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001514 if test.testTLSUnique {
1515 flags = append(flags, "-tls-unique")
1516 }
1517
David Benjamin025b3d32014-07-01 19:53:04 -04001518 flags = append(flags, test.flags...)
1519
1520 var shim *exec.Cmd
1521 if *useValgrind {
1522 shim = valgrindOf(false, shim_path, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001523 } else if *useGDB {
1524 shim = gdbOf(shim_path, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001525 } else {
1526 shim = exec.Command(shim_path, flags...)
1527 }
David Benjamin025b3d32014-07-01 19:53:04 -04001528 shim.Stdin = os.Stdin
1529 var stdoutBuf, stderrBuf bytes.Buffer
1530 shim.Stdout = &stdoutBuf
1531 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001532 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001533 shim.Env = os.Environ()
1534 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001535 if *mallocTestDebug {
1536 shim.Env = append(shim.Env, "MALLOC_ABORT_ON_FAIL=1")
1537 }
1538 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1539 }
David Benjamin025b3d32014-07-01 19:53:04 -04001540
1541 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001542 panic(err)
1543 }
David Benjamin87c8a642015-02-21 01:54:29 -05001544 waitChan := make(chan error, 1)
1545 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001546
1547 config := test.config
David Benjamin1d5c83e2014-07-22 19:20:02 -04001548 config.ClientSessionCache = NewLRUClientSessionCache(1)
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001549 config.ServerSessionCache = NewLRUServerSessionCache(1)
David Benjamin025b3d32014-07-01 19:53:04 -04001550 if test.testType == clientTest {
1551 if len(config.Certificates) == 0 {
1552 config.Certificates = []Certificate{getRSACertificate()}
1553 }
David Benjamin87c8a642015-02-21 01:54:29 -05001554 } else {
1555 // Supply a ServerName to ensure a constant session cache key,
1556 // rather than falling back to net.Conn.RemoteAddr.
1557 if len(config.ServerName) == 0 {
1558 config.ServerName = "test"
1559 }
David Benjamin025b3d32014-07-01 19:53:04 -04001560 }
Adam Langley95c29f32014-06-20 12:00:00 -07001561
David Benjamin87c8a642015-02-21 01:54:29 -05001562 conn, err := acceptOrWait(listener, waitChan)
1563 if err == nil {
1564 err = doExchange(test, &config, conn, test.messageLen, false /* not a resumption */)
1565 conn.Close()
1566 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001567
David Benjamin1d5c83e2014-07-22 19:20:02 -04001568 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -04001569 var resumeConfig Config
1570 if test.resumeConfig != nil {
1571 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -05001572 if len(resumeConfig.ServerName) == 0 {
1573 resumeConfig.ServerName = config.ServerName
1574 }
David Benjamin01fe8202014-09-24 15:21:44 -04001575 if len(resumeConfig.Certificates) == 0 {
1576 resumeConfig.Certificates = []Certificate{getRSACertificate()}
1577 }
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001578 if !test.newSessionsOnResume {
1579 resumeConfig.SessionTicketKey = config.SessionTicketKey
1580 resumeConfig.ClientSessionCache = config.ClientSessionCache
1581 resumeConfig.ServerSessionCache = config.ServerSessionCache
1582 }
David Benjamin01fe8202014-09-24 15:21:44 -04001583 } else {
1584 resumeConfig = config
1585 }
David Benjamin87c8a642015-02-21 01:54:29 -05001586 var connResume net.Conn
1587 connResume, err = acceptOrWait(listener, waitChan)
1588 if err == nil {
1589 err = doExchange(test, &resumeConfig, connResume, test.messageLen, true /* resumption */)
1590 connResume.Close()
1591 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001592 }
1593
David Benjamin87c8a642015-02-21 01:54:29 -05001594 // Close the listener now. This is to avoid hangs should the shim try to
1595 // open more connections than expected.
1596 listener.Close()
1597 listener = nil
1598
1599 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -08001600 if exitError, ok := childErr.(*exec.ExitError); ok {
1601 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
1602 return errMoreMallocs
1603 }
1604 }
Adam Langley95c29f32014-06-20 12:00:00 -07001605
1606 stdout := string(stdoutBuf.Bytes())
1607 stderr := string(stderrBuf.Bytes())
1608 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -04001609 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -07001610 localError := "none"
1611 if err != nil {
1612 localError = err.Error()
1613 }
1614 if len(test.expectedLocalError) != 0 {
1615 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1616 }
Adam Langley95c29f32014-06-20 12:00:00 -07001617
1618 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001619 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001620 if childErr != nil {
1621 childError = childErr.Error()
1622 }
1623
1624 var msg string
1625 switch {
1626 case failed && !test.shouldFail:
1627 msg = "unexpected failure"
1628 case !failed && test.shouldFail:
1629 msg = "unexpected success"
1630 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -07001631 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001632 default:
1633 panic("internal error")
1634 }
1635
David Benjaminc565ebb2015-04-03 04:06:36 -04001636 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001637 }
1638
David Benjaminc565ebb2015-04-03 04:06:36 -04001639 if !*useValgrind && !failed && len(stderr) > 0 {
Adam Langley95c29f32014-06-20 12:00:00 -07001640 println(stderr)
1641 }
1642
1643 return nil
1644}
1645
1646var tlsVersions = []struct {
1647 name string
1648 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001649 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001650 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001651}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001652 {"SSL3", VersionSSL30, "-no-ssl3", false},
1653 {"TLS1", VersionTLS10, "-no-tls1", true},
1654 {"TLS11", VersionTLS11, "-no-tls11", false},
1655 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -07001656}
1657
1658var testCipherSuites = []struct {
1659 name string
1660 id uint16
1661}{
1662 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001663 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001664 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001665 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001666 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001667 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001668 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001669 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1670 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001671 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001672 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1673 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001674 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
David Benjamine9a80ff2015-04-07 00:46:46 -04001675 {"DHE-RSA-CHACHA20-POLY1305", TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001676 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1677 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001678 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1679 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001680 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001681 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -04001682 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001683 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001684 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001685 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001686 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001687 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001688 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001689 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -04001690 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001691 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -04001692 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1693 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001694 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1695 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin48cae082014-10-27 01:06:24 -04001696 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001697 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001698 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001699}
1700
David Benjamin8b8c0062014-11-23 02:47:52 -05001701func hasComponent(suiteName, component string) bool {
1702 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1703}
1704
David Benjaminf7768e42014-08-31 02:06:47 -04001705func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001706 return hasComponent(suiteName, "GCM") ||
1707 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001708 hasComponent(suiteName, "SHA384") ||
1709 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001710}
1711
1712func isDTLSCipher(suiteName string) bool {
David Benjamine95d20d2014-12-23 11:16:01 -05001713 return !hasComponent(suiteName, "RC4")
David Benjaminf7768e42014-08-31 02:06:47 -04001714}
1715
Adam Langleya7997f12015-05-14 17:38:50 -07001716func bigFromHex(hex string) *big.Int {
1717 ret, ok := new(big.Int).SetString(hex, 16)
1718 if !ok {
1719 panic("failed to parse hex number 0x" + hex)
1720 }
1721 return ret
1722}
1723
Adam Langley95c29f32014-06-20 12:00:00 -07001724func addCipherSuiteTests() {
1725 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04001726 const psk = "12345"
1727 const pskIdentity = "luggage combo"
1728
Adam Langley95c29f32014-06-20 12:00:00 -07001729 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04001730 var certFile string
1731 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05001732 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07001733 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001734 certFile = ecdsaCertificateFile
1735 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001736 } else {
1737 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001738 certFile = rsaCertificateFile
1739 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001740 }
1741
David Benjamin48cae082014-10-27 01:06:24 -04001742 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05001743 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04001744 flags = append(flags,
1745 "-psk", psk,
1746 "-psk-identity", pskIdentity)
1747 }
1748
Adam Langley95c29f32014-06-20 12:00:00 -07001749 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04001750 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07001751 continue
1752 }
1753
David Benjamin025b3d32014-07-01 19:53:04 -04001754 testCases = append(testCases, testCase{
1755 testType: clientTest,
1756 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07001757 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001758 MinVersion: ver.version,
1759 MaxVersion: ver.version,
1760 CipherSuites: []uint16{suite.id},
1761 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04001762 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04001763 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07001764 },
David Benjamin48cae082014-10-27 01:06:24 -04001765 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001766 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07001767 })
David Benjamin025b3d32014-07-01 19:53:04 -04001768
David Benjamin76d8abe2014-08-14 16:25:34 -04001769 testCases = append(testCases, testCase{
1770 testType: serverTest,
1771 name: ver.name + "-" + suite.name + "-server",
1772 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001773 MinVersion: ver.version,
1774 MaxVersion: ver.version,
1775 CipherSuites: []uint16{suite.id},
1776 Certificates: []Certificate{cert},
1777 PreSharedKey: []byte(psk),
1778 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04001779 },
1780 certFile: certFile,
1781 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04001782 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001783 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04001784 })
David Benjamin6fd297b2014-08-11 18:43:38 -04001785
David Benjamin8b8c0062014-11-23 02:47:52 -05001786 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04001787 testCases = append(testCases, testCase{
1788 testType: clientTest,
1789 protocol: dtls,
1790 name: "D" + ver.name + "-" + suite.name + "-client",
1791 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001792 MinVersion: ver.version,
1793 MaxVersion: ver.version,
1794 CipherSuites: []uint16{suite.id},
1795 Certificates: []Certificate{cert},
1796 PreSharedKey: []byte(psk),
1797 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04001798 },
David Benjamin48cae082014-10-27 01:06:24 -04001799 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001800 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04001801 })
1802 testCases = append(testCases, testCase{
1803 testType: serverTest,
1804 protocol: dtls,
1805 name: "D" + ver.name + "-" + suite.name + "-server",
1806 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001807 MinVersion: ver.version,
1808 MaxVersion: ver.version,
1809 CipherSuites: []uint16{suite.id},
1810 Certificates: []Certificate{cert},
1811 PreSharedKey: []byte(psk),
1812 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04001813 },
1814 certFile: certFile,
1815 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04001816 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001817 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04001818 })
1819 }
Adam Langley95c29f32014-06-20 12:00:00 -07001820 }
1821 }
Adam Langleya7997f12015-05-14 17:38:50 -07001822
1823 testCases = append(testCases, testCase{
1824 name: "WeakDH",
1825 config: Config{
1826 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1827 Bugs: ProtocolBugs{
1828 // This is a 1023-bit prime number, generated
1829 // with:
1830 // openssl gendh 1023 | openssl asn1parse -i
1831 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
1832 },
1833 },
1834 shouldFail: true,
1835 expectedError: "BAD_DH_P_LENGTH",
1836 })
Adam Langley95c29f32014-06-20 12:00:00 -07001837}
1838
1839func addBadECDSASignatureTests() {
1840 for badR := BadValue(1); badR < NumBadValues; badR++ {
1841 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04001842 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07001843 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
1844 config: Config{
1845 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1846 Certificates: []Certificate{getECDSACertificate()},
1847 Bugs: ProtocolBugs{
1848 BadECDSAR: badR,
1849 BadECDSAS: badS,
1850 },
1851 },
1852 shouldFail: true,
1853 expectedError: "SIGNATURE",
1854 })
1855 }
1856 }
1857}
1858
Adam Langley80842bd2014-06-20 12:00:00 -07001859func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04001860 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001861 name: "MaxCBCPadding",
1862 config: Config{
1863 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1864 Bugs: ProtocolBugs{
1865 MaxPadding: true,
1866 },
1867 },
1868 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
1869 })
David Benjamin025b3d32014-07-01 19:53:04 -04001870 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001871 name: "BadCBCPadding",
1872 config: Config{
1873 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1874 Bugs: ProtocolBugs{
1875 PaddingFirstByteBad: true,
1876 },
1877 },
1878 shouldFail: true,
1879 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
1880 })
1881 // OpenSSL previously had an issue where the first byte of padding in
1882 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04001883 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001884 name: "BadCBCPadding255",
1885 config: Config{
1886 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1887 Bugs: ProtocolBugs{
1888 MaxPadding: true,
1889 PaddingFirstByteBadIf255: true,
1890 },
1891 },
1892 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
1893 shouldFail: true,
1894 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
1895 })
1896}
1897
Kenny Root7fdeaf12014-08-05 15:23:37 -07001898func addCBCSplittingTests() {
1899 testCases = append(testCases, testCase{
1900 name: "CBCRecordSplitting",
1901 config: Config{
1902 MaxVersion: VersionTLS10,
1903 MinVersion: VersionTLS10,
1904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1905 },
1906 messageLen: -1, // read until EOF
1907 flags: []string{
1908 "-async",
1909 "-write-different-record-sizes",
1910 "-cbc-record-splitting",
1911 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04001912 })
1913 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07001914 name: "CBCRecordSplittingPartialWrite",
1915 config: Config{
1916 MaxVersion: VersionTLS10,
1917 MinVersion: VersionTLS10,
1918 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1919 },
1920 messageLen: -1, // read until EOF
1921 flags: []string{
1922 "-async",
1923 "-write-different-record-sizes",
1924 "-cbc-record-splitting",
1925 "-partial-write",
1926 },
1927 })
1928}
1929
David Benjamin636293b2014-07-08 17:59:18 -04001930func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04001931 // Add a dummy cert pool to stress certificate authority parsing.
1932 // TODO(davidben): Add tests that those values parse out correctly.
1933 certPool := x509.NewCertPool()
1934 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
1935 if err != nil {
1936 panic(err)
1937 }
1938 certPool.AddCert(cert)
1939
David Benjamin636293b2014-07-08 17:59:18 -04001940 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04001941 testCases = append(testCases, testCase{
1942 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04001943 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04001944 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04001945 MinVersion: ver.version,
1946 MaxVersion: ver.version,
1947 ClientAuth: RequireAnyClientCert,
1948 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04001949 },
1950 flags: []string{
1951 "-cert-file", rsaCertificateFile,
1952 "-key-file", rsaKeyFile,
1953 },
1954 })
1955 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04001956 testType: serverTest,
1957 name: ver.name + "-Server-ClientAuth-RSA",
1958 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04001959 MinVersion: ver.version,
1960 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04001961 Certificates: []Certificate{rsaCertificate},
1962 },
1963 flags: []string{"-require-any-client-certificate"},
1964 })
David Benjamine098ec22014-08-27 23:13:20 -04001965 if ver.version != VersionSSL30 {
1966 testCases = append(testCases, testCase{
1967 testType: serverTest,
1968 name: ver.name + "-Server-ClientAuth-ECDSA",
1969 config: Config{
1970 MinVersion: ver.version,
1971 MaxVersion: ver.version,
1972 Certificates: []Certificate{ecdsaCertificate},
1973 },
1974 flags: []string{"-require-any-client-certificate"},
1975 })
1976 testCases = append(testCases, testCase{
1977 testType: clientTest,
1978 name: ver.name + "-Client-ClientAuth-ECDSA",
1979 config: Config{
1980 MinVersion: ver.version,
1981 MaxVersion: ver.version,
1982 ClientAuth: RequireAnyClientCert,
1983 ClientCAs: certPool,
1984 },
1985 flags: []string{
1986 "-cert-file", ecdsaCertificateFile,
1987 "-key-file", ecdsaKeyFile,
1988 },
1989 })
1990 }
David Benjamin636293b2014-07-08 17:59:18 -04001991 }
1992}
1993
Adam Langley75712922014-10-10 16:23:43 -07001994func addExtendedMasterSecretTests() {
1995 const expectEMSFlag = "-expect-extended-master-secret"
1996
1997 for _, with := range []bool{false, true} {
1998 prefix := "No"
1999 var flags []string
2000 if with {
2001 prefix = ""
2002 flags = []string{expectEMSFlag}
2003 }
2004
2005 for _, isClient := range []bool{false, true} {
2006 suffix := "-Server"
2007 testType := serverTest
2008 if isClient {
2009 suffix = "-Client"
2010 testType = clientTest
2011 }
2012
2013 for _, ver := range tlsVersions {
2014 test := testCase{
2015 testType: testType,
2016 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2017 config: Config{
2018 MinVersion: ver.version,
2019 MaxVersion: ver.version,
2020 Bugs: ProtocolBugs{
2021 NoExtendedMasterSecret: !with,
2022 RequireExtendedMasterSecret: with,
2023 },
2024 },
David Benjamin48cae082014-10-27 01:06:24 -04002025 flags: flags,
2026 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002027 }
2028 if test.shouldFail {
2029 test.expectedLocalError = "extended master secret required but not supported by peer"
2030 }
2031 testCases = append(testCases, test)
2032 }
2033 }
2034 }
2035
Adam Langleyba5934b2015-06-02 10:50:35 -07002036 for _, isClient := range []bool{false, true} {
2037 for _, supportedInFirstConnection := range []bool{false, true} {
2038 for _, supportedInResumeConnection := range []bool{false, true} {
2039 boolToWord := func(b bool) string {
2040 if b {
2041 return "Yes"
2042 }
2043 return "No"
2044 }
2045 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2046 if isClient {
2047 suffix += "Client"
2048 } else {
2049 suffix += "Server"
2050 }
2051
2052 supportedConfig := Config{
2053 Bugs: ProtocolBugs{
2054 RequireExtendedMasterSecret: true,
2055 },
2056 }
2057
2058 noSupportConfig := Config{
2059 Bugs: ProtocolBugs{
2060 NoExtendedMasterSecret: true,
2061 },
2062 }
2063
2064 test := testCase{
2065 name: "ExtendedMasterSecret-" + suffix,
2066 resumeSession: true,
2067 }
2068
2069 if !isClient {
2070 test.testType = serverTest
2071 }
2072
2073 if supportedInFirstConnection {
2074 test.config = supportedConfig
2075 } else {
2076 test.config = noSupportConfig
2077 }
2078
2079 if supportedInResumeConnection {
2080 test.resumeConfig = &supportedConfig
2081 } else {
2082 test.resumeConfig = &noSupportConfig
2083 }
2084
2085 switch suffix {
2086 case "YesToYes-Client", "YesToYes-Server":
2087 // When a session is resumed, it should
2088 // still be aware that its master
2089 // secret was generated via EMS and
2090 // thus it's safe to use tls-unique.
2091 test.flags = []string{expectEMSFlag}
2092 case "NoToYes-Server":
2093 // If an original connection did not
2094 // contain EMS, but a resumption
2095 // handshake does, then a server should
2096 // not resume the session.
2097 test.expectResumeRejected = true
2098 case "YesToNo-Server":
2099 // Resuming an EMS session without the
2100 // EMS extension should cause the
2101 // server to abort the connection.
2102 test.shouldFail = true
2103 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2104 case "NoToYes-Client":
2105 // A client should abort a connection
2106 // where the server resumed a non-EMS
2107 // session but echoed the EMS
2108 // extension.
2109 test.shouldFail = true
2110 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2111 case "YesToNo-Client":
2112 // A client should abort a connection
2113 // where the server didn't echo EMS
2114 // when the session used it.
2115 test.shouldFail = true
2116 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2117 }
2118
2119 testCases = append(testCases, test)
2120 }
2121 }
2122 }
Adam Langley75712922014-10-10 16:23:43 -07002123}
2124
David Benjamin43ec06f2014-08-05 02:28:57 -04002125// Adds tests that try to cover the range of the handshake state machine, under
2126// various conditions. Some of these are redundant with other tests, but they
2127// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002128func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002129 var tests []testCase
2130
2131 // Basic handshake, with resumption. Client and server,
2132 // session ID and session ticket.
2133 tests = append(tests, testCase{
2134 name: "Basic-Client",
2135 resumeSession: true,
2136 })
2137 tests = append(tests, testCase{
2138 name: "Basic-Client-RenewTicket",
2139 config: Config{
2140 Bugs: ProtocolBugs{
2141 RenewTicketOnResume: true,
2142 },
2143 },
2144 resumeSession: true,
2145 })
2146 tests = append(tests, testCase{
2147 name: "Basic-Client-NoTicket",
2148 config: Config{
2149 SessionTicketsDisabled: true,
2150 },
2151 resumeSession: true,
2152 })
2153 tests = append(tests, testCase{
2154 name: "Basic-Client-Implicit",
2155 flags: []string{"-implicit-handshake"},
2156 resumeSession: true,
2157 })
2158 tests = append(tests, testCase{
2159 testType: serverTest,
2160 name: "Basic-Server",
2161 resumeSession: true,
2162 })
2163 tests = append(tests, testCase{
2164 testType: serverTest,
2165 name: "Basic-Server-NoTickets",
2166 config: Config{
2167 SessionTicketsDisabled: true,
2168 },
2169 resumeSession: true,
2170 })
2171 tests = append(tests, testCase{
2172 testType: serverTest,
2173 name: "Basic-Server-Implicit",
2174 flags: []string{"-implicit-handshake"},
2175 resumeSession: true,
2176 })
2177 tests = append(tests, testCase{
2178 testType: serverTest,
2179 name: "Basic-Server-EarlyCallback",
2180 flags: []string{"-use-early-callback"},
2181 resumeSession: true,
2182 })
2183
2184 // TLS client auth.
2185 tests = append(tests, testCase{
2186 testType: clientTest,
2187 name: "ClientAuth-Client",
2188 config: Config{
2189 ClientAuth: RequireAnyClientCert,
2190 },
2191 flags: []string{
2192 "-cert-file", rsaCertificateFile,
2193 "-key-file", rsaKeyFile,
2194 },
2195 })
2196 tests = append(tests, testCase{
2197 testType: serverTest,
2198 name: "ClientAuth-Server",
2199 config: Config{
2200 Certificates: []Certificate{rsaCertificate},
2201 },
2202 flags: []string{"-require-any-client-certificate"},
2203 })
2204
2205 // No session ticket support; server doesn't send NewSessionTicket.
2206 tests = append(tests, testCase{
2207 name: "SessionTicketsDisabled-Client",
2208 config: Config{
2209 SessionTicketsDisabled: true,
2210 },
2211 })
2212 tests = append(tests, testCase{
2213 testType: serverTest,
2214 name: "SessionTicketsDisabled-Server",
2215 config: Config{
2216 SessionTicketsDisabled: true,
2217 },
2218 })
2219
2220 // Skip ServerKeyExchange in PSK key exchange if there's no
2221 // identity hint.
2222 tests = append(tests, testCase{
2223 name: "EmptyPSKHint-Client",
2224 config: Config{
2225 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2226 PreSharedKey: []byte("secret"),
2227 },
2228 flags: []string{"-psk", "secret"},
2229 })
2230 tests = append(tests, testCase{
2231 testType: serverTest,
2232 name: "EmptyPSKHint-Server",
2233 config: Config{
2234 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2235 PreSharedKey: []byte("secret"),
2236 },
2237 flags: []string{"-psk", "secret"},
2238 })
2239
2240 if protocol == tls {
2241 tests = append(tests, testCase{
2242 name: "Renegotiate-Client",
2243 renegotiate: true,
2244 })
2245 // NPN on client and server; results in post-handshake message.
2246 tests = append(tests, testCase{
2247 name: "NPN-Client",
2248 config: Config{
2249 NextProtos: []string{"foo"},
2250 },
2251 flags: []string{"-select-next-proto", "foo"},
2252 expectedNextProto: "foo",
2253 expectedNextProtoType: npn,
2254 })
2255 tests = append(tests, testCase{
2256 testType: serverTest,
2257 name: "NPN-Server",
2258 config: Config{
2259 NextProtos: []string{"bar"},
2260 },
2261 flags: []string{
2262 "-advertise-npn", "\x03foo\x03bar\x03baz",
2263 "-expect-next-proto", "bar",
2264 },
2265 expectedNextProto: "bar",
2266 expectedNextProtoType: npn,
2267 })
2268
2269 // TODO(davidben): Add tests for when False Start doesn't trigger.
2270
2271 // Client does False Start and negotiates NPN.
2272 tests = append(tests, testCase{
2273 name: "FalseStart",
2274 config: Config{
2275 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2276 NextProtos: []string{"foo"},
2277 Bugs: ProtocolBugs{
2278 ExpectFalseStart: true,
2279 },
2280 },
2281 flags: []string{
2282 "-false-start",
2283 "-select-next-proto", "foo",
2284 },
2285 shimWritesFirst: true,
2286 resumeSession: true,
2287 })
2288
2289 // Client does False Start and negotiates ALPN.
2290 tests = append(tests, testCase{
2291 name: "FalseStart-ALPN",
2292 config: Config{
2293 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2294 NextProtos: []string{"foo"},
2295 Bugs: ProtocolBugs{
2296 ExpectFalseStart: true,
2297 },
2298 },
2299 flags: []string{
2300 "-false-start",
2301 "-advertise-alpn", "\x03foo",
2302 },
2303 shimWritesFirst: true,
2304 resumeSession: true,
2305 })
2306
2307 // Client does False Start but doesn't explicitly call
2308 // SSL_connect.
2309 tests = append(tests, testCase{
2310 name: "FalseStart-Implicit",
2311 config: Config{
2312 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2313 NextProtos: []string{"foo"},
2314 },
2315 flags: []string{
2316 "-implicit-handshake",
2317 "-false-start",
2318 "-advertise-alpn", "\x03foo",
2319 },
2320 })
2321
2322 // False Start without session tickets.
2323 tests = append(tests, testCase{
2324 name: "FalseStart-SessionTicketsDisabled",
2325 config: Config{
2326 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2327 NextProtos: []string{"foo"},
2328 SessionTicketsDisabled: true,
2329 Bugs: ProtocolBugs{
2330 ExpectFalseStart: true,
2331 },
2332 },
2333 flags: []string{
2334 "-false-start",
2335 "-select-next-proto", "foo",
2336 },
2337 shimWritesFirst: true,
2338 })
2339
2340 // Server parses a V2ClientHello.
2341 tests = append(tests, testCase{
2342 testType: serverTest,
2343 name: "SendV2ClientHello",
2344 config: Config{
2345 // Choose a cipher suite that does not involve
2346 // elliptic curves, so no extensions are
2347 // involved.
2348 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2349 Bugs: ProtocolBugs{
2350 SendV2ClientHello: true,
2351 },
2352 },
2353 })
2354
2355 // Client sends a Channel ID.
2356 tests = append(tests, testCase{
2357 name: "ChannelID-Client",
2358 config: Config{
2359 RequestChannelID: true,
2360 },
2361 flags: []string{"-send-channel-id", channelIDKeyFile},
2362 resumeSession: true,
2363 expectChannelID: true,
2364 })
2365
2366 // Server accepts a Channel ID.
2367 tests = append(tests, testCase{
2368 testType: serverTest,
2369 name: "ChannelID-Server",
2370 config: Config{
2371 ChannelID: channelIDKey,
2372 },
2373 flags: []string{
2374 "-expect-channel-id",
2375 base64.StdEncoding.EncodeToString(channelIDBytes),
2376 },
2377 resumeSession: true,
2378 expectChannelID: true,
2379 })
2380 } else {
2381 tests = append(tests, testCase{
2382 name: "SkipHelloVerifyRequest",
2383 config: Config{
2384 Bugs: ProtocolBugs{
2385 SkipHelloVerifyRequest: true,
2386 },
2387 },
2388 })
2389 }
2390
David Benjamin43ec06f2014-08-05 02:28:57 -04002391 var suffix string
2392 var flags []string
2393 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04002394 if protocol == dtls {
2395 suffix = "-DTLS"
2396 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002397 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04002398 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04002399 flags = append(flags, "-async")
2400 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04002401 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04002402 }
2403 if splitHandshake {
2404 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04002405 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04002406 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002407 for _, test := range tests {
2408 test.protocol = protocol
2409 test.name += suffix
2410 test.config.Bugs.MaxHandshakeRecordLength = maxHandshakeRecordLength
2411 test.flags = append(test.flags, flags...)
2412 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002413 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002414}
2415
Adam Langley524e7172015-02-20 16:04:00 -08002416func addDDoSCallbackTests() {
2417 // DDoS callback.
2418
2419 for _, resume := range []bool{false, true} {
2420 suffix := "Resume"
2421 if resume {
2422 suffix = "No" + suffix
2423 }
2424
2425 testCases = append(testCases, testCase{
2426 testType: serverTest,
2427 name: "Server-DDoS-OK-" + suffix,
2428 flags: []string{"-install-ddos-callback"},
2429 resumeSession: resume,
2430 })
2431
2432 failFlag := "-fail-ddos-callback"
2433 if resume {
2434 failFlag = "-fail-second-ddos-callback"
2435 }
2436 testCases = append(testCases, testCase{
2437 testType: serverTest,
2438 name: "Server-DDoS-Reject-" + suffix,
2439 flags: []string{"-install-ddos-callback", failFlag},
2440 resumeSession: resume,
2441 shouldFail: true,
2442 expectedError: ":CONNECTION_REJECTED:",
2443 })
2444 }
2445}
2446
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002447func addVersionNegotiationTests() {
2448 for i, shimVers := range tlsVersions {
2449 // Assemble flags to disable all newer versions on the shim.
2450 var flags []string
2451 for _, vers := range tlsVersions[i+1:] {
2452 flags = append(flags, vers.flag)
2453 }
2454
2455 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002456 protocols := []protocol{tls}
2457 if runnerVers.hasDTLS && shimVers.hasDTLS {
2458 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002459 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002460 for _, protocol := range protocols {
2461 expectedVersion := shimVers.version
2462 if runnerVers.version < shimVers.version {
2463 expectedVersion = runnerVers.version
2464 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002465
David Benjamin8b8c0062014-11-23 02:47:52 -05002466 suffix := shimVers.name + "-" + runnerVers.name
2467 if protocol == dtls {
2468 suffix += "-DTLS"
2469 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002470
David Benjamin1eb367c2014-12-12 18:17:51 -05002471 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2472
David Benjamin1e29a6b2014-12-10 02:27:24 -05002473 clientVers := shimVers.version
2474 if clientVers > VersionTLS10 {
2475 clientVers = VersionTLS10
2476 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002477 testCases = append(testCases, testCase{
2478 protocol: protocol,
2479 testType: clientTest,
2480 name: "VersionNegotiation-Client-" + suffix,
2481 config: Config{
2482 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002483 Bugs: ProtocolBugs{
2484 ExpectInitialRecordVersion: clientVers,
2485 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002486 },
2487 flags: flags,
2488 expectedVersion: expectedVersion,
2489 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002490 testCases = append(testCases, testCase{
2491 protocol: protocol,
2492 testType: clientTest,
2493 name: "VersionNegotiation-Client2-" + suffix,
2494 config: Config{
2495 MaxVersion: runnerVers.version,
2496 Bugs: ProtocolBugs{
2497 ExpectInitialRecordVersion: clientVers,
2498 },
2499 },
2500 flags: []string{"-max-version", shimVersFlag},
2501 expectedVersion: expectedVersion,
2502 })
David Benjamin8b8c0062014-11-23 02:47:52 -05002503
2504 testCases = append(testCases, testCase{
2505 protocol: protocol,
2506 testType: serverTest,
2507 name: "VersionNegotiation-Server-" + suffix,
2508 config: Config{
2509 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002510 Bugs: ProtocolBugs{
2511 ExpectInitialRecordVersion: expectedVersion,
2512 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002513 },
2514 flags: flags,
2515 expectedVersion: expectedVersion,
2516 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002517 testCases = append(testCases, testCase{
2518 protocol: protocol,
2519 testType: serverTest,
2520 name: "VersionNegotiation-Server2-" + suffix,
2521 config: Config{
2522 MaxVersion: runnerVers.version,
2523 Bugs: ProtocolBugs{
2524 ExpectInitialRecordVersion: expectedVersion,
2525 },
2526 },
2527 flags: []string{"-max-version", shimVersFlag},
2528 expectedVersion: expectedVersion,
2529 })
David Benjamin8b8c0062014-11-23 02:47:52 -05002530 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002531 }
2532 }
2533}
2534
David Benjaminaccb4542014-12-12 23:44:33 -05002535func addMinimumVersionTests() {
2536 for i, shimVers := range tlsVersions {
2537 // Assemble flags to disable all older versions on the shim.
2538 var flags []string
2539 for _, vers := range tlsVersions[:i] {
2540 flags = append(flags, vers.flag)
2541 }
2542
2543 for _, runnerVers := range tlsVersions {
2544 protocols := []protocol{tls}
2545 if runnerVers.hasDTLS && shimVers.hasDTLS {
2546 protocols = append(protocols, dtls)
2547 }
2548 for _, protocol := range protocols {
2549 suffix := shimVers.name + "-" + runnerVers.name
2550 if protocol == dtls {
2551 suffix += "-DTLS"
2552 }
2553 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2554
David Benjaminaccb4542014-12-12 23:44:33 -05002555 var expectedVersion uint16
2556 var shouldFail bool
2557 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05002558 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05002559 if runnerVers.version >= shimVers.version {
2560 expectedVersion = runnerVers.version
2561 } else {
2562 shouldFail = true
2563 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05002564 if runnerVers.version > VersionSSL30 {
2565 expectedLocalError = "remote error: protocol version not supported"
2566 } else {
2567 expectedLocalError = "remote error: handshake failure"
2568 }
David Benjaminaccb4542014-12-12 23:44:33 -05002569 }
2570
2571 testCases = append(testCases, testCase{
2572 protocol: protocol,
2573 testType: clientTest,
2574 name: "MinimumVersion-Client-" + suffix,
2575 config: Config{
2576 MaxVersion: runnerVers.version,
2577 },
David Benjamin87909c02014-12-13 01:55:01 -05002578 flags: flags,
2579 expectedVersion: expectedVersion,
2580 shouldFail: shouldFail,
2581 expectedError: expectedError,
2582 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002583 })
2584 testCases = append(testCases, testCase{
2585 protocol: protocol,
2586 testType: clientTest,
2587 name: "MinimumVersion-Client2-" + suffix,
2588 config: Config{
2589 MaxVersion: runnerVers.version,
2590 },
David Benjamin87909c02014-12-13 01:55:01 -05002591 flags: []string{"-min-version", shimVersFlag},
2592 expectedVersion: expectedVersion,
2593 shouldFail: shouldFail,
2594 expectedError: expectedError,
2595 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002596 })
2597
2598 testCases = append(testCases, testCase{
2599 protocol: protocol,
2600 testType: serverTest,
2601 name: "MinimumVersion-Server-" + suffix,
2602 config: Config{
2603 MaxVersion: runnerVers.version,
2604 },
David Benjamin87909c02014-12-13 01:55:01 -05002605 flags: flags,
2606 expectedVersion: expectedVersion,
2607 shouldFail: shouldFail,
2608 expectedError: expectedError,
2609 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002610 })
2611 testCases = append(testCases, testCase{
2612 protocol: protocol,
2613 testType: serverTest,
2614 name: "MinimumVersion-Server2-" + suffix,
2615 config: Config{
2616 MaxVersion: runnerVers.version,
2617 },
David Benjamin87909c02014-12-13 01:55:01 -05002618 flags: []string{"-min-version", shimVersFlag},
2619 expectedVersion: expectedVersion,
2620 shouldFail: shouldFail,
2621 expectedError: expectedError,
2622 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002623 })
2624 }
2625 }
2626 }
2627}
2628
David Benjamin5c24a1d2014-08-31 00:59:27 -04002629func addD5BugTests() {
2630 testCases = append(testCases, testCase{
2631 testType: serverTest,
2632 name: "D5Bug-NoQuirk-Reject",
2633 config: Config{
2634 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2635 Bugs: ProtocolBugs{
2636 SSL3RSAKeyExchange: true,
2637 },
2638 },
2639 shouldFail: true,
2640 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
2641 })
2642 testCases = append(testCases, testCase{
2643 testType: serverTest,
2644 name: "D5Bug-Quirk-Normal",
2645 config: Config{
2646 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2647 },
2648 flags: []string{"-tls-d5-bug"},
2649 })
2650 testCases = append(testCases, testCase{
2651 testType: serverTest,
2652 name: "D5Bug-Quirk-Bug",
2653 config: Config{
2654 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2655 Bugs: ProtocolBugs{
2656 SSL3RSAKeyExchange: true,
2657 },
2658 },
2659 flags: []string{"-tls-d5-bug"},
2660 })
2661}
2662
David Benjamine78bfde2014-09-06 12:45:15 -04002663func addExtensionTests() {
2664 testCases = append(testCases, testCase{
2665 testType: clientTest,
2666 name: "DuplicateExtensionClient",
2667 config: Config{
2668 Bugs: ProtocolBugs{
2669 DuplicateExtension: true,
2670 },
2671 },
2672 shouldFail: true,
2673 expectedLocalError: "remote error: error decoding message",
2674 })
2675 testCases = append(testCases, testCase{
2676 testType: serverTest,
2677 name: "DuplicateExtensionServer",
2678 config: Config{
2679 Bugs: ProtocolBugs{
2680 DuplicateExtension: true,
2681 },
2682 },
2683 shouldFail: true,
2684 expectedLocalError: "remote error: error decoding message",
2685 })
2686 testCases = append(testCases, testCase{
2687 testType: clientTest,
2688 name: "ServerNameExtensionClient",
2689 config: Config{
2690 Bugs: ProtocolBugs{
2691 ExpectServerName: "example.com",
2692 },
2693 },
2694 flags: []string{"-host-name", "example.com"},
2695 })
2696 testCases = append(testCases, testCase{
2697 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05002698 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04002699 config: Config{
2700 Bugs: ProtocolBugs{
2701 ExpectServerName: "mismatch.com",
2702 },
2703 },
2704 flags: []string{"-host-name", "example.com"},
2705 shouldFail: true,
2706 expectedLocalError: "tls: unexpected server name",
2707 })
2708 testCases = append(testCases, testCase{
2709 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05002710 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04002711 config: Config{
2712 Bugs: ProtocolBugs{
2713 ExpectServerName: "missing.com",
2714 },
2715 },
2716 shouldFail: true,
2717 expectedLocalError: "tls: unexpected server name",
2718 })
2719 testCases = append(testCases, testCase{
2720 testType: serverTest,
2721 name: "ServerNameExtensionServer",
2722 config: Config{
2723 ServerName: "example.com",
2724 },
2725 flags: []string{"-expect-server-name", "example.com"},
2726 resumeSession: true,
2727 })
David Benjaminae2888f2014-09-06 12:58:58 -04002728 testCases = append(testCases, testCase{
2729 testType: clientTest,
2730 name: "ALPNClient",
2731 config: Config{
2732 NextProtos: []string{"foo"},
2733 },
2734 flags: []string{
2735 "-advertise-alpn", "\x03foo\x03bar\x03baz",
2736 "-expect-alpn", "foo",
2737 },
David Benjaminfc7b0862014-09-06 13:21:53 -04002738 expectedNextProto: "foo",
2739 expectedNextProtoType: alpn,
2740 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04002741 })
2742 testCases = append(testCases, testCase{
2743 testType: serverTest,
2744 name: "ALPNServer",
2745 config: Config{
2746 NextProtos: []string{"foo", "bar", "baz"},
2747 },
2748 flags: []string{
2749 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2750 "-select-alpn", "foo",
2751 },
David Benjaminfc7b0862014-09-06 13:21:53 -04002752 expectedNextProto: "foo",
2753 expectedNextProtoType: alpn,
2754 resumeSession: true,
2755 })
2756 // Test that the server prefers ALPN over NPN.
2757 testCases = append(testCases, testCase{
2758 testType: serverTest,
2759 name: "ALPNServer-Preferred",
2760 config: Config{
2761 NextProtos: []string{"foo", "bar", "baz"},
2762 },
2763 flags: []string{
2764 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2765 "-select-alpn", "foo",
2766 "-advertise-npn", "\x03foo\x03bar\x03baz",
2767 },
2768 expectedNextProto: "foo",
2769 expectedNextProtoType: alpn,
2770 resumeSession: true,
2771 })
2772 testCases = append(testCases, testCase{
2773 testType: serverTest,
2774 name: "ALPNServer-Preferred-Swapped",
2775 config: Config{
2776 NextProtos: []string{"foo", "bar", "baz"},
2777 Bugs: ProtocolBugs{
2778 SwapNPNAndALPN: true,
2779 },
2780 },
2781 flags: []string{
2782 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2783 "-select-alpn", "foo",
2784 "-advertise-npn", "\x03foo\x03bar\x03baz",
2785 },
2786 expectedNextProto: "foo",
2787 expectedNextProtoType: alpn,
2788 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04002789 })
Adam Langley38311732014-10-16 19:04:35 -07002790 // Resume with a corrupt ticket.
2791 testCases = append(testCases, testCase{
2792 testType: serverTest,
2793 name: "CorruptTicket",
2794 config: Config{
2795 Bugs: ProtocolBugs{
2796 CorruptTicket: true,
2797 },
2798 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07002799 resumeSession: true,
2800 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07002801 })
2802 // Resume with an oversized session id.
2803 testCases = append(testCases, testCase{
2804 testType: serverTest,
2805 name: "OversizedSessionId",
2806 config: Config{
2807 Bugs: ProtocolBugs{
2808 OversizedSessionId: true,
2809 },
2810 },
2811 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07002812 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07002813 expectedError: ":DECODE_ERROR:",
2814 })
David Benjaminca6c8262014-11-15 19:06:08 -05002815 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
2816 // are ignored.
2817 testCases = append(testCases, testCase{
2818 protocol: dtls,
2819 name: "SRTP-Client",
2820 config: Config{
2821 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
2822 },
2823 flags: []string{
2824 "-srtp-profiles",
2825 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2826 },
2827 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
2828 })
2829 testCases = append(testCases, testCase{
2830 protocol: dtls,
2831 testType: serverTest,
2832 name: "SRTP-Server",
2833 config: Config{
2834 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
2835 },
2836 flags: []string{
2837 "-srtp-profiles",
2838 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2839 },
2840 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
2841 })
2842 // Test that the MKI is ignored.
2843 testCases = append(testCases, testCase{
2844 protocol: dtls,
2845 testType: serverTest,
2846 name: "SRTP-Server-IgnoreMKI",
2847 config: Config{
2848 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
2849 Bugs: ProtocolBugs{
2850 SRTPMasterKeyIdentifer: "bogus",
2851 },
2852 },
2853 flags: []string{
2854 "-srtp-profiles",
2855 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2856 },
2857 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
2858 })
2859 // Test that SRTP isn't negotiated on the server if there were
2860 // no matching profiles.
2861 testCases = append(testCases, testCase{
2862 protocol: dtls,
2863 testType: serverTest,
2864 name: "SRTP-Server-NoMatch",
2865 config: Config{
2866 SRTPProtectionProfiles: []uint16{100, 101, 102},
2867 },
2868 flags: []string{
2869 "-srtp-profiles",
2870 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2871 },
2872 expectedSRTPProtectionProfile: 0,
2873 })
2874 // Test that the server returning an invalid SRTP profile is
2875 // flagged as an error by the client.
2876 testCases = append(testCases, testCase{
2877 protocol: dtls,
2878 name: "SRTP-Client-NoMatch",
2879 config: Config{
2880 Bugs: ProtocolBugs{
2881 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
2882 },
2883 },
2884 flags: []string{
2885 "-srtp-profiles",
2886 "SRTP_AES128_CM_SHA1_80",
2887 },
2888 shouldFail: true,
2889 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
2890 })
David Benjamin61f95272014-11-25 01:55:35 -05002891 // Test OCSP stapling and SCT list.
2892 testCases = append(testCases, testCase{
2893 name: "OCSPStapling",
2894 flags: []string{
2895 "-enable-ocsp-stapling",
2896 "-expect-ocsp-response",
2897 base64.StdEncoding.EncodeToString(testOCSPResponse),
2898 },
2899 })
2900 testCases = append(testCases, testCase{
2901 name: "SignedCertificateTimestampList",
2902 flags: []string{
2903 "-enable-signed-cert-timestamps",
2904 "-expect-signed-cert-timestamps",
2905 base64.StdEncoding.EncodeToString(testSCTList),
2906 },
2907 })
David Benjamine78bfde2014-09-06 12:45:15 -04002908}
2909
David Benjamin01fe8202014-09-24 15:21:44 -04002910func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04002911 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04002912 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002913 protocols := []protocol{tls}
2914 if sessionVers.hasDTLS && resumeVers.hasDTLS {
2915 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05002916 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002917 for _, protocol := range protocols {
2918 suffix := "-" + sessionVers.name + "-" + resumeVers.name
2919 if protocol == dtls {
2920 suffix += "-DTLS"
2921 }
2922
David Benjaminece3de92015-03-16 18:02:20 -04002923 if sessionVers.version == resumeVers.version {
2924 testCases = append(testCases, testCase{
2925 protocol: protocol,
2926 name: "Resume-Client" + suffix,
2927 resumeSession: true,
2928 config: Config{
2929 MaxVersion: sessionVers.version,
2930 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05002931 },
David Benjaminece3de92015-03-16 18:02:20 -04002932 expectedVersion: sessionVers.version,
2933 expectedResumeVersion: resumeVers.version,
2934 })
2935 } else {
2936 testCases = append(testCases, testCase{
2937 protocol: protocol,
2938 name: "Resume-Client-Mismatch" + suffix,
2939 resumeSession: true,
2940 config: Config{
2941 MaxVersion: sessionVers.version,
2942 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05002943 },
David Benjaminece3de92015-03-16 18:02:20 -04002944 expectedVersion: sessionVers.version,
2945 resumeConfig: &Config{
2946 MaxVersion: resumeVers.version,
2947 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2948 Bugs: ProtocolBugs{
2949 AllowSessionVersionMismatch: true,
2950 },
2951 },
2952 expectedResumeVersion: resumeVers.version,
2953 shouldFail: true,
2954 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
2955 })
2956 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002957
2958 testCases = append(testCases, testCase{
2959 protocol: protocol,
2960 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05002961 resumeSession: true,
2962 config: Config{
2963 MaxVersion: sessionVers.version,
2964 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2965 },
2966 expectedVersion: sessionVers.version,
2967 resumeConfig: &Config{
2968 MaxVersion: resumeVers.version,
2969 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2970 },
2971 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07002972 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05002973 expectedResumeVersion: resumeVers.version,
2974 })
2975
David Benjamin8b8c0062014-11-23 02:47:52 -05002976 testCases = append(testCases, testCase{
2977 protocol: protocol,
2978 testType: serverTest,
2979 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05002980 resumeSession: true,
2981 config: Config{
2982 MaxVersion: sessionVers.version,
2983 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2984 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07002985 expectedVersion: sessionVers.version,
2986 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05002987 resumeConfig: &Config{
2988 MaxVersion: resumeVers.version,
2989 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
2990 },
2991 expectedResumeVersion: resumeVers.version,
2992 })
2993 }
David Benjamin01fe8202014-09-24 15:21:44 -04002994 }
2995 }
David Benjaminece3de92015-03-16 18:02:20 -04002996
2997 testCases = append(testCases, testCase{
2998 name: "Resume-Client-CipherMismatch",
2999 resumeSession: true,
3000 config: Config{
3001 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3002 },
3003 resumeConfig: &Config{
3004 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3005 Bugs: ProtocolBugs{
3006 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3007 },
3008 },
3009 shouldFail: true,
3010 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3011 })
David Benjamin01fe8202014-09-24 15:21:44 -04003012}
3013
Adam Langley2ae77d22014-10-28 17:29:33 -07003014func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003015 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003016 testCases = append(testCases, testCase{
3017 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003018 name: "Renegotiate-Server-Forbidden",
David Benjaminb16346b2015-04-08 19:16:58 -04003019 renegotiate: true,
3020 flags: []string{"-reject-peer-renegotiations"},
3021 shouldFail: true,
3022 expectedError: ":NO_RENEGOTIATION:",
3023 expectedLocalError: "remote error: no renegotiation",
3024 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003025 // TODO(agl): test the renegotiation info SCSV.
Adam Langleycf2d4f42014-10-28 19:06:14 -07003026 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003027 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003028 config: Config{
3029 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003030 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003031 },
3032 },
3033 renegotiate: true,
3034 })
3035 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003036 name: "Renegotiate-Client-EmptyExt",
3037 renegotiate: true,
3038 config: Config{
3039 Bugs: ProtocolBugs{
3040 EmptyRenegotiationInfo: true,
3041 },
3042 },
3043 shouldFail: true,
3044 expectedError: ":RENEGOTIATION_MISMATCH:",
3045 })
3046 testCases = append(testCases, testCase{
3047 name: "Renegotiate-Client-BadExt",
3048 renegotiate: true,
3049 config: Config{
3050 Bugs: ProtocolBugs{
3051 BadRenegotiationInfo: true,
3052 },
3053 },
3054 shouldFail: true,
3055 expectedError: ":RENEGOTIATION_MISMATCH:",
3056 })
3057 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04003058 name: "Renegotiate-Client-NoExt",
3059 renegotiate: true,
3060 config: Config{
3061 Bugs: ProtocolBugs{
3062 NoRenegotiationInfo: true,
3063 },
3064 },
3065 shouldFail: true,
3066 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3067 flags: []string{"-no-legacy-server-connect"},
3068 })
3069 testCases = append(testCases, testCase{
3070 name: "Renegotiate-Client-NoExt-Allowed",
3071 renegotiate: true,
3072 config: Config{
3073 Bugs: ProtocolBugs{
3074 NoRenegotiationInfo: true,
3075 },
3076 },
3077 })
3078 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003079 name: "Renegotiate-Client-SwitchCiphers",
3080 renegotiate: true,
3081 config: Config{
3082 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3083 },
3084 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3085 })
3086 testCases = append(testCases, testCase{
3087 name: "Renegotiate-Client-SwitchCiphers2",
3088 renegotiate: true,
3089 config: Config{
3090 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3091 },
3092 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3093 })
David Benjaminc44b1df2014-11-23 12:11:01 -05003094 testCases = append(testCases, testCase{
David Benjaminb16346b2015-04-08 19:16:58 -04003095 name: "Renegotiate-Client-Forbidden",
3096 renegotiate: true,
3097 flags: []string{"-reject-peer-renegotiations"},
3098 shouldFail: true,
3099 expectedError: ":NO_RENEGOTIATION:",
3100 expectedLocalError: "remote error: no renegotiation",
3101 })
3102 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003103 name: "Renegotiate-SameClientVersion",
3104 renegotiate: true,
3105 config: Config{
3106 MaxVersion: VersionTLS10,
3107 Bugs: ProtocolBugs{
3108 RequireSameRenegoClientVersion: true,
3109 },
3110 },
3111 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003112}
3113
David Benjamin5e961c12014-11-07 01:48:35 -05003114func addDTLSReplayTests() {
3115 // Test that sequence number replays are detected.
3116 testCases = append(testCases, testCase{
3117 protocol: dtls,
3118 name: "DTLS-Replay",
3119 replayWrites: true,
3120 })
3121
3122 // Test the outgoing sequence number skipping by values larger
3123 // than the retransmit window.
3124 testCases = append(testCases, testCase{
3125 protocol: dtls,
3126 name: "DTLS-Replay-LargeGaps",
3127 config: Config{
3128 Bugs: ProtocolBugs{
3129 SequenceNumberIncrement: 127,
3130 },
3131 },
3132 replayWrites: true,
3133 })
3134}
3135
Feng Lu41aa3252014-11-21 22:47:56 -08003136func addFastRadioPaddingTests() {
David Benjamin1e29a6b2014-12-10 02:27:24 -05003137 testCases = append(testCases, testCase{
3138 protocol: tls,
3139 name: "FastRadio-Padding",
Feng Lu41aa3252014-11-21 22:47:56 -08003140 config: Config{
3141 Bugs: ProtocolBugs{
3142 RequireFastradioPadding: true,
3143 },
3144 },
David Benjamin1e29a6b2014-12-10 02:27:24 -05003145 flags: []string{"-fastradio-padding"},
Feng Lu41aa3252014-11-21 22:47:56 -08003146 })
David Benjamin1e29a6b2014-12-10 02:27:24 -05003147 testCases = append(testCases, testCase{
3148 protocol: dtls,
David Benjamin5f237bc2015-02-11 17:14:15 -05003149 name: "FastRadio-Padding-DTLS",
Feng Lu41aa3252014-11-21 22:47:56 -08003150 config: Config{
3151 Bugs: ProtocolBugs{
3152 RequireFastradioPadding: true,
3153 },
3154 },
David Benjamin1e29a6b2014-12-10 02:27:24 -05003155 flags: []string{"-fastradio-padding"},
Feng Lu41aa3252014-11-21 22:47:56 -08003156 })
3157}
3158
David Benjamin000800a2014-11-14 01:43:59 -05003159var testHashes = []struct {
3160 name string
3161 id uint8
3162}{
3163 {"SHA1", hashSHA1},
3164 {"SHA224", hashSHA224},
3165 {"SHA256", hashSHA256},
3166 {"SHA384", hashSHA384},
3167 {"SHA512", hashSHA512},
3168}
3169
3170func addSigningHashTests() {
3171 // Make sure each hash works. Include some fake hashes in the list and
3172 // ensure they're ignored.
3173 for _, hash := range testHashes {
3174 testCases = append(testCases, testCase{
3175 name: "SigningHash-ClientAuth-" + hash.name,
3176 config: Config{
3177 ClientAuth: RequireAnyClientCert,
3178 SignatureAndHashes: []signatureAndHash{
3179 {signatureRSA, 42},
3180 {signatureRSA, hash.id},
3181 {signatureRSA, 255},
3182 },
3183 },
3184 flags: []string{
3185 "-cert-file", rsaCertificateFile,
3186 "-key-file", rsaKeyFile,
3187 },
3188 })
3189
3190 testCases = append(testCases, testCase{
3191 testType: serverTest,
3192 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
3193 config: Config{
3194 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3195 SignatureAndHashes: []signatureAndHash{
3196 {signatureRSA, 42},
3197 {signatureRSA, hash.id},
3198 {signatureRSA, 255},
3199 },
3200 },
3201 })
3202 }
3203
3204 // Test that hash resolution takes the signature type into account.
3205 testCases = append(testCases, testCase{
3206 name: "SigningHash-ClientAuth-SignatureType",
3207 config: Config{
3208 ClientAuth: RequireAnyClientCert,
3209 SignatureAndHashes: []signatureAndHash{
3210 {signatureECDSA, hashSHA512},
3211 {signatureRSA, hashSHA384},
3212 {signatureECDSA, hashSHA1},
3213 },
3214 },
3215 flags: []string{
3216 "-cert-file", rsaCertificateFile,
3217 "-key-file", rsaKeyFile,
3218 },
3219 })
3220
3221 testCases = append(testCases, testCase{
3222 testType: serverTest,
3223 name: "SigningHash-ServerKeyExchange-SignatureType",
3224 config: Config{
3225 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3226 SignatureAndHashes: []signatureAndHash{
3227 {signatureECDSA, hashSHA512},
3228 {signatureRSA, hashSHA384},
3229 {signatureECDSA, hashSHA1},
3230 },
3231 },
3232 })
3233
3234 // Test that, if the list is missing, the peer falls back to SHA-1.
3235 testCases = append(testCases, testCase{
3236 name: "SigningHash-ClientAuth-Fallback",
3237 config: Config{
3238 ClientAuth: RequireAnyClientCert,
3239 SignatureAndHashes: []signatureAndHash{
3240 {signatureRSA, hashSHA1},
3241 },
3242 Bugs: ProtocolBugs{
3243 NoSignatureAndHashes: true,
3244 },
3245 },
3246 flags: []string{
3247 "-cert-file", rsaCertificateFile,
3248 "-key-file", rsaKeyFile,
3249 },
3250 })
3251
3252 testCases = append(testCases, testCase{
3253 testType: serverTest,
3254 name: "SigningHash-ServerKeyExchange-Fallback",
3255 config: Config{
3256 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3257 SignatureAndHashes: []signatureAndHash{
3258 {signatureRSA, hashSHA1},
3259 },
3260 Bugs: ProtocolBugs{
3261 NoSignatureAndHashes: true,
3262 },
3263 },
3264 })
David Benjamin72dc7832015-03-16 17:49:43 -04003265
3266 // Test that hash preferences are enforced. BoringSSL defaults to
3267 // rejecting MD5 signatures.
3268 testCases = append(testCases, testCase{
3269 testType: serverTest,
3270 name: "SigningHash-ClientAuth-Enforced",
3271 config: Config{
3272 Certificates: []Certificate{rsaCertificate},
3273 SignatureAndHashes: []signatureAndHash{
3274 {signatureRSA, hashMD5},
3275 // Advertise SHA-1 so the handshake will
3276 // proceed, but the shim's preferences will be
3277 // ignored in CertificateVerify generation, so
3278 // MD5 will be chosen.
3279 {signatureRSA, hashSHA1},
3280 },
3281 Bugs: ProtocolBugs{
3282 IgnorePeerSignatureAlgorithmPreferences: true,
3283 },
3284 },
3285 flags: []string{"-require-any-client-certificate"},
3286 shouldFail: true,
3287 expectedError: ":WRONG_SIGNATURE_TYPE:",
3288 })
3289
3290 testCases = append(testCases, testCase{
3291 name: "SigningHash-ServerKeyExchange-Enforced",
3292 config: Config{
3293 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3294 SignatureAndHashes: []signatureAndHash{
3295 {signatureRSA, hashMD5},
3296 },
3297 Bugs: ProtocolBugs{
3298 IgnorePeerSignatureAlgorithmPreferences: true,
3299 },
3300 },
3301 shouldFail: true,
3302 expectedError: ":WRONG_SIGNATURE_TYPE:",
3303 })
David Benjamin000800a2014-11-14 01:43:59 -05003304}
3305
David Benjamin83f90402015-01-27 01:09:43 -05003306// timeouts is the retransmit schedule for BoringSSL. It doubles and
3307// caps at 60 seconds. On the 13th timeout, it gives up.
3308var timeouts = []time.Duration{
3309 1 * time.Second,
3310 2 * time.Second,
3311 4 * time.Second,
3312 8 * time.Second,
3313 16 * time.Second,
3314 32 * time.Second,
3315 60 * time.Second,
3316 60 * time.Second,
3317 60 * time.Second,
3318 60 * time.Second,
3319 60 * time.Second,
3320 60 * time.Second,
3321 60 * time.Second,
3322}
3323
3324func addDTLSRetransmitTests() {
3325 // Test that this is indeed the timeout schedule. Stress all
3326 // four patterns of handshake.
3327 for i := 1; i < len(timeouts); i++ {
3328 number := strconv.Itoa(i)
3329 testCases = append(testCases, testCase{
3330 protocol: dtls,
3331 name: "DTLS-Retransmit-Client-" + number,
3332 config: Config{
3333 Bugs: ProtocolBugs{
3334 TimeoutSchedule: timeouts[:i],
3335 },
3336 },
3337 resumeSession: true,
3338 flags: []string{"-async"},
3339 })
3340 testCases = append(testCases, testCase{
3341 protocol: dtls,
3342 testType: serverTest,
3343 name: "DTLS-Retransmit-Server-" + number,
3344 config: Config{
3345 Bugs: ProtocolBugs{
3346 TimeoutSchedule: timeouts[:i],
3347 },
3348 },
3349 resumeSession: true,
3350 flags: []string{"-async"},
3351 })
3352 }
3353
3354 // Test that exceeding the timeout schedule hits a read
3355 // timeout.
3356 testCases = append(testCases, testCase{
3357 protocol: dtls,
3358 name: "DTLS-Retransmit-Timeout",
3359 config: Config{
3360 Bugs: ProtocolBugs{
3361 TimeoutSchedule: timeouts,
3362 },
3363 },
3364 resumeSession: true,
3365 flags: []string{"-async"},
3366 shouldFail: true,
3367 expectedError: ":READ_TIMEOUT_EXPIRED:",
3368 })
3369
3370 // Test that timeout handling has a fudge factor, due to API
3371 // problems.
3372 testCases = append(testCases, testCase{
3373 protocol: dtls,
3374 name: "DTLS-Retransmit-Fudge",
3375 config: Config{
3376 Bugs: ProtocolBugs{
3377 TimeoutSchedule: []time.Duration{
3378 timeouts[0] - 10*time.Millisecond,
3379 },
3380 },
3381 },
3382 resumeSession: true,
3383 flags: []string{"-async"},
3384 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05003385
3386 // Test that the final Finished retransmitting isn't
3387 // duplicated if the peer badly fragments everything.
3388 testCases = append(testCases, testCase{
3389 testType: serverTest,
3390 protocol: dtls,
3391 name: "DTLS-Retransmit-Fragmented",
3392 config: Config{
3393 Bugs: ProtocolBugs{
3394 TimeoutSchedule: []time.Duration{timeouts[0]},
3395 MaxHandshakeRecordLength: 2,
3396 },
3397 },
3398 flags: []string{"-async"},
3399 })
David Benjamin83f90402015-01-27 01:09:43 -05003400}
3401
David Benjaminc565ebb2015-04-03 04:06:36 -04003402func addExportKeyingMaterialTests() {
3403 for _, vers := range tlsVersions {
3404 if vers.version == VersionSSL30 {
3405 continue
3406 }
3407 testCases = append(testCases, testCase{
3408 name: "ExportKeyingMaterial-" + vers.name,
3409 config: Config{
3410 MaxVersion: vers.version,
3411 },
3412 exportKeyingMaterial: 1024,
3413 exportLabel: "label",
3414 exportContext: "context",
3415 useExportContext: true,
3416 })
3417 testCases = append(testCases, testCase{
3418 name: "ExportKeyingMaterial-NoContext-" + vers.name,
3419 config: Config{
3420 MaxVersion: vers.version,
3421 },
3422 exportKeyingMaterial: 1024,
3423 })
3424 testCases = append(testCases, testCase{
3425 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
3426 config: Config{
3427 MaxVersion: vers.version,
3428 },
3429 exportKeyingMaterial: 1024,
3430 useExportContext: true,
3431 })
3432 testCases = append(testCases, testCase{
3433 name: "ExportKeyingMaterial-Small-" + vers.name,
3434 config: Config{
3435 MaxVersion: vers.version,
3436 },
3437 exportKeyingMaterial: 1,
3438 exportLabel: "label",
3439 exportContext: "context",
3440 useExportContext: true,
3441 })
3442 }
3443 testCases = append(testCases, testCase{
3444 name: "ExportKeyingMaterial-SSL3",
3445 config: Config{
3446 MaxVersion: VersionSSL30,
3447 },
3448 exportKeyingMaterial: 1024,
3449 exportLabel: "label",
3450 exportContext: "context",
3451 useExportContext: true,
3452 shouldFail: true,
3453 expectedError: "failed to export keying material",
3454 })
3455}
3456
Adam Langleyaf0e32c2015-06-03 09:57:23 -07003457func addTLSUniqueTests() {
3458 for _, isClient := range []bool{false, true} {
3459 for _, isResumption := range []bool{false, true} {
3460 for _, hasEMS := range []bool{false, true} {
3461 var suffix string
3462 if isResumption {
3463 suffix = "Resume-"
3464 } else {
3465 suffix = "Full-"
3466 }
3467
3468 if hasEMS {
3469 suffix += "EMS-"
3470 } else {
3471 suffix += "NoEMS-"
3472 }
3473
3474 if isClient {
3475 suffix += "Client"
3476 } else {
3477 suffix += "Server"
3478 }
3479
3480 test := testCase{
3481 name: "TLSUnique-" + suffix,
3482 testTLSUnique: true,
3483 config: Config{
3484 Bugs: ProtocolBugs{
3485 NoExtendedMasterSecret: !hasEMS,
3486 },
3487 },
3488 }
3489
3490 if isResumption {
3491 test.resumeSession = true
3492 test.resumeConfig = &Config{
3493 Bugs: ProtocolBugs{
3494 NoExtendedMasterSecret: !hasEMS,
3495 },
3496 }
3497 }
3498
3499 if isResumption && !hasEMS {
3500 test.shouldFail = true
3501 test.expectedError = "failed to get tls-unique"
3502 }
3503
3504 testCases = append(testCases, test)
3505 }
3506 }
3507 }
3508}
3509
David Benjamin884fdf12014-08-02 15:28:23 -04003510func worker(statusChan chan statusMsg, c chan *testCase, buildDir string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07003511 defer wg.Done()
3512
3513 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08003514 var err error
3515
3516 if *mallocTest < 0 {
3517 statusChan <- statusMsg{test: test, started: true}
3518 err = runTest(test, buildDir, -1)
3519 } else {
3520 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
3521 statusChan <- statusMsg{test: test, started: true}
3522 if err = runTest(test, buildDir, mallocNumToFail); err != errMoreMallocs {
3523 if err != nil {
3524 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
3525 }
3526 break
3527 }
3528 }
3529 }
Adam Langley95c29f32014-06-20 12:00:00 -07003530 statusChan <- statusMsg{test: test, err: err}
3531 }
3532}
3533
3534type statusMsg struct {
3535 test *testCase
3536 started bool
3537 err error
3538}
3539
David Benjamin5f237bc2015-02-11 17:14:15 -05003540func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07003541 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07003542
David Benjamin5f237bc2015-02-11 17:14:15 -05003543 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07003544 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05003545 if !*pipe {
3546 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05003547 var erase string
3548 for i := 0; i < lineLen; i++ {
3549 erase += "\b \b"
3550 }
3551 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05003552 }
3553
Adam Langley95c29f32014-06-20 12:00:00 -07003554 if msg.started {
3555 started++
3556 } else {
3557 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05003558
3559 if msg.err != nil {
3560 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
3561 failed++
3562 testOutput.addResult(msg.test.name, "FAIL")
3563 } else {
3564 if *pipe {
3565 // Print each test instead of a status line.
3566 fmt.Printf("PASSED (%s)\n", msg.test.name)
3567 }
3568 testOutput.addResult(msg.test.name, "PASS")
3569 }
Adam Langley95c29f32014-06-20 12:00:00 -07003570 }
3571
David Benjamin5f237bc2015-02-11 17:14:15 -05003572 if !*pipe {
3573 // Print a new status line.
3574 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
3575 lineLen = len(line)
3576 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07003577 }
Adam Langley95c29f32014-06-20 12:00:00 -07003578 }
David Benjamin5f237bc2015-02-11 17:14:15 -05003579
3580 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07003581}
3582
3583func main() {
3584 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 -04003585 var flagNumWorkers *int = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
David Benjamin884fdf12014-08-02 15:28:23 -04003586 var flagBuildDir *string = flag.String("build-dir", "../../../build", "The build directory to run the shim from.")
Adam Langley95c29f32014-06-20 12:00:00 -07003587
3588 flag.Parse()
3589
3590 addCipherSuiteTests()
3591 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07003592 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07003593 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04003594 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08003595 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003596 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05003597 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04003598 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04003599 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04003600 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07003601 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07003602 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05003603 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05003604 addSigningHashTests()
Feng Lu41aa3252014-11-21 22:47:56 -08003605 addFastRadioPaddingTests()
David Benjamin83f90402015-01-27 01:09:43 -05003606 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04003607 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07003608 addTLSUniqueTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04003609 for _, async := range []bool{false, true} {
3610 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04003611 for _, protocol := range []protocol{tls, dtls} {
3612 addStateMachineCoverageTests(async, splitHandshake, protocol)
3613 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003614 }
3615 }
Adam Langley95c29f32014-06-20 12:00:00 -07003616
3617 var wg sync.WaitGroup
3618
David Benjamin2bc8e6f2014-08-02 15:22:37 -04003619 numWorkers := *flagNumWorkers
Adam Langley95c29f32014-06-20 12:00:00 -07003620
3621 statusChan := make(chan statusMsg, numWorkers)
3622 testChan := make(chan *testCase, numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05003623 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07003624
David Benjamin025b3d32014-07-01 19:53:04 -04003625 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07003626
3627 for i := 0; i < numWorkers; i++ {
3628 wg.Add(1)
David Benjamin884fdf12014-08-02 15:28:23 -04003629 go worker(statusChan, testChan, *flagBuildDir, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07003630 }
3631
David Benjamin025b3d32014-07-01 19:53:04 -04003632 for i := range testCases {
3633 if len(*flagTest) == 0 || *flagTest == testCases[i].name {
3634 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07003635 }
3636 }
3637
3638 close(testChan)
3639 wg.Wait()
3640 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05003641 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07003642
3643 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05003644
3645 if *jsonOutput != "" {
3646 if err := testOutput.writeTo(*jsonOutput); err != nil {
3647 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
3648 }
3649 }
David Benjamin2ab7a862015-04-04 17:02:18 -04003650
3651 if !testOutput.allPassed {
3652 os.Exit(1)
3653 }
Adam Langley95c29f32014-06-20 12:00:00 -07003654}