Adam Langley | 7fcfd3b | 2016-05-20 11:02:50 -0700 | [diff] [blame] | 1 | // Copyright (c) 2016, Google Inc. |
| 2 | // |
| 3 | // Permission to use, copy, modify, and/or distribute this software for any |
| 4 | // purpose with or without fee is hereby granted, provided that the above |
| 5 | // copyright notice and this permission notice appear in all copies. |
| 6 | // |
| 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
David Benjamin | 0d1b096 | 2016-08-01 09:50:57 -0400 | [diff] [blame] | 13 | // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Adam Langley | 7fcfd3b | 2016-05-20 11:02:50 -0700 | [diff] [blame] | 14 | |
Adam Langley | dc7e9c4 | 2015-09-29 15:21:04 -0700 | [diff] [blame] | 15 | package runner |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "bytes" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 19 | "crypto/ecdsa" |
| 20 | "crypto/elliptic" |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 21 | "crypto/x509" |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 22 | "encoding/base64" |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 23 | "encoding/json" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 24 | "encoding/pem" |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 25 | "errors" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 26 | "flag" |
| 27 | "fmt" |
| 28 | "io" |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 29 | "io/ioutil" |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 30 | "math/big" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 31 | "net" |
| 32 | "os" |
| 33 | "os/exec" |
David Benjamin | 884fdf1 | 2014-08-02 15:28:23 -0400 | [diff] [blame] | 34 | "path" |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 35 | "path/filepath" |
David Benjamin | 2bc8e6f | 2014-08-02 15:22:37 -0400 | [diff] [blame] | 36 | "runtime" |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 37 | "strconv" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 38 | "strings" |
| 39 | "sync" |
| 40 | "syscall" |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 41 | "time" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 42 | ) |
| 43 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 44 | var ( |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 45 | useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind") |
| 46 | useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb") |
| 47 | useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb") |
| 48 | flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection") |
| 49 | mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.") |
| 50 | mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.") |
| 51 | jsonOutput = flag.String("json-output", "", "The file to output JSON results to.") |
| 52 | pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.") |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 53 | testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests") |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 54 | numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.") |
| 55 | shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.") |
| 56 | resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.") |
| 57 | fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.") |
| 58 | transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.") |
| 59 | idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.") |
| 60 | deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.") |
| 61 | allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.") |
EKR | 173bf93 | 2016-07-29 15:52:49 +0200 | [diff] [blame] | 62 | looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.") |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 63 | shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.") |
| 64 | includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 65 | ) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 66 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 67 | // ShimConfigurations is used with the “json” package and represents a shim |
| 68 | // config file. |
| 69 | type ShimConfiguration struct { |
| 70 | // DisabledTests maps from a glob-based pattern to a freeform string. |
| 71 | // The glob pattern is used to exclude tests from being run and the |
| 72 | // freeform string is unparsed but expected to explain why the test is |
| 73 | // disabled. |
| 74 | DisabledTests map[string]string |
| 75 | |
| 76 | // ErrorMap maps from expected error strings to the correct error |
| 77 | // string for the shim in question. For example, it might map |
| 78 | // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something |
| 79 | // like “SSL_ERROR_NO_CYPHER_OVERLAP”. |
| 80 | ErrorMap map[string]string |
| 81 | } |
| 82 | |
| 83 | var shimConfig ShimConfiguration |
| 84 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 85 | type testCert int |
| 86 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 87 | const ( |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 88 | testCertRSA testCert = iota |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 89 | testCertRSA1024 |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 90 | testCertECDSAP256 |
| 91 | testCertECDSAP384 |
| 92 | testCertECDSAP521 |
| 93 | ) |
| 94 | |
| 95 | const ( |
| 96 | rsaCertificateFile = "cert.pem" |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 97 | rsa1024CertificateFile = "rsa_1024_cert.pem" |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 98 | ecdsaP256CertificateFile = "ecdsa_p256_cert.pem" |
| 99 | ecdsaP384CertificateFile = "ecdsa_p384_cert.pem" |
| 100 | ecdsaP521CertificateFile = "ecdsa_p521_cert.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 101 | ) |
| 102 | |
| 103 | const ( |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 104 | rsaKeyFile = "key.pem" |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 105 | rsa1024KeyFile = "rsa_1024_key.pem" |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 106 | ecdsaP256KeyFile = "ecdsa_p256_key.pem" |
| 107 | ecdsaP384KeyFile = "ecdsa_p384_key.pem" |
| 108 | ecdsaP521KeyFile = "ecdsa_p521_key.pem" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 109 | channelIDKeyFile = "channel_id_key.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 110 | ) |
| 111 | |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 112 | var ( |
| 113 | rsaCertificate Certificate |
| 114 | rsa1024Certificate Certificate |
| 115 | ecdsaP256Certificate Certificate |
| 116 | ecdsaP384Certificate Certificate |
| 117 | ecdsaP521Certificate Certificate |
| 118 | ) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 119 | |
| 120 | var testCerts = []struct { |
| 121 | id testCert |
| 122 | certFile, keyFile string |
| 123 | cert *Certificate |
| 124 | }{ |
| 125 | { |
| 126 | id: testCertRSA, |
| 127 | certFile: rsaCertificateFile, |
| 128 | keyFile: rsaKeyFile, |
| 129 | cert: &rsaCertificate, |
| 130 | }, |
| 131 | { |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 132 | id: testCertRSA1024, |
| 133 | certFile: rsa1024CertificateFile, |
| 134 | keyFile: rsa1024KeyFile, |
| 135 | cert: &rsa1024Certificate, |
| 136 | }, |
| 137 | { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 138 | id: testCertECDSAP256, |
| 139 | certFile: ecdsaP256CertificateFile, |
| 140 | keyFile: ecdsaP256KeyFile, |
| 141 | cert: &ecdsaP256Certificate, |
| 142 | }, |
| 143 | { |
| 144 | id: testCertECDSAP384, |
| 145 | certFile: ecdsaP384CertificateFile, |
| 146 | keyFile: ecdsaP384KeyFile, |
| 147 | cert: &ecdsaP384Certificate, |
| 148 | }, |
| 149 | { |
| 150 | id: testCertECDSAP521, |
| 151 | certFile: ecdsaP521CertificateFile, |
| 152 | keyFile: ecdsaP521KeyFile, |
| 153 | cert: &ecdsaP521Certificate, |
| 154 | }, |
| 155 | } |
| 156 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 157 | var channelIDKey *ecdsa.PrivateKey |
| 158 | var channelIDBytes []byte |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 159 | |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 160 | var testOCSPResponse = []byte{1, 2, 3, 4} |
| 161 | var testSCTList = []byte{5, 6, 7, 8} |
| 162 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 163 | func initCertificates() { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 164 | for i := range testCerts { |
| 165 | cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile)) |
| 166 | if err != nil { |
| 167 | panic(err) |
| 168 | } |
| 169 | cert.OCSPStaple = testOCSPResponse |
| 170 | cert.SignedCertificateTimestampList = testSCTList |
| 171 | *testCerts[i].cert = cert |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 172 | } |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 173 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 174 | channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile)) |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 175 | if err != nil { |
| 176 | panic(err) |
| 177 | } |
| 178 | channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock) |
| 179 | if channelIDDERBlock.Type != "EC PRIVATE KEY" { |
| 180 | panic("bad key type") |
| 181 | } |
| 182 | channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes) |
| 183 | if err != nil { |
| 184 | panic(err) |
| 185 | } |
| 186 | if channelIDKey.Curve != elliptic.P256() { |
| 187 | panic("bad curve") |
| 188 | } |
| 189 | |
| 190 | channelIDBytes = make([]byte, 64) |
| 191 | writeIntPadded(channelIDBytes[:32], channelIDKey.X) |
| 192 | writeIntPadded(channelIDBytes[32:], channelIDKey.Y) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 193 | } |
| 194 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 195 | func getRunnerCertificate(t testCert) Certificate { |
| 196 | for _, cert := range testCerts { |
| 197 | if cert.id == t { |
| 198 | return *cert.cert |
| 199 | } |
| 200 | } |
| 201 | panic("Unknown test certificate") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 202 | } |
| 203 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 204 | func getShimCertificate(t testCert) string { |
| 205 | for _, cert := range testCerts { |
| 206 | if cert.id == t { |
| 207 | return cert.certFile |
| 208 | } |
| 209 | } |
| 210 | panic("Unknown test certificate") |
| 211 | } |
| 212 | |
| 213 | func getShimKey(t testCert) string { |
| 214 | for _, cert := range testCerts { |
| 215 | if cert.id == t { |
| 216 | return cert.keyFile |
| 217 | } |
| 218 | } |
| 219 | panic("Unknown test certificate") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 220 | } |
| 221 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 222 | type testType int |
| 223 | |
| 224 | const ( |
| 225 | clientTest testType = iota |
| 226 | serverTest |
| 227 | ) |
| 228 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 229 | type protocol int |
| 230 | |
| 231 | const ( |
| 232 | tls protocol = iota |
| 233 | dtls |
| 234 | ) |
| 235 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 236 | const ( |
| 237 | alpn = 1 |
| 238 | npn = 2 |
| 239 | ) |
| 240 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 241 | type testCase struct { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 242 | testType testType |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 243 | protocol protocol |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 244 | name string |
| 245 | config Config |
| 246 | shouldFail bool |
| 247 | expectedError string |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 248 | // expectedLocalError, if not empty, contains a substring that must be |
| 249 | // found in the local error. |
| 250 | expectedLocalError string |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 251 | // expectedVersion, if non-zero, specifies the TLS version that must be |
| 252 | // negotiated. |
| 253 | expectedVersion uint16 |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 254 | // expectedResumeVersion, if non-zero, specifies the TLS version that |
| 255 | // must be negotiated on resumption. If zero, expectedVersion is used. |
| 256 | expectedResumeVersion uint16 |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 257 | // expectedCipher, if non-zero, specifies the TLS cipher suite that |
| 258 | // should be negotiated. |
| 259 | expectedCipher uint16 |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 260 | // expectChannelID controls whether the connection should have |
| 261 | // negotiated a Channel ID with channelIDKey. |
| 262 | expectChannelID bool |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 263 | // expectedNextProto controls whether the connection should |
| 264 | // negotiate a next protocol via NPN or ALPN. |
| 265 | expectedNextProto string |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 266 | // expectNoNextProto, if true, means that no next protocol should be |
| 267 | // negotiated. |
| 268 | expectNoNextProto bool |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 269 | // expectedNextProtoType, if non-zero, is the expected next |
| 270 | // protocol negotiation mechanism. |
| 271 | expectedNextProtoType int |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 272 | // expectedSRTPProtectionProfile is the DTLS-SRTP profile that |
| 273 | // should be negotiated. If zero, none should be negotiated. |
| 274 | expectedSRTPProtectionProfile uint16 |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 275 | // expectedOCSPResponse, if not nil, is the expected OCSP response to be received. |
| 276 | expectedOCSPResponse []uint8 |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 277 | // expectedSCTList, if not nil, is the expected SCT list to be received. |
| 278 | expectedSCTList []uint8 |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 279 | // expectedPeerSignatureAlgorithm, if not zero, is the signature |
| 280 | // algorithm that the peer should have used in the handshake. |
| 281 | expectedPeerSignatureAlgorithm signatureAlgorithm |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 282 | // expectedCurveID, if not zero, is the curve that the handshake should |
| 283 | // have used. |
| 284 | expectedCurveID CurveID |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 285 | // messageLen is the length, in bytes, of the test message that will be |
| 286 | // sent. |
| 287 | messageLen int |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 288 | // messageCount is the number of test messages that will be sent. |
| 289 | messageCount int |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 290 | // certFile is the path to the certificate to use for the server. |
| 291 | certFile string |
| 292 | // keyFile is the path to the private key to use for the server. |
| 293 | keyFile string |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 294 | // resumeSession controls whether a second connection should be tested |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 295 | // which attempts to resume the first session. |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 296 | resumeSession bool |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 297 | // expectResumeRejected, if true, specifies that the attempted |
| 298 | // resumption must be rejected by the client. This is only valid for a |
| 299 | // serverTest. |
| 300 | expectResumeRejected bool |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 301 | // resumeConfig, if not nil, points to a Config to be used on |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 302 | // resumption. Unless newSessionsOnResume is set, |
| 303 | // SessionTicketKey, ServerSessionCache, and |
| 304 | // ClientSessionCache are copied from the initial connection's |
| 305 | // config. If nil, the initial connection's config is used. |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 306 | resumeConfig *Config |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 307 | // newSessionsOnResume, if true, will cause resumeConfig to |
| 308 | // use a different session resumption context. |
| 309 | newSessionsOnResume bool |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 310 | // noSessionCache, if true, will cause the server to run without a |
| 311 | // session cache. |
| 312 | noSessionCache bool |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 313 | // sendPrefix sends a prefix on the socket before actually performing a |
| 314 | // handshake. |
| 315 | sendPrefix string |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 316 | // shimWritesFirst controls whether the shim sends an initial "hello" |
| 317 | // message before doing a roundtrip with the runner. |
| 318 | shimWritesFirst bool |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 319 | // shimShutsDown, if true, runs a test where the shim shuts down the |
| 320 | // connection immediately after the handshake rather than echoing |
| 321 | // messages from the runner. |
| 322 | shimShutsDown bool |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 323 | // renegotiate indicates the number of times the connection should be |
| 324 | // renegotiated during the exchange. |
| 325 | renegotiate int |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 326 | // sendHalfHelloRequest, if true, causes the server to send half a |
| 327 | // HelloRequest when the handshake completes. |
| 328 | sendHalfHelloRequest bool |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 329 | // renegotiateCiphers is a list of ciphersuite ids that will be |
| 330 | // switched in just before renegotiation. |
| 331 | renegotiateCiphers []uint16 |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 332 | // replayWrites, if true, configures the underlying transport |
| 333 | // to replay every write it makes in DTLS tests. |
| 334 | replayWrites bool |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 335 | // damageFirstWrite, if true, configures the underlying transport to |
| 336 | // damage the final byte of the first application data write. |
| 337 | damageFirstWrite bool |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 338 | // exportKeyingMaterial, if non-zero, configures the test to exchange |
| 339 | // keying material and verify they match. |
| 340 | exportKeyingMaterial int |
| 341 | exportLabel string |
| 342 | exportContext string |
| 343 | useExportContext bool |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 344 | // flags, if not empty, contains a list of command-line flags that will |
| 345 | // be passed to the shim program. |
| 346 | flags []string |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 347 | // testTLSUnique, if true, causes the shim to send the tls-unique value |
| 348 | // which will be compared against the expected value. |
| 349 | testTLSUnique bool |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 350 | // sendEmptyRecords is the number of consecutive empty records to send |
| 351 | // before and after the test message. |
| 352 | sendEmptyRecords int |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 353 | // sendWarningAlerts is the number of consecutive warning alerts to send |
| 354 | // before and after the test message. |
| 355 | sendWarningAlerts int |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 356 | // expectMessageDropped, if true, means the test message is expected to |
| 357 | // be dropped by the client rather than echoed back. |
| 358 | expectMessageDropped bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 361 | var testCases []testCase |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 362 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 363 | func writeTranscript(test *testCase, isResume bool, data []byte) { |
| 364 | if len(data) == 0 { |
| 365 | return |
| 366 | } |
| 367 | |
| 368 | protocol := "tls" |
| 369 | if test.protocol == dtls { |
| 370 | protocol = "dtls" |
| 371 | } |
| 372 | |
| 373 | side := "client" |
| 374 | if test.testType == serverTest { |
| 375 | side = "server" |
| 376 | } |
| 377 | |
| 378 | dir := path.Join(*transcriptDir, protocol, side) |
| 379 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 380 | fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err) |
| 381 | return |
| 382 | } |
| 383 | |
| 384 | name := test.name |
| 385 | if isResume { |
| 386 | name += "-Resume" |
| 387 | } else { |
| 388 | name += "-Normal" |
| 389 | } |
| 390 | |
| 391 | if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil { |
| 392 | fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err) |
| 393 | } |
| 394 | } |
| 395 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 396 | // A timeoutConn implements an idle timeout on each Read and Write operation. |
| 397 | type timeoutConn struct { |
| 398 | net.Conn |
| 399 | timeout time.Duration |
| 400 | } |
| 401 | |
| 402 | func (t *timeoutConn) Read(b []byte) (int, error) { |
| 403 | if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil { |
| 404 | return 0, err |
| 405 | } |
| 406 | return t.Conn.Read(b) |
| 407 | } |
| 408 | |
| 409 | func (t *timeoutConn) Write(b []byte) (int, error) { |
| 410 | if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil { |
| 411 | return 0, err |
| 412 | } |
| 413 | return t.Conn.Write(b) |
| 414 | } |
| 415 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 416 | func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error { |
David Benjamin | 01784b4 | 2016-06-07 18:00:52 -0400 | [diff] [blame] | 417 | conn = &timeoutConn{conn, *idleTimeout} |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 418 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 419 | if test.protocol == dtls { |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 420 | config.Bugs.PacketAdaptor = newPacketAdaptor(conn) |
| 421 | conn = config.Bugs.PacketAdaptor |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 422 | } |
| 423 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 424 | if *flagDebug || len(*transcriptDir) != 0 { |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 425 | local, peer := "client", "server" |
| 426 | if test.testType == clientTest { |
| 427 | local, peer = peer, local |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 428 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 429 | connDebug := &recordingConn{ |
| 430 | Conn: conn, |
| 431 | isDatagram: test.protocol == dtls, |
| 432 | local: local, |
| 433 | peer: peer, |
| 434 | } |
| 435 | conn = connDebug |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 436 | if *flagDebug { |
| 437 | defer connDebug.WriteTo(os.Stdout) |
| 438 | } |
| 439 | if len(*transcriptDir) != 0 { |
| 440 | defer func() { |
| 441 | writeTranscript(test, isResume, connDebug.Transcript()) |
| 442 | }() |
| 443 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 444 | |
| 445 | if config.Bugs.PacketAdaptor != nil { |
| 446 | config.Bugs.PacketAdaptor.debug = connDebug |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | if test.replayWrites { |
| 451 | conn = newReplayAdaptor(conn) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 452 | } |
| 453 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 454 | var connDamage *damageAdaptor |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 455 | if test.damageFirstWrite { |
| 456 | connDamage = newDamageAdaptor(conn) |
| 457 | conn = connDamage |
| 458 | } |
| 459 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 460 | if test.sendPrefix != "" { |
| 461 | if _, err := conn.Write([]byte(test.sendPrefix)); err != nil { |
| 462 | return err |
| 463 | } |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 464 | } |
| 465 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 466 | var tlsConn *Conn |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 467 | if test.testType == clientTest { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 468 | if test.protocol == dtls { |
| 469 | tlsConn = DTLSServer(conn, config) |
| 470 | } else { |
| 471 | tlsConn = Server(conn, config) |
| 472 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 473 | } else { |
| 474 | config.InsecureSkipVerify = true |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 475 | if test.protocol == dtls { |
| 476 | tlsConn = DTLSClient(conn, config) |
| 477 | } else { |
| 478 | tlsConn = Client(conn, config) |
| 479 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 480 | } |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 481 | defer tlsConn.Close() |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 482 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 483 | if err := tlsConn.Handshake(); err != nil { |
| 484 | return err |
| 485 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 486 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 487 | // TODO(davidben): move all per-connection expectations into a dedicated |
| 488 | // expectations struct that can be specified separately for the two |
| 489 | // legs. |
| 490 | expectedVersion := test.expectedVersion |
| 491 | if isResume && test.expectedResumeVersion != 0 { |
| 492 | expectedVersion = test.expectedResumeVersion |
| 493 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 494 | connState := tlsConn.ConnectionState() |
| 495 | if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 496 | return fmt.Errorf("got version %x, expected %x", vers, expectedVersion) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 499 | if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher { |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 500 | return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher) |
| 501 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 502 | if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected { |
| 503 | return fmt.Errorf("didResume is %t, but we expected the opposite", didResume) |
| 504 | } |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 505 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 506 | if test.expectChannelID { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 507 | channelID := connState.ChannelID |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 508 | if channelID == nil { |
| 509 | return fmt.Errorf("no channel ID negotiated") |
| 510 | } |
| 511 | if channelID.Curve != channelIDKey.Curve || |
| 512 | channelIDKey.X.Cmp(channelIDKey.X) != 0 || |
| 513 | channelIDKey.Y.Cmp(channelIDKey.Y) != 0 { |
| 514 | return fmt.Errorf("incorrect channel ID") |
| 515 | } |
| 516 | } |
| 517 | |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 518 | if expected := test.expectedNextProto; expected != "" { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 519 | if actual := connState.NegotiatedProtocol; actual != expected { |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 520 | return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected) |
| 521 | } |
| 522 | } |
| 523 | |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 524 | if test.expectNoNextProto { |
| 525 | if actual := connState.NegotiatedProtocol; actual != "" { |
| 526 | return fmt.Errorf("got unexpected next proto %s", actual) |
| 527 | } |
| 528 | } |
| 529 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 530 | if test.expectedNextProtoType != 0 { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 531 | if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN { |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 532 | return fmt.Errorf("next proto type mismatch") |
| 533 | } |
| 534 | } |
| 535 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 536 | if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile { |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 537 | return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile) |
| 538 | } |
| 539 | |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 540 | if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) { |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 541 | return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 542 | } |
| 543 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 544 | if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) { |
| 545 | return fmt.Errorf("SCT list mismatch") |
| 546 | } |
| 547 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 548 | if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm { |
| 549 | return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm) |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 550 | } |
| 551 | |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 552 | if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID { |
| 553 | return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID) |
| 554 | } |
| 555 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 556 | if test.exportKeyingMaterial > 0 { |
| 557 | actual := make([]byte, test.exportKeyingMaterial) |
| 558 | if _, err := io.ReadFull(tlsConn, actual); err != nil { |
| 559 | return err |
| 560 | } |
| 561 | expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext) |
| 562 | if err != nil { |
| 563 | return err |
| 564 | } |
| 565 | if !bytes.Equal(actual, expected) { |
| 566 | return fmt.Errorf("keying material mismatch") |
| 567 | } |
| 568 | } |
| 569 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 570 | if test.testTLSUnique { |
| 571 | var peersValue [12]byte |
| 572 | if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil { |
| 573 | return err |
| 574 | } |
| 575 | expected := tlsConn.ConnectionState().TLSUnique |
| 576 | if !bytes.Equal(peersValue[:], expected) { |
| 577 | return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected) |
| 578 | } |
| 579 | } |
| 580 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 581 | if test.shimWritesFirst { |
| 582 | var buf [5]byte |
| 583 | _, err := io.ReadFull(tlsConn, buf[:]) |
| 584 | if err != nil { |
| 585 | return err |
| 586 | } |
| 587 | if string(buf[:]) != "hello" { |
| 588 | return fmt.Errorf("bad initial message") |
| 589 | } |
| 590 | } |
| 591 | |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 592 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 593 | tlsConn.Write(nil) |
| 594 | } |
| 595 | |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 596 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 597 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 598 | } |
| 599 | |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 600 | if test.sendHalfHelloRequest { |
| 601 | tlsConn.SendHalfHelloRequest() |
| 602 | } |
| 603 | |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 604 | if test.renegotiate > 0 { |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 605 | if test.renegotiateCiphers != nil { |
| 606 | config.CipherSuites = test.renegotiateCiphers |
| 607 | } |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 608 | for i := 0; i < test.renegotiate; i++ { |
| 609 | if err := tlsConn.Renegotiate(); err != nil { |
| 610 | return err |
| 611 | } |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 612 | } |
| 613 | } else if test.renegotiateCiphers != nil { |
| 614 | panic("renegotiateCiphers without renegotiate") |
| 615 | } |
| 616 | |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 617 | if test.damageFirstWrite { |
| 618 | connDamage.setDamage(true) |
| 619 | tlsConn.Write([]byte("DAMAGED WRITE")) |
| 620 | connDamage.setDamage(false) |
| 621 | } |
| 622 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 623 | messageLen := test.messageLen |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 624 | if messageLen < 0 { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 625 | if test.protocol == dtls { |
| 626 | return fmt.Errorf("messageLen < 0 not supported for DTLS tests") |
| 627 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 628 | // Read until EOF. |
| 629 | _, err := io.Copy(ioutil.Discard, tlsConn) |
| 630 | return err |
| 631 | } |
David Benjamin | 4417d05 | 2015-04-05 04:17:25 -0400 | [diff] [blame] | 632 | if messageLen == 0 { |
| 633 | messageLen = 32 |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 634 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 635 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 636 | messageCount := test.messageCount |
| 637 | if messageCount == 0 { |
| 638 | messageCount = 1 |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 639 | } |
| 640 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 641 | for j := 0; j < messageCount; j++ { |
| 642 | testMessage := make([]byte, messageLen) |
| 643 | for i := range testMessage { |
| 644 | testMessage[i] = 0x42 ^ byte(j) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 645 | } |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 646 | tlsConn.Write(testMessage) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 647 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 648 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 649 | tlsConn.Write(nil) |
| 650 | } |
| 651 | |
| 652 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 653 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 654 | } |
| 655 | |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 656 | if test.shimShutsDown || test.expectMessageDropped { |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 657 | // The shim will not respond. |
| 658 | continue |
| 659 | } |
| 660 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 661 | buf := make([]byte, len(testMessage)) |
| 662 | if test.protocol == dtls { |
| 663 | bufTmp := make([]byte, len(buf)+1) |
| 664 | n, err := tlsConn.Read(bufTmp) |
| 665 | if err != nil { |
| 666 | return err |
| 667 | } |
| 668 | if n != len(buf) { |
| 669 | return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf)) |
| 670 | } |
| 671 | copy(buf, bufTmp) |
| 672 | } else { |
| 673 | _, err := io.ReadFull(tlsConn, buf) |
| 674 | if err != nil { |
| 675 | return err |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | for i, v := range buf { |
| 680 | if v != testMessage[i]^0xff { |
| 681 | return fmt.Errorf("bad reply contents at byte %d", i) |
| 682 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
| 686 | return nil |
| 687 | } |
| 688 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 689 | func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd { |
| 690 | valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"} |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 691 | if dbAttach { |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 692 | valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 693 | } |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 694 | valgrindArgs = append(valgrindArgs, path) |
| 695 | valgrindArgs = append(valgrindArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 696 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 697 | return exec.Command("valgrind", valgrindArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 698 | } |
| 699 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 700 | func gdbOf(path string, args ...string) *exec.Cmd { |
| 701 | xtermArgs := []string{"-e", "gdb", "--args"} |
| 702 | xtermArgs = append(xtermArgs, path) |
| 703 | xtermArgs = append(xtermArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 704 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 705 | return exec.Command("xterm", xtermArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 706 | } |
| 707 | |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 708 | func lldbOf(path string, args ...string) *exec.Cmd { |
| 709 | xtermArgs := []string{"-e", "lldb", "--"} |
| 710 | xtermArgs = append(xtermArgs, path) |
| 711 | xtermArgs = append(xtermArgs, args...) |
| 712 | |
| 713 | return exec.Command("xterm", xtermArgs...) |
| 714 | } |
| 715 | |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 716 | var ( |
| 717 | errMoreMallocs = errors.New("child process did not exhaust all allocation calls") |
| 718 | errUnimplemented = errors.New("child process does not implement needed flags") |
| 719 | ) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 720 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 721 | // accept accepts a connection from listener, unless waitChan signals a process |
| 722 | // exit first. |
| 723 | func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) { |
| 724 | type connOrError struct { |
| 725 | conn net.Conn |
| 726 | err error |
| 727 | } |
| 728 | connChan := make(chan connOrError, 1) |
| 729 | go func() { |
| 730 | conn, err := listener.Accept() |
| 731 | connChan <- connOrError{conn, err} |
| 732 | close(connChan) |
| 733 | }() |
| 734 | select { |
| 735 | case result := <-connChan: |
| 736 | return result.conn, result.err |
| 737 | case childErr := <-waitChan: |
| 738 | waitChan <- childErr |
| 739 | return nil, fmt.Errorf("child exited early: %s", childErr) |
| 740 | } |
| 741 | } |
| 742 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 743 | func translateExpectedError(errorStr string) string { |
| 744 | if translated, ok := shimConfig.ErrorMap[errorStr]; ok { |
| 745 | return translated |
| 746 | } |
| 747 | |
| 748 | if *looseErrors { |
| 749 | return "" |
| 750 | } |
| 751 | |
| 752 | return errorStr |
| 753 | } |
| 754 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 755 | func runTest(test *testCase, shimPath string, mallocNumToFail int64) error { |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 756 | if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) { |
| 757 | panic("Error expected without shouldFail in " + test.name) |
| 758 | } |
| 759 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 760 | if test.expectResumeRejected && !test.resumeSession { |
| 761 | panic("expectResumeRejected without resumeSession in " + test.name) |
| 762 | } |
| 763 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 764 | listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}}) |
| 765 | if err != nil { |
| 766 | panic(err) |
| 767 | } |
| 768 | defer func() { |
| 769 | if listener != nil { |
| 770 | listener.Close() |
| 771 | } |
| 772 | }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 773 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 774 | flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)} |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 775 | if test.testType == serverTest { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 776 | flags = append(flags, "-server") |
| 777 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 778 | flags = append(flags, "-key-file") |
| 779 | if test.keyFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 780 | flags = append(flags, path.Join(*resourceDir, rsaKeyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 781 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 782 | flags = append(flags, path.Join(*resourceDir, test.keyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | flags = append(flags, "-cert-file") |
| 786 | if test.certFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 787 | flags = append(flags, path.Join(*resourceDir, rsaCertificateFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 788 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 789 | flags = append(flags, path.Join(*resourceDir, test.certFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 790 | } |
| 791 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 792 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 793 | if test.protocol == dtls { |
| 794 | flags = append(flags, "-dtls") |
| 795 | } |
| 796 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 797 | if test.resumeSession { |
| 798 | flags = append(flags, "-resume") |
| 799 | } |
| 800 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 801 | if test.shimWritesFirst { |
| 802 | flags = append(flags, "-shim-writes-first") |
| 803 | } |
| 804 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 805 | if test.shimShutsDown { |
| 806 | flags = append(flags, "-shim-shuts-down") |
| 807 | } |
| 808 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 809 | if test.exportKeyingMaterial > 0 { |
| 810 | flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial)) |
| 811 | flags = append(flags, "-export-label", test.exportLabel) |
| 812 | flags = append(flags, "-export-context", test.exportContext) |
| 813 | if test.useExportContext { |
| 814 | flags = append(flags, "-use-export-context") |
| 815 | } |
| 816 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 817 | if test.expectResumeRejected { |
| 818 | flags = append(flags, "-expect-session-miss") |
| 819 | } |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 820 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 821 | if test.testTLSUnique { |
| 822 | flags = append(flags, "-tls-unique") |
| 823 | } |
| 824 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 825 | flags = append(flags, test.flags...) |
| 826 | |
| 827 | var shim *exec.Cmd |
| 828 | if *useValgrind { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 829 | shim = valgrindOf(false, shimPath, flags...) |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 830 | } else if *useGDB { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 831 | shim = gdbOf(shimPath, flags...) |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 832 | } else if *useLLDB { |
| 833 | shim = lldbOf(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 834 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 835 | shim = exec.Command(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 836 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 837 | shim.Stdin = os.Stdin |
| 838 | var stdoutBuf, stderrBuf bytes.Buffer |
| 839 | shim.Stdout = &stdoutBuf |
| 840 | shim.Stderr = &stderrBuf |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 841 | if mallocNumToFail >= 0 { |
David Benjamin | 9e128b0 | 2015-02-09 13:13:09 -0500 | [diff] [blame] | 842 | shim.Env = os.Environ() |
| 843 | shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10)) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 844 | if *mallocTestDebug { |
David Benjamin | 184494d | 2015-06-12 18:23:47 -0400 | [diff] [blame] | 845 | shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 846 | } |
| 847 | shim.Env = append(shim.Env, "_MALLOC_CHECK=1") |
| 848 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 849 | |
| 850 | if err := shim.Start(); err != nil { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 851 | panic(err) |
| 852 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 853 | waitChan := make(chan error, 1) |
| 854 | go func() { waitChan <- shim.Wait() }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 855 | |
| 856 | config := test.config |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 857 | if !test.noSessionCache { |
| 858 | config.ClientSessionCache = NewLRUClientSessionCache(1) |
| 859 | config.ServerSessionCache = NewLRUServerSessionCache(1) |
| 860 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 861 | if test.testType == clientTest { |
| 862 | if len(config.Certificates) == 0 { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 863 | config.Certificates = []Certificate{rsaCertificate} |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 864 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 865 | } else { |
| 866 | // Supply a ServerName to ensure a constant session cache key, |
| 867 | // rather than falling back to net.Conn.RemoteAddr. |
| 868 | if len(config.ServerName) == 0 { |
| 869 | config.ServerName = "test" |
| 870 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 871 | } |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 872 | if *fuzzer { |
| 873 | config.Bugs.NullAllCiphers = true |
| 874 | } |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 875 | if *deterministic { |
| 876 | config.Rand = &deterministicRand{} |
| 877 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 878 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 879 | conn, err := acceptOrWait(listener, waitChan) |
| 880 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 881 | err = doExchange(test, &config, conn, false /* not a resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 882 | conn.Close() |
| 883 | } |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 884 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 885 | if err == nil && test.resumeSession { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 886 | var resumeConfig Config |
| 887 | if test.resumeConfig != nil { |
| 888 | resumeConfig = *test.resumeConfig |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 889 | if len(resumeConfig.ServerName) == 0 { |
| 890 | resumeConfig.ServerName = config.ServerName |
| 891 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 892 | if len(resumeConfig.Certificates) == 0 { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 893 | resumeConfig.Certificates = []Certificate{rsaCertificate} |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 894 | } |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 895 | if test.newSessionsOnResume { |
| 896 | if !test.noSessionCache { |
| 897 | resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1) |
| 898 | resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1) |
| 899 | } |
| 900 | } else { |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 901 | resumeConfig.SessionTicketKey = config.SessionTicketKey |
| 902 | resumeConfig.ClientSessionCache = config.ClientSessionCache |
| 903 | resumeConfig.ServerSessionCache = config.ServerSessionCache |
| 904 | } |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 905 | if *fuzzer { |
| 906 | resumeConfig.Bugs.NullAllCiphers = true |
| 907 | } |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 908 | resumeConfig.Rand = config.Rand |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 909 | } else { |
| 910 | resumeConfig = config |
| 911 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 912 | var connResume net.Conn |
| 913 | connResume, err = acceptOrWait(listener, waitChan) |
| 914 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 915 | err = doExchange(test, &resumeConfig, connResume, true /* resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 916 | connResume.Close() |
| 917 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 918 | } |
| 919 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 920 | // Close the listener now. This is to avoid hangs should the shim try to |
| 921 | // open more connections than expected. |
| 922 | listener.Close() |
| 923 | listener = nil |
| 924 | |
| 925 | childErr := <-waitChan |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 926 | if exitError, ok := childErr.(*exec.ExitError); ok { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 927 | switch exitError.Sys().(syscall.WaitStatus).ExitStatus() { |
| 928 | case 88: |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 929 | return errMoreMallocs |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 930 | case 89: |
| 931 | return errUnimplemented |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 932 | } |
| 933 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 934 | |
David Benjamin | 9bea349 | 2016-03-02 10:59:16 -0500 | [diff] [blame] | 935 | // Account for Windows line endings. |
| 936 | stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1) |
| 937 | stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1) |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 938 | |
| 939 | // Separate the errors from the shim and those from tools like |
| 940 | // AddressSanitizer. |
| 941 | var extraStderr string |
| 942 | if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 { |
| 943 | stderr = stderrParts[0] |
| 944 | extraStderr = stderrParts[1] |
| 945 | } |
| 946 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 947 | failed := err != nil || childErr != nil |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 948 | expectedError := translateExpectedError(test.expectedError) |
| 949 | correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError) |
EKR | 173bf93 | 2016-07-29 15:52:49 +0200 | [diff] [blame] | 950 | |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 951 | localError := "none" |
| 952 | if err != nil { |
| 953 | localError = err.Error() |
| 954 | } |
| 955 | if len(test.expectedLocalError) != 0 { |
| 956 | correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError) |
| 957 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 958 | |
| 959 | if failed != test.shouldFail || failed && !correctFailure { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 960 | childError := "none" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 961 | if childErr != nil { |
| 962 | childError = childErr.Error() |
| 963 | } |
| 964 | |
| 965 | var msg string |
| 966 | switch { |
| 967 | case failed && !test.shouldFail: |
| 968 | msg = "unexpected failure" |
| 969 | case !failed && test.shouldFail: |
| 970 | msg = "unexpected success" |
| 971 | case failed && !correctFailure: |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 972 | msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 973 | default: |
| 974 | panic("internal error") |
| 975 | } |
| 976 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 977 | return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 978 | } |
| 979 | |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 980 | if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) { |
| 981 | return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | return nil |
| 985 | } |
| 986 | |
| 987 | var tlsVersions = []struct { |
| 988 | name string |
| 989 | version uint16 |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 990 | flag string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 991 | hasDTLS bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 992 | }{ |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 993 | {"SSL3", VersionSSL30, "-no-ssl3", false}, |
| 994 | {"TLS1", VersionTLS10, "-no-tls1", true}, |
| 995 | {"TLS11", VersionTLS11, "-no-tls11", false}, |
| 996 | {"TLS12", VersionTLS12, "-no-tls12", true}, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 997 | {"TLS13", VersionTLS13, "-no-tls13", false}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | var testCipherSuites = []struct { |
| 1001 | name string |
| 1002 | id uint16 |
| 1003 | }{ |
| 1004 | {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1005 | {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1006 | {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1007 | {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1008 | {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1009 | {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1010 | {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1011 | {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1012 | {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1013 | {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1014 | {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384}, |
| 1015 | {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1016 | {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1017 | {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1018 | {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1019 | {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}, |
| 1020 | {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1021 | {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1022 | {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1023 | {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 1024 | {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1025 | {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1026 | {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1027 | {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1028 | {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1029 | {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1030 | {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1031 | {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1032 | {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 1033 | {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1034 | {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA}, |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 1035 | {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 1036 | {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 1037 | {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 1038 | {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384}, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1039 | {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 1040 | {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA}, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 1041 | {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 1042 | {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1043 | {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256}, |
Steven Valdez | 3084e7b | 2016-06-02 12:07:20 -0400 | [diff] [blame] | 1044 | {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256}, |
| 1045 | {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384}, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1046 | {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1047 | {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1048 | {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA}, |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1049 | {"NULL-SHA", TLS_RSA_WITH_NULL_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1052 | func hasComponent(suiteName, component string) bool { |
| 1053 | return strings.Contains("-"+suiteName+"-", "-"+component+"-") |
| 1054 | } |
| 1055 | |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1056 | func isTLS12Only(suiteName string) bool { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1057 | return hasComponent(suiteName, "GCM") || |
| 1058 | hasComponent(suiteName, "SHA256") || |
David Benjamin | e9a80ff | 2015-04-07 00:46:46 -0400 | [diff] [blame] | 1059 | hasComponent(suiteName, "SHA384") || |
| 1060 | hasComponent(suiteName, "POLY1305") |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1061 | } |
| 1062 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1063 | func isTLS13Suite(suiteName string) bool { |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 1064 | // Only AEADs. |
| 1065 | if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") { |
| 1066 | return false |
| 1067 | } |
| 1068 | // No old CHACHA20_POLY1305. |
| 1069 | if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") { |
| 1070 | return false |
| 1071 | } |
| 1072 | // Must have ECDHE. |
| 1073 | // TODO(davidben,svaldez): Add pure PSK support. |
| 1074 | if !hasComponent(suiteName, "ECDHE") { |
| 1075 | return false |
| 1076 | } |
| 1077 | // TODO(davidben,svaldez): Add PSK support. |
| 1078 | if hasComponent(suiteName, "PSK") { |
| 1079 | return false |
| 1080 | } |
| 1081 | return true |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1084 | func isDTLSCipher(suiteName string) bool { |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1085 | return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL") |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1086 | } |
| 1087 | |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 1088 | func bigFromHex(hex string) *big.Int { |
| 1089 | ret, ok := new(big.Int).SetString(hex, 16) |
| 1090 | if !ok { |
| 1091 | panic("failed to parse hex number 0x" + hex) |
| 1092 | } |
| 1093 | return ret |
| 1094 | } |
| 1095 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1096 | func addBasicTests() { |
| 1097 | basicTests := []testCase{ |
| 1098 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1099 | name: "NoFallbackSCSV", |
| 1100 | config: Config{ |
| 1101 | Bugs: ProtocolBugs{ |
| 1102 | FailIfNotFallbackSCSV: true, |
| 1103 | }, |
| 1104 | }, |
| 1105 | shouldFail: true, |
| 1106 | expectedLocalError: "no fallback SCSV found", |
| 1107 | }, |
| 1108 | { |
| 1109 | name: "SendFallbackSCSV", |
| 1110 | config: Config{ |
| 1111 | Bugs: ProtocolBugs{ |
| 1112 | FailIfNotFallbackSCSV: true, |
| 1113 | }, |
| 1114 | }, |
| 1115 | flags: []string{"-fallback-scsv"}, |
| 1116 | }, |
| 1117 | { |
| 1118 | name: "ClientCertificateTypes", |
| 1119 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1120 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1121 | ClientAuth: RequestClientCert, |
| 1122 | ClientCertificateTypes: []byte{ |
| 1123 | CertTypeDSSSign, |
| 1124 | CertTypeRSASign, |
| 1125 | CertTypeECDSASign, |
| 1126 | }, |
| 1127 | }, |
| 1128 | flags: []string{ |
| 1129 | "-expect-certificate-types", |
| 1130 | base64.StdEncoding.EncodeToString([]byte{ |
| 1131 | CertTypeDSSSign, |
| 1132 | CertTypeRSASign, |
| 1133 | CertTypeECDSASign, |
| 1134 | }), |
| 1135 | }, |
| 1136 | }, |
| 1137 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1138 | name: "UnauthenticatedECDH", |
| 1139 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1140 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1141 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1142 | Bugs: ProtocolBugs{ |
| 1143 | UnauthenticatedECDH: true, |
| 1144 | }, |
| 1145 | }, |
| 1146 | shouldFail: true, |
| 1147 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1148 | }, |
| 1149 | { |
| 1150 | name: "SkipCertificateStatus", |
| 1151 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1152 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1153 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1154 | Bugs: ProtocolBugs{ |
| 1155 | SkipCertificateStatus: true, |
| 1156 | }, |
| 1157 | }, |
| 1158 | flags: []string{ |
| 1159 | "-enable-ocsp-stapling", |
| 1160 | }, |
| 1161 | }, |
| 1162 | { |
| 1163 | name: "SkipServerKeyExchange", |
| 1164 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1165 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1166 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1167 | Bugs: ProtocolBugs{ |
| 1168 | SkipServerKeyExchange: true, |
| 1169 | }, |
| 1170 | }, |
| 1171 | shouldFail: true, |
| 1172 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1173 | }, |
| 1174 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1175 | testType: serverTest, |
| 1176 | name: "Alert", |
| 1177 | config: Config{ |
| 1178 | Bugs: ProtocolBugs{ |
| 1179 | SendSpuriousAlert: alertRecordOverflow, |
| 1180 | }, |
| 1181 | }, |
| 1182 | shouldFail: true, |
| 1183 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1184 | }, |
| 1185 | { |
| 1186 | protocol: dtls, |
| 1187 | testType: serverTest, |
| 1188 | name: "Alert-DTLS", |
| 1189 | config: Config{ |
| 1190 | Bugs: ProtocolBugs{ |
| 1191 | SendSpuriousAlert: alertRecordOverflow, |
| 1192 | }, |
| 1193 | }, |
| 1194 | shouldFail: true, |
| 1195 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1196 | }, |
| 1197 | { |
| 1198 | testType: serverTest, |
| 1199 | name: "FragmentAlert", |
| 1200 | config: Config{ |
| 1201 | Bugs: ProtocolBugs{ |
| 1202 | FragmentAlert: true, |
| 1203 | SendSpuriousAlert: alertRecordOverflow, |
| 1204 | }, |
| 1205 | }, |
| 1206 | shouldFail: true, |
| 1207 | expectedError: ":BAD_ALERT:", |
| 1208 | }, |
| 1209 | { |
| 1210 | protocol: dtls, |
| 1211 | testType: serverTest, |
| 1212 | name: "FragmentAlert-DTLS", |
| 1213 | config: Config{ |
| 1214 | Bugs: ProtocolBugs{ |
| 1215 | FragmentAlert: true, |
| 1216 | SendSpuriousAlert: alertRecordOverflow, |
| 1217 | }, |
| 1218 | }, |
| 1219 | shouldFail: true, |
| 1220 | expectedError: ":BAD_ALERT:", |
| 1221 | }, |
| 1222 | { |
| 1223 | testType: serverTest, |
David Benjamin | 0d3a8c6 | 2016-03-11 22:25:18 -0500 | [diff] [blame] | 1224 | name: "DoubleAlert", |
| 1225 | config: Config{ |
| 1226 | Bugs: ProtocolBugs{ |
| 1227 | DoubleAlert: true, |
| 1228 | SendSpuriousAlert: alertRecordOverflow, |
| 1229 | }, |
| 1230 | }, |
| 1231 | shouldFail: true, |
| 1232 | expectedError: ":BAD_ALERT:", |
| 1233 | }, |
| 1234 | { |
| 1235 | protocol: dtls, |
| 1236 | testType: serverTest, |
| 1237 | name: "DoubleAlert-DTLS", |
| 1238 | config: Config{ |
| 1239 | Bugs: ProtocolBugs{ |
| 1240 | DoubleAlert: true, |
| 1241 | SendSpuriousAlert: alertRecordOverflow, |
| 1242 | }, |
| 1243 | }, |
| 1244 | shouldFail: true, |
| 1245 | expectedError: ":BAD_ALERT:", |
| 1246 | }, |
| 1247 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1248 | name: "SkipNewSessionTicket", |
| 1249 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1250 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1251 | Bugs: ProtocolBugs{ |
| 1252 | SkipNewSessionTicket: true, |
| 1253 | }, |
| 1254 | }, |
| 1255 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1256 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1257 | }, |
| 1258 | { |
| 1259 | testType: serverTest, |
| 1260 | name: "FallbackSCSV", |
| 1261 | config: Config{ |
| 1262 | MaxVersion: VersionTLS11, |
| 1263 | Bugs: ProtocolBugs{ |
| 1264 | SendFallbackSCSV: true, |
| 1265 | }, |
| 1266 | }, |
| 1267 | shouldFail: true, |
| 1268 | expectedError: ":INAPPROPRIATE_FALLBACK:", |
| 1269 | }, |
| 1270 | { |
| 1271 | testType: serverTest, |
| 1272 | name: "FallbackSCSV-VersionMatch", |
| 1273 | config: Config{ |
| 1274 | Bugs: ProtocolBugs{ |
| 1275 | SendFallbackSCSV: true, |
| 1276 | }, |
| 1277 | }, |
| 1278 | }, |
| 1279 | { |
| 1280 | testType: serverTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1281 | name: "FallbackSCSV-VersionMatch-TLS12", |
| 1282 | config: Config{ |
| 1283 | MaxVersion: VersionTLS12, |
| 1284 | Bugs: ProtocolBugs{ |
| 1285 | SendFallbackSCSV: true, |
| 1286 | }, |
| 1287 | }, |
| 1288 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 1289 | }, |
| 1290 | { |
| 1291 | testType: serverTest, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1292 | name: "FragmentedClientVersion", |
| 1293 | config: Config{ |
| 1294 | Bugs: ProtocolBugs{ |
| 1295 | MaxHandshakeRecordLength: 1, |
| 1296 | FragmentClientVersion: true, |
| 1297 | }, |
| 1298 | }, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1299 | expectedVersion: VersionTLS13, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1300 | }, |
| 1301 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1302 | testType: serverTest, |
| 1303 | name: "HttpGET", |
| 1304 | sendPrefix: "GET / HTTP/1.0\n", |
| 1305 | shouldFail: true, |
| 1306 | expectedError: ":HTTP_REQUEST:", |
| 1307 | }, |
| 1308 | { |
| 1309 | testType: serverTest, |
| 1310 | name: "HttpPOST", |
| 1311 | sendPrefix: "POST / HTTP/1.0\n", |
| 1312 | shouldFail: true, |
| 1313 | expectedError: ":HTTP_REQUEST:", |
| 1314 | }, |
| 1315 | { |
| 1316 | testType: serverTest, |
| 1317 | name: "HttpHEAD", |
| 1318 | sendPrefix: "HEAD / HTTP/1.0\n", |
| 1319 | shouldFail: true, |
| 1320 | expectedError: ":HTTP_REQUEST:", |
| 1321 | }, |
| 1322 | { |
| 1323 | testType: serverTest, |
| 1324 | name: "HttpPUT", |
| 1325 | sendPrefix: "PUT / HTTP/1.0\n", |
| 1326 | shouldFail: true, |
| 1327 | expectedError: ":HTTP_REQUEST:", |
| 1328 | }, |
| 1329 | { |
| 1330 | testType: serverTest, |
| 1331 | name: "HttpCONNECT", |
| 1332 | sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n", |
| 1333 | shouldFail: true, |
| 1334 | expectedError: ":HTTPS_PROXY_REQUEST:", |
| 1335 | }, |
| 1336 | { |
| 1337 | testType: serverTest, |
| 1338 | name: "Garbage", |
| 1339 | sendPrefix: "blah", |
| 1340 | shouldFail: true, |
David Benjamin | 97760d5 | 2015-07-24 23:02:49 -0400 | [diff] [blame] | 1341 | expectedError: ":WRONG_VERSION_NUMBER:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1342 | }, |
| 1343 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1344 | name: "RSAEphemeralKey", |
| 1345 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1346 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1347 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 1348 | Bugs: ProtocolBugs{ |
| 1349 | RSAEphemeralKey: true, |
| 1350 | }, |
| 1351 | }, |
| 1352 | shouldFail: true, |
| 1353 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1354 | }, |
| 1355 | { |
| 1356 | name: "DisableEverything", |
Steven Valdez | 4f94b1c | 2016-05-24 12:31:07 -0400 | [diff] [blame] | 1357 | flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1358 | shouldFail: true, |
| 1359 | expectedError: ":WRONG_SSL_VERSION:", |
| 1360 | }, |
| 1361 | { |
| 1362 | protocol: dtls, |
| 1363 | name: "DisableEverything-DTLS", |
| 1364 | flags: []string{"-no-tls12", "-no-tls1"}, |
| 1365 | shouldFail: true, |
| 1366 | expectedError: ":WRONG_SSL_VERSION:", |
| 1367 | }, |
| 1368 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1369 | protocol: dtls, |
| 1370 | testType: serverTest, |
| 1371 | name: "MTU", |
| 1372 | config: Config{ |
| 1373 | Bugs: ProtocolBugs{ |
| 1374 | MaxPacketLength: 256, |
| 1375 | }, |
| 1376 | }, |
| 1377 | flags: []string{"-mtu", "256"}, |
| 1378 | }, |
| 1379 | { |
| 1380 | protocol: dtls, |
| 1381 | testType: serverTest, |
| 1382 | name: "MTUExceeded", |
| 1383 | config: Config{ |
| 1384 | Bugs: ProtocolBugs{ |
| 1385 | MaxPacketLength: 255, |
| 1386 | }, |
| 1387 | }, |
| 1388 | flags: []string{"-mtu", "256"}, |
| 1389 | shouldFail: true, |
| 1390 | expectedLocalError: "dtls: exceeded maximum packet length", |
| 1391 | }, |
| 1392 | { |
| 1393 | name: "CertMismatchRSA", |
| 1394 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1395 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1396 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1397 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1398 | Bugs: ProtocolBugs{ |
| 1399 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1400 | }, |
| 1401 | }, |
| 1402 | shouldFail: true, |
| 1403 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1404 | }, |
| 1405 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1406 | name: "CertMismatchRSA-TLS13", |
| 1407 | config: Config{ |
| 1408 | MaxVersion: VersionTLS13, |
| 1409 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1410 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 1411 | Bugs: ProtocolBugs{ |
| 1412 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1413 | }, |
| 1414 | }, |
| 1415 | shouldFail: true, |
| 1416 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1417 | }, |
| 1418 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1419 | name: "CertMismatchECDSA", |
| 1420 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1421 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1422 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1423 | Certificates: []Certificate{rsaCertificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1424 | Bugs: ProtocolBugs{ |
| 1425 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1426 | }, |
| 1427 | }, |
| 1428 | shouldFail: true, |
| 1429 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1430 | }, |
| 1431 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1432 | name: "CertMismatchECDSA-TLS13", |
| 1433 | config: Config{ |
| 1434 | MaxVersion: VersionTLS13, |
| 1435 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1436 | Certificates: []Certificate{rsaCertificate}, |
| 1437 | Bugs: ProtocolBugs{ |
| 1438 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1439 | }, |
| 1440 | }, |
| 1441 | shouldFail: true, |
| 1442 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1443 | }, |
| 1444 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1445 | name: "EmptyCertificateList", |
| 1446 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1447 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1448 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1449 | Bugs: ProtocolBugs{ |
| 1450 | EmptyCertificateList: true, |
| 1451 | }, |
| 1452 | }, |
| 1453 | shouldFail: true, |
| 1454 | expectedError: ":DECODE_ERROR:", |
| 1455 | }, |
| 1456 | { |
David Benjamin | 9ec1c75 | 2016-07-14 12:45:01 -0400 | [diff] [blame] | 1457 | name: "EmptyCertificateList-TLS13", |
| 1458 | config: Config{ |
| 1459 | MaxVersion: VersionTLS13, |
| 1460 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1461 | Bugs: ProtocolBugs{ |
| 1462 | EmptyCertificateList: true, |
| 1463 | }, |
| 1464 | }, |
| 1465 | shouldFail: true, |
David Benjamin | 4087df9 | 2016-08-01 20:16:31 -0400 | [diff] [blame] | 1466 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
David Benjamin | 9ec1c75 | 2016-07-14 12:45:01 -0400 | [diff] [blame] | 1467 | }, |
| 1468 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1469 | name: "TLSFatalBadPackets", |
| 1470 | damageFirstWrite: true, |
| 1471 | shouldFail: true, |
| 1472 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 1473 | }, |
| 1474 | { |
| 1475 | protocol: dtls, |
| 1476 | name: "DTLSIgnoreBadPackets", |
| 1477 | damageFirstWrite: true, |
| 1478 | }, |
| 1479 | { |
| 1480 | protocol: dtls, |
| 1481 | name: "DTLSIgnoreBadPackets-Async", |
| 1482 | damageFirstWrite: true, |
| 1483 | flags: []string{"-async"}, |
| 1484 | }, |
| 1485 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1486 | name: "AppDataBeforeHandshake", |
| 1487 | config: Config{ |
| 1488 | Bugs: ProtocolBugs{ |
| 1489 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1490 | }, |
| 1491 | }, |
| 1492 | shouldFail: true, |
| 1493 | expectedError: ":UNEXPECTED_RECORD:", |
| 1494 | }, |
| 1495 | { |
| 1496 | name: "AppDataBeforeHandshake-Empty", |
| 1497 | config: Config{ |
| 1498 | Bugs: ProtocolBugs{ |
| 1499 | AppDataBeforeHandshake: []byte{}, |
| 1500 | }, |
| 1501 | }, |
| 1502 | shouldFail: true, |
| 1503 | expectedError: ":UNEXPECTED_RECORD:", |
| 1504 | }, |
| 1505 | { |
| 1506 | protocol: dtls, |
| 1507 | name: "AppDataBeforeHandshake-DTLS", |
| 1508 | config: Config{ |
| 1509 | Bugs: ProtocolBugs{ |
| 1510 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1511 | }, |
| 1512 | }, |
| 1513 | shouldFail: true, |
| 1514 | expectedError: ":UNEXPECTED_RECORD:", |
| 1515 | }, |
| 1516 | { |
| 1517 | protocol: dtls, |
| 1518 | name: "AppDataBeforeHandshake-DTLS-Empty", |
| 1519 | config: Config{ |
| 1520 | Bugs: ProtocolBugs{ |
| 1521 | AppDataBeforeHandshake: []byte{}, |
| 1522 | }, |
| 1523 | }, |
| 1524 | shouldFail: true, |
| 1525 | expectedError: ":UNEXPECTED_RECORD:", |
| 1526 | }, |
| 1527 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1528 | name: "AppDataAfterChangeCipherSpec", |
| 1529 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1530 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1531 | Bugs: ProtocolBugs{ |
| 1532 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1533 | }, |
| 1534 | }, |
| 1535 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1536 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1537 | }, |
| 1538 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1539 | name: "AppDataAfterChangeCipherSpec-Empty", |
| 1540 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1541 | MaxVersion: VersionTLS12, |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1542 | Bugs: ProtocolBugs{ |
| 1543 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1544 | }, |
| 1545 | }, |
| 1546 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1547 | expectedError: ":UNEXPECTED_RECORD:", |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1548 | }, |
| 1549 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1550 | protocol: dtls, |
| 1551 | name: "AppDataAfterChangeCipherSpec-DTLS", |
| 1552 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1553 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1554 | Bugs: ProtocolBugs{ |
| 1555 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1556 | }, |
| 1557 | }, |
| 1558 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1559 | // application data. |
| 1560 | }, |
| 1561 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1562 | protocol: dtls, |
| 1563 | name: "AppDataAfterChangeCipherSpec-DTLS-Empty", |
| 1564 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1565 | MaxVersion: VersionTLS12, |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1566 | Bugs: ProtocolBugs{ |
| 1567 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1568 | }, |
| 1569 | }, |
| 1570 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1571 | // application data. |
| 1572 | }, |
| 1573 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1574 | name: "AlertAfterChangeCipherSpec", |
| 1575 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1576 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1577 | Bugs: ProtocolBugs{ |
| 1578 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1579 | }, |
| 1580 | }, |
| 1581 | shouldFail: true, |
| 1582 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1583 | }, |
| 1584 | { |
| 1585 | protocol: dtls, |
| 1586 | name: "AlertAfterChangeCipherSpec-DTLS", |
| 1587 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1588 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1589 | Bugs: ProtocolBugs{ |
| 1590 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1591 | }, |
| 1592 | }, |
| 1593 | shouldFail: true, |
| 1594 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1595 | }, |
| 1596 | { |
| 1597 | protocol: dtls, |
| 1598 | name: "ReorderHandshakeFragments-Small-DTLS", |
| 1599 | config: Config{ |
| 1600 | Bugs: ProtocolBugs{ |
| 1601 | ReorderHandshakeFragments: true, |
| 1602 | // Small enough that every handshake message is |
| 1603 | // fragmented. |
| 1604 | MaxHandshakeRecordLength: 2, |
| 1605 | }, |
| 1606 | }, |
| 1607 | }, |
| 1608 | { |
| 1609 | protocol: dtls, |
| 1610 | name: "ReorderHandshakeFragments-Large-DTLS", |
| 1611 | config: Config{ |
| 1612 | Bugs: ProtocolBugs{ |
| 1613 | ReorderHandshakeFragments: true, |
| 1614 | // Large enough that no handshake message is |
| 1615 | // fragmented. |
| 1616 | MaxHandshakeRecordLength: 2048, |
| 1617 | }, |
| 1618 | }, |
| 1619 | }, |
| 1620 | { |
| 1621 | protocol: dtls, |
| 1622 | name: "MixCompleteMessageWithFragments-DTLS", |
| 1623 | config: Config{ |
| 1624 | Bugs: ProtocolBugs{ |
| 1625 | ReorderHandshakeFragments: true, |
| 1626 | MixCompleteMessageWithFragments: true, |
| 1627 | MaxHandshakeRecordLength: 2, |
| 1628 | }, |
| 1629 | }, |
| 1630 | }, |
| 1631 | { |
| 1632 | name: "SendInvalidRecordType", |
| 1633 | config: Config{ |
| 1634 | Bugs: ProtocolBugs{ |
| 1635 | SendInvalidRecordType: true, |
| 1636 | }, |
| 1637 | }, |
| 1638 | shouldFail: true, |
| 1639 | expectedError: ":UNEXPECTED_RECORD:", |
| 1640 | }, |
| 1641 | { |
| 1642 | protocol: dtls, |
| 1643 | name: "SendInvalidRecordType-DTLS", |
| 1644 | config: Config{ |
| 1645 | Bugs: ProtocolBugs{ |
| 1646 | SendInvalidRecordType: true, |
| 1647 | }, |
| 1648 | }, |
| 1649 | shouldFail: true, |
| 1650 | expectedError: ":UNEXPECTED_RECORD:", |
| 1651 | }, |
| 1652 | { |
| 1653 | name: "FalseStart-SkipServerSecondLeg", |
| 1654 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1655 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1656 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1657 | NextProtos: []string{"foo"}, |
| 1658 | Bugs: ProtocolBugs{ |
| 1659 | SkipNewSessionTicket: true, |
| 1660 | SkipChangeCipherSpec: true, |
| 1661 | SkipFinished: true, |
| 1662 | ExpectFalseStart: true, |
| 1663 | }, |
| 1664 | }, |
| 1665 | flags: []string{ |
| 1666 | "-false-start", |
| 1667 | "-handshake-never-done", |
| 1668 | "-advertise-alpn", "\x03foo", |
| 1669 | }, |
| 1670 | shimWritesFirst: true, |
| 1671 | shouldFail: true, |
| 1672 | expectedError: ":UNEXPECTED_RECORD:", |
| 1673 | }, |
| 1674 | { |
| 1675 | name: "FalseStart-SkipServerSecondLeg-Implicit", |
| 1676 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1677 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1678 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1679 | NextProtos: []string{"foo"}, |
| 1680 | Bugs: ProtocolBugs{ |
| 1681 | SkipNewSessionTicket: true, |
| 1682 | SkipChangeCipherSpec: true, |
| 1683 | SkipFinished: true, |
| 1684 | }, |
| 1685 | }, |
| 1686 | flags: []string{ |
| 1687 | "-implicit-handshake", |
| 1688 | "-false-start", |
| 1689 | "-handshake-never-done", |
| 1690 | "-advertise-alpn", "\x03foo", |
| 1691 | }, |
| 1692 | shouldFail: true, |
| 1693 | expectedError: ":UNEXPECTED_RECORD:", |
| 1694 | }, |
| 1695 | { |
| 1696 | testType: serverTest, |
| 1697 | name: "FailEarlyCallback", |
| 1698 | flags: []string{"-fail-early-callback"}, |
| 1699 | shouldFail: true, |
| 1700 | expectedError: ":CONNECTION_REJECTED:", |
| 1701 | expectedLocalError: "remote error: access denied", |
| 1702 | }, |
| 1703 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1704 | protocol: dtls, |
| 1705 | name: "FragmentMessageTypeMismatch-DTLS", |
| 1706 | config: Config{ |
| 1707 | Bugs: ProtocolBugs{ |
| 1708 | MaxHandshakeRecordLength: 2, |
| 1709 | FragmentMessageTypeMismatch: true, |
| 1710 | }, |
| 1711 | }, |
| 1712 | shouldFail: true, |
| 1713 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1714 | }, |
| 1715 | { |
| 1716 | protocol: dtls, |
| 1717 | name: "FragmentMessageLengthMismatch-DTLS", |
| 1718 | config: Config{ |
| 1719 | Bugs: ProtocolBugs{ |
| 1720 | MaxHandshakeRecordLength: 2, |
| 1721 | FragmentMessageLengthMismatch: true, |
| 1722 | }, |
| 1723 | }, |
| 1724 | shouldFail: true, |
| 1725 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1726 | }, |
| 1727 | { |
| 1728 | protocol: dtls, |
| 1729 | name: "SplitFragments-Header-DTLS", |
| 1730 | config: Config{ |
| 1731 | Bugs: ProtocolBugs{ |
| 1732 | SplitFragments: 2, |
| 1733 | }, |
| 1734 | }, |
| 1735 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1736 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1737 | }, |
| 1738 | { |
| 1739 | protocol: dtls, |
| 1740 | name: "SplitFragments-Boundary-DTLS", |
| 1741 | config: Config{ |
| 1742 | Bugs: ProtocolBugs{ |
| 1743 | SplitFragments: dtlsRecordHeaderLen, |
| 1744 | }, |
| 1745 | }, |
| 1746 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1747 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1748 | }, |
| 1749 | { |
| 1750 | protocol: dtls, |
| 1751 | name: "SplitFragments-Body-DTLS", |
| 1752 | config: Config{ |
| 1753 | Bugs: ProtocolBugs{ |
| 1754 | SplitFragments: dtlsRecordHeaderLen + 1, |
| 1755 | }, |
| 1756 | }, |
| 1757 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1758 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1759 | }, |
| 1760 | { |
| 1761 | protocol: dtls, |
| 1762 | name: "SendEmptyFragments-DTLS", |
| 1763 | config: Config{ |
| 1764 | Bugs: ProtocolBugs{ |
| 1765 | SendEmptyFragments: true, |
| 1766 | }, |
| 1767 | }, |
| 1768 | }, |
| 1769 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1770 | name: "BadFinished-Client", |
| 1771 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1772 | MaxVersion: VersionTLS12, |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1773 | Bugs: ProtocolBugs{ |
| 1774 | BadFinished: true, |
| 1775 | }, |
| 1776 | }, |
| 1777 | shouldFail: true, |
| 1778 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1779 | }, |
| 1780 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1781 | name: "BadFinished-Client-TLS13", |
| 1782 | config: Config{ |
| 1783 | MaxVersion: VersionTLS13, |
| 1784 | Bugs: ProtocolBugs{ |
| 1785 | BadFinished: true, |
| 1786 | }, |
| 1787 | }, |
| 1788 | shouldFail: true, |
| 1789 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1790 | }, |
| 1791 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1792 | testType: serverTest, |
| 1793 | name: "BadFinished-Server", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1794 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1795 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1796 | Bugs: ProtocolBugs{ |
| 1797 | BadFinished: true, |
| 1798 | }, |
| 1799 | }, |
| 1800 | shouldFail: true, |
| 1801 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1802 | }, |
| 1803 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1804 | testType: serverTest, |
| 1805 | name: "BadFinished-Server-TLS13", |
| 1806 | config: Config{ |
| 1807 | MaxVersion: VersionTLS13, |
| 1808 | Bugs: ProtocolBugs{ |
| 1809 | BadFinished: true, |
| 1810 | }, |
| 1811 | }, |
| 1812 | shouldFail: true, |
| 1813 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1814 | }, |
| 1815 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1816 | name: "FalseStart-BadFinished", |
| 1817 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1818 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1819 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1820 | NextProtos: []string{"foo"}, |
| 1821 | Bugs: ProtocolBugs{ |
| 1822 | BadFinished: true, |
| 1823 | ExpectFalseStart: true, |
| 1824 | }, |
| 1825 | }, |
| 1826 | flags: []string{ |
| 1827 | "-false-start", |
| 1828 | "-handshake-never-done", |
| 1829 | "-advertise-alpn", "\x03foo", |
| 1830 | }, |
| 1831 | shimWritesFirst: true, |
| 1832 | shouldFail: true, |
| 1833 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1834 | }, |
| 1835 | { |
| 1836 | name: "NoFalseStart-NoALPN", |
| 1837 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1838 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1839 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1840 | Bugs: ProtocolBugs{ |
| 1841 | ExpectFalseStart: true, |
| 1842 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1843 | }, |
| 1844 | }, |
| 1845 | flags: []string{ |
| 1846 | "-false-start", |
| 1847 | }, |
| 1848 | shimWritesFirst: true, |
| 1849 | shouldFail: true, |
| 1850 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1851 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1852 | }, |
| 1853 | { |
| 1854 | name: "NoFalseStart-NoAEAD", |
| 1855 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1856 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1857 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1858 | NextProtos: []string{"foo"}, |
| 1859 | Bugs: ProtocolBugs{ |
| 1860 | ExpectFalseStart: true, |
| 1861 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1862 | }, |
| 1863 | }, |
| 1864 | flags: []string{ |
| 1865 | "-false-start", |
| 1866 | "-advertise-alpn", "\x03foo", |
| 1867 | }, |
| 1868 | shimWritesFirst: true, |
| 1869 | shouldFail: true, |
| 1870 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1871 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1872 | }, |
| 1873 | { |
| 1874 | name: "NoFalseStart-RSA", |
| 1875 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1876 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1877 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1878 | NextProtos: []string{"foo"}, |
| 1879 | Bugs: ProtocolBugs{ |
| 1880 | ExpectFalseStart: true, |
| 1881 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1882 | }, |
| 1883 | }, |
| 1884 | flags: []string{ |
| 1885 | "-false-start", |
| 1886 | "-advertise-alpn", "\x03foo", |
| 1887 | }, |
| 1888 | shimWritesFirst: true, |
| 1889 | shouldFail: true, |
| 1890 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1891 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1892 | }, |
| 1893 | { |
| 1894 | name: "NoFalseStart-DHE_RSA", |
| 1895 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1896 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1897 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1898 | NextProtos: []string{"foo"}, |
| 1899 | Bugs: ProtocolBugs{ |
| 1900 | ExpectFalseStart: true, |
| 1901 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1902 | }, |
| 1903 | }, |
| 1904 | flags: []string{ |
| 1905 | "-false-start", |
| 1906 | "-advertise-alpn", "\x03foo", |
| 1907 | }, |
| 1908 | shimWritesFirst: true, |
| 1909 | shouldFail: true, |
| 1910 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1911 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1912 | }, |
| 1913 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1914 | protocol: dtls, |
| 1915 | name: "SendSplitAlert-Sync", |
| 1916 | config: Config{ |
| 1917 | Bugs: ProtocolBugs{ |
| 1918 | SendSplitAlert: true, |
| 1919 | }, |
| 1920 | }, |
| 1921 | }, |
| 1922 | { |
| 1923 | protocol: dtls, |
| 1924 | name: "SendSplitAlert-Async", |
| 1925 | config: Config{ |
| 1926 | Bugs: ProtocolBugs{ |
| 1927 | SendSplitAlert: true, |
| 1928 | }, |
| 1929 | }, |
| 1930 | flags: []string{"-async"}, |
| 1931 | }, |
| 1932 | { |
| 1933 | protocol: dtls, |
| 1934 | name: "PackDTLSHandshake", |
| 1935 | config: Config{ |
| 1936 | Bugs: ProtocolBugs{ |
| 1937 | MaxHandshakeRecordLength: 2, |
| 1938 | PackHandshakeFragments: 20, |
| 1939 | PackHandshakeRecords: 200, |
| 1940 | }, |
| 1941 | }, |
| 1942 | }, |
| 1943 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1944 | name: "SendEmptyRecords-Pass", |
| 1945 | sendEmptyRecords: 32, |
| 1946 | }, |
| 1947 | { |
| 1948 | name: "SendEmptyRecords", |
| 1949 | sendEmptyRecords: 33, |
| 1950 | shouldFail: true, |
| 1951 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1952 | }, |
| 1953 | { |
| 1954 | name: "SendEmptyRecords-Async", |
| 1955 | sendEmptyRecords: 33, |
| 1956 | flags: []string{"-async"}, |
| 1957 | shouldFail: true, |
| 1958 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1959 | }, |
| 1960 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 1961 | name: "SendWarningAlerts-Pass", |
| 1962 | config: Config{ |
| 1963 | MaxVersion: VersionTLS12, |
| 1964 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1965 | sendWarningAlerts: 4, |
| 1966 | }, |
| 1967 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 1968 | protocol: dtls, |
| 1969 | name: "SendWarningAlerts-DTLS-Pass", |
| 1970 | config: Config{ |
| 1971 | MaxVersion: VersionTLS12, |
| 1972 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1973 | sendWarningAlerts: 4, |
| 1974 | }, |
| 1975 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 1976 | name: "SendWarningAlerts-TLS13", |
| 1977 | config: Config{ |
| 1978 | MaxVersion: VersionTLS13, |
| 1979 | }, |
| 1980 | sendWarningAlerts: 4, |
| 1981 | shouldFail: true, |
| 1982 | expectedError: ":BAD_ALERT:", |
| 1983 | expectedLocalError: "remote error: error decoding message", |
| 1984 | }, |
| 1985 | { |
| 1986 | name: "SendWarningAlerts", |
| 1987 | config: Config{ |
| 1988 | MaxVersion: VersionTLS12, |
| 1989 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1990 | sendWarningAlerts: 5, |
| 1991 | shouldFail: true, |
| 1992 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 1993 | }, |
| 1994 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 1995 | name: "SendWarningAlerts-Async", |
| 1996 | config: Config{ |
| 1997 | MaxVersion: VersionTLS12, |
| 1998 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1999 | sendWarningAlerts: 5, |
| 2000 | flags: []string{"-async"}, |
| 2001 | shouldFail: true, |
| 2002 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 2003 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 2004 | { |
| 2005 | name: "EmptySessionID", |
| 2006 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2007 | MaxVersion: VersionTLS12, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 2008 | SessionTicketsDisabled: true, |
| 2009 | }, |
| 2010 | noSessionCache: true, |
| 2011 | flags: []string{"-expect-no-session"}, |
| 2012 | }, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 2013 | { |
| 2014 | name: "Unclean-Shutdown", |
| 2015 | config: Config{ |
| 2016 | Bugs: ProtocolBugs{ |
| 2017 | NoCloseNotify: true, |
| 2018 | ExpectCloseNotify: true, |
| 2019 | }, |
| 2020 | }, |
| 2021 | shimShutsDown: true, |
| 2022 | flags: []string{"-check-close-notify"}, |
| 2023 | shouldFail: true, |
| 2024 | expectedError: "Unexpected SSL_shutdown result: -1 != 1", |
| 2025 | }, |
| 2026 | { |
| 2027 | name: "Unclean-Shutdown-Ignored", |
| 2028 | config: Config{ |
| 2029 | Bugs: ProtocolBugs{ |
| 2030 | NoCloseNotify: true, |
| 2031 | }, |
| 2032 | }, |
| 2033 | shimShutsDown: true, |
| 2034 | }, |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 2035 | { |
David Benjamin | fa214e4 | 2016-05-10 17:03:10 -0400 | [diff] [blame] | 2036 | name: "Unclean-Shutdown-Alert", |
| 2037 | config: Config{ |
| 2038 | Bugs: ProtocolBugs{ |
| 2039 | SendAlertOnShutdown: alertDecompressionFailure, |
| 2040 | ExpectCloseNotify: true, |
| 2041 | }, |
| 2042 | }, |
| 2043 | shimShutsDown: true, |
| 2044 | flags: []string{"-check-close-notify"}, |
| 2045 | shouldFail: true, |
| 2046 | expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:", |
| 2047 | }, |
| 2048 | { |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 2049 | name: "LargePlaintext", |
| 2050 | config: Config{ |
| 2051 | Bugs: ProtocolBugs{ |
| 2052 | SendLargeRecords: true, |
| 2053 | }, |
| 2054 | }, |
| 2055 | messageLen: maxPlaintext + 1, |
| 2056 | shouldFail: true, |
| 2057 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2058 | }, |
| 2059 | { |
| 2060 | protocol: dtls, |
| 2061 | name: "LargePlaintext-DTLS", |
| 2062 | config: Config{ |
| 2063 | Bugs: ProtocolBugs{ |
| 2064 | SendLargeRecords: true, |
| 2065 | }, |
| 2066 | }, |
| 2067 | messageLen: maxPlaintext + 1, |
| 2068 | shouldFail: true, |
| 2069 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2070 | }, |
| 2071 | { |
| 2072 | name: "LargeCiphertext", |
| 2073 | config: Config{ |
| 2074 | Bugs: ProtocolBugs{ |
| 2075 | SendLargeRecords: true, |
| 2076 | }, |
| 2077 | }, |
| 2078 | messageLen: maxPlaintext * 2, |
| 2079 | shouldFail: true, |
| 2080 | expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:", |
| 2081 | }, |
| 2082 | { |
| 2083 | protocol: dtls, |
| 2084 | name: "LargeCiphertext-DTLS", |
| 2085 | config: Config{ |
| 2086 | Bugs: ProtocolBugs{ |
| 2087 | SendLargeRecords: true, |
| 2088 | }, |
| 2089 | }, |
| 2090 | messageLen: maxPlaintext * 2, |
| 2091 | // Unlike the other four cases, DTLS drops records which |
| 2092 | // are invalid before authentication, so the connection |
| 2093 | // does not fail. |
| 2094 | expectMessageDropped: true, |
| 2095 | }, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2096 | { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2097 | // In TLS 1.2 and below, empty NewSessionTicket messages |
| 2098 | // mean the server changed its mind on sending a ticket. |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2099 | name: "SendEmptySessionTicket", |
| 2100 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2101 | MaxVersion: VersionTLS12, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2102 | Bugs: ProtocolBugs{ |
| 2103 | SendEmptySessionTicket: true, |
| 2104 | FailIfSessionOffered: true, |
| 2105 | }, |
| 2106 | }, |
| 2107 | flags: []string{"-expect-no-session"}, |
| 2108 | resumeSession: true, |
| 2109 | expectResumeRejected: true, |
| 2110 | }, |
David Benjamin | 99fdfb9 | 2015-11-02 12:11:35 -0500 | [diff] [blame] | 2111 | { |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2112 | name: "BadHelloRequest-1", |
| 2113 | renegotiate: 1, |
| 2114 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2115 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2116 | Bugs: ProtocolBugs{ |
| 2117 | BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1}, |
| 2118 | }, |
| 2119 | }, |
| 2120 | flags: []string{ |
| 2121 | "-renegotiate-freely", |
| 2122 | "-expect-total-renegotiations", "1", |
| 2123 | }, |
| 2124 | shouldFail: true, |
David Benjamin | 163f29a | 2016-07-28 11:05:58 -0400 | [diff] [blame] | 2125 | expectedError: ":EXCESSIVE_MESSAGE_SIZE:", |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2126 | }, |
| 2127 | { |
| 2128 | name: "BadHelloRequest-2", |
| 2129 | renegotiate: 1, |
| 2130 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2131 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2132 | Bugs: ProtocolBugs{ |
| 2133 | BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0}, |
| 2134 | }, |
| 2135 | }, |
| 2136 | flags: []string{ |
| 2137 | "-renegotiate-freely", |
| 2138 | "-expect-total-renegotiations", "1", |
| 2139 | }, |
| 2140 | shouldFail: true, |
| 2141 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2142 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2143 | { |
| 2144 | testType: serverTest, |
| 2145 | name: "SupportTicketsWithSessionID", |
| 2146 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2147 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2148 | SessionTicketsDisabled: true, |
| 2149 | }, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2150 | resumeConfig: &Config{ |
| 2151 | MaxVersion: VersionTLS12, |
| 2152 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2153 | resumeSession: true, |
| 2154 | }, |
David Benjamin | 02edcd0 | 2016-07-27 17:40:37 -0400 | [diff] [blame] | 2155 | { |
| 2156 | protocol: dtls, |
| 2157 | name: "DTLS-SendExtraFinished", |
| 2158 | config: Config{ |
| 2159 | Bugs: ProtocolBugs{ |
| 2160 | SendExtraFinished: true, |
| 2161 | }, |
| 2162 | }, |
| 2163 | shouldFail: true, |
| 2164 | expectedError: ":UNEXPECTED_RECORD:", |
| 2165 | }, |
| 2166 | { |
| 2167 | protocol: dtls, |
| 2168 | name: "DTLS-SendExtraFinished-Reordered", |
| 2169 | config: Config{ |
| 2170 | Bugs: ProtocolBugs{ |
| 2171 | MaxHandshakeRecordLength: 2, |
| 2172 | ReorderHandshakeFragments: true, |
| 2173 | SendExtraFinished: true, |
| 2174 | }, |
| 2175 | }, |
| 2176 | shouldFail: true, |
| 2177 | expectedError: ":UNEXPECTED_RECORD:", |
| 2178 | }, |
David Benjamin | e97fb48 | 2016-07-29 09:23:07 -0400 | [diff] [blame] | 2179 | { |
| 2180 | testType: serverTest, |
| 2181 | name: "V2ClientHello-EmptyRecordPrefix", |
| 2182 | config: Config{ |
| 2183 | // Choose a cipher suite that does not involve |
| 2184 | // elliptic curves, so no extensions are |
| 2185 | // involved. |
| 2186 | MaxVersion: VersionTLS12, |
| 2187 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2188 | Bugs: ProtocolBugs{ |
| 2189 | SendV2ClientHello: true, |
| 2190 | }, |
| 2191 | }, |
| 2192 | sendPrefix: string([]byte{ |
| 2193 | byte(recordTypeHandshake), |
| 2194 | 3, 1, // version |
| 2195 | 0, 0, // length |
| 2196 | }), |
| 2197 | // A no-op empty record may not be sent before V2ClientHello. |
| 2198 | shouldFail: true, |
| 2199 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 2200 | }, |
| 2201 | { |
| 2202 | testType: serverTest, |
| 2203 | name: "V2ClientHello-WarningAlertPrefix", |
| 2204 | config: Config{ |
| 2205 | // Choose a cipher suite that does not involve |
| 2206 | // elliptic curves, so no extensions are |
| 2207 | // involved. |
| 2208 | MaxVersion: VersionTLS12, |
| 2209 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2210 | Bugs: ProtocolBugs{ |
| 2211 | SendV2ClientHello: true, |
| 2212 | }, |
| 2213 | }, |
| 2214 | sendPrefix: string([]byte{ |
| 2215 | byte(recordTypeAlert), |
| 2216 | 3, 1, // version |
| 2217 | 0, 2, // length |
| 2218 | alertLevelWarning, byte(alertDecompressionFailure), |
| 2219 | }), |
| 2220 | // A no-op warning alert may not be sent before V2ClientHello. |
| 2221 | shouldFail: true, |
| 2222 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 2223 | }, |
Steven Valdez | 1dc53d2 | 2016-07-26 12:27:38 -0400 | [diff] [blame] | 2224 | { |
| 2225 | testType: clientTest, |
| 2226 | name: "KeyUpdate", |
| 2227 | config: Config{ |
| 2228 | MaxVersion: VersionTLS13, |
| 2229 | Bugs: ProtocolBugs{ |
| 2230 | SendKeyUpdateBeforeEveryAppDataRecord: true, |
| 2231 | }, |
| 2232 | }, |
| 2233 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2234 | } |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2235 | testCases = append(testCases, basicTests...) |
| 2236 | } |
| 2237 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2238 | func addCipherSuiteTests() { |
David Benjamin | e470e66 | 2016-07-18 15:47:32 +0200 | [diff] [blame] | 2239 | const bogusCipher = 0xfe00 |
| 2240 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2241 | for _, suite := range testCipherSuites { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2242 | const psk = "12345" |
| 2243 | const pskIdentity = "luggage combo" |
| 2244 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2245 | var cert Certificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2246 | var certFile string |
| 2247 | var keyFile string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2248 | if hasComponent(suite.name, "ECDSA") { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2249 | cert = ecdsaP256Certificate |
| 2250 | certFile = ecdsaP256CertificateFile |
| 2251 | keyFile = ecdsaP256KeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2252 | } else { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2253 | cert = rsaCertificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2254 | certFile = rsaCertificateFile |
| 2255 | keyFile = rsaKeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2258 | var flags []string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2259 | if hasComponent(suite.name, "PSK") { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2260 | flags = append(flags, |
| 2261 | "-psk", psk, |
| 2262 | "-psk-identity", pskIdentity) |
| 2263 | } |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 2264 | if hasComponent(suite.name, "NULL") { |
| 2265 | // NULL ciphers must be explicitly enabled. |
| 2266 | flags = append(flags, "-cipher", "DEFAULT:NULL-SHA") |
| 2267 | } |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 2268 | if hasComponent(suite.name, "CECPQ1") { |
| 2269 | // CECPQ1 ciphers must be explicitly enabled. |
| 2270 | flags = append(flags, "-cipher", "DEFAULT:kCECPQ1") |
| 2271 | } |
David Benjamin | 881f196 | 2016-08-10 18:29:12 -0400 | [diff] [blame] | 2272 | if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") { |
| 2273 | // ECDHE_PSK AES_GCM ciphers must be explicitly enabled |
| 2274 | // for now. |
| 2275 | flags = append(flags, "-cipher", suite.name) |
| 2276 | } |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2277 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2278 | for _, ver := range tlsVersions { |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2279 | for _, protocol := range []protocol{tls, dtls} { |
| 2280 | var prefix string |
| 2281 | if protocol == dtls { |
| 2282 | if !ver.hasDTLS { |
| 2283 | continue |
| 2284 | } |
| 2285 | prefix = "D" |
| 2286 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2287 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2288 | var shouldServerFail, shouldClientFail bool |
| 2289 | if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 { |
| 2290 | // BoringSSL clients accept ECDHE on SSLv3, but |
| 2291 | // a BoringSSL server will never select it |
| 2292 | // because the extension is missing. |
| 2293 | shouldServerFail = true |
| 2294 | } |
| 2295 | if isTLS12Only(suite.name) && ver.version < VersionTLS12 { |
| 2296 | shouldClientFail = true |
| 2297 | shouldServerFail = true |
| 2298 | } |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 2299 | if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2300 | shouldClientFail = true |
| 2301 | shouldServerFail = true |
| 2302 | } |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2303 | if !isDTLSCipher(suite.name) && protocol == dtls { |
| 2304 | shouldClientFail = true |
| 2305 | shouldServerFail = true |
| 2306 | } |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 2307 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2308 | var expectedServerError, expectedClientError string |
| 2309 | if shouldServerFail { |
| 2310 | expectedServerError = ":NO_SHARED_CIPHER:" |
| 2311 | } |
| 2312 | if shouldClientFail { |
| 2313 | expectedClientError = ":WRONG_CIPHER_RETURNED:" |
| 2314 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2315 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2316 | testCases = append(testCases, testCase{ |
| 2317 | testType: serverTest, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2318 | protocol: protocol, |
| 2319 | |
| 2320 | name: prefix + ver.name + "-" + suite.name + "-server", |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2321 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2322 | MinVersion: ver.version, |
| 2323 | MaxVersion: ver.version, |
| 2324 | CipherSuites: []uint16{suite.id}, |
| 2325 | Certificates: []Certificate{cert}, |
| 2326 | PreSharedKey: []byte(psk), |
| 2327 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2328 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2329 | EnableAllCiphers: shouldServerFail, |
| 2330 | IgnorePeerCipherPreferences: shouldServerFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2331 | }, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2332 | }, |
| 2333 | certFile: certFile, |
| 2334 | keyFile: keyFile, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2335 | flags: flags, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 2336 | resumeSession: true, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2337 | shouldFail: shouldServerFail, |
| 2338 | expectedError: expectedServerError, |
| 2339 | }) |
| 2340 | |
| 2341 | testCases = append(testCases, testCase{ |
| 2342 | testType: clientTest, |
| 2343 | protocol: protocol, |
| 2344 | name: prefix + ver.name + "-" + suite.name + "-client", |
| 2345 | config: Config{ |
| 2346 | MinVersion: ver.version, |
| 2347 | MaxVersion: ver.version, |
| 2348 | CipherSuites: []uint16{suite.id}, |
| 2349 | Certificates: []Certificate{cert}, |
| 2350 | PreSharedKey: []byte(psk), |
| 2351 | PreSharedKeyIdentity: pskIdentity, |
| 2352 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2353 | EnableAllCiphers: shouldClientFail, |
| 2354 | IgnorePeerCipherPreferences: shouldClientFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2355 | }, |
| 2356 | }, |
| 2357 | flags: flags, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 2358 | resumeSession: true, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2359 | shouldFail: shouldClientFail, |
| 2360 | expectedError: expectedClientError, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2361 | }) |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2362 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2363 | if !shouldClientFail { |
| 2364 | // Ensure the maximum record size is accepted. |
| 2365 | testCases = append(testCases, testCase{ |
| 2366 | name: prefix + ver.name + "-" + suite.name + "-LargeRecord", |
| 2367 | config: Config{ |
| 2368 | MinVersion: ver.version, |
| 2369 | MaxVersion: ver.version, |
| 2370 | CipherSuites: []uint16{suite.id}, |
| 2371 | Certificates: []Certificate{cert}, |
| 2372 | PreSharedKey: []byte(psk), |
| 2373 | PreSharedKeyIdentity: pskIdentity, |
| 2374 | }, |
| 2375 | flags: flags, |
| 2376 | messageLen: maxPlaintext, |
| 2377 | }) |
| 2378 | } |
| 2379 | } |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2380 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2381 | } |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2382 | |
| 2383 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2384 | name: "NoSharedCipher", |
| 2385 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2386 | MaxVersion: VersionTLS12, |
| 2387 | CipherSuites: []uint16{}, |
| 2388 | }, |
| 2389 | shouldFail: true, |
| 2390 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2391 | }) |
| 2392 | |
| 2393 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2394 | name: "NoSharedCipher-TLS13", |
| 2395 | config: Config{ |
| 2396 | MaxVersion: VersionTLS13, |
| 2397 | CipherSuites: []uint16{}, |
| 2398 | }, |
| 2399 | shouldFail: true, |
| 2400 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2401 | }) |
| 2402 | |
| 2403 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2404 | name: "UnsupportedCipherSuite", |
| 2405 | config: Config{ |
| 2406 | MaxVersion: VersionTLS12, |
| 2407 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2408 | Bugs: ProtocolBugs{ |
| 2409 | IgnorePeerCipherPreferences: true, |
| 2410 | }, |
| 2411 | }, |
| 2412 | flags: []string{"-cipher", "DEFAULT:!RC4"}, |
| 2413 | shouldFail: true, |
| 2414 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 2415 | }) |
| 2416 | |
| 2417 | testCases = append(testCases, testCase{ |
David Benjamin | e470e66 | 2016-07-18 15:47:32 +0200 | [diff] [blame] | 2418 | name: "ServerHelloBogusCipher", |
| 2419 | config: Config{ |
| 2420 | MaxVersion: VersionTLS12, |
| 2421 | Bugs: ProtocolBugs{ |
| 2422 | SendCipherSuite: bogusCipher, |
| 2423 | }, |
| 2424 | }, |
| 2425 | shouldFail: true, |
| 2426 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2427 | }) |
| 2428 | testCases = append(testCases, testCase{ |
| 2429 | name: "ServerHelloBogusCipher-TLS13", |
| 2430 | config: Config{ |
| 2431 | MaxVersion: VersionTLS13, |
| 2432 | Bugs: ProtocolBugs{ |
| 2433 | SendCipherSuite: bogusCipher, |
| 2434 | }, |
| 2435 | }, |
| 2436 | shouldFail: true, |
| 2437 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2438 | }) |
| 2439 | |
| 2440 | testCases = append(testCases, testCase{ |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2441 | name: "WeakDH", |
| 2442 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2443 | MaxVersion: VersionTLS12, |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2444 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2445 | Bugs: ProtocolBugs{ |
| 2446 | // This is a 1023-bit prime number, generated |
| 2447 | // with: |
| 2448 | // openssl gendh 1023 | openssl asn1parse -i |
| 2449 | DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"), |
| 2450 | }, |
| 2451 | }, |
| 2452 | shouldFail: true, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2453 | expectedError: ":BAD_DH_P_LENGTH:", |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2454 | }) |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2455 | |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2456 | testCases = append(testCases, testCase{ |
| 2457 | name: "SillyDH", |
| 2458 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2459 | MaxVersion: VersionTLS12, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2460 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2461 | Bugs: ProtocolBugs{ |
| 2462 | // This is a 4097-bit prime number, generated |
| 2463 | // with: |
| 2464 | // openssl gendh 4097 | openssl asn1parse -i |
| 2465 | DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"), |
| 2466 | }, |
| 2467 | }, |
| 2468 | shouldFail: true, |
| 2469 | expectedError: ":DH_P_TOO_LONG:", |
| 2470 | }) |
| 2471 | |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2472 | // This test ensures that Diffie-Hellman public values are padded with |
| 2473 | // zeros so that they're the same length as the prime. This is to avoid |
| 2474 | // hitting a bug in yaSSL. |
| 2475 | testCases = append(testCases, testCase{ |
| 2476 | testType: serverTest, |
| 2477 | name: "DHPublicValuePadded", |
| 2478 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2479 | MaxVersion: VersionTLS12, |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2480 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2481 | Bugs: ProtocolBugs{ |
| 2482 | RequireDHPublicValueLen: (1025 + 7) / 8, |
| 2483 | }, |
| 2484 | }, |
| 2485 | flags: []string{"-use-sparse-dh-prime"}, |
| 2486 | }) |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2487 | |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2488 | // The server must be tolerant to bogus ciphers. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2489 | testCases = append(testCases, testCase{ |
| 2490 | testType: serverTest, |
| 2491 | name: "UnknownCipher", |
| 2492 | config: Config{ |
| 2493 | CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2494 | }, |
| 2495 | }) |
| 2496 | |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2497 | // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS |
| 2498 | // 1.1 specific cipher suite settings. A server is setup with the given |
| 2499 | // cipher lists and then a connection is made for each member of |
| 2500 | // expectations. The cipher suite that the server selects must match |
| 2501 | // the specified one. |
| 2502 | var versionSpecificCiphersTest = []struct { |
| 2503 | ciphersDefault, ciphersTLS10, ciphersTLS11 string |
| 2504 | // expectations is a map from TLS version to cipher suite id. |
| 2505 | expectations map[uint16]uint16 |
| 2506 | }{ |
| 2507 | { |
| 2508 | // Test that the null case (where no version-specific ciphers are set) |
| 2509 | // works as expected. |
| 2510 | "RC4-SHA:AES128-SHA", // default ciphers |
| 2511 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2512 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2513 | map[uint16]uint16{ |
| 2514 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2515 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2516 | VersionTLS11: TLS_RSA_WITH_RC4_128_SHA, |
| 2517 | VersionTLS12: TLS_RSA_WITH_RC4_128_SHA, |
| 2518 | }, |
| 2519 | }, |
| 2520 | { |
| 2521 | // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different |
| 2522 | // cipher. |
| 2523 | "RC4-SHA:AES128-SHA", // default |
| 2524 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2525 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2526 | map[uint16]uint16{ |
| 2527 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2528 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2529 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2530 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2531 | }, |
| 2532 | }, |
| 2533 | { |
| 2534 | // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different |
| 2535 | // cipher. |
| 2536 | "RC4-SHA:AES128-SHA", // default |
| 2537 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2538 | "AES128-SHA", // these ciphers for TLS ≥ 1.1 |
| 2539 | map[uint16]uint16{ |
| 2540 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2541 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2542 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2543 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2544 | }, |
| 2545 | }, |
| 2546 | { |
| 2547 | // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should |
| 2548 | // mask ciphers_tls10 for TLS 1.1 and 1.2. |
| 2549 | "RC4-SHA:AES128-SHA", // default |
| 2550 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2551 | "AES256-SHA", // these ciphers for TLS ≥ 1.1 |
| 2552 | map[uint16]uint16{ |
| 2553 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2554 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2555 | VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2556 | VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2557 | }, |
| 2558 | }, |
| 2559 | } |
| 2560 | |
| 2561 | for i, test := range versionSpecificCiphersTest { |
| 2562 | for version, expectedCipherSuite := range test.expectations { |
| 2563 | flags := []string{"-cipher", test.ciphersDefault} |
| 2564 | if len(test.ciphersTLS10) > 0 { |
| 2565 | flags = append(flags, "-cipher-tls10", test.ciphersTLS10) |
| 2566 | } |
| 2567 | if len(test.ciphersTLS11) > 0 { |
| 2568 | flags = append(flags, "-cipher-tls11", test.ciphersTLS11) |
| 2569 | } |
| 2570 | |
| 2571 | testCases = append(testCases, testCase{ |
| 2572 | testType: serverTest, |
| 2573 | name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version), |
| 2574 | config: Config{ |
| 2575 | MaxVersion: version, |
| 2576 | MinVersion: version, |
| 2577 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA}, |
| 2578 | }, |
| 2579 | flags: flags, |
| 2580 | expectedCipher: expectedCipherSuite, |
| 2581 | }) |
| 2582 | } |
| 2583 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | func addBadECDSASignatureTests() { |
| 2587 | for badR := BadValue(1); badR < NumBadValues; badR++ { |
| 2588 | for badS := BadValue(1); badS < NumBadValues; badS++ { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2589 | testCases = append(testCases, testCase{ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2590 | name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS), |
| 2591 | config: Config{ |
| 2592 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2593 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2594 | Bugs: ProtocolBugs{ |
| 2595 | BadECDSAR: badR, |
| 2596 | BadECDSAS: badS, |
| 2597 | }, |
| 2598 | }, |
| 2599 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2600 | expectedError: ":BAD_SIGNATURE:", |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2601 | }) |
| 2602 | } |
| 2603 | } |
| 2604 | } |
| 2605 | |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2606 | func addCBCPaddingTests() { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2607 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2608 | name: "MaxCBCPadding", |
| 2609 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2610 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2611 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2612 | Bugs: ProtocolBugs{ |
| 2613 | MaxPadding: true, |
| 2614 | }, |
| 2615 | }, |
| 2616 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2617 | }) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2618 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2619 | name: "BadCBCPadding", |
| 2620 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2621 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2622 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2623 | Bugs: ProtocolBugs{ |
| 2624 | PaddingFirstByteBad: true, |
| 2625 | }, |
| 2626 | }, |
| 2627 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2628 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2629 | }) |
| 2630 | // OpenSSL previously had an issue where the first byte of padding in |
| 2631 | // 255 bytes of padding wasn't checked. |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2632 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2633 | name: "BadCBCPadding255", |
| 2634 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2635 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2636 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2637 | Bugs: ProtocolBugs{ |
| 2638 | MaxPadding: true, |
| 2639 | PaddingFirstByteBadIf255: true, |
| 2640 | }, |
| 2641 | }, |
| 2642 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2643 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2644 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2645 | }) |
| 2646 | } |
| 2647 | |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2648 | func addCBCSplittingTests() { |
| 2649 | testCases = append(testCases, testCase{ |
| 2650 | name: "CBCRecordSplitting", |
| 2651 | config: Config{ |
| 2652 | MaxVersion: VersionTLS10, |
| 2653 | MinVersion: VersionTLS10, |
| 2654 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2655 | }, |
David Benjamin | ac8302a | 2015-09-01 17:18:15 -0400 | [diff] [blame] | 2656 | messageLen: -1, // read until EOF |
| 2657 | resumeSession: true, |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2658 | flags: []string{ |
| 2659 | "-async", |
| 2660 | "-write-different-record-sizes", |
| 2661 | "-cbc-record-splitting", |
| 2662 | }, |
David Benjamin | a8e3e0e | 2014-08-06 22:11:10 -0400 | [diff] [blame] | 2663 | }) |
| 2664 | testCases = append(testCases, testCase{ |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2665 | name: "CBCRecordSplittingPartialWrite", |
| 2666 | config: Config{ |
| 2667 | MaxVersion: VersionTLS10, |
| 2668 | MinVersion: VersionTLS10, |
| 2669 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2670 | }, |
| 2671 | messageLen: -1, // read until EOF |
| 2672 | flags: []string{ |
| 2673 | "-async", |
| 2674 | "-write-different-record-sizes", |
| 2675 | "-cbc-record-splitting", |
| 2676 | "-partial-write", |
| 2677 | }, |
| 2678 | }) |
| 2679 | } |
| 2680 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2681 | func addClientAuthTests() { |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 2682 | // Add a dummy cert pool to stress certificate authority parsing. |
| 2683 | // TODO(davidben): Add tests that those values parse out correctly. |
| 2684 | certPool := x509.NewCertPool() |
| 2685 | cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0]) |
| 2686 | if err != nil { |
| 2687 | panic(err) |
| 2688 | } |
| 2689 | certPool.AddCert(cert) |
| 2690 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2691 | for _, ver := range tlsVersions { |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2692 | testCases = append(testCases, testCase{ |
| 2693 | testType: clientTest, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2694 | name: ver.name + "-Client-ClientAuth-RSA", |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2695 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2696 | MinVersion: ver.version, |
| 2697 | MaxVersion: ver.version, |
| 2698 | ClientAuth: RequireAnyClientCert, |
| 2699 | ClientCAs: certPool, |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2700 | }, |
| 2701 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2702 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2703 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2704 | }, |
| 2705 | }) |
| 2706 | testCases = append(testCases, testCase{ |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2707 | testType: serverTest, |
| 2708 | name: ver.name + "-Server-ClientAuth-RSA", |
| 2709 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2710 | MinVersion: ver.version, |
| 2711 | MaxVersion: ver.version, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2712 | Certificates: []Certificate{rsaCertificate}, |
| 2713 | }, |
| 2714 | flags: []string{"-require-any-client-certificate"}, |
| 2715 | }) |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2716 | if ver.version != VersionSSL30 { |
| 2717 | testCases = append(testCases, testCase{ |
| 2718 | testType: serverTest, |
| 2719 | name: ver.name + "-Server-ClientAuth-ECDSA", |
| 2720 | config: Config{ |
| 2721 | MinVersion: ver.version, |
| 2722 | MaxVersion: ver.version, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2723 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2724 | }, |
| 2725 | flags: []string{"-require-any-client-certificate"}, |
| 2726 | }) |
| 2727 | testCases = append(testCases, testCase{ |
| 2728 | testType: clientTest, |
| 2729 | name: ver.name + "-Client-ClientAuth-ECDSA", |
| 2730 | config: Config{ |
| 2731 | MinVersion: ver.version, |
| 2732 | MaxVersion: ver.version, |
| 2733 | ClientAuth: RequireAnyClientCert, |
| 2734 | ClientCAs: certPool, |
| 2735 | }, |
| 2736 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2737 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 2738 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2739 | }, |
| 2740 | }) |
| 2741 | } |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2742 | } |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2743 | |
| 2744 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2745 | name: "NoClientCertificate", |
| 2746 | config: Config{ |
| 2747 | MaxVersion: VersionTLS12, |
| 2748 | ClientAuth: RequireAnyClientCert, |
| 2749 | }, |
| 2750 | shouldFail: true, |
| 2751 | expectedLocalError: "client didn't provide a certificate", |
| 2752 | }) |
| 2753 | |
| 2754 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2755 | name: "NoClientCertificate-TLS13", |
| 2756 | config: Config{ |
| 2757 | MaxVersion: VersionTLS13, |
| 2758 | ClientAuth: RequireAnyClientCert, |
| 2759 | }, |
| 2760 | shouldFail: true, |
| 2761 | expectedLocalError: "client didn't provide a certificate", |
| 2762 | }) |
| 2763 | |
| 2764 | testCases = append(testCases, testCase{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2765 | testType: serverTest, |
| 2766 | name: "RequireAnyClientCertificate", |
| 2767 | config: Config{ |
| 2768 | MaxVersion: VersionTLS12, |
| 2769 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2770 | flags: []string{"-require-any-client-certificate"}, |
| 2771 | shouldFail: true, |
| 2772 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2773 | }) |
| 2774 | |
| 2775 | testCases = append(testCases, testCase{ |
| 2776 | testType: serverTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2777 | name: "RequireAnyClientCertificate-TLS13", |
| 2778 | config: Config{ |
| 2779 | MaxVersion: VersionTLS13, |
| 2780 | }, |
| 2781 | flags: []string{"-require-any-client-certificate"}, |
| 2782 | shouldFail: true, |
| 2783 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2784 | }) |
| 2785 | |
| 2786 | testCases = append(testCases, testCase{ |
| 2787 | testType: serverTest, |
David Benjamin | df28c3a | 2016-03-10 16:11:51 -0500 | [diff] [blame] | 2788 | name: "RequireAnyClientCertificate-SSL3", |
| 2789 | config: Config{ |
| 2790 | MaxVersion: VersionSSL30, |
| 2791 | }, |
| 2792 | flags: []string{"-require-any-client-certificate"}, |
| 2793 | shouldFail: true, |
| 2794 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2795 | }) |
| 2796 | |
| 2797 | testCases = append(testCases, testCase{ |
| 2798 | testType: serverTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2799 | name: "SkipClientCertificate", |
| 2800 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2801 | MaxVersion: VersionTLS12, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2802 | Bugs: ProtocolBugs{ |
| 2803 | SkipClientCertificate: true, |
| 2804 | }, |
| 2805 | }, |
| 2806 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2807 | flags: []string{"-verify-peer"}, |
| 2808 | shouldFail: true, |
David Benjamin | df28c3a | 2016-03-10 16:11:51 -0500 | [diff] [blame] | 2809 | expectedError: ":UNEXPECTED_MESSAGE:", |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2810 | }) |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2811 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2812 | testCases = append(testCases, testCase{ |
| 2813 | testType: serverTest, |
| 2814 | name: "SkipClientCertificate-TLS13", |
| 2815 | config: Config{ |
| 2816 | MaxVersion: VersionTLS13, |
| 2817 | Bugs: ProtocolBugs{ |
| 2818 | SkipClientCertificate: true, |
| 2819 | }, |
| 2820 | }, |
| 2821 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2822 | flags: []string{"-verify-peer"}, |
| 2823 | shouldFail: true, |
| 2824 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2825 | }) |
| 2826 | |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2827 | // Client auth is only legal in certificate-based ciphers. |
| 2828 | testCases = append(testCases, testCase{ |
| 2829 | testType: clientTest, |
| 2830 | name: "ClientAuth-PSK", |
| 2831 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2832 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2833 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 2834 | PreSharedKey: []byte("secret"), |
| 2835 | ClientAuth: RequireAnyClientCert, |
| 2836 | }, |
| 2837 | flags: []string{ |
| 2838 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2839 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2840 | "-psk", "secret", |
| 2841 | }, |
| 2842 | shouldFail: true, |
| 2843 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2844 | }) |
| 2845 | testCases = append(testCases, testCase{ |
| 2846 | testType: clientTest, |
| 2847 | name: "ClientAuth-ECDHE_PSK", |
| 2848 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2849 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2850 | CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 2851 | PreSharedKey: []byte("secret"), |
| 2852 | ClientAuth: RequireAnyClientCert, |
| 2853 | }, |
| 2854 | flags: []string{ |
| 2855 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2856 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2857 | "-psk", "secret", |
| 2858 | }, |
| 2859 | shouldFail: true, |
| 2860 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2861 | }) |
David Benjamin | 2f8935d | 2016-07-13 19:47:39 -0400 | [diff] [blame] | 2862 | |
| 2863 | // Regression test for a bug where the client CA list, if explicitly |
| 2864 | // set to NULL, was mis-encoded. |
| 2865 | testCases = append(testCases, testCase{ |
| 2866 | testType: serverTest, |
| 2867 | name: "Null-Client-CA-List", |
| 2868 | config: Config{ |
| 2869 | MaxVersion: VersionTLS12, |
| 2870 | Certificates: []Certificate{rsaCertificate}, |
| 2871 | }, |
| 2872 | flags: []string{ |
| 2873 | "-require-any-client-certificate", |
| 2874 | "-use-null-client-ca-list", |
| 2875 | }, |
| 2876 | }) |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2877 | } |
| 2878 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2879 | func addExtendedMasterSecretTests() { |
| 2880 | const expectEMSFlag = "-expect-extended-master-secret" |
| 2881 | |
| 2882 | for _, with := range []bool{false, true} { |
| 2883 | prefix := "No" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2884 | if with { |
| 2885 | prefix = "" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | for _, isClient := range []bool{false, true} { |
| 2889 | suffix := "-Server" |
| 2890 | testType := serverTest |
| 2891 | if isClient { |
| 2892 | suffix = "-Client" |
| 2893 | testType = clientTest |
| 2894 | } |
| 2895 | |
| 2896 | for _, ver := range tlsVersions { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2897 | // In TLS 1.3, the extension is irrelevant and |
| 2898 | // always reports as enabled. |
| 2899 | var flags []string |
| 2900 | if with || ver.version >= VersionTLS13 { |
| 2901 | flags = []string{expectEMSFlag} |
| 2902 | } |
| 2903 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2904 | test := testCase{ |
| 2905 | testType: testType, |
| 2906 | name: prefix + "ExtendedMasterSecret-" + ver.name + suffix, |
| 2907 | config: Config{ |
| 2908 | MinVersion: ver.version, |
| 2909 | MaxVersion: ver.version, |
| 2910 | Bugs: ProtocolBugs{ |
| 2911 | NoExtendedMasterSecret: !with, |
| 2912 | RequireExtendedMasterSecret: with, |
| 2913 | }, |
| 2914 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2915 | flags: flags, |
| 2916 | shouldFail: ver.version == VersionSSL30 && with, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2917 | } |
| 2918 | if test.shouldFail { |
| 2919 | test.expectedLocalError = "extended master secret required but not supported by peer" |
| 2920 | } |
| 2921 | testCases = append(testCases, test) |
| 2922 | } |
| 2923 | } |
| 2924 | } |
| 2925 | |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2926 | for _, isClient := range []bool{false, true} { |
| 2927 | for _, supportedInFirstConnection := range []bool{false, true} { |
| 2928 | for _, supportedInResumeConnection := range []bool{false, true} { |
| 2929 | boolToWord := func(b bool) string { |
| 2930 | if b { |
| 2931 | return "Yes" |
| 2932 | } |
| 2933 | return "No" |
| 2934 | } |
| 2935 | suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-" |
| 2936 | if isClient { |
| 2937 | suffix += "Client" |
| 2938 | } else { |
| 2939 | suffix += "Server" |
| 2940 | } |
| 2941 | |
| 2942 | supportedConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2943 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2944 | Bugs: ProtocolBugs{ |
| 2945 | RequireExtendedMasterSecret: true, |
| 2946 | }, |
| 2947 | } |
| 2948 | |
| 2949 | noSupportConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2950 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2951 | Bugs: ProtocolBugs{ |
| 2952 | NoExtendedMasterSecret: true, |
| 2953 | }, |
| 2954 | } |
| 2955 | |
| 2956 | test := testCase{ |
| 2957 | name: "ExtendedMasterSecret-" + suffix, |
| 2958 | resumeSession: true, |
| 2959 | } |
| 2960 | |
| 2961 | if !isClient { |
| 2962 | test.testType = serverTest |
| 2963 | } |
| 2964 | |
| 2965 | if supportedInFirstConnection { |
| 2966 | test.config = supportedConfig |
| 2967 | } else { |
| 2968 | test.config = noSupportConfig |
| 2969 | } |
| 2970 | |
| 2971 | if supportedInResumeConnection { |
| 2972 | test.resumeConfig = &supportedConfig |
| 2973 | } else { |
| 2974 | test.resumeConfig = &noSupportConfig |
| 2975 | } |
| 2976 | |
| 2977 | switch suffix { |
| 2978 | case "YesToYes-Client", "YesToYes-Server": |
| 2979 | // When a session is resumed, it should |
| 2980 | // still be aware that its master |
| 2981 | // secret was generated via EMS and |
| 2982 | // thus it's safe to use tls-unique. |
| 2983 | test.flags = []string{expectEMSFlag} |
| 2984 | case "NoToYes-Server": |
| 2985 | // If an original connection did not |
| 2986 | // contain EMS, but a resumption |
| 2987 | // handshake does, then a server should |
| 2988 | // not resume the session. |
| 2989 | test.expectResumeRejected = true |
| 2990 | case "YesToNo-Server": |
| 2991 | // Resuming an EMS session without the |
| 2992 | // EMS extension should cause the |
| 2993 | // server to abort the connection. |
| 2994 | test.shouldFail = true |
| 2995 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 2996 | case "NoToYes-Client": |
| 2997 | // A client should abort a connection |
| 2998 | // where the server resumed a non-EMS |
| 2999 | // session but echoed the EMS |
| 3000 | // extension. |
| 3001 | test.shouldFail = true |
| 3002 | test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:" |
| 3003 | case "YesToNo-Client": |
| 3004 | // A client should abort a connection |
| 3005 | // where the server didn't echo EMS |
| 3006 | // when the session used it. |
| 3007 | test.shouldFail = true |
| 3008 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 3009 | } |
| 3010 | |
| 3011 | testCases = append(testCases, test) |
| 3012 | } |
| 3013 | } |
| 3014 | } |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3017 | type stateMachineTestConfig struct { |
| 3018 | protocol protocol |
| 3019 | async bool |
| 3020 | splitHandshake, packHandshakeFlight bool |
| 3021 | } |
| 3022 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 3023 | // Adds tests that try to cover the range of the handshake state machine, under |
| 3024 | // various conditions. Some of these are redundant with other tests, but they |
| 3025 | // only cover the synchronous case. |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3026 | func addAllStateMachineCoverageTests() { |
| 3027 | for _, async := range []bool{false, true} { |
| 3028 | for _, protocol := range []protocol{tls, dtls} { |
| 3029 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3030 | protocol: protocol, |
| 3031 | async: async, |
| 3032 | }) |
| 3033 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3034 | protocol: protocol, |
| 3035 | async: async, |
| 3036 | splitHandshake: true, |
| 3037 | }) |
| 3038 | if protocol == tls { |
| 3039 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3040 | protocol: protocol, |
| 3041 | async: async, |
| 3042 | packHandshakeFlight: true, |
| 3043 | }) |
| 3044 | } |
| 3045 | } |
| 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | func addStateMachineCoverageTests(config stateMachineTestConfig) { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3050 | var tests []testCase |
| 3051 | |
| 3052 | // Basic handshake, with resumption. Client and server, |
| 3053 | // session ID and session ticket. |
| 3054 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3055 | name: "Basic-Client", |
| 3056 | config: Config{ |
| 3057 | MaxVersion: VersionTLS12, |
| 3058 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3059 | resumeSession: true, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3060 | // Ensure session tickets are used, not session IDs. |
| 3061 | noSessionCache: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3062 | }) |
| 3063 | tests = append(tests, testCase{ |
| 3064 | name: "Basic-Client-RenewTicket", |
| 3065 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3066 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3067 | Bugs: ProtocolBugs{ |
| 3068 | RenewTicketOnResume: true, |
| 3069 | }, |
| 3070 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 3071 | flags: []string{"-expect-ticket-renewal"}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3072 | resumeSession: true, |
| 3073 | }) |
| 3074 | tests = append(tests, testCase{ |
| 3075 | name: "Basic-Client-NoTicket", |
| 3076 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3077 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3078 | SessionTicketsDisabled: true, |
| 3079 | }, |
| 3080 | resumeSession: true, |
| 3081 | }) |
| 3082 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3083 | name: "Basic-Client-Implicit", |
| 3084 | config: Config{ |
| 3085 | MaxVersion: VersionTLS12, |
| 3086 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3087 | flags: []string{"-implicit-handshake"}, |
| 3088 | resumeSession: true, |
| 3089 | }) |
| 3090 | tests = append(tests, testCase{ |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3091 | testType: serverTest, |
| 3092 | name: "Basic-Server", |
| 3093 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3094 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3095 | Bugs: ProtocolBugs{ |
| 3096 | RequireSessionTickets: true, |
| 3097 | }, |
| 3098 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3099 | resumeSession: true, |
| 3100 | }) |
| 3101 | tests = append(tests, testCase{ |
| 3102 | testType: serverTest, |
| 3103 | name: "Basic-Server-NoTickets", |
| 3104 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3105 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3106 | SessionTicketsDisabled: true, |
| 3107 | }, |
| 3108 | resumeSession: true, |
| 3109 | }) |
| 3110 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3111 | testType: serverTest, |
| 3112 | name: "Basic-Server-Implicit", |
| 3113 | config: Config{ |
| 3114 | MaxVersion: VersionTLS12, |
| 3115 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3116 | flags: []string{"-implicit-handshake"}, |
| 3117 | resumeSession: true, |
| 3118 | }) |
| 3119 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3120 | testType: serverTest, |
| 3121 | name: "Basic-Server-EarlyCallback", |
| 3122 | config: Config{ |
| 3123 | MaxVersion: VersionTLS12, |
| 3124 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3125 | flags: []string{"-use-early-callback"}, |
| 3126 | resumeSession: true, |
| 3127 | }) |
| 3128 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3129 | // TLS 1.3 basic handshake shapes. |
| 3130 | tests = append(tests, testCase{ |
| 3131 | name: "TLS13-1RTT-Client", |
| 3132 | config: Config{ |
| 3133 | MaxVersion: VersionTLS13, |
| 3134 | }, |
| 3135 | }) |
| 3136 | tests = append(tests, testCase{ |
| 3137 | testType: serverTest, |
| 3138 | name: "TLS13-1RTT-Server", |
| 3139 | config: Config{ |
| 3140 | MaxVersion: VersionTLS13, |
| 3141 | }, |
| 3142 | }) |
| 3143 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3144 | // TLS client auth. |
| 3145 | tests = append(tests, testCase{ |
| 3146 | testType: clientTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3147 | name: "ClientAuth-NoCertificate-Client", |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3148 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3149 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3150 | ClientAuth: RequestClientCert, |
| 3151 | }, |
| 3152 | }) |
| 3153 | tests = append(tests, testCase{ |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3154 | testType: serverTest, |
| 3155 | name: "ClientAuth-NoCertificate-Server", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3156 | config: Config{ |
| 3157 | MaxVersion: VersionTLS12, |
| 3158 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3159 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3160 | flags: []string{"-verify-peer"}, |
| 3161 | }) |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3162 | if config.protocol == tls { |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3163 | tests = append(tests, testCase{ |
| 3164 | testType: clientTest, |
| 3165 | name: "ClientAuth-NoCertificate-Client-SSL3", |
| 3166 | config: Config{ |
| 3167 | MaxVersion: VersionSSL30, |
| 3168 | ClientAuth: RequestClientCert, |
| 3169 | }, |
| 3170 | }) |
| 3171 | tests = append(tests, testCase{ |
| 3172 | testType: serverTest, |
| 3173 | name: "ClientAuth-NoCertificate-Server-SSL3", |
| 3174 | config: Config{ |
| 3175 | MaxVersion: VersionSSL30, |
| 3176 | }, |
| 3177 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3178 | flags: []string{"-verify-peer"}, |
| 3179 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3180 | tests = append(tests, testCase{ |
| 3181 | testType: clientTest, |
| 3182 | name: "ClientAuth-NoCertificate-Client-TLS13", |
| 3183 | config: Config{ |
| 3184 | MaxVersion: VersionTLS13, |
| 3185 | ClientAuth: RequestClientCert, |
| 3186 | }, |
| 3187 | }) |
| 3188 | tests = append(tests, testCase{ |
| 3189 | testType: serverTest, |
| 3190 | name: "ClientAuth-NoCertificate-Server-TLS13", |
| 3191 | config: Config{ |
| 3192 | MaxVersion: VersionTLS13, |
| 3193 | }, |
| 3194 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3195 | flags: []string{"-verify-peer"}, |
| 3196 | }) |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3197 | } |
| 3198 | tests = append(tests, testCase{ |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3199 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3200 | name: "ClientAuth-RSA-Client", |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3201 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3202 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3203 | ClientAuth: RequireAnyClientCert, |
| 3204 | }, |
| 3205 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3206 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3207 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3208 | }, |
| 3209 | }) |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3210 | tests = append(tests, testCase{ |
| 3211 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3212 | name: "ClientAuth-RSA-Client-TLS13", |
| 3213 | config: Config{ |
| 3214 | MaxVersion: VersionTLS13, |
| 3215 | ClientAuth: RequireAnyClientCert, |
| 3216 | }, |
| 3217 | flags: []string{ |
| 3218 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3219 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3220 | }, |
| 3221 | }) |
| 3222 | tests = append(tests, testCase{ |
| 3223 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3224 | name: "ClientAuth-ECDSA-Client", |
| 3225 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3226 | MaxVersion: VersionTLS12, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3227 | ClientAuth: RequireAnyClientCert, |
| 3228 | }, |
| 3229 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3230 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3231 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3232 | }, |
| 3233 | }) |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3234 | tests = append(tests, testCase{ |
| 3235 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3236 | name: "ClientAuth-ECDSA-Client-TLS13", |
| 3237 | config: Config{ |
| 3238 | MaxVersion: VersionTLS13, |
| 3239 | ClientAuth: RequireAnyClientCert, |
| 3240 | }, |
| 3241 | flags: []string{ |
| 3242 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3243 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 3244 | }, |
| 3245 | }) |
| 3246 | tests = append(tests, testCase{ |
| 3247 | testType: clientTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3248 | name: "ClientAuth-NoCertificate-OldCallback", |
| 3249 | config: Config{ |
| 3250 | MaxVersion: VersionTLS12, |
| 3251 | ClientAuth: RequestClientCert, |
| 3252 | }, |
| 3253 | flags: []string{"-use-old-client-cert-callback"}, |
| 3254 | }) |
| 3255 | tests = append(tests, testCase{ |
| 3256 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3257 | name: "ClientAuth-NoCertificate-OldCallback-TLS13", |
| 3258 | config: Config{ |
| 3259 | MaxVersion: VersionTLS13, |
| 3260 | ClientAuth: RequestClientCert, |
| 3261 | }, |
| 3262 | flags: []string{"-use-old-client-cert-callback"}, |
| 3263 | }) |
| 3264 | tests = append(tests, testCase{ |
| 3265 | testType: clientTest, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3266 | name: "ClientAuth-OldCallback", |
| 3267 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3268 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3269 | ClientAuth: RequireAnyClientCert, |
| 3270 | }, |
| 3271 | flags: []string{ |
| 3272 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3273 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3274 | "-use-old-client-cert-callback", |
| 3275 | }, |
| 3276 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3277 | tests = append(tests, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3278 | testType: clientTest, |
| 3279 | name: "ClientAuth-OldCallback-TLS13", |
| 3280 | config: Config{ |
| 3281 | MaxVersion: VersionTLS13, |
| 3282 | ClientAuth: RequireAnyClientCert, |
| 3283 | }, |
| 3284 | flags: []string{ |
| 3285 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3286 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3287 | "-use-old-client-cert-callback", |
| 3288 | }, |
| 3289 | }) |
| 3290 | tests = append(tests, testCase{ |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3291 | testType: serverTest, |
| 3292 | name: "ClientAuth-Server", |
| 3293 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3294 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3295 | Certificates: []Certificate{rsaCertificate}, |
| 3296 | }, |
| 3297 | flags: []string{"-require-any-client-certificate"}, |
| 3298 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3299 | tests = append(tests, testCase{ |
| 3300 | testType: serverTest, |
| 3301 | name: "ClientAuth-Server-TLS13", |
| 3302 | config: Config{ |
| 3303 | MaxVersion: VersionTLS13, |
| 3304 | Certificates: []Certificate{rsaCertificate}, |
| 3305 | }, |
| 3306 | flags: []string{"-require-any-client-certificate"}, |
| 3307 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3308 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3309 | // Test each key exchange on the server side for async keys. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3310 | tests = append(tests, testCase{ |
| 3311 | testType: serverTest, |
| 3312 | name: "Basic-Server-RSA", |
| 3313 | config: Config{ |
| 3314 | MaxVersion: VersionTLS12, |
| 3315 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 3316 | }, |
| 3317 | flags: []string{ |
| 3318 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3319 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3320 | }, |
| 3321 | }) |
| 3322 | tests = append(tests, testCase{ |
| 3323 | testType: serverTest, |
| 3324 | name: "Basic-Server-ECDHE-RSA", |
| 3325 | config: Config{ |
| 3326 | MaxVersion: VersionTLS12, |
| 3327 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3328 | }, |
| 3329 | flags: []string{ |
| 3330 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3331 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3332 | }, |
| 3333 | }) |
| 3334 | tests = append(tests, testCase{ |
| 3335 | testType: serverTest, |
| 3336 | name: "Basic-Server-ECDHE-ECDSA", |
| 3337 | config: Config{ |
| 3338 | MaxVersion: VersionTLS12, |
| 3339 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 3340 | }, |
| 3341 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3342 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3343 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3344 | }, |
| 3345 | }) |
| 3346 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3347 | // No session ticket support; server doesn't send NewSessionTicket. |
| 3348 | tests = append(tests, testCase{ |
| 3349 | name: "SessionTicketsDisabled-Client", |
| 3350 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3351 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3352 | SessionTicketsDisabled: true, |
| 3353 | }, |
| 3354 | }) |
| 3355 | tests = append(tests, testCase{ |
| 3356 | testType: serverTest, |
| 3357 | name: "SessionTicketsDisabled-Server", |
| 3358 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3359 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3360 | SessionTicketsDisabled: true, |
| 3361 | }, |
| 3362 | }) |
| 3363 | |
| 3364 | // Skip ServerKeyExchange in PSK key exchange if there's no |
| 3365 | // identity hint. |
| 3366 | tests = append(tests, testCase{ |
| 3367 | name: "EmptyPSKHint-Client", |
| 3368 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3369 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3370 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3371 | PreSharedKey: []byte("secret"), |
| 3372 | }, |
| 3373 | flags: []string{"-psk", "secret"}, |
| 3374 | }) |
| 3375 | tests = append(tests, testCase{ |
| 3376 | testType: serverTest, |
| 3377 | name: "EmptyPSKHint-Server", |
| 3378 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3379 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3380 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3381 | PreSharedKey: []byte("secret"), |
| 3382 | }, |
| 3383 | flags: []string{"-psk", "secret"}, |
| 3384 | }) |
| 3385 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3386 | // OCSP stapling tests. |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3387 | tests = append(tests, testCase{ |
| 3388 | testType: clientTest, |
| 3389 | name: "OCSPStapling-Client", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3390 | config: Config{ |
| 3391 | MaxVersion: VersionTLS12, |
| 3392 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3393 | flags: []string{ |
| 3394 | "-enable-ocsp-stapling", |
| 3395 | "-expect-ocsp-response", |
| 3396 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3397 | "-verify-peer", |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3398 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3399 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3400 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3401 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3402 | testType: serverTest, |
| 3403 | name: "OCSPStapling-Server", |
| 3404 | config: Config{ |
| 3405 | MaxVersion: VersionTLS12, |
| 3406 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3407 | expectedOCSPResponse: testOCSPResponse, |
| 3408 | flags: []string{ |
| 3409 | "-ocsp-response", |
| 3410 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3411 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3412 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3413 | }) |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3414 | tests = append(tests, testCase{ |
| 3415 | testType: clientTest, |
| 3416 | name: "OCSPStapling-Client-TLS13", |
| 3417 | config: Config{ |
| 3418 | MaxVersion: VersionTLS13, |
| 3419 | }, |
| 3420 | flags: []string{ |
| 3421 | "-enable-ocsp-stapling", |
| 3422 | "-expect-ocsp-response", |
| 3423 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3424 | "-verify-peer", |
| 3425 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3426 | resumeSession: true, |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3427 | }) |
| 3428 | tests = append(tests, testCase{ |
| 3429 | testType: serverTest, |
| 3430 | name: "OCSPStapling-Server-TLS13", |
| 3431 | config: Config{ |
| 3432 | MaxVersion: VersionTLS13, |
| 3433 | }, |
| 3434 | expectedOCSPResponse: testOCSPResponse, |
| 3435 | flags: []string{ |
| 3436 | "-ocsp-response", |
| 3437 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3438 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3439 | resumeSession: true, |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3440 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3441 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3442 | // Certificate verification tests. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3443 | for _, vers := range tlsVersions { |
| 3444 | if config.protocol == dtls && !vers.hasDTLS { |
| 3445 | continue |
| 3446 | } |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3447 | for _, testType := range []testType{clientTest, serverTest} { |
| 3448 | suffix := "-Client" |
| 3449 | if testType == serverTest { |
| 3450 | suffix = "-Server" |
| 3451 | } |
| 3452 | suffix += "-" + vers.name |
| 3453 | |
| 3454 | flag := "-verify-peer" |
| 3455 | if testType == serverTest { |
| 3456 | flag = "-require-any-client-certificate" |
| 3457 | } |
| 3458 | |
| 3459 | tests = append(tests, testCase{ |
| 3460 | testType: testType, |
| 3461 | name: "CertificateVerificationSucceed" + suffix, |
| 3462 | config: Config{ |
| 3463 | MaxVersion: vers.version, |
| 3464 | Certificates: []Certificate{rsaCertificate}, |
| 3465 | }, |
| 3466 | flags: []string{ |
| 3467 | flag, |
| 3468 | "-expect-verify-result", |
| 3469 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3470 | resumeSession: true, |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3471 | }) |
| 3472 | tests = append(tests, testCase{ |
| 3473 | testType: testType, |
| 3474 | name: "CertificateVerificationFail" + suffix, |
| 3475 | config: Config{ |
| 3476 | MaxVersion: vers.version, |
| 3477 | Certificates: []Certificate{rsaCertificate}, |
| 3478 | }, |
| 3479 | flags: []string{ |
| 3480 | flag, |
| 3481 | "-verify-fail", |
| 3482 | }, |
| 3483 | shouldFail: true, |
| 3484 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 3485 | }) |
| 3486 | } |
| 3487 | |
| 3488 | // By default, the client is in a soft fail mode where the peer |
| 3489 | // certificate is verified but failures are non-fatal. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3490 | tests = append(tests, testCase{ |
| 3491 | testType: clientTest, |
| 3492 | name: "CertificateVerificationSoftFail-" + vers.name, |
| 3493 | config: Config{ |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3494 | MaxVersion: vers.version, |
| 3495 | Certificates: []Certificate{rsaCertificate}, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3496 | }, |
| 3497 | flags: []string{ |
| 3498 | "-verify-fail", |
| 3499 | "-expect-verify-result", |
| 3500 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3501 | resumeSession: true, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3502 | }) |
| 3503 | } |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3504 | |
David Benjamin | 1d4f4c0 | 2016-07-26 18:03:08 -0400 | [diff] [blame] | 3505 | tests = append(tests, testCase{ |
| 3506 | name: "ShimSendAlert", |
| 3507 | flags: []string{"-send-alert"}, |
| 3508 | shimWritesFirst: true, |
| 3509 | shouldFail: true, |
| 3510 | expectedLocalError: "remote error: decompression failure", |
| 3511 | }) |
| 3512 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3513 | if config.protocol == tls { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3514 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3515 | name: "Renegotiate-Client", |
| 3516 | config: Config{ |
| 3517 | MaxVersion: VersionTLS12, |
| 3518 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 3519 | renegotiate: 1, |
| 3520 | flags: []string{ |
| 3521 | "-renegotiate-freely", |
| 3522 | "-expect-total-renegotiations", "1", |
| 3523 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3524 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3525 | |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 3526 | tests = append(tests, testCase{ |
| 3527 | name: "SendHalfHelloRequest", |
| 3528 | config: Config{ |
| 3529 | MaxVersion: VersionTLS12, |
| 3530 | Bugs: ProtocolBugs{ |
| 3531 | PackHelloRequestWithFinished: config.packHandshakeFlight, |
| 3532 | }, |
| 3533 | }, |
| 3534 | sendHalfHelloRequest: true, |
| 3535 | flags: []string{"-renegotiate-ignore"}, |
| 3536 | shouldFail: true, |
| 3537 | expectedError: ":UNEXPECTED_RECORD:", |
| 3538 | }) |
| 3539 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3540 | // NPN on client and server; results in post-handshake message. |
| 3541 | tests = append(tests, testCase{ |
| 3542 | name: "NPN-Client", |
| 3543 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3544 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3545 | NextProtos: []string{"foo"}, |
| 3546 | }, |
| 3547 | flags: []string{"-select-next-proto", "foo"}, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3548 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3549 | expectedNextProto: "foo", |
| 3550 | expectedNextProtoType: npn, |
| 3551 | }) |
| 3552 | tests = append(tests, testCase{ |
| 3553 | testType: serverTest, |
| 3554 | name: "NPN-Server", |
| 3555 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3556 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3557 | NextProtos: []string{"bar"}, |
| 3558 | }, |
| 3559 | flags: []string{ |
| 3560 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3561 | "-expect-next-proto", "bar", |
| 3562 | }, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3563 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3564 | expectedNextProto: "bar", |
| 3565 | expectedNextProtoType: npn, |
| 3566 | }) |
| 3567 | |
| 3568 | // TODO(davidben): Add tests for when False Start doesn't trigger. |
| 3569 | |
| 3570 | // Client does False Start and negotiates NPN. |
| 3571 | tests = append(tests, testCase{ |
| 3572 | name: "FalseStart", |
| 3573 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3574 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3575 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3576 | NextProtos: []string{"foo"}, |
| 3577 | Bugs: ProtocolBugs{ |
| 3578 | ExpectFalseStart: true, |
| 3579 | }, |
| 3580 | }, |
| 3581 | flags: []string{ |
| 3582 | "-false-start", |
| 3583 | "-select-next-proto", "foo", |
| 3584 | }, |
| 3585 | shimWritesFirst: true, |
| 3586 | resumeSession: true, |
| 3587 | }) |
| 3588 | |
| 3589 | // Client does False Start and negotiates ALPN. |
| 3590 | tests = append(tests, testCase{ |
| 3591 | name: "FalseStart-ALPN", |
| 3592 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3593 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3594 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3595 | NextProtos: []string{"foo"}, |
| 3596 | Bugs: ProtocolBugs{ |
| 3597 | ExpectFalseStart: true, |
| 3598 | }, |
| 3599 | }, |
| 3600 | flags: []string{ |
| 3601 | "-false-start", |
| 3602 | "-advertise-alpn", "\x03foo", |
| 3603 | }, |
| 3604 | shimWritesFirst: true, |
| 3605 | resumeSession: true, |
| 3606 | }) |
| 3607 | |
| 3608 | // Client does False Start but doesn't explicitly call |
| 3609 | // SSL_connect. |
| 3610 | tests = append(tests, testCase{ |
| 3611 | name: "FalseStart-Implicit", |
| 3612 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3613 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3614 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3615 | NextProtos: []string{"foo"}, |
| 3616 | }, |
| 3617 | flags: []string{ |
| 3618 | "-implicit-handshake", |
| 3619 | "-false-start", |
| 3620 | "-advertise-alpn", "\x03foo", |
| 3621 | }, |
| 3622 | }) |
| 3623 | |
| 3624 | // False Start without session tickets. |
| 3625 | tests = append(tests, testCase{ |
| 3626 | name: "FalseStart-SessionTicketsDisabled", |
| 3627 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3628 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3629 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3630 | NextProtos: []string{"foo"}, |
| 3631 | SessionTicketsDisabled: true, |
| 3632 | Bugs: ProtocolBugs{ |
| 3633 | ExpectFalseStart: true, |
| 3634 | }, |
| 3635 | }, |
| 3636 | flags: []string{ |
| 3637 | "-false-start", |
| 3638 | "-select-next-proto", "foo", |
| 3639 | }, |
| 3640 | shimWritesFirst: true, |
| 3641 | }) |
| 3642 | |
Adam Langley | df759b5 | 2016-07-11 15:24:37 -0700 | [diff] [blame] | 3643 | tests = append(tests, testCase{ |
| 3644 | name: "FalseStart-CECPQ1", |
| 3645 | config: Config{ |
| 3646 | MaxVersion: VersionTLS12, |
| 3647 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 3648 | NextProtos: []string{"foo"}, |
| 3649 | Bugs: ProtocolBugs{ |
| 3650 | ExpectFalseStart: true, |
| 3651 | }, |
| 3652 | }, |
| 3653 | flags: []string{ |
| 3654 | "-false-start", |
| 3655 | "-cipher", "DEFAULT:kCECPQ1", |
| 3656 | "-select-next-proto", "foo", |
| 3657 | }, |
| 3658 | shimWritesFirst: true, |
| 3659 | resumeSession: true, |
| 3660 | }) |
| 3661 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3662 | // Server parses a V2ClientHello. |
| 3663 | tests = append(tests, testCase{ |
| 3664 | testType: serverTest, |
| 3665 | name: "SendV2ClientHello", |
| 3666 | config: Config{ |
| 3667 | // Choose a cipher suite that does not involve |
| 3668 | // elliptic curves, so no extensions are |
| 3669 | // involved. |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3670 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3671 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 3672 | Bugs: ProtocolBugs{ |
| 3673 | SendV2ClientHello: true, |
| 3674 | }, |
| 3675 | }, |
| 3676 | }) |
| 3677 | |
| 3678 | // Client sends a Channel ID. |
| 3679 | tests = append(tests, testCase{ |
| 3680 | name: "ChannelID-Client", |
| 3681 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3682 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3683 | RequestChannelID: true, |
| 3684 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3685 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3686 | resumeSession: true, |
| 3687 | expectChannelID: true, |
| 3688 | }) |
| 3689 | |
| 3690 | // Server accepts a Channel ID. |
| 3691 | tests = append(tests, testCase{ |
| 3692 | testType: serverTest, |
| 3693 | name: "ChannelID-Server", |
| 3694 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3695 | MaxVersion: VersionTLS12, |
| 3696 | ChannelID: channelIDKey, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3697 | }, |
| 3698 | flags: []string{ |
| 3699 | "-expect-channel-id", |
| 3700 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3701 | }, |
| 3702 | resumeSession: true, |
| 3703 | expectChannelID: true, |
| 3704 | }) |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3705 | |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3706 | // Channel ID and NPN at the same time, to ensure their relative |
| 3707 | // ordering is correct. |
| 3708 | tests = append(tests, testCase{ |
| 3709 | name: "ChannelID-NPN-Client", |
| 3710 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3711 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3712 | RequestChannelID: true, |
| 3713 | NextProtos: []string{"foo"}, |
| 3714 | }, |
| 3715 | flags: []string{ |
| 3716 | "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile), |
| 3717 | "-select-next-proto", "foo", |
| 3718 | }, |
| 3719 | resumeSession: true, |
| 3720 | expectChannelID: true, |
| 3721 | expectedNextProto: "foo", |
| 3722 | expectedNextProtoType: npn, |
| 3723 | }) |
| 3724 | tests = append(tests, testCase{ |
| 3725 | testType: serverTest, |
| 3726 | name: "ChannelID-NPN-Server", |
| 3727 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3728 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3729 | ChannelID: channelIDKey, |
| 3730 | NextProtos: []string{"bar"}, |
| 3731 | }, |
| 3732 | flags: []string{ |
| 3733 | "-expect-channel-id", |
| 3734 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3735 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3736 | "-expect-next-proto", "bar", |
| 3737 | }, |
| 3738 | resumeSession: true, |
| 3739 | expectChannelID: true, |
| 3740 | expectedNextProto: "bar", |
| 3741 | expectedNextProtoType: npn, |
| 3742 | }) |
| 3743 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3744 | // Bidirectional shutdown with the runner initiating. |
| 3745 | tests = append(tests, testCase{ |
| 3746 | name: "Shutdown-Runner", |
| 3747 | config: Config{ |
| 3748 | Bugs: ProtocolBugs{ |
| 3749 | ExpectCloseNotify: true, |
| 3750 | }, |
| 3751 | }, |
| 3752 | flags: []string{"-check-close-notify"}, |
| 3753 | }) |
| 3754 | |
| 3755 | // Bidirectional shutdown with the shim initiating. The runner, |
| 3756 | // in the meantime, sends garbage before the close_notify which |
| 3757 | // the shim must ignore. |
| 3758 | tests = append(tests, testCase{ |
| 3759 | name: "Shutdown-Shim", |
| 3760 | config: Config{ |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 3761 | MaxVersion: VersionTLS12, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3762 | Bugs: ProtocolBugs{ |
| 3763 | ExpectCloseNotify: true, |
| 3764 | }, |
| 3765 | }, |
| 3766 | shimShutsDown: true, |
| 3767 | sendEmptyRecords: 1, |
| 3768 | sendWarningAlerts: 1, |
| 3769 | flags: []string{"-check-close-notify"}, |
| 3770 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3771 | } else { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3772 | // TODO(davidben): DTLS 1.3 will want a similar thing for |
| 3773 | // HelloRetryRequest. |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3774 | tests = append(tests, testCase{ |
| 3775 | name: "SkipHelloVerifyRequest", |
| 3776 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3777 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3778 | Bugs: ProtocolBugs{ |
| 3779 | SkipHelloVerifyRequest: true, |
| 3780 | }, |
| 3781 | }, |
| 3782 | }) |
| 3783 | } |
| 3784 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3785 | for _, test := range tests { |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3786 | test.protocol = config.protocol |
| 3787 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3788 | test.name += "-DTLS" |
| 3789 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3790 | if config.async { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3791 | test.name += "-Async" |
| 3792 | test.flags = append(test.flags, "-async") |
| 3793 | } else { |
| 3794 | test.name += "-Sync" |
| 3795 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3796 | if config.splitHandshake { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3797 | test.name += "-SplitHandshakeRecords" |
| 3798 | test.config.Bugs.MaxHandshakeRecordLength = 1 |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3799 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3800 | test.config.Bugs.MaxPacketLength = 256 |
| 3801 | test.flags = append(test.flags, "-mtu", "256") |
| 3802 | } |
| 3803 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3804 | if config.packHandshakeFlight { |
| 3805 | test.name += "-PackHandshakeFlight" |
| 3806 | test.config.Bugs.PackHandshakeFlight = true |
| 3807 | } |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3808 | testCases = append(testCases, test) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 3809 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 3810 | } |
| 3811 | |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3812 | func addDDoSCallbackTests() { |
| 3813 | // DDoS callback. |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3814 | for _, resume := range []bool{false, true} { |
| 3815 | suffix := "Resume" |
| 3816 | if resume { |
| 3817 | suffix = "No" + suffix |
| 3818 | } |
| 3819 | |
| 3820 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3821 | testType: serverTest, |
| 3822 | name: "Server-DDoS-OK-" + suffix, |
| 3823 | config: Config{ |
| 3824 | MaxVersion: VersionTLS12, |
| 3825 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3826 | flags: []string{"-install-ddos-callback"}, |
| 3827 | resumeSession: resume, |
| 3828 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3829 | testCases = append(testCases, testCase{ |
| 3830 | testType: serverTest, |
| 3831 | name: "Server-DDoS-OK-" + suffix + "-TLS13", |
| 3832 | config: Config{ |
| 3833 | MaxVersion: VersionTLS13, |
| 3834 | }, |
| 3835 | flags: []string{"-install-ddos-callback"}, |
| 3836 | resumeSession: resume, |
| 3837 | }) |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3838 | |
| 3839 | failFlag := "-fail-ddos-callback" |
| 3840 | if resume { |
| 3841 | failFlag = "-fail-second-ddos-callback" |
| 3842 | } |
| 3843 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3844 | testType: serverTest, |
| 3845 | name: "Server-DDoS-Reject-" + suffix, |
| 3846 | config: Config{ |
| 3847 | MaxVersion: VersionTLS12, |
| 3848 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3849 | flags: []string{"-install-ddos-callback", failFlag}, |
| 3850 | resumeSession: resume, |
| 3851 | shouldFail: true, |
| 3852 | expectedError: ":CONNECTION_REJECTED:", |
| 3853 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3854 | testCases = append(testCases, testCase{ |
| 3855 | testType: serverTest, |
| 3856 | name: "Server-DDoS-Reject-" + suffix + "-TLS13", |
| 3857 | config: Config{ |
| 3858 | MaxVersion: VersionTLS13, |
| 3859 | }, |
| 3860 | flags: []string{"-install-ddos-callback", failFlag}, |
| 3861 | resumeSession: resume, |
| 3862 | shouldFail: true, |
| 3863 | expectedError: ":CONNECTION_REJECTED:", |
| 3864 | }) |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3865 | } |
| 3866 | } |
| 3867 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3868 | func addVersionNegotiationTests() { |
| 3869 | for i, shimVers := range tlsVersions { |
| 3870 | // Assemble flags to disable all newer versions on the shim. |
| 3871 | var flags []string |
| 3872 | for _, vers := range tlsVersions[i+1:] { |
| 3873 | flags = append(flags, vers.flag) |
| 3874 | } |
| 3875 | |
| 3876 | for _, runnerVers := range tlsVersions { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3877 | protocols := []protocol{tls} |
| 3878 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 3879 | protocols = append(protocols, dtls) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3880 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3881 | for _, protocol := range protocols { |
| 3882 | expectedVersion := shimVers.version |
| 3883 | if runnerVers.version < shimVers.version { |
| 3884 | expectedVersion = runnerVers.version |
| 3885 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3886 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3887 | suffix := shimVers.name + "-" + runnerVers.name |
| 3888 | if protocol == dtls { |
| 3889 | suffix += "-DTLS" |
| 3890 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3891 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3892 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 3893 | |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3894 | clientVers := shimVers.version |
| 3895 | if clientVers > VersionTLS10 { |
| 3896 | clientVers = VersionTLS10 |
| 3897 | } |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3898 | serverVers := expectedVersion |
| 3899 | if expectedVersion >= VersionTLS13 { |
| 3900 | serverVers = VersionTLS10 |
| 3901 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3902 | testCases = append(testCases, testCase{ |
| 3903 | protocol: protocol, |
| 3904 | testType: clientTest, |
| 3905 | name: "VersionNegotiation-Client-" + suffix, |
| 3906 | config: Config{ |
| 3907 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3908 | Bugs: ProtocolBugs{ |
| 3909 | ExpectInitialRecordVersion: clientVers, |
| 3910 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3911 | }, |
| 3912 | flags: flags, |
| 3913 | expectedVersion: expectedVersion, |
| 3914 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3915 | testCases = append(testCases, testCase{ |
| 3916 | protocol: protocol, |
| 3917 | testType: clientTest, |
| 3918 | name: "VersionNegotiation-Client2-" + suffix, |
| 3919 | config: Config{ |
| 3920 | MaxVersion: runnerVers.version, |
| 3921 | Bugs: ProtocolBugs{ |
| 3922 | ExpectInitialRecordVersion: clientVers, |
| 3923 | }, |
| 3924 | }, |
| 3925 | flags: []string{"-max-version", shimVersFlag}, |
| 3926 | expectedVersion: expectedVersion, |
| 3927 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3928 | |
| 3929 | testCases = append(testCases, testCase{ |
| 3930 | protocol: protocol, |
| 3931 | testType: serverTest, |
| 3932 | name: "VersionNegotiation-Server-" + suffix, |
| 3933 | config: Config{ |
| 3934 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3935 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3936 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3937 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3938 | }, |
| 3939 | flags: flags, |
| 3940 | expectedVersion: expectedVersion, |
| 3941 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3942 | testCases = append(testCases, testCase{ |
| 3943 | protocol: protocol, |
| 3944 | testType: serverTest, |
| 3945 | name: "VersionNegotiation-Server2-" + suffix, |
| 3946 | config: Config{ |
| 3947 | MaxVersion: runnerVers.version, |
| 3948 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3949 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3950 | }, |
| 3951 | }, |
| 3952 | flags: []string{"-max-version", shimVersFlag}, |
| 3953 | expectedVersion: expectedVersion, |
| 3954 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3955 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3956 | } |
| 3957 | } |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 3958 | |
| 3959 | // Test for version tolerance. |
| 3960 | testCases = append(testCases, testCase{ |
| 3961 | testType: serverTest, |
| 3962 | name: "MinorVersionTolerance", |
| 3963 | config: Config{ |
| 3964 | Bugs: ProtocolBugs{ |
| 3965 | SendClientVersion: 0x03ff, |
| 3966 | }, |
| 3967 | }, |
| 3968 | expectedVersion: VersionTLS13, |
| 3969 | }) |
| 3970 | testCases = append(testCases, testCase{ |
| 3971 | testType: serverTest, |
| 3972 | name: "MajorVersionTolerance", |
| 3973 | config: Config{ |
| 3974 | Bugs: ProtocolBugs{ |
| 3975 | SendClientVersion: 0x0400, |
| 3976 | }, |
| 3977 | }, |
| 3978 | expectedVersion: VersionTLS13, |
| 3979 | }) |
| 3980 | testCases = append(testCases, testCase{ |
| 3981 | protocol: dtls, |
| 3982 | testType: serverTest, |
| 3983 | name: "MinorVersionTolerance-DTLS", |
| 3984 | config: Config{ |
| 3985 | Bugs: ProtocolBugs{ |
| 3986 | SendClientVersion: 0x03ff, |
| 3987 | }, |
| 3988 | }, |
| 3989 | expectedVersion: VersionTLS12, |
| 3990 | }) |
| 3991 | testCases = append(testCases, testCase{ |
| 3992 | protocol: dtls, |
| 3993 | testType: serverTest, |
| 3994 | name: "MajorVersionTolerance-DTLS", |
| 3995 | config: Config{ |
| 3996 | Bugs: ProtocolBugs{ |
| 3997 | SendClientVersion: 0x0400, |
| 3998 | }, |
| 3999 | }, |
| 4000 | expectedVersion: VersionTLS12, |
| 4001 | }) |
| 4002 | |
| 4003 | // Test that versions below 3.0 are rejected. |
| 4004 | testCases = append(testCases, testCase{ |
| 4005 | testType: serverTest, |
| 4006 | name: "VersionTooLow", |
| 4007 | config: Config{ |
| 4008 | Bugs: ProtocolBugs{ |
| 4009 | SendClientVersion: 0x0200, |
| 4010 | }, |
| 4011 | }, |
| 4012 | shouldFail: true, |
| 4013 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4014 | }) |
| 4015 | testCases = append(testCases, testCase{ |
| 4016 | protocol: dtls, |
| 4017 | testType: serverTest, |
| 4018 | name: "VersionTooLow-DTLS", |
| 4019 | config: Config{ |
| 4020 | Bugs: ProtocolBugs{ |
| 4021 | // 0x0201 is the lowest version expressable in |
| 4022 | // DTLS. |
| 4023 | SendClientVersion: 0x0201, |
| 4024 | }, |
| 4025 | }, |
| 4026 | shouldFail: true, |
| 4027 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4028 | }) |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4029 | |
| 4030 | // Test TLS 1.3's downgrade signal. |
| 4031 | testCases = append(testCases, testCase{ |
| 4032 | name: "Downgrade-TLS12-Client", |
| 4033 | config: Config{ |
| 4034 | Bugs: ProtocolBugs{ |
| 4035 | NegotiateVersion: VersionTLS12, |
| 4036 | }, |
| 4037 | }, |
| 4038 | shouldFail: true, |
| 4039 | expectedError: ":DOWNGRADE_DETECTED:", |
| 4040 | }) |
| 4041 | testCases = append(testCases, testCase{ |
| 4042 | testType: serverTest, |
| 4043 | name: "Downgrade-TLS12-Server", |
| 4044 | config: Config{ |
| 4045 | Bugs: ProtocolBugs{ |
| 4046 | SendClientVersion: VersionTLS12, |
| 4047 | }, |
| 4048 | }, |
| 4049 | shouldFail: true, |
| 4050 | expectedLocalError: "tls: downgrade from TLS 1.3 detected", |
| 4051 | }) |
David Benjamin | 5e7e7cc | 2016-07-21 12:55:28 +0200 | [diff] [blame] | 4052 | |
| 4053 | // Test that FALLBACK_SCSV is sent and that the downgrade signal works |
| 4054 | // behave correctly when both real maximum and fallback versions are |
| 4055 | // set. |
| 4056 | testCases = append(testCases, testCase{ |
| 4057 | name: "Downgrade-TLS12-Client-Fallback", |
| 4058 | config: Config{ |
| 4059 | Bugs: ProtocolBugs{ |
| 4060 | FailIfNotFallbackSCSV: true, |
| 4061 | }, |
| 4062 | }, |
| 4063 | flags: []string{ |
| 4064 | "-max-version", strconv.Itoa(VersionTLS13), |
| 4065 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 4066 | }, |
| 4067 | shouldFail: true, |
| 4068 | expectedError: ":DOWNGRADE_DETECTED:", |
| 4069 | }) |
| 4070 | testCases = append(testCases, testCase{ |
| 4071 | name: "Downgrade-TLS12-Client-FallbackEqualsMax", |
| 4072 | flags: []string{ |
| 4073 | "-max-version", strconv.Itoa(VersionTLS12), |
| 4074 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 4075 | }, |
| 4076 | }) |
| 4077 | |
| 4078 | // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather |
| 4079 | // just have such connections fail than risk getting confused because we |
| 4080 | // didn't sent the 1.3 ClientHello.) |
| 4081 | testCases = append(testCases, testCase{ |
| 4082 | name: "Downgrade-TLS12-Fallback-CheckVersion", |
| 4083 | config: Config{ |
| 4084 | Bugs: ProtocolBugs{ |
| 4085 | NegotiateVersion: VersionTLS13, |
| 4086 | FailIfNotFallbackSCSV: true, |
| 4087 | }, |
| 4088 | }, |
| 4089 | flags: []string{ |
| 4090 | "-max-version", strconv.Itoa(VersionTLS13), |
| 4091 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 4092 | }, |
| 4093 | shouldFail: true, |
| 4094 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4095 | }) |
| 4096 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4097 | } |
| 4098 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4099 | func addMinimumVersionTests() { |
| 4100 | for i, shimVers := range tlsVersions { |
| 4101 | // Assemble flags to disable all older versions on the shim. |
| 4102 | var flags []string |
| 4103 | for _, vers := range tlsVersions[:i] { |
| 4104 | flags = append(flags, vers.flag) |
| 4105 | } |
| 4106 | |
| 4107 | for _, runnerVers := range tlsVersions { |
| 4108 | protocols := []protocol{tls} |
| 4109 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 4110 | protocols = append(protocols, dtls) |
| 4111 | } |
| 4112 | for _, protocol := range protocols { |
| 4113 | suffix := shimVers.name + "-" + runnerVers.name |
| 4114 | if protocol == dtls { |
| 4115 | suffix += "-DTLS" |
| 4116 | } |
| 4117 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 4118 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4119 | var expectedVersion uint16 |
| 4120 | var shouldFail bool |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4121 | var expectedClientError, expectedServerError string |
| 4122 | var expectedClientLocalError, expectedServerLocalError string |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4123 | if runnerVers.version >= shimVers.version { |
| 4124 | expectedVersion = runnerVers.version |
| 4125 | } else { |
| 4126 | shouldFail = true |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4127 | expectedServerError = ":UNSUPPORTED_PROTOCOL:" |
| 4128 | expectedServerLocalError = "remote error: protocol version not supported" |
| 4129 | if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 { |
| 4130 | // If the client's minimum version is TLS 1.3 and the runner's |
| 4131 | // maximum is below TLS 1.2, the runner will fail to select a |
| 4132 | // cipher before the shim rejects the selected version. |
| 4133 | expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:" |
| 4134 | expectedClientLocalError = "tls: no cipher suite supported by both client and server" |
| 4135 | } else { |
| 4136 | expectedClientError = expectedServerError |
| 4137 | expectedClientLocalError = expectedServerLocalError |
| 4138 | } |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | testCases = append(testCases, testCase{ |
| 4142 | protocol: protocol, |
| 4143 | testType: clientTest, |
| 4144 | name: "MinimumVersion-Client-" + suffix, |
| 4145 | config: Config{ |
| 4146 | MaxVersion: runnerVers.version, |
| 4147 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4148 | flags: flags, |
| 4149 | expectedVersion: expectedVersion, |
| 4150 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4151 | expectedError: expectedClientError, |
| 4152 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4153 | }) |
| 4154 | testCases = append(testCases, testCase{ |
| 4155 | protocol: protocol, |
| 4156 | testType: clientTest, |
| 4157 | name: "MinimumVersion-Client2-" + suffix, |
| 4158 | config: Config{ |
| 4159 | MaxVersion: runnerVers.version, |
| 4160 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4161 | flags: []string{"-min-version", shimVersFlag}, |
| 4162 | expectedVersion: expectedVersion, |
| 4163 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4164 | expectedError: expectedClientError, |
| 4165 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4166 | }) |
| 4167 | |
| 4168 | testCases = append(testCases, testCase{ |
| 4169 | protocol: protocol, |
| 4170 | testType: serverTest, |
| 4171 | name: "MinimumVersion-Server-" + suffix, |
| 4172 | config: Config{ |
| 4173 | MaxVersion: runnerVers.version, |
| 4174 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4175 | flags: flags, |
| 4176 | expectedVersion: expectedVersion, |
| 4177 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4178 | expectedError: expectedServerError, |
| 4179 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4180 | }) |
| 4181 | testCases = append(testCases, testCase{ |
| 4182 | protocol: protocol, |
| 4183 | testType: serverTest, |
| 4184 | name: "MinimumVersion-Server2-" + suffix, |
| 4185 | config: Config{ |
| 4186 | MaxVersion: runnerVers.version, |
| 4187 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4188 | flags: []string{"-min-version", shimVersFlag}, |
| 4189 | expectedVersion: expectedVersion, |
| 4190 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4191 | expectedError: expectedServerError, |
| 4192 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4193 | }) |
| 4194 | } |
| 4195 | } |
| 4196 | } |
| 4197 | } |
| 4198 | |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4199 | func addExtensionTests() { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4200 | // TODO(davidben): Extensions, where applicable, all move their server |
| 4201 | // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these |
| 4202 | // tests for both. Also test interaction with 0-RTT when implemented. |
| 4203 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4204 | // Repeat extensions tests all versions except SSL 3.0. |
| 4205 | for _, ver := range tlsVersions { |
| 4206 | if ver.version == VersionSSL30 { |
| 4207 | continue |
| 4208 | } |
| 4209 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4210 | // Test that duplicate extensions are rejected. |
| 4211 | testCases = append(testCases, testCase{ |
| 4212 | testType: clientTest, |
| 4213 | name: "DuplicateExtensionClient-" + ver.name, |
| 4214 | config: Config{ |
| 4215 | MaxVersion: ver.version, |
| 4216 | Bugs: ProtocolBugs{ |
| 4217 | DuplicateExtension: true, |
| 4218 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4219 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4220 | shouldFail: true, |
| 4221 | expectedLocalError: "remote error: error decoding message", |
| 4222 | }) |
| 4223 | testCases = append(testCases, testCase{ |
| 4224 | testType: serverTest, |
| 4225 | name: "DuplicateExtensionServer-" + ver.name, |
| 4226 | config: Config{ |
| 4227 | MaxVersion: ver.version, |
| 4228 | Bugs: ProtocolBugs{ |
| 4229 | DuplicateExtension: true, |
| 4230 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4231 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4232 | shouldFail: true, |
| 4233 | expectedLocalError: "remote error: error decoding message", |
| 4234 | }) |
| 4235 | |
| 4236 | // Test SNI. |
| 4237 | testCases = append(testCases, testCase{ |
| 4238 | testType: clientTest, |
| 4239 | name: "ServerNameExtensionClient-" + ver.name, |
| 4240 | config: Config{ |
| 4241 | MaxVersion: ver.version, |
| 4242 | Bugs: ProtocolBugs{ |
| 4243 | ExpectServerName: "example.com", |
| 4244 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4245 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4246 | flags: []string{"-host-name", "example.com"}, |
| 4247 | }) |
| 4248 | testCases = append(testCases, testCase{ |
| 4249 | testType: clientTest, |
| 4250 | name: "ServerNameExtensionClientMismatch-" + ver.name, |
| 4251 | config: Config{ |
| 4252 | MaxVersion: ver.version, |
| 4253 | Bugs: ProtocolBugs{ |
| 4254 | ExpectServerName: "mismatch.com", |
| 4255 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4256 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4257 | flags: []string{"-host-name", "example.com"}, |
| 4258 | shouldFail: true, |
| 4259 | expectedLocalError: "tls: unexpected server name", |
| 4260 | }) |
| 4261 | testCases = append(testCases, testCase{ |
| 4262 | testType: clientTest, |
| 4263 | name: "ServerNameExtensionClientMissing-" + ver.name, |
| 4264 | config: Config{ |
| 4265 | MaxVersion: ver.version, |
| 4266 | Bugs: ProtocolBugs{ |
| 4267 | ExpectServerName: "missing.com", |
| 4268 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4269 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4270 | shouldFail: true, |
| 4271 | expectedLocalError: "tls: unexpected server name", |
| 4272 | }) |
| 4273 | testCases = append(testCases, testCase{ |
| 4274 | testType: serverTest, |
| 4275 | name: "ServerNameExtensionServer-" + ver.name, |
| 4276 | config: Config{ |
| 4277 | MaxVersion: ver.version, |
| 4278 | ServerName: "example.com", |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 4279 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4280 | flags: []string{"-expect-server-name", "example.com"}, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4281 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4282 | }) |
| 4283 | |
| 4284 | // Test ALPN. |
| 4285 | testCases = append(testCases, testCase{ |
| 4286 | testType: clientTest, |
| 4287 | name: "ALPNClient-" + ver.name, |
| 4288 | config: Config{ |
| 4289 | MaxVersion: ver.version, |
| 4290 | NextProtos: []string{"foo"}, |
| 4291 | }, |
| 4292 | flags: []string{ |
| 4293 | "-advertise-alpn", "\x03foo\x03bar\x03baz", |
| 4294 | "-expect-alpn", "foo", |
| 4295 | }, |
| 4296 | expectedNextProto: "foo", |
| 4297 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4298 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4299 | }) |
| 4300 | testCases = append(testCases, testCase{ |
David Benjamin | 3e51757 | 2016-08-11 11:52:23 -0400 | [diff] [blame] | 4301 | testType: clientTest, |
| 4302 | name: "ALPNClient-Mismatch-" + ver.name, |
| 4303 | config: Config{ |
| 4304 | MaxVersion: ver.version, |
| 4305 | Bugs: ProtocolBugs{ |
| 4306 | SendALPN: "baz", |
| 4307 | }, |
| 4308 | }, |
| 4309 | flags: []string{ |
| 4310 | "-advertise-alpn", "\x03foo\x03bar", |
| 4311 | }, |
| 4312 | shouldFail: true, |
| 4313 | expectedError: ":INVALID_ALPN_PROTOCOL:", |
| 4314 | expectedLocalError: "remote error: illegal parameter", |
| 4315 | }) |
| 4316 | testCases = append(testCases, testCase{ |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4317 | testType: serverTest, |
| 4318 | name: "ALPNServer-" + ver.name, |
| 4319 | config: Config{ |
| 4320 | MaxVersion: ver.version, |
| 4321 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4322 | }, |
| 4323 | flags: []string{ |
| 4324 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4325 | "-select-alpn", "foo", |
| 4326 | }, |
| 4327 | expectedNextProto: "foo", |
| 4328 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4329 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4330 | }) |
| 4331 | testCases = append(testCases, testCase{ |
| 4332 | testType: serverTest, |
| 4333 | name: "ALPNServer-Decline-" + ver.name, |
| 4334 | config: Config{ |
| 4335 | MaxVersion: ver.version, |
| 4336 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4337 | }, |
| 4338 | flags: []string{"-decline-alpn"}, |
| 4339 | expectNoNextProto: true, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4340 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4341 | }) |
| 4342 | |
David Benjamin | 25fe85b | 2016-08-09 20:00:32 -0400 | [diff] [blame] | 4343 | // Test ALPN in async mode as well to ensure that extensions callbacks are only |
| 4344 | // called once. |
| 4345 | testCases = append(testCases, testCase{ |
| 4346 | testType: serverTest, |
| 4347 | name: "ALPNServer-Async-" + ver.name, |
| 4348 | config: Config{ |
| 4349 | MaxVersion: ver.version, |
| 4350 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4351 | }, |
| 4352 | flags: []string{ |
| 4353 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4354 | "-select-alpn", "foo", |
| 4355 | "-async", |
| 4356 | }, |
| 4357 | expectedNextProto: "foo", |
| 4358 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4359 | resumeSession: true, |
David Benjamin | 25fe85b | 2016-08-09 20:00:32 -0400 | [diff] [blame] | 4360 | }) |
| 4361 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4362 | var emptyString string |
| 4363 | testCases = append(testCases, testCase{ |
| 4364 | testType: clientTest, |
| 4365 | name: "ALPNClient-EmptyProtocolName-" + ver.name, |
| 4366 | config: Config{ |
| 4367 | MaxVersion: ver.version, |
| 4368 | NextProtos: []string{""}, |
| 4369 | Bugs: ProtocolBugs{ |
| 4370 | // A server returning an empty ALPN protocol |
| 4371 | // should be rejected. |
| 4372 | ALPNProtocol: &emptyString, |
| 4373 | }, |
| 4374 | }, |
| 4375 | flags: []string{ |
| 4376 | "-advertise-alpn", "\x03foo", |
| 4377 | }, |
| 4378 | shouldFail: true, |
| 4379 | expectedError: ":PARSE_TLSEXT:", |
| 4380 | }) |
| 4381 | testCases = append(testCases, testCase{ |
| 4382 | testType: serverTest, |
| 4383 | name: "ALPNServer-EmptyProtocolName-" + ver.name, |
| 4384 | config: Config{ |
| 4385 | MaxVersion: ver.version, |
| 4386 | // A ClientHello containing an empty ALPN protocol |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4387 | // should be rejected. |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4388 | NextProtos: []string{"foo", "", "baz"}, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4389 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4390 | flags: []string{ |
| 4391 | "-select-alpn", "foo", |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 4392 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4393 | shouldFail: true, |
| 4394 | expectedError: ":PARSE_TLSEXT:", |
| 4395 | }) |
| 4396 | |
| 4397 | // Test NPN and the interaction with ALPN. |
| 4398 | if ver.version < VersionTLS13 { |
| 4399 | // Test that the server prefers ALPN over NPN. |
| 4400 | testCases = append(testCases, testCase{ |
| 4401 | testType: serverTest, |
| 4402 | name: "ALPNServer-Preferred-" + ver.name, |
| 4403 | config: Config{ |
| 4404 | MaxVersion: ver.version, |
| 4405 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4406 | }, |
| 4407 | flags: []string{ |
| 4408 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4409 | "-select-alpn", "foo", |
| 4410 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4411 | }, |
| 4412 | expectedNextProto: "foo", |
| 4413 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4414 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4415 | }) |
| 4416 | testCases = append(testCases, testCase{ |
| 4417 | testType: serverTest, |
| 4418 | name: "ALPNServer-Preferred-Swapped-" + ver.name, |
| 4419 | config: Config{ |
| 4420 | MaxVersion: ver.version, |
| 4421 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4422 | Bugs: ProtocolBugs{ |
| 4423 | SwapNPNAndALPN: true, |
| 4424 | }, |
| 4425 | }, |
| 4426 | flags: []string{ |
| 4427 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4428 | "-select-alpn", "foo", |
| 4429 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4430 | }, |
| 4431 | expectedNextProto: "foo", |
| 4432 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4433 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4434 | }) |
| 4435 | |
| 4436 | // Test that negotiating both NPN and ALPN is forbidden. |
| 4437 | testCases = append(testCases, testCase{ |
| 4438 | name: "NegotiateALPNAndNPN-" + ver.name, |
| 4439 | config: Config{ |
| 4440 | MaxVersion: ver.version, |
| 4441 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4442 | Bugs: ProtocolBugs{ |
| 4443 | NegotiateALPNAndNPN: true, |
| 4444 | }, |
| 4445 | }, |
| 4446 | flags: []string{ |
| 4447 | "-advertise-alpn", "\x03foo", |
| 4448 | "-select-next-proto", "foo", |
| 4449 | }, |
| 4450 | shouldFail: true, |
| 4451 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4452 | }) |
| 4453 | testCases = append(testCases, testCase{ |
| 4454 | name: "NegotiateALPNAndNPN-Swapped-" + ver.name, |
| 4455 | config: Config{ |
| 4456 | MaxVersion: ver.version, |
| 4457 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4458 | Bugs: ProtocolBugs{ |
| 4459 | NegotiateALPNAndNPN: true, |
| 4460 | SwapNPNAndALPN: true, |
| 4461 | }, |
| 4462 | }, |
| 4463 | flags: []string{ |
| 4464 | "-advertise-alpn", "\x03foo", |
| 4465 | "-select-next-proto", "foo", |
| 4466 | }, |
| 4467 | shouldFail: true, |
| 4468 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4469 | }) |
| 4470 | |
| 4471 | // Test that NPN can be disabled with SSL_OP_DISABLE_NPN. |
| 4472 | testCases = append(testCases, testCase{ |
| 4473 | name: "DisableNPN-" + ver.name, |
| 4474 | config: Config{ |
| 4475 | MaxVersion: ver.version, |
| 4476 | NextProtos: []string{"foo"}, |
| 4477 | }, |
| 4478 | flags: []string{ |
| 4479 | "-select-next-proto", "foo", |
| 4480 | "-disable-npn", |
| 4481 | }, |
| 4482 | expectNoNextProto: true, |
| 4483 | }) |
| 4484 | } |
| 4485 | |
| 4486 | // Test ticket behavior. |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4487 | |
| 4488 | // Resume with a corrupt ticket. |
| 4489 | testCases = append(testCases, testCase{ |
| 4490 | testType: serverTest, |
| 4491 | name: "CorruptTicket-" + ver.name, |
| 4492 | config: Config{ |
| 4493 | MaxVersion: ver.version, |
| 4494 | Bugs: ProtocolBugs{ |
| 4495 | CorruptTicket: true, |
| 4496 | }, |
| 4497 | }, |
| 4498 | resumeSession: true, |
| 4499 | expectResumeRejected: true, |
| 4500 | }) |
| 4501 | // Test the ticket callback, with and without renewal. |
| 4502 | testCases = append(testCases, testCase{ |
| 4503 | testType: serverTest, |
| 4504 | name: "TicketCallback-" + ver.name, |
| 4505 | config: Config{ |
| 4506 | MaxVersion: ver.version, |
| 4507 | }, |
| 4508 | resumeSession: true, |
| 4509 | flags: []string{"-use-ticket-callback"}, |
| 4510 | }) |
| 4511 | testCases = append(testCases, testCase{ |
| 4512 | testType: serverTest, |
| 4513 | name: "TicketCallback-Renew-" + ver.name, |
| 4514 | config: Config{ |
| 4515 | MaxVersion: ver.version, |
| 4516 | Bugs: ProtocolBugs{ |
| 4517 | ExpectNewTicket: true, |
| 4518 | }, |
| 4519 | }, |
| 4520 | flags: []string{"-use-ticket-callback", "-renew-ticket"}, |
| 4521 | resumeSession: true, |
| 4522 | }) |
| 4523 | |
| 4524 | // Test that the ticket callback is only called once when everything before |
| 4525 | // it in the ClientHello is asynchronous. This corrupts the ticket so |
| 4526 | // certificate selection callbacks run. |
| 4527 | testCases = append(testCases, testCase{ |
| 4528 | testType: serverTest, |
| 4529 | name: "TicketCallback-SingleCall-" + ver.name, |
| 4530 | config: Config{ |
| 4531 | MaxVersion: ver.version, |
| 4532 | Bugs: ProtocolBugs{ |
| 4533 | CorruptTicket: true, |
| 4534 | }, |
| 4535 | }, |
| 4536 | resumeSession: true, |
| 4537 | expectResumeRejected: true, |
| 4538 | flags: []string{ |
| 4539 | "-use-ticket-callback", |
| 4540 | "-async", |
| 4541 | }, |
| 4542 | }) |
| 4543 | |
| 4544 | // Resume with an oversized session id. |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4545 | if ver.version < VersionTLS13 { |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4546 | testCases = append(testCases, testCase{ |
| 4547 | testType: serverTest, |
| 4548 | name: "OversizedSessionId-" + ver.name, |
| 4549 | config: Config{ |
| 4550 | MaxVersion: ver.version, |
| 4551 | Bugs: ProtocolBugs{ |
| 4552 | OversizedSessionId: true, |
| 4553 | }, |
| 4554 | }, |
| 4555 | resumeSession: true, |
| 4556 | shouldFail: true, |
| 4557 | expectedError: ":DECODE_ERROR:", |
| 4558 | }) |
| 4559 | } |
| 4560 | |
| 4561 | // Basic DTLS-SRTP tests. Include fake profiles to ensure they |
| 4562 | // are ignored. |
| 4563 | if ver.hasDTLS { |
| 4564 | testCases = append(testCases, testCase{ |
| 4565 | protocol: dtls, |
| 4566 | name: "SRTP-Client-" + ver.name, |
| 4567 | config: Config{ |
| 4568 | MaxVersion: ver.version, |
| 4569 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4570 | }, |
| 4571 | flags: []string{ |
| 4572 | "-srtp-profiles", |
| 4573 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4574 | }, |
| 4575 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4576 | }) |
| 4577 | testCases = append(testCases, testCase{ |
| 4578 | protocol: dtls, |
| 4579 | testType: serverTest, |
| 4580 | name: "SRTP-Server-" + ver.name, |
| 4581 | config: Config{ |
| 4582 | MaxVersion: ver.version, |
| 4583 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4584 | }, |
| 4585 | flags: []string{ |
| 4586 | "-srtp-profiles", |
| 4587 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4588 | }, |
| 4589 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4590 | }) |
| 4591 | // Test that the MKI is ignored. |
| 4592 | testCases = append(testCases, testCase{ |
| 4593 | protocol: dtls, |
| 4594 | testType: serverTest, |
| 4595 | name: "SRTP-Server-IgnoreMKI-" + ver.name, |
| 4596 | config: Config{ |
| 4597 | MaxVersion: ver.version, |
| 4598 | SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80}, |
| 4599 | Bugs: ProtocolBugs{ |
| 4600 | SRTPMasterKeyIdentifer: "bogus", |
| 4601 | }, |
| 4602 | }, |
| 4603 | flags: []string{ |
| 4604 | "-srtp-profiles", |
| 4605 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4606 | }, |
| 4607 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4608 | }) |
| 4609 | // Test that SRTP isn't negotiated on the server if there were |
| 4610 | // no matching profiles. |
| 4611 | testCases = append(testCases, testCase{ |
| 4612 | protocol: dtls, |
| 4613 | testType: serverTest, |
| 4614 | name: "SRTP-Server-NoMatch-" + ver.name, |
| 4615 | config: Config{ |
| 4616 | MaxVersion: ver.version, |
| 4617 | SRTPProtectionProfiles: []uint16{100, 101, 102}, |
| 4618 | }, |
| 4619 | flags: []string{ |
| 4620 | "-srtp-profiles", |
| 4621 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4622 | }, |
| 4623 | expectedSRTPProtectionProfile: 0, |
| 4624 | }) |
| 4625 | // Test that the server returning an invalid SRTP profile is |
| 4626 | // flagged as an error by the client. |
| 4627 | testCases = append(testCases, testCase{ |
| 4628 | protocol: dtls, |
| 4629 | name: "SRTP-Client-NoMatch-" + ver.name, |
| 4630 | config: Config{ |
| 4631 | MaxVersion: ver.version, |
| 4632 | Bugs: ProtocolBugs{ |
| 4633 | SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32, |
| 4634 | }, |
| 4635 | }, |
| 4636 | flags: []string{ |
| 4637 | "-srtp-profiles", |
| 4638 | "SRTP_AES128_CM_SHA1_80", |
| 4639 | }, |
| 4640 | shouldFail: true, |
| 4641 | expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:", |
| 4642 | }) |
| 4643 | } |
| 4644 | |
| 4645 | // Test SCT list. |
| 4646 | testCases = append(testCases, testCase{ |
| 4647 | name: "SignedCertificateTimestampList-Client-" + ver.name, |
| 4648 | testType: clientTest, |
| 4649 | config: Config{ |
| 4650 | MaxVersion: ver.version, |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 4651 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4652 | flags: []string{ |
| 4653 | "-enable-signed-cert-timestamps", |
| 4654 | "-expect-signed-cert-timestamps", |
| 4655 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 4656 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4657 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4658 | }) |
| 4659 | testCases = append(testCases, testCase{ |
| 4660 | name: "SendSCTListOnResume-" + ver.name, |
| 4661 | config: Config{ |
| 4662 | MaxVersion: ver.version, |
| 4663 | Bugs: ProtocolBugs{ |
| 4664 | SendSCTListOnResume: []byte("bogus"), |
| 4665 | }, |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 4666 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4667 | flags: []string{ |
| 4668 | "-enable-signed-cert-timestamps", |
| 4669 | "-expect-signed-cert-timestamps", |
| 4670 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 4671 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4672 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4673 | }) |
| 4674 | testCases = append(testCases, testCase{ |
| 4675 | name: "SignedCertificateTimestampList-Server-" + ver.name, |
| 4676 | testType: serverTest, |
| 4677 | config: Config{ |
| 4678 | MaxVersion: ver.version, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4679 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4680 | flags: []string{ |
| 4681 | "-signed-cert-timestamps", |
| 4682 | base64.StdEncoding.EncodeToString(testSCTList), |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4683 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4684 | expectedSCTList: testSCTList, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4685 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4686 | }) |
| 4687 | } |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4688 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 4689 | testCases = append(testCases, testCase{ |
Adam Langley | 33ad2b5 | 2015-07-20 17:43:53 -0700 | [diff] [blame] | 4690 | testType: clientTest, |
| 4691 | name: "ClientHelloPadding", |
| 4692 | config: Config{ |
| 4693 | Bugs: ProtocolBugs{ |
| 4694 | RequireClientHelloSize: 512, |
| 4695 | }, |
| 4696 | }, |
| 4697 | // This hostname just needs to be long enough to push the |
| 4698 | // ClientHello into F5's danger zone between 256 and 511 bytes |
| 4699 | // long. |
| 4700 | flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"}, |
| 4701 | }) |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 4702 | |
| 4703 | // Extensions should not function in SSL 3.0. |
| 4704 | testCases = append(testCases, testCase{ |
| 4705 | testType: serverTest, |
| 4706 | name: "SSLv3Extensions-NoALPN", |
| 4707 | config: Config{ |
| 4708 | MaxVersion: VersionSSL30, |
| 4709 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4710 | }, |
| 4711 | flags: []string{ |
| 4712 | "-select-alpn", "foo", |
| 4713 | }, |
| 4714 | expectNoNextProto: true, |
| 4715 | }) |
| 4716 | |
| 4717 | // Test session tickets separately as they follow a different codepath. |
| 4718 | testCases = append(testCases, testCase{ |
| 4719 | testType: serverTest, |
| 4720 | name: "SSLv3Extensions-NoTickets", |
| 4721 | config: Config{ |
| 4722 | MaxVersion: VersionSSL30, |
| 4723 | Bugs: ProtocolBugs{ |
| 4724 | // Historically, session tickets in SSL 3.0 |
| 4725 | // failed in different ways depending on whether |
| 4726 | // the client supported renegotiation_info. |
| 4727 | NoRenegotiationInfo: true, |
| 4728 | }, |
| 4729 | }, |
| 4730 | resumeSession: true, |
| 4731 | }) |
| 4732 | testCases = append(testCases, testCase{ |
| 4733 | testType: serverTest, |
| 4734 | name: "SSLv3Extensions-NoTickets2", |
| 4735 | config: Config{ |
| 4736 | MaxVersion: VersionSSL30, |
| 4737 | }, |
| 4738 | resumeSession: true, |
| 4739 | }) |
| 4740 | |
| 4741 | // But SSL 3.0 does send and process renegotiation_info. |
| 4742 | testCases = append(testCases, testCase{ |
| 4743 | testType: serverTest, |
| 4744 | name: "SSLv3Extensions-RenegotiationInfo", |
| 4745 | config: Config{ |
| 4746 | MaxVersion: VersionSSL30, |
| 4747 | Bugs: ProtocolBugs{ |
| 4748 | RequireRenegotiationInfo: true, |
| 4749 | }, |
| 4750 | }, |
| 4751 | }) |
| 4752 | testCases = append(testCases, testCase{ |
| 4753 | testType: serverTest, |
| 4754 | name: "SSLv3Extensions-RenegotiationInfo-SCSV", |
| 4755 | config: Config{ |
| 4756 | MaxVersion: VersionSSL30, |
| 4757 | Bugs: ProtocolBugs{ |
| 4758 | NoRenegotiationInfo: true, |
| 4759 | SendRenegotiationSCSV: true, |
| 4760 | RequireRenegotiationInfo: true, |
| 4761 | }, |
| 4762 | }, |
| 4763 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 4764 | |
| 4765 | // Test that illegal extensions in TLS 1.3 are rejected by the client if |
| 4766 | // in ServerHello. |
| 4767 | testCases = append(testCases, testCase{ |
| 4768 | name: "NPN-Forbidden-TLS13", |
| 4769 | config: Config{ |
| 4770 | MaxVersion: VersionTLS13, |
| 4771 | NextProtos: []string{"foo"}, |
| 4772 | Bugs: ProtocolBugs{ |
| 4773 | NegotiateNPNAtAllVersions: true, |
| 4774 | }, |
| 4775 | }, |
| 4776 | flags: []string{"-select-next-proto", "foo"}, |
| 4777 | shouldFail: true, |
| 4778 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4779 | }) |
| 4780 | testCases = append(testCases, testCase{ |
| 4781 | name: "EMS-Forbidden-TLS13", |
| 4782 | config: Config{ |
| 4783 | MaxVersion: VersionTLS13, |
| 4784 | Bugs: ProtocolBugs{ |
| 4785 | NegotiateEMSAtAllVersions: true, |
| 4786 | }, |
| 4787 | }, |
| 4788 | shouldFail: true, |
| 4789 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4790 | }) |
| 4791 | testCases = append(testCases, testCase{ |
| 4792 | name: "RenegotiationInfo-Forbidden-TLS13", |
| 4793 | config: Config{ |
| 4794 | MaxVersion: VersionTLS13, |
| 4795 | Bugs: ProtocolBugs{ |
| 4796 | NegotiateRenegotiationInfoAtAllVersions: true, |
| 4797 | }, |
| 4798 | }, |
| 4799 | shouldFail: true, |
| 4800 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4801 | }) |
| 4802 | testCases = append(testCases, testCase{ |
| 4803 | name: "ChannelID-Forbidden-TLS13", |
| 4804 | config: Config{ |
| 4805 | MaxVersion: VersionTLS13, |
| 4806 | RequestChannelID: true, |
| 4807 | Bugs: ProtocolBugs{ |
| 4808 | NegotiateChannelIDAtAllVersions: true, |
| 4809 | }, |
| 4810 | }, |
| 4811 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
| 4812 | shouldFail: true, |
| 4813 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4814 | }) |
| 4815 | testCases = append(testCases, testCase{ |
| 4816 | name: "Ticket-Forbidden-TLS13", |
| 4817 | config: Config{ |
| 4818 | MaxVersion: VersionTLS12, |
| 4819 | }, |
| 4820 | resumeConfig: &Config{ |
| 4821 | MaxVersion: VersionTLS13, |
| 4822 | Bugs: ProtocolBugs{ |
| 4823 | AdvertiseTicketExtension: true, |
| 4824 | }, |
| 4825 | }, |
| 4826 | resumeSession: true, |
| 4827 | shouldFail: true, |
| 4828 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4829 | }) |
| 4830 | |
| 4831 | // Test that illegal extensions in TLS 1.3 are declined by the server if |
| 4832 | // offered in ClientHello. The runner's server will fail if this occurs, |
| 4833 | // so we exercise the offering path. (EMS and Renegotiation Info are |
| 4834 | // implicit in every test.) |
| 4835 | testCases = append(testCases, testCase{ |
| 4836 | testType: serverTest, |
| 4837 | name: "ChannelID-Declined-TLS13", |
| 4838 | config: Config{ |
| 4839 | MaxVersion: VersionTLS13, |
| 4840 | ChannelID: channelIDKey, |
| 4841 | }, |
| 4842 | flags: []string{"-enable-channel-id"}, |
| 4843 | }) |
| 4844 | testCases = append(testCases, testCase{ |
| 4845 | testType: serverTest, |
| 4846 | name: "NPN-Server", |
| 4847 | config: Config{ |
| 4848 | MaxVersion: VersionTLS13, |
| 4849 | NextProtos: []string{"bar"}, |
| 4850 | }, |
| 4851 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 4852 | }) |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4853 | } |
| 4854 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4855 | func addResumptionVersionTests() { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4856 | for _, sessionVers := range tlsVersions { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4857 | for _, resumeVers := range tlsVersions { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4858 | cipher := TLS_RSA_WITH_AES_128_CBC_SHA |
| 4859 | if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 { |
| 4860 | // TLS 1.3 only shares ciphers with TLS 1.2, so |
| 4861 | // we skip certain combinations and use a |
| 4862 | // different cipher to test with. |
| 4863 | cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
| 4864 | if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 { |
| 4865 | continue |
| 4866 | } |
| 4867 | } |
| 4868 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4869 | protocols := []protocol{tls} |
| 4870 | if sessionVers.hasDTLS && resumeVers.hasDTLS { |
| 4871 | protocols = append(protocols, dtls) |
David Benjamin | bdf5e72 | 2014-11-11 00:52:15 -0500 | [diff] [blame] | 4872 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4873 | for _, protocol := range protocols { |
| 4874 | suffix := "-" + sessionVers.name + "-" + resumeVers.name |
| 4875 | if protocol == dtls { |
| 4876 | suffix += "-DTLS" |
| 4877 | } |
| 4878 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4879 | if sessionVers.version == resumeVers.version { |
| 4880 | testCases = append(testCases, testCase{ |
| 4881 | protocol: protocol, |
| 4882 | name: "Resume-Client" + suffix, |
| 4883 | resumeSession: true, |
| 4884 | config: Config{ |
| 4885 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4886 | CipherSuites: []uint16{cipher}, |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame^] | 4887 | Bugs: ProtocolBugs{ |
| 4888 | ExpectNoTLS12Session: sessionVers.version >= VersionTLS13, |
| 4889 | ExpectNoTLS13PSK: sessionVers.version < VersionTLS13, |
| 4890 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4891 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4892 | expectedVersion: sessionVers.version, |
| 4893 | expectedResumeVersion: resumeVers.version, |
| 4894 | }) |
| 4895 | } else { |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame^] | 4896 | error := ":OLD_SESSION_VERSION_NOT_RETURNED:" |
| 4897 | |
| 4898 | // Offering a TLS 1.3 session sends an empty session ID, so |
| 4899 | // there is no way to convince a non-lookahead client the |
| 4900 | // session was resumed. It will appear to the client that a |
| 4901 | // stray ChangeCipherSpec was sent. |
| 4902 | if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 { |
| 4903 | error = ":UNEXPECTED_RECORD:" |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4904 | } |
| 4905 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4906 | testCases = append(testCases, testCase{ |
| 4907 | protocol: protocol, |
| 4908 | name: "Resume-Client-Mismatch" + suffix, |
| 4909 | resumeSession: true, |
| 4910 | config: Config{ |
| 4911 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4912 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4913 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4914 | expectedVersion: sessionVers.version, |
| 4915 | resumeConfig: &Config{ |
| 4916 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4917 | CipherSuites: []uint16{cipher}, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4918 | Bugs: ProtocolBugs{ |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame^] | 4919 | AcceptAnySession: true, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4920 | }, |
| 4921 | }, |
| 4922 | expectedResumeVersion: resumeVers.version, |
| 4923 | shouldFail: true, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4924 | expectedError: error, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4925 | }) |
| 4926 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4927 | |
| 4928 | testCases = append(testCases, testCase{ |
| 4929 | protocol: protocol, |
| 4930 | name: "Resume-Client-NoResume" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4931 | resumeSession: true, |
| 4932 | config: Config{ |
| 4933 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4934 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4935 | }, |
| 4936 | expectedVersion: sessionVers.version, |
| 4937 | resumeConfig: &Config{ |
| 4938 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4939 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4940 | }, |
| 4941 | newSessionsOnResume: true, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 4942 | expectResumeRejected: true, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4943 | expectedResumeVersion: resumeVers.version, |
| 4944 | }) |
| 4945 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4946 | testCases = append(testCases, testCase{ |
| 4947 | protocol: protocol, |
| 4948 | testType: serverTest, |
| 4949 | name: "Resume-Server" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4950 | resumeSession: true, |
| 4951 | config: Config{ |
| 4952 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4953 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4954 | }, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 4955 | expectedVersion: sessionVers.version, |
| 4956 | expectResumeRejected: sessionVers.version != resumeVers.version, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4957 | resumeConfig: &Config{ |
| 4958 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4959 | CipherSuites: []uint16{cipher}, |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame^] | 4960 | Bugs: ProtocolBugs{ |
| 4961 | SendBothTickets: true, |
| 4962 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4963 | }, |
| 4964 | expectedResumeVersion: resumeVers.version, |
| 4965 | }) |
| 4966 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4967 | } |
| 4968 | } |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4969 | |
| 4970 | testCases = append(testCases, testCase{ |
| 4971 | name: "Resume-Client-CipherMismatch", |
| 4972 | resumeSession: true, |
| 4973 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4974 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4975 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 4976 | }, |
| 4977 | resumeConfig: &Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4978 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4979 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 4980 | Bugs: ProtocolBugs{ |
| 4981 | SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 4982 | }, |
| 4983 | }, |
| 4984 | shouldFail: true, |
| 4985 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 4986 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4987 | |
| 4988 | testCases = append(testCases, testCase{ |
| 4989 | name: "Resume-Client-CipherMismatch-TLS13", |
| 4990 | resumeSession: true, |
| 4991 | config: Config{ |
| 4992 | MaxVersion: VersionTLS13, |
| 4993 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4994 | }, |
| 4995 | resumeConfig: &Config{ |
| 4996 | MaxVersion: VersionTLS13, |
| 4997 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4998 | Bugs: ProtocolBugs{ |
| 4999 | SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, |
| 5000 | }, |
| 5001 | }, |
| 5002 | shouldFail: true, |
| 5003 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 5004 | }) |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5005 | } |
| 5006 | |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 5007 | func addRenegotiationTests() { |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 5008 | // Servers cannot renegotiate. |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5009 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5010 | testType: serverTest, |
| 5011 | name: "Renegotiate-Server-Forbidden", |
| 5012 | config: Config{ |
| 5013 | MaxVersion: VersionTLS12, |
| 5014 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5015 | renegotiate: 1, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5016 | shouldFail: true, |
| 5017 | expectedError: ":NO_RENEGOTIATION:", |
| 5018 | expectedLocalError: "remote error: no renegotiation", |
| 5019 | }) |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5020 | // The server shouldn't echo the renegotiation extension unless |
| 5021 | // requested by the client. |
| 5022 | testCases = append(testCases, testCase{ |
| 5023 | testType: serverTest, |
| 5024 | name: "Renegotiate-Server-NoExt", |
| 5025 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5026 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5027 | Bugs: ProtocolBugs{ |
| 5028 | NoRenegotiationInfo: true, |
| 5029 | RequireRenegotiationInfo: true, |
| 5030 | }, |
| 5031 | }, |
| 5032 | shouldFail: true, |
| 5033 | expectedLocalError: "renegotiation extension missing", |
| 5034 | }) |
| 5035 | // The renegotiation SCSV should be sufficient for the server to echo |
| 5036 | // the extension. |
| 5037 | testCases = append(testCases, testCase{ |
| 5038 | testType: serverTest, |
| 5039 | name: "Renegotiate-Server-NoExt-SCSV", |
| 5040 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5041 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5042 | Bugs: ProtocolBugs{ |
| 5043 | NoRenegotiationInfo: true, |
| 5044 | SendRenegotiationSCSV: true, |
| 5045 | RequireRenegotiationInfo: true, |
| 5046 | }, |
| 5047 | }, |
| 5048 | }) |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5049 | testCases = append(testCases, testCase{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 5050 | name: "Renegotiate-Client", |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5051 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5052 | MaxVersion: VersionTLS12, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5053 | Bugs: ProtocolBugs{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 5054 | FailIfResumeOnRenego: true, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5055 | }, |
| 5056 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5057 | renegotiate: 1, |
| 5058 | flags: []string{ |
| 5059 | "-renegotiate-freely", |
| 5060 | "-expect-total-renegotiations", "1", |
| 5061 | }, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5062 | }) |
| 5063 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5064 | name: "Renegotiate-Client-EmptyExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5065 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5066 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5067 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5068 | Bugs: ProtocolBugs{ |
| 5069 | EmptyRenegotiationInfo: true, |
| 5070 | }, |
| 5071 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5072 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5073 | shouldFail: true, |
| 5074 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5075 | }) |
| 5076 | testCases = append(testCases, testCase{ |
| 5077 | name: "Renegotiate-Client-BadExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5078 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5079 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5080 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5081 | Bugs: ProtocolBugs{ |
| 5082 | BadRenegotiationInfo: true, |
| 5083 | }, |
| 5084 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5085 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5086 | shouldFail: true, |
| 5087 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5088 | }) |
| 5089 | testCases = append(testCases, testCase{ |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5090 | name: "Renegotiate-Client-Downgrade", |
| 5091 | renegotiate: 1, |
| 5092 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5093 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5094 | Bugs: ProtocolBugs{ |
| 5095 | NoRenegotiationInfoAfterInitial: true, |
| 5096 | }, |
| 5097 | }, |
| 5098 | flags: []string{"-renegotiate-freely"}, |
| 5099 | shouldFail: true, |
| 5100 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5101 | }) |
| 5102 | testCases = append(testCases, testCase{ |
| 5103 | name: "Renegotiate-Client-Upgrade", |
| 5104 | renegotiate: 1, |
| 5105 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5106 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5107 | Bugs: ProtocolBugs{ |
| 5108 | NoRenegotiationInfoInInitial: true, |
| 5109 | }, |
| 5110 | }, |
| 5111 | flags: []string{"-renegotiate-freely"}, |
| 5112 | shouldFail: true, |
| 5113 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5114 | }) |
| 5115 | testCases = append(testCases, testCase{ |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5116 | name: "Renegotiate-Client-NoExt-Allowed", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5117 | renegotiate: 1, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5118 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5119 | MaxVersion: VersionTLS12, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5120 | Bugs: ProtocolBugs{ |
| 5121 | NoRenegotiationInfo: true, |
| 5122 | }, |
| 5123 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5124 | flags: []string{ |
| 5125 | "-renegotiate-freely", |
| 5126 | "-expect-total-renegotiations", "1", |
| 5127 | }, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5128 | }) |
David Benjamin | e7e36aa | 2016-08-08 12:39:41 -0400 | [diff] [blame] | 5129 | |
| 5130 | // Test that the server may switch ciphers on renegotiation without |
| 5131 | // problems. |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5132 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5133 | name: "Renegotiate-Client-SwitchCiphers", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5134 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5135 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5136 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5137 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 5138 | }, |
| 5139 | renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5140 | flags: []string{ |
| 5141 | "-renegotiate-freely", |
| 5142 | "-expect-total-renegotiations", "1", |
| 5143 | }, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5144 | }) |
| 5145 | testCases = append(testCases, testCase{ |
| 5146 | name: "Renegotiate-Client-SwitchCiphers2", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5147 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5148 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5149 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5150 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5151 | }, |
| 5152 | renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5153 | flags: []string{ |
| 5154 | "-renegotiate-freely", |
| 5155 | "-expect-total-renegotiations", "1", |
| 5156 | }, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5157 | }) |
David Benjamin | e7e36aa | 2016-08-08 12:39:41 -0400 | [diff] [blame] | 5158 | |
| 5159 | // Test that the server may not switch versions on renegotiation. |
| 5160 | testCases = append(testCases, testCase{ |
| 5161 | name: "Renegotiate-Client-SwitchVersion", |
| 5162 | config: Config{ |
| 5163 | MaxVersion: VersionTLS12, |
| 5164 | // Pick a cipher which exists at both versions. |
| 5165 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 5166 | Bugs: ProtocolBugs{ |
| 5167 | NegotiateVersionOnRenego: VersionTLS11, |
| 5168 | }, |
| 5169 | }, |
| 5170 | renegotiate: 1, |
| 5171 | flags: []string{ |
| 5172 | "-renegotiate-freely", |
| 5173 | "-expect-total-renegotiations", "1", |
| 5174 | }, |
| 5175 | shouldFail: true, |
| 5176 | expectedError: ":WRONG_SSL_VERSION:", |
| 5177 | }) |
| 5178 | |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5179 | testCases = append(testCases, testCase{ |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5180 | name: "Renegotiate-SameClientVersion", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5181 | renegotiate: 1, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5182 | config: Config{ |
| 5183 | MaxVersion: VersionTLS10, |
| 5184 | Bugs: ProtocolBugs{ |
| 5185 | RequireSameRenegoClientVersion: true, |
| 5186 | }, |
| 5187 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5188 | flags: []string{ |
| 5189 | "-renegotiate-freely", |
| 5190 | "-expect-total-renegotiations", "1", |
| 5191 | }, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5192 | }) |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5193 | testCases = append(testCases, testCase{ |
| 5194 | name: "Renegotiate-FalseStart", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5195 | renegotiate: 1, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5196 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5197 | MaxVersion: VersionTLS12, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5198 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5199 | NextProtos: []string{"foo"}, |
| 5200 | }, |
| 5201 | flags: []string{ |
| 5202 | "-false-start", |
| 5203 | "-select-next-proto", "foo", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5204 | "-renegotiate-freely", |
David Benjamin | 324dce4 | 2015-10-12 19:49:00 -0400 | [diff] [blame] | 5205 | "-expect-total-renegotiations", "1", |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5206 | }, |
| 5207 | shimWritesFirst: true, |
| 5208 | }) |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5209 | |
| 5210 | // Client-side renegotiation controls. |
| 5211 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5212 | name: "Renegotiate-Client-Forbidden-1", |
| 5213 | config: Config{ |
| 5214 | MaxVersion: VersionTLS12, |
| 5215 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5216 | renegotiate: 1, |
| 5217 | shouldFail: true, |
| 5218 | expectedError: ":NO_RENEGOTIATION:", |
| 5219 | expectedLocalError: "remote error: no renegotiation", |
| 5220 | }) |
| 5221 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5222 | name: "Renegotiate-Client-Once-1", |
| 5223 | config: Config{ |
| 5224 | MaxVersion: VersionTLS12, |
| 5225 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5226 | renegotiate: 1, |
| 5227 | flags: []string{ |
| 5228 | "-renegotiate-once", |
| 5229 | "-expect-total-renegotiations", "1", |
| 5230 | }, |
| 5231 | }) |
| 5232 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5233 | name: "Renegotiate-Client-Freely-1", |
| 5234 | config: Config{ |
| 5235 | MaxVersion: VersionTLS12, |
| 5236 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5237 | renegotiate: 1, |
| 5238 | flags: []string{ |
| 5239 | "-renegotiate-freely", |
| 5240 | "-expect-total-renegotiations", "1", |
| 5241 | }, |
| 5242 | }) |
| 5243 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5244 | name: "Renegotiate-Client-Once-2", |
| 5245 | config: Config{ |
| 5246 | MaxVersion: VersionTLS12, |
| 5247 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5248 | renegotiate: 2, |
| 5249 | flags: []string{"-renegotiate-once"}, |
| 5250 | shouldFail: true, |
| 5251 | expectedError: ":NO_RENEGOTIATION:", |
| 5252 | expectedLocalError: "remote error: no renegotiation", |
| 5253 | }) |
| 5254 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5255 | name: "Renegotiate-Client-Freely-2", |
| 5256 | config: Config{ |
| 5257 | MaxVersion: VersionTLS12, |
| 5258 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5259 | renegotiate: 2, |
| 5260 | flags: []string{ |
| 5261 | "-renegotiate-freely", |
| 5262 | "-expect-total-renegotiations", "2", |
| 5263 | }, |
| 5264 | }) |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5265 | testCases = append(testCases, testCase{ |
| 5266 | name: "Renegotiate-Client-NoIgnore", |
| 5267 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5268 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5269 | Bugs: ProtocolBugs{ |
| 5270 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5271 | }, |
| 5272 | }, |
| 5273 | shouldFail: true, |
| 5274 | expectedError: ":NO_RENEGOTIATION:", |
| 5275 | }) |
| 5276 | testCases = append(testCases, testCase{ |
| 5277 | name: "Renegotiate-Client-Ignore", |
| 5278 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5279 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5280 | Bugs: ProtocolBugs{ |
| 5281 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5282 | }, |
| 5283 | }, |
| 5284 | flags: []string{ |
| 5285 | "-renegotiate-ignore", |
| 5286 | "-expect-total-renegotiations", "0", |
| 5287 | }, |
| 5288 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5289 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5290 | // Stray HelloRequests during the handshake are ignored in TLS 1.2. |
David Benjamin | 71dd666 | 2016-07-08 14:10:48 -0700 | [diff] [blame] | 5291 | testCases = append(testCases, testCase{ |
| 5292 | name: "StrayHelloRequest", |
| 5293 | config: Config{ |
| 5294 | MaxVersion: VersionTLS12, |
| 5295 | Bugs: ProtocolBugs{ |
| 5296 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5297 | }, |
| 5298 | }, |
| 5299 | }) |
| 5300 | testCases = append(testCases, testCase{ |
| 5301 | name: "StrayHelloRequest-Packed", |
| 5302 | config: Config{ |
| 5303 | MaxVersion: VersionTLS12, |
| 5304 | Bugs: ProtocolBugs{ |
| 5305 | PackHandshakeFlight: true, |
| 5306 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5307 | }, |
| 5308 | }, |
| 5309 | }) |
| 5310 | |
David Benjamin | 12d2c48 | 2016-07-24 10:56:51 -0400 | [diff] [blame] | 5311 | // Test renegotiation works if HelloRequest and server Finished come in |
| 5312 | // the same record. |
| 5313 | testCases = append(testCases, testCase{ |
| 5314 | name: "Renegotiate-Client-Packed", |
| 5315 | config: Config{ |
| 5316 | MaxVersion: VersionTLS12, |
| 5317 | Bugs: ProtocolBugs{ |
| 5318 | PackHandshakeFlight: true, |
| 5319 | PackHelloRequestWithFinished: true, |
| 5320 | }, |
| 5321 | }, |
| 5322 | renegotiate: 1, |
| 5323 | flags: []string{ |
| 5324 | "-renegotiate-freely", |
| 5325 | "-expect-total-renegotiations", "1", |
| 5326 | }, |
| 5327 | }) |
| 5328 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5329 | // Renegotiation is forbidden in TLS 1.3. |
| 5330 | testCases = append(testCases, testCase{ |
| 5331 | name: "Renegotiate-Client-TLS13", |
| 5332 | config: Config{ |
| 5333 | MaxVersion: VersionTLS13, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5334 | Bugs: ProtocolBugs{ |
| 5335 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5336 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5337 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5338 | flags: []string{ |
| 5339 | "-renegotiate-freely", |
| 5340 | }, |
Steven Valdez | 8e1c7be | 2016-07-26 12:39:22 -0400 | [diff] [blame] | 5341 | shouldFail: true, |
| 5342 | expectedError: ":UNEXPECTED_MESSAGE:", |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5343 | }) |
| 5344 | |
| 5345 | // Stray HelloRequests during the handshake are forbidden in TLS 1.3. |
| 5346 | testCases = append(testCases, testCase{ |
| 5347 | name: "StrayHelloRequest-TLS13", |
| 5348 | config: Config{ |
| 5349 | MaxVersion: VersionTLS13, |
| 5350 | Bugs: ProtocolBugs{ |
| 5351 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5352 | }, |
| 5353 | }, |
| 5354 | shouldFail: true, |
| 5355 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 5356 | }) |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 5357 | } |
| 5358 | |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5359 | func addDTLSReplayTests() { |
| 5360 | // Test that sequence number replays are detected. |
| 5361 | testCases = append(testCases, testCase{ |
| 5362 | protocol: dtls, |
| 5363 | name: "DTLS-Replay", |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5364 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5365 | replayWrites: true, |
| 5366 | }) |
| 5367 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5368 | // Test the incoming sequence number skipping by values larger |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5369 | // than the retransmit window. |
| 5370 | testCases = append(testCases, testCase{ |
| 5371 | protocol: dtls, |
| 5372 | name: "DTLS-Replay-LargeGaps", |
| 5373 | config: Config{ |
| 5374 | Bugs: ProtocolBugs{ |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5375 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5376 | return in * 127 |
| 5377 | }, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5378 | }, |
| 5379 | }, |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5380 | messageCount: 200, |
| 5381 | replayWrites: true, |
| 5382 | }) |
| 5383 | |
| 5384 | // Test the incoming sequence number changing non-monotonically. |
| 5385 | testCases = append(testCases, testCase{ |
| 5386 | protocol: dtls, |
| 5387 | name: "DTLS-Replay-NonMonotonic", |
| 5388 | config: Config{ |
| 5389 | Bugs: ProtocolBugs{ |
| 5390 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5391 | return in ^ 31 |
| 5392 | }, |
| 5393 | }, |
| 5394 | }, |
| 5395 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5396 | replayWrites: true, |
| 5397 | }) |
| 5398 | } |
| 5399 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5400 | var testSignatureAlgorithms = []struct { |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5401 | name string |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5402 | id signatureAlgorithm |
| 5403 | cert testCert |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5404 | }{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5405 | {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA}, |
| 5406 | {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA}, |
| 5407 | {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA}, |
| 5408 | {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5409 | {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5410 | {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256}, |
| 5411 | {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384}, |
| 5412 | {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521}, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5413 | {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA}, |
| 5414 | {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA}, |
| 5415 | {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5416 | // Tests for key types prior to TLS 1.2. |
| 5417 | {"RSA", 0, testCertRSA}, |
| 5418 | {"ECDSA", 0, testCertECDSAP256}, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5419 | } |
| 5420 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5421 | const fakeSigAlg1 signatureAlgorithm = 0x2a01 |
| 5422 | const fakeSigAlg2 signatureAlgorithm = 0xff01 |
| 5423 | |
| 5424 | func addSignatureAlgorithmTests() { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5425 | // Not all ciphers involve a signature. Advertise a list which gives all |
| 5426 | // versions a signing cipher. |
| 5427 | signingCiphers := []uint16{ |
| 5428 | TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 5429 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 5430 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 5431 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 5432 | TLS_DHE_RSA_WITH_AES_128_CBC_SHA, |
| 5433 | } |
| 5434 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5435 | var allAlgorithms []signatureAlgorithm |
| 5436 | for _, alg := range testSignatureAlgorithms { |
| 5437 | if alg.id != 0 { |
| 5438 | allAlgorithms = append(allAlgorithms, alg.id) |
| 5439 | } |
| 5440 | } |
| 5441 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5442 | // Make sure each signature algorithm works. Include some fake values in |
| 5443 | // the list and ensure they're ignored. |
| 5444 | for _, alg := range testSignatureAlgorithms { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5445 | for _, ver := range tlsVersions { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5446 | if (ver.version < VersionTLS12) != (alg.id == 0) { |
| 5447 | continue |
| 5448 | } |
| 5449 | |
| 5450 | // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing |
| 5451 | // or remove it in C. |
| 5452 | if ver.version == VersionSSL30 && alg.cert != testCertRSA { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5453 | continue |
| 5454 | } |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5455 | |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5456 | var shouldFail bool |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5457 | // ecdsa_sha1 does not exist in TLS 1.3. |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5458 | if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 { |
| 5459 | shouldFail = true |
| 5460 | } |
| 5461 | // RSA-PSS does not exist in TLS 1.2. |
| 5462 | if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") { |
| 5463 | shouldFail = true |
| 5464 | } |
| 5465 | |
| 5466 | var signError, verifyError string |
| 5467 | if shouldFail { |
| 5468 | signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:" |
| 5469 | verifyError = ":WRONG_SIGNATURE_TYPE:" |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5470 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5471 | |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5472 | suffix := "-" + alg.name + "-" + ver.name |
David Benjamin | 6e80765 | 2015-11-02 12:02:20 -0500 | [diff] [blame] | 5473 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5474 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5475 | name: "ClientAuth-Sign" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5476 | config: Config{ |
| 5477 | MaxVersion: ver.version, |
| 5478 | ClientAuth: RequireAnyClientCert, |
| 5479 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5480 | fakeSigAlg1, |
| 5481 | alg.id, |
| 5482 | fakeSigAlg2, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5483 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5484 | }, |
| 5485 | flags: []string{ |
| 5486 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5487 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5488 | "-enable-all-curves", |
| 5489 | }, |
| 5490 | shouldFail: shouldFail, |
| 5491 | expectedError: signError, |
| 5492 | expectedPeerSignatureAlgorithm: alg.id, |
| 5493 | }) |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5494 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5495 | testCases = append(testCases, testCase{ |
| 5496 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5497 | name: "ClientAuth-Verify" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5498 | config: Config{ |
| 5499 | MaxVersion: ver.version, |
| 5500 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5501 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5502 | alg.id, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5503 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5504 | Bugs: ProtocolBugs{ |
| 5505 | SkipECDSACurveCheck: shouldFail, |
| 5506 | IgnoreSignatureVersionChecks: shouldFail, |
| 5507 | // The client won't advertise 1.3-only algorithms after |
| 5508 | // version negotiation. |
| 5509 | IgnorePeerSignatureAlgorithmPreferences: shouldFail, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5510 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5511 | }, |
| 5512 | flags: []string{ |
| 5513 | "-require-any-client-certificate", |
| 5514 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5515 | "-enable-all-curves", |
| 5516 | }, |
| 5517 | shouldFail: shouldFail, |
| 5518 | expectedError: verifyError, |
| 5519 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5520 | |
| 5521 | testCases = append(testCases, testCase{ |
| 5522 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5523 | name: "ServerAuth-Sign" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5524 | config: Config{ |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5525 | MaxVersion: ver.version, |
| 5526 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5527 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5528 | fakeSigAlg1, |
| 5529 | alg.id, |
| 5530 | fakeSigAlg2, |
| 5531 | }, |
| 5532 | }, |
| 5533 | flags: []string{ |
| 5534 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5535 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5536 | "-enable-all-curves", |
| 5537 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5538 | shouldFail: shouldFail, |
| 5539 | expectedError: signError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5540 | expectedPeerSignatureAlgorithm: alg.id, |
| 5541 | }) |
| 5542 | |
| 5543 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5544 | name: "ServerAuth-Verify" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5545 | config: Config{ |
| 5546 | MaxVersion: ver.version, |
| 5547 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5548 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5549 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5550 | alg.id, |
| 5551 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5552 | Bugs: ProtocolBugs{ |
| 5553 | SkipECDSACurveCheck: shouldFail, |
| 5554 | IgnoreSignatureVersionChecks: shouldFail, |
| 5555 | }, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5556 | }, |
| 5557 | flags: []string{ |
| 5558 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5559 | "-enable-all-curves", |
| 5560 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5561 | shouldFail: shouldFail, |
| 5562 | expectedError: verifyError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5563 | }) |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5564 | |
| 5565 | if !shouldFail { |
| 5566 | testCases = append(testCases, testCase{ |
| 5567 | testType: serverTest, |
| 5568 | name: "ClientAuth-InvalidSignature" + suffix, |
| 5569 | config: Config{ |
| 5570 | MaxVersion: ver.version, |
| 5571 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5572 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5573 | alg.id, |
| 5574 | }, |
| 5575 | Bugs: ProtocolBugs{ |
| 5576 | InvalidSignature: true, |
| 5577 | }, |
| 5578 | }, |
| 5579 | flags: []string{ |
| 5580 | "-require-any-client-certificate", |
| 5581 | "-enable-all-curves", |
| 5582 | }, |
| 5583 | shouldFail: true, |
| 5584 | expectedError: ":BAD_SIGNATURE:", |
| 5585 | }) |
| 5586 | |
| 5587 | testCases = append(testCases, testCase{ |
| 5588 | name: "ServerAuth-InvalidSignature" + suffix, |
| 5589 | config: Config{ |
| 5590 | MaxVersion: ver.version, |
| 5591 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5592 | CipherSuites: signingCiphers, |
| 5593 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5594 | alg.id, |
| 5595 | }, |
| 5596 | Bugs: ProtocolBugs{ |
| 5597 | InvalidSignature: true, |
| 5598 | }, |
| 5599 | }, |
| 5600 | flags: []string{"-enable-all-curves"}, |
| 5601 | shouldFail: true, |
| 5602 | expectedError: ":BAD_SIGNATURE:", |
| 5603 | }) |
| 5604 | } |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5605 | |
| 5606 | if ver.version >= VersionTLS12 && !shouldFail { |
| 5607 | testCases = append(testCases, testCase{ |
| 5608 | name: "ClientAuth-Sign-Negotiate" + suffix, |
| 5609 | config: Config{ |
| 5610 | MaxVersion: ver.version, |
| 5611 | ClientAuth: RequireAnyClientCert, |
| 5612 | VerifySignatureAlgorithms: allAlgorithms, |
| 5613 | }, |
| 5614 | flags: []string{ |
| 5615 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5616 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5617 | "-enable-all-curves", |
| 5618 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 5619 | }, |
| 5620 | expectedPeerSignatureAlgorithm: alg.id, |
| 5621 | }) |
| 5622 | |
| 5623 | testCases = append(testCases, testCase{ |
| 5624 | testType: serverTest, |
| 5625 | name: "ServerAuth-Sign-Negotiate" + suffix, |
| 5626 | config: Config{ |
| 5627 | MaxVersion: ver.version, |
| 5628 | CipherSuites: signingCiphers, |
| 5629 | VerifySignatureAlgorithms: allAlgorithms, |
| 5630 | }, |
| 5631 | flags: []string{ |
| 5632 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5633 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5634 | "-enable-all-curves", |
| 5635 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 5636 | }, |
| 5637 | expectedPeerSignatureAlgorithm: alg.id, |
| 5638 | }) |
| 5639 | } |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5640 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5641 | } |
| 5642 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5643 | // Test that algorithm selection takes the key type into account. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5644 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5645 | name: "ClientAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5646 | config: Config{ |
| 5647 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5648 | MaxVersion: VersionTLS12, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5649 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5650 | signatureECDSAWithP521AndSHA512, |
| 5651 | signatureRSAPKCS1WithSHA384, |
| 5652 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5653 | }, |
| 5654 | }, |
| 5655 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5656 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5657 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5658 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5659 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5660 | }) |
| 5661 | |
| 5662 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5663 | name: "ClientAuth-SignatureType-TLS13", |
| 5664 | config: Config{ |
| 5665 | ClientAuth: RequireAnyClientCert, |
| 5666 | MaxVersion: VersionTLS13, |
| 5667 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5668 | signatureECDSAWithP521AndSHA512, |
| 5669 | signatureRSAPKCS1WithSHA384, |
| 5670 | signatureRSAPSSWithSHA384, |
| 5671 | signatureECDSAWithSHA1, |
| 5672 | }, |
| 5673 | }, |
| 5674 | flags: []string{ |
| 5675 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5676 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5677 | }, |
| 5678 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 5679 | }) |
| 5680 | |
| 5681 | testCases = append(testCases, testCase{ |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5682 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5683 | name: "ServerAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5684 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5685 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5686 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5687 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5688 | signatureECDSAWithP521AndSHA512, |
| 5689 | signatureRSAPKCS1WithSHA384, |
| 5690 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5691 | }, |
| 5692 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5693 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5694 | }) |
| 5695 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5696 | testCases = append(testCases, testCase{ |
| 5697 | testType: serverTest, |
| 5698 | name: "ServerAuth-SignatureType-TLS13", |
| 5699 | config: Config{ |
| 5700 | MaxVersion: VersionTLS13, |
| 5701 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5702 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5703 | signatureECDSAWithP521AndSHA512, |
| 5704 | signatureRSAPKCS1WithSHA384, |
| 5705 | signatureRSAPSSWithSHA384, |
| 5706 | signatureECDSAWithSHA1, |
| 5707 | }, |
| 5708 | }, |
| 5709 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 5710 | }) |
| 5711 | |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5712 | // Test that signature verification takes the key type into account. |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5713 | testCases = append(testCases, testCase{ |
| 5714 | testType: serverTest, |
| 5715 | name: "Verify-ClientAuth-SignatureType", |
| 5716 | config: Config{ |
| 5717 | MaxVersion: VersionTLS12, |
| 5718 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5719 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5720 | signatureRSAPKCS1WithSHA256, |
| 5721 | }, |
| 5722 | Bugs: ProtocolBugs{ |
| 5723 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5724 | }, |
| 5725 | }, |
| 5726 | flags: []string{ |
| 5727 | "-require-any-client-certificate", |
| 5728 | }, |
| 5729 | shouldFail: true, |
| 5730 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5731 | }) |
| 5732 | |
| 5733 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5734 | testType: serverTest, |
| 5735 | name: "Verify-ClientAuth-SignatureType-TLS13", |
| 5736 | config: Config{ |
| 5737 | MaxVersion: VersionTLS13, |
| 5738 | Certificates: []Certificate{rsaCertificate}, |
| 5739 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5740 | signatureRSAPSSWithSHA256, |
| 5741 | }, |
| 5742 | Bugs: ProtocolBugs{ |
| 5743 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5744 | }, |
| 5745 | }, |
| 5746 | flags: []string{ |
| 5747 | "-require-any-client-certificate", |
| 5748 | }, |
| 5749 | shouldFail: true, |
| 5750 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5751 | }) |
| 5752 | |
| 5753 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5754 | name: "Verify-ServerAuth-SignatureType", |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5755 | config: Config{ |
| 5756 | MaxVersion: VersionTLS12, |
| 5757 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5758 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5759 | signatureRSAPKCS1WithSHA256, |
| 5760 | }, |
| 5761 | Bugs: ProtocolBugs{ |
| 5762 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5763 | }, |
| 5764 | }, |
| 5765 | shouldFail: true, |
| 5766 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5767 | }) |
| 5768 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5769 | testCases = append(testCases, testCase{ |
| 5770 | name: "Verify-ServerAuth-SignatureType-TLS13", |
| 5771 | config: Config{ |
| 5772 | MaxVersion: VersionTLS13, |
| 5773 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5774 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5775 | signatureRSAPSSWithSHA256, |
| 5776 | }, |
| 5777 | Bugs: ProtocolBugs{ |
| 5778 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5779 | }, |
| 5780 | }, |
| 5781 | shouldFail: true, |
| 5782 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5783 | }) |
| 5784 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5785 | // Test that, if the list is missing, the peer falls back to SHA-1 in |
| 5786 | // TLS 1.2, but not TLS 1.3. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5787 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5788 | name: "ClientAuth-SHA1-Fallback", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5789 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5790 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5791 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5792 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5793 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5794 | }, |
| 5795 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5796 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5797 | }, |
| 5798 | }, |
| 5799 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5800 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5801 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5802 | }, |
| 5803 | }) |
| 5804 | |
| 5805 | testCases = append(testCases, testCase{ |
| 5806 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5807 | name: "ServerAuth-SHA1-Fallback", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5808 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5809 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5810 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5811 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5812 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5813 | }, |
| 5814 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5815 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5816 | }, |
| 5817 | }, |
| 5818 | }) |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5819 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5820 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5821 | name: "ClientAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5822 | config: Config{ |
| 5823 | MaxVersion: VersionTLS13, |
| 5824 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5825 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5826 | signatureRSAPKCS1WithSHA1, |
| 5827 | }, |
| 5828 | Bugs: ProtocolBugs{ |
| 5829 | NoSignatureAlgorithms: true, |
| 5830 | }, |
| 5831 | }, |
| 5832 | flags: []string{ |
| 5833 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5834 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5835 | }, |
David Benjamin | 4890165 | 2016-08-01 12:12:47 -0400 | [diff] [blame] | 5836 | shouldFail: true, |
| 5837 | // An empty CertificateRequest signature algorithm list is a |
| 5838 | // syntax error in TLS 1.3. |
| 5839 | expectedError: ":DECODE_ERROR:", |
| 5840 | expectedLocalError: "remote error: error decoding message", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5841 | }) |
| 5842 | |
| 5843 | testCases = append(testCases, testCase{ |
| 5844 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5845 | name: "ServerAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5846 | config: Config{ |
| 5847 | MaxVersion: VersionTLS13, |
| 5848 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5849 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5850 | signatureRSAPKCS1WithSHA1, |
| 5851 | }, |
| 5852 | Bugs: ProtocolBugs{ |
| 5853 | NoSignatureAlgorithms: true, |
| 5854 | }, |
| 5855 | }, |
| 5856 | shouldFail: true, |
| 5857 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5858 | }) |
| 5859 | |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 5860 | // Test that hash preferences are enforced. BoringSSL does not implement |
| 5861 | // MD5 signatures. |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5862 | testCases = append(testCases, testCase{ |
| 5863 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5864 | name: "ClientAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5865 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5866 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5867 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5868 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5869 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5870 | }, |
| 5871 | Bugs: ProtocolBugs{ |
| 5872 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5873 | }, |
| 5874 | }, |
| 5875 | flags: []string{"-require-any-client-certificate"}, |
| 5876 | shouldFail: true, |
| 5877 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5878 | }) |
| 5879 | |
| 5880 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5881 | name: "ServerAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5882 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5883 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5884 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5885 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5886 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5887 | }, |
| 5888 | Bugs: ProtocolBugs{ |
| 5889 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5890 | }, |
| 5891 | }, |
| 5892 | shouldFail: true, |
| 5893 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5894 | }) |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 5895 | testCases = append(testCases, testCase{ |
| 5896 | testType: serverTest, |
| 5897 | name: "ClientAuth-Enforced-TLS13", |
| 5898 | config: Config{ |
| 5899 | MaxVersion: VersionTLS13, |
| 5900 | Certificates: []Certificate{rsaCertificate}, |
| 5901 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5902 | signatureRSAPKCS1WithMD5, |
| 5903 | }, |
| 5904 | Bugs: ProtocolBugs{ |
| 5905 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5906 | IgnoreSignatureVersionChecks: true, |
| 5907 | }, |
| 5908 | }, |
| 5909 | flags: []string{"-require-any-client-certificate"}, |
| 5910 | shouldFail: true, |
| 5911 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5912 | }) |
| 5913 | |
| 5914 | testCases = append(testCases, testCase{ |
| 5915 | name: "ServerAuth-Enforced-TLS13", |
| 5916 | config: Config{ |
| 5917 | MaxVersion: VersionTLS13, |
| 5918 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5919 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5920 | signatureRSAPKCS1WithMD5, |
| 5921 | }, |
| 5922 | Bugs: ProtocolBugs{ |
| 5923 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5924 | IgnoreSignatureVersionChecks: true, |
| 5925 | }, |
| 5926 | }, |
| 5927 | shouldFail: true, |
| 5928 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5929 | }) |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5930 | |
| 5931 | // Test that the agreed upon digest respects the client preferences and |
| 5932 | // the server digests. |
| 5933 | testCases = append(testCases, testCase{ |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5934 | name: "NoCommonAlgorithms-Digests", |
| 5935 | config: Config{ |
| 5936 | MaxVersion: VersionTLS12, |
| 5937 | ClientAuth: RequireAnyClientCert, |
| 5938 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5939 | signatureRSAPKCS1WithSHA512, |
| 5940 | signatureRSAPKCS1WithSHA1, |
| 5941 | }, |
| 5942 | }, |
| 5943 | flags: []string{ |
| 5944 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5945 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5946 | "-digest-prefs", "SHA256", |
| 5947 | }, |
| 5948 | shouldFail: true, |
| 5949 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5950 | }) |
| 5951 | testCases = append(testCases, testCase{ |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 5952 | name: "NoCommonAlgorithms", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5953 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5954 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5955 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5956 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5957 | signatureRSAPKCS1WithSHA512, |
| 5958 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5959 | }, |
| 5960 | }, |
| 5961 | flags: []string{ |
| 5962 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5963 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5964 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5965 | }, |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5966 | shouldFail: true, |
| 5967 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5968 | }) |
| 5969 | testCases = append(testCases, testCase{ |
| 5970 | name: "NoCommonAlgorithms-TLS13", |
| 5971 | config: Config{ |
| 5972 | MaxVersion: VersionTLS13, |
| 5973 | ClientAuth: RequireAnyClientCert, |
| 5974 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5975 | signatureRSAPSSWithSHA512, |
| 5976 | signatureRSAPSSWithSHA384, |
| 5977 | }, |
| 5978 | }, |
| 5979 | flags: []string{ |
| 5980 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5981 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5982 | "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)), |
| 5983 | }, |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 5984 | shouldFail: true, |
| 5985 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5986 | }) |
| 5987 | testCases = append(testCases, testCase{ |
| 5988 | name: "Agree-Digest-SHA256", |
| 5989 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5990 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5991 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5992 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5993 | signatureRSAPKCS1WithSHA1, |
| 5994 | signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5995 | }, |
| 5996 | }, |
| 5997 | flags: []string{ |
| 5998 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5999 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6000 | "-digest-prefs", "SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6001 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6002 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6003 | }) |
| 6004 | testCases = append(testCases, testCase{ |
| 6005 | name: "Agree-Digest-SHA1", |
| 6006 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6007 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6008 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6009 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6010 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6011 | }, |
| 6012 | }, |
| 6013 | flags: []string{ |
| 6014 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6015 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6016 | "-digest-prefs", "SHA512,SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6017 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6018 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6019 | }) |
| 6020 | testCases = append(testCases, testCase{ |
| 6021 | name: "Agree-Digest-Default", |
| 6022 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6023 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6024 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6025 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6026 | signatureRSAPKCS1WithSHA256, |
| 6027 | signatureECDSAWithP256AndSHA256, |
| 6028 | signatureRSAPKCS1WithSHA1, |
| 6029 | signatureECDSAWithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6030 | }, |
| 6031 | }, |
| 6032 | flags: []string{ |
| 6033 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6034 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6035 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6036 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6037 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6038 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6039 | // Test that the signing preference list may include extra algorithms |
| 6040 | // without negotiation problems. |
| 6041 | testCases = append(testCases, testCase{ |
| 6042 | testType: serverTest, |
| 6043 | name: "FilterExtraAlgorithms", |
| 6044 | config: Config{ |
| 6045 | MaxVersion: VersionTLS12, |
| 6046 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6047 | signatureRSAPKCS1WithSHA256, |
| 6048 | }, |
| 6049 | }, |
| 6050 | flags: []string{ |
| 6051 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6052 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6053 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)), |
| 6054 | "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)), |
| 6055 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
| 6056 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)), |
| 6057 | }, |
| 6058 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
| 6059 | }) |
| 6060 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6061 | // In TLS 1.2 and below, ECDSA uses the curve list rather than the |
| 6062 | // signature algorithms. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6063 | testCases = append(testCases, testCase{ |
| 6064 | name: "CheckLeafCurve", |
| 6065 | config: Config{ |
| 6066 | MaxVersion: VersionTLS12, |
| 6067 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 6068 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6069 | }, |
| 6070 | flags: []string{"-p384-only"}, |
| 6071 | shouldFail: true, |
| 6072 | expectedError: ":BAD_ECC_CERT:", |
| 6073 | }) |
David Benjamin | 75ea5bb | 2016-07-08 17:43:29 -0700 | [diff] [blame] | 6074 | |
| 6075 | // In TLS 1.3, ECDSA does not use the ECDHE curve list. |
| 6076 | testCases = append(testCases, testCase{ |
| 6077 | name: "CheckLeafCurve-TLS13", |
| 6078 | config: Config{ |
| 6079 | MaxVersion: VersionTLS13, |
| 6080 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6081 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 6082 | }, |
| 6083 | flags: []string{"-p384-only"}, |
| 6084 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6085 | |
| 6086 | // In TLS 1.2, the ECDSA curve is not in the signature algorithm. |
| 6087 | testCases = append(testCases, testCase{ |
| 6088 | name: "ECDSACurveMismatch-Verify-TLS12", |
| 6089 | config: Config{ |
| 6090 | MaxVersion: VersionTLS12, |
| 6091 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6092 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6093 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6094 | signatureECDSAWithP384AndSHA384, |
| 6095 | }, |
| 6096 | }, |
| 6097 | }) |
| 6098 | |
| 6099 | // In TLS 1.3, the ECDSA curve comes from the signature algorithm. |
| 6100 | testCases = append(testCases, testCase{ |
| 6101 | name: "ECDSACurveMismatch-Verify-TLS13", |
| 6102 | config: Config{ |
| 6103 | MaxVersion: VersionTLS13, |
| 6104 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6105 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6106 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6107 | signatureECDSAWithP384AndSHA384, |
| 6108 | }, |
| 6109 | Bugs: ProtocolBugs{ |
| 6110 | SkipECDSACurveCheck: true, |
| 6111 | }, |
| 6112 | }, |
| 6113 | shouldFail: true, |
| 6114 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6115 | }) |
| 6116 | |
| 6117 | // Signature algorithm selection in TLS 1.3 should take the curve into |
| 6118 | // account. |
| 6119 | testCases = append(testCases, testCase{ |
| 6120 | testType: serverTest, |
| 6121 | name: "ECDSACurveMismatch-Sign-TLS13", |
| 6122 | config: Config{ |
| 6123 | MaxVersion: VersionTLS13, |
| 6124 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6125 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6126 | signatureECDSAWithP384AndSHA384, |
| 6127 | signatureECDSAWithP256AndSHA256, |
| 6128 | }, |
| 6129 | }, |
| 6130 | flags: []string{ |
| 6131 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 6132 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 6133 | }, |
| 6134 | expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6135 | }) |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 6136 | |
| 6137 | // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the |
| 6138 | // server does not attempt to sign in that case. |
| 6139 | testCases = append(testCases, testCase{ |
| 6140 | testType: serverTest, |
| 6141 | name: "RSA-PSS-Large", |
| 6142 | config: Config{ |
| 6143 | MaxVersion: VersionTLS13, |
| 6144 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6145 | signatureRSAPSSWithSHA512, |
| 6146 | }, |
| 6147 | }, |
| 6148 | flags: []string{ |
| 6149 | "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile), |
| 6150 | "-key-file", path.Join(*resourceDir, rsa1024KeyFile), |
| 6151 | }, |
| 6152 | shouldFail: true, |
| 6153 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6154 | }) |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6155 | } |
| 6156 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6157 | // timeouts is the retransmit schedule for BoringSSL. It doubles and |
| 6158 | // caps at 60 seconds. On the 13th timeout, it gives up. |
| 6159 | var timeouts = []time.Duration{ |
| 6160 | 1 * time.Second, |
| 6161 | 2 * time.Second, |
| 6162 | 4 * time.Second, |
| 6163 | 8 * time.Second, |
| 6164 | 16 * time.Second, |
| 6165 | 32 * time.Second, |
| 6166 | 60 * time.Second, |
| 6167 | 60 * time.Second, |
| 6168 | 60 * time.Second, |
| 6169 | 60 * time.Second, |
| 6170 | 60 * time.Second, |
| 6171 | 60 * time.Second, |
| 6172 | 60 * time.Second, |
| 6173 | } |
| 6174 | |
Taylor Brandstetter | 376a0fe | 2016-05-10 19:30:28 -0700 | [diff] [blame] | 6175 | // shortTimeouts is an alternate set of timeouts which would occur if the |
| 6176 | // initial timeout duration was set to 250ms. |
| 6177 | var shortTimeouts = []time.Duration{ |
| 6178 | 250 * time.Millisecond, |
| 6179 | 500 * time.Millisecond, |
| 6180 | 1 * time.Second, |
| 6181 | 2 * time.Second, |
| 6182 | 4 * time.Second, |
| 6183 | 8 * time.Second, |
| 6184 | 16 * time.Second, |
| 6185 | 32 * time.Second, |
| 6186 | 60 * time.Second, |
| 6187 | 60 * time.Second, |
| 6188 | 60 * time.Second, |
| 6189 | 60 * time.Second, |
| 6190 | 60 * time.Second, |
| 6191 | } |
| 6192 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6193 | func addDTLSRetransmitTests() { |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6194 | // These tests work by coordinating some behavior on both the shim and |
| 6195 | // the runner. |
| 6196 | // |
| 6197 | // TimeoutSchedule configures the runner to send a series of timeout |
| 6198 | // opcodes to the shim (see packetAdaptor) immediately before reading |
| 6199 | // each peer handshake flight N. The timeout opcode both simulates a |
| 6200 | // timeout in the shim and acts as a synchronization point to help the |
| 6201 | // runner bracket each handshake flight. |
| 6202 | // |
| 6203 | // We assume the shim does not read from the channel eagerly. It must |
| 6204 | // first wait until it has sent flight N and is ready to receive |
| 6205 | // handshake flight N+1. At this point, it will process the timeout |
| 6206 | // opcode. It must then immediately respond with a timeout ACK and act |
| 6207 | // as if the shim was idle for the specified amount of time. |
| 6208 | // |
| 6209 | // The runner then drops all packets received before the ACK and |
| 6210 | // continues waiting for flight N. This ordering results in one attempt |
| 6211 | // at sending flight N to be dropped. For the test to complete, the |
| 6212 | // shim must send flight N again, testing that the shim implements DTLS |
| 6213 | // retransmit on a timeout. |
| 6214 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6215 | // TODO(davidben): Add DTLS 1.3 versions of these tests. There will |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6216 | // likely be more epochs to cross and the final message's retransmit may |
| 6217 | // be more complex. |
| 6218 | |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6219 | for _, async := range []bool{true, false} { |
| 6220 | var tests []testCase |
| 6221 | |
| 6222 | // Test that this is indeed the timeout schedule. Stress all |
| 6223 | // four patterns of handshake. |
| 6224 | for i := 1; i < len(timeouts); i++ { |
| 6225 | number := strconv.Itoa(i) |
| 6226 | tests = append(tests, testCase{ |
| 6227 | protocol: dtls, |
| 6228 | name: "DTLS-Retransmit-Client-" + number, |
| 6229 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6230 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6231 | Bugs: ProtocolBugs{ |
| 6232 | TimeoutSchedule: timeouts[:i], |
| 6233 | }, |
| 6234 | }, |
| 6235 | resumeSession: true, |
| 6236 | }) |
| 6237 | tests = append(tests, testCase{ |
| 6238 | protocol: dtls, |
| 6239 | testType: serverTest, |
| 6240 | name: "DTLS-Retransmit-Server-" + number, |
| 6241 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6242 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6243 | Bugs: ProtocolBugs{ |
| 6244 | TimeoutSchedule: timeouts[:i], |
| 6245 | }, |
| 6246 | }, |
| 6247 | resumeSession: true, |
| 6248 | }) |
| 6249 | } |
| 6250 | |
| 6251 | // Test that exceeding the timeout schedule hits a read |
| 6252 | // timeout. |
| 6253 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6254 | protocol: dtls, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6255 | name: "DTLS-Retransmit-Timeout", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6256 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6257 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6258 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6259 | TimeoutSchedule: timeouts, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6260 | }, |
| 6261 | }, |
| 6262 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6263 | shouldFail: true, |
| 6264 | expectedError: ":READ_TIMEOUT_EXPIRED:", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6265 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6266 | |
| 6267 | if async { |
| 6268 | // Test that timeout handling has a fudge factor, due to API |
| 6269 | // problems. |
| 6270 | tests = append(tests, testCase{ |
| 6271 | protocol: dtls, |
| 6272 | name: "DTLS-Retransmit-Fudge", |
| 6273 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6274 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6275 | Bugs: ProtocolBugs{ |
| 6276 | TimeoutSchedule: []time.Duration{ |
| 6277 | timeouts[0] - 10*time.Millisecond, |
| 6278 | }, |
| 6279 | }, |
| 6280 | }, |
| 6281 | resumeSession: true, |
| 6282 | }) |
| 6283 | } |
| 6284 | |
| 6285 | // Test that the final Finished retransmitting isn't |
| 6286 | // duplicated if the peer badly fragments everything. |
| 6287 | tests = append(tests, testCase{ |
| 6288 | testType: serverTest, |
| 6289 | protocol: dtls, |
| 6290 | name: "DTLS-Retransmit-Fragmented", |
| 6291 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6292 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6293 | Bugs: ProtocolBugs{ |
| 6294 | TimeoutSchedule: []time.Duration{timeouts[0]}, |
| 6295 | MaxHandshakeRecordLength: 2, |
| 6296 | }, |
| 6297 | }, |
| 6298 | }) |
| 6299 | |
| 6300 | // Test the timeout schedule when a shorter initial timeout duration is set. |
| 6301 | tests = append(tests, testCase{ |
| 6302 | protocol: dtls, |
| 6303 | name: "DTLS-Retransmit-Short-Client", |
| 6304 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6305 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6306 | Bugs: ProtocolBugs{ |
| 6307 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
| 6308 | }, |
| 6309 | }, |
| 6310 | resumeSession: true, |
| 6311 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
| 6312 | }) |
| 6313 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6314 | protocol: dtls, |
| 6315 | testType: serverTest, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6316 | name: "DTLS-Retransmit-Short-Server", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6317 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6318 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6319 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6320 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6321 | }, |
| 6322 | }, |
| 6323 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6324 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6325 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6326 | |
| 6327 | for _, test := range tests { |
| 6328 | if async { |
| 6329 | test.name += "-Async" |
| 6330 | test.flags = append(test.flags, "-async") |
| 6331 | } |
| 6332 | |
| 6333 | testCases = append(testCases, test) |
| 6334 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6335 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6336 | } |
| 6337 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 6338 | func addExportKeyingMaterialTests() { |
| 6339 | for _, vers := range tlsVersions { |
| 6340 | if vers.version == VersionSSL30 { |
| 6341 | continue |
| 6342 | } |
| 6343 | testCases = append(testCases, testCase{ |
| 6344 | name: "ExportKeyingMaterial-" + vers.name, |
| 6345 | config: Config{ |
| 6346 | MaxVersion: vers.version, |
| 6347 | }, |
| 6348 | exportKeyingMaterial: 1024, |
| 6349 | exportLabel: "label", |
| 6350 | exportContext: "context", |
| 6351 | useExportContext: true, |
| 6352 | }) |
| 6353 | testCases = append(testCases, testCase{ |
| 6354 | name: "ExportKeyingMaterial-NoContext-" + vers.name, |
| 6355 | config: Config{ |
| 6356 | MaxVersion: vers.version, |
| 6357 | }, |
| 6358 | exportKeyingMaterial: 1024, |
| 6359 | }) |
| 6360 | testCases = append(testCases, testCase{ |
| 6361 | name: "ExportKeyingMaterial-EmptyContext-" + vers.name, |
| 6362 | config: Config{ |
| 6363 | MaxVersion: vers.version, |
| 6364 | }, |
| 6365 | exportKeyingMaterial: 1024, |
| 6366 | useExportContext: true, |
| 6367 | }) |
| 6368 | testCases = append(testCases, testCase{ |
| 6369 | name: "ExportKeyingMaterial-Small-" + vers.name, |
| 6370 | config: Config{ |
| 6371 | MaxVersion: vers.version, |
| 6372 | }, |
| 6373 | exportKeyingMaterial: 1, |
| 6374 | exportLabel: "label", |
| 6375 | exportContext: "context", |
| 6376 | useExportContext: true, |
| 6377 | }) |
| 6378 | } |
| 6379 | testCases = append(testCases, testCase{ |
| 6380 | name: "ExportKeyingMaterial-SSL3", |
| 6381 | config: Config{ |
| 6382 | MaxVersion: VersionSSL30, |
| 6383 | }, |
| 6384 | exportKeyingMaterial: 1024, |
| 6385 | exportLabel: "label", |
| 6386 | exportContext: "context", |
| 6387 | useExportContext: true, |
| 6388 | shouldFail: true, |
| 6389 | expectedError: "failed to export keying material", |
| 6390 | }) |
| 6391 | } |
| 6392 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6393 | func addTLSUniqueTests() { |
| 6394 | for _, isClient := range []bool{false, true} { |
| 6395 | for _, isResumption := range []bool{false, true} { |
| 6396 | for _, hasEMS := range []bool{false, true} { |
| 6397 | var suffix string |
| 6398 | if isResumption { |
| 6399 | suffix = "Resume-" |
| 6400 | } else { |
| 6401 | suffix = "Full-" |
| 6402 | } |
| 6403 | |
| 6404 | if hasEMS { |
| 6405 | suffix += "EMS-" |
| 6406 | } else { |
| 6407 | suffix += "NoEMS-" |
| 6408 | } |
| 6409 | |
| 6410 | if isClient { |
| 6411 | suffix += "Client" |
| 6412 | } else { |
| 6413 | suffix += "Server" |
| 6414 | } |
| 6415 | |
| 6416 | test := testCase{ |
| 6417 | name: "TLSUnique-" + suffix, |
| 6418 | testTLSUnique: true, |
| 6419 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6420 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6421 | Bugs: ProtocolBugs{ |
| 6422 | NoExtendedMasterSecret: !hasEMS, |
| 6423 | }, |
| 6424 | }, |
| 6425 | } |
| 6426 | |
| 6427 | if isResumption { |
| 6428 | test.resumeSession = true |
| 6429 | test.resumeConfig = &Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6430 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6431 | Bugs: ProtocolBugs{ |
| 6432 | NoExtendedMasterSecret: !hasEMS, |
| 6433 | }, |
| 6434 | } |
| 6435 | } |
| 6436 | |
| 6437 | if isResumption && !hasEMS { |
| 6438 | test.shouldFail = true |
| 6439 | test.expectedError = "failed to get tls-unique" |
| 6440 | } |
| 6441 | |
| 6442 | testCases = append(testCases, test) |
| 6443 | } |
| 6444 | } |
| 6445 | } |
| 6446 | } |
| 6447 | |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6448 | func addCustomExtensionTests() { |
| 6449 | expectedContents := "custom extension" |
| 6450 | emptyString := "" |
| 6451 | |
| 6452 | for _, isClient := range []bool{false, true} { |
| 6453 | suffix := "Server" |
| 6454 | flag := "-enable-server-custom-extension" |
| 6455 | testType := serverTest |
| 6456 | if isClient { |
| 6457 | suffix = "Client" |
| 6458 | flag = "-enable-client-custom-extension" |
| 6459 | testType = clientTest |
| 6460 | } |
| 6461 | |
| 6462 | testCases = append(testCases, testCase{ |
| 6463 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6464 | name: "CustomExtensions-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6465 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6466 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6467 | Bugs: ProtocolBugs{ |
| 6468 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6469 | ExpectedCustomExtension: &expectedContents, |
| 6470 | }, |
| 6471 | }, |
| 6472 | flags: []string{flag}, |
| 6473 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6474 | testCases = append(testCases, testCase{ |
| 6475 | testType: testType, |
| 6476 | name: "CustomExtensions-" + suffix + "-TLS13", |
| 6477 | config: Config{ |
| 6478 | MaxVersion: VersionTLS13, |
| 6479 | Bugs: ProtocolBugs{ |
| 6480 | CustomExtension: expectedContents, |
| 6481 | ExpectedCustomExtension: &expectedContents, |
| 6482 | }, |
| 6483 | }, |
| 6484 | flags: []string{flag}, |
| 6485 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6486 | |
| 6487 | // If the parse callback fails, the handshake should also fail. |
| 6488 | testCases = append(testCases, testCase{ |
| 6489 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6490 | name: "CustomExtensions-ParseError-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6491 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6492 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6493 | Bugs: ProtocolBugs{ |
| 6494 | CustomExtension: expectedContents + "foo", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6495 | ExpectedCustomExtension: &expectedContents, |
| 6496 | }, |
| 6497 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6498 | flags: []string{flag}, |
| 6499 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6500 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6501 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6502 | testCases = append(testCases, testCase{ |
| 6503 | testType: testType, |
| 6504 | name: "CustomExtensions-ParseError-" + suffix + "-TLS13", |
| 6505 | config: Config{ |
| 6506 | MaxVersion: VersionTLS13, |
| 6507 | Bugs: ProtocolBugs{ |
| 6508 | CustomExtension: expectedContents + "foo", |
| 6509 | ExpectedCustomExtension: &expectedContents, |
| 6510 | }, |
| 6511 | }, |
| 6512 | flags: []string{flag}, |
| 6513 | shouldFail: true, |
| 6514 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6515 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6516 | |
| 6517 | // If the add callback fails, the handshake should also fail. |
| 6518 | testCases = append(testCases, testCase{ |
| 6519 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6520 | name: "CustomExtensions-FailAdd-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6521 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6522 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6523 | Bugs: ProtocolBugs{ |
| 6524 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6525 | ExpectedCustomExtension: &expectedContents, |
| 6526 | }, |
| 6527 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6528 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 6529 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6530 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6531 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6532 | testCases = append(testCases, testCase{ |
| 6533 | testType: testType, |
| 6534 | name: "CustomExtensions-FailAdd-" + suffix + "-TLS13", |
| 6535 | config: Config{ |
| 6536 | MaxVersion: VersionTLS13, |
| 6537 | Bugs: ProtocolBugs{ |
| 6538 | CustomExtension: expectedContents, |
| 6539 | ExpectedCustomExtension: &expectedContents, |
| 6540 | }, |
| 6541 | }, |
| 6542 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 6543 | shouldFail: true, |
| 6544 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6545 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6546 | |
| 6547 | // If the add callback returns zero, no extension should be |
| 6548 | // added. |
| 6549 | skipCustomExtension := expectedContents |
| 6550 | if isClient { |
| 6551 | // For the case where the client skips sending the |
| 6552 | // custom extension, the server must not “echo” it. |
| 6553 | skipCustomExtension = "" |
| 6554 | } |
| 6555 | testCases = append(testCases, testCase{ |
| 6556 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6557 | name: "CustomExtensions-Skip-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6558 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6559 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6560 | Bugs: ProtocolBugs{ |
| 6561 | CustomExtension: skipCustomExtension, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6562 | ExpectedCustomExtension: &emptyString, |
| 6563 | }, |
| 6564 | }, |
| 6565 | flags: []string{flag, "-custom-extension-skip"}, |
| 6566 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6567 | testCases = append(testCases, testCase{ |
| 6568 | testType: testType, |
| 6569 | name: "CustomExtensions-Skip-" + suffix + "-TLS13", |
| 6570 | config: Config{ |
| 6571 | MaxVersion: VersionTLS13, |
| 6572 | Bugs: ProtocolBugs{ |
| 6573 | CustomExtension: skipCustomExtension, |
| 6574 | ExpectedCustomExtension: &emptyString, |
| 6575 | }, |
| 6576 | }, |
| 6577 | flags: []string{flag, "-custom-extension-skip"}, |
| 6578 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6579 | } |
| 6580 | |
| 6581 | // The custom extension add callback should not be called if the client |
| 6582 | // doesn't send the extension. |
| 6583 | testCases = append(testCases, testCase{ |
| 6584 | testType: serverTest, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6585 | name: "CustomExtensions-NotCalled-Server", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6586 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6587 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6588 | Bugs: ProtocolBugs{ |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6589 | ExpectedCustomExtension: &emptyString, |
| 6590 | }, |
| 6591 | }, |
| 6592 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 6593 | }) |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6594 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6595 | testCases = append(testCases, testCase{ |
| 6596 | testType: serverTest, |
| 6597 | name: "CustomExtensions-NotCalled-Server-TLS13", |
| 6598 | config: Config{ |
| 6599 | MaxVersion: VersionTLS13, |
| 6600 | Bugs: ProtocolBugs{ |
| 6601 | ExpectedCustomExtension: &emptyString, |
| 6602 | }, |
| 6603 | }, |
| 6604 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 6605 | }) |
| 6606 | |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6607 | // Test an unknown extension from the server. |
| 6608 | testCases = append(testCases, testCase{ |
| 6609 | testType: clientTest, |
| 6610 | name: "UnknownExtension-Client", |
| 6611 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6612 | MaxVersion: VersionTLS12, |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6613 | Bugs: ProtocolBugs{ |
| 6614 | CustomExtension: expectedContents, |
| 6615 | }, |
| 6616 | }, |
David Benjamin | 0c40a96 | 2016-08-01 12:05:50 -0400 | [diff] [blame] | 6617 | shouldFail: true, |
| 6618 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6619 | expectedLocalError: "remote error: unsupported extension", |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6620 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6621 | testCases = append(testCases, testCase{ |
| 6622 | testType: clientTest, |
| 6623 | name: "UnknownExtension-Client-TLS13", |
| 6624 | config: Config{ |
| 6625 | MaxVersion: VersionTLS13, |
| 6626 | Bugs: ProtocolBugs{ |
| 6627 | CustomExtension: expectedContents, |
| 6628 | }, |
| 6629 | }, |
David Benjamin | 0c40a96 | 2016-08-01 12:05:50 -0400 | [diff] [blame] | 6630 | shouldFail: true, |
| 6631 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6632 | expectedLocalError: "remote error: unsupported extension", |
| 6633 | }) |
| 6634 | |
| 6635 | // Test a known but unoffered extension from the server. |
| 6636 | testCases = append(testCases, testCase{ |
| 6637 | testType: clientTest, |
| 6638 | name: "UnofferedExtension-Client", |
| 6639 | config: Config{ |
| 6640 | MaxVersion: VersionTLS12, |
| 6641 | Bugs: ProtocolBugs{ |
| 6642 | SendALPN: "alpn", |
| 6643 | }, |
| 6644 | }, |
| 6645 | shouldFail: true, |
| 6646 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6647 | expectedLocalError: "remote error: unsupported extension", |
| 6648 | }) |
| 6649 | testCases = append(testCases, testCase{ |
| 6650 | testType: clientTest, |
| 6651 | name: "UnofferedExtension-Client-TLS13", |
| 6652 | config: Config{ |
| 6653 | MaxVersion: VersionTLS13, |
| 6654 | Bugs: ProtocolBugs{ |
| 6655 | SendALPN: "alpn", |
| 6656 | }, |
| 6657 | }, |
| 6658 | shouldFail: true, |
| 6659 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6660 | expectedLocalError: "remote error: unsupported extension", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6661 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6662 | } |
| 6663 | |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 6664 | func addRSAClientKeyExchangeTests() { |
| 6665 | for bad := RSABadValue(1); bad < NumRSABadValues; bad++ { |
| 6666 | testCases = append(testCases, testCase{ |
| 6667 | testType: serverTest, |
| 6668 | name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad), |
| 6669 | config: Config{ |
| 6670 | // Ensure the ClientHello version and final |
| 6671 | // version are different, to detect if the |
| 6672 | // server uses the wrong one. |
| 6673 | MaxVersion: VersionTLS11, |
| 6674 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 6675 | Bugs: ProtocolBugs{ |
| 6676 | BadRSAClientKeyExchange: bad, |
| 6677 | }, |
| 6678 | }, |
| 6679 | shouldFail: true, |
| 6680 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6681 | }) |
| 6682 | } |
| 6683 | } |
| 6684 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6685 | var testCurves = []struct { |
| 6686 | name string |
| 6687 | id CurveID |
| 6688 | }{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6689 | {"P-256", CurveP256}, |
| 6690 | {"P-384", CurveP384}, |
| 6691 | {"P-521", CurveP521}, |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 6692 | {"X25519", CurveX25519}, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6693 | } |
| 6694 | |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6695 | const bogusCurve = 0x1234 |
| 6696 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6697 | func addCurveTests() { |
| 6698 | for _, curve := range testCurves { |
| 6699 | testCases = append(testCases, testCase{ |
| 6700 | name: "CurveTest-Client-" + curve.name, |
| 6701 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6702 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6703 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6704 | CurvePreferences: []CurveID{curve.id}, |
| 6705 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6706 | flags: []string{"-enable-all-curves"}, |
| 6707 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6708 | }) |
| 6709 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6710 | name: "CurveTest-Client-" + curve.name + "-TLS13", |
| 6711 | config: Config{ |
| 6712 | MaxVersion: VersionTLS13, |
| 6713 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6714 | CurvePreferences: []CurveID{curve.id}, |
| 6715 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6716 | flags: []string{"-enable-all-curves"}, |
| 6717 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6718 | }) |
| 6719 | testCases = append(testCases, testCase{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6720 | testType: serverTest, |
| 6721 | name: "CurveTest-Server-" + curve.name, |
| 6722 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6723 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6724 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6725 | CurvePreferences: []CurveID{curve.id}, |
| 6726 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6727 | flags: []string{"-enable-all-curves"}, |
| 6728 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6729 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6730 | testCases = append(testCases, testCase{ |
| 6731 | testType: serverTest, |
| 6732 | name: "CurveTest-Server-" + curve.name + "-TLS13", |
| 6733 | config: Config{ |
| 6734 | MaxVersion: VersionTLS13, |
| 6735 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6736 | CurvePreferences: []CurveID{curve.id}, |
| 6737 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6738 | flags: []string{"-enable-all-curves"}, |
| 6739 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6740 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6741 | } |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 6742 | |
| 6743 | // The server must be tolerant to bogus curves. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 6744 | testCases = append(testCases, testCase{ |
| 6745 | testType: serverTest, |
| 6746 | name: "UnknownCurve", |
| 6747 | config: Config{ |
| 6748 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6749 | CurvePreferences: []CurveID{bogusCurve, CurveP256}, |
| 6750 | }, |
| 6751 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6752 | |
| 6753 | // The server must not consider ECDHE ciphers when there are no |
| 6754 | // supported curves. |
| 6755 | testCases = append(testCases, testCase{ |
| 6756 | testType: serverTest, |
| 6757 | name: "NoSupportedCurves", |
| 6758 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6759 | MaxVersion: VersionTLS12, |
| 6760 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6761 | Bugs: ProtocolBugs{ |
| 6762 | NoSupportedCurves: true, |
| 6763 | }, |
| 6764 | }, |
| 6765 | shouldFail: true, |
| 6766 | expectedError: ":NO_SHARED_CIPHER:", |
| 6767 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6768 | testCases = append(testCases, testCase{ |
| 6769 | testType: serverTest, |
| 6770 | name: "NoSupportedCurves-TLS13", |
| 6771 | config: Config{ |
| 6772 | MaxVersion: VersionTLS13, |
| 6773 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6774 | Bugs: ProtocolBugs{ |
| 6775 | NoSupportedCurves: true, |
| 6776 | }, |
| 6777 | }, |
| 6778 | shouldFail: true, |
| 6779 | expectedError: ":NO_SHARED_CIPHER:", |
| 6780 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6781 | |
| 6782 | // The server must fall back to another cipher when there are no |
| 6783 | // supported curves. |
| 6784 | testCases = append(testCases, testCase{ |
| 6785 | testType: serverTest, |
| 6786 | name: "NoCommonCurves", |
| 6787 | config: Config{ |
| 6788 | MaxVersion: VersionTLS12, |
| 6789 | CipherSuites: []uint16{ |
| 6790 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6791 | TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6792 | }, |
| 6793 | CurvePreferences: []CurveID{CurveP224}, |
| 6794 | }, |
| 6795 | expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6796 | }) |
| 6797 | |
| 6798 | // The client must reject bogus curves and disabled curves. |
| 6799 | testCases = append(testCases, testCase{ |
| 6800 | name: "BadECDHECurve", |
| 6801 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6802 | MaxVersion: VersionTLS12, |
| 6803 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6804 | Bugs: ProtocolBugs{ |
| 6805 | SendCurve: bogusCurve, |
| 6806 | }, |
| 6807 | }, |
| 6808 | shouldFail: true, |
| 6809 | expectedError: ":WRONG_CURVE:", |
| 6810 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6811 | testCases = append(testCases, testCase{ |
| 6812 | name: "BadECDHECurve-TLS13", |
| 6813 | config: Config{ |
| 6814 | MaxVersion: VersionTLS13, |
| 6815 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6816 | Bugs: ProtocolBugs{ |
| 6817 | SendCurve: bogusCurve, |
| 6818 | }, |
| 6819 | }, |
| 6820 | shouldFail: true, |
| 6821 | expectedError: ":WRONG_CURVE:", |
| 6822 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6823 | |
| 6824 | testCases = append(testCases, testCase{ |
| 6825 | name: "UnsupportedCurve", |
| 6826 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6827 | MaxVersion: VersionTLS12, |
| 6828 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6829 | CurvePreferences: []CurveID{CurveP256}, |
| 6830 | Bugs: ProtocolBugs{ |
| 6831 | IgnorePeerCurvePreferences: true, |
| 6832 | }, |
| 6833 | }, |
| 6834 | flags: []string{"-p384-only"}, |
| 6835 | shouldFail: true, |
| 6836 | expectedError: ":WRONG_CURVE:", |
| 6837 | }) |
| 6838 | |
David Benjamin | 4f92157 | 2016-07-17 14:20:10 +0200 | [diff] [blame] | 6839 | testCases = append(testCases, testCase{ |
| 6840 | // TODO(davidben): Add a TLS 1.3 version where |
| 6841 | // HelloRetryRequest requests an unsupported curve. |
| 6842 | name: "UnsupportedCurve-ServerHello-TLS13", |
| 6843 | config: Config{ |
| 6844 | MaxVersion: VersionTLS12, |
| 6845 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6846 | CurvePreferences: []CurveID{CurveP384}, |
| 6847 | Bugs: ProtocolBugs{ |
| 6848 | SendCurve: CurveP256, |
| 6849 | }, |
| 6850 | }, |
| 6851 | flags: []string{"-p384-only"}, |
| 6852 | shouldFail: true, |
| 6853 | expectedError: ":WRONG_CURVE:", |
| 6854 | }) |
| 6855 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6856 | // Test invalid curve points. |
| 6857 | testCases = append(testCases, testCase{ |
| 6858 | name: "InvalidECDHPoint-Client", |
| 6859 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6860 | MaxVersion: VersionTLS12, |
| 6861 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6862 | CurvePreferences: []CurveID{CurveP256}, |
| 6863 | Bugs: ProtocolBugs{ |
| 6864 | InvalidECDHPoint: true, |
| 6865 | }, |
| 6866 | }, |
| 6867 | shouldFail: true, |
| 6868 | expectedError: ":INVALID_ENCODING:", |
| 6869 | }) |
| 6870 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6871 | name: "InvalidECDHPoint-Client-TLS13", |
| 6872 | config: Config{ |
| 6873 | MaxVersion: VersionTLS13, |
| 6874 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6875 | CurvePreferences: []CurveID{CurveP256}, |
| 6876 | Bugs: ProtocolBugs{ |
| 6877 | InvalidECDHPoint: true, |
| 6878 | }, |
| 6879 | }, |
| 6880 | shouldFail: true, |
| 6881 | expectedError: ":INVALID_ENCODING:", |
| 6882 | }) |
| 6883 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6884 | testType: serverTest, |
| 6885 | name: "InvalidECDHPoint-Server", |
| 6886 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6887 | MaxVersion: VersionTLS12, |
| 6888 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6889 | CurvePreferences: []CurveID{CurveP256}, |
| 6890 | Bugs: ProtocolBugs{ |
| 6891 | InvalidECDHPoint: true, |
| 6892 | }, |
| 6893 | }, |
| 6894 | shouldFail: true, |
| 6895 | expectedError: ":INVALID_ENCODING:", |
| 6896 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6897 | testCases = append(testCases, testCase{ |
| 6898 | testType: serverTest, |
| 6899 | name: "InvalidECDHPoint-Server-TLS13", |
| 6900 | config: Config{ |
| 6901 | MaxVersion: VersionTLS13, |
| 6902 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6903 | CurvePreferences: []CurveID{CurveP256}, |
| 6904 | Bugs: ProtocolBugs{ |
| 6905 | InvalidECDHPoint: true, |
| 6906 | }, |
| 6907 | }, |
| 6908 | shouldFail: true, |
| 6909 | expectedError: ":INVALID_ENCODING:", |
| 6910 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6911 | } |
| 6912 | |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6913 | func addCECPQ1Tests() { |
| 6914 | testCases = append(testCases, testCase{ |
| 6915 | testType: clientTest, |
| 6916 | name: "CECPQ1-Client-BadX25519Part", |
| 6917 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6918 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6919 | MinVersion: VersionTLS12, |
| 6920 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6921 | Bugs: ProtocolBugs{ |
| 6922 | CECPQ1BadX25519Part: true, |
| 6923 | }, |
| 6924 | }, |
| 6925 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6926 | shouldFail: true, |
| 6927 | expectedLocalError: "local error: bad record MAC", |
| 6928 | }) |
| 6929 | testCases = append(testCases, testCase{ |
| 6930 | testType: clientTest, |
| 6931 | name: "CECPQ1-Client-BadNewhopePart", |
| 6932 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6933 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6934 | MinVersion: VersionTLS12, |
| 6935 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6936 | Bugs: ProtocolBugs{ |
| 6937 | CECPQ1BadNewhopePart: true, |
| 6938 | }, |
| 6939 | }, |
| 6940 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6941 | shouldFail: true, |
| 6942 | expectedLocalError: "local error: bad record MAC", |
| 6943 | }) |
| 6944 | testCases = append(testCases, testCase{ |
| 6945 | testType: serverTest, |
| 6946 | name: "CECPQ1-Server-BadX25519Part", |
| 6947 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6948 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6949 | MinVersion: VersionTLS12, |
| 6950 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6951 | Bugs: ProtocolBugs{ |
| 6952 | CECPQ1BadX25519Part: true, |
| 6953 | }, |
| 6954 | }, |
| 6955 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6956 | shouldFail: true, |
| 6957 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6958 | }) |
| 6959 | testCases = append(testCases, testCase{ |
| 6960 | testType: serverTest, |
| 6961 | name: "CECPQ1-Server-BadNewhopePart", |
| 6962 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6963 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6964 | MinVersion: VersionTLS12, |
| 6965 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6966 | Bugs: ProtocolBugs{ |
| 6967 | CECPQ1BadNewhopePart: true, |
| 6968 | }, |
| 6969 | }, |
| 6970 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6971 | shouldFail: true, |
| 6972 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6973 | }) |
| 6974 | } |
| 6975 | |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6976 | func addKeyExchangeInfoTests() { |
| 6977 | testCases = append(testCases, testCase{ |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6978 | name: "KeyExchangeInfo-DHE-Client", |
| 6979 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6980 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6981 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6982 | Bugs: ProtocolBugs{ |
| 6983 | // This is a 1234-bit prime number, generated |
| 6984 | // with: |
| 6985 | // openssl gendh 1234 | openssl asn1parse -i |
| 6986 | DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"), |
| 6987 | }, |
| 6988 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 6989 | flags: []string{"-expect-dhe-group-size", "1234"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6990 | }) |
| 6991 | testCases = append(testCases, testCase{ |
| 6992 | testType: serverTest, |
| 6993 | name: "KeyExchangeInfo-DHE-Server", |
| 6994 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6995 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6996 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6997 | }, |
| 6998 | // bssl_shim as a server configures a 2048-bit DHE group. |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 6999 | flags: []string{"-expect-dhe-group-size", "2048"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7000 | }) |
| 7001 | |
| 7002 | testCases = append(testCases, testCase{ |
| 7003 | name: "KeyExchangeInfo-ECDHE-Client", |
| 7004 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7005 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7006 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7007 | CurvePreferences: []CurveID{CurveX25519}, |
| 7008 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 7009 | flags: []string{"-expect-curve-id", "29", "-enable-all-curves"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7010 | }) |
| 7011 | testCases = append(testCases, testCase{ |
| 7012 | testType: serverTest, |
| 7013 | name: "KeyExchangeInfo-ECDHE-Server", |
| 7014 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7015 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7016 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7017 | CurvePreferences: []CurveID{CurveX25519}, |
| 7018 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 7019 | flags: []string{"-expect-curve-id", "29", "-enable-all-curves"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7020 | }) |
| 7021 | } |
| 7022 | |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 7023 | func addTLS13RecordTests() { |
| 7024 | testCases = append(testCases, testCase{ |
| 7025 | name: "TLS13-RecordPadding", |
| 7026 | config: Config{ |
| 7027 | MaxVersion: VersionTLS13, |
| 7028 | MinVersion: VersionTLS13, |
| 7029 | Bugs: ProtocolBugs{ |
| 7030 | RecordPadding: 10, |
| 7031 | }, |
| 7032 | }, |
| 7033 | }) |
| 7034 | |
| 7035 | testCases = append(testCases, testCase{ |
| 7036 | name: "TLS13-EmptyRecords", |
| 7037 | config: Config{ |
| 7038 | MaxVersion: VersionTLS13, |
| 7039 | MinVersion: VersionTLS13, |
| 7040 | Bugs: ProtocolBugs{ |
| 7041 | OmitRecordContents: true, |
| 7042 | }, |
| 7043 | }, |
| 7044 | shouldFail: true, |
| 7045 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7046 | }) |
| 7047 | |
| 7048 | testCases = append(testCases, testCase{ |
| 7049 | name: "TLS13-OnlyPadding", |
| 7050 | config: Config{ |
| 7051 | MaxVersion: VersionTLS13, |
| 7052 | MinVersion: VersionTLS13, |
| 7053 | Bugs: ProtocolBugs{ |
| 7054 | OmitRecordContents: true, |
| 7055 | RecordPadding: 10, |
| 7056 | }, |
| 7057 | }, |
| 7058 | shouldFail: true, |
| 7059 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7060 | }) |
| 7061 | |
| 7062 | testCases = append(testCases, testCase{ |
| 7063 | name: "TLS13-WrongOuterRecord", |
| 7064 | config: Config{ |
| 7065 | MaxVersion: VersionTLS13, |
| 7066 | MinVersion: VersionTLS13, |
| 7067 | Bugs: ProtocolBugs{ |
| 7068 | OuterRecordType: recordTypeHandshake, |
| 7069 | }, |
| 7070 | }, |
| 7071 | shouldFail: true, |
| 7072 | expectedError: ":INVALID_OUTER_RECORD_TYPE:", |
| 7073 | }) |
| 7074 | } |
| 7075 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7076 | func addChangeCipherSpecTests() { |
| 7077 | // Test missing ChangeCipherSpecs. |
| 7078 | testCases = append(testCases, testCase{ |
| 7079 | name: "SkipChangeCipherSpec-Client", |
| 7080 | config: Config{ |
| 7081 | MaxVersion: VersionTLS12, |
| 7082 | Bugs: ProtocolBugs{ |
| 7083 | SkipChangeCipherSpec: true, |
| 7084 | }, |
| 7085 | }, |
| 7086 | shouldFail: true, |
| 7087 | expectedError: ":UNEXPECTED_RECORD:", |
| 7088 | }) |
| 7089 | testCases = append(testCases, testCase{ |
| 7090 | testType: serverTest, |
| 7091 | name: "SkipChangeCipherSpec-Server", |
| 7092 | config: Config{ |
| 7093 | MaxVersion: VersionTLS12, |
| 7094 | Bugs: ProtocolBugs{ |
| 7095 | SkipChangeCipherSpec: true, |
| 7096 | }, |
| 7097 | }, |
| 7098 | shouldFail: true, |
| 7099 | expectedError: ":UNEXPECTED_RECORD:", |
| 7100 | }) |
| 7101 | testCases = append(testCases, testCase{ |
| 7102 | testType: serverTest, |
| 7103 | name: "SkipChangeCipherSpec-Server-NPN", |
| 7104 | config: Config{ |
| 7105 | MaxVersion: VersionTLS12, |
| 7106 | NextProtos: []string{"bar"}, |
| 7107 | Bugs: ProtocolBugs{ |
| 7108 | SkipChangeCipherSpec: true, |
| 7109 | }, |
| 7110 | }, |
| 7111 | flags: []string{ |
| 7112 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 7113 | }, |
| 7114 | shouldFail: true, |
| 7115 | expectedError: ":UNEXPECTED_RECORD:", |
| 7116 | }) |
| 7117 | |
| 7118 | // Test synchronization between the handshake and ChangeCipherSpec. |
| 7119 | // Partial post-CCS handshake messages before ChangeCipherSpec should be |
| 7120 | // rejected. Test both with and without handshake packing to handle both |
| 7121 | // when the partial post-CCS message is in its own record and when it is |
| 7122 | // attached to the pre-CCS message. |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7123 | for _, packed := range []bool{false, true} { |
| 7124 | var suffix string |
| 7125 | if packed { |
| 7126 | suffix = "-Packed" |
| 7127 | } |
| 7128 | |
| 7129 | testCases = append(testCases, testCase{ |
| 7130 | name: "FragmentAcrossChangeCipherSpec-Client" + suffix, |
| 7131 | config: Config{ |
| 7132 | MaxVersion: VersionTLS12, |
| 7133 | Bugs: ProtocolBugs{ |
| 7134 | FragmentAcrossChangeCipherSpec: true, |
| 7135 | PackHandshakeFlight: packed, |
| 7136 | }, |
| 7137 | }, |
| 7138 | shouldFail: true, |
| 7139 | expectedError: ":UNEXPECTED_RECORD:", |
| 7140 | }) |
| 7141 | testCases = append(testCases, testCase{ |
| 7142 | name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix, |
| 7143 | config: Config{ |
| 7144 | MaxVersion: VersionTLS12, |
| 7145 | }, |
| 7146 | resumeSession: true, |
| 7147 | resumeConfig: &Config{ |
| 7148 | MaxVersion: VersionTLS12, |
| 7149 | Bugs: ProtocolBugs{ |
| 7150 | FragmentAcrossChangeCipherSpec: true, |
| 7151 | PackHandshakeFlight: packed, |
| 7152 | }, |
| 7153 | }, |
| 7154 | shouldFail: true, |
| 7155 | expectedError: ":UNEXPECTED_RECORD:", |
| 7156 | }) |
| 7157 | testCases = append(testCases, testCase{ |
| 7158 | testType: serverTest, |
| 7159 | name: "FragmentAcrossChangeCipherSpec-Server" + suffix, |
| 7160 | config: Config{ |
| 7161 | MaxVersion: VersionTLS12, |
| 7162 | Bugs: ProtocolBugs{ |
| 7163 | FragmentAcrossChangeCipherSpec: true, |
| 7164 | PackHandshakeFlight: packed, |
| 7165 | }, |
| 7166 | }, |
| 7167 | shouldFail: true, |
| 7168 | expectedError: ":UNEXPECTED_RECORD:", |
| 7169 | }) |
| 7170 | testCases = append(testCases, testCase{ |
| 7171 | testType: serverTest, |
| 7172 | name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix, |
| 7173 | config: Config{ |
| 7174 | MaxVersion: VersionTLS12, |
| 7175 | }, |
| 7176 | resumeSession: true, |
| 7177 | resumeConfig: &Config{ |
| 7178 | MaxVersion: VersionTLS12, |
| 7179 | Bugs: ProtocolBugs{ |
| 7180 | FragmentAcrossChangeCipherSpec: true, |
| 7181 | PackHandshakeFlight: packed, |
| 7182 | }, |
| 7183 | }, |
| 7184 | shouldFail: true, |
| 7185 | expectedError: ":UNEXPECTED_RECORD:", |
| 7186 | }) |
| 7187 | testCases = append(testCases, testCase{ |
| 7188 | testType: serverTest, |
| 7189 | name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix, |
| 7190 | config: Config{ |
| 7191 | MaxVersion: VersionTLS12, |
| 7192 | NextProtos: []string{"bar"}, |
| 7193 | Bugs: ProtocolBugs{ |
| 7194 | FragmentAcrossChangeCipherSpec: true, |
| 7195 | PackHandshakeFlight: packed, |
| 7196 | }, |
| 7197 | }, |
| 7198 | flags: []string{ |
| 7199 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 7200 | }, |
| 7201 | shouldFail: true, |
| 7202 | expectedError: ":UNEXPECTED_RECORD:", |
| 7203 | }) |
| 7204 | } |
| 7205 | |
David Benjamin | 6167281 | 2016-07-14 23:10:43 -0400 | [diff] [blame] | 7206 | // Test that, in DTLS, ChangeCipherSpec is not allowed when there are |
| 7207 | // messages in the handshake queue. Do this by testing the server |
| 7208 | // reading the client Finished, reversing the flight so Finished comes |
| 7209 | // first. |
| 7210 | testCases = append(testCases, testCase{ |
| 7211 | protocol: dtls, |
| 7212 | testType: serverTest, |
| 7213 | name: "SendUnencryptedFinished-DTLS", |
| 7214 | config: Config{ |
| 7215 | MaxVersion: VersionTLS12, |
| 7216 | Bugs: ProtocolBugs{ |
| 7217 | SendUnencryptedFinished: true, |
| 7218 | ReverseHandshakeFragments: true, |
| 7219 | }, |
| 7220 | }, |
| 7221 | shouldFail: true, |
| 7222 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7223 | }) |
| 7224 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7225 | // Test synchronization between encryption changes and the handshake in |
| 7226 | // TLS 1.3, where ChangeCipherSpec is implicit. |
| 7227 | testCases = append(testCases, testCase{ |
| 7228 | name: "PartialEncryptedExtensionsWithServerHello", |
| 7229 | config: Config{ |
| 7230 | MaxVersion: VersionTLS13, |
| 7231 | Bugs: ProtocolBugs{ |
| 7232 | PartialEncryptedExtensionsWithServerHello: true, |
| 7233 | }, |
| 7234 | }, |
| 7235 | shouldFail: true, |
| 7236 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7237 | }) |
| 7238 | testCases = append(testCases, testCase{ |
| 7239 | testType: serverTest, |
| 7240 | name: "PartialClientFinishedWithClientHello", |
| 7241 | config: Config{ |
| 7242 | MaxVersion: VersionTLS13, |
| 7243 | Bugs: ProtocolBugs{ |
| 7244 | PartialClientFinishedWithClientHello: true, |
| 7245 | }, |
| 7246 | }, |
| 7247 | shouldFail: true, |
| 7248 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7249 | }) |
| 7250 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7251 | // Test that early ChangeCipherSpecs are handled correctly. |
| 7252 | testCases = append(testCases, testCase{ |
| 7253 | testType: serverTest, |
| 7254 | name: "EarlyChangeCipherSpec-server-1", |
| 7255 | config: Config{ |
| 7256 | MaxVersion: VersionTLS12, |
| 7257 | Bugs: ProtocolBugs{ |
| 7258 | EarlyChangeCipherSpec: 1, |
| 7259 | }, |
| 7260 | }, |
| 7261 | shouldFail: true, |
| 7262 | expectedError: ":UNEXPECTED_RECORD:", |
| 7263 | }) |
| 7264 | testCases = append(testCases, testCase{ |
| 7265 | testType: serverTest, |
| 7266 | name: "EarlyChangeCipherSpec-server-2", |
| 7267 | config: Config{ |
| 7268 | MaxVersion: VersionTLS12, |
| 7269 | Bugs: ProtocolBugs{ |
| 7270 | EarlyChangeCipherSpec: 2, |
| 7271 | }, |
| 7272 | }, |
| 7273 | shouldFail: true, |
| 7274 | expectedError: ":UNEXPECTED_RECORD:", |
| 7275 | }) |
| 7276 | testCases = append(testCases, testCase{ |
| 7277 | protocol: dtls, |
| 7278 | name: "StrayChangeCipherSpec", |
| 7279 | config: Config{ |
| 7280 | // TODO(davidben): Once DTLS 1.3 exists, test |
| 7281 | // that stray ChangeCipherSpec messages are |
| 7282 | // rejected. |
| 7283 | MaxVersion: VersionTLS12, |
| 7284 | Bugs: ProtocolBugs{ |
| 7285 | StrayChangeCipherSpec: true, |
| 7286 | }, |
| 7287 | }, |
| 7288 | }) |
| 7289 | |
| 7290 | // Test that the contents of ChangeCipherSpec are checked. |
| 7291 | testCases = append(testCases, testCase{ |
| 7292 | name: "BadChangeCipherSpec-1", |
| 7293 | config: Config{ |
| 7294 | MaxVersion: VersionTLS12, |
| 7295 | Bugs: ProtocolBugs{ |
| 7296 | BadChangeCipherSpec: []byte{2}, |
| 7297 | }, |
| 7298 | }, |
| 7299 | shouldFail: true, |
| 7300 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7301 | }) |
| 7302 | testCases = append(testCases, testCase{ |
| 7303 | name: "BadChangeCipherSpec-2", |
| 7304 | config: Config{ |
| 7305 | MaxVersion: VersionTLS12, |
| 7306 | Bugs: ProtocolBugs{ |
| 7307 | BadChangeCipherSpec: []byte{1, 1}, |
| 7308 | }, |
| 7309 | }, |
| 7310 | shouldFail: true, |
| 7311 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7312 | }) |
| 7313 | testCases = append(testCases, testCase{ |
| 7314 | protocol: dtls, |
| 7315 | name: "BadChangeCipherSpec-DTLS-1", |
| 7316 | config: Config{ |
| 7317 | MaxVersion: VersionTLS12, |
| 7318 | Bugs: ProtocolBugs{ |
| 7319 | BadChangeCipherSpec: []byte{2}, |
| 7320 | }, |
| 7321 | }, |
| 7322 | shouldFail: true, |
| 7323 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7324 | }) |
| 7325 | testCases = append(testCases, testCase{ |
| 7326 | protocol: dtls, |
| 7327 | name: "BadChangeCipherSpec-DTLS-2", |
| 7328 | config: Config{ |
| 7329 | MaxVersion: VersionTLS12, |
| 7330 | Bugs: ProtocolBugs{ |
| 7331 | BadChangeCipherSpec: []byte{1, 1}, |
| 7332 | }, |
| 7333 | }, |
| 7334 | shouldFail: true, |
| 7335 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7336 | }) |
| 7337 | } |
| 7338 | |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7339 | func addWrongMessageTypeTests() { |
| 7340 | for _, protocol := range []protocol{tls, dtls} { |
| 7341 | var suffix string |
| 7342 | if protocol == dtls { |
| 7343 | suffix = "-DTLS" |
| 7344 | } |
| 7345 | |
| 7346 | testCases = append(testCases, testCase{ |
| 7347 | protocol: protocol, |
| 7348 | testType: serverTest, |
| 7349 | name: "WrongMessageType-ClientHello" + suffix, |
| 7350 | config: Config{ |
| 7351 | MaxVersion: VersionTLS12, |
| 7352 | Bugs: ProtocolBugs{ |
| 7353 | SendWrongMessageType: typeClientHello, |
| 7354 | }, |
| 7355 | }, |
| 7356 | shouldFail: true, |
| 7357 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7358 | expectedLocalError: "remote error: unexpected message", |
| 7359 | }) |
| 7360 | |
| 7361 | if protocol == dtls { |
| 7362 | testCases = append(testCases, testCase{ |
| 7363 | protocol: protocol, |
| 7364 | name: "WrongMessageType-HelloVerifyRequest" + suffix, |
| 7365 | config: Config{ |
| 7366 | MaxVersion: VersionTLS12, |
| 7367 | Bugs: ProtocolBugs{ |
| 7368 | SendWrongMessageType: typeHelloVerifyRequest, |
| 7369 | }, |
| 7370 | }, |
| 7371 | shouldFail: true, |
| 7372 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7373 | expectedLocalError: "remote error: unexpected message", |
| 7374 | }) |
| 7375 | } |
| 7376 | |
| 7377 | testCases = append(testCases, testCase{ |
| 7378 | protocol: protocol, |
| 7379 | name: "WrongMessageType-ServerHello" + suffix, |
| 7380 | config: Config{ |
| 7381 | MaxVersion: VersionTLS12, |
| 7382 | Bugs: ProtocolBugs{ |
| 7383 | SendWrongMessageType: typeServerHello, |
| 7384 | }, |
| 7385 | }, |
| 7386 | shouldFail: true, |
| 7387 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7388 | expectedLocalError: "remote error: unexpected message", |
| 7389 | }) |
| 7390 | |
| 7391 | testCases = append(testCases, testCase{ |
| 7392 | protocol: protocol, |
| 7393 | name: "WrongMessageType-ServerCertificate" + suffix, |
| 7394 | config: Config{ |
| 7395 | MaxVersion: VersionTLS12, |
| 7396 | Bugs: ProtocolBugs{ |
| 7397 | SendWrongMessageType: typeCertificate, |
| 7398 | }, |
| 7399 | }, |
| 7400 | shouldFail: true, |
| 7401 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7402 | expectedLocalError: "remote error: unexpected message", |
| 7403 | }) |
| 7404 | |
| 7405 | testCases = append(testCases, testCase{ |
| 7406 | protocol: protocol, |
| 7407 | name: "WrongMessageType-CertificateStatus" + suffix, |
| 7408 | config: Config{ |
| 7409 | MaxVersion: VersionTLS12, |
| 7410 | Bugs: ProtocolBugs{ |
| 7411 | SendWrongMessageType: typeCertificateStatus, |
| 7412 | }, |
| 7413 | }, |
| 7414 | flags: []string{"-enable-ocsp-stapling"}, |
| 7415 | shouldFail: true, |
| 7416 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7417 | expectedLocalError: "remote error: unexpected message", |
| 7418 | }) |
| 7419 | |
| 7420 | testCases = append(testCases, testCase{ |
| 7421 | protocol: protocol, |
| 7422 | name: "WrongMessageType-ServerKeyExchange" + suffix, |
| 7423 | config: Config{ |
| 7424 | MaxVersion: VersionTLS12, |
| 7425 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7426 | Bugs: ProtocolBugs{ |
| 7427 | SendWrongMessageType: typeServerKeyExchange, |
| 7428 | }, |
| 7429 | }, |
| 7430 | shouldFail: true, |
| 7431 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7432 | expectedLocalError: "remote error: unexpected message", |
| 7433 | }) |
| 7434 | |
| 7435 | testCases = append(testCases, testCase{ |
| 7436 | protocol: protocol, |
| 7437 | name: "WrongMessageType-CertificateRequest" + suffix, |
| 7438 | config: Config{ |
| 7439 | MaxVersion: VersionTLS12, |
| 7440 | ClientAuth: RequireAnyClientCert, |
| 7441 | Bugs: ProtocolBugs{ |
| 7442 | SendWrongMessageType: typeCertificateRequest, |
| 7443 | }, |
| 7444 | }, |
| 7445 | shouldFail: true, |
| 7446 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7447 | expectedLocalError: "remote error: unexpected message", |
| 7448 | }) |
| 7449 | |
| 7450 | testCases = append(testCases, testCase{ |
| 7451 | protocol: protocol, |
| 7452 | name: "WrongMessageType-ServerHelloDone" + suffix, |
| 7453 | config: Config{ |
| 7454 | MaxVersion: VersionTLS12, |
| 7455 | Bugs: ProtocolBugs{ |
| 7456 | SendWrongMessageType: typeServerHelloDone, |
| 7457 | }, |
| 7458 | }, |
| 7459 | shouldFail: true, |
| 7460 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7461 | expectedLocalError: "remote error: unexpected message", |
| 7462 | }) |
| 7463 | |
| 7464 | testCases = append(testCases, testCase{ |
| 7465 | testType: serverTest, |
| 7466 | protocol: protocol, |
| 7467 | name: "WrongMessageType-ClientCertificate" + suffix, |
| 7468 | config: Config{ |
| 7469 | Certificates: []Certificate{rsaCertificate}, |
| 7470 | MaxVersion: VersionTLS12, |
| 7471 | Bugs: ProtocolBugs{ |
| 7472 | SendWrongMessageType: typeCertificate, |
| 7473 | }, |
| 7474 | }, |
| 7475 | flags: []string{"-require-any-client-certificate"}, |
| 7476 | shouldFail: true, |
| 7477 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7478 | expectedLocalError: "remote error: unexpected message", |
| 7479 | }) |
| 7480 | |
| 7481 | testCases = append(testCases, testCase{ |
| 7482 | testType: serverTest, |
| 7483 | protocol: protocol, |
| 7484 | name: "WrongMessageType-CertificateVerify" + suffix, |
| 7485 | config: Config{ |
| 7486 | Certificates: []Certificate{rsaCertificate}, |
| 7487 | MaxVersion: VersionTLS12, |
| 7488 | Bugs: ProtocolBugs{ |
| 7489 | SendWrongMessageType: typeCertificateVerify, |
| 7490 | }, |
| 7491 | }, |
| 7492 | flags: []string{"-require-any-client-certificate"}, |
| 7493 | shouldFail: true, |
| 7494 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7495 | expectedLocalError: "remote error: unexpected message", |
| 7496 | }) |
| 7497 | |
| 7498 | testCases = append(testCases, testCase{ |
| 7499 | testType: serverTest, |
| 7500 | protocol: protocol, |
| 7501 | name: "WrongMessageType-ClientKeyExchange" + suffix, |
| 7502 | config: Config{ |
| 7503 | MaxVersion: VersionTLS12, |
| 7504 | Bugs: ProtocolBugs{ |
| 7505 | SendWrongMessageType: typeClientKeyExchange, |
| 7506 | }, |
| 7507 | }, |
| 7508 | shouldFail: true, |
| 7509 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7510 | expectedLocalError: "remote error: unexpected message", |
| 7511 | }) |
| 7512 | |
| 7513 | if protocol != dtls { |
| 7514 | testCases = append(testCases, testCase{ |
| 7515 | testType: serverTest, |
| 7516 | protocol: protocol, |
| 7517 | name: "WrongMessageType-NextProtocol" + suffix, |
| 7518 | config: Config{ |
| 7519 | MaxVersion: VersionTLS12, |
| 7520 | NextProtos: []string{"bar"}, |
| 7521 | Bugs: ProtocolBugs{ |
| 7522 | SendWrongMessageType: typeNextProtocol, |
| 7523 | }, |
| 7524 | }, |
| 7525 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 7526 | shouldFail: true, |
| 7527 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7528 | expectedLocalError: "remote error: unexpected message", |
| 7529 | }) |
| 7530 | |
| 7531 | testCases = append(testCases, testCase{ |
| 7532 | testType: serverTest, |
| 7533 | protocol: protocol, |
| 7534 | name: "WrongMessageType-ChannelID" + suffix, |
| 7535 | config: Config{ |
| 7536 | MaxVersion: VersionTLS12, |
| 7537 | ChannelID: channelIDKey, |
| 7538 | Bugs: ProtocolBugs{ |
| 7539 | SendWrongMessageType: typeChannelID, |
| 7540 | }, |
| 7541 | }, |
| 7542 | flags: []string{ |
| 7543 | "-expect-channel-id", |
| 7544 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 7545 | }, |
| 7546 | shouldFail: true, |
| 7547 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7548 | expectedLocalError: "remote error: unexpected message", |
| 7549 | }) |
| 7550 | } |
| 7551 | |
| 7552 | testCases = append(testCases, testCase{ |
| 7553 | testType: serverTest, |
| 7554 | protocol: protocol, |
| 7555 | name: "WrongMessageType-ClientFinished" + suffix, |
| 7556 | config: Config{ |
| 7557 | MaxVersion: VersionTLS12, |
| 7558 | Bugs: ProtocolBugs{ |
| 7559 | SendWrongMessageType: typeFinished, |
| 7560 | }, |
| 7561 | }, |
| 7562 | shouldFail: true, |
| 7563 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7564 | expectedLocalError: "remote error: unexpected message", |
| 7565 | }) |
| 7566 | |
| 7567 | testCases = append(testCases, testCase{ |
| 7568 | protocol: protocol, |
| 7569 | name: "WrongMessageType-NewSessionTicket" + suffix, |
| 7570 | config: Config{ |
| 7571 | MaxVersion: VersionTLS12, |
| 7572 | Bugs: ProtocolBugs{ |
| 7573 | SendWrongMessageType: typeNewSessionTicket, |
| 7574 | }, |
| 7575 | }, |
| 7576 | shouldFail: true, |
| 7577 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7578 | expectedLocalError: "remote error: unexpected message", |
| 7579 | }) |
| 7580 | |
| 7581 | testCases = append(testCases, testCase{ |
| 7582 | protocol: protocol, |
| 7583 | name: "WrongMessageType-ServerFinished" + suffix, |
| 7584 | config: Config{ |
| 7585 | MaxVersion: VersionTLS12, |
| 7586 | Bugs: ProtocolBugs{ |
| 7587 | SendWrongMessageType: typeFinished, |
| 7588 | }, |
| 7589 | }, |
| 7590 | shouldFail: true, |
| 7591 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7592 | expectedLocalError: "remote error: unexpected message", |
| 7593 | }) |
| 7594 | |
| 7595 | } |
| 7596 | } |
| 7597 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7598 | func addTLS13WrongMessageTypeTests() { |
| 7599 | testCases = append(testCases, testCase{ |
| 7600 | testType: serverTest, |
| 7601 | name: "WrongMessageType-TLS13-ClientHello", |
| 7602 | config: Config{ |
| 7603 | MaxVersion: VersionTLS13, |
| 7604 | Bugs: ProtocolBugs{ |
| 7605 | SendWrongMessageType: typeClientHello, |
| 7606 | }, |
| 7607 | }, |
| 7608 | shouldFail: true, |
| 7609 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7610 | expectedLocalError: "remote error: unexpected message", |
| 7611 | }) |
| 7612 | |
| 7613 | testCases = append(testCases, testCase{ |
| 7614 | name: "WrongMessageType-TLS13-ServerHello", |
| 7615 | config: Config{ |
| 7616 | MaxVersion: VersionTLS13, |
| 7617 | Bugs: ProtocolBugs{ |
| 7618 | SendWrongMessageType: typeServerHello, |
| 7619 | }, |
| 7620 | }, |
| 7621 | shouldFail: true, |
| 7622 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7623 | // The alert comes in with the wrong encryption. |
| 7624 | expectedLocalError: "local error: bad record MAC", |
| 7625 | }) |
| 7626 | |
| 7627 | testCases = append(testCases, testCase{ |
| 7628 | name: "WrongMessageType-TLS13-EncryptedExtensions", |
| 7629 | config: Config{ |
| 7630 | MaxVersion: VersionTLS13, |
| 7631 | Bugs: ProtocolBugs{ |
| 7632 | SendWrongMessageType: typeEncryptedExtensions, |
| 7633 | }, |
| 7634 | }, |
| 7635 | shouldFail: true, |
| 7636 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7637 | expectedLocalError: "remote error: unexpected message", |
| 7638 | }) |
| 7639 | |
| 7640 | testCases = append(testCases, testCase{ |
| 7641 | name: "WrongMessageType-TLS13-CertificateRequest", |
| 7642 | config: Config{ |
| 7643 | MaxVersion: VersionTLS13, |
| 7644 | ClientAuth: RequireAnyClientCert, |
| 7645 | Bugs: ProtocolBugs{ |
| 7646 | SendWrongMessageType: typeCertificateRequest, |
| 7647 | }, |
| 7648 | }, |
| 7649 | shouldFail: true, |
| 7650 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7651 | expectedLocalError: "remote error: unexpected message", |
| 7652 | }) |
| 7653 | |
| 7654 | testCases = append(testCases, testCase{ |
| 7655 | name: "WrongMessageType-TLS13-ServerCertificate", |
| 7656 | config: Config{ |
| 7657 | MaxVersion: VersionTLS13, |
| 7658 | Bugs: ProtocolBugs{ |
| 7659 | SendWrongMessageType: typeCertificate, |
| 7660 | }, |
| 7661 | }, |
| 7662 | shouldFail: true, |
| 7663 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7664 | expectedLocalError: "remote error: unexpected message", |
| 7665 | }) |
| 7666 | |
| 7667 | testCases = append(testCases, testCase{ |
| 7668 | name: "WrongMessageType-TLS13-ServerCertificateVerify", |
| 7669 | config: Config{ |
| 7670 | MaxVersion: VersionTLS13, |
| 7671 | Bugs: ProtocolBugs{ |
| 7672 | SendWrongMessageType: typeCertificateVerify, |
| 7673 | }, |
| 7674 | }, |
| 7675 | shouldFail: true, |
| 7676 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7677 | expectedLocalError: "remote error: unexpected message", |
| 7678 | }) |
| 7679 | |
| 7680 | testCases = append(testCases, testCase{ |
| 7681 | name: "WrongMessageType-TLS13-ServerFinished", |
| 7682 | config: Config{ |
| 7683 | MaxVersion: VersionTLS13, |
| 7684 | Bugs: ProtocolBugs{ |
| 7685 | SendWrongMessageType: typeFinished, |
| 7686 | }, |
| 7687 | }, |
| 7688 | shouldFail: true, |
| 7689 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7690 | expectedLocalError: "remote error: unexpected message", |
| 7691 | }) |
| 7692 | |
| 7693 | testCases = append(testCases, testCase{ |
| 7694 | testType: serverTest, |
| 7695 | name: "WrongMessageType-TLS13-ClientCertificate", |
| 7696 | config: Config{ |
| 7697 | Certificates: []Certificate{rsaCertificate}, |
| 7698 | MaxVersion: VersionTLS13, |
| 7699 | Bugs: ProtocolBugs{ |
| 7700 | SendWrongMessageType: typeCertificate, |
| 7701 | }, |
| 7702 | }, |
| 7703 | flags: []string{"-require-any-client-certificate"}, |
| 7704 | shouldFail: true, |
| 7705 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7706 | expectedLocalError: "remote error: unexpected message", |
| 7707 | }) |
| 7708 | |
| 7709 | testCases = append(testCases, testCase{ |
| 7710 | testType: serverTest, |
| 7711 | name: "WrongMessageType-TLS13-ClientCertificateVerify", |
| 7712 | config: Config{ |
| 7713 | Certificates: []Certificate{rsaCertificate}, |
| 7714 | MaxVersion: VersionTLS13, |
| 7715 | Bugs: ProtocolBugs{ |
| 7716 | SendWrongMessageType: typeCertificateVerify, |
| 7717 | }, |
| 7718 | }, |
| 7719 | flags: []string{"-require-any-client-certificate"}, |
| 7720 | shouldFail: true, |
| 7721 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7722 | expectedLocalError: "remote error: unexpected message", |
| 7723 | }) |
| 7724 | |
| 7725 | testCases = append(testCases, testCase{ |
| 7726 | testType: serverTest, |
| 7727 | name: "WrongMessageType-TLS13-ClientFinished", |
| 7728 | config: Config{ |
| 7729 | MaxVersion: VersionTLS13, |
| 7730 | Bugs: ProtocolBugs{ |
| 7731 | SendWrongMessageType: typeFinished, |
| 7732 | }, |
| 7733 | }, |
| 7734 | shouldFail: true, |
| 7735 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7736 | expectedLocalError: "remote error: unexpected message", |
| 7737 | }) |
| 7738 | } |
| 7739 | |
| 7740 | func addTLS13HandshakeTests() { |
| 7741 | testCases = append(testCases, testCase{ |
| 7742 | testType: clientTest, |
| 7743 | name: "MissingKeyShare-Client", |
| 7744 | config: Config{ |
| 7745 | MaxVersion: VersionTLS13, |
| 7746 | Bugs: ProtocolBugs{ |
| 7747 | MissingKeyShare: true, |
| 7748 | }, |
| 7749 | }, |
| 7750 | shouldFail: true, |
| 7751 | expectedError: ":MISSING_KEY_SHARE:", |
| 7752 | }) |
| 7753 | |
| 7754 | testCases = append(testCases, testCase{ |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7755 | testType: serverTest, |
| 7756 | name: "MissingKeyShare-Server", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7757 | config: Config{ |
| 7758 | MaxVersion: VersionTLS13, |
| 7759 | Bugs: ProtocolBugs{ |
| 7760 | MissingKeyShare: true, |
| 7761 | }, |
| 7762 | }, |
| 7763 | shouldFail: true, |
| 7764 | expectedError: ":MISSING_KEY_SHARE:", |
| 7765 | }) |
| 7766 | |
| 7767 | testCases = append(testCases, testCase{ |
| 7768 | testType: clientTest, |
| 7769 | name: "ClientHelloMissingKeyShare", |
| 7770 | config: Config{ |
| 7771 | MaxVersion: VersionTLS13, |
| 7772 | Bugs: ProtocolBugs{ |
| 7773 | MissingKeyShare: true, |
| 7774 | }, |
| 7775 | }, |
| 7776 | shouldFail: true, |
| 7777 | expectedError: ":MISSING_KEY_SHARE:", |
| 7778 | }) |
| 7779 | |
| 7780 | testCases = append(testCases, testCase{ |
| 7781 | testType: clientTest, |
| 7782 | name: "MissingKeyShare", |
| 7783 | config: Config{ |
| 7784 | MaxVersion: VersionTLS13, |
| 7785 | Bugs: ProtocolBugs{ |
| 7786 | MissingKeyShare: true, |
| 7787 | }, |
| 7788 | }, |
| 7789 | shouldFail: true, |
| 7790 | expectedError: ":MISSING_KEY_SHARE:", |
| 7791 | }) |
| 7792 | |
| 7793 | testCases = append(testCases, testCase{ |
| 7794 | testType: serverTest, |
| 7795 | name: "DuplicateKeyShares", |
| 7796 | config: Config{ |
| 7797 | MaxVersion: VersionTLS13, |
| 7798 | Bugs: ProtocolBugs{ |
| 7799 | DuplicateKeyShares: true, |
| 7800 | }, |
| 7801 | }, |
| 7802 | }) |
| 7803 | |
| 7804 | testCases = append(testCases, testCase{ |
| 7805 | testType: clientTest, |
| 7806 | name: "EmptyEncryptedExtensions", |
| 7807 | config: Config{ |
| 7808 | MaxVersion: VersionTLS13, |
| 7809 | Bugs: ProtocolBugs{ |
| 7810 | EmptyEncryptedExtensions: true, |
| 7811 | }, |
| 7812 | }, |
| 7813 | shouldFail: true, |
| 7814 | expectedLocalError: "remote error: error decoding message", |
| 7815 | }) |
| 7816 | |
| 7817 | testCases = append(testCases, testCase{ |
| 7818 | testType: clientTest, |
| 7819 | name: "EncryptedExtensionsWithKeyShare", |
| 7820 | config: Config{ |
| 7821 | MaxVersion: VersionTLS13, |
| 7822 | Bugs: ProtocolBugs{ |
| 7823 | EncryptedExtensionsWithKeyShare: true, |
| 7824 | }, |
| 7825 | }, |
| 7826 | shouldFail: true, |
| 7827 | expectedLocalError: "remote error: unsupported extension", |
| 7828 | }) |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7829 | |
| 7830 | testCases = append(testCases, testCase{ |
| 7831 | testType: serverTest, |
| 7832 | name: "SendHelloRetryRequest", |
| 7833 | config: Config{ |
| 7834 | MaxVersion: VersionTLS13, |
| 7835 | // Require a HelloRetryRequest for every curve. |
| 7836 | DefaultCurves: []CurveID{}, |
| 7837 | }, |
| 7838 | expectedCurveID: CurveX25519, |
| 7839 | }) |
| 7840 | |
| 7841 | testCases = append(testCases, testCase{ |
| 7842 | testType: serverTest, |
| 7843 | name: "SendHelloRetryRequest-2", |
| 7844 | config: Config{ |
| 7845 | MaxVersion: VersionTLS13, |
| 7846 | DefaultCurves: []CurveID{CurveP384}, |
| 7847 | }, |
| 7848 | // Although the ClientHello did not predict our preferred curve, |
| 7849 | // we always select it whether it is predicted or not. |
| 7850 | expectedCurveID: CurveX25519, |
| 7851 | }) |
| 7852 | |
| 7853 | testCases = append(testCases, testCase{ |
| 7854 | name: "UnknownCurve-HelloRetryRequest", |
| 7855 | config: Config{ |
| 7856 | MaxVersion: VersionTLS13, |
| 7857 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7858 | CurvePreferences: []CurveID{CurveP384}, |
| 7859 | Bugs: ProtocolBugs{ |
| 7860 | SendHelloRetryRequestCurve: bogusCurve, |
| 7861 | }, |
| 7862 | }, |
| 7863 | shouldFail: true, |
| 7864 | expectedError: ":WRONG_CURVE:", |
| 7865 | }) |
| 7866 | |
| 7867 | testCases = append(testCases, testCase{ |
| 7868 | name: "DisabledCurve-HelloRetryRequest", |
| 7869 | config: Config{ |
| 7870 | MaxVersion: VersionTLS13, |
| 7871 | CurvePreferences: []CurveID{CurveP256}, |
| 7872 | Bugs: ProtocolBugs{ |
| 7873 | IgnorePeerCurvePreferences: true, |
| 7874 | }, |
| 7875 | }, |
| 7876 | flags: []string{"-p384-only"}, |
| 7877 | shouldFail: true, |
| 7878 | expectedError: ":WRONG_CURVE:", |
| 7879 | }) |
| 7880 | |
| 7881 | testCases = append(testCases, testCase{ |
| 7882 | name: "UnnecessaryHelloRetryRequest", |
| 7883 | config: Config{ |
| 7884 | MaxVersion: VersionTLS13, |
| 7885 | Bugs: ProtocolBugs{ |
| 7886 | UnnecessaryHelloRetryRequest: true, |
| 7887 | }, |
| 7888 | }, |
| 7889 | shouldFail: true, |
| 7890 | expectedError: ":WRONG_CURVE:", |
| 7891 | }) |
| 7892 | |
| 7893 | testCases = append(testCases, testCase{ |
| 7894 | name: "SecondHelloRetryRequest", |
| 7895 | config: Config{ |
| 7896 | MaxVersion: VersionTLS13, |
| 7897 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7898 | CurvePreferences: []CurveID{CurveP384}, |
| 7899 | Bugs: ProtocolBugs{ |
| 7900 | SecondHelloRetryRequest: true, |
| 7901 | }, |
| 7902 | }, |
| 7903 | shouldFail: true, |
| 7904 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7905 | }) |
| 7906 | |
| 7907 | testCases = append(testCases, testCase{ |
| 7908 | testType: serverTest, |
| 7909 | name: "SecondClientHelloMissingKeyShare", |
| 7910 | config: Config{ |
| 7911 | MaxVersion: VersionTLS13, |
| 7912 | DefaultCurves: []CurveID{}, |
| 7913 | Bugs: ProtocolBugs{ |
| 7914 | SecondClientHelloMissingKeyShare: true, |
| 7915 | }, |
| 7916 | }, |
| 7917 | shouldFail: true, |
| 7918 | expectedError: ":MISSING_KEY_SHARE:", |
| 7919 | }) |
| 7920 | |
| 7921 | testCases = append(testCases, testCase{ |
| 7922 | testType: serverTest, |
| 7923 | name: "SecondClientHelloWrongCurve", |
| 7924 | config: Config{ |
| 7925 | MaxVersion: VersionTLS13, |
| 7926 | DefaultCurves: []CurveID{}, |
| 7927 | Bugs: ProtocolBugs{ |
| 7928 | MisinterpretHelloRetryRequestCurve: CurveP521, |
| 7929 | }, |
| 7930 | }, |
| 7931 | shouldFail: true, |
| 7932 | expectedError: ":WRONG_CURVE:", |
| 7933 | }) |
| 7934 | |
| 7935 | testCases = append(testCases, testCase{ |
| 7936 | name: "HelloRetryRequestVersionMismatch", |
| 7937 | config: Config{ |
| 7938 | MaxVersion: VersionTLS13, |
| 7939 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7940 | CurvePreferences: []CurveID{CurveP384}, |
| 7941 | Bugs: ProtocolBugs{ |
| 7942 | SendServerHelloVersion: 0x0305, |
| 7943 | }, |
| 7944 | }, |
| 7945 | shouldFail: true, |
| 7946 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 7947 | }) |
| 7948 | |
| 7949 | testCases = append(testCases, testCase{ |
| 7950 | name: "HelloRetryRequestCurveMismatch", |
| 7951 | config: Config{ |
| 7952 | MaxVersion: VersionTLS13, |
| 7953 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7954 | CurvePreferences: []CurveID{CurveP384}, |
| 7955 | Bugs: ProtocolBugs{ |
| 7956 | // Send P-384 (correct) in the HelloRetryRequest. |
| 7957 | SendHelloRetryRequestCurve: CurveP384, |
| 7958 | // But send P-256 in the ServerHello. |
| 7959 | SendCurve: CurveP256, |
| 7960 | }, |
| 7961 | }, |
| 7962 | shouldFail: true, |
| 7963 | expectedError: ":WRONG_CURVE:", |
| 7964 | }) |
| 7965 | |
| 7966 | // Test the server selecting a curve that requires a HelloRetryRequest |
| 7967 | // without sending it. |
| 7968 | testCases = append(testCases, testCase{ |
| 7969 | name: "SkipHelloRetryRequest", |
| 7970 | config: Config{ |
| 7971 | MaxVersion: VersionTLS13, |
| 7972 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7973 | CurvePreferences: []CurveID{CurveP384}, |
| 7974 | Bugs: ProtocolBugs{ |
| 7975 | SkipHelloRetryRequest: true, |
| 7976 | }, |
| 7977 | }, |
| 7978 | shouldFail: true, |
| 7979 | expectedError: ":WRONG_CURVE:", |
| 7980 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7981 | } |
| 7982 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7983 | func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7984 | defer wg.Done() |
| 7985 | |
| 7986 | for test := range c { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 7987 | var err error |
| 7988 | |
| 7989 | if *mallocTest < 0 { |
| 7990 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7991 | err = runTest(test, shimPath, -1) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 7992 | } else { |
| 7993 | for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ { |
| 7994 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7995 | if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 7996 | if err != nil { |
| 7997 | fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err) |
| 7998 | } |
| 7999 | break |
| 8000 | } |
| 8001 | } |
| 8002 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8003 | statusChan <- statusMsg{test: test, err: err} |
| 8004 | } |
| 8005 | } |
| 8006 | |
| 8007 | type statusMsg struct { |
| 8008 | test *testCase |
| 8009 | started bool |
| 8010 | err error |
| 8011 | } |
| 8012 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8013 | func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8014 | var started, done, failed, unimplemented, lineLen int |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8015 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8016 | testOutput := newTestOutput() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8017 | for msg := range statusChan { |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8018 | if !*pipe { |
| 8019 | // Erase the previous status line. |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 8020 | var erase string |
| 8021 | for i := 0; i < lineLen; i++ { |
| 8022 | erase += "\b \b" |
| 8023 | } |
| 8024 | fmt.Print(erase) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8025 | } |
| 8026 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8027 | if msg.started { |
| 8028 | started++ |
| 8029 | } else { |
| 8030 | done++ |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8031 | |
| 8032 | if msg.err != nil { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8033 | if msg.err == errUnimplemented { |
| 8034 | if *pipe { |
| 8035 | // Print each test instead of a status line. |
| 8036 | fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name) |
| 8037 | } |
| 8038 | unimplemented++ |
| 8039 | testOutput.addResult(msg.test.name, "UNIMPLEMENTED") |
| 8040 | } else { |
| 8041 | fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err) |
| 8042 | failed++ |
| 8043 | testOutput.addResult(msg.test.name, "FAIL") |
| 8044 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8045 | } else { |
| 8046 | if *pipe { |
| 8047 | // Print each test instead of a status line. |
| 8048 | fmt.Printf("PASSED (%s)\n", msg.test.name) |
| 8049 | } |
| 8050 | testOutput.addResult(msg.test.name, "PASS") |
| 8051 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8052 | } |
| 8053 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8054 | if !*pipe { |
| 8055 | // Print a new status line. |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8056 | line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8057 | lineLen = len(line) |
| 8058 | os.Stdout.WriteString(line) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8059 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8060 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8061 | |
| 8062 | doneChan <- testOutput |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8063 | } |
| 8064 | |
| 8065 | func main() { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8066 | flag.Parse() |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8067 | *resourceDir = path.Clean(*resourceDir) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 8068 | initCertificates() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8069 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8070 | addBasicTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8071 | addCipherSuiteTests() |
| 8072 | addBadECDSASignatureTests() |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8073 | addCBCPaddingTests() |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 8074 | addCBCSplittingTests() |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 8075 | addClientAuthTests() |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 8076 | addDDoSCallbackTests() |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 8077 | addVersionNegotiationTests() |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 8078 | addMinimumVersionTests() |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 8079 | addExtensionTests() |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 8080 | addResumptionVersionTests() |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 8081 | addExtendedMasterSecretTests() |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 8082 | addRenegotiationTests() |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 8083 | addDTLSReplayTests() |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 8084 | addSignatureAlgorithmTests() |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 8085 | addDTLSRetransmitTests() |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 8086 | addExportKeyingMaterialTests() |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 8087 | addTLSUniqueTests() |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 8088 | addCustomExtensionTests() |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 8089 | addRSAClientKeyExchangeTests() |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 8090 | addCurveTests() |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 8091 | addCECPQ1Tests() |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 8092 | addKeyExchangeInfoTests() |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 8093 | addTLS13RecordTests() |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 8094 | addAllStateMachineCoverageTests() |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 8095 | addChangeCipherSpecTests() |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8096 | addWrongMessageTypeTests() |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8097 | addTLS13WrongMessageTypeTests() |
| 8098 | addTLS13HandshakeTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8099 | |
| 8100 | var wg sync.WaitGroup |
| 8101 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8102 | statusChan := make(chan statusMsg, *numWorkers) |
| 8103 | testChan := make(chan *testCase, *numWorkers) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8104 | doneChan := make(chan *testOutput) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8105 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8106 | if len(*shimConfigFile) != 0 { |
| 8107 | encoded, err := ioutil.ReadFile(*shimConfigFile) |
| 8108 | if err != nil { |
| 8109 | fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err) |
| 8110 | os.Exit(1) |
| 8111 | } |
| 8112 | |
| 8113 | if err := json.Unmarshal(encoded, &shimConfig); err != nil { |
| 8114 | fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err) |
| 8115 | os.Exit(1) |
| 8116 | } |
| 8117 | } |
| 8118 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8119 | go statusPrinter(doneChan, statusChan, len(testCases)) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8120 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8121 | for i := 0; i < *numWorkers; i++ { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8122 | wg.Add(1) |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8123 | go worker(statusChan, testChan, *shimPath, &wg) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8124 | } |
| 8125 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8126 | var foundTest bool |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8127 | for i := range testCases { |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8128 | matched := true |
| 8129 | if len(*testToRun) != 0 { |
| 8130 | var err error |
| 8131 | matched, err = filepath.Match(*testToRun, testCases[i].name) |
| 8132 | if err != nil { |
| 8133 | fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err) |
| 8134 | os.Exit(1) |
| 8135 | } |
| 8136 | } |
| 8137 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8138 | if !*includeDisabled { |
| 8139 | for pattern := range shimConfig.DisabledTests { |
| 8140 | isDisabled, err := filepath.Match(pattern, testCases[i].name) |
| 8141 | if err != nil { |
| 8142 | fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err) |
| 8143 | os.Exit(1) |
| 8144 | } |
| 8145 | |
| 8146 | if isDisabled { |
| 8147 | matched = false |
| 8148 | break |
| 8149 | } |
| 8150 | } |
| 8151 | } |
| 8152 | |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8153 | if matched { |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8154 | foundTest = true |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8155 | testChan <- &testCases[i] |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8156 | } |
| 8157 | } |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8158 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8159 | if !foundTest { |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8160 | fmt.Fprintf(os.Stderr, "No tests run\n") |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8161 | os.Exit(1) |
| 8162 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8163 | |
| 8164 | close(testChan) |
| 8165 | wg.Wait() |
| 8166 | close(statusChan) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8167 | testOutput := <-doneChan |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8168 | |
| 8169 | fmt.Printf("\n") |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8170 | |
| 8171 | if *jsonOutput != "" { |
| 8172 | if err := testOutput.writeTo(*jsonOutput); err != nil { |
| 8173 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 8174 | } |
| 8175 | } |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 8176 | |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8177 | if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 { |
| 8178 | os.Exit(1) |
| 8179 | } |
| 8180 | |
| 8181 | if !testOutput.noneFailed { |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 8182 | os.Exit(1) |
| 8183 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8184 | } |