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 |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 297 | // resumeRenewedSession controls whether a third connection should be |
| 298 | // tested which attempts to resume the second connection's session. |
| 299 | resumeRenewedSession bool |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 300 | // expectResumeRejected, if true, specifies that the attempted |
| 301 | // resumption must be rejected by the client. This is only valid for a |
| 302 | // serverTest. |
| 303 | expectResumeRejected bool |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 304 | // resumeConfig, if not nil, points to a Config to be used on |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 305 | // resumption. Unless newSessionsOnResume is set, |
| 306 | // SessionTicketKey, ServerSessionCache, and |
| 307 | // ClientSessionCache are copied from the initial connection's |
| 308 | // config. If nil, the initial connection's config is used. |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 309 | resumeConfig *Config |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 310 | // newSessionsOnResume, if true, will cause resumeConfig to |
| 311 | // use a different session resumption context. |
| 312 | newSessionsOnResume bool |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 313 | // noSessionCache, if true, will cause the server to run without a |
| 314 | // session cache. |
| 315 | noSessionCache bool |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 316 | // sendPrefix sends a prefix on the socket before actually performing a |
| 317 | // handshake. |
| 318 | sendPrefix string |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 319 | // shimWritesFirst controls whether the shim sends an initial "hello" |
| 320 | // message before doing a roundtrip with the runner. |
| 321 | shimWritesFirst bool |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 322 | // shimShutsDown, if true, runs a test where the shim shuts down the |
| 323 | // connection immediately after the handshake rather than echoing |
| 324 | // messages from the runner. |
| 325 | shimShutsDown bool |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 326 | // renegotiate indicates the number of times the connection should be |
| 327 | // renegotiated during the exchange. |
| 328 | renegotiate int |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 329 | // sendHalfHelloRequest, if true, causes the server to send half a |
| 330 | // HelloRequest when the handshake completes. |
| 331 | sendHalfHelloRequest bool |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 332 | // renegotiateCiphers is a list of ciphersuite ids that will be |
| 333 | // switched in just before renegotiation. |
| 334 | renegotiateCiphers []uint16 |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 335 | // replayWrites, if true, configures the underlying transport |
| 336 | // to replay every write it makes in DTLS tests. |
| 337 | replayWrites bool |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 338 | // damageFirstWrite, if true, configures the underlying transport to |
| 339 | // damage the final byte of the first application data write. |
| 340 | damageFirstWrite bool |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 341 | // exportKeyingMaterial, if non-zero, configures the test to exchange |
| 342 | // keying material and verify they match. |
| 343 | exportKeyingMaterial int |
| 344 | exportLabel string |
| 345 | exportContext string |
| 346 | useExportContext bool |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 347 | // flags, if not empty, contains a list of command-line flags that will |
| 348 | // be passed to the shim program. |
| 349 | flags []string |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 350 | // testTLSUnique, if true, causes the shim to send the tls-unique value |
| 351 | // which will be compared against the expected value. |
| 352 | testTLSUnique bool |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 353 | // sendEmptyRecords is the number of consecutive empty records to send |
| 354 | // before and after the test message. |
| 355 | sendEmptyRecords int |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 356 | // sendWarningAlerts is the number of consecutive warning alerts to send |
| 357 | // before and after the test message. |
| 358 | sendWarningAlerts int |
Steven Valdez | 32635b8 | 2016-08-16 11:25:03 -0400 | [diff] [blame] | 359 | // sendKeyUpdates is the number of consecutive key updates to send |
| 360 | // before and after the test message. |
| 361 | sendKeyUpdates int |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 362 | // expectMessageDropped, if true, means the test message is expected to |
| 363 | // be dropped by the client rather than echoed back. |
| 364 | expectMessageDropped bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 367 | var testCases []testCase |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 368 | |
David Benjamin | c07afb7 | 2016-09-22 10:18:58 -0400 | [diff] [blame] | 369 | func writeTranscript(test *testCase, num int, data []byte) { |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 370 | if len(data) == 0 { |
| 371 | return |
| 372 | } |
| 373 | |
| 374 | protocol := "tls" |
| 375 | if test.protocol == dtls { |
| 376 | protocol = "dtls" |
| 377 | } |
| 378 | |
| 379 | side := "client" |
| 380 | if test.testType == serverTest { |
| 381 | side = "server" |
| 382 | } |
| 383 | |
| 384 | dir := path.Join(*transcriptDir, protocol, side) |
| 385 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 386 | fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err) |
| 387 | return |
| 388 | } |
| 389 | |
David Benjamin | c07afb7 | 2016-09-22 10:18:58 -0400 | [diff] [blame] | 390 | name := fmt.Sprintf("%s-%d", test.name, num) |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 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 | c07afb7 | 2016-09-22 10:18:58 -0400 | [diff] [blame] | 416 | func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error { |
David Benjamin | e54af06 | 2016-08-08 19:21:18 -0400 | [diff] [blame] | 417 | if !test.noSessionCache { |
| 418 | if config.ClientSessionCache == nil { |
| 419 | config.ClientSessionCache = NewLRUClientSessionCache(1) |
| 420 | } |
| 421 | if config.ServerSessionCache == nil { |
| 422 | config.ServerSessionCache = NewLRUServerSessionCache(1) |
| 423 | } |
| 424 | } |
| 425 | if test.testType == clientTest { |
| 426 | if len(config.Certificates) == 0 { |
| 427 | config.Certificates = []Certificate{rsaCertificate} |
| 428 | } |
| 429 | } else { |
| 430 | // Supply a ServerName to ensure a constant session cache key, |
| 431 | // rather than falling back to net.Conn.RemoteAddr. |
| 432 | if len(config.ServerName) == 0 { |
| 433 | config.ServerName = "test" |
| 434 | } |
| 435 | } |
| 436 | if *fuzzer { |
| 437 | config.Bugs.NullAllCiphers = true |
| 438 | } |
David Benjamin | 01a9057 | 2016-09-22 00:11:43 -0400 | [diff] [blame] | 439 | if *deterministic { |
| 440 | config.Time = func() time.Time { return time.Unix(1234, 1234) } |
| 441 | } |
David Benjamin | e54af06 | 2016-08-08 19:21:18 -0400 | [diff] [blame] | 442 | |
David Benjamin | 01784b4 | 2016-06-07 18:00:52 -0400 | [diff] [blame] | 443 | conn = &timeoutConn{conn, *idleTimeout} |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 444 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 445 | if test.protocol == dtls { |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 446 | config.Bugs.PacketAdaptor = newPacketAdaptor(conn) |
| 447 | conn = config.Bugs.PacketAdaptor |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 448 | } |
| 449 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 450 | if *flagDebug || len(*transcriptDir) != 0 { |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 451 | local, peer := "client", "server" |
| 452 | if test.testType == clientTest { |
| 453 | local, peer = peer, local |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 454 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 455 | connDebug := &recordingConn{ |
| 456 | Conn: conn, |
| 457 | isDatagram: test.protocol == dtls, |
| 458 | local: local, |
| 459 | peer: peer, |
| 460 | } |
| 461 | conn = connDebug |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 462 | if *flagDebug { |
| 463 | defer connDebug.WriteTo(os.Stdout) |
| 464 | } |
| 465 | if len(*transcriptDir) != 0 { |
| 466 | defer func() { |
David Benjamin | c07afb7 | 2016-09-22 10:18:58 -0400 | [diff] [blame] | 467 | writeTranscript(test, num, connDebug.Transcript()) |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 468 | }() |
| 469 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 470 | |
| 471 | if config.Bugs.PacketAdaptor != nil { |
| 472 | config.Bugs.PacketAdaptor.debug = connDebug |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | if test.replayWrites { |
| 477 | conn = newReplayAdaptor(conn) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 478 | } |
| 479 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 480 | var connDamage *damageAdaptor |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 481 | if test.damageFirstWrite { |
| 482 | connDamage = newDamageAdaptor(conn) |
| 483 | conn = connDamage |
| 484 | } |
| 485 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 486 | if test.sendPrefix != "" { |
| 487 | if _, err := conn.Write([]byte(test.sendPrefix)); err != nil { |
| 488 | return err |
| 489 | } |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 490 | } |
| 491 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 492 | var tlsConn *Conn |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 493 | if test.testType == clientTest { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 494 | if test.protocol == dtls { |
| 495 | tlsConn = DTLSServer(conn, config) |
| 496 | } else { |
| 497 | tlsConn = Server(conn, config) |
| 498 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 499 | } else { |
| 500 | config.InsecureSkipVerify = true |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 501 | if test.protocol == dtls { |
| 502 | tlsConn = DTLSClient(conn, config) |
| 503 | } else { |
| 504 | tlsConn = Client(conn, config) |
| 505 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 506 | } |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 507 | defer tlsConn.Close() |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 508 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 509 | if err := tlsConn.Handshake(); err != nil { |
| 510 | return err |
| 511 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 512 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 513 | // TODO(davidben): move all per-connection expectations into a dedicated |
| 514 | // expectations struct that can be specified separately for the two |
| 515 | // legs. |
| 516 | expectedVersion := test.expectedVersion |
| 517 | if isResume && test.expectedResumeVersion != 0 { |
| 518 | expectedVersion = test.expectedResumeVersion |
| 519 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 520 | connState := tlsConn.ConnectionState() |
| 521 | if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 522 | return fmt.Errorf("got version %x, expected %x", vers, expectedVersion) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 523 | } |
| 524 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 525 | if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher { |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 526 | return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher) |
| 527 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 528 | if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected { |
| 529 | return fmt.Errorf("didResume is %t, but we expected the opposite", didResume) |
| 530 | } |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 531 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 532 | if test.expectChannelID { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 533 | channelID := connState.ChannelID |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 534 | if channelID == nil { |
| 535 | return fmt.Errorf("no channel ID negotiated") |
| 536 | } |
| 537 | if channelID.Curve != channelIDKey.Curve || |
| 538 | channelIDKey.X.Cmp(channelIDKey.X) != 0 || |
| 539 | channelIDKey.Y.Cmp(channelIDKey.Y) != 0 { |
| 540 | return fmt.Errorf("incorrect channel ID") |
| 541 | } |
| 542 | } |
| 543 | |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 544 | if expected := test.expectedNextProto; expected != "" { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 545 | if actual := connState.NegotiatedProtocol; actual != expected { |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 546 | return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected) |
| 547 | } |
| 548 | } |
| 549 | |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 550 | if test.expectNoNextProto { |
| 551 | if actual := connState.NegotiatedProtocol; actual != "" { |
| 552 | return fmt.Errorf("got unexpected next proto %s", actual) |
| 553 | } |
| 554 | } |
| 555 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 556 | if test.expectedNextProtoType != 0 { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 557 | if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN { |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 558 | return fmt.Errorf("next proto type mismatch") |
| 559 | } |
| 560 | } |
| 561 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 562 | if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile { |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 563 | return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile) |
| 564 | } |
| 565 | |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 566 | if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) { |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 567 | 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] | 568 | } |
| 569 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 570 | if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) { |
| 571 | return fmt.Errorf("SCT list mismatch") |
| 572 | } |
| 573 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 574 | if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm { |
| 575 | 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] | 576 | } |
| 577 | |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 578 | if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID { |
| 579 | return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID) |
| 580 | } |
| 581 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 582 | if test.exportKeyingMaterial > 0 { |
| 583 | actual := make([]byte, test.exportKeyingMaterial) |
| 584 | if _, err := io.ReadFull(tlsConn, actual); err != nil { |
| 585 | return err |
| 586 | } |
| 587 | expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext) |
| 588 | if err != nil { |
| 589 | return err |
| 590 | } |
| 591 | if !bytes.Equal(actual, expected) { |
| 592 | return fmt.Errorf("keying material mismatch") |
| 593 | } |
| 594 | } |
| 595 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 596 | if test.testTLSUnique { |
| 597 | var peersValue [12]byte |
| 598 | if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil { |
| 599 | return err |
| 600 | } |
| 601 | expected := tlsConn.ConnectionState().TLSUnique |
| 602 | if !bytes.Equal(peersValue[:], expected) { |
| 603 | return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected) |
| 604 | } |
| 605 | } |
| 606 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 607 | if test.shimWritesFirst { |
| 608 | var buf [5]byte |
| 609 | _, err := io.ReadFull(tlsConn, buf[:]) |
| 610 | if err != nil { |
| 611 | return err |
| 612 | } |
| 613 | if string(buf[:]) != "hello" { |
| 614 | return fmt.Errorf("bad initial message") |
| 615 | } |
| 616 | } |
| 617 | |
Steven Valdez | 32635b8 | 2016-08-16 11:25:03 -0400 | [diff] [blame] | 618 | for i := 0; i < test.sendKeyUpdates; i++ { |
David Benjamin | 7f0965a | 2016-09-30 15:14:01 -0400 | [diff] [blame] | 619 | if err := tlsConn.SendKeyUpdate(); err != nil { |
| 620 | return err |
| 621 | } |
Steven Valdez | 32635b8 | 2016-08-16 11:25:03 -0400 | [diff] [blame] | 622 | } |
| 623 | |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 624 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 625 | tlsConn.Write(nil) |
| 626 | } |
| 627 | |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 628 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 629 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 630 | } |
| 631 | |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 632 | if test.sendHalfHelloRequest { |
| 633 | tlsConn.SendHalfHelloRequest() |
| 634 | } |
| 635 | |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 636 | if test.renegotiate > 0 { |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 637 | if test.renegotiateCiphers != nil { |
| 638 | config.CipherSuites = test.renegotiateCiphers |
| 639 | } |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 640 | for i := 0; i < test.renegotiate; i++ { |
| 641 | if err := tlsConn.Renegotiate(); err != nil { |
| 642 | return err |
| 643 | } |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 644 | } |
| 645 | } else if test.renegotiateCiphers != nil { |
| 646 | panic("renegotiateCiphers without renegotiate") |
| 647 | } |
| 648 | |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 649 | if test.damageFirstWrite { |
| 650 | connDamage.setDamage(true) |
| 651 | tlsConn.Write([]byte("DAMAGED WRITE")) |
| 652 | connDamage.setDamage(false) |
| 653 | } |
| 654 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 655 | messageLen := test.messageLen |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 656 | if messageLen < 0 { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 657 | if test.protocol == dtls { |
| 658 | return fmt.Errorf("messageLen < 0 not supported for DTLS tests") |
| 659 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 660 | // Read until EOF. |
| 661 | _, err := io.Copy(ioutil.Discard, tlsConn) |
| 662 | return err |
| 663 | } |
David Benjamin | 4417d05 | 2015-04-05 04:17:25 -0400 | [diff] [blame] | 664 | if messageLen == 0 { |
| 665 | messageLen = 32 |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 666 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 667 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 668 | messageCount := test.messageCount |
| 669 | if messageCount == 0 { |
| 670 | messageCount = 1 |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 671 | } |
| 672 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 673 | for j := 0; j < messageCount; j++ { |
| 674 | testMessage := make([]byte, messageLen) |
| 675 | for i := range testMessage { |
| 676 | testMessage[i] = 0x42 ^ byte(j) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 677 | } |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 678 | tlsConn.Write(testMessage) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 679 | |
Steven Valdez | 32635b8 | 2016-08-16 11:25:03 -0400 | [diff] [blame] | 680 | for i := 0; i < test.sendKeyUpdates; i++ { |
| 681 | tlsConn.SendKeyUpdate() |
| 682 | } |
| 683 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 684 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 685 | tlsConn.Write(nil) |
| 686 | } |
| 687 | |
| 688 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 689 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 690 | } |
| 691 | |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 692 | if test.shimShutsDown || test.expectMessageDropped { |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 693 | // The shim will not respond. |
| 694 | continue |
| 695 | } |
| 696 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 697 | buf := make([]byte, len(testMessage)) |
| 698 | if test.protocol == dtls { |
| 699 | bufTmp := make([]byte, len(buf)+1) |
| 700 | n, err := tlsConn.Read(bufTmp) |
| 701 | if err != nil { |
| 702 | return err |
| 703 | } |
| 704 | if n != len(buf) { |
| 705 | return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf)) |
| 706 | } |
| 707 | copy(buf, bufTmp) |
| 708 | } else { |
| 709 | _, err := io.ReadFull(tlsConn, buf) |
| 710 | if err != nil { |
| 711 | return err |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | for i, v := range buf { |
| 716 | if v != testMessage[i]^0xff { |
| 717 | return fmt.Errorf("bad reply contents at byte %d", i) |
| 718 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
| 722 | return nil |
| 723 | } |
| 724 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 725 | func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd { |
David Benjamin | d2ba889 | 2016-09-20 19:41:04 -0400 | [diff] [blame] | 726 | valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"} |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 727 | if dbAttach { |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 728 | 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] | 729 | } |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 730 | valgrindArgs = append(valgrindArgs, path) |
| 731 | valgrindArgs = append(valgrindArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 732 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 733 | return exec.Command("valgrind", valgrindArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 734 | } |
| 735 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 736 | func gdbOf(path string, args ...string) *exec.Cmd { |
| 737 | xtermArgs := []string{"-e", "gdb", "--args"} |
| 738 | xtermArgs = append(xtermArgs, path) |
| 739 | xtermArgs = append(xtermArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 740 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 741 | return exec.Command("xterm", xtermArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 742 | } |
| 743 | |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 744 | func lldbOf(path string, args ...string) *exec.Cmd { |
| 745 | xtermArgs := []string{"-e", "lldb", "--"} |
| 746 | xtermArgs = append(xtermArgs, path) |
| 747 | xtermArgs = append(xtermArgs, args...) |
| 748 | |
| 749 | return exec.Command("xterm", xtermArgs...) |
| 750 | } |
| 751 | |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 752 | var ( |
| 753 | errMoreMallocs = errors.New("child process did not exhaust all allocation calls") |
| 754 | errUnimplemented = errors.New("child process does not implement needed flags") |
| 755 | ) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 756 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 757 | // accept accepts a connection from listener, unless waitChan signals a process |
| 758 | // exit first. |
| 759 | func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) { |
| 760 | type connOrError struct { |
| 761 | conn net.Conn |
| 762 | err error |
| 763 | } |
| 764 | connChan := make(chan connOrError, 1) |
| 765 | go func() { |
| 766 | conn, err := listener.Accept() |
| 767 | connChan <- connOrError{conn, err} |
| 768 | close(connChan) |
| 769 | }() |
| 770 | select { |
| 771 | case result := <-connChan: |
| 772 | return result.conn, result.err |
| 773 | case childErr := <-waitChan: |
| 774 | waitChan <- childErr |
| 775 | return nil, fmt.Errorf("child exited early: %s", childErr) |
| 776 | } |
| 777 | } |
| 778 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 779 | func translateExpectedError(errorStr string) string { |
| 780 | if translated, ok := shimConfig.ErrorMap[errorStr]; ok { |
| 781 | return translated |
| 782 | } |
| 783 | |
| 784 | if *looseErrors { |
| 785 | return "" |
| 786 | } |
| 787 | |
| 788 | return errorStr |
| 789 | } |
| 790 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 791 | func runTest(test *testCase, shimPath string, mallocNumToFail int64) error { |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 792 | if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) { |
| 793 | panic("Error expected without shouldFail in " + test.name) |
| 794 | } |
| 795 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 796 | if test.expectResumeRejected && !test.resumeSession { |
| 797 | panic("expectResumeRejected without resumeSession in " + test.name) |
| 798 | } |
| 799 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 800 | listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}}) |
| 801 | if err != nil { |
| 802 | panic(err) |
| 803 | } |
| 804 | defer func() { |
| 805 | if listener != nil { |
| 806 | listener.Close() |
| 807 | } |
| 808 | }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 809 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 810 | flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)} |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 811 | if test.testType == serverTest { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 812 | flags = append(flags, "-server") |
| 813 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 814 | flags = append(flags, "-key-file") |
| 815 | if test.keyFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 816 | flags = append(flags, path.Join(*resourceDir, rsaKeyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 817 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 818 | flags = append(flags, path.Join(*resourceDir, test.keyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | flags = append(flags, "-cert-file") |
| 822 | if test.certFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 823 | flags = append(flags, path.Join(*resourceDir, rsaCertificateFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 824 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 825 | flags = append(flags, path.Join(*resourceDir, test.certFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 826 | } |
| 827 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 828 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 829 | if test.protocol == dtls { |
| 830 | flags = append(flags, "-dtls") |
| 831 | } |
| 832 | |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 833 | var resumeCount int |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 834 | if test.resumeSession { |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 835 | resumeCount++ |
| 836 | if test.resumeRenewedSession { |
| 837 | resumeCount++ |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | if resumeCount > 0 { |
| 842 | flags = append(flags, "-resume-count", strconv.Itoa(resumeCount)) |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 843 | } |
| 844 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 845 | if test.shimWritesFirst { |
| 846 | flags = append(flags, "-shim-writes-first") |
| 847 | } |
| 848 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 849 | if test.shimShutsDown { |
| 850 | flags = append(flags, "-shim-shuts-down") |
| 851 | } |
| 852 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 853 | if test.exportKeyingMaterial > 0 { |
| 854 | flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial)) |
| 855 | flags = append(flags, "-export-label", test.exportLabel) |
| 856 | flags = append(flags, "-export-context", test.exportContext) |
| 857 | if test.useExportContext { |
| 858 | flags = append(flags, "-use-export-context") |
| 859 | } |
| 860 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 861 | if test.expectResumeRejected { |
| 862 | flags = append(flags, "-expect-session-miss") |
| 863 | } |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 864 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 865 | if test.testTLSUnique { |
| 866 | flags = append(flags, "-tls-unique") |
| 867 | } |
| 868 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 869 | flags = append(flags, test.flags...) |
| 870 | |
| 871 | var shim *exec.Cmd |
| 872 | if *useValgrind { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 873 | shim = valgrindOf(false, shimPath, flags...) |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 874 | } else if *useGDB { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 875 | shim = gdbOf(shimPath, flags...) |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 876 | } else if *useLLDB { |
| 877 | shim = lldbOf(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 878 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 879 | shim = exec.Command(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 880 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 881 | shim.Stdin = os.Stdin |
| 882 | var stdoutBuf, stderrBuf bytes.Buffer |
| 883 | shim.Stdout = &stdoutBuf |
| 884 | shim.Stderr = &stderrBuf |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 885 | if mallocNumToFail >= 0 { |
David Benjamin | 9e128b0 | 2015-02-09 13:13:09 -0500 | [diff] [blame] | 886 | shim.Env = os.Environ() |
| 887 | 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] | 888 | if *mallocTestDebug { |
David Benjamin | 184494d | 2015-06-12 18:23:47 -0400 | [diff] [blame] | 889 | shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 890 | } |
| 891 | shim.Env = append(shim.Env, "_MALLOC_CHECK=1") |
| 892 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 893 | |
| 894 | if err := shim.Start(); err != nil { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 895 | panic(err) |
| 896 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 897 | waitChan := make(chan error, 1) |
| 898 | go func() { waitChan <- shim.Wait() }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 899 | |
| 900 | config := test.config |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 901 | |
David Benjamin | 7a4aaa4 | 2016-09-20 17:58:14 -0400 | [diff] [blame] | 902 | if *deterministic { |
| 903 | config.Rand = &deterministicRand{} |
| 904 | } |
| 905 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 906 | conn, err := acceptOrWait(listener, waitChan) |
| 907 | if err == nil { |
David Benjamin | c07afb7 | 2016-09-22 10:18:58 -0400 | [diff] [blame] | 908 | err = doExchange(test, &config, conn, false /* not a resumption */, 0) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 909 | conn.Close() |
| 910 | } |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 911 | |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 912 | for i := 0; err == nil && i < resumeCount; i++ { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 913 | var resumeConfig Config |
| 914 | if test.resumeConfig != nil { |
| 915 | resumeConfig = *test.resumeConfig |
David Benjamin | e54af06 | 2016-08-08 19:21:18 -0400 | [diff] [blame] | 916 | if !test.newSessionsOnResume { |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 917 | resumeConfig.SessionTicketKey = config.SessionTicketKey |
| 918 | resumeConfig.ClientSessionCache = config.ClientSessionCache |
| 919 | resumeConfig.ServerSessionCache = config.ServerSessionCache |
| 920 | } |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 921 | resumeConfig.Rand = config.Rand |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 922 | } else { |
| 923 | resumeConfig = config |
| 924 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 925 | var connResume net.Conn |
| 926 | connResume, err = acceptOrWait(listener, waitChan) |
| 927 | if err == nil { |
David Benjamin | c07afb7 | 2016-09-22 10:18:58 -0400 | [diff] [blame] | 928 | err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 929 | connResume.Close() |
| 930 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 931 | } |
| 932 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 933 | // Close the listener now. This is to avoid hangs should the shim try to |
| 934 | // open more connections than expected. |
| 935 | listener.Close() |
| 936 | listener = nil |
| 937 | |
| 938 | childErr := <-waitChan |
David Benjamin | d2ba889 | 2016-09-20 19:41:04 -0400 | [diff] [blame] | 939 | var isValgrindError bool |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 940 | if exitError, ok := childErr.(*exec.ExitError); ok { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 941 | switch exitError.Sys().(syscall.WaitStatus).ExitStatus() { |
| 942 | case 88: |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 943 | return errMoreMallocs |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 944 | case 89: |
| 945 | return errUnimplemented |
David Benjamin | d2ba889 | 2016-09-20 19:41:04 -0400 | [diff] [blame] | 946 | case 99: |
| 947 | isValgrindError = true |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 948 | } |
| 949 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 950 | |
David Benjamin | 9bea349 | 2016-03-02 10:59:16 -0500 | [diff] [blame] | 951 | // Account for Windows line endings. |
| 952 | stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1) |
| 953 | stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1) |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 954 | |
| 955 | // Separate the errors from the shim and those from tools like |
| 956 | // AddressSanitizer. |
| 957 | var extraStderr string |
| 958 | if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 { |
| 959 | stderr = stderrParts[0] |
| 960 | extraStderr = stderrParts[1] |
| 961 | } |
| 962 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 963 | failed := err != nil || childErr != nil |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 964 | expectedError := translateExpectedError(test.expectedError) |
| 965 | correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError) |
EKR | 173bf93 | 2016-07-29 15:52:49 +0200 | [diff] [blame] | 966 | |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 967 | localError := "none" |
| 968 | if err != nil { |
| 969 | localError = err.Error() |
| 970 | } |
| 971 | if len(test.expectedLocalError) != 0 { |
| 972 | correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError) |
| 973 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 974 | |
| 975 | if failed != test.shouldFail || failed && !correctFailure { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 976 | childError := "none" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 977 | if childErr != nil { |
| 978 | childError = childErr.Error() |
| 979 | } |
| 980 | |
| 981 | var msg string |
| 982 | switch { |
| 983 | case failed && !test.shouldFail: |
| 984 | msg = "unexpected failure" |
| 985 | case !failed && test.shouldFail: |
| 986 | msg = "unexpected success" |
| 987 | case failed && !correctFailure: |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 988 | msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 989 | default: |
| 990 | panic("internal error") |
| 991 | } |
| 992 | |
David Benjamin | 9aafb64 | 2016-09-20 19:36:53 -0400 | [diff] [blame] | 993 | return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 994 | } |
| 995 | |
David Benjamin | d2ba889 | 2016-09-20 19:41:04 -0400 | [diff] [blame] | 996 | if len(extraStderr) > 0 || (!failed && len(stderr) > 0) { |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 997 | return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 998 | } |
| 999 | |
David Benjamin | d2ba889 | 2016-09-20 19:41:04 -0400 | [diff] [blame] | 1000 | if *useValgrind && isValgrindError { |
| 1001 | return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr) |
| 1002 | } |
| 1003 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1004 | return nil |
| 1005 | } |
| 1006 | |
| 1007 | var tlsVersions = []struct { |
| 1008 | name string |
| 1009 | version uint16 |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 1010 | flag string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1011 | hasDTLS bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1012 | }{ |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1013 | {"SSL3", VersionSSL30, "-no-ssl3", false}, |
| 1014 | {"TLS1", VersionTLS10, "-no-tls1", true}, |
| 1015 | {"TLS11", VersionTLS11, "-no-tls11", false}, |
| 1016 | {"TLS12", VersionTLS12, "-no-tls12", true}, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1017 | {"TLS13", VersionTLS13, "-no-tls13", false}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | var testCipherSuites = []struct { |
| 1021 | name string |
| 1022 | id uint16 |
| 1023 | }{ |
| 1024 | {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1025 | {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1026 | {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1027 | {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1028 | {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1029 | {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1030 | {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1031 | {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1032 | {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1033 | {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1034 | {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384}, |
| 1035 | {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1036 | {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1037 | {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1038 | {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1039 | {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}, |
| 1040 | {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1041 | {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1042 | {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1043 | {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 1044 | {"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] | 1045 | {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1046 | {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1047 | {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1048 | {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1049 | {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1050 | {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1051 | {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 1052 | {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD}, |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 1053 | {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 1054 | {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 1055 | {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 1056 | {"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] | 1057 | {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 1058 | {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA}, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 1059 | {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 1060 | {"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] | 1061 | {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256}, |
Steven Valdez | 3084e7b | 2016-06-02 12:07:20 -0400 | [diff] [blame] | 1062 | {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256}, |
| 1063 | {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384}, |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1064 | {"NULL-SHA", TLS_RSA_WITH_NULL_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1067 | func hasComponent(suiteName, component string) bool { |
| 1068 | return strings.Contains("-"+suiteName+"-", "-"+component+"-") |
| 1069 | } |
| 1070 | |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1071 | func isTLS12Only(suiteName string) bool { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1072 | return hasComponent(suiteName, "GCM") || |
| 1073 | hasComponent(suiteName, "SHA256") || |
David Benjamin | e9a80ff | 2015-04-07 00:46:46 -0400 | [diff] [blame] | 1074 | hasComponent(suiteName, "SHA384") || |
| 1075 | hasComponent(suiteName, "POLY1305") |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1076 | } |
| 1077 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1078 | func isTLS13Suite(suiteName string) bool { |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 1079 | // Only AEADs. |
| 1080 | if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") { |
| 1081 | return false |
| 1082 | } |
| 1083 | // No old CHACHA20_POLY1305. |
| 1084 | if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") { |
| 1085 | return false |
| 1086 | } |
| 1087 | // Must have ECDHE. |
| 1088 | // TODO(davidben,svaldez): Add pure PSK support. |
| 1089 | if !hasComponent(suiteName, "ECDHE") { |
| 1090 | return false |
| 1091 | } |
| 1092 | // TODO(davidben,svaldez): Add PSK support. |
| 1093 | if hasComponent(suiteName, "PSK") { |
| 1094 | return false |
| 1095 | } |
| 1096 | return true |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1099 | func isDTLSCipher(suiteName string) bool { |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1100 | return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL") |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1101 | } |
| 1102 | |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 1103 | func bigFromHex(hex string) *big.Int { |
| 1104 | ret, ok := new(big.Int).SetString(hex, 16) |
| 1105 | if !ok { |
| 1106 | panic("failed to parse hex number 0x" + hex) |
| 1107 | } |
| 1108 | return ret |
| 1109 | } |
| 1110 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1111 | func addBasicTests() { |
| 1112 | basicTests := []testCase{ |
| 1113 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1114 | name: "NoFallbackSCSV", |
| 1115 | config: Config{ |
| 1116 | Bugs: ProtocolBugs{ |
| 1117 | FailIfNotFallbackSCSV: true, |
| 1118 | }, |
| 1119 | }, |
| 1120 | shouldFail: true, |
| 1121 | expectedLocalError: "no fallback SCSV found", |
| 1122 | }, |
| 1123 | { |
| 1124 | name: "SendFallbackSCSV", |
| 1125 | config: Config{ |
| 1126 | Bugs: ProtocolBugs{ |
| 1127 | FailIfNotFallbackSCSV: true, |
| 1128 | }, |
| 1129 | }, |
| 1130 | flags: []string{"-fallback-scsv"}, |
| 1131 | }, |
| 1132 | { |
| 1133 | name: "ClientCertificateTypes", |
| 1134 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1135 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1136 | ClientAuth: RequestClientCert, |
| 1137 | ClientCertificateTypes: []byte{ |
| 1138 | CertTypeDSSSign, |
| 1139 | CertTypeRSASign, |
| 1140 | CertTypeECDSASign, |
| 1141 | }, |
| 1142 | }, |
| 1143 | flags: []string{ |
| 1144 | "-expect-certificate-types", |
| 1145 | base64.StdEncoding.EncodeToString([]byte{ |
| 1146 | CertTypeDSSSign, |
| 1147 | CertTypeRSASign, |
| 1148 | CertTypeECDSASign, |
| 1149 | }), |
| 1150 | }, |
| 1151 | }, |
| 1152 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1153 | name: "UnauthenticatedECDH", |
| 1154 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1155 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1156 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1157 | Bugs: ProtocolBugs{ |
| 1158 | UnauthenticatedECDH: true, |
| 1159 | }, |
| 1160 | }, |
| 1161 | shouldFail: true, |
| 1162 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1163 | }, |
| 1164 | { |
| 1165 | name: "SkipCertificateStatus", |
| 1166 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1167 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1168 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1169 | Bugs: ProtocolBugs{ |
| 1170 | SkipCertificateStatus: true, |
| 1171 | }, |
| 1172 | }, |
| 1173 | flags: []string{ |
| 1174 | "-enable-ocsp-stapling", |
| 1175 | }, |
| 1176 | }, |
| 1177 | { |
| 1178 | name: "SkipServerKeyExchange", |
| 1179 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1180 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1181 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1182 | Bugs: ProtocolBugs{ |
| 1183 | SkipServerKeyExchange: true, |
| 1184 | }, |
| 1185 | }, |
| 1186 | shouldFail: true, |
| 1187 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1188 | }, |
| 1189 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1190 | testType: serverTest, |
| 1191 | name: "Alert", |
| 1192 | config: Config{ |
| 1193 | Bugs: ProtocolBugs{ |
| 1194 | SendSpuriousAlert: alertRecordOverflow, |
| 1195 | }, |
| 1196 | }, |
| 1197 | shouldFail: true, |
| 1198 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1199 | }, |
| 1200 | { |
| 1201 | protocol: dtls, |
| 1202 | testType: serverTest, |
| 1203 | name: "Alert-DTLS", |
| 1204 | config: Config{ |
| 1205 | Bugs: ProtocolBugs{ |
| 1206 | SendSpuriousAlert: alertRecordOverflow, |
| 1207 | }, |
| 1208 | }, |
| 1209 | shouldFail: true, |
| 1210 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1211 | }, |
| 1212 | { |
| 1213 | testType: serverTest, |
| 1214 | name: "FragmentAlert", |
| 1215 | config: Config{ |
| 1216 | Bugs: ProtocolBugs{ |
| 1217 | FragmentAlert: true, |
| 1218 | SendSpuriousAlert: alertRecordOverflow, |
| 1219 | }, |
| 1220 | }, |
| 1221 | shouldFail: true, |
| 1222 | expectedError: ":BAD_ALERT:", |
| 1223 | }, |
| 1224 | { |
| 1225 | protocol: dtls, |
| 1226 | testType: serverTest, |
| 1227 | name: "FragmentAlert-DTLS", |
| 1228 | config: Config{ |
| 1229 | Bugs: ProtocolBugs{ |
| 1230 | FragmentAlert: true, |
| 1231 | SendSpuriousAlert: alertRecordOverflow, |
| 1232 | }, |
| 1233 | }, |
| 1234 | shouldFail: true, |
| 1235 | expectedError: ":BAD_ALERT:", |
| 1236 | }, |
| 1237 | { |
| 1238 | testType: serverTest, |
David Benjamin | 0d3a8c6 | 2016-03-11 22:25:18 -0500 | [diff] [blame] | 1239 | name: "DoubleAlert", |
| 1240 | config: Config{ |
| 1241 | Bugs: ProtocolBugs{ |
| 1242 | DoubleAlert: true, |
| 1243 | SendSpuriousAlert: alertRecordOverflow, |
| 1244 | }, |
| 1245 | }, |
| 1246 | shouldFail: true, |
| 1247 | expectedError: ":BAD_ALERT:", |
| 1248 | }, |
| 1249 | { |
| 1250 | protocol: dtls, |
| 1251 | testType: serverTest, |
| 1252 | name: "DoubleAlert-DTLS", |
| 1253 | config: Config{ |
| 1254 | Bugs: ProtocolBugs{ |
| 1255 | DoubleAlert: true, |
| 1256 | SendSpuriousAlert: alertRecordOverflow, |
| 1257 | }, |
| 1258 | }, |
| 1259 | shouldFail: true, |
| 1260 | expectedError: ":BAD_ALERT:", |
| 1261 | }, |
| 1262 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1263 | name: "SkipNewSessionTicket", |
| 1264 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1265 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1266 | Bugs: ProtocolBugs{ |
| 1267 | SkipNewSessionTicket: true, |
| 1268 | }, |
| 1269 | }, |
| 1270 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1271 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1272 | }, |
| 1273 | { |
| 1274 | testType: serverTest, |
| 1275 | name: "FallbackSCSV", |
| 1276 | config: Config{ |
| 1277 | MaxVersion: VersionTLS11, |
| 1278 | Bugs: ProtocolBugs{ |
| 1279 | SendFallbackSCSV: true, |
| 1280 | }, |
| 1281 | }, |
| 1282 | shouldFail: true, |
| 1283 | expectedError: ":INAPPROPRIATE_FALLBACK:", |
| 1284 | }, |
| 1285 | { |
| 1286 | testType: serverTest, |
| 1287 | name: "FallbackSCSV-VersionMatch", |
| 1288 | config: Config{ |
| 1289 | Bugs: ProtocolBugs{ |
| 1290 | SendFallbackSCSV: true, |
| 1291 | }, |
| 1292 | }, |
| 1293 | }, |
| 1294 | { |
| 1295 | testType: serverTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1296 | name: "FallbackSCSV-VersionMatch-TLS12", |
| 1297 | config: Config{ |
| 1298 | MaxVersion: VersionTLS12, |
| 1299 | Bugs: ProtocolBugs{ |
| 1300 | SendFallbackSCSV: true, |
| 1301 | }, |
| 1302 | }, |
| 1303 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 1304 | }, |
| 1305 | { |
| 1306 | testType: serverTest, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1307 | name: "FragmentedClientVersion", |
| 1308 | config: Config{ |
| 1309 | Bugs: ProtocolBugs{ |
| 1310 | MaxHandshakeRecordLength: 1, |
| 1311 | FragmentClientVersion: true, |
| 1312 | }, |
| 1313 | }, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1314 | expectedVersion: VersionTLS13, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1315 | }, |
| 1316 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1317 | testType: serverTest, |
| 1318 | name: "HttpGET", |
| 1319 | sendPrefix: "GET / HTTP/1.0\n", |
| 1320 | shouldFail: true, |
| 1321 | expectedError: ":HTTP_REQUEST:", |
| 1322 | }, |
| 1323 | { |
| 1324 | testType: serverTest, |
| 1325 | name: "HttpPOST", |
| 1326 | sendPrefix: "POST / HTTP/1.0\n", |
| 1327 | shouldFail: true, |
| 1328 | expectedError: ":HTTP_REQUEST:", |
| 1329 | }, |
| 1330 | { |
| 1331 | testType: serverTest, |
| 1332 | name: "HttpHEAD", |
| 1333 | sendPrefix: "HEAD / HTTP/1.0\n", |
| 1334 | shouldFail: true, |
| 1335 | expectedError: ":HTTP_REQUEST:", |
| 1336 | }, |
| 1337 | { |
| 1338 | testType: serverTest, |
| 1339 | name: "HttpPUT", |
| 1340 | sendPrefix: "PUT / HTTP/1.0\n", |
| 1341 | shouldFail: true, |
| 1342 | expectedError: ":HTTP_REQUEST:", |
| 1343 | }, |
| 1344 | { |
| 1345 | testType: serverTest, |
| 1346 | name: "HttpCONNECT", |
| 1347 | sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n", |
| 1348 | shouldFail: true, |
| 1349 | expectedError: ":HTTPS_PROXY_REQUEST:", |
| 1350 | }, |
| 1351 | { |
| 1352 | testType: serverTest, |
| 1353 | name: "Garbage", |
| 1354 | sendPrefix: "blah", |
| 1355 | shouldFail: true, |
David Benjamin | 97760d5 | 2015-07-24 23:02:49 -0400 | [diff] [blame] | 1356 | expectedError: ":WRONG_VERSION_NUMBER:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1357 | }, |
| 1358 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1359 | name: "RSAEphemeralKey", |
| 1360 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1361 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1362 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 1363 | Bugs: ProtocolBugs{ |
| 1364 | RSAEphemeralKey: true, |
| 1365 | }, |
| 1366 | }, |
| 1367 | shouldFail: true, |
| 1368 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1369 | }, |
| 1370 | { |
| 1371 | name: "DisableEverything", |
Steven Valdez | 4f94b1c | 2016-05-24 12:31:07 -0400 | [diff] [blame] | 1372 | flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1373 | shouldFail: true, |
| 1374 | expectedError: ":WRONG_SSL_VERSION:", |
| 1375 | }, |
| 1376 | { |
| 1377 | protocol: dtls, |
| 1378 | name: "DisableEverything-DTLS", |
| 1379 | flags: []string{"-no-tls12", "-no-tls1"}, |
| 1380 | shouldFail: true, |
| 1381 | expectedError: ":WRONG_SSL_VERSION:", |
| 1382 | }, |
| 1383 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1384 | protocol: dtls, |
| 1385 | testType: serverTest, |
| 1386 | name: "MTU", |
| 1387 | config: Config{ |
| 1388 | Bugs: ProtocolBugs{ |
| 1389 | MaxPacketLength: 256, |
| 1390 | }, |
| 1391 | }, |
| 1392 | flags: []string{"-mtu", "256"}, |
| 1393 | }, |
| 1394 | { |
| 1395 | protocol: dtls, |
| 1396 | testType: serverTest, |
| 1397 | name: "MTUExceeded", |
| 1398 | config: Config{ |
| 1399 | Bugs: ProtocolBugs{ |
| 1400 | MaxPacketLength: 255, |
| 1401 | }, |
| 1402 | }, |
| 1403 | flags: []string{"-mtu", "256"}, |
| 1404 | shouldFail: true, |
| 1405 | expectedLocalError: "dtls: exceeded maximum packet length", |
| 1406 | }, |
| 1407 | { |
| 1408 | name: "CertMismatchRSA", |
| 1409 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1410 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1411 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1412 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1413 | Bugs: ProtocolBugs{ |
| 1414 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1415 | }, |
| 1416 | }, |
| 1417 | shouldFail: true, |
| 1418 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1419 | }, |
| 1420 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1421 | name: "CertMismatchRSA-TLS13", |
| 1422 | config: Config{ |
| 1423 | MaxVersion: VersionTLS13, |
| 1424 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1425 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 1426 | Bugs: ProtocolBugs{ |
| 1427 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1428 | }, |
| 1429 | }, |
| 1430 | shouldFail: true, |
| 1431 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1432 | }, |
| 1433 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1434 | name: "CertMismatchECDSA", |
| 1435 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1436 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1437 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1438 | Certificates: []Certificate{rsaCertificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1439 | Bugs: ProtocolBugs{ |
| 1440 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1441 | }, |
| 1442 | }, |
| 1443 | shouldFail: true, |
| 1444 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1445 | }, |
| 1446 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1447 | name: "CertMismatchECDSA-TLS13", |
| 1448 | config: Config{ |
| 1449 | MaxVersion: VersionTLS13, |
| 1450 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1451 | Certificates: []Certificate{rsaCertificate}, |
| 1452 | Bugs: ProtocolBugs{ |
| 1453 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1454 | }, |
| 1455 | }, |
| 1456 | shouldFail: true, |
| 1457 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1458 | }, |
| 1459 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1460 | name: "EmptyCertificateList", |
| 1461 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1462 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1463 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1464 | Bugs: ProtocolBugs{ |
| 1465 | EmptyCertificateList: true, |
| 1466 | }, |
| 1467 | }, |
| 1468 | shouldFail: true, |
| 1469 | expectedError: ":DECODE_ERROR:", |
| 1470 | }, |
| 1471 | { |
David Benjamin | 9ec1c75 | 2016-07-14 12:45:01 -0400 | [diff] [blame] | 1472 | name: "EmptyCertificateList-TLS13", |
| 1473 | config: Config{ |
| 1474 | MaxVersion: VersionTLS13, |
| 1475 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1476 | Bugs: ProtocolBugs{ |
| 1477 | EmptyCertificateList: true, |
| 1478 | }, |
| 1479 | }, |
| 1480 | shouldFail: true, |
David Benjamin | 4087df9 | 2016-08-01 20:16:31 -0400 | [diff] [blame] | 1481 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
David Benjamin | 9ec1c75 | 2016-07-14 12:45:01 -0400 | [diff] [blame] | 1482 | }, |
| 1483 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1484 | name: "TLSFatalBadPackets", |
| 1485 | damageFirstWrite: true, |
| 1486 | shouldFail: true, |
| 1487 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 1488 | }, |
| 1489 | { |
| 1490 | protocol: dtls, |
| 1491 | name: "DTLSIgnoreBadPackets", |
| 1492 | damageFirstWrite: true, |
| 1493 | }, |
| 1494 | { |
| 1495 | protocol: dtls, |
| 1496 | name: "DTLSIgnoreBadPackets-Async", |
| 1497 | damageFirstWrite: true, |
| 1498 | flags: []string{"-async"}, |
| 1499 | }, |
| 1500 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1501 | name: "AppDataBeforeHandshake", |
| 1502 | config: Config{ |
| 1503 | Bugs: ProtocolBugs{ |
| 1504 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1505 | }, |
| 1506 | }, |
| 1507 | shouldFail: true, |
| 1508 | expectedError: ":UNEXPECTED_RECORD:", |
| 1509 | }, |
| 1510 | { |
| 1511 | name: "AppDataBeforeHandshake-Empty", |
| 1512 | config: Config{ |
| 1513 | Bugs: ProtocolBugs{ |
| 1514 | AppDataBeforeHandshake: []byte{}, |
| 1515 | }, |
| 1516 | }, |
| 1517 | shouldFail: true, |
| 1518 | expectedError: ":UNEXPECTED_RECORD:", |
| 1519 | }, |
| 1520 | { |
| 1521 | protocol: dtls, |
| 1522 | name: "AppDataBeforeHandshake-DTLS", |
| 1523 | config: Config{ |
| 1524 | Bugs: ProtocolBugs{ |
| 1525 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1526 | }, |
| 1527 | }, |
| 1528 | shouldFail: true, |
| 1529 | expectedError: ":UNEXPECTED_RECORD:", |
| 1530 | }, |
| 1531 | { |
| 1532 | protocol: dtls, |
| 1533 | name: "AppDataBeforeHandshake-DTLS-Empty", |
| 1534 | config: Config{ |
| 1535 | Bugs: ProtocolBugs{ |
| 1536 | AppDataBeforeHandshake: []byte{}, |
| 1537 | }, |
| 1538 | }, |
| 1539 | shouldFail: true, |
| 1540 | expectedError: ":UNEXPECTED_RECORD:", |
| 1541 | }, |
| 1542 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1543 | name: "AppDataAfterChangeCipherSpec", |
| 1544 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1545 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1546 | Bugs: ProtocolBugs{ |
| 1547 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1548 | }, |
| 1549 | }, |
| 1550 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1551 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1552 | }, |
| 1553 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1554 | name: "AppDataAfterChangeCipherSpec-Empty", |
| 1555 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1556 | MaxVersion: VersionTLS12, |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1557 | Bugs: ProtocolBugs{ |
| 1558 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1559 | }, |
| 1560 | }, |
| 1561 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1562 | expectedError: ":UNEXPECTED_RECORD:", |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1563 | }, |
| 1564 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1565 | protocol: dtls, |
| 1566 | name: "AppDataAfterChangeCipherSpec-DTLS", |
| 1567 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1568 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1569 | Bugs: ProtocolBugs{ |
| 1570 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1571 | }, |
| 1572 | }, |
| 1573 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1574 | // application data. |
| 1575 | }, |
| 1576 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1577 | protocol: dtls, |
| 1578 | name: "AppDataAfterChangeCipherSpec-DTLS-Empty", |
| 1579 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1580 | MaxVersion: VersionTLS12, |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1581 | Bugs: ProtocolBugs{ |
| 1582 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1583 | }, |
| 1584 | }, |
| 1585 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1586 | // application data. |
| 1587 | }, |
| 1588 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1589 | name: "AlertAfterChangeCipherSpec", |
| 1590 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1591 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1592 | Bugs: ProtocolBugs{ |
| 1593 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1594 | }, |
| 1595 | }, |
| 1596 | shouldFail: true, |
| 1597 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1598 | }, |
| 1599 | { |
| 1600 | protocol: dtls, |
| 1601 | name: "AlertAfterChangeCipherSpec-DTLS", |
| 1602 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1603 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1604 | Bugs: ProtocolBugs{ |
| 1605 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1606 | }, |
| 1607 | }, |
| 1608 | shouldFail: true, |
| 1609 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1610 | }, |
| 1611 | { |
| 1612 | protocol: dtls, |
| 1613 | name: "ReorderHandshakeFragments-Small-DTLS", |
| 1614 | config: Config{ |
| 1615 | Bugs: ProtocolBugs{ |
| 1616 | ReorderHandshakeFragments: true, |
| 1617 | // Small enough that every handshake message is |
| 1618 | // fragmented. |
| 1619 | MaxHandshakeRecordLength: 2, |
| 1620 | }, |
| 1621 | }, |
| 1622 | }, |
| 1623 | { |
| 1624 | protocol: dtls, |
| 1625 | name: "ReorderHandshakeFragments-Large-DTLS", |
| 1626 | config: Config{ |
| 1627 | Bugs: ProtocolBugs{ |
| 1628 | ReorderHandshakeFragments: true, |
| 1629 | // Large enough that no handshake message is |
| 1630 | // fragmented. |
| 1631 | MaxHandshakeRecordLength: 2048, |
| 1632 | }, |
| 1633 | }, |
| 1634 | }, |
| 1635 | { |
| 1636 | protocol: dtls, |
| 1637 | name: "MixCompleteMessageWithFragments-DTLS", |
| 1638 | config: Config{ |
| 1639 | Bugs: ProtocolBugs{ |
| 1640 | ReorderHandshakeFragments: true, |
| 1641 | MixCompleteMessageWithFragments: true, |
| 1642 | MaxHandshakeRecordLength: 2, |
| 1643 | }, |
| 1644 | }, |
| 1645 | }, |
| 1646 | { |
| 1647 | name: "SendInvalidRecordType", |
| 1648 | config: Config{ |
| 1649 | Bugs: ProtocolBugs{ |
| 1650 | SendInvalidRecordType: true, |
| 1651 | }, |
| 1652 | }, |
| 1653 | shouldFail: true, |
| 1654 | expectedError: ":UNEXPECTED_RECORD:", |
| 1655 | }, |
| 1656 | { |
| 1657 | protocol: dtls, |
| 1658 | name: "SendInvalidRecordType-DTLS", |
| 1659 | config: Config{ |
| 1660 | Bugs: ProtocolBugs{ |
| 1661 | SendInvalidRecordType: true, |
| 1662 | }, |
| 1663 | }, |
| 1664 | shouldFail: true, |
| 1665 | expectedError: ":UNEXPECTED_RECORD:", |
| 1666 | }, |
| 1667 | { |
| 1668 | name: "FalseStart-SkipServerSecondLeg", |
| 1669 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1670 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1671 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1672 | NextProtos: []string{"foo"}, |
| 1673 | Bugs: ProtocolBugs{ |
| 1674 | SkipNewSessionTicket: true, |
| 1675 | SkipChangeCipherSpec: true, |
| 1676 | SkipFinished: true, |
| 1677 | ExpectFalseStart: true, |
| 1678 | }, |
| 1679 | }, |
| 1680 | flags: []string{ |
| 1681 | "-false-start", |
| 1682 | "-handshake-never-done", |
| 1683 | "-advertise-alpn", "\x03foo", |
| 1684 | }, |
| 1685 | shimWritesFirst: true, |
| 1686 | shouldFail: true, |
| 1687 | expectedError: ":UNEXPECTED_RECORD:", |
| 1688 | }, |
| 1689 | { |
| 1690 | name: "FalseStart-SkipServerSecondLeg-Implicit", |
| 1691 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1692 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1693 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1694 | NextProtos: []string{"foo"}, |
| 1695 | Bugs: ProtocolBugs{ |
| 1696 | SkipNewSessionTicket: true, |
| 1697 | SkipChangeCipherSpec: true, |
| 1698 | SkipFinished: true, |
| 1699 | }, |
| 1700 | }, |
| 1701 | flags: []string{ |
| 1702 | "-implicit-handshake", |
| 1703 | "-false-start", |
| 1704 | "-handshake-never-done", |
| 1705 | "-advertise-alpn", "\x03foo", |
| 1706 | }, |
| 1707 | shouldFail: true, |
| 1708 | expectedError: ":UNEXPECTED_RECORD:", |
| 1709 | }, |
| 1710 | { |
| 1711 | testType: serverTest, |
| 1712 | name: "FailEarlyCallback", |
| 1713 | flags: []string{"-fail-early-callback"}, |
| 1714 | shouldFail: true, |
| 1715 | expectedError: ":CONNECTION_REJECTED:", |
David Benjamin | 2c66e07 | 2016-09-16 15:58:00 -0400 | [diff] [blame] | 1716 | expectedLocalError: "remote error: handshake failure", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1717 | }, |
| 1718 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1719 | protocol: dtls, |
| 1720 | name: "FragmentMessageTypeMismatch-DTLS", |
| 1721 | config: Config{ |
| 1722 | Bugs: ProtocolBugs{ |
| 1723 | MaxHandshakeRecordLength: 2, |
| 1724 | FragmentMessageTypeMismatch: true, |
| 1725 | }, |
| 1726 | }, |
| 1727 | shouldFail: true, |
| 1728 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1729 | }, |
| 1730 | { |
| 1731 | protocol: dtls, |
| 1732 | name: "FragmentMessageLengthMismatch-DTLS", |
| 1733 | config: Config{ |
| 1734 | Bugs: ProtocolBugs{ |
| 1735 | MaxHandshakeRecordLength: 2, |
| 1736 | FragmentMessageLengthMismatch: true, |
| 1737 | }, |
| 1738 | }, |
| 1739 | shouldFail: true, |
| 1740 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1741 | }, |
| 1742 | { |
| 1743 | protocol: dtls, |
| 1744 | name: "SplitFragments-Header-DTLS", |
| 1745 | config: Config{ |
| 1746 | Bugs: ProtocolBugs{ |
| 1747 | SplitFragments: 2, |
| 1748 | }, |
| 1749 | }, |
| 1750 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1751 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1752 | }, |
| 1753 | { |
| 1754 | protocol: dtls, |
| 1755 | name: "SplitFragments-Boundary-DTLS", |
| 1756 | config: Config{ |
| 1757 | Bugs: ProtocolBugs{ |
| 1758 | SplitFragments: dtlsRecordHeaderLen, |
| 1759 | }, |
| 1760 | }, |
| 1761 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1762 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1763 | }, |
| 1764 | { |
| 1765 | protocol: dtls, |
| 1766 | name: "SplitFragments-Body-DTLS", |
| 1767 | config: Config{ |
| 1768 | Bugs: ProtocolBugs{ |
| 1769 | SplitFragments: dtlsRecordHeaderLen + 1, |
| 1770 | }, |
| 1771 | }, |
| 1772 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1773 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1774 | }, |
| 1775 | { |
| 1776 | protocol: dtls, |
| 1777 | name: "SendEmptyFragments-DTLS", |
| 1778 | config: Config{ |
| 1779 | Bugs: ProtocolBugs{ |
| 1780 | SendEmptyFragments: true, |
| 1781 | }, |
| 1782 | }, |
| 1783 | }, |
| 1784 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1785 | name: "BadFinished-Client", |
| 1786 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1787 | MaxVersion: VersionTLS12, |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1788 | Bugs: ProtocolBugs{ |
| 1789 | BadFinished: true, |
| 1790 | }, |
| 1791 | }, |
| 1792 | shouldFail: true, |
| 1793 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1794 | }, |
| 1795 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1796 | name: "BadFinished-Client-TLS13", |
| 1797 | config: Config{ |
| 1798 | MaxVersion: VersionTLS13, |
| 1799 | Bugs: ProtocolBugs{ |
| 1800 | BadFinished: true, |
| 1801 | }, |
| 1802 | }, |
| 1803 | shouldFail: true, |
| 1804 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1805 | }, |
| 1806 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1807 | testType: serverTest, |
| 1808 | name: "BadFinished-Server", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1809 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1810 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1811 | Bugs: ProtocolBugs{ |
| 1812 | BadFinished: true, |
| 1813 | }, |
| 1814 | }, |
| 1815 | shouldFail: true, |
| 1816 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1817 | }, |
| 1818 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1819 | testType: serverTest, |
| 1820 | name: "BadFinished-Server-TLS13", |
| 1821 | config: Config{ |
| 1822 | MaxVersion: VersionTLS13, |
| 1823 | Bugs: ProtocolBugs{ |
| 1824 | BadFinished: true, |
| 1825 | }, |
| 1826 | }, |
| 1827 | shouldFail: true, |
| 1828 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1829 | }, |
| 1830 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1831 | name: "FalseStart-BadFinished", |
| 1832 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1833 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1834 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1835 | NextProtos: []string{"foo"}, |
| 1836 | Bugs: ProtocolBugs{ |
| 1837 | BadFinished: true, |
| 1838 | ExpectFalseStart: true, |
| 1839 | }, |
| 1840 | }, |
| 1841 | flags: []string{ |
| 1842 | "-false-start", |
| 1843 | "-handshake-never-done", |
| 1844 | "-advertise-alpn", "\x03foo", |
| 1845 | }, |
| 1846 | shimWritesFirst: true, |
| 1847 | shouldFail: true, |
| 1848 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1849 | }, |
| 1850 | { |
| 1851 | name: "NoFalseStart-NoALPN", |
| 1852 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1853 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1854 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1855 | Bugs: ProtocolBugs{ |
| 1856 | ExpectFalseStart: true, |
| 1857 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1858 | }, |
| 1859 | }, |
| 1860 | flags: []string{ |
| 1861 | "-false-start", |
| 1862 | }, |
| 1863 | shimWritesFirst: true, |
| 1864 | shouldFail: true, |
| 1865 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1866 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1867 | }, |
| 1868 | { |
| 1869 | name: "NoFalseStart-NoAEAD", |
| 1870 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1871 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1872 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1873 | NextProtos: []string{"foo"}, |
| 1874 | Bugs: ProtocolBugs{ |
| 1875 | ExpectFalseStart: true, |
| 1876 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1877 | }, |
| 1878 | }, |
| 1879 | flags: []string{ |
| 1880 | "-false-start", |
| 1881 | "-advertise-alpn", "\x03foo", |
| 1882 | }, |
| 1883 | shimWritesFirst: true, |
| 1884 | shouldFail: true, |
| 1885 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1886 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1887 | }, |
| 1888 | { |
| 1889 | name: "NoFalseStart-RSA", |
| 1890 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1891 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1892 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1893 | NextProtos: []string{"foo"}, |
| 1894 | Bugs: ProtocolBugs{ |
| 1895 | ExpectFalseStart: true, |
| 1896 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1897 | }, |
| 1898 | }, |
| 1899 | flags: []string{ |
| 1900 | "-false-start", |
| 1901 | "-advertise-alpn", "\x03foo", |
| 1902 | }, |
| 1903 | shimWritesFirst: true, |
| 1904 | shouldFail: true, |
| 1905 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1906 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1907 | }, |
| 1908 | { |
| 1909 | name: "NoFalseStart-DHE_RSA", |
| 1910 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1911 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1912 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1913 | NextProtos: []string{"foo"}, |
| 1914 | Bugs: ProtocolBugs{ |
| 1915 | ExpectFalseStart: true, |
| 1916 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1917 | }, |
| 1918 | }, |
| 1919 | flags: []string{ |
| 1920 | "-false-start", |
| 1921 | "-advertise-alpn", "\x03foo", |
| 1922 | }, |
| 1923 | shimWritesFirst: true, |
| 1924 | shouldFail: true, |
| 1925 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1926 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1927 | }, |
| 1928 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1929 | protocol: dtls, |
| 1930 | name: "SendSplitAlert-Sync", |
| 1931 | config: Config{ |
| 1932 | Bugs: ProtocolBugs{ |
| 1933 | SendSplitAlert: true, |
| 1934 | }, |
| 1935 | }, |
| 1936 | }, |
| 1937 | { |
| 1938 | protocol: dtls, |
| 1939 | name: "SendSplitAlert-Async", |
| 1940 | config: Config{ |
| 1941 | Bugs: ProtocolBugs{ |
| 1942 | SendSplitAlert: true, |
| 1943 | }, |
| 1944 | }, |
| 1945 | flags: []string{"-async"}, |
| 1946 | }, |
| 1947 | { |
| 1948 | protocol: dtls, |
| 1949 | name: "PackDTLSHandshake", |
| 1950 | config: Config{ |
| 1951 | Bugs: ProtocolBugs{ |
| 1952 | MaxHandshakeRecordLength: 2, |
| 1953 | PackHandshakeFragments: 20, |
| 1954 | PackHandshakeRecords: 200, |
| 1955 | }, |
| 1956 | }, |
| 1957 | }, |
| 1958 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1959 | name: "SendEmptyRecords-Pass", |
| 1960 | sendEmptyRecords: 32, |
| 1961 | }, |
| 1962 | { |
| 1963 | name: "SendEmptyRecords", |
| 1964 | sendEmptyRecords: 33, |
| 1965 | shouldFail: true, |
| 1966 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1967 | }, |
| 1968 | { |
| 1969 | name: "SendEmptyRecords-Async", |
| 1970 | sendEmptyRecords: 33, |
| 1971 | flags: []string{"-async"}, |
| 1972 | shouldFail: true, |
| 1973 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1974 | }, |
| 1975 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 1976 | name: "SendWarningAlerts-Pass", |
| 1977 | config: Config{ |
| 1978 | MaxVersion: VersionTLS12, |
| 1979 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1980 | sendWarningAlerts: 4, |
| 1981 | }, |
| 1982 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 1983 | protocol: dtls, |
| 1984 | name: "SendWarningAlerts-DTLS-Pass", |
| 1985 | config: Config{ |
| 1986 | MaxVersion: VersionTLS12, |
| 1987 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1988 | sendWarningAlerts: 4, |
| 1989 | }, |
| 1990 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 1991 | name: "SendWarningAlerts-TLS13", |
| 1992 | config: Config{ |
| 1993 | MaxVersion: VersionTLS13, |
| 1994 | }, |
| 1995 | sendWarningAlerts: 4, |
| 1996 | shouldFail: true, |
| 1997 | expectedError: ":BAD_ALERT:", |
| 1998 | expectedLocalError: "remote error: error decoding message", |
| 1999 | }, |
| 2000 | { |
| 2001 | name: "SendWarningAlerts", |
| 2002 | config: Config{ |
| 2003 | MaxVersion: VersionTLS12, |
| 2004 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2005 | sendWarningAlerts: 5, |
| 2006 | shouldFail: true, |
| 2007 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 2008 | }, |
| 2009 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 2010 | name: "SendWarningAlerts-Async", |
| 2011 | config: Config{ |
| 2012 | MaxVersion: VersionTLS12, |
| 2013 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2014 | sendWarningAlerts: 5, |
| 2015 | flags: []string{"-async"}, |
| 2016 | shouldFail: true, |
| 2017 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 2018 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 2019 | { |
Steven Valdez | 32635b8 | 2016-08-16 11:25:03 -0400 | [diff] [blame] | 2020 | name: "SendKeyUpdates", |
| 2021 | config: Config{ |
| 2022 | MaxVersion: VersionTLS13, |
| 2023 | }, |
| 2024 | sendKeyUpdates: 33, |
| 2025 | shouldFail: true, |
| 2026 | expectedError: ":TOO_MANY_KEY_UPDATES:", |
| 2027 | }, |
| 2028 | { |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 2029 | name: "EmptySessionID", |
| 2030 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2031 | MaxVersion: VersionTLS12, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 2032 | SessionTicketsDisabled: true, |
| 2033 | }, |
| 2034 | noSessionCache: true, |
| 2035 | flags: []string{"-expect-no-session"}, |
| 2036 | }, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 2037 | { |
| 2038 | name: "Unclean-Shutdown", |
| 2039 | config: Config{ |
| 2040 | Bugs: ProtocolBugs{ |
| 2041 | NoCloseNotify: true, |
| 2042 | ExpectCloseNotify: true, |
| 2043 | }, |
| 2044 | }, |
| 2045 | shimShutsDown: true, |
| 2046 | flags: []string{"-check-close-notify"}, |
| 2047 | shouldFail: true, |
| 2048 | expectedError: "Unexpected SSL_shutdown result: -1 != 1", |
| 2049 | }, |
| 2050 | { |
| 2051 | name: "Unclean-Shutdown-Ignored", |
| 2052 | config: Config{ |
| 2053 | Bugs: ProtocolBugs{ |
| 2054 | NoCloseNotify: true, |
| 2055 | }, |
| 2056 | }, |
| 2057 | shimShutsDown: true, |
| 2058 | }, |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 2059 | { |
David Benjamin | fa214e4 | 2016-05-10 17:03:10 -0400 | [diff] [blame] | 2060 | name: "Unclean-Shutdown-Alert", |
| 2061 | config: Config{ |
| 2062 | Bugs: ProtocolBugs{ |
| 2063 | SendAlertOnShutdown: alertDecompressionFailure, |
| 2064 | ExpectCloseNotify: true, |
| 2065 | }, |
| 2066 | }, |
| 2067 | shimShutsDown: true, |
| 2068 | flags: []string{"-check-close-notify"}, |
| 2069 | shouldFail: true, |
| 2070 | expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:", |
| 2071 | }, |
| 2072 | { |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 2073 | name: "LargePlaintext", |
| 2074 | config: Config{ |
| 2075 | Bugs: ProtocolBugs{ |
| 2076 | SendLargeRecords: true, |
| 2077 | }, |
| 2078 | }, |
| 2079 | messageLen: maxPlaintext + 1, |
| 2080 | shouldFail: true, |
| 2081 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2082 | }, |
| 2083 | { |
| 2084 | protocol: dtls, |
| 2085 | name: "LargePlaintext-DTLS", |
| 2086 | config: Config{ |
| 2087 | Bugs: ProtocolBugs{ |
| 2088 | SendLargeRecords: true, |
| 2089 | }, |
| 2090 | }, |
| 2091 | messageLen: maxPlaintext + 1, |
| 2092 | shouldFail: true, |
| 2093 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2094 | }, |
| 2095 | { |
| 2096 | name: "LargeCiphertext", |
| 2097 | config: Config{ |
| 2098 | Bugs: ProtocolBugs{ |
| 2099 | SendLargeRecords: true, |
| 2100 | }, |
| 2101 | }, |
| 2102 | messageLen: maxPlaintext * 2, |
| 2103 | shouldFail: true, |
| 2104 | expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:", |
| 2105 | }, |
| 2106 | { |
| 2107 | protocol: dtls, |
| 2108 | name: "LargeCiphertext-DTLS", |
| 2109 | config: Config{ |
| 2110 | Bugs: ProtocolBugs{ |
| 2111 | SendLargeRecords: true, |
| 2112 | }, |
| 2113 | }, |
| 2114 | messageLen: maxPlaintext * 2, |
| 2115 | // Unlike the other four cases, DTLS drops records which |
| 2116 | // are invalid before authentication, so the connection |
| 2117 | // does not fail. |
| 2118 | expectMessageDropped: true, |
| 2119 | }, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2120 | { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2121 | // In TLS 1.2 and below, empty NewSessionTicket messages |
| 2122 | // mean the server changed its mind on sending a ticket. |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2123 | name: "SendEmptySessionTicket", |
| 2124 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2125 | MaxVersion: VersionTLS12, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2126 | Bugs: ProtocolBugs{ |
| 2127 | SendEmptySessionTicket: true, |
| 2128 | FailIfSessionOffered: true, |
| 2129 | }, |
| 2130 | }, |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 2131 | flags: []string{"-expect-no-session"}, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2132 | }, |
David Benjamin | 99fdfb9 | 2015-11-02 12:11:35 -0500 | [diff] [blame] | 2133 | { |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2134 | name: "BadHelloRequest-1", |
| 2135 | renegotiate: 1, |
| 2136 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2137 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2138 | Bugs: ProtocolBugs{ |
| 2139 | BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1}, |
| 2140 | }, |
| 2141 | }, |
| 2142 | flags: []string{ |
| 2143 | "-renegotiate-freely", |
| 2144 | "-expect-total-renegotiations", "1", |
| 2145 | }, |
| 2146 | shouldFail: true, |
David Benjamin | 163f29a | 2016-07-28 11:05:58 -0400 | [diff] [blame] | 2147 | expectedError: ":EXCESSIVE_MESSAGE_SIZE:", |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2148 | }, |
| 2149 | { |
| 2150 | name: "BadHelloRequest-2", |
| 2151 | renegotiate: 1, |
| 2152 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2153 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2154 | Bugs: ProtocolBugs{ |
| 2155 | BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0}, |
| 2156 | }, |
| 2157 | }, |
| 2158 | flags: []string{ |
| 2159 | "-renegotiate-freely", |
| 2160 | "-expect-total-renegotiations", "1", |
| 2161 | }, |
| 2162 | shouldFail: true, |
| 2163 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2164 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2165 | { |
| 2166 | testType: serverTest, |
| 2167 | name: "SupportTicketsWithSessionID", |
| 2168 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2169 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2170 | SessionTicketsDisabled: true, |
| 2171 | }, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2172 | resumeConfig: &Config{ |
| 2173 | MaxVersion: VersionTLS12, |
| 2174 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2175 | resumeSession: true, |
| 2176 | }, |
David Benjamin | 02edcd0 | 2016-07-27 17:40:37 -0400 | [diff] [blame] | 2177 | { |
| 2178 | protocol: dtls, |
| 2179 | name: "DTLS-SendExtraFinished", |
| 2180 | config: Config{ |
| 2181 | Bugs: ProtocolBugs{ |
| 2182 | SendExtraFinished: true, |
| 2183 | }, |
| 2184 | }, |
| 2185 | shouldFail: true, |
| 2186 | expectedError: ":UNEXPECTED_RECORD:", |
| 2187 | }, |
| 2188 | { |
| 2189 | protocol: dtls, |
| 2190 | name: "DTLS-SendExtraFinished-Reordered", |
| 2191 | config: Config{ |
| 2192 | Bugs: ProtocolBugs{ |
| 2193 | MaxHandshakeRecordLength: 2, |
| 2194 | ReorderHandshakeFragments: true, |
| 2195 | SendExtraFinished: true, |
| 2196 | }, |
| 2197 | }, |
| 2198 | shouldFail: true, |
| 2199 | expectedError: ":UNEXPECTED_RECORD:", |
| 2200 | }, |
David Benjamin | e97fb48 | 2016-07-29 09:23:07 -0400 | [diff] [blame] | 2201 | { |
| 2202 | testType: serverTest, |
| 2203 | name: "V2ClientHello-EmptyRecordPrefix", |
| 2204 | config: Config{ |
| 2205 | // Choose a cipher suite that does not involve |
| 2206 | // elliptic curves, so no extensions are |
| 2207 | // involved. |
| 2208 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2209 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | e97fb48 | 2016-07-29 09:23:07 -0400 | [diff] [blame] | 2210 | Bugs: ProtocolBugs{ |
| 2211 | SendV2ClientHello: true, |
| 2212 | }, |
| 2213 | }, |
| 2214 | sendPrefix: string([]byte{ |
| 2215 | byte(recordTypeHandshake), |
| 2216 | 3, 1, // version |
| 2217 | 0, 0, // length |
| 2218 | }), |
| 2219 | // A no-op empty record may not be sent before V2ClientHello. |
| 2220 | shouldFail: true, |
| 2221 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 2222 | }, |
| 2223 | { |
| 2224 | testType: serverTest, |
| 2225 | name: "V2ClientHello-WarningAlertPrefix", |
| 2226 | config: Config{ |
| 2227 | // Choose a cipher suite that does not involve |
| 2228 | // elliptic curves, so no extensions are |
| 2229 | // involved. |
| 2230 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2231 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | e97fb48 | 2016-07-29 09:23:07 -0400 | [diff] [blame] | 2232 | Bugs: ProtocolBugs{ |
| 2233 | SendV2ClientHello: true, |
| 2234 | }, |
| 2235 | }, |
| 2236 | sendPrefix: string([]byte{ |
| 2237 | byte(recordTypeAlert), |
| 2238 | 3, 1, // version |
| 2239 | 0, 2, // length |
| 2240 | alertLevelWarning, byte(alertDecompressionFailure), |
| 2241 | }), |
| 2242 | // A no-op warning alert may not be sent before V2ClientHello. |
| 2243 | shouldFail: true, |
| 2244 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 2245 | }, |
Steven Valdez | 1dc53d2 | 2016-07-26 12:27:38 -0400 | [diff] [blame] | 2246 | { |
| 2247 | testType: clientTest, |
| 2248 | name: "KeyUpdate", |
| 2249 | config: Config{ |
| 2250 | MaxVersion: VersionTLS13, |
| 2251 | Bugs: ProtocolBugs{ |
| 2252 | SendKeyUpdateBeforeEveryAppDataRecord: true, |
| 2253 | }, |
| 2254 | }, |
| 2255 | }, |
David Benjamin | abe94e3 | 2016-09-04 14:18:58 -0400 | [diff] [blame] | 2256 | { |
| 2257 | name: "SendSNIWarningAlert", |
| 2258 | config: Config{ |
| 2259 | MaxVersion: VersionTLS12, |
| 2260 | Bugs: ProtocolBugs{ |
| 2261 | SendSNIWarningAlert: true, |
| 2262 | }, |
| 2263 | }, |
| 2264 | }, |
David Benjamin | c241d79 | 2016-09-09 10:34:20 -0400 | [diff] [blame] | 2265 | { |
| 2266 | testType: serverTest, |
| 2267 | name: "ExtraCompressionMethods-TLS12", |
| 2268 | config: Config{ |
| 2269 | MaxVersion: VersionTLS12, |
| 2270 | Bugs: ProtocolBugs{ |
| 2271 | SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6}, |
| 2272 | }, |
| 2273 | }, |
| 2274 | }, |
| 2275 | { |
| 2276 | testType: serverTest, |
| 2277 | name: "ExtraCompressionMethods-TLS13", |
| 2278 | config: Config{ |
| 2279 | MaxVersion: VersionTLS13, |
| 2280 | Bugs: ProtocolBugs{ |
| 2281 | SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6}, |
| 2282 | }, |
| 2283 | }, |
| 2284 | shouldFail: true, |
| 2285 | expectedError: ":INVALID_COMPRESSION_LIST:", |
| 2286 | expectedLocalError: "remote error: illegal parameter", |
| 2287 | }, |
| 2288 | { |
| 2289 | testType: serverTest, |
| 2290 | name: "NoNullCompression-TLS12", |
| 2291 | config: Config{ |
| 2292 | MaxVersion: VersionTLS12, |
| 2293 | Bugs: ProtocolBugs{ |
| 2294 | SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6}, |
| 2295 | }, |
| 2296 | }, |
| 2297 | shouldFail: true, |
| 2298 | expectedError: ":NO_COMPRESSION_SPECIFIED:", |
| 2299 | expectedLocalError: "remote error: illegal parameter", |
| 2300 | }, |
| 2301 | { |
| 2302 | testType: serverTest, |
| 2303 | name: "NoNullCompression-TLS13", |
| 2304 | config: Config{ |
| 2305 | MaxVersion: VersionTLS13, |
| 2306 | Bugs: ProtocolBugs{ |
| 2307 | SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6}, |
| 2308 | }, |
| 2309 | }, |
| 2310 | shouldFail: true, |
| 2311 | expectedError: ":INVALID_COMPRESSION_LIST:", |
| 2312 | expectedLocalError: "remote error: illegal parameter", |
| 2313 | }, |
David Benjamin | 65ac997 | 2016-09-02 21:35:25 -0400 | [diff] [blame] | 2314 | { |
| 2315 | name: "GREASE-TLS12", |
| 2316 | config: Config{ |
| 2317 | MaxVersion: VersionTLS12, |
| 2318 | Bugs: ProtocolBugs{ |
| 2319 | ExpectGREASE: true, |
| 2320 | }, |
| 2321 | }, |
| 2322 | flags: []string{"-enable-grease"}, |
| 2323 | }, |
| 2324 | { |
| 2325 | name: "GREASE-TLS13", |
| 2326 | config: Config{ |
| 2327 | MaxVersion: VersionTLS13, |
| 2328 | Bugs: ProtocolBugs{ |
| 2329 | ExpectGREASE: true, |
| 2330 | }, |
| 2331 | }, |
| 2332 | flags: []string{"-enable-grease"}, |
| 2333 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2334 | } |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2335 | testCases = append(testCases, basicTests...) |
David Benjamin | a252b34 | 2016-09-26 19:57:53 -0400 | [diff] [blame] | 2336 | |
| 2337 | // Test that very large messages can be received. |
| 2338 | cert := rsaCertificate |
| 2339 | for i := 0; i < 50; i++ { |
| 2340 | cert.Certificate = append(cert.Certificate, cert.Certificate[0]) |
| 2341 | } |
| 2342 | testCases = append(testCases, testCase{ |
| 2343 | name: "LargeMessage", |
| 2344 | config: Config{ |
| 2345 | Certificates: []Certificate{cert}, |
| 2346 | }, |
| 2347 | }) |
| 2348 | testCases = append(testCases, testCase{ |
| 2349 | protocol: dtls, |
| 2350 | name: "LargeMessage-DTLS", |
| 2351 | config: Config{ |
| 2352 | Certificates: []Certificate{cert}, |
| 2353 | }, |
| 2354 | }) |
| 2355 | |
| 2356 | // They are rejected if the maximum certificate chain length is capped. |
| 2357 | testCases = append(testCases, testCase{ |
| 2358 | name: "LargeMessage-Reject", |
| 2359 | config: Config{ |
| 2360 | Certificates: []Certificate{cert}, |
| 2361 | }, |
| 2362 | flags: []string{"-max-cert-list", "16384"}, |
| 2363 | shouldFail: true, |
| 2364 | expectedError: ":EXCESSIVE_MESSAGE_SIZE:", |
| 2365 | }) |
| 2366 | testCases = append(testCases, testCase{ |
| 2367 | protocol: dtls, |
| 2368 | name: "LargeMessage-Reject-DTLS", |
| 2369 | config: Config{ |
| 2370 | Certificates: []Certificate{cert}, |
| 2371 | }, |
| 2372 | flags: []string{"-max-cert-list", "16384"}, |
| 2373 | shouldFail: true, |
| 2374 | expectedError: ":EXCESSIVE_MESSAGE_SIZE:", |
| 2375 | }) |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2378 | func addCipherSuiteTests() { |
David Benjamin | e470e66 | 2016-07-18 15:47:32 +0200 | [diff] [blame] | 2379 | const bogusCipher = 0xfe00 |
| 2380 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2381 | for _, suite := range testCipherSuites { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2382 | const psk = "12345" |
| 2383 | const pskIdentity = "luggage combo" |
| 2384 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2385 | var cert Certificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2386 | var certFile string |
| 2387 | var keyFile string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2388 | if hasComponent(suite.name, "ECDSA") { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2389 | cert = ecdsaP256Certificate |
| 2390 | certFile = ecdsaP256CertificateFile |
| 2391 | keyFile = ecdsaP256KeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2392 | } else { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2393 | cert = rsaCertificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2394 | certFile = rsaCertificateFile |
| 2395 | keyFile = rsaKeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2396 | } |
| 2397 | |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2398 | var flags []string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2399 | if hasComponent(suite.name, "PSK") { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2400 | flags = append(flags, |
| 2401 | "-psk", psk, |
| 2402 | "-psk-identity", pskIdentity) |
| 2403 | } |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 2404 | if hasComponent(suite.name, "NULL") { |
| 2405 | // NULL ciphers must be explicitly enabled. |
| 2406 | flags = append(flags, "-cipher", "DEFAULT:NULL-SHA") |
| 2407 | } |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 2408 | if hasComponent(suite.name, "CECPQ1") { |
| 2409 | // CECPQ1 ciphers must be explicitly enabled. |
| 2410 | flags = append(flags, "-cipher", "DEFAULT:kCECPQ1") |
| 2411 | } |
David Benjamin | 881f196 | 2016-08-10 18:29:12 -0400 | [diff] [blame] | 2412 | if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") { |
| 2413 | // ECDHE_PSK AES_GCM ciphers must be explicitly enabled |
| 2414 | // for now. |
| 2415 | flags = append(flags, "-cipher", suite.name) |
| 2416 | } |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2417 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2418 | for _, ver := range tlsVersions { |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2419 | for _, protocol := range []protocol{tls, dtls} { |
| 2420 | var prefix string |
| 2421 | if protocol == dtls { |
| 2422 | if !ver.hasDTLS { |
| 2423 | continue |
| 2424 | } |
| 2425 | prefix = "D" |
| 2426 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2427 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2428 | var shouldServerFail, shouldClientFail bool |
| 2429 | if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 { |
| 2430 | // BoringSSL clients accept ECDHE on SSLv3, but |
| 2431 | // a BoringSSL server will never select it |
| 2432 | // because the extension is missing. |
| 2433 | shouldServerFail = true |
| 2434 | } |
| 2435 | if isTLS12Only(suite.name) && ver.version < VersionTLS12 { |
| 2436 | shouldClientFail = true |
| 2437 | shouldServerFail = true |
| 2438 | } |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 2439 | if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2440 | shouldClientFail = true |
| 2441 | shouldServerFail = true |
| 2442 | } |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2443 | if !isDTLSCipher(suite.name) && protocol == dtls { |
| 2444 | shouldClientFail = true |
| 2445 | shouldServerFail = true |
| 2446 | } |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 2447 | |
David Benjamin | 5ecb88b | 2016-10-04 17:51:35 -0400 | [diff] [blame^] | 2448 | var sendCipherSuite uint16 |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2449 | var expectedServerError, expectedClientError string |
David Benjamin | 5ecb88b | 2016-10-04 17:51:35 -0400 | [diff] [blame^] | 2450 | serverCipherSuites := []uint16{suite.id} |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2451 | if shouldServerFail { |
| 2452 | expectedServerError = ":NO_SHARED_CIPHER:" |
| 2453 | } |
| 2454 | if shouldClientFail { |
| 2455 | expectedClientError = ":WRONG_CIPHER_RETURNED:" |
David Benjamin | 5ecb88b | 2016-10-04 17:51:35 -0400 | [diff] [blame^] | 2456 | // Configure the server to select ciphers as normal but |
| 2457 | // select an incompatible cipher in ServerHello. |
| 2458 | serverCipherSuites = nil |
| 2459 | sendCipherSuite = suite.id |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2460 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2461 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2462 | testCases = append(testCases, testCase{ |
| 2463 | testType: serverTest, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2464 | protocol: protocol, |
| 2465 | |
| 2466 | name: prefix + ver.name + "-" + suite.name + "-server", |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2467 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2468 | MinVersion: ver.version, |
| 2469 | MaxVersion: ver.version, |
| 2470 | CipherSuites: []uint16{suite.id}, |
| 2471 | Certificates: []Certificate{cert}, |
| 2472 | PreSharedKey: []byte(psk), |
| 2473 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2474 | Bugs: ProtocolBugs{ |
David Benjamin | 5ecb88b | 2016-10-04 17:51:35 -0400 | [diff] [blame^] | 2475 | AdvertiseAllConfiguredCiphers: true, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2476 | }, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2477 | }, |
| 2478 | certFile: certFile, |
| 2479 | keyFile: keyFile, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2480 | flags: flags, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 2481 | resumeSession: true, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2482 | shouldFail: shouldServerFail, |
| 2483 | expectedError: expectedServerError, |
| 2484 | }) |
| 2485 | |
| 2486 | testCases = append(testCases, testCase{ |
| 2487 | testType: clientTest, |
| 2488 | protocol: protocol, |
| 2489 | name: prefix + ver.name + "-" + suite.name + "-client", |
| 2490 | config: Config{ |
| 2491 | MinVersion: ver.version, |
| 2492 | MaxVersion: ver.version, |
David Benjamin | 5ecb88b | 2016-10-04 17:51:35 -0400 | [diff] [blame^] | 2493 | CipherSuites: serverCipherSuites, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2494 | Certificates: []Certificate{cert}, |
| 2495 | PreSharedKey: []byte(psk), |
| 2496 | PreSharedKeyIdentity: pskIdentity, |
| 2497 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2498 | IgnorePeerCipherPreferences: shouldClientFail, |
David Benjamin | 5ecb88b | 2016-10-04 17:51:35 -0400 | [diff] [blame^] | 2499 | SendCipherSuite: sendCipherSuite, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2500 | }, |
| 2501 | }, |
| 2502 | flags: flags, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 2503 | resumeSession: true, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2504 | shouldFail: shouldClientFail, |
| 2505 | expectedError: expectedClientError, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2506 | }) |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2507 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2508 | if !shouldClientFail { |
| 2509 | // Ensure the maximum record size is accepted. |
| 2510 | testCases = append(testCases, testCase{ |
| 2511 | name: prefix + ver.name + "-" + suite.name + "-LargeRecord", |
| 2512 | config: Config{ |
| 2513 | MinVersion: ver.version, |
| 2514 | MaxVersion: ver.version, |
| 2515 | CipherSuites: []uint16{suite.id}, |
| 2516 | Certificates: []Certificate{cert}, |
| 2517 | PreSharedKey: []byte(psk), |
| 2518 | PreSharedKeyIdentity: pskIdentity, |
| 2519 | }, |
| 2520 | flags: flags, |
| 2521 | messageLen: maxPlaintext, |
| 2522 | }) |
| 2523 | } |
| 2524 | } |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2525 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2526 | } |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2527 | |
| 2528 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2529 | name: "NoSharedCipher", |
| 2530 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2531 | MaxVersion: VersionTLS12, |
| 2532 | CipherSuites: []uint16{}, |
| 2533 | }, |
| 2534 | shouldFail: true, |
| 2535 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2536 | }) |
| 2537 | |
| 2538 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2539 | name: "NoSharedCipher-TLS13", |
| 2540 | config: Config{ |
| 2541 | MaxVersion: VersionTLS13, |
| 2542 | CipherSuites: []uint16{}, |
| 2543 | }, |
| 2544 | shouldFail: true, |
| 2545 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2546 | }) |
| 2547 | |
| 2548 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2549 | name: "UnsupportedCipherSuite", |
| 2550 | config: Config{ |
| 2551 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 9c8c418 | 2016-08-24 14:36:54 -0700 | [diff] [blame] | 2552 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2553 | Bugs: ProtocolBugs{ |
| 2554 | IgnorePeerCipherPreferences: true, |
| 2555 | }, |
| 2556 | }, |
Matt Braithwaite | 9c8c418 | 2016-08-24 14:36:54 -0700 | [diff] [blame] | 2557 | flags: []string{"-cipher", "DEFAULT:!AES"}, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2558 | shouldFail: true, |
| 2559 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 2560 | }) |
| 2561 | |
| 2562 | testCases = append(testCases, testCase{ |
David Benjamin | e470e66 | 2016-07-18 15:47:32 +0200 | [diff] [blame] | 2563 | name: "ServerHelloBogusCipher", |
| 2564 | config: Config{ |
| 2565 | MaxVersion: VersionTLS12, |
| 2566 | Bugs: ProtocolBugs{ |
| 2567 | SendCipherSuite: bogusCipher, |
| 2568 | }, |
| 2569 | }, |
| 2570 | shouldFail: true, |
| 2571 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2572 | }) |
| 2573 | testCases = append(testCases, testCase{ |
| 2574 | name: "ServerHelloBogusCipher-TLS13", |
| 2575 | config: Config{ |
| 2576 | MaxVersion: VersionTLS13, |
| 2577 | Bugs: ProtocolBugs{ |
| 2578 | SendCipherSuite: bogusCipher, |
| 2579 | }, |
| 2580 | }, |
| 2581 | shouldFail: true, |
| 2582 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2583 | }) |
| 2584 | |
| 2585 | testCases = append(testCases, testCase{ |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2586 | name: "WeakDH", |
| 2587 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2588 | MaxVersion: VersionTLS12, |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2589 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2590 | Bugs: ProtocolBugs{ |
| 2591 | // This is a 1023-bit prime number, generated |
| 2592 | // with: |
| 2593 | // openssl gendh 1023 | openssl asn1parse -i |
| 2594 | DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"), |
| 2595 | }, |
| 2596 | }, |
| 2597 | shouldFail: true, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2598 | expectedError: ":BAD_DH_P_LENGTH:", |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2599 | }) |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2600 | |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2601 | testCases = append(testCases, testCase{ |
| 2602 | name: "SillyDH", |
| 2603 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2604 | MaxVersion: VersionTLS12, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2605 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2606 | Bugs: ProtocolBugs{ |
| 2607 | // This is a 4097-bit prime number, generated |
| 2608 | // with: |
| 2609 | // openssl gendh 4097 | openssl asn1parse -i |
| 2610 | DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"), |
| 2611 | }, |
| 2612 | }, |
| 2613 | shouldFail: true, |
| 2614 | expectedError: ":DH_P_TOO_LONG:", |
| 2615 | }) |
| 2616 | |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2617 | // This test ensures that Diffie-Hellman public values are padded with |
| 2618 | // zeros so that they're the same length as the prime. This is to avoid |
| 2619 | // hitting a bug in yaSSL. |
| 2620 | testCases = append(testCases, testCase{ |
| 2621 | testType: serverTest, |
| 2622 | name: "DHPublicValuePadded", |
| 2623 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2624 | MaxVersion: VersionTLS12, |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2625 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2626 | Bugs: ProtocolBugs{ |
| 2627 | RequireDHPublicValueLen: (1025 + 7) / 8, |
| 2628 | }, |
| 2629 | }, |
| 2630 | flags: []string{"-use-sparse-dh-prime"}, |
| 2631 | }) |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2632 | |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2633 | // The server must be tolerant to bogus ciphers. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2634 | testCases = append(testCases, testCase{ |
| 2635 | testType: serverTest, |
| 2636 | name: "UnknownCipher", |
| 2637 | config: Config{ |
| 2638 | CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 5ecb88b | 2016-10-04 17:51:35 -0400 | [diff] [blame^] | 2639 | Bugs: ProtocolBugs{ |
| 2640 | AdvertiseAllConfiguredCiphers: true, |
| 2641 | }, |
| 2642 | }, |
| 2643 | }) |
| 2644 | testCases = append(testCases, testCase{ |
| 2645 | testType: serverTest, |
| 2646 | name: "UnknownCipher-TLS13", |
| 2647 | config: Config{ |
| 2648 | MaxVersion: VersionTLS13, |
| 2649 | CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2650 | Bugs: ProtocolBugs{ |
| 2651 | AdvertiseAllConfiguredCiphers: true, |
| 2652 | }, |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2653 | }, |
| 2654 | }) |
| 2655 | |
David Benjamin | 7867934 | 2016-09-16 19:42:05 -0400 | [diff] [blame] | 2656 | // Test empty ECDHE_PSK identity hints work as expected. |
| 2657 | testCases = append(testCases, testCase{ |
| 2658 | name: "EmptyECDHEPSKHint", |
| 2659 | config: Config{ |
| 2660 | MaxVersion: VersionTLS12, |
| 2661 | CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 2662 | PreSharedKey: []byte("secret"), |
| 2663 | }, |
| 2664 | flags: []string{"-psk", "secret"}, |
| 2665 | }) |
| 2666 | |
| 2667 | // Test empty PSK identity hints work as expected, even if an explicit |
| 2668 | // ServerKeyExchange is sent. |
| 2669 | testCases = append(testCases, testCase{ |
| 2670 | name: "ExplicitEmptyPSKHint", |
| 2671 | config: Config{ |
| 2672 | MaxVersion: VersionTLS12, |
| 2673 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 2674 | PreSharedKey: []byte("secret"), |
| 2675 | Bugs: ProtocolBugs{ |
| 2676 | AlwaysSendPreSharedKeyIdentityHint: true, |
| 2677 | }, |
| 2678 | }, |
| 2679 | flags: []string{"-psk", "secret"}, |
| 2680 | }) |
| 2681 | |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2682 | // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS |
| 2683 | // 1.1 specific cipher suite settings. A server is setup with the given |
| 2684 | // cipher lists and then a connection is made for each member of |
| 2685 | // expectations. The cipher suite that the server selects must match |
| 2686 | // the specified one. |
| 2687 | var versionSpecificCiphersTest = []struct { |
| 2688 | ciphersDefault, ciphersTLS10, ciphersTLS11 string |
| 2689 | // expectations is a map from TLS version to cipher suite id. |
| 2690 | expectations map[uint16]uint16 |
| 2691 | }{ |
| 2692 | { |
| 2693 | // Test that the null case (where no version-specific ciphers are set) |
| 2694 | // works as expected. |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2695 | "DES-CBC3-SHA:AES128-SHA", // default ciphers |
| 2696 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2697 | "", // no ciphers specifically for TLS ≥ 1.1 |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2698 | map[uint16]uint16{ |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2699 | VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
| 2700 | VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
| 2701 | VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
| 2702 | VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2703 | }, |
| 2704 | }, |
| 2705 | { |
| 2706 | // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different |
| 2707 | // cipher. |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2708 | "DES-CBC3-SHA:AES128-SHA", // default |
| 2709 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2710 | "", // no ciphers specifically for TLS ≥ 1.1 |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2711 | map[uint16]uint16{ |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2712 | VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2713 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2714 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2715 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2716 | }, |
| 2717 | }, |
| 2718 | { |
| 2719 | // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different |
| 2720 | // cipher. |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2721 | "DES-CBC3-SHA:AES128-SHA", // default |
| 2722 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2723 | "AES128-SHA", // these ciphers for TLS ≥ 1.1 |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2724 | map[uint16]uint16{ |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2725 | VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
| 2726 | VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2727 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2728 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2729 | }, |
| 2730 | }, |
| 2731 | { |
| 2732 | // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should |
| 2733 | // mask ciphers_tls10 for TLS 1.1 and 1.2. |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2734 | "DES-CBC3-SHA:AES128-SHA", // default |
| 2735 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2736 | "AES256-SHA", // these ciphers for TLS ≥ 1.1 |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2737 | map[uint16]uint16{ |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2738 | VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2739 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2740 | VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2741 | VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2742 | }, |
| 2743 | }, |
| 2744 | } |
| 2745 | |
| 2746 | for i, test := range versionSpecificCiphersTest { |
| 2747 | for version, expectedCipherSuite := range test.expectations { |
| 2748 | flags := []string{"-cipher", test.ciphersDefault} |
| 2749 | if len(test.ciphersTLS10) > 0 { |
| 2750 | flags = append(flags, "-cipher-tls10", test.ciphersTLS10) |
| 2751 | } |
| 2752 | if len(test.ciphersTLS11) > 0 { |
| 2753 | flags = append(flags, "-cipher-tls11", test.ciphersTLS11) |
| 2754 | } |
| 2755 | |
| 2756 | testCases = append(testCases, testCase{ |
| 2757 | testType: serverTest, |
| 2758 | name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version), |
| 2759 | config: Config{ |
| 2760 | MaxVersion: version, |
| 2761 | MinVersion: version, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2762 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA}, |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2763 | }, |
| 2764 | flags: flags, |
| 2765 | expectedCipher: expectedCipherSuite, |
| 2766 | }) |
| 2767 | } |
| 2768 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | func addBadECDSASignatureTests() { |
| 2772 | for badR := BadValue(1); badR < NumBadValues; badR++ { |
| 2773 | for badS := BadValue(1); badS < NumBadValues; badS++ { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2774 | testCases = append(testCases, testCase{ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2775 | name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS), |
| 2776 | config: Config{ |
| 2777 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2778 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2779 | Bugs: ProtocolBugs{ |
| 2780 | BadECDSAR: badR, |
| 2781 | BadECDSAS: badS, |
| 2782 | }, |
| 2783 | }, |
| 2784 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2785 | expectedError: ":BAD_SIGNATURE:", |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2786 | }) |
| 2787 | } |
| 2788 | } |
| 2789 | } |
| 2790 | |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2791 | func addCBCPaddingTests() { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2792 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2793 | name: "MaxCBCPadding", |
| 2794 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2795 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2796 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2797 | Bugs: ProtocolBugs{ |
| 2798 | MaxPadding: true, |
| 2799 | }, |
| 2800 | }, |
| 2801 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2802 | }) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2803 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2804 | name: "BadCBCPadding", |
| 2805 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2806 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2807 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2808 | Bugs: ProtocolBugs{ |
| 2809 | PaddingFirstByteBad: true, |
| 2810 | }, |
| 2811 | }, |
| 2812 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2813 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2814 | }) |
| 2815 | // OpenSSL previously had an issue where the first byte of padding in |
| 2816 | // 255 bytes of padding wasn't checked. |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2817 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2818 | name: "BadCBCPadding255", |
| 2819 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2820 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2821 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2822 | Bugs: ProtocolBugs{ |
| 2823 | MaxPadding: true, |
| 2824 | PaddingFirstByteBadIf255: true, |
| 2825 | }, |
| 2826 | }, |
| 2827 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2828 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2829 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2830 | }) |
| 2831 | } |
| 2832 | |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2833 | func addCBCSplittingTests() { |
| 2834 | testCases = append(testCases, testCase{ |
| 2835 | name: "CBCRecordSplitting", |
| 2836 | config: Config{ |
| 2837 | MaxVersion: VersionTLS10, |
| 2838 | MinVersion: VersionTLS10, |
| 2839 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2840 | }, |
David Benjamin | ac8302a | 2015-09-01 17:18:15 -0400 | [diff] [blame] | 2841 | messageLen: -1, // read until EOF |
| 2842 | resumeSession: true, |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2843 | flags: []string{ |
| 2844 | "-async", |
| 2845 | "-write-different-record-sizes", |
| 2846 | "-cbc-record-splitting", |
| 2847 | }, |
David Benjamin | a8e3e0e | 2014-08-06 22:11:10 -0400 | [diff] [blame] | 2848 | }) |
| 2849 | testCases = append(testCases, testCase{ |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2850 | name: "CBCRecordSplittingPartialWrite", |
| 2851 | config: Config{ |
| 2852 | MaxVersion: VersionTLS10, |
| 2853 | MinVersion: VersionTLS10, |
| 2854 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2855 | }, |
| 2856 | messageLen: -1, // read until EOF |
| 2857 | flags: []string{ |
| 2858 | "-async", |
| 2859 | "-write-different-record-sizes", |
| 2860 | "-cbc-record-splitting", |
| 2861 | "-partial-write", |
| 2862 | }, |
| 2863 | }) |
| 2864 | } |
| 2865 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2866 | func addClientAuthTests() { |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 2867 | // Add a dummy cert pool to stress certificate authority parsing. |
| 2868 | // TODO(davidben): Add tests that those values parse out correctly. |
| 2869 | certPool := x509.NewCertPool() |
| 2870 | cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0]) |
| 2871 | if err != nil { |
| 2872 | panic(err) |
| 2873 | } |
| 2874 | certPool.AddCert(cert) |
| 2875 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2876 | for _, ver := range tlsVersions { |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2877 | testCases = append(testCases, testCase{ |
| 2878 | testType: clientTest, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2879 | name: ver.name + "-Client-ClientAuth-RSA", |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2880 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2881 | MinVersion: ver.version, |
| 2882 | MaxVersion: ver.version, |
| 2883 | ClientAuth: RequireAnyClientCert, |
| 2884 | ClientCAs: certPool, |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2885 | }, |
| 2886 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2887 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2888 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2889 | }, |
| 2890 | }) |
| 2891 | testCases = append(testCases, testCase{ |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2892 | testType: serverTest, |
| 2893 | name: ver.name + "-Server-ClientAuth-RSA", |
| 2894 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2895 | MinVersion: ver.version, |
| 2896 | MaxVersion: ver.version, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2897 | Certificates: []Certificate{rsaCertificate}, |
| 2898 | }, |
| 2899 | flags: []string{"-require-any-client-certificate"}, |
| 2900 | }) |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2901 | if ver.version != VersionSSL30 { |
| 2902 | testCases = append(testCases, testCase{ |
| 2903 | testType: serverTest, |
| 2904 | name: ver.name + "-Server-ClientAuth-ECDSA", |
| 2905 | config: Config{ |
| 2906 | MinVersion: ver.version, |
| 2907 | MaxVersion: ver.version, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2908 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2909 | }, |
| 2910 | flags: []string{"-require-any-client-certificate"}, |
| 2911 | }) |
| 2912 | testCases = append(testCases, testCase{ |
| 2913 | testType: clientTest, |
| 2914 | name: ver.name + "-Client-ClientAuth-ECDSA", |
| 2915 | config: Config{ |
| 2916 | MinVersion: ver.version, |
| 2917 | MaxVersion: ver.version, |
| 2918 | ClientAuth: RequireAnyClientCert, |
| 2919 | ClientCAs: certPool, |
| 2920 | }, |
| 2921 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2922 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 2923 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2924 | }, |
| 2925 | }) |
| 2926 | } |
Adam Langley | 3764683 | 2016-08-01 16:16:46 -0700 | [diff] [blame] | 2927 | |
| 2928 | testCases = append(testCases, testCase{ |
| 2929 | name: "NoClientCertificate-" + ver.name, |
| 2930 | config: Config{ |
| 2931 | MinVersion: ver.version, |
| 2932 | MaxVersion: ver.version, |
| 2933 | ClientAuth: RequireAnyClientCert, |
| 2934 | }, |
| 2935 | shouldFail: true, |
| 2936 | expectedLocalError: "client didn't provide a certificate", |
| 2937 | }) |
| 2938 | |
| 2939 | testCases = append(testCases, testCase{ |
| 2940 | // Even if not configured to expect a certificate, OpenSSL will |
| 2941 | // return X509_V_OK as the verify_result. |
| 2942 | testType: serverTest, |
| 2943 | name: "NoClientCertificateRequested-Server-" + ver.name, |
| 2944 | config: Config{ |
| 2945 | MinVersion: ver.version, |
| 2946 | MaxVersion: ver.version, |
| 2947 | }, |
| 2948 | flags: []string{ |
| 2949 | "-expect-verify-result", |
| 2950 | }, |
| 2951 | // TODO(davidben): Switch this to true when TLS 1.3 |
| 2952 | // supports session resumption. |
| 2953 | resumeSession: ver.version < VersionTLS13, |
| 2954 | }) |
| 2955 | |
| 2956 | testCases = append(testCases, testCase{ |
| 2957 | // If a client certificate is not provided, OpenSSL will still |
| 2958 | // return X509_V_OK as the verify_result. |
| 2959 | testType: serverTest, |
| 2960 | name: "NoClientCertificate-Server-" + ver.name, |
| 2961 | config: Config{ |
| 2962 | MinVersion: ver.version, |
| 2963 | MaxVersion: ver.version, |
| 2964 | }, |
| 2965 | flags: []string{ |
| 2966 | "-expect-verify-result", |
| 2967 | "-verify-peer", |
| 2968 | }, |
| 2969 | // TODO(davidben): Switch this to true when TLS 1.3 |
| 2970 | // supports session resumption. |
| 2971 | resumeSession: ver.version < VersionTLS13, |
| 2972 | }) |
| 2973 | |
| 2974 | testCases = append(testCases, testCase{ |
| 2975 | testType: serverTest, |
| 2976 | name: "RequireAnyClientCertificate-" + ver.name, |
| 2977 | config: Config{ |
| 2978 | MinVersion: ver.version, |
| 2979 | MaxVersion: ver.version, |
| 2980 | }, |
| 2981 | flags: []string{"-require-any-client-certificate"}, |
| 2982 | shouldFail: true, |
| 2983 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2984 | }) |
| 2985 | |
| 2986 | if ver.version != VersionSSL30 { |
| 2987 | testCases = append(testCases, testCase{ |
| 2988 | testType: serverTest, |
| 2989 | name: "SkipClientCertificate-" + ver.name, |
| 2990 | config: Config{ |
| 2991 | MinVersion: ver.version, |
| 2992 | MaxVersion: ver.version, |
| 2993 | Bugs: ProtocolBugs{ |
| 2994 | SkipClientCertificate: true, |
| 2995 | }, |
| 2996 | }, |
| 2997 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2998 | flags: []string{"-verify-peer"}, |
| 2999 | shouldFail: true, |
| 3000 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 3001 | }) |
| 3002 | } |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 3003 | } |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3004 | |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 3005 | // Client auth is only legal in certificate-based ciphers. |
| 3006 | testCases = append(testCases, testCase{ |
| 3007 | testType: clientTest, |
| 3008 | name: "ClientAuth-PSK", |
| 3009 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3010 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 3011 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3012 | PreSharedKey: []byte("secret"), |
| 3013 | ClientAuth: RequireAnyClientCert, |
| 3014 | }, |
| 3015 | flags: []string{ |
| 3016 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3017 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3018 | "-psk", "secret", |
| 3019 | }, |
| 3020 | shouldFail: true, |
| 3021 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 3022 | }) |
| 3023 | testCases = append(testCases, testCase{ |
| 3024 | testType: clientTest, |
| 3025 | name: "ClientAuth-ECDHE_PSK", |
| 3026 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3027 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 3028 | CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 3029 | PreSharedKey: []byte("secret"), |
| 3030 | ClientAuth: RequireAnyClientCert, |
| 3031 | }, |
| 3032 | flags: []string{ |
| 3033 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3034 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3035 | "-psk", "secret", |
| 3036 | }, |
| 3037 | shouldFail: true, |
| 3038 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 3039 | }) |
David Benjamin | 2f8935d | 2016-07-13 19:47:39 -0400 | [diff] [blame] | 3040 | |
| 3041 | // Regression test for a bug where the client CA list, if explicitly |
| 3042 | // set to NULL, was mis-encoded. |
| 3043 | testCases = append(testCases, testCase{ |
| 3044 | testType: serverTest, |
| 3045 | name: "Null-Client-CA-List", |
| 3046 | config: Config{ |
| 3047 | MaxVersion: VersionTLS12, |
| 3048 | Certificates: []Certificate{rsaCertificate}, |
| 3049 | }, |
| 3050 | flags: []string{ |
| 3051 | "-require-any-client-certificate", |
| 3052 | "-use-null-client-ca-list", |
| 3053 | }, |
| 3054 | }) |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 3055 | } |
| 3056 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3057 | func addExtendedMasterSecretTests() { |
| 3058 | const expectEMSFlag = "-expect-extended-master-secret" |
| 3059 | |
| 3060 | for _, with := range []bool{false, true} { |
| 3061 | prefix := "No" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3062 | if with { |
| 3063 | prefix = "" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | for _, isClient := range []bool{false, true} { |
| 3067 | suffix := "-Server" |
| 3068 | testType := serverTest |
| 3069 | if isClient { |
| 3070 | suffix = "-Client" |
| 3071 | testType = clientTest |
| 3072 | } |
| 3073 | |
| 3074 | for _, ver := range tlsVersions { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3075 | // In TLS 1.3, the extension is irrelevant and |
| 3076 | // always reports as enabled. |
| 3077 | var flags []string |
| 3078 | if with || ver.version >= VersionTLS13 { |
| 3079 | flags = []string{expectEMSFlag} |
| 3080 | } |
| 3081 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3082 | test := testCase{ |
| 3083 | testType: testType, |
| 3084 | name: prefix + "ExtendedMasterSecret-" + ver.name + suffix, |
| 3085 | config: Config{ |
| 3086 | MinVersion: ver.version, |
| 3087 | MaxVersion: ver.version, |
| 3088 | Bugs: ProtocolBugs{ |
| 3089 | NoExtendedMasterSecret: !with, |
| 3090 | RequireExtendedMasterSecret: with, |
| 3091 | }, |
| 3092 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 3093 | flags: flags, |
| 3094 | shouldFail: ver.version == VersionSSL30 && with, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3095 | } |
| 3096 | if test.shouldFail { |
| 3097 | test.expectedLocalError = "extended master secret required but not supported by peer" |
| 3098 | } |
| 3099 | testCases = append(testCases, test) |
| 3100 | } |
| 3101 | } |
| 3102 | } |
| 3103 | |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 3104 | for _, isClient := range []bool{false, true} { |
| 3105 | for _, supportedInFirstConnection := range []bool{false, true} { |
| 3106 | for _, supportedInResumeConnection := range []bool{false, true} { |
| 3107 | boolToWord := func(b bool) string { |
| 3108 | if b { |
| 3109 | return "Yes" |
| 3110 | } |
| 3111 | return "No" |
| 3112 | } |
| 3113 | suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-" |
| 3114 | if isClient { |
| 3115 | suffix += "Client" |
| 3116 | } else { |
| 3117 | suffix += "Server" |
| 3118 | } |
| 3119 | |
| 3120 | supportedConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3121 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 3122 | Bugs: ProtocolBugs{ |
| 3123 | RequireExtendedMasterSecret: true, |
| 3124 | }, |
| 3125 | } |
| 3126 | |
| 3127 | noSupportConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3128 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 3129 | Bugs: ProtocolBugs{ |
| 3130 | NoExtendedMasterSecret: true, |
| 3131 | }, |
| 3132 | } |
| 3133 | |
| 3134 | test := testCase{ |
| 3135 | name: "ExtendedMasterSecret-" + suffix, |
| 3136 | resumeSession: true, |
| 3137 | } |
| 3138 | |
| 3139 | if !isClient { |
| 3140 | test.testType = serverTest |
| 3141 | } |
| 3142 | |
| 3143 | if supportedInFirstConnection { |
| 3144 | test.config = supportedConfig |
| 3145 | } else { |
| 3146 | test.config = noSupportConfig |
| 3147 | } |
| 3148 | |
| 3149 | if supportedInResumeConnection { |
| 3150 | test.resumeConfig = &supportedConfig |
| 3151 | } else { |
| 3152 | test.resumeConfig = &noSupportConfig |
| 3153 | } |
| 3154 | |
| 3155 | switch suffix { |
| 3156 | case "YesToYes-Client", "YesToYes-Server": |
| 3157 | // When a session is resumed, it should |
| 3158 | // still be aware that its master |
| 3159 | // secret was generated via EMS and |
| 3160 | // thus it's safe to use tls-unique. |
| 3161 | test.flags = []string{expectEMSFlag} |
| 3162 | case "NoToYes-Server": |
| 3163 | // If an original connection did not |
| 3164 | // contain EMS, but a resumption |
| 3165 | // handshake does, then a server should |
| 3166 | // not resume the session. |
| 3167 | test.expectResumeRejected = true |
| 3168 | case "YesToNo-Server": |
| 3169 | // Resuming an EMS session without the |
| 3170 | // EMS extension should cause the |
| 3171 | // server to abort the connection. |
| 3172 | test.shouldFail = true |
| 3173 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 3174 | case "NoToYes-Client": |
| 3175 | // A client should abort a connection |
| 3176 | // where the server resumed a non-EMS |
| 3177 | // session but echoed the EMS |
| 3178 | // extension. |
| 3179 | test.shouldFail = true |
| 3180 | test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:" |
| 3181 | case "YesToNo-Client": |
| 3182 | // A client should abort a connection |
| 3183 | // where the server didn't echo EMS |
| 3184 | // when the session used it. |
| 3185 | test.shouldFail = true |
| 3186 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 3187 | } |
| 3188 | |
| 3189 | testCases = append(testCases, test) |
| 3190 | } |
| 3191 | } |
| 3192 | } |
David Benjamin | 163c956 | 2016-08-29 23:14:17 -0400 | [diff] [blame] | 3193 | |
| 3194 | // Switching EMS on renegotiation is forbidden. |
| 3195 | testCases = append(testCases, testCase{ |
| 3196 | name: "ExtendedMasterSecret-Renego-NoEMS", |
| 3197 | config: Config{ |
| 3198 | MaxVersion: VersionTLS12, |
| 3199 | Bugs: ProtocolBugs{ |
| 3200 | NoExtendedMasterSecret: true, |
| 3201 | NoExtendedMasterSecretOnRenegotiation: true, |
| 3202 | }, |
| 3203 | }, |
| 3204 | renegotiate: 1, |
| 3205 | flags: []string{ |
| 3206 | "-renegotiate-freely", |
| 3207 | "-expect-total-renegotiations", "1", |
| 3208 | }, |
| 3209 | }) |
| 3210 | |
| 3211 | testCases = append(testCases, testCase{ |
| 3212 | name: "ExtendedMasterSecret-Renego-Upgrade", |
| 3213 | config: Config{ |
| 3214 | MaxVersion: VersionTLS12, |
| 3215 | Bugs: ProtocolBugs{ |
| 3216 | NoExtendedMasterSecret: true, |
| 3217 | }, |
| 3218 | }, |
| 3219 | renegotiate: 1, |
| 3220 | flags: []string{ |
| 3221 | "-renegotiate-freely", |
| 3222 | "-expect-total-renegotiations", "1", |
| 3223 | }, |
| 3224 | shouldFail: true, |
| 3225 | expectedError: ":RENEGOTIATION_EMS_MISMATCH:", |
| 3226 | }) |
| 3227 | |
| 3228 | testCases = append(testCases, testCase{ |
| 3229 | name: "ExtendedMasterSecret-Renego-Downgrade", |
| 3230 | config: Config{ |
| 3231 | MaxVersion: VersionTLS12, |
| 3232 | Bugs: ProtocolBugs{ |
| 3233 | NoExtendedMasterSecretOnRenegotiation: true, |
| 3234 | }, |
| 3235 | }, |
| 3236 | renegotiate: 1, |
| 3237 | flags: []string{ |
| 3238 | "-renegotiate-freely", |
| 3239 | "-expect-total-renegotiations", "1", |
| 3240 | }, |
| 3241 | shouldFail: true, |
| 3242 | expectedError: ":RENEGOTIATION_EMS_MISMATCH:", |
| 3243 | }) |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3246 | type stateMachineTestConfig struct { |
| 3247 | protocol protocol |
| 3248 | async bool |
| 3249 | splitHandshake, packHandshakeFlight bool |
| 3250 | } |
| 3251 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 3252 | // Adds tests that try to cover the range of the handshake state machine, under |
| 3253 | // various conditions. Some of these are redundant with other tests, but they |
| 3254 | // only cover the synchronous case. |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3255 | func addAllStateMachineCoverageTests() { |
| 3256 | for _, async := range []bool{false, true} { |
| 3257 | for _, protocol := range []protocol{tls, dtls} { |
| 3258 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3259 | protocol: protocol, |
| 3260 | async: async, |
| 3261 | }) |
| 3262 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3263 | protocol: protocol, |
| 3264 | async: async, |
| 3265 | splitHandshake: true, |
| 3266 | }) |
| 3267 | if protocol == tls { |
| 3268 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3269 | protocol: protocol, |
| 3270 | async: async, |
| 3271 | packHandshakeFlight: true, |
| 3272 | }) |
| 3273 | } |
| 3274 | } |
| 3275 | } |
| 3276 | } |
| 3277 | |
| 3278 | func addStateMachineCoverageTests(config stateMachineTestConfig) { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3279 | var tests []testCase |
| 3280 | |
| 3281 | // Basic handshake, with resumption. Client and server, |
| 3282 | // session ID and session ticket. |
| 3283 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3284 | name: "Basic-Client", |
| 3285 | config: Config{ |
| 3286 | MaxVersion: VersionTLS12, |
| 3287 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3288 | resumeSession: true, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3289 | // Ensure session tickets are used, not session IDs. |
| 3290 | noSessionCache: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3291 | }) |
| 3292 | tests = append(tests, testCase{ |
| 3293 | name: "Basic-Client-RenewTicket", |
| 3294 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3295 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3296 | Bugs: ProtocolBugs{ |
| 3297 | RenewTicketOnResume: true, |
| 3298 | }, |
| 3299 | }, |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 3300 | flags: []string{"-expect-ticket-renewal"}, |
| 3301 | resumeSession: true, |
| 3302 | resumeRenewedSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3303 | }) |
| 3304 | tests = append(tests, testCase{ |
| 3305 | name: "Basic-Client-NoTicket", |
| 3306 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3307 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3308 | SessionTicketsDisabled: true, |
| 3309 | }, |
| 3310 | resumeSession: true, |
| 3311 | }) |
| 3312 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3313 | name: "Basic-Client-Implicit", |
| 3314 | config: Config{ |
| 3315 | MaxVersion: VersionTLS12, |
| 3316 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3317 | flags: []string{"-implicit-handshake"}, |
| 3318 | resumeSession: true, |
| 3319 | }) |
| 3320 | tests = append(tests, testCase{ |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3321 | testType: serverTest, |
| 3322 | name: "Basic-Server", |
| 3323 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3324 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3325 | Bugs: ProtocolBugs{ |
| 3326 | RequireSessionTickets: true, |
| 3327 | }, |
| 3328 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3329 | resumeSession: true, |
| 3330 | }) |
| 3331 | tests = append(tests, testCase{ |
| 3332 | testType: serverTest, |
| 3333 | name: "Basic-Server-NoTickets", |
| 3334 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3335 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3336 | SessionTicketsDisabled: true, |
| 3337 | }, |
| 3338 | resumeSession: true, |
| 3339 | }) |
| 3340 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3341 | testType: serverTest, |
| 3342 | name: "Basic-Server-Implicit", |
| 3343 | config: Config{ |
| 3344 | MaxVersion: VersionTLS12, |
| 3345 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3346 | flags: []string{"-implicit-handshake"}, |
| 3347 | resumeSession: true, |
| 3348 | }) |
| 3349 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3350 | testType: serverTest, |
| 3351 | name: "Basic-Server-EarlyCallback", |
| 3352 | config: Config{ |
| 3353 | MaxVersion: VersionTLS12, |
| 3354 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3355 | flags: []string{"-use-early-callback"}, |
| 3356 | resumeSession: true, |
| 3357 | }) |
| 3358 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3359 | // TLS 1.3 basic handshake shapes. |
David Benjamin | e73c7f4 | 2016-08-17 00:29:33 -0400 | [diff] [blame] | 3360 | if config.protocol == tls { |
| 3361 | tests = append(tests, testCase{ |
| 3362 | name: "TLS13-1RTT-Client", |
| 3363 | config: Config{ |
| 3364 | MaxVersion: VersionTLS13, |
| 3365 | MinVersion: VersionTLS13, |
| 3366 | }, |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 3367 | resumeSession: true, |
| 3368 | resumeRenewedSession: true, |
David Benjamin | e73c7f4 | 2016-08-17 00:29:33 -0400 | [diff] [blame] | 3369 | }) |
| 3370 | |
| 3371 | tests = append(tests, testCase{ |
| 3372 | testType: serverTest, |
| 3373 | name: "TLS13-1RTT-Server", |
| 3374 | config: Config{ |
| 3375 | MaxVersion: VersionTLS13, |
| 3376 | MinVersion: VersionTLS13, |
| 3377 | }, |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 3378 | resumeSession: true, |
| 3379 | resumeRenewedSession: true, |
David Benjamin | e73c7f4 | 2016-08-17 00:29:33 -0400 | [diff] [blame] | 3380 | }) |
| 3381 | |
| 3382 | tests = append(tests, testCase{ |
| 3383 | name: "TLS13-HelloRetryRequest-Client", |
| 3384 | config: Config{ |
| 3385 | MaxVersion: VersionTLS13, |
| 3386 | MinVersion: VersionTLS13, |
| 3387 | // P-384 requires a HelloRetryRequest against |
| 3388 | // BoringSSL's default configuration. Assert |
| 3389 | // that we do indeed test this with |
| 3390 | // ExpectMissingKeyShare. |
| 3391 | CurvePreferences: []CurveID{CurveP384}, |
| 3392 | Bugs: ProtocolBugs{ |
| 3393 | ExpectMissingKeyShare: true, |
| 3394 | }, |
| 3395 | }, |
| 3396 | // Cover HelloRetryRequest during an ECDHE-PSK resumption. |
| 3397 | resumeSession: true, |
| 3398 | }) |
| 3399 | |
| 3400 | tests = append(tests, testCase{ |
| 3401 | testType: serverTest, |
| 3402 | name: "TLS13-HelloRetryRequest-Server", |
| 3403 | config: Config{ |
| 3404 | MaxVersion: VersionTLS13, |
| 3405 | MinVersion: VersionTLS13, |
| 3406 | // Require a HelloRetryRequest for every curve. |
| 3407 | DefaultCurves: []CurveID{}, |
| 3408 | }, |
| 3409 | // Cover HelloRetryRequest during an ECDHE-PSK resumption. |
| 3410 | resumeSession: true, |
| 3411 | }) |
| 3412 | } |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3413 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3414 | // TLS client auth. |
| 3415 | tests = append(tests, testCase{ |
| 3416 | testType: clientTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3417 | name: "ClientAuth-NoCertificate-Client", |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3418 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3419 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3420 | ClientAuth: RequestClientCert, |
| 3421 | }, |
| 3422 | }) |
| 3423 | tests = append(tests, testCase{ |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3424 | testType: serverTest, |
| 3425 | name: "ClientAuth-NoCertificate-Server", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3426 | config: Config{ |
| 3427 | MaxVersion: VersionTLS12, |
| 3428 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3429 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3430 | flags: []string{"-verify-peer"}, |
| 3431 | }) |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3432 | if config.protocol == tls { |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3433 | tests = append(tests, testCase{ |
| 3434 | testType: clientTest, |
| 3435 | name: "ClientAuth-NoCertificate-Client-SSL3", |
| 3436 | config: Config{ |
| 3437 | MaxVersion: VersionSSL30, |
| 3438 | ClientAuth: RequestClientCert, |
| 3439 | }, |
| 3440 | }) |
| 3441 | tests = append(tests, testCase{ |
| 3442 | testType: serverTest, |
| 3443 | name: "ClientAuth-NoCertificate-Server-SSL3", |
| 3444 | config: Config{ |
| 3445 | MaxVersion: VersionSSL30, |
| 3446 | }, |
| 3447 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3448 | flags: []string{"-verify-peer"}, |
| 3449 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3450 | tests = append(tests, testCase{ |
| 3451 | testType: clientTest, |
| 3452 | name: "ClientAuth-NoCertificate-Client-TLS13", |
| 3453 | config: Config{ |
| 3454 | MaxVersion: VersionTLS13, |
| 3455 | ClientAuth: RequestClientCert, |
| 3456 | }, |
| 3457 | }) |
| 3458 | tests = append(tests, testCase{ |
| 3459 | testType: serverTest, |
| 3460 | name: "ClientAuth-NoCertificate-Server-TLS13", |
| 3461 | config: Config{ |
| 3462 | MaxVersion: VersionTLS13, |
| 3463 | }, |
| 3464 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3465 | flags: []string{"-verify-peer"}, |
| 3466 | }) |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3467 | } |
| 3468 | tests = append(tests, testCase{ |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3469 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3470 | name: "ClientAuth-RSA-Client", |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3471 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3472 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3473 | ClientAuth: RequireAnyClientCert, |
| 3474 | }, |
| 3475 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3476 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3477 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3478 | }, |
| 3479 | }) |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3480 | tests = append(tests, testCase{ |
| 3481 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3482 | name: "ClientAuth-RSA-Client-TLS13", |
| 3483 | config: Config{ |
| 3484 | MaxVersion: VersionTLS13, |
| 3485 | ClientAuth: RequireAnyClientCert, |
| 3486 | }, |
| 3487 | flags: []string{ |
| 3488 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3489 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3490 | }, |
| 3491 | }) |
| 3492 | tests = append(tests, testCase{ |
| 3493 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3494 | name: "ClientAuth-ECDSA-Client", |
| 3495 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3496 | MaxVersion: VersionTLS12, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3497 | ClientAuth: RequireAnyClientCert, |
| 3498 | }, |
| 3499 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3500 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3501 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3502 | }, |
| 3503 | }) |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3504 | tests = append(tests, testCase{ |
| 3505 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3506 | name: "ClientAuth-ECDSA-Client-TLS13", |
| 3507 | config: Config{ |
| 3508 | MaxVersion: VersionTLS13, |
| 3509 | ClientAuth: RequireAnyClientCert, |
| 3510 | }, |
| 3511 | flags: []string{ |
| 3512 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3513 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 3514 | }, |
| 3515 | }) |
| 3516 | tests = append(tests, testCase{ |
| 3517 | testType: clientTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3518 | name: "ClientAuth-NoCertificate-OldCallback", |
| 3519 | config: Config{ |
| 3520 | MaxVersion: VersionTLS12, |
| 3521 | ClientAuth: RequestClientCert, |
| 3522 | }, |
| 3523 | flags: []string{"-use-old-client-cert-callback"}, |
| 3524 | }) |
| 3525 | tests = append(tests, testCase{ |
| 3526 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3527 | name: "ClientAuth-NoCertificate-OldCallback-TLS13", |
| 3528 | config: Config{ |
| 3529 | MaxVersion: VersionTLS13, |
| 3530 | ClientAuth: RequestClientCert, |
| 3531 | }, |
| 3532 | flags: []string{"-use-old-client-cert-callback"}, |
| 3533 | }) |
| 3534 | tests = append(tests, testCase{ |
| 3535 | testType: clientTest, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3536 | name: "ClientAuth-OldCallback", |
| 3537 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3538 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3539 | ClientAuth: RequireAnyClientCert, |
| 3540 | }, |
| 3541 | flags: []string{ |
| 3542 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3543 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3544 | "-use-old-client-cert-callback", |
| 3545 | }, |
| 3546 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3547 | tests = append(tests, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3548 | testType: clientTest, |
| 3549 | name: "ClientAuth-OldCallback-TLS13", |
| 3550 | config: Config{ |
| 3551 | MaxVersion: VersionTLS13, |
| 3552 | ClientAuth: RequireAnyClientCert, |
| 3553 | }, |
| 3554 | flags: []string{ |
| 3555 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3556 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3557 | "-use-old-client-cert-callback", |
| 3558 | }, |
| 3559 | }) |
| 3560 | tests = append(tests, testCase{ |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3561 | testType: serverTest, |
| 3562 | name: "ClientAuth-Server", |
| 3563 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3564 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3565 | Certificates: []Certificate{rsaCertificate}, |
| 3566 | }, |
| 3567 | flags: []string{"-require-any-client-certificate"}, |
| 3568 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3569 | tests = append(tests, testCase{ |
| 3570 | testType: serverTest, |
| 3571 | name: "ClientAuth-Server-TLS13", |
| 3572 | config: Config{ |
| 3573 | MaxVersion: VersionTLS13, |
| 3574 | Certificates: []Certificate{rsaCertificate}, |
| 3575 | }, |
| 3576 | flags: []string{"-require-any-client-certificate"}, |
| 3577 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3578 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3579 | // Test each key exchange on the server side for async keys. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3580 | tests = append(tests, testCase{ |
| 3581 | testType: serverTest, |
| 3582 | name: "Basic-Server-RSA", |
| 3583 | config: Config{ |
| 3584 | MaxVersion: VersionTLS12, |
| 3585 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 3586 | }, |
| 3587 | flags: []string{ |
| 3588 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3589 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3590 | }, |
| 3591 | }) |
| 3592 | tests = append(tests, testCase{ |
| 3593 | testType: serverTest, |
| 3594 | name: "Basic-Server-ECDHE-RSA", |
| 3595 | config: Config{ |
| 3596 | MaxVersion: VersionTLS12, |
| 3597 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3598 | }, |
| 3599 | flags: []string{ |
| 3600 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3601 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3602 | }, |
| 3603 | }) |
| 3604 | tests = append(tests, testCase{ |
| 3605 | testType: serverTest, |
| 3606 | name: "Basic-Server-ECDHE-ECDSA", |
| 3607 | config: Config{ |
| 3608 | MaxVersion: VersionTLS12, |
| 3609 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 3610 | }, |
| 3611 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3612 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3613 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3614 | }, |
| 3615 | }) |
| 3616 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3617 | // No session ticket support; server doesn't send NewSessionTicket. |
| 3618 | tests = append(tests, testCase{ |
| 3619 | name: "SessionTicketsDisabled-Client", |
| 3620 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3621 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3622 | SessionTicketsDisabled: true, |
| 3623 | }, |
| 3624 | }) |
| 3625 | tests = append(tests, testCase{ |
| 3626 | testType: serverTest, |
| 3627 | name: "SessionTicketsDisabled-Server", |
| 3628 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3629 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3630 | SessionTicketsDisabled: true, |
| 3631 | }, |
| 3632 | }) |
| 3633 | |
| 3634 | // Skip ServerKeyExchange in PSK key exchange if there's no |
| 3635 | // identity hint. |
| 3636 | tests = append(tests, testCase{ |
| 3637 | name: "EmptyPSKHint-Client", |
| 3638 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3639 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3640 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3641 | PreSharedKey: []byte("secret"), |
| 3642 | }, |
| 3643 | flags: []string{"-psk", "secret"}, |
| 3644 | }) |
| 3645 | tests = append(tests, testCase{ |
| 3646 | testType: serverTest, |
| 3647 | name: "EmptyPSKHint-Server", |
| 3648 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3649 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3650 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3651 | PreSharedKey: []byte("secret"), |
| 3652 | }, |
| 3653 | flags: []string{"-psk", "secret"}, |
| 3654 | }) |
| 3655 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3656 | // OCSP stapling tests. |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3657 | tests = append(tests, testCase{ |
| 3658 | testType: clientTest, |
| 3659 | name: "OCSPStapling-Client", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3660 | config: Config{ |
| 3661 | MaxVersion: VersionTLS12, |
| 3662 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3663 | flags: []string{ |
| 3664 | "-enable-ocsp-stapling", |
| 3665 | "-expect-ocsp-response", |
| 3666 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3667 | "-verify-peer", |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3668 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3669 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3670 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3671 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3672 | testType: serverTest, |
| 3673 | name: "OCSPStapling-Server", |
| 3674 | config: Config{ |
| 3675 | MaxVersion: VersionTLS12, |
| 3676 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3677 | expectedOCSPResponse: testOCSPResponse, |
| 3678 | flags: []string{ |
| 3679 | "-ocsp-response", |
| 3680 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3681 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3682 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3683 | }) |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3684 | tests = append(tests, testCase{ |
| 3685 | testType: clientTest, |
| 3686 | name: "OCSPStapling-Client-TLS13", |
| 3687 | config: Config{ |
| 3688 | MaxVersion: VersionTLS13, |
| 3689 | }, |
| 3690 | flags: []string{ |
| 3691 | "-enable-ocsp-stapling", |
| 3692 | "-expect-ocsp-response", |
| 3693 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3694 | "-verify-peer", |
| 3695 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3696 | resumeSession: true, |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3697 | }) |
| 3698 | tests = append(tests, testCase{ |
| 3699 | testType: serverTest, |
| 3700 | name: "OCSPStapling-Server-TLS13", |
| 3701 | config: Config{ |
| 3702 | MaxVersion: VersionTLS13, |
| 3703 | }, |
| 3704 | expectedOCSPResponse: testOCSPResponse, |
| 3705 | flags: []string{ |
| 3706 | "-ocsp-response", |
| 3707 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3708 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3709 | resumeSession: true, |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3710 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3711 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3712 | // Certificate verification tests. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3713 | for _, vers := range tlsVersions { |
| 3714 | if config.protocol == dtls && !vers.hasDTLS { |
| 3715 | continue |
| 3716 | } |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3717 | for _, testType := range []testType{clientTest, serverTest} { |
| 3718 | suffix := "-Client" |
| 3719 | if testType == serverTest { |
| 3720 | suffix = "-Server" |
| 3721 | } |
| 3722 | suffix += "-" + vers.name |
| 3723 | |
| 3724 | flag := "-verify-peer" |
| 3725 | if testType == serverTest { |
| 3726 | flag = "-require-any-client-certificate" |
| 3727 | } |
| 3728 | |
| 3729 | tests = append(tests, testCase{ |
| 3730 | testType: testType, |
| 3731 | name: "CertificateVerificationSucceed" + suffix, |
| 3732 | config: Config{ |
| 3733 | MaxVersion: vers.version, |
| 3734 | Certificates: []Certificate{rsaCertificate}, |
| 3735 | }, |
| 3736 | flags: []string{ |
| 3737 | flag, |
| 3738 | "-expect-verify-result", |
| 3739 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3740 | resumeSession: true, |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3741 | }) |
| 3742 | tests = append(tests, testCase{ |
| 3743 | testType: testType, |
| 3744 | name: "CertificateVerificationFail" + suffix, |
| 3745 | config: Config{ |
| 3746 | MaxVersion: vers.version, |
| 3747 | Certificates: []Certificate{rsaCertificate}, |
| 3748 | }, |
| 3749 | flags: []string{ |
| 3750 | flag, |
| 3751 | "-verify-fail", |
| 3752 | }, |
| 3753 | shouldFail: true, |
| 3754 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 3755 | }) |
| 3756 | } |
| 3757 | |
| 3758 | // By default, the client is in a soft fail mode where the peer |
| 3759 | // certificate is verified but failures are non-fatal. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3760 | tests = append(tests, testCase{ |
| 3761 | testType: clientTest, |
| 3762 | name: "CertificateVerificationSoftFail-" + vers.name, |
| 3763 | config: Config{ |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3764 | MaxVersion: vers.version, |
| 3765 | Certificates: []Certificate{rsaCertificate}, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3766 | }, |
| 3767 | flags: []string{ |
| 3768 | "-verify-fail", |
| 3769 | "-expect-verify-result", |
| 3770 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3771 | resumeSession: true, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3772 | }) |
| 3773 | } |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3774 | |
David Benjamin | 1d4f4c0 | 2016-07-26 18:03:08 -0400 | [diff] [blame] | 3775 | tests = append(tests, testCase{ |
| 3776 | name: "ShimSendAlert", |
| 3777 | flags: []string{"-send-alert"}, |
| 3778 | shimWritesFirst: true, |
| 3779 | shouldFail: true, |
| 3780 | expectedLocalError: "remote error: decompression failure", |
| 3781 | }) |
| 3782 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3783 | if config.protocol == tls { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3784 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3785 | name: "Renegotiate-Client", |
| 3786 | config: Config{ |
| 3787 | MaxVersion: VersionTLS12, |
| 3788 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 3789 | renegotiate: 1, |
| 3790 | flags: []string{ |
| 3791 | "-renegotiate-freely", |
| 3792 | "-expect-total-renegotiations", "1", |
| 3793 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3794 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3795 | |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 3796 | tests = append(tests, testCase{ |
| 3797 | name: "SendHalfHelloRequest", |
| 3798 | config: Config{ |
| 3799 | MaxVersion: VersionTLS12, |
| 3800 | Bugs: ProtocolBugs{ |
| 3801 | PackHelloRequestWithFinished: config.packHandshakeFlight, |
| 3802 | }, |
| 3803 | }, |
| 3804 | sendHalfHelloRequest: true, |
| 3805 | flags: []string{"-renegotiate-ignore"}, |
| 3806 | shouldFail: true, |
| 3807 | expectedError: ":UNEXPECTED_RECORD:", |
| 3808 | }) |
| 3809 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3810 | // NPN on client and server; results in post-handshake message. |
| 3811 | tests = append(tests, testCase{ |
| 3812 | name: "NPN-Client", |
| 3813 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3814 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3815 | NextProtos: []string{"foo"}, |
| 3816 | }, |
| 3817 | flags: []string{"-select-next-proto", "foo"}, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3818 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3819 | expectedNextProto: "foo", |
| 3820 | expectedNextProtoType: npn, |
| 3821 | }) |
| 3822 | tests = append(tests, testCase{ |
| 3823 | testType: serverTest, |
| 3824 | name: "NPN-Server", |
| 3825 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3826 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3827 | NextProtos: []string{"bar"}, |
| 3828 | }, |
| 3829 | flags: []string{ |
| 3830 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3831 | "-expect-next-proto", "bar", |
| 3832 | }, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3833 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3834 | expectedNextProto: "bar", |
| 3835 | expectedNextProtoType: npn, |
| 3836 | }) |
| 3837 | |
| 3838 | // TODO(davidben): Add tests for when False Start doesn't trigger. |
| 3839 | |
| 3840 | // Client does False Start and negotiates NPN. |
| 3841 | tests = append(tests, testCase{ |
| 3842 | name: "FalseStart", |
| 3843 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3844 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3845 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3846 | NextProtos: []string{"foo"}, |
| 3847 | Bugs: ProtocolBugs{ |
| 3848 | ExpectFalseStart: true, |
| 3849 | }, |
| 3850 | }, |
| 3851 | flags: []string{ |
| 3852 | "-false-start", |
| 3853 | "-select-next-proto", "foo", |
| 3854 | }, |
| 3855 | shimWritesFirst: true, |
| 3856 | resumeSession: true, |
| 3857 | }) |
| 3858 | |
| 3859 | // Client does False Start and negotiates ALPN. |
| 3860 | tests = append(tests, testCase{ |
| 3861 | name: "FalseStart-ALPN", |
| 3862 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3863 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3864 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3865 | NextProtos: []string{"foo"}, |
| 3866 | Bugs: ProtocolBugs{ |
| 3867 | ExpectFalseStart: true, |
| 3868 | }, |
| 3869 | }, |
| 3870 | flags: []string{ |
| 3871 | "-false-start", |
| 3872 | "-advertise-alpn", "\x03foo", |
| 3873 | }, |
| 3874 | shimWritesFirst: true, |
| 3875 | resumeSession: true, |
| 3876 | }) |
| 3877 | |
| 3878 | // Client does False Start but doesn't explicitly call |
| 3879 | // SSL_connect. |
| 3880 | tests = append(tests, testCase{ |
| 3881 | name: "FalseStart-Implicit", |
| 3882 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3883 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3884 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3885 | NextProtos: []string{"foo"}, |
| 3886 | }, |
| 3887 | flags: []string{ |
| 3888 | "-implicit-handshake", |
| 3889 | "-false-start", |
| 3890 | "-advertise-alpn", "\x03foo", |
| 3891 | }, |
| 3892 | }) |
| 3893 | |
| 3894 | // False Start without session tickets. |
| 3895 | tests = append(tests, testCase{ |
| 3896 | name: "FalseStart-SessionTicketsDisabled", |
| 3897 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3898 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3899 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3900 | NextProtos: []string{"foo"}, |
| 3901 | SessionTicketsDisabled: true, |
| 3902 | Bugs: ProtocolBugs{ |
| 3903 | ExpectFalseStart: true, |
| 3904 | }, |
| 3905 | }, |
| 3906 | flags: []string{ |
| 3907 | "-false-start", |
| 3908 | "-select-next-proto", "foo", |
| 3909 | }, |
| 3910 | shimWritesFirst: true, |
| 3911 | }) |
| 3912 | |
Adam Langley | df759b5 | 2016-07-11 15:24:37 -0700 | [diff] [blame] | 3913 | tests = append(tests, testCase{ |
| 3914 | name: "FalseStart-CECPQ1", |
| 3915 | config: Config{ |
| 3916 | MaxVersion: VersionTLS12, |
| 3917 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 3918 | NextProtos: []string{"foo"}, |
| 3919 | Bugs: ProtocolBugs{ |
| 3920 | ExpectFalseStart: true, |
| 3921 | }, |
| 3922 | }, |
| 3923 | flags: []string{ |
| 3924 | "-false-start", |
| 3925 | "-cipher", "DEFAULT:kCECPQ1", |
| 3926 | "-select-next-proto", "foo", |
| 3927 | }, |
| 3928 | shimWritesFirst: true, |
| 3929 | resumeSession: true, |
| 3930 | }) |
| 3931 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3932 | // Server parses a V2ClientHello. |
| 3933 | tests = append(tests, testCase{ |
| 3934 | testType: serverTest, |
| 3935 | name: "SendV2ClientHello", |
| 3936 | config: Config{ |
| 3937 | // Choose a cipher suite that does not involve |
| 3938 | // elliptic curves, so no extensions are |
| 3939 | // involved. |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3940 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 3941 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3942 | Bugs: ProtocolBugs{ |
| 3943 | SendV2ClientHello: true, |
| 3944 | }, |
| 3945 | }, |
| 3946 | }) |
| 3947 | |
| 3948 | // Client sends a Channel ID. |
| 3949 | tests = append(tests, testCase{ |
| 3950 | name: "ChannelID-Client", |
| 3951 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3952 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3953 | RequestChannelID: true, |
| 3954 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3955 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3956 | resumeSession: true, |
| 3957 | expectChannelID: true, |
| 3958 | }) |
| 3959 | |
| 3960 | // Server accepts a Channel ID. |
| 3961 | tests = append(tests, testCase{ |
| 3962 | testType: serverTest, |
| 3963 | name: "ChannelID-Server", |
| 3964 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3965 | MaxVersion: VersionTLS12, |
| 3966 | ChannelID: channelIDKey, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3967 | }, |
| 3968 | flags: []string{ |
| 3969 | "-expect-channel-id", |
| 3970 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3971 | }, |
| 3972 | resumeSession: true, |
| 3973 | expectChannelID: true, |
| 3974 | }) |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3975 | |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3976 | // Channel ID and NPN at the same time, to ensure their relative |
| 3977 | // ordering is correct. |
| 3978 | tests = append(tests, testCase{ |
| 3979 | name: "ChannelID-NPN-Client", |
| 3980 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3981 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3982 | RequestChannelID: true, |
| 3983 | NextProtos: []string{"foo"}, |
| 3984 | }, |
| 3985 | flags: []string{ |
| 3986 | "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile), |
| 3987 | "-select-next-proto", "foo", |
| 3988 | }, |
| 3989 | resumeSession: true, |
| 3990 | expectChannelID: true, |
| 3991 | expectedNextProto: "foo", |
| 3992 | expectedNextProtoType: npn, |
| 3993 | }) |
| 3994 | tests = append(tests, testCase{ |
| 3995 | testType: serverTest, |
| 3996 | name: "ChannelID-NPN-Server", |
| 3997 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3998 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3999 | ChannelID: channelIDKey, |
| 4000 | NextProtos: []string{"bar"}, |
| 4001 | }, |
| 4002 | flags: []string{ |
| 4003 | "-expect-channel-id", |
| 4004 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 4005 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4006 | "-expect-next-proto", "bar", |
| 4007 | }, |
| 4008 | resumeSession: true, |
| 4009 | expectChannelID: true, |
| 4010 | expectedNextProto: "bar", |
| 4011 | expectedNextProtoType: npn, |
| 4012 | }) |
| 4013 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 4014 | // Bidirectional shutdown with the runner initiating. |
| 4015 | tests = append(tests, testCase{ |
| 4016 | name: "Shutdown-Runner", |
| 4017 | config: Config{ |
| 4018 | Bugs: ProtocolBugs{ |
| 4019 | ExpectCloseNotify: true, |
| 4020 | }, |
| 4021 | }, |
| 4022 | flags: []string{"-check-close-notify"}, |
| 4023 | }) |
| 4024 | |
| 4025 | // Bidirectional shutdown with the shim initiating. The runner, |
| 4026 | // in the meantime, sends garbage before the close_notify which |
| 4027 | // the shim must ignore. |
| 4028 | tests = append(tests, testCase{ |
| 4029 | name: "Shutdown-Shim", |
| 4030 | config: Config{ |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 4031 | MaxVersion: VersionTLS12, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 4032 | Bugs: ProtocolBugs{ |
| 4033 | ExpectCloseNotify: true, |
| 4034 | }, |
| 4035 | }, |
| 4036 | shimShutsDown: true, |
| 4037 | sendEmptyRecords: 1, |
| 4038 | sendWarningAlerts: 1, |
| 4039 | flags: []string{"-check-close-notify"}, |
| 4040 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 4041 | } else { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4042 | // TODO(davidben): DTLS 1.3 will want a similar thing for |
| 4043 | // HelloRetryRequest. |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 4044 | tests = append(tests, testCase{ |
| 4045 | name: "SkipHelloVerifyRequest", |
| 4046 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4047 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 4048 | Bugs: ProtocolBugs{ |
| 4049 | SkipHelloVerifyRequest: true, |
| 4050 | }, |
| 4051 | }, |
| 4052 | }) |
| 4053 | } |
| 4054 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 4055 | for _, test := range tests { |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 4056 | test.protocol = config.protocol |
| 4057 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 4058 | test.name += "-DTLS" |
| 4059 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 4060 | if config.async { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 4061 | test.name += "-Async" |
| 4062 | test.flags = append(test.flags, "-async") |
| 4063 | } else { |
| 4064 | test.name += "-Sync" |
| 4065 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 4066 | if config.splitHandshake { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 4067 | test.name += "-SplitHandshakeRecords" |
| 4068 | test.config.Bugs.MaxHandshakeRecordLength = 1 |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 4069 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 4070 | test.config.Bugs.MaxPacketLength = 256 |
| 4071 | test.flags = append(test.flags, "-mtu", "256") |
| 4072 | } |
| 4073 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 4074 | if config.packHandshakeFlight { |
| 4075 | test.name += "-PackHandshakeFlight" |
| 4076 | test.config.Bugs.PackHandshakeFlight = true |
| 4077 | } |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 4078 | testCases = append(testCases, test) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 4079 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 4080 | } |
| 4081 | |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4082 | func addDDoSCallbackTests() { |
| 4083 | // DDoS callback. |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4084 | for _, resume := range []bool{false, true} { |
| 4085 | suffix := "Resume" |
| 4086 | if resume { |
| 4087 | suffix = "No" + suffix |
| 4088 | } |
| 4089 | |
| 4090 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4091 | testType: serverTest, |
| 4092 | name: "Server-DDoS-OK-" + suffix, |
| 4093 | config: Config{ |
| 4094 | MaxVersion: VersionTLS12, |
| 4095 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4096 | flags: []string{"-install-ddos-callback"}, |
| 4097 | resumeSession: resume, |
| 4098 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4099 | testCases = append(testCases, testCase{ |
| 4100 | testType: serverTest, |
| 4101 | name: "Server-DDoS-OK-" + suffix + "-TLS13", |
| 4102 | config: Config{ |
| 4103 | MaxVersion: VersionTLS13, |
| 4104 | }, |
| 4105 | flags: []string{"-install-ddos-callback"}, |
| 4106 | resumeSession: resume, |
| 4107 | }) |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4108 | |
| 4109 | failFlag := "-fail-ddos-callback" |
| 4110 | if resume { |
| 4111 | failFlag = "-fail-second-ddos-callback" |
| 4112 | } |
| 4113 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4114 | testType: serverTest, |
| 4115 | name: "Server-DDoS-Reject-" + suffix, |
| 4116 | config: Config{ |
| 4117 | MaxVersion: VersionTLS12, |
| 4118 | }, |
David Benjamin | 2c66e07 | 2016-09-16 15:58:00 -0400 | [diff] [blame] | 4119 | flags: []string{"-install-ddos-callback", failFlag}, |
| 4120 | resumeSession: resume, |
| 4121 | shouldFail: true, |
| 4122 | expectedError: ":CONNECTION_REJECTED:", |
| 4123 | expectedLocalError: "remote error: internal error", |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4124 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4125 | testCases = append(testCases, testCase{ |
| 4126 | testType: serverTest, |
| 4127 | name: "Server-DDoS-Reject-" + suffix + "-TLS13", |
| 4128 | config: Config{ |
| 4129 | MaxVersion: VersionTLS13, |
| 4130 | }, |
David Benjamin | 2c66e07 | 2016-09-16 15:58:00 -0400 | [diff] [blame] | 4131 | flags: []string{"-install-ddos-callback", failFlag}, |
| 4132 | resumeSession: resume, |
| 4133 | shouldFail: true, |
| 4134 | expectedError: ":CONNECTION_REJECTED:", |
| 4135 | expectedLocalError: "remote error: internal error", |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4136 | }) |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4137 | } |
| 4138 | } |
| 4139 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4140 | func addVersionNegotiationTests() { |
| 4141 | for i, shimVers := range tlsVersions { |
| 4142 | // Assemble flags to disable all newer versions on the shim. |
| 4143 | var flags []string |
| 4144 | for _, vers := range tlsVersions[i+1:] { |
| 4145 | flags = append(flags, vers.flag) |
| 4146 | } |
| 4147 | |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4148 | // Test configuring the runner's maximum version. |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4149 | for _, runnerVers := range tlsVersions { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4150 | protocols := []protocol{tls} |
| 4151 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 4152 | protocols = append(protocols, dtls) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4153 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4154 | for _, protocol := range protocols { |
| 4155 | expectedVersion := shimVers.version |
| 4156 | if runnerVers.version < shimVers.version { |
| 4157 | expectedVersion = runnerVers.version |
| 4158 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4159 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4160 | suffix := shimVers.name + "-" + runnerVers.name |
| 4161 | if protocol == dtls { |
| 4162 | suffix += "-DTLS" |
| 4163 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4164 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 4165 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 4166 | |
David Benjamin | b1dd8cd | 2016-09-26 19:20:48 -0400 | [diff] [blame] | 4167 | // Determine the expected initial record-layer versions. |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 4168 | clientVers := shimVers.version |
| 4169 | if clientVers > VersionTLS10 { |
| 4170 | clientVers = VersionTLS10 |
| 4171 | } |
David Benjamin | b1dd8cd | 2016-09-26 19:20:48 -0400 | [diff] [blame] | 4172 | clientVers = versionToWire(clientVers, protocol == dtls) |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4173 | serverVers := expectedVersion |
| 4174 | if expectedVersion >= VersionTLS13 { |
| 4175 | serverVers = VersionTLS10 |
| 4176 | } |
David Benjamin | b1dd8cd | 2016-09-26 19:20:48 -0400 | [diff] [blame] | 4177 | serverVers = versionToWire(serverVers, protocol == dtls) |
| 4178 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4179 | testCases = append(testCases, testCase{ |
| 4180 | protocol: protocol, |
| 4181 | testType: clientTest, |
| 4182 | name: "VersionNegotiation-Client-" + suffix, |
| 4183 | config: Config{ |
| 4184 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 4185 | Bugs: ProtocolBugs{ |
| 4186 | ExpectInitialRecordVersion: clientVers, |
| 4187 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4188 | }, |
| 4189 | flags: flags, |
| 4190 | expectedVersion: expectedVersion, |
| 4191 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 4192 | testCases = append(testCases, testCase{ |
| 4193 | protocol: protocol, |
| 4194 | testType: clientTest, |
| 4195 | name: "VersionNegotiation-Client2-" + suffix, |
| 4196 | config: Config{ |
| 4197 | MaxVersion: runnerVers.version, |
| 4198 | Bugs: ProtocolBugs{ |
| 4199 | ExpectInitialRecordVersion: clientVers, |
| 4200 | }, |
| 4201 | }, |
| 4202 | flags: []string{"-max-version", shimVersFlag}, |
| 4203 | expectedVersion: expectedVersion, |
| 4204 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4205 | |
| 4206 | testCases = append(testCases, testCase{ |
| 4207 | protocol: protocol, |
| 4208 | testType: serverTest, |
| 4209 | name: "VersionNegotiation-Server-" + suffix, |
| 4210 | config: Config{ |
| 4211 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 4212 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4213 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 4214 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4215 | }, |
| 4216 | flags: flags, |
| 4217 | expectedVersion: expectedVersion, |
| 4218 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 4219 | testCases = append(testCases, testCase{ |
| 4220 | protocol: protocol, |
| 4221 | testType: serverTest, |
| 4222 | name: "VersionNegotiation-Server2-" + suffix, |
| 4223 | config: Config{ |
| 4224 | MaxVersion: runnerVers.version, |
| 4225 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4226 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 4227 | }, |
| 4228 | }, |
| 4229 | flags: []string{"-max-version", shimVersFlag}, |
| 4230 | expectedVersion: expectedVersion, |
| 4231 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4232 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4233 | } |
| 4234 | } |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4235 | |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4236 | // Test the version extension at all versions. |
| 4237 | for _, vers := range tlsVersions { |
| 4238 | protocols := []protocol{tls} |
| 4239 | if vers.hasDTLS { |
| 4240 | protocols = append(protocols, dtls) |
| 4241 | } |
| 4242 | for _, protocol := range protocols { |
| 4243 | suffix := vers.name |
| 4244 | if protocol == dtls { |
| 4245 | suffix += "-DTLS" |
| 4246 | } |
| 4247 | |
| 4248 | wireVersion := versionToWire(vers.version, protocol == dtls) |
| 4249 | testCases = append(testCases, testCase{ |
| 4250 | protocol: protocol, |
| 4251 | testType: serverTest, |
| 4252 | name: "VersionNegotiationExtension-" + suffix, |
| 4253 | config: Config{ |
| 4254 | Bugs: ProtocolBugs{ |
| 4255 | SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222}, |
| 4256 | }, |
| 4257 | }, |
| 4258 | expectedVersion: vers.version, |
| 4259 | }) |
| 4260 | } |
| 4261 | |
| 4262 | } |
| 4263 | |
| 4264 | // If all versions are unknown, negotiation fails. |
| 4265 | testCases = append(testCases, testCase{ |
| 4266 | testType: serverTest, |
| 4267 | name: "NoSupportedVersions", |
| 4268 | config: Config{ |
| 4269 | Bugs: ProtocolBugs{ |
| 4270 | SendSupportedVersions: []uint16{0x1111}, |
| 4271 | }, |
| 4272 | }, |
| 4273 | shouldFail: true, |
| 4274 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4275 | }) |
| 4276 | testCases = append(testCases, testCase{ |
| 4277 | protocol: dtls, |
| 4278 | testType: serverTest, |
| 4279 | name: "NoSupportedVersions-DTLS", |
| 4280 | config: Config{ |
| 4281 | Bugs: ProtocolBugs{ |
| 4282 | SendSupportedVersions: []uint16{0x1111}, |
| 4283 | }, |
| 4284 | }, |
| 4285 | shouldFail: true, |
| 4286 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4287 | }) |
| 4288 | |
| 4289 | testCases = append(testCases, testCase{ |
| 4290 | testType: serverTest, |
| 4291 | name: "ClientHelloVersionTooHigh", |
| 4292 | config: Config{ |
| 4293 | MaxVersion: VersionTLS13, |
| 4294 | Bugs: ProtocolBugs{ |
| 4295 | SendClientVersion: 0x0304, |
| 4296 | OmitSupportedVersions: true, |
| 4297 | }, |
| 4298 | }, |
| 4299 | expectedVersion: VersionTLS12, |
| 4300 | }) |
| 4301 | |
| 4302 | testCases = append(testCases, testCase{ |
| 4303 | testType: serverTest, |
| 4304 | name: "ConflictingVersionNegotiation", |
| 4305 | config: Config{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4306 | Bugs: ProtocolBugs{ |
David Benjamin | ad75a66 | 2016-09-30 15:42:59 -0400 | [diff] [blame] | 4307 | SendClientVersion: VersionTLS12, |
| 4308 | SendSupportedVersions: []uint16{VersionTLS11}, |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4309 | }, |
| 4310 | }, |
David Benjamin | ad75a66 | 2016-09-30 15:42:59 -0400 | [diff] [blame] | 4311 | // The extension takes precedence over the ClientHello version. |
| 4312 | expectedVersion: VersionTLS11, |
| 4313 | }) |
| 4314 | |
| 4315 | testCases = append(testCases, testCase{ |
| 4316 | testType: serverTest, |
| 4317 | name: "ConflictingVersionNegotiation-2", |
| 4318 | config: Config{ |
| 4319 | Bugs: ProtocolBugs{ |
| 4320 | SendClientVersion: VersionTLS11, |
| 4321 | SendSupportedVersions: []uint16{VersionTLS12}, |
| 4322 | }, |
| 4323 | }, |
| 4324 | // The extension takes precedence over the ClientHello version. |
| 4325 | expectedVersion: VersionTLS12, |
| 4326 | }) |
| 4327 | |
| 4328 | testCases = append(testCases, testCase{ |
| 4329 | testType: serverTest, |
| 4330 | name: "RejectFinalTLS13", |
| 4331 | config: Config{ |
| 4332 | Bugs: ProtocolBugs{ |
| 4333 | SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12}, |
| 4334 | }, |
| 4335 | }, |
| 4336 | // We currently implement a draft TLS 1.3 version. Ensure that |
| 4337 | // the true TLS 1.3 value is ignored for now. |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4338 | expectedVersion: VersionTLS12, |
| 4339 | }) |
| 4340 | |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4341 | // Test for version tolerance. |
| 4342 | testCases = append(testCases, testCase{ |
| 4343 | testType: serverTest, |
| 4344 | name: "MinorVersionTolerance", |
| 4345 | config: Config{ |
| 4346 | Bugs: ProtocolBugs{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4347 | SendClientVersion: 0x03ff, |
| 4348 | OmitSupportedVersions: true, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4349 | }, |
| 4350 | }, |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4351 | expectedVersion: VersionTLS12, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4352 | }) |
| 4353 | testCases = append(testCases, testCase{ |
| 4354 | testType: serverTest, |
| 4355 | name: "MajorVersionTolerance", |
| 4356 | config: Config{ |
| 4357 | Bugs: ProtocolBugs{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4358 | SendClientVersion: 0x0400, |
| 4359 | OmitSupportedVersions: true, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4360 | }, |
| 4361 | }, |
David Benjamin | ad75a66 | 2016-09-30 15:42:59 -0400 | [diff] [blame] | 4362 | // TLS 1.3 must be negotiated with the supported_versions |
| 4363 | // extension, not ClientHello.version. |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4364 | expectedVersion: VersionTLS12, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4365 | }) |
David Benjamin | ad75a66 | 2016-09-30 15:42:59 -0400 | [diff] [blame] | 4366 | testCases = append(testCases, testCase{ |
| 4367 | testType: serverTest, |
| 4368 | name: "VersionTolerance-TLS13", |
| 4369 | config: Config{ |
| 4370 | Bugs: ProtocolBugs{ |
| 4371 | // Although TLS 1.3 does not use |
| 4372 | // ClientHello.version, it still tolerates high |
| 4373 | // values there. |
| 4374 | SendClientVersion: 0x0400, |
| 4375 | }, |
| 4376 | }, |
| 4377 | expectedVersion: VersionTLS13, |
| 4378 | }) |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4379 | |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4380 | testCases = append(testCases, testCase{ |
| 4381 | protocol: dtls, |
| 4382 | testType: serverTest, |
| 4383 | name: "MinorVersionTolerance-DTLS", |
| 4384 | config: Config{ |
| 4385 | Bugs: ProtocolBugs{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4386 | SendClientVersion: 0xfe00, |
| 4387 | OmitSupportedVersions: true, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4388 | }, |
| 4389 | }, |
| 4390 | expectedVersion: VersionTLS12, |
| 4391 | }) |
| 4392 | testCases = append(testCases, testCase{ |
| 4393 | protocol: dtls, |
| 4394 | testType: serverTest, |
| 4395 | name: "MajorVersionTolerance-DTLS", |
| 4396 | config: Config{ |
| 4397 | Bugs: ProtocolBugs{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4398 | SendClientVersion: 0xfdff, |
| 4399 | OmitSupportedVersions: true, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4400 | }, |
| 4401 | }, |
| 4402 | expectedVersion: VersionTLS12, |
| 4403 | }) |
| 4404 | |
| 4405 | // Test that versions below 3.0 are rejected. |
| 4406 | testCases = append(testCases, testCase{ |
| 4407 | testType: serverTest, |
| 4408 | name: "VersionTooLow", |
| 4409 | config: Config{ |
| 4410 | Bugs: ProtocolBugs{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4411 | SendClientVersion: 0x0200, |
| 4412 | OmitSupportedVersions: true, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4413 | }, |
| 4414 | }, |
| 4415 | shouldFail: true, |
| 4416 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4417 | }) |
| 4418 | testCases = append(testCases, testCase{ |
| 4419 | protocol: dtls, |
| 4420 | testType: serverTest, |
| 4421 | name: "VersionTooLow-DTLS", |
| 4422 | config: Config{ |
| 4423 | Bugs: ProtocolBugs{ |
David Benjamin | 3c6a1ea | 2016-09-26 18:30:05 -0400 | [diff] [blame] | 4424 | SendClientVersion: 0xffff, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4425 | }, |
| 4426 | }, |
| 4427 | shouldFail: true, |
| 4428 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4429 | }) |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4430 | |
David Benjamin | 2dc0204 | 2016-09-19 19:57:37 -0400 | [diff] [blame] | 4431 | testCases = append(testCases, testCase{ |
| 4432 | name: "ServerBogusVersion", |
| 4433 | config: Config{ |
| 4434 | Bugs: ProtocolBugs{ |
| 4435 | SendServerHelloVersion: 0x1234, |
| 4436 | }, |
| 4437 | }, |
| 4438 | shouldFail: true, |
| 4439 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4440 | }) |
| 4441 | |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4442 | // Test TLS 1.3's downgrade signal. |
| 4443 | testCases = append(testCases, testCase{ |
| 4444 | name: "Downgrade-TLS12-Client", |
| 4445 | config: Config{ |
| 4446 | Bugs: ProtocolBugs{ |
| 4447 | NegotiateVersion: VersionTLS12, |
| 4448 | }, |
| 4449 | }, |
David Benjamin | 592b532 | 2016-09-30 15:15:01 -0400 | [diff] [blame] | 4450 | expectedVersion: VersionTLS12, |
David Benjamin | 5510863 | 2016-08-11 22:01:18 -0400 | [diff] [blame] | 4451 | // TODO(davidben): This test should fail once TLS 1.3 is final |
| 4452 | // and the fallback signal restored. |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4453 | }) |
| 4454 | testCases = append(testCases, testCase{ |
| 4455 | testType: serverTest, |
| 4456 | name: "Downgrade-TLS12-Server", |
| 4457 | config: Config{ |
| 4458 | Bugs: ProtocolBugs{ |
David Benjamin | 592b532 | 2016-09-30 15:15:01 -0400 | [diff] [blame] | 4459 | SendSupportedVersions: []uint16{VersionTLS12}, |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4460 | }, |
| 4461 | }, |
David Benjamin | 592b532 | 2016-09-30 15:15:01 -0400 | [diff] [blame] | 4462 | expectedVersion: VersionTLS12, |
David Benjamin | 5510863 | 2016-08-11 22:01:18 -0400 | [diff] [blame] | 4463 | // TODO(davidben): This test should fail once TLS 1.3 is final |
| 4464 | // and the fallback signal restored. |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4465 | }) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4466 | } |
| 4467 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4468 | func addMinimumVersionTests() { |
| 4469 | for i, shimVers := range tlsVersions { |
| 4470 | // Assemble flags to disable all older versions on the shim. |
| 4471 | var flags []string |
| 4472 | for _, vers := range tlsVersions[:i] { |
| 4473 | flags = append(flags, vers.flag) |
| 4474 | } |
| 4475 | |
| 4476 | for _, runnerVers := range tlsVersions { |
| 4477 | protocols := []protocol{tls} |
| 4478 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 4479 | protocols = append(protocols, dtls) |
| 4480 | } |
| 4481 | for _, protocol := range protocols { |
| 4482 | suffix := shimVers.name + "-" + runnerVers.name |
| 4483 | if protocol == dtls { |
| 4484 | suffix += "-DTLS" |
| 4485 | } |
| 4486 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 4487 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4488 | var expectedVersion uint16 |
| 4489 | var shouldFail bool |
David Benjamin | 6dbde98 | 2016-10-03 19:11:14 -0400 | [diff] [blame] | 4490 | var expectedError, expectedLocalError string |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4491 | if runnerVers.version >= shimVers.version { |
| 4492 | expectedVersion = runnerVers.version |
| 4493 | } else { |
| 4494 | shouldFail = true |
David Benjamin | 6dbde98 | 2016-10-03 19:11:14 -0400 | [diff] [blame] | 4495 | expectedError = ":UNSUPPORTED_PROTOCOL:" |
| 4496 | expectedLocalError = "remote error: protocol version not supported" |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | testCases = append(testCases, testCase{ |
| 4500 | protocol: protocol, |
| 4501 | testType: clientTest, |
| 4502 | name: "MinimumVersion-Client-" + suffix, |
| 4503 | config: Config{ |
| 4504 | MaxVersion: runnerVers.version, |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4505 | Bugs: ProtocolBugs{ |
David Benjamin | 6dbde98 | 2016-10-03 19:11:14 -0400 | [diff] [blame] | 4506 | // Ensure the server does not decline to |
| 4507 | // select a version (versions extension) or |
| 4508 | // cipher (some ciphers depend on versions). |
| 4509 | NegotiateVersion: runnerVers.version, |
| 4510 | IgnorePeerCipherPreferences: shouldFail, |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4511 | }, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4512 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4513 | flags: flags, |
| 4514 | expectedVersion: expectedVersion, |
| 4515 | shouldFail: shouldFail, |
David Benjamin | 6dbde98 | 2016-10-03 19:11:14 -0400 | [diff] [blame] | 4516 | expectedError: expectedError, |
| 4517 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4518 | }) |
| 4519 | testCases = append(testCases, testCase{ |
| 4520 | protocol: protocol, |
| 4521 | testType: clientTest, |
| 4522 | name: "MinimumVersion-Client2-" + suffix, |
| 4523 | config: Config{ |
| 4524 | MaxVersion: runnerVers.version, |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4525 | Bugs: ProtocolBugs{ |
David Benjamin | 6dbde98 | 2016-10-03 19:11:14 -0400 | [diff] [blame] | 4526 | // Ensure the server does not decline to |
| 4527 | // select a version (versions extension) or |
| 4528 | // cipher (some ciphers depend on versions). |
| 4529 | NegotiateVersion: runnerVers.version, |
| 4530 | IgnorePeerCipherPreferences: shouldFail, |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4531 | }, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4532 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4533 | flags: []string{"-min-version", shimVersFlag}, |
| 4534 | expectedVersion: expectedVersion, |
| 4535 | shouldFail: shouldFail, |
David Benjamin | 6dbde98 | 2016-10-03 19:11:14 -0400 | [diff] [blame] | 4536 | expectedError: expectedError, |
| 4537 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4538 | }) |
| 4539 | |
| 4540 | testCases = append(testCases, testCase{ |
| 4541 | protocol: protocol, |
| 4542 | testType: serverTest, |
| 4543 | name: "MinimumVersion-Server-" + suffix, |
| 4544 | config: Config{ |
| 4545 | MaxVersion: runnerVers.version, |
| 4546 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4547 | flags: flags, |
| 4548 | expectedVersion: expectedVersion, |
| 4549 | shouldFail: shouldFail, |
David Benjamin | 6dbde98 | 2016-10-03 19:11:14 -0400 | [diff] [blame] | 4550 | expectedError: expectedError, |
| 4551 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4552 | }) |
| 4553 | testCases = append(testCases, testCase{ |
| 4554 | protocol: protocol, |
| 4555 | testType: serverTest, |
| 4556 | name: "MinimumVersion-Server2-" + suffix, |
| 4557 | config: Config{ |
| 4558 | MaxVersion: runnerVers.version, |
| 4559 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4560 | flags: []string{"-min-version", shimVersFlag}, |
| 4561 | expectedVersion: expectedVersion, |
| 4562 | shouldFail: shouldFail, |
David Benjamin | 6dbde98 | 2016-10-03 19:11:14 -0400 | [diff] [blame] | 4563 | expectedError: expectedError, |
| 4564 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4565 | }) |
| 4566 | } |
| 4567 | } |
| 4568 | } |
| 4569 | } |
| 4570 | |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4571 | func addExtensionTests() { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4572 | // TODO(davidben): Extensions, where applicable, all move their server |
| 4573 | // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these |
| 4574 | // tests for both. Also test interaction with 0-RTT when implemented. |
| 4575 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4576 | // Repeat extensions tests all versions except SSL 3.0. |
| 4577 | for _, ver := range tlsVersions { |
| 4578 | if ver.version == VersionSSL30 { |
| 4579 | continue |
| 4580 | } |
| 4581 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4582 | // Test that duplicate extensions are rejected. |
| 4583 | testCases = append(testCases, testCase{ |
| 4584 | testType: clientTest, |
| 4585 | name: "DuplicateExtensionClient-" + ver.name, |
| 4586 | config: Config{ |
| 4587 | MaxVersion: ver.version, |
| 4588 | Bugs: ProtocolBugs{ |
| 4589 | DuplicateExtension: true, |
| 4590 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4591 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4592 | shouldFail: true, |
| 4593 | expectedLocalError: "remote error: error decoding message", |
| 4594 | }) |
| 4595 | testCases = append(testCases, testCase{ |
| 4596 | testType: serverTest, |
| 4597 | name: "DuplicateExtensionServer-" + ver.name, |
| 4598 | config: Config{ |
| 4599 | MaxVersion: ver.version, |
| 4600 | Bugs: ProtocolBugs{ |
| 4601 | DuplicateExtension: true, |
| 4602 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4603 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4604 | shouldFail: true, |
| 4605 | expectedLocalError: "remote error: error decoding message", |
| 4606 | }) |
| 4607 | |
| 4608 | // Test SNI. |
| 4609 | testCases = append(testCases, testCase{ |
| 4610 | testType: clientTest, |
| 4611 | name: "ServerNameExtensionClient-" + ver.name, |
| 4612 | config: Config{ |
| 4613 | MaxVersion: ver.version, |
| 4614 | Bugs: ProtocolBugs{ |
| 4615 | ExpectServerName: "example.com", |
| 4616 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4617 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4618 | flags: []string{"-host-name", "example.com"}, |
| 4619 | }) |
| 4620 | testCases = append(testCases, testCase{ |
| 4621 | testType: clientTest, |
| 4622 | name: "ServerNameExtensionClientMismatch-" + ver.name, |
| 4623 | config: Config{ |
| 4624 | MaxVersion: ver.version, |
| 4625 | Bugs: ProtocolBugs{ |
| 4626 | ExpectServerName: "mismatch.com", |
| 4627 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4628 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4629 | flags: []string{"-host-name", "example.com"}, |
| 4630 | shouldFail: true, |
| 4631 | expectedLocalError: "tls: unexpected server name", |
| 4632 | }) |
| 4633 | testCases = append(testCases, testCase{ |
| 4634 | testType: clientTest, |
| 4635 | name: "ServerNameExtensionClientMissing-" + ver.name, |
| 4636 | config: Config{ |
| 4637 | MaxVersion: ver.version, |
| 4638 | Bugs: ProtocolBugs{ |
| 4639 | ExpectServerName: "missing.com", |
| 4640 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4641 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4642 | shouldFail: true, |
| 4643 | expectedLocalError: "tls: unexpected server name", |
| 4644 | }) |
| 4645 | testCases = append(testCases, testCase{ |
| 4646 | testType: serverTest, |
| 4647 | name: "ServerNameExtensionServer-" + ver.name, |
| 4648 | config: Config{ |
| 4649 | MaxVersion: ver.version, |
| 4650 | ServerName: "example.com", |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 4651 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4652 | flags: []string{"-expect-server-name", "example.com"}, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4653 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4654 | }) |
| 4655 | |
| 4656 | // Test ALPN. |
| 4657 | testCases = append(testCases, testCase{ |
| 4658 | testType: clientTest, |
| 4659 | name: "ALPNClient-" + ver.name, |
| 4660 | config: Config{ |
| 4661 | MaxVersion: ver.version, |
| 4662 | NextProtos: []string{"foo"}, |
| 4663 | }, |
| 4664 | flags: []string{ |
| 4665 | "-advertise-alpn", "\x03foo\x03bar\x03baz", |
| 4666 | "-expect-alpn", "foo", |
| 4667 | }, |
| 4668 | expectedNextProto: "foo", |
| 4669 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4670 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4671 | }) |
| 4672 | testCases = append(testCases, testCase{ |
David Benjamin | 3e51757 | 2016-08-11 11:52:23 -0400 | [diff] [blame] | 4673 | testType: clientTest, |
| 4674 | name: "ALPNClient-Mismatch-" + ver.name, |
| 4675 | config: Config{ |
| 4676 | MaxVersion: ver.version, |
| 4677 | Bugs: ProtocolBugs{ |
| 4678 | SendALPN: "baz", |
| 4679 | }, |
| 4680 | }, |
| 4681 | flags: []string{ |
| 4682 | "-advertise-alpn", "\x03foo\x03bar", |
| 4683 | }, |
| 4684 | shouldFail: true, |
| 4685 | expectedError: ":INVALID_ALPN_PROTOCOL:", |
| 4686 | expectedLocalError: "remote error: illegal parameter", |
| 4687 | }) |
| 4688 | testCases = append(testCases, testCase{ |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4689 | testType: serverTest, |
| 4690 | name: "ALPNServer-" + ver.name, |
| 4691 | config: Config{ |
| 4692 | MaxVersion: ver.version, |
| 4693 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4694 | }, |
| 4695 | flags: []string{ |
| 4696 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4697 | "-select-alpn", "foo", |
| 4698 | }, |
| 4699 | expectedNextProto: "foo", |
| 4700 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4701 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4702 | }) |
| 4703 | testCases = append(testCases, testCase{ |
| 4704 | testType: serverTest, |
| 4705 | name: "ALPNServer-Decline-" + ver.name, |
| 4706 | config: Config{ |
| 4707 | MaxVersion: ver.version, |
| 4708 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4709 | }, |
| 4710 | flags: []string{"-decline-alpn"}, |
| 4711 | expectNoNextProto: true, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4712 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4713 | }) |
| 4714 | |
David Benjamin | 25fe85b | 2016-08-09 20:00:32 -0400 | [diff] [blame] | 4715 | // Test ALPN in async mode as well to ensure that extensions callbacks are only |
| 4716 | // called once. |
| 4717 | testCases = append(testCases, testCase{ |
| 4718 | testType: serverTest, |
| 4719 | name: "ALPNServer-Async-" + ver.name, |
| 4720 | config: Config{ |
| 4721 | MaxVersion: ver.version, |
| 4722 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4723 | }, |
| 4724 | flags: []string{ |
| 4725 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4726 | "-select-alpn", "foo", |
| 4727 | "-async", |
| 4728 | }, |
| 4729 | expectedNextProto: "foo", |
| 4730 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4731 | resumeSession: true, |
David Benjamin | 25fe85b | 2016-08-09 20:00:32 -0400 | [diff] [blame] | 4732 | }) |
| 4733 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4734 | var emptyString string |
| 4735 | testCases = append(testCases, testCase{ |
| 4736 | testType: clientTest, |
| 4737 | name: "ALPNClient-EmptyProtocolName-" + ver.name, |
| 4738 | config: Config{ |
| 4739 | MaxVersion: ver.version, |
| 4740 | NextProtos: []string{""}, |
| 4741 | Bugs: ProtocolBugs{ |
| 4742 | // A server returning an empty ALPN protocol |
| 4743 | // should be rejected. |
| 4744 | ALPNProtocol: &emptyString, |
| 4745 | }, |
| 4746 | }, |
| 4747 | flags: []string{ |
| 4748 | "-advertise-alpn", "\x03foo", |
| 4749 | }, |
| 4750 | shouldFail: true, |
| 4751 | expectedError: ":PARSE_TLSEXT:", |
| 4752 | }) |
| 4753 | testCases = append(testCases, testCase{ |
| 4754 | testType: serverTest, |
| 4755 | name: "ALPNServer-EmptyProtocolName-" + ver.name, |
| 4756 | config: Config{ |
| 4757 | MaxVersion: ver.version, |
| 4758 | // A ClientHello containing an empty ALPN protocol |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4759 | // should be rejected. |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4760 | NextProtos: []string{"foo", "", "baz"}, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4761 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4762 | flags: []string{ |
| 4763 | "-select-alpn", "foo", |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 4764 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4765 | shouldFail: true, |
| 4766 | expectedError: ":PARSE_TLSEXT:", |
| 4767 | }) |
| 4768 | |
| 4769 | // Test NPN and the interaction with ALPN. |
| 4770 | if ver.version < VersionTLS13 { |
| 4771 | // Test that the server prefers ALPN over NPN. |
| 4772 | testCases = append(testCases, testCase{ |
| 4773 | testType: serverTest, |
| 4774 | name: "ALPNServer-Preferred-" + ver.name, |
| 4775 | config: Config{ |
| 4776 | MaxVersion: ver.version, |
| 4777 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4778 | }, |
| 4779 | flags: []string{ |
| 4780 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4781 | "-select-alpn", "foo", |
| 4782 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4783 | }, |
| 4784 | expectedNextProto: "foo", |
| 4785 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4786 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4787 | }) |
| 4788 | testCases = append(testCases, testCase{ |
| 4789 | testType: serverTest, |
| 4790 | name: "ALPNServer-Preferred-Swapped-" + ver.name, |
| 4791 | config: Config{ |
| 4792 | MaxVersion: ver.version, |
| 4793 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4794 | Bugs: ProtocolBugs{ |
| 4795 | SwapNPNAndALPN: true, |
| 4796 | }, |
| 4797 | }, |
| 4798 | flags: []string{ |
| 4799 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4800 | "-select-alpn", "foo", |
| 4801 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4802 | }, |
| 4803 | expectedNextProto: "foo", |
| 4804 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4805 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4806 | }) |
| 4807 | |
| 4808 | // Test that negotiating both NPN and ALPN is forbidden. |
| 4809 | testCases = append(testCases, testCase{ |
| 4810 | name: "NegotiateALPNAndNPN-" + ver.name, |
| 4811 | config: Config{ |
| 4812 | MaxVersion: ver.version, |
| 4813 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4814 | Bugs: ProtocolBugs{ |
| 4815 | NegotiateALPNAndNPN: true, |
| 4816 | }, |
| 4817 | }, |
| 4818 | flags: []string{ |
| 4819 | "-advertise-alpn", "\x03foo", |
| 4820 | "-select-next-proto", "foo", |
| 4821 | }, |
| 4822 | shouldFail: true, |
| 4823 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4824 | }) |
| 4825 | testCases = append(testCases, testCase{ |
| 4826 | name: "NegotiateALPNAndNPN-Swapped-" + ver.name, |
| 4827 | config: Config{ |
| 4828 | MaxVersion: ver.version, |
| 4829 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4830 | Bugs: ProtocolBugs{ |
| 4831 | NegotiateALPNAndNPN: true, |
| 4832 | SwapNPNAndALPN: true, |
| 4833 | }, |
| 4834 | }, |
| 4835 | flags: []string{ |
| 4836 | "-advertise-alpn", "\x03foo", |
| 4837 | "-select-next-proto", "foo", |
| 4838 | }, |
| 4839 | shouldFail: true, |
| 4840 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4841 | }) |
| 4842 | |
| 4843 | // Test that NPN can be disabled with SSL_OP_DISABLE_NPN. |
| 4844 | testCases = append(testCases, testCase{ |
| 4845 | name: "DisableNPN-" + ver.name, |
| 4846 | config: Config{ |
| 4847 | MaxVersion: ver.version, |
| 4848 | NextProtos: []string{"foo"}, |
| 4849 | }, |
| 4850 | flags: []string{ |
| 4851 | "-select-next-proto", "foo", |
| 4852 | "-disable-npn", |
| 4853 | }, |
| 4854 | expectNoNextProto: true, |
| 4855 | }) |
| 4856 | } |
| 4857 | |
| 4858 | // Test ticket behavior. |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4859 | |
| 4860 | // Resume with a corrupt ticket. |
| 4861 | testCases = append(testCases, testCase{ |
| 4862 | testType: serverTest, |
| 4863 | name: "CorruptTicket-" + ver.name, |
| 4864 | config: Config{ |
| 4865 | MaxVersion: ver.version, |
| 4866 | Bugs: ProtocolBugs{ |
| 4867 | CorruptTicket: true, |
| 4868 | }, |
| 4869 | }, |
| 4870 | resumeSession: true, |
| 4871 | expectResumeRejected: true, |
| 4872 | }) |
| 4873 | // Test the ticket callback, with and without renewal. |
| 4874 | testCases = append(testCases, testCase{ |
| 4875 | testType: serverTest, |
| 4876 | name: "TicketCallback-" + ver.name, |
| 4877 | config: Config{ |
| 4878 | MaxVersion: ver.version, |
| 4879 | }, |
| 4880 | resumeSession: true, |
| 4881 | flags: []string{"-use-ticket-callback"}, |
| 4882 | }) |
| 4883 | testCases = append(testCases, testCase{ |
| 4884 | testType: serverTest, |
| 4885 | name: "TicketCallback-Renew-" + ver.name, |
| 4886 | config: Config{ |
| 4887 | MaxVersion: ver.version, |
| 4888 | Bugs: ProtocolBugs{ |
| 4889 | ExpectNewTicket: true, |
| 4890 | }, |
| 4891 | }, |
| 4892 | flags: []string{"-use-ticket-callback", "-renew-ticket"}, |
| 4893 | resumeSession: true, |
| 4894 | }) |
| 4895 | |
| 4896 | // Test that the ticket callback is only called once when everything before |
| 4897 | // it in the ClientHello is asynchronous. This corrupts the ticket so |
| 4898 | // certificate selection callbacks run. |
| 4899 | testCases = append(testCases, testCase{ |
| 4900 | testType: serverTest, |
| 4901 | name: "TicketCallback-SingleCall-" + ver.name, |
| 4902 | config: Config{ |
| 4903 | MaxVersion: ver.version, |
| 4904 | Bugs: ProtocolBugs{ |
| 4905 | CorruptTicket: true, |
| 4906 | }, |
| 4907 | }, |
| 4908 | resumeSession: true, |
| 4909 | expectResumeRejected: true, |
| 4910 | flags: []string{ |
| 4911 | "-use-ticket-callback", |
| 4912 | "-async", |
| 4913 | }, |
| 4914 | }) |
| 4915 | |
| 4916 | // Resume with an oversized session id. |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4917 | if ver.version < VersionTLS13 { |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4918 | testCases = append(testCases, testCase{ |
| 4919 | testType: serverTest, |
| 4920 | name: "OversizedSessionId-" + ver.name, |
| 4921 | config: Config{ |
| 4922 | MaxVersion: ver.version, |
| 4923 | Bugs: ProtocolBugs{ |
| 4924 | OversizedSessionId: true, |
| 4925 | }, |
| 4926 | }, |
| 4927 | resumeSession: true, |
| 4928 | shouldFail: true, |
| 4929 | expectedError: ":DECODE_ERROR:", |
| 4930 | }) |
| 4931 | } |
| 4932 | |
| 4933 | // Basic DTLS-SRTP tests. Include fake profiles to ensure they |
| 4934 | // are ignored. |
| 4935 | if ver.hasDTLS { |
| 4936 | testCases = append(testCases, testCase{ |
| 4937 | protocol: dtls, |
| 4938 | name: "SRTP-Client-" + ver.name, |
| 4939 | config: Config{ |
| 4940 | MaxVersion: ver.version, |
| 4941 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4942 | }, |
| 4943 | flags: []string{ |
| 4944 | "-srtp-profiles", |
| 4945 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4946 | }, |
| 4947 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4948 | }) |
| 4949 | testCases = append(testCases, testCase{ |
| 4950 | protocol: dtls, |
| 4951 | testType: serverTest, |
| 4952 | name: "SRTP-Server-" + ver.name, |
| 4953 | config: Config{ |
| 4954 | MaxVersion: ver.version, |
| 4955 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4956 | }, |
| 4957 | flags: []string{ |
| 4958 | "-srtp-profiles", |
| 4959 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4960 | }, |
| 4961 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4962 | }) |
| 4963 | // Test that the MKI is ignored. |
| 4964 | testCases = append(testCases, testCase{ |
| 4965 | protocol: dtls, |
| 4966 | testType: serverTest, |
| 4967 | name: "SRTP-Server-IgnoreMKI-" + ver.name, |
| 4968 | config: Config{ |
| 4969 | MaxVersion: ver.version, |
| 4970 | SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80}, |
| 4971 | Bugs: ProtocolBugs{ |
| 4972 | SRTPMasterKeyIdentifer: "bogus", |
| 4973 | }, |
| 4974 | }, |
| 4975 | flags: []string{ |
| 4976 | "-srtp-profiles", |
| 4977 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4978 | }, |
| 4979 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4980 | }) |
| 4981 | // Test that SRTP isn't negotiated on the server if there were |
| 4982 | // no matching profiles. |
| 4983 | testCases = append(testCases, testCase{ |
| 4984 | protocol: dtls, |
| 4985 | testType: serverTest, |
| 4986 | name: "SRTP-Server-NoMatch-" + ver.name, |
| 4987 | config: Config{ |
| 4988 | MaxVersion: ver.version, |
| 4989 | SRTPProtectionProfiles: []uint16{100, 101, 102}, |
| 4990 | }, |
| 4991 | flags: []string{ |
| 4992 | "-srtp-profiles", |
| 4993 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4994 | }, |
| 4995 | expectedSRTPProtectionProfile: 0, |
| 4996 | }) |
| 4997 | // Test that the server returning an invalid SRTP profile is |
| 4998 | // flagged as an error by the client. |
| 4999 | testCases = append(testCases, testCase{ |
| 5000 | protocol: dtls, |
| 5001 | name: "SRTP-Client-NoMatch-" + ver.name, |
| 5002 | config: Config{ |
| 5003 | MaxVersion: ver.version, |
| 5004 | Bugs: ProtocolBugs{ |
| 5005 | SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32, |
| 5006 | }, |
| 5007 | }, |
| 5008 | flags: []string{ |
| 5009 | "-srtp-profiles", |
| 5010 | "SRTP_AES128_CM_SHA1_80", |
| 5011 | }, |
| 5012 | shouldFail: true, |
| 5013 | expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:", |
| 5014 | }) |
| 5015 | } |
| 5016 | |
| 5017 | // Test SCT list. |
| 5018 | testCases = append(testCases, testCase{ |
| 5019 | name: "SignedCertificateTimestampList-Client-" + ver.name, |
| 5020 | testType: clientTest, |
| 5021 | config: Config{ |
| 5022 | MaxVersion: ver.version, |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 5023 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5024 | flags: []string{ |
| 5025 | "-enable-signed-cert-timestamps", |
| 5026 | "-expect-signed-cert-timestamps", |
| 5027 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 5028 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5029 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5030 | }) |
David Benjamin | daa8850 | 2016-10-04 16:32:16 -0400 | [diff] [blame] | 5031 | |
| 5032 | // The SCT extension did not specify that it must only be sent on resumption as it |
| 5033 | // should have, so test that we tolerate but ignore it. |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5034 | testCases = append(testCases, testCase{ |
| 5035 | name: "SendSCTListOnResume-" + ver.name, |
| 5036 | config: Config{ |
| 5037 | MaxVersion: ver.version, |
| 5038 | Bugs: ProtocolBugs{ |
| 5039 | SendSCTListOnResume: []byte("bogus"), |
| 5040 | }, |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 5041 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5042 | flags: []string{ |
| 5043 | "-enable-signed-cert-timestamps", |
| 5044 | "-expect-signed-cert-timestamps", |
| 5045 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 5046 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5047 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5048 | }) |
David Benjamin | daa8850 | 2016-10-04 16:32:16 -0400 | [diff] [blame] | 5049 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5050 | testCases = append(testCases, testCase{ |
| 5051 | name: "SignedCertificateTimestampList-Server-" + ver.name, |
| 5052 | testType: serverTest, |
| 5053 | config: Config{ |
| 5054 | MaxVersion: ver.version, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 5055 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5056 | flags: []string{ |
| 5057 | "-signed-cert-timestamps", |
| 5058 | base64.StdEncoding.EncodeToString(testSCTList), |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 5059 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5060 | expectedSCTList: testSCTList, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5061 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5062 | }) |
| 5063 | } |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5064 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 5065 | testCases = append(testCases, testCase{ |
Adam Langley | 33ad2b5 | 2015-07-20 17:43:53 -0700 | [diff] [blame] | 5066 | testType: clientTest, |
| 5067 | name: "ClientHelloPadding", |
| 5068 | config: Config{ |
| 5069 | Bugs: ProtocolBugs{ |
| 5070 | RequireClientHelloSize: 512, |
| 5071 | }, |
| 5072 | }, |
| 5073 | // This hostname just needs to be long enough to push the |
| 5074 | // ClientHello into F5's danger zone between 256 and 511 bytes |
| 5075 | // long. |
| 5076 | flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"}, |
| 5077 | }) |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 5078 | |
| 5079 | // Extensions should not function in SSL 3.0. |
| 5080 | testCases = append(testCases, testCase{ |
| 5081 | testType: serverTest, |
| 5082 | name: "SSLv3Extensions-NoALPN", |
| 5083 | config: Config{ |
| 5084 | MaxVersion: VersionSSL30, |
| 5085 | NextProtos: []string{"foo", "bar", "baz"}, |
| 5086 | }, |
| 5087 | flags: []string{ |
| 5088 | "-select-alpn", "foo", |
| 5089 | }, |
| 5090 | expectNoNextProto: true, |
| 5091 | }) |
| 5092 | |
| 5093 | // Test session tickets separately as they follow a different codepath. |
| 5094 | testCases = append(testCases, testCase{ |
| 5095 | testType: serverTest, |
| 5096 | name: "SSLv3Extensions-NoTickets", |
| 5097 | config: Config{ |
| 5098 | MaxVersion: VersionSSL30, |
| 5099 | Bugs: ProtocolBugs{ |
| 5100 | // Historically, session tickets in SSL 3.0 |
| 5101 | // failed in different ways depending on whether |
| 5102 | // the client supported renegotiation_info. |
| 5103 | NoRenegotiationInfo: true, |
| 5104 | }, |
| 5105 | }, |
| 5106 | resumeSession: true, |
| 5107 | }) |
| 5108 | testCases = append(testCases, testCase{ |
| 5109 | testType: serverTest, |
| 5110 | name: "SSLv3Extensions-NoTickets2", |
| 5111 | config: Config{ |
| 5112 | MaxVersion: VersionSSL30, |
| 5113 | }, |
| 5114 | resumeSession: true, |
| 5115 | }) |
| 5116 | |
| 5117 | // But SSL 3.0 does send and process renegotiation_info. |
| 5118 | testCases = append(testCases, testCase{ |
| 5119 | testType: serverTest, |
| 5120 | name: "SSLv3Extensions-RenegotiationInfo", |
| 5121 | config: Config{ |
| 5122 | MaxVersion: VersionSSL30, |
| 5123 | Bugs: ProtocolBugs{ |
| 5124 | RequireRenegotiationInfo: true, |
| 5125 | }, |
| 5126 | }, |
| 5127 | }) |
| 5128 | testCases = append(testCases, testCase{ |
| 5129 | testType: serverTest, |
| 5130 | name: "SSLv3Extensions-RenegotiationInfo-SCSV", |
| 5131 | config: Config{ |
| 5132 | MaxVersion: VersionSSL30, |
| 5133 | Bugs: ProtocolBugs{ |
| 5134 | NoRenegotiationInfo: true, |
| 5135 | SendRenegotiationSCSV: true, |
| 5136 | RequireRenegotiationInfo: true, |
| 5137 | }, |
| 5138 | }, |
| 5139 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5140 | |
| 5141 | // Test that illegal extensions in TLS 1.3 are rejected by the client if |
| 5142 | // in ServerHello. |
| 5143 | testCases = append(testCases, testCase{ |
| 5144 | name: "NPN-Forbidden-TLS13", |
| 5145 | config: Config{ |
| 5146 | MaxVersion: VersionTLS13, |
| 5147 | NextProtos: []string{"foo"}, |
| 5148 | Bugs: ProtocolBugs{ |
| 5149 | NegotiateNPNAtAllVersions: true, |
| 5150 | }, |
| 5151 | }, |
| 5152 | flags: []string{"-select-next-proto", "foo"}, |
| 5153 | shouldFail: true, |
| 5154 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 5155 | }) |
| 5156 | testCases = append(testCases, testCase{ |
| 5157 | name: "EMS-Forbidden-TLS13", |
| 5158 | config: Config{ |
| 5159 | MaxVersion: VersionTLS13, |
| 5160 | Bugs: ProtocolBugs{ |
| 5161 | NegotiateEMSAtAllVersions: true, |
| 5162 | }, |
| 5163 | }, |
| 5164 | shouldFail: true, |
| 5165 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 5166 | }) |
| 5167 | testCases = append(testCases, testCase{ |
| 5168 | name: "RenegotiationInfo-Forbidden-TLS13", |
| 5169 | config: Config{ |
| 5170 | MaxVersion: VersionTLS13, |
| 5171 | Bugs: ProtocolBugs{ |
| 5172 | NegotiateRenegotiationInfoAtAllVersions: true, |
| 5173 | }, |
| 5174 | }, |
| 5175 | shouldFail: true, |
| 5176 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 5177 | }) |
| 5178 | testCases = append(testCases, testCase{ |
| 5179 | name: "ChannelID-Forbidden-TLS13", |
| 5180 | config: Config{ |
| 5181 | MaxVersion: VersionTLS13, |
| 5182 | RequestChannelID: true, |
| 5183 | Bugs: ProtocolBugs{ |
| 5184 | NegotiateChannelIDAtAllVersions: true, |
| 5185 | }, |
| 5186 | }, |
| 5187 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
| 5188 | shouldFail: true, |
| 5189 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 5190 | }) |
| 5191 | testCases = append(testCases, testCase{ |
| 5192 | name: "Ticket-Forbidden-TLS13", |
| 5193 | config: Config{ |
| 5194 | MaxVersion: VersionTLS12, |
| 5195 | }, |
| 5196 | resumeConfig: &Config{ |
| 5197 | MaxVersion: VersionTLS13, |
| 5198 | Bugs: ProtocolBugs{ |
| 5199 | AdvertiseTicketExtension: true, |
| 5200 | }, |
| 5201 | }, |
| 5202 | resumeSession: true, |
| 5203 | shouldFail: true, |
| 5204 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 5205 | }) |
| 5206 | |
| 5207 | // Test that illegal extensions in TLS 1.3 are declined by the server if |
| 5208 | // offered in ClientHello. The runner's server will fail if this occurs, |
| 5209 | // so we exercise the offering path. (EMS and Renegotiation Info are |
| 5210 | // implicit in every test.) |
| 5211 | testCases = append(testCases, testCase{ |
| 5212 | testType: serverTest, |
| 5213 | name: "ChannelID-Declined-TLS13", |
| 5214 | config: Config{ |
| 5215 | MaxVersion: VersionTLS13, |
| 5216 | ChannelID: channelIDKey, |
| 5217 | }, |
| 5218 | flags: []string{"-enable-channel-id"}, |
| 5219 | }) |
| 5220 | testCases = append(testCases, testCase{ |
| 5221 | testType: serverTest, |
David Benjamin | 7364719 | 2016-09-22 16:24:04 -0400 | [diff] [blame] | 5222 | name: "NPN-Declined-TLS13", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5223 | config: Config{ |
| 5224 | MaxVersion: VersionTLS13, |
| 5225 | NextProtos: []string{"bar"}, |
| 5226 | }, |
| 5227 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 5228 | }) |
David Benjamin | 196df5b | 2016-09-21 16:23:27 -0400 | [diff] [blame] | 5229 | |
| 5230 | testCases = append(testCases, testCase{ |
| 5231 | testType: serverTest, |
| 5232 | name: "InvalidChannelIDSignature", |
| 5233 | config: Config{ |
| 5234 | MaxVersion: VersionTLS12, |
| 5235 | ChannelID: channelIDKey, |
| 5236 | Bugs: ProtocolBugs{ |
| 5237 | InvalidChannelIDSignature: true, |
| 5238 | }, |
| 5239 | }, |
| 5240 | flags: []string{"-enable-channel-id"}, |
| 5241 | shouldFail: true, |
| 5242 | expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:", |
| 5243 | expectedLocalError: "remote error: error decrypting message", |
| 5244 | }) |
David Benjamin | daa8850 | 2016-10-04 16:32:16 -0400 | [diff] [blame] | 5245 | |
| 5246 | // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is |
| 5247 | // tolerated. |
| 5248 | testCases = append(testCases, testCase{ |
| 5249 | name: "SendOCSPResponseOnResume-TLS12", |
| 5250 | config: Config{ |
| 5251 | MaxVersion: VersionTLS12, |
| 5252 | Bugs: ProtocolBugs{ |
| 5253 | SendOCSPResponseOnResume: []byte("bogus"), |
| 5254 | }, |
| 5255 | }, |
| 5256 | flags: []string{ |
| 5257 | "-enable-ocsp-stapling", |
| 5258 | "-expect-ocsp-response", |
| 5259 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 5260 | }, |
| 5261 | resumeSession: true, |
| 5262 | }) |
| 5263 | |
| 5264 | // Beginning TLS 1.3, enforce this does not happen. |
| 5265 | testCases = append(testCases, testCase{ |
| 5266 | name: "SendOCSPResponseOnResume-TLS13", |
| 5267 | config: Config{ |
| 5268 | MaxVersion: VersionTLS13, |
| 5269 | Bugs: ProtocolBugs{ |
| 5270 | SendOCSPResponseOnResume: []byte("bogus"), |
| 5271 | }, |
| 5272 | }, |
| 5273 | flags: []string{ |
| 5274 | "-enable-ocsp-stapling", |
| 5275 | "-expect-ocsp-response", |
| 5276 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 5277 | }, |
| 5278 | resumeSession: true, |
| 5279 | shouldFail: true, |
| 5280 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 5281 | }) |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 5282 | } |
| 5283 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5284 | func addResumptionVersionTests() { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5285 | for _, sessionVers := range tlsVersions { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5286 | for _, resumeVers := range tlsVersions { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5287 | cipher := TLS_RSA_WITH_AES_128_CBC_SHA |
| 5288 | if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 { |
| 5289 | // TLS 1.3 only shares ciphers with TLS 1.2, so |
| 5290 | // we skip certain combinations and use a |
| 5291 | // different cipher to test with. |
| 5292 | cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
| 5293 | if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 { |
| 5294 | continue |
| 5295 | } |
| 5296 | } |
| 5297 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5298 | protocols := []protocol{tls} |
| 5299 | if sessionVers.hasDTLS && resumeVers.hasDTLS { |
| 5300 | protocols = append(protocols, dtls) |
David Benjamin | bdf5e72 | 2014-11-11 00:52:15 -0500 | [diff] [blame] | 5301 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5302 | for _, protocol := range protocols { |
| 5303 | suffix := "-" + sessionVers.name + "-" + resumeVers.name |
| 5304 | if protocol == dtls { |
| 5305 | suffix += "-DTLS" |
| 5306 | } |
| 5307 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5308 | if sessionVers.version == resumeVers.version { |
| 5309 | testCases = append(testCases, testCase{ |
| 5310 | protocol: protocol, |
| 5311 | name: "Resume-Client" + suffix, |
| 5312 | resumeSession: true, |
| 5313 | config: Config{ |
| 5314 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5315 | CipherSuites: []uint16{cipher}, |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 5316 | Bugs: ProtocolBugs{ |
| 5317 | ExpectNoTLS12Session: sessionVers.version >= VersionTLS13, |
| 5318 | ExpectNoTLS13PSK: sessionVers.version < VersionTLS13, |
| 5319 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5320 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5321 | expectedVersion: sessionVers.version, |
| 5322 | expectedResumeVersion: resumeVers.version, |
| 5323 | }) |
| 5324 | } else { |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 5325 | error := ":OLD_SESSION_VERSION_NOT_RETURNED:" |
| 5326 | |
| 5327 | // Offering a TLS 1.3 session sends an empty session ID, so |
| 5328 | // there is no way to convince a non-lookahead client the |
| 5329 | // session was resumed. It will appear to the client that a |
| 5330 | // stray ChangeCipherSpec was sent. |
| 5331 | if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 { |
| 5332 | error = ":UNEXPECTED_RECORD:" |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5333 | } |
| 5334 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5335 | testCases = append(testCases, testCase{ |
| 5336 | protocol: protocol, |
| 5337 | name: "Resume-Client-Mismatch" + suffix, |
| 5338 | resumeSession: true, |
| 5339 | config: Config{ |
| 5340 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5341 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5342 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5343 | expectedVersion: sessionVers.version, |
| 5344 | resumeConfig: &Config{ |
| 5345 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5346 | CipherSuites: []uint16{cipher}, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5347 | Bugs: ProtocolBugs{ |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 5348 | AcceptAnySession: true, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5349 | }, |
| 5350 | }, |
| 5351 | expectedResumeVersion: resumeVers.version, |
| 5352 | shouldFail: true, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5353 | expectedError: error, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5354 | }) |
| 5355 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5356 | |
| 5357 | testCases = append(testCases, testCase{ |
| 5358 | protocol: protocol, |
| 5359 | name: "Resume-Client-NoResume" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5360 | resumeSession: true, |
| 5361 | config: Config{ |
| 5362 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5363 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5364 | }, |
| 5365 | expectedVersion: sessionVers.version, |
| 5366 | resumeConfig: &Config{ |
| 5367 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5368 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5369 | }, |
| 5370 | newSessionsOnResume: true, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 5371 | expectResumeRejected: true, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5372 | expectedResumeVersion: resumeVers.version, |
| 5373 | }) |
| 5374 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5375 | testCases = append(testCases, testCase{ |
| 5376 | protocol: protocol, |
| 5377 | testType: serverTest, |
| 5378 | name: "Resume-Server" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5379 | resumeSession: true, |
| 5380 | config: Config{ |
| 5381 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5382 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5383 | }, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 5384 | expectedVersion: sessionVers.version, |
| 5385 | expectResumeRejected: sessionVers.version != resumeVers.version, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5386 | resumeConfig: &Config{ |
| 5387 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5388 | CipherSuites: []uint16{cipher}, |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 5389 | Bugs: ProtocolBugs{ |
| 5390 | SendBothTickets: true, |
| 5391 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5392 | }, |
| 5393 | expectedResumeVersion: resumeVers.version, |
| 5394 | }) |
| 5395 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5396 | } |
| 5397 | } |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5398 | |
| 5399 | testCases = append(testCases, testCase{ |
| 5400 | name: "Resume-Client-CipherMismatch", |
| 5401 | resumeSession: true, |
| 5402 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5403 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5404 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 5405 | }, |
| 5406 | resumeConfig: &Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5407 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5408 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 5409 | Bugs: ProtocolBugs{ |
| 5410 | SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 5411 | }, |
| 5412 | }, |
| 5413 | shouldFail: true, |
| 5414 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 5415 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5416 | |
| 5417 | testCases = append(testCases, testCase{ |
| 5418 | name: "Resume-Client-CipherMismatch-TLS13", |
| 5419 | resumeSession: true, |
| 5420 | config: Config{ |
| 5421 | MaxVersion: VersionTLS13, |
| 5422 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5423 | }, |
| 5424 | resumeConfig: &Config{ |
| 5425 | MaxVersion: VersionTLS13, |
| 5426 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5427 | Bugs: ProtocolBugs{ |
| 5428 | SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, |
| 5429 | }, |
| 5430 | }, |
| 5431 | shouldFail: true, |
| 5432 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 5433 | }) |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5434 | } |
| 5435 | |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 5436 | func addRenegotiationTests() { |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 5437 | // Servers cannot renegotiate. |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5438 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5439 | testType: serverTest, |
| 5440 | name: "Renegotiate-Server-Forbidden", |
| 5441 | config: Config{ |
| 5442 | MaxVersion: VersionTLS12, |
| 5443 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5444 | renegotiate: 1, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5445 | shouldFail: true, |
| 5446 | expectedError: ":NO_RENEGOTIATION:", |
| 5447 | expectedLocalError: "remote error: no renegotiation", |
| 5448 | }) |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5449 | // The server shouldn't echo the renegotiation extension unless |
| 5450 | // requested by the client. |
| 5451 | testCases = append(testCases, testCase{ |
| 5452 | testType: serverTest, |
| 5453 | name: "Renegotiate-Server-NoExt", |
| 5454 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5455 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5456 | Bugs: ProtocolBugs{ |
| 5457 | NoRenegotiationInfo: true, |
| 5458 | RequireRenegotiationInfo: true, |
| 5459 | }, |
| 5460 | }, |
| 5461 | shouldFail: true, |
| 5462 | expectedLocalError: "renegotiation extension missing", |
| 5463 | }) |
| 5464 | // The renegotiation SCSV should be sufficient for the server to echo |
| 5465 | // the extension. |
| 5466 | testCases = append(testCases, testCase{ |
| 5467 | testType: serverTest, |
| 5468 | name: "Renegotiate-Server-NoExt-SCSV", |
| 5469 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5470 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5471 | Bugs: ProtocolBugs{ |
| 5472 | NoRenegotiationInfo: true, |
| 5473 | SendRenegotiationSCSV: true, |
| 5474 | RequireRenegotiationInfo: true, |
| 5475 | }, |
| 5476 | }, |
| 5477 | }) |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5478 | testCases = append(testCases, testCase{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 5479 | name: "Renegotiate-Client", |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5480 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5481 | MaxVersion: VersionTLS12, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5482 | Bugs: ProtocolBugs{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 5483 | FailIfResumeOnRenego: true, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5484 | }, |
| 5485 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5486 | renegotiate: 1, |
| 5487 | flags: []string{ |
| 5488 | "-renegotiate-freely", |
| 5489 | "-expect-total-renegotiations", "1", |
| 5490 | }, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5491 | }) |
| 5492 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5493 | name: "Renegotiate-Client-EmptyExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5494 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5495 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5496 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5497 | Bugs: ProtocolBugs{ |
| 5498 | EmptyRenegotiationInfo: true, |
| 5499 | }, |
| 5500 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5501 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5502 | shouldFail: true, |
| 5503 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5504 | }) |
| 5505 | testCases = append(testCases, testCase{ |
| 5506 | name: "Renegotiate-Client-BadExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5507 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5508 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5509 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5510 | Bugs: ProtocolBugs{ |
| 5511 | BadRenegotiationInfo: true, |
| 5512 | }, |
| 5513 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5514 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5515 | shouldFail: true, |
| 5516 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5517 | }) |
| 5518 | testCases = append(testCases, testCase{ |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5519 | name: "Renegotiate-Client-Downgrade", |
| 5520 | renegotiate: 1, |
| 5521 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5522 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5523 | Bugs: ProtocolBugs{ |
| 5524 | NoRenegotiationInfoAfterInitial: true, |
| 5525 | }, |
| 5526 | }, |
| 5527 | flags: []string{"-renegotiate-freely"}, |
| 5528 | shouldFail: true, |
| 5529 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5530 | }) |
| 5531 | testCases = append(testCases, testCase{ |
| 5532 | name: "Renegotiate-Client-Upgrade", |
| 5533 | renegotiate: 1, |
| 5534 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5535 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5536 | Bugs: ProtocolBugs{ |
| 5537 | NoRenegotiationInfoInInitial: true, |
| 5538 | }, |
| 5539 | }, |
| 5540 | flags: []string{"-renegotiate-freely"}, |
| 5541 | shouldFail: true, |
| 5542 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5543 | }) |
| 5544 | testCases = append(testCases, testCase{ |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5545 | name: "Renegotiate-Client-NoExt-Allowed", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5546 | renegotiate: 1, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5547 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5548 | MaxVersion: VersionTLS12, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5549 | Bugs: ProtocolBugs{ |
| 5550 | NoRenegotiationInfo: true, |
| 5551 | }, |
| 5552 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5553 | flags: []string{ |
| 5554 | "-renegotiate-freely", |
| 5555 | "-expect-total-renegotiations", "1", |
| 5556 | }, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5557 | }) |
David Benjamin | e7e36aa | 2016-08-08 12:39:41 -0400 | [diff] [blame] | 5558 | |
| 5559 | // Test that the server may switch ciphers on renegotiation without |
| 5560 | // problems. |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5561 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5562 | name: "Renegotiate-Client-SwitchCiphers", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5563 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5564 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5565 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 5566 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5567 | }, |
| 5568 | renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5569 | flags: []string{ |
| 5570 | "-renegotiate-freely", |
| 5571 | "-expect-total-renegotiations", "1", |
| 5572 | }, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5573 | }) |
| 5574 | testCases = append(testCases, testCase{ |
| 5575 | name: "Renegotiate-Client-SwitchCiphers2", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5576 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5577 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5578 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5579 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5580 | }, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 5581 | renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5582 | flags: []string{ |
| 5583 | "-renegotiate-freely", |
| 5584 | "-expect-total-renegotiations", "1", |
| 5585 | }, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5586 | }) |
David Benjamin | e7e36aa | 2016-08-08 12:39:41 -0400 | [diff] [blame] | 5587 | |
| 5588 | // Test that the server may not switch versions on renegotiation. |
| 5589 | testCases = append(testCases, testCase{ |
| 5590 | name: "Renegotiate-Client-SwitchVersion", |
| 5591 | config: Config{ |
| 5592 | MaxVersion: VersionTLS12, |
| 5593 | // Pick a cipher which exists at both versions. |
| 5594 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 5595 | Bugs: ProtocolBugs{ |
| 5596 | NegotiateVersionOnRenego: VersionTLS11, |
| 5597 | }, |
| 5598 | }, |
| 5599 | renegotiate: 1, |
| 5600 | flags: []string{ |
| 5601 | "-renegotiate-freely", |
| 5602 | "-expect-total-renegotiations", "1", |
| 5603 | }, |
| 5604 | shouldFail: true, |
| 5605 | expectedError: ":WRONG_SSL_VERSION:", |
| 5606 | }) |
| 5607 | |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5608 | testCases = append(testCases, testCase{ |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5609 | name: "Renegotiate-SameClientVersion", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5610 | renegotiate: 1, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5611 | config: Config{ |
| 5612 | MaxVersion: VersionTLS10, |
| 5613 | Bugs: ProtocolBugs{ |
| 5614 | RequireSameRenegoClientVersion: true, |
| 5615 | }, |
| 5616 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5617 | flags: []string{ |
| 5618 | "-renegotiate-freely", |
| 5619 | "-expect-total-renegotiations", "1", |
| 5620 | }, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5621 | }) |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5622 | testCases = append(testCases, testCase{ |
| 5623 | name: "Renegotiate-FalseStart", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5624 | renegotiate: 1, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5625 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5626 | MaxVersion: VersionTLS12, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5627 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5628 | NextProtos: []string{"foo"}, |
| 5629 | }, |
| 5630 | flags: []string{ |
| 5631 | "-false-start", |
| 5632 | "-select-next-proto", "foo", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5633 | "-renegotiate-freely", |
David Benjamin | 324dce4 | 2015-10-12 19:49:00 -0400 | [diff] [blame] | 5634 | "-expect-total-renegotiations", "1", |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5635 | }, |
| 5636 | shimWritesFirst: true, |
| 5637 | }) |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5638 | |
| 5639 | // Client-side renegotiation controls. |
| 5640 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5641 | name: "Renegotiate-Client-Forbidden-1", |
| 5642 | config: Config{ |
| 5643 | MaxVersion: VersionTLS12, |
| 5644 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5645 | renegotiate: 1, |
| 5646 | shouldFail: true, |
| 5647 | expectedError: ":NO_RENEGOTIATION:", |
| 5648 | expectedLocalError: "remote error: no renegotiation", |
| 5649 | }) |
| 5650 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5651 | name: "Renegotiate-Client-Once-1", |
| 5652 | config: Config{ |
| 5653 | MaxVersion: VersionTLS12, |
| 5654 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5655 | renegotiate: 1, |
| 5656 | flags: []string{ |
| 5657 | "-renegotiate-once", |
| 5658 | "-expect-total-renegotiations", "1", |
| 5659 | }, |
| 5660 | }) |
| 5661 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5662 | name: "Renegotiate-Client-Freely-1", |
| 5663 | config: Config{ |
| 5664 | MaxVersion: VersionTLS12, |
| 5665 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5666 | renegotiate: 1, |
| 5667 | flags: []string{ |
| 5668 | "-renegotiate-freely", |
| 5669 | "-expect-total-renegotiations", "1", |
| 5670 | }, |
| 5671 | }) |
| 5672 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5673 | name: "Renegotiate-Client-Once-2", |
| 5674 | config: Config{ |
| 5675 | MaxVersion: VersionTLS12, |
| 5676 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5677 | renegotiate: 2, |
| 5678 | flags: []string{"-renegotiate-once"}, |
| 5679 | shouldFail: true, |
| 5680 | expectedError: ":NO_RENEGOTIATION:", |
| 5681 | expectedLocalError: "remote error: no renegotiation", |
| 5682 | }) |
| 5683 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5684 | name: "Renegotiate-Client-Freely-2", |
| 5685 | config: Config{ |
| 5686 | MaxVersion: VersionTLS12, |
| 5687 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5688 | renegotiate: 2, |
| 5689 | flags: []string{ |
| 5690 | "-renegotiate-freely", |
| 5691 | "-expect-total-renegotiations", "2", |
| 5692 | }, |
| 5693 | }) |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5694 | testCases = append(testCases, testCase{ |
| 5695 | name: "Renegotiate-Client-NoIgnore", |
| 5696 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5697 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5698 | Bugs: ProtocolBugs{ |
| 5699 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5700 | }, |
| 5701 | }, |
| 5702 | shouldFail: true, |
| 5703 | expectedError: ":NO_RENEGOTIATION:", |
| 5704 | }) |
| 5705 | testCases = append(testCases, testCase{ |
| 5706 | name: "Renegotiate-Client-Ignore", |
| 5707 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5708 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5709 | Bugs: ProtocolBugs{ |
| 5710 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5711 | }, |
| 5712 | }, |
| 5713 | flags: []string{ |
| 5714 | "-renegotiate-ignore", |
| 5715 | "-expect-total-renegotiations", "0", |
| 5716 | }, |
| 5717 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5718 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5719 | // Stray HelloRequests during the handshake are ignored in TLS 1.2. |
David Benjamin | 71dd666 | 2016-07-08 14:10:48 -0700 | [diff] [blame] | 5720 | testCases = append(testCases, testCase{ |
| 5721 | name: "StrayHelloRequest", |
| 5722 | config: Config{ |
| 5723 | MaxVersion: VersionTLS12, |
| 5724 | Bugs: ProtocolBugs{ |
| 5725 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5726 | }, |
| 5727 | }, |
| 5728 | }) |
| 5729 | testCases = append(testCases, testCase{ |
| 5730 | name: "StrayHelloRequest-Packed", |
| 5731 | config: Config{ |
| 5732 | MaxVersion: VersionTLS12, |
| 5733 | Bugs: ProtocolBugs{ |
| 5734 | PackHandshakeFlight: true, |
| 5735 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5736 | }, |
| 5737 | }, |
| 5738 | }) |
| 5739 | |
David Benjamin | 12d2c48 | 2016-07-24 10:56:51 -0400 | [diff] [blame] | 5740 | // Test renegotiation works if HelloRequest and server Finished come in |
| 5741 | // the same record. |
| 5742 | testCases = append(testCases, testCase{ |
| 5743 | name: "Renegotiate-Client-Packed", |
| 5744 | config: Config{ |
| 5745 | MaxVersion: VersionTLS12, |
| 5746 | Bugs: ProtocolBugs{ |
| 5747 | PackHandshakeFlight: true, |
| 5748 | PackHelloRequestWithFinished: true, |
| 5749 | }, |
| 5750 | }, |
| 5751 | renegotiate: 1, |
| 5752 | flags: []string{ |
| 5753 | "-renegotiate-freely", |
| 5754 | "-expect-total-renegotiations", "1", |
| 5755 | }, |
| 5756 | }) |
| 5757 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5758 | // Renegotiation is forbidden in TLS 1.3. |
| 5759 | testCases = append(testCases, testCase{ |
| 5760 | name: "Renegotiate-Client-TLS13", |
| 5761 | config: Config{ |
| 5762 | MaxVersion: VersionTLS13, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5763 | Bugs: ProtocolBugs{ |
| 5764 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5765 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5766 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5767 | flags: []string{ |
| 5768 | "-renegotiate-freely", |
| 5769 | }, |
Steven Valdez | 8e1c7be | 2016-07-26 12:39:22 -0400 | [diff] [blame] | 5770 | shouldFail: true, |
| 5771 | expectedError: ":UNEXPECTED_MESSAGE:", |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5772 | }) |
| 5773 | |
| 5774 | // Stray HelloRequests during the handshake are forbidden in TLS 1.3. |
| 5775 | testCases = append(testCases, testCase{ |
| 5776 | name: "StrayHelloRequest-TLS13", |
| 5777 | config: Config{ |
| 5778 | MaxVersion: VersionTLS13, |
| 5779 | Bugs: ProtocolBugs{ |
| 5780 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5781 | }, |
| 5782 | }, |
| 5783 | shouldFail: true, |
| 5784 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 5785 | }) |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 5786 | } |
| 5787 | |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5788 | func addDTLSReplayTests() { |
| 5789 | // Test that sequence number replays are detected. |
| 5790 | testCases = append(testCases, testCase{ |
| 5791 | protocol: dtls, |
| 5792 | name: "DTLS-Replay", |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5793 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5794 | replayWrites: true, |
| 5795 | }) |
| 5796 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5797 | // Test the incoming sequence number skipping by values larger |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5798 | // than the retransmit window. |
| 5799 | testCases = append(testCases, testCase{ |
| 5800 | protocol: dtls, |
| 5801 | name: "DTLS-Replay-LargeGaps", |
| 5802 | config: Config{ |
| 5803 | Bugs: ProtocolBugs{ |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5804 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5805 | return in * 127 |
| 5806 | }, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5807 | }, |
| 5808 | }, |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5809 | messageCount: 200, |
| 5810 | replayWrites: true, |
| 5811 | }) |
| 5812 | |
| 5813 | // Test the incoming sequence number changing non-monotonically. |
| 5814 | testCases = append(testCases, testCase{ |
| 5815 | protocol: dtls, |
| 5816 | name: "DTLS-Replay-NonMonotonic", |
| 5817 | config: Config{ |
| 5818 | Bugs: ProtocolBugs{ |
| 5819 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5820 | return in ^ 31 |
| 5821 | }, |
| 5822 | }, |
| 5823 | }, |
| 5824 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5825 | replayWrites: true, |
| 5826 | }) |
| 5827 | } |
| 5828 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5829 | var testSignatureAlgorithms = []struct { |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5830 | name string |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5831 | id signatureAlgorithm |
| 5832 | cert testCert |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5833 | }{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5834 | {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA}, |
| 5835 | {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA}, |
| 5836 | {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA}, |
| 5837 | {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5838 | {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5839 | {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256}, |
| 5840 | {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384}, |
| 5841 | {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521}, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5842 | {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA}, |
| 5843 | {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA}, |
| 5844 | {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5845 | // Tests for key types prior to TLS 1.2. |
| 5846 | {"RSA", 0, testCertRSA}, |
| 5847 | {"ECDSA", 0, testCertECDSAP256}, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5848 | } |
| 5849 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5850 | const fakeSigAlg1 signatureAlgorithm = 0x2a01 |
| 5851 | const fakeSigAlg2 signatureAlgorithm = 0xff01 |
| 5852 | |
| 5853 | func addSignatureAlgorithmTests() { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5854 | // Not all ciphers involve a signature. Advertise a list which gives all |
| 5855 | // versions a signing cipher. |
| 5856 | signingCiphers := []uint16{ |
| 5857 | TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 5858 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 5859 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 5860 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 5861 | TLS_DHE_RSA_WITH_AES_128_CBC_SHA, |
| 5862 | } |
| 5863 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5864 | var allAlgorithms []signatureAlgorithm |
| 5865 | for _, alg := range testSignatureAlgorithms { |
| 5866 | if alg.id != 0 { |
| 5867 | allAlgorithms = append(allAlgorithms, alg.id) |
| 5868 | } |
| 5869 | } |
| 5870 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5871 | // Make sure each signature algorithm works. Include some fake values in |
| 5872 | // the list and ensure they're ignored. |
| 5873 | for _, alg := range testSignatureAlgorithms { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5874 | for _, ver := range tlsVersions { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5875 | if (ver.version < VersionTLS12) != (alg.id == 0) { |
| 5876 | continue |
| 5877 | } |
| 5878 | |
| 5879 | // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing |
| 5880 | // or remove it in C. |
| 5881 | if ver.version == VersionSSL30 && alg.cert != testCertRSA { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5882 | continue |
| 5883 | } |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5884 | |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5885 | var shouldFail bool |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5886 | // ecdsa_sha1 does not exist in TLS 1.3. |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5887 | if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 { |
| 5888 | shouldFail = true |
| 5889 | } |
Steven Valdez | 54ed58e | 2016-08-18 14:03:49 -0400 | [diff] [blame] | 5890 | // RSA-PKCS1 does not exist in TLS 1.3. |
| 5891 | if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") { |
| 5892 | shouldFail = true |
| 5893 | } |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5894 | |
| 5895 | var signError, verifyError string |
| 5896 | if shouldFail { |
| 5897 | signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:" |
| 5898 | verifyError = ":WRONG_SIGNATURE_TYPE:" |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5899 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5900 | |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5901 | suffix := "-" + alg.name + "-" + ver.name |
David Benjamin | 6e80765 | 2015-11-02 12:02:20 -0500 | [diff] [blame] | 5902 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5903 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5904 | name: "ClientAuth-Sign" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5905 | config: Config{ |
| 5906 | MaxVersion: ver.version, |
| 5907 | ClientAuth: RequireAnyClientCert, |
| 5908 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5909 | fakeSigAlg1, |
| 5910 | alg.id, |
| 5911 | fakeSigAlg2, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5912 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5913 | }, |
| 5914 | flags: []string{ |
| 5915 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5916 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5917 | "-enable-all-curves", |
| 5918 | }, |
| 5919 | shouldFail: shouldFail, |
| 5920 | expectedError: signError, |
| 5921 | expectedPeerSignatureAlgorithm: alg.id, |
| 5922 | }) |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5923 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5924 | testCases = append(testCases, testCase{ |
| 5925 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5926 | name: "ClientAuth-Verify" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5927 | config: Config{ |
| 5928 | MaxVersion: ver.version, |
| 5929 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5930 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5931 | alg.id, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5932 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5933 | Bugs: ProtocolBugs{ |
| 5934 | SkipECDSACurveCheck: shouldFail, |
| 5935 | IgnoreSignatureVersionChecks: shouldFail, |
| 5936 | // The client won't advertise 1.3-only algorithms after |
| 5937 | // version negotiation. |
| 5938 | IgnorePeerSignatureAlgorithmPreferences: shouldFail, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5939 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5940 | }, |
| 5941 | flags: []string{ |
| 5942 | "-require-any-client-certificate", |
| 5943 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5944 | "-enable-all-curves", |
| 5945 | }, |
| 5946 | shouldFail: shouldFail, |
| 5947 | expectedError: verifyError, |
| 5948 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5949 | |
| 5950 | testCases = append(testCases, testCase{ |
| 5951 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5952 | name: "ServerAuth-Sign" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5953 | config: Config{ |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5954 | MaxVersion: ver.version, |
| 5955 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5956 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5957 | fakeSigAlg1, |
| 5958 | alg.id, |
| 5959 | fakeSigAlg2, |
| 5960 | }, |
| 5961 | }, |
| 5962 | flags: []string{ |
| 5963 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5964 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5965 | "-enable-all-curves", |
| 5966 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5967 | shouldFail: shouldFail, |
| 5968 | expectedError: signError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5969 | expectedPeerSignatureAlgorithm: alg.id, |
| 5970 | }) |
| 5971 | |
| 5972 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5973 | name: "ServerAuth-Verify" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5974 | config: Config{ |
| 5975 | MaxVersion: ver.version, |
| 5976 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5977 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5978 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5979 | alg.id, |
| 5980 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5981 | Bugs: ProtocolBugs{ |
| 5982 | SkipECDSACurveCheck: shouldFail, |
| 5983 | IgnoreSignatureVersionChecks: shouldFail, |
| 5984 | }, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5985 | }, |
| 5986 | flags: []string{ |
| 5987 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5988 | "-enable-all-curves", |
| 5989 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5990 | shouldFail: shouldFail, |
| 5991 | expectedError: verifyError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5992 | }) |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5993 | |
| 5994 | if !shouldFail { |
| 5995 | testCases = append(testCases, testCase{ |
| 5996 | testType: serverTest, |
| 5997 | name: "ClientAuth-InvalidSignature" + suffix, |
| 5998 | config: Config{ |
| 5999 | MaxVersion: ver.version, |
| 6000 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 6001 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6002 | alg.id, |
| 6003 | }, |
| 6004 | Bugs: ProtocolBugs{ |
| 6005 | InvalidSignature: true, |
| 6006 | }, |
| 6007 | }, |
| 6008 | flags: []string{ |
| 6009 | "-require-any-client-certificate", |
| 6010 | "-enable-all-curves", |
| 6011 | }, |
| 6012 | shouldFail: true, |
| 6013 | expectedError: ":BAD_SIGNATURE:", |
| 6014 | }) |
| 6015 | |
| 6016 | testCases = append(testCases, testCase{ |
| 6017 | name: "ServerAuth-InvalidSignature" + suffix, |
| 6018 | config: Config{ |
| 6019 | MaxVersion: ver.version, |
| 6020 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 6021 | CipherSuites: signingCiphers, |
| 6022 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6023 | alg.id, |
| 6024 | }, |
| 6025 | Bugs: ProtocolBugs{ |
| 6026 | InvalidSignature: true, |
| 6027 | }, |
| 6028 | }, |
| 6029 | flags: []string{"-enable-all-curves"}, |
| 6030 | shouldFail: true, |
| 6031 | expectedError: ":BAD_SIGNATURE:", |
| 6032 | }) |
| 6033 | } |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6034 | |
| 6035 | if ver.version >= VersionTLS12 && !shouldFail { |
| 6036 | testCases = append(testCases, testCase{ |
| 6037 | name: "ClientAuth-Sign-Negotiate" + suffix, |
| 6038 | config: Config{ |
| 6039 | MaxVersion: ver.version, |
| 6040 | ClientAuth: RequireAnyClientCert, |
| 6041 | VerifySignatureAlgorithms: allAlgorithms, |
| 6042 | }, |
| 6043 | flags: []string{ |
| 6044 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 6045 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 6046 | "-enable-all-curves", |
| 6047 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 6048 | }, |
| 6049 | expectedPeerSignatureAlgorithm: alg.id, |
| 6050 | }) |
| 6051 | |
| 6052 | testCases = append(testCases, testCase{ |
| 6053 | testType: serverTest, |
| 6054 | name: "ServerAuth-Sign-Negotiate" + suffix, |
| 6055 | config: Config{ |
| 6056 | MaxVersion: ver.version, |
| 6057 | CipherSuites: signingCiphers, |
| 6058 | VerifySignatureAlgorithms: allAlgorithms, |
| 6059 | }, |
| 6060 | flags: []string{ |
| 6061 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 6062 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 6063 | "-enable-all-curves", |
| 6064 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 6065 | }, |
| 6066 | expectedPeerSignatureAlgorithm: alg.id, |
| 6067 | }) |
| 6068 | } |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6069 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6070 | } |
| 6071 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6072 | // Test that algorithm selection takes the key type into account. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6073 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6074 | name: "ClientAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6075 | config: Config{ |
| 6076 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6077 | MaxVersion: VersionTLS12, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6078 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6079 | signatureECDSAWithP521AndSHA512, |
| 6080 | signatureRSAPKCS1WithSHA384, |
| 6081 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6082 | }, |
| 6083 | }, |
| 6084 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6085 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6086 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6087 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6088 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6089 | }) |
| 6090 | |
| 6091 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6092 | name: "ClientAuth-SignatureType-TLS13", |
| 6093 | config: Config{ |
| 6094 | ClientAuth: RequireAnyClientCert, |
| 6095 | MaxVersion: VersionTLS13, |
| 6096 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6097 | signatureECDSAWithP521AndSHA512, |
| 6098 | signatureRSAPKCS1WithSHA384, |
| 6099 | signatureRSAPSSWithSHA384, |
| 6100 | signatureECDSAWithSHA1, |
| 6101 | }, |
| 6102 | }, |
| 6103 | flags: []string{ |
| 6104 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6105 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6106 | }, |
| 6107 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 6108 | }) |
| 6109 | |
| 6110 | testCases = append(testCases, testCase{ |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6111 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6112 | name: "ServerAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6113 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6114 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6115 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6116 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6117 | signatureECDSAWithP521AndSHA512, |
| 6118 | signatureRSAPKCS1WithSHA384, |
| 6119 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6120 | }, |
| 6121 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6122 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6123 | }) |
| 6124 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6125 | testCases = append(testCases, testCase{ |
| 6126 | testType: serverTest, |
| 6127 | name: "ServerAuth-SignatureType-TLS13", |
| 6128 | config: Config{ |
| 6129 | MaxVersion: VersionTLS13, |
| 6130 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6131 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6132 | signatureECDSAWithP521AndSHA512, |
| 6133 | signatureRSAPKCS1WithSHA384, |
| 6134 | signatureRSAPSSWithSHA384, |
| 6135 | signatureECDSAWithSHA1, |
| 6136 | }, |
| 6137 | }, |
| 6138 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 6139 | }) |
| 6140 | |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 6141 | // Test that signature verification takes the key type into account. |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 6142 | testCases = append(testCases, testCase{ |
| 6143 | testType: serverTest, |
| 6144 | name: "Verify-ClientAuth-SignatureType", |
| 6145 | config: Config{ |
| 6146 | MaxVersion: VersionTLS12, |
| 6147 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6148 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 6149 | signatureRSAPKCS1WithSHA256, |
| 6150 | }, |
| 6151 | Bugs: ProtocolBugs{ |
| 6152 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6153 | }, |
| 6154 | }, |
| 6155 | flags: []string{ |
| 6156 | "-require-any-client-certificate", |
| 6157 | }, |
| 6158 | shouldFail: true, |
| 6159 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6160 | }) |
| 6161 | |
| 6162 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6163 | testType: serverTest, |
| 6164 | name: "Verify-ClientAuth-SignatureType-TLS13", |
| 6165 | config: Config{ |
| 6166 | MaxVersion: VersionTLS13, |
| 6167 | Certificates: []Certificate{rsaCertificate}, |
| 6168 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6169 | signatureRSAPSSWithSHA256, |
| 6170 | }, |
| 6171 | Bugs: ProtocolBugs{ |
| 6172 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6173 | }, |
| 6174 | }, |
| 6175 | flags: []string{ |
| 6176 | "-require-any-client-certificate", |
| 6177 | }, |
| 6178 | shouldFail: true, |
| 6179 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6180 | }) |
| 6181 | |
| 6182 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6183 | name: "Verify-ServerAuth-SignatureType", |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 6184 | config: Config{ |
| 6185 | MaxVersion: VersionTLS12, |
| 6186 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6187 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 6188 | signatureRSAPKCS1WithSHA256, |
| 6189 | }, |
| 6190 | Bugs: ProtocolBugs{ |
| 6191 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6192 | }, |
| 6193 | }, |
| 6194 | shouldFail: true, |
| 6195 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6196 | }) |
| 6197 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6198 | testCases = append(testCases, testCase{ |
| 6199 | name: "Verify-ServerAuth-SignatureType-TLS13", |
| 6200 | config: Config{ |
| 6201 | MaxVersion: VersionTLS13, |
| 6202 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6203 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6204 | signatureRSAPSSWithSHA256, |
| 6205 | }, |
| 6206 | Bugs: ProtocolBugs{ |
| 6207 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6208 | }, |
| 6209 | }, |
| 6210 | shouldFail: true, |
| 6211 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6212 | }) |
| 6213 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6214 | // Test that, if the list is missing, the peer falls back to SHA-1 in |
| 6215 | // TLS 1.2, but not TLS 1.3. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6216 | testCases = append(testCases, testCase{ |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 6217 | name: "ClientAuth-SHA1-Fallback-RSA", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6218 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6219 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6220 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6221 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6222 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6223 | }, |
| 6224 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6225 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6226 | }, |
| 6227 | }, |
| 6228 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6229 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6230 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6231 | }, |
| 6232 | }) |
| 6233 | |
| 6234 | testCases = append(testCases, testCase{ |
| 6235 | testType: serverTest, |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 6236 | name: "ServerAuth-SHA1-Fallback-RSA", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6237 | config: Config{ |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 6238 | MaxVersion: VersionTLS12, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6239 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6240 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6241 | }, |
| 6242 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6243 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6244 | }, |
| 6245 | }, |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 6246 | flags: []string{ |
| 6247 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6248 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6249 | }, |
| 6250 | }) |
| 6251 | |
| 6252 | testCases = append(testCases, testCase{ |
| 6253 | name: "ClientAuth-SHA1-Fallback-ECDSA", |
| 6254 | config: Config{ |
| 6255 | MaxVersion: VersionTLS12, |
| 6256 | ClientAuth: RequireAnyClientCert, |
| 6257 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6258 | signatureECDSAWithSHA1, |
| 6259 | }, |
| 6260 | Bugs: ProtocolBugs{ |
| 6261 | NoSignatureAlgorithms: true, |
| 6262 | }, |
| 6263 | }, |
| 6264 | flags: []string{ |
| 6265 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 6266 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 6267 | }, |
| 6268 | }) |
| 6269 | |
| 6270 | testCases = append(testCases, testCase{ |
| 6271 | testType: serverTest, |
| 6272 | name: "ServerAuth-SHA1-Fallback-ECDSA", |
| 6273 | config: Config{ |
| 6274 | MaxVersion: VersionTLS12, |
| 6275 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6276 | signatureECDSAWithSHA1, |
| 6277 | }, |
| 6278 | Bugs: ProtocolBugs{ |
| 6279 | NoSignatureAlgorithms: true, |
| 6280 | }, |
| 6281 | }, |
| 6282 | flags: []string{ |
| 6283 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 6284 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 6285 | }, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6286 | }) |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6287 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6288 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6289 | name: "ClientAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6290 | config: Config{ |
| 6291 | MaxVersion: VersionTLS13, |
| 6292 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6293 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6294 | signatureRSAPKCS1WithSHA1, |
| 6295 | }, |
| 6296 | Bugs: ProtocolBugs{ |
| 6297 | NoSignatureAlgorithms: true, |
| 6298 | }, |
| 6299 | }, |
| 6300 | flags: []string{ |
| 6301 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6302 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6303 | }, |
David Benjamin | 4890165 | 2016-08-01 12:12:47 -0400 | [diff] [blame] | 6304 | shouldFail: true, |
| 6305 | // An empty CertificateRequest signature algorithm list is a |
| 6306 | // syntax error in TLS 1.3. |
| 6307 | expectedError: ":DECODE_ERROR:", |
| 6308 | expectedLocalError: "remote error: error decoding message", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6309 | }) |
| 6310 | |
| 6311 | testCases = append(testCases, testCase{ |
| 6312 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6313 | name: "ServerAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6314 | config: Config{ |
| 6315 | MaxVersion: VersionTLS13, |
| 6316 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6317 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6318 | signatureRSAPKCS1WithSHA1, |
| 6319 | }, |
| 6320 | Bugs: ProtocolBugs{ |
| 6321 | NoSignatureAlgorithms: true, |
| 6322 | }, |
| 6323 | }, |
| 6324 | shouldFail: true, |
| 6325 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6326 | }) |
| 6327 | |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 6328 | // Test that hash preferences are enforced. BoringSSL does not implement |
| 6329 | // MD5 signatures. |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6330 | testCases = append(testCases, testCase{ |
| 6331 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6332 | name: "ClientAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6333 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6334 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6335 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6336 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6337 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6338 | }, |
| 6339 | Bugs: ProtocolBugs{ |
| 6340 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 6341 | }, |
| 6342 | }, |
| 6343 | flags: []string{"-require-any-client-certificate"}, |
| 6344 | shouldFail: true, |
| 6345 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6346 | }) |
| 6347 | |
| 6348 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6349 | name: "ServerAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6350 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6351 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6352 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6353 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6354 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6355 | }, |
| 6356 | Bugs: ProtocolBugs{ |
| 6357 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 6358 | }, |
| 6359 | }, |
| 6360 | shouldFail: true, |
| 6361 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6362 | }) |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 6363 | testCases = append(testCases, testCase{ |
| 6364 | testType: serverTest, |
| 6365 | name: "ClientAuth-Enforced-TLS13", |
| 6366 | config: Config{ |
| 6367 | MaxVersion: VersionTLS13, |
| 6368 | Certificates: []Certificate{rsaCertificate}, |
| 6369 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6370 | signatureRSAPKCS1WithMD5, |
| 6371 | }, |
| 6372 | Bugs: ProtocolBugs{ |
| 6373 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 6374 | IgnoreSignatureVersionChecks: true, |
| 6375 | }, |
| 6376 | }, |
| 6377 | flags: []string{"-require-any-client-certificate"}, |
| 6378 | shouldFail: true, |
| 6379 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6380 | }) |
| 6381 | |
| 6382 | testCases = append(testCases, testCase{ |
| 6383 | name: "ServerAuth-Enforced-TLS13", |
| 6384 | config: Config{ |
| 6385 | MaxVersion: VersionTLS13, |
| 6386 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6387 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6388 | signatureRSAPKCS1WithMD5, |
| 6389 | }, |
| 6390 | Bugs: ProtocolBugs{ |
| 6391 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 6392 | IgnoreSignatureVersionChecks: true, |
| 6393 | }, |
| 6394 | }, |
| 6395 | shouldFail: true, |
| 6396 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6397 | }) |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6398 | |
| 6399 | // Test that the agreed upon digest respects the client preferences and |
| 6400 | // the server digests. |
| 6401 | testCases = append(testCases, testCase{ |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6402 | name: "NoCommonAlgorithms-Digests", |
| 6403 | config: Config{ |
| 6404 | MaxVersion: VersionTLS12, |
| 6405 | ClientAuth: RequireAnyClientCert, |
| 6406 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6407 | signatureRSAPKCS1WithSHA512, |
| 6408 | signatureRSAPKCS1WithSHA1, |
| 6409 | }, |
| 6410 | }, |
| 6411 | flags: []string{ |
| 6412 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6413 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6414 | "-digest-prefs", "SHA256", |
| 6415 | }, |
| 6416 | shouldFail: true, |
| 6417 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6418 | }) |
| 6419 | testCases = append(testCases, testCase{ |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 6420 | name: "NoCommonAlgorithms", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6421 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6422 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6423 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6424 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6425 | signatureRSAPKCS1WithSHA512, |
| 6426 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6427 | }, |
| 6428 | }, |
| 6429 | flags: []string{ |
| 6430 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6431 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6432 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6433 | }, |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6434 | shouldFail: true, |
| 6435 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6436 | }) |
| 6437 | testCases = append(testCases, testCase{ |
| 6438 | name: "NoCommonAlgorithms-TLS13", |
| 6439 | config: Config{ |
| 6440 | MaxVersion: VersionTLS13, |
| 6441 | ClientAuth: RequireAnyClientCert, |
| 6442 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6443 | signatureRSAPSSWithSHA512, |
| 6444 | signatureRSAPSSWithSHA384, |
| 6445 | }, |
| 6446 | }, |
| 6447 | flags: []string{ |
| 6448 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6449 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6450 | "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)), |
| 6451 | }, |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 6452 | shouldFail: true, |
| 6453 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6454 | }) |
| 6455 | testCases = append(testCases, testCase{ |
| 6456 | name: "Agree-Digest-SHA256", |
| 6457 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6458 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6459 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6460 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6461 | signatureRSAPKCS1WithSHA1, |
| 6462 | signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6463 | }, |
| 6464 | }, |
| 6465 | flags: []string{ |
| 6466 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6467 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6468 | "-digest-prefs", "SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6469 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6470 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6471 | }) |
| 6472 | testCases = append(testCases, testCase{ |
| 6473 | name: "Agree-Digest-SHA1", |
| 6474 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6475 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6476 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6477 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6478 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6479 | }, |
| 6480 | }, |
| 6481 | flags: []string{ |
| 6482 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6483 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6484 | "-digest-prefs", "SHA512,SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6485 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6486 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6487 | }) |
| 6488 | testCases = append(testCases, testCase{ |
| 6489 | name: "Agree-Digest-Default", |
| 6490 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6491 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6492 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6493 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6494 | signatureRSAPKCS1WithSHA256, |
| 6495 | signatureECDSAWithP256AndSHA256, |
| 6496 | signatureRSAPKCS1WithSHA1, |
| 6497 | signatureECDSAWithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6498 | }, |
| 6499 | }, |
| 6500 | flags: []string{ |
| 6501 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6502 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6503 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6504 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6505 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6506 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6507 | // Test that the signing preference list may include extra algorithms |
| 6508 | // without negotiation problems. |
| 6509 | testCases = append(testCases, testCase{ |
| 6510 | testType: serverTest, |
| 6511 | name: "FilterExtraAlgorithms", |
| 6512 | config: Config{ |
| 6513 | MaxVersion: VersionTLS12, |
| 6514 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6515 | signatureRSAPKCS1WithSHA256, |
| 6516 | }, |
| 6517 | }, |
| 6518 | flags: []string{ |
| 6519 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6520 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6521 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)), |
| 6522 | "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)), |
| 6523 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
| 6524 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)), |
| 6525 | }, |
| 6526 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
| 6527 | }) |
| 6528 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6529 | // In TLS 1.2 and below, ECDSA uses the curve list rather than the |
| 6530 | // signature algorithms. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6531 | testCases = append(testCases, testCase{ |
| 6532 | name: "CheckLeafCurve", |
| 6533 | config: Config{ |
| 6534 | MaxVersion: VersionTLS12, |
| 6535 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 6536 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6537 | }, |
| 6538 | flags: []string{"-p384-only"}, |
| 6539 | shouldFail: true, |
| 6540 | expectedError: ":BAD_ECC_CERT:", |
| 6541 | }) |
David Benjamin | 75ea5bb | 2016-07-08 17:43:29 -0700 | [diff] [blame] | 6542 | |
| 6543 | // In TLS 1.3, ECDSA does not use the ECDHE curve list. |
| 6544 | testCases = append(testCases, testCase{ |
| 6545 | name: "CheckLeafCurve-TLS13", |
| 6546 | config: Config{ |
| 6547 | MaxVersion: VersionTLS13, |
| 6548 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6549 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 6550 | }, |
| 6551 | flags: []string{"-p384-only"}, |
| 6552 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6553 | |
| 6554 | // In TLS 1.2, the ECDSA curve is not in the signature algorithm. |
| 6555 | testCases = append(testCases, testCase{ |
| 6556 | name: "ECDSACurveMismatch-Verify-TLS12", |
| 6557 | config: Config{ |
| 6558 | MaxVersion: VersionTLS12, |
| 6559 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6560 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6561 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6562 | signatureECDSAWithP384AndSHA384, |
| 6563 | }, |
| 6564 | }, |
| 6565 | }) |
| 6566 | |
| 6567 | // In TLS 1.3, the ECDSA curve comes from the signature algorithm. |
| 6568 | testCases = append(testCases, testCase{ |
| 6569 | name: "ECDSACurveMismatch-Verify-TLS13", |
| 6570 | config: Config{ |
| 6571 | MaxVersion: VersionTLS13, |
| 6572 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6573 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6574 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6575 | signatureECDSAWithP384AndSHA384, |
| 6576 | }, |
| 6577 | Bugs: ProtocolBugs{ |
| 6578 | SkipECDSACurveCheck: true, |
| 6579 | }, |
| 6580 | }, |
| 6581 | shouldFail: true, |
| 6582 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6583 | }) |
| 6584 | |
| 6585 | // Signature algorithm selection in TLS 1.3 should take the curve into |
| 6586 | // account. |
| 6587 | testCases = append(testCases, testCase{ |
| 6588 | testType: serverTest, |
| 6589 | name: "ECDSACurveMismatch-Sign-TLS13", |
| 6590 | config: Config{ |
| 6591 | MaxVersion: VersionTLS13, |
| 6592 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6593 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6594 | signatureECDSAWithP384AndSHA384, |
| 6595 | signatureECDSAWithP256AndSHA256, |
| 6596 | }, |
| 6597 | }, |
| 6598 | flags: []string{ |
| 6599 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 6600 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 6601 | }, |
| 6602 | expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6603 | }) |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 6604 | |
| 6605 | // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the |
| 6606 | // server does not attempt to sign in that case. |
| 6607 | testCases = append(testCases, testCase{ |
| 6608 | testType: serverTest, |
| 6609 | name: "RSA-PSS-Large", |
| 6610 | config: Config{ |
| 6611 | MaxVersion: VersionTLS13, |
| 6612 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6613 | signatureRSAPSSWithSHA512, |
| 6614 | }, |
| 6615 | }, |
| 6616 | flags: []string{ |
| 6617 | "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile), |
| 6618 | "-key-file", path.Join(*resourceDir, rsa1024KeyFile), |
| 6619 | }, |
| 6620 | shouldFail: true, |
| 6621 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6622 | }) |
David Benjamin | 57e929f | 2016-08-30 00:30:38 -0400 | [diff] [blame] | 6623 | |
| 6624 | // Test that RSA-PSS is enabled by default for TLS 1.2. |
| 6625 | testCases = append(testCases, testCase{ |
| 6626 | testType: clientTest, |
| 6627 | name: "RSA-PSS-Default-Verify", |
| 6628 | config: Config{ |
| 6629 | MaxVersion: VersionTLS12, |
| 6630 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6631 | signatureRSAPSSWithSHA256, |
| 6632 | }, |
| 6633 | }, |
| 6634 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 6635 | }) |
| 6636 | |
| 6637 | testCases = append(testCases, testCase{ |
| 6638 | testType: serverTest, |
| 6639 | name: "RSA-PSS-Default-Sign", |
| 6640 | config: Config{ |
| 6641 | MaxVersion: VersionTLS12, |
| 6642 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6643 | signatureRSAPSSWithSHA256, |
| 6644 | }, |
| 6645 | }, |
| 6646 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 6647 | }) |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6648 | } |
| 6649 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6650 | // timeouts is the retransmit schedule for BoringSSL. It doubles and |
| 6651 | // caps at 60 seconds. On the 13th timeout, it gives up. |
| 6652 | var timeouts = []time.Duration{ |
| 6653 | 1 * time.Second, |
| 6654 | 2 * time.Second, |
| 6655 | 4 * time.Second, |
| 6656 | 8 * time.Second, |
| 6657 | 16 * time.Second, |
| 6658 | 32 * time.Second, |
| 6659 | 60 * time.Second, |
| 6660 | 60 * time.Second, |
| 6661 | 60 * time.Second, |
| 6662 | 60 * time.Second, |
| 6663 | 60 * time.Second, |
| 6664 | 60 * time.Second, |
| 6665 | 60 * time.Second, |
| 6666 | } |
| 6667 | |
Taylor Brandstetter | 376a0fe | 2016-05-10 19:30:28 -0700 | [diff] [blame] | 6668 | // shortTimeouts is an alternate set of timeouts which would occur if the |
| 6669 | // initial timeout duration was set to 250ms. |
| 6670 | var shortTimeouts = []time.Duration{ |
| 6671 | 250 * time.Millisecond, |
| 6672 | 500 * time.Millisecond, |
| 6673 | 1 * time.Second, |
| 6674 | 2 * time.Second, |
| 6675 | 4 * time.Second, |
| 6676 | 8 * time.Second, |
| 6677 | 16 * time.Second, |
| 6678 | 32 * time.Second, |
| 6679 | 60 * time.Second, |
| 6680 | 60 * time.Second, |
| 6681 | 60 * time.Second, |
| 6682 | 60 * time.Second, |
| 6683 | 60 * time.Second, |
| 6684 | } |
| 6685 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6686 | func addDTLSRetransmitTests() { |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6687 | // These tests work by coordinating some behavior on both the shim and |
| 6688 | // the runner. |
| 6689 | // |
| 6690 | // TimeoutSchedule configures the runner to send a series of timeout |
| 6691 | // opcodes to the shim (see packetAdaptor) immediately before reading |
| 6692 | // each peer handshake flight N. The timeout opcode both simulates a |
| 6693 | // timeout in the shim and acts as a synchronization point to help the |
| 6694 | // runner bracket each handshake flight. |
| 6695 | // |
| 6696 | // We assume the shim does not read from the channel eagerly. It must |
| 6697 | // first wait until it has sent flight N and is ready to receive |
| 6698 | // handshake flight N+1. At this point, it will process the timeout |
| 6699 | // opcode. It must then immediately respond with a timeout ACK and act |
| 6700 | // as if the shim was idle for the specified amount of time. |
| 6701 | // |
| 6702 | // The runner then drops all packets received before the ACK and |
| 6703 | // continues waiting for flight N. This ordering results in one attempt |
| 6704 | // at sending flight N to be dropped. For the test to complete, the |
| 6705 | // shim must send flight N again, testing that the shim implements DTLS |
| 6706 | // retransmit on a timeout. |
| 6707 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6708 | // TODO(davidben): Add DTLS 1.3 versions of these tests. There will |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6709 | // likely be more epochs to cross and the final message's retransmit may |
| 6710 | // be more complex. |
| 6711 | |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6712 | for _, async := range []bool{true, false} { |
| 6713 | var tests []testCase |
| 6714 | |
| 6715 | // Test that this is indeed the timeout schedule. Stress all |
| 6716 | // four patterns of handshake. |
| 6717 | for i := 1; i < len(timeouts); i++ { |
| 6718 | number := strconv.Itoa(i) |
| 6719 | tests = append(tests, testCase{ |
| 6720 | protocol: dtls, |
| 6721 | name: "DTLS-Retransmit-Client-" + number, |
| 6722 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6723 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6724 | Bugs: ProtocolBugs{ |
| 6725 | TimeoutSchedule: timeouts[:i], |
| 6726 | }, |
| 6727 | }, |
| 6728 | resumeSession: true, |
| 6729 | }) |
| 6730 | tests = append(tests, testCase{ |
| 6731 | protocol: dtls, |
| 6732 | testType: serverTest, |
| 6733 | name: "DTLS-Retransmit-Server-" + number, |
| 6734 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6735 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6736 | Bugs: ProtocolBugs{ |
| 6737 | TimeoutSchedule: timeouts[:i], |
| 6738 | }, |
| 6739 | }, |
| 6740 | resumeSession: true, |
| 6741 | }) |
| 6742 | } |
| 6743 | |
| 6744 | // Test that exceeding the timeout schedule hits a read |
| 6745 | // timeout. |
| 6746 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6747 | protocol: dtls, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6748 | name: "DTLS-Retransmit-Timeout", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6749 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6750 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6751 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6752 | TimeoutSchedule: timeouts, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6753 | }, |
| 6754 | }, |
| 6755 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6756 | shouldFail: true, |
| 6757 | expectedError: ":READ_TIMEOUT_EXPIRED:", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6758 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6759 | |
| 6760 | if async { |
| 6761 | // Test that timeout handling has a fudge factor, due to API |
| 6762 | // problems. |
| 6763 | tests = append(tests, testCase{ |
| 6764 | protocol: dtls, |
| 6765 | name: "DTLS-Retransmit-Fudge", |
| 6766 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6767 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6768 | Bugs: ProtocolBugs{ |
| 6769 | TimeoutSchedule: []time.Duration{ |
| 6770 | timeouts[0] - 10*time.Millisecond, |
| 6771 | }, |
| 6772 | }, |
| 6773 | }, |
| 6774 | resumeSession: true, |
| 6775 | }) |
| 6776 | } |
| 6777 | |
| 6778 | // Test that the final Finished retransmitting isn't |
| 6779 | // duplicated if the peer badly fragments everything. |
| 6780 | tests = append(tests, testCase{ |
| 6781 | testType: serverTest, |
| 6782 | protocol: dtls, |
| 6783 | name: "DTLS-Retransmit-Fragmented", |
| 6784 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6785 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6786 | Bugs: ProtocolBugs{ |
| 6787 | TimeoutSchedule: []time.Duration{timeouts[0]}, |
| 6788 | MaxHandshakeRecordLength: 2, |
| 6789 | }, |
| 6790 | }, |
| 6791 | }) |
| 6792 | |
| 6793 | // Test the timeout schedule when a shorter initial timeout duration is set. |
| 6794 | tests = append(tests, testCase{ |
| 6795 | protocol: dtls, |
| 6796 | name: "DTLS-Retransmit-Short-Client", |
| 6797 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6798 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6799 | Bugs: ProtocolBugs{ |
| 6800 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
| 6801 | }, |
| 6802 | }, |
| 6803 | resumeSession: true, |
| 6804 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
| 6805 | }) |
| 6806 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6807 | protocol: dtls, |
| 6808 | testType: serverTest, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6809 | name: "DTLS-Retransmit-Short-Server", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6810 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6811 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6812 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6813 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6814 | }, |
| 6815 | }, |
| 6816 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6817 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6818 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6819 | |
| 6820 | for _, test := range tests { |
| 6821 | if async { |
| 6822 | test.name += "-Async" |
| 6823 | test.flags = append(test.flags, "-async") |
| 6824 | } |
| 6825 | |
| 6826 | testCases = append(testCases, test) |
| 6827 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6828 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6829 | } |
| 6830 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 6831 | func addExportKeyingMaterialTests() { |
| 6832 | for _, vers := range tlsVersions { |
| 6833 | if vers.version == VersionSSL30 { |
| 6834 | continue |
| 6835 | } |
| 6836 | testCases = append(testCases, testCase{ |
| 6837 | name: "ExportKeyingMaterial-" + vers.name, |
| 6838 | config: Config{ |
| 6839 | MaxVersion: vers.version, |
| 6840 | }, |
| 6841 | exportKeyingMaterial: 1024, |
| 6842 | exportLabel: "label", |
| 6843 | exportContext: "context", |
| 6844 | useExportContext: true, |
| 6845 | }) |
| 6846 | testCases = append(testCases, testCase{ |
| 6847 | name: "ExportKeyingMaterial-NoContext-" + vers.name, |
| 6848 | config: Config{ |
| 6849 | MaxVersion: vers.version, |
| 6850 | }, |
| 6851 | exportKeyingMaterial: 1024, |
| 6852 | }) |
| 6853 | testCases = append(testCases, testCase{ |
| 6854 | name: "ExportKeyingMaterial-EmptyContext-" + vers.name, |
| 6855 | config: Config{ |
| 6856 | MaxVersion: vers.version, |
| 6857 | }, |
| 6858 | exportKeyingMaterial: 1024, |
| 6859 | useExportContext: true, |
| 6860 | }) |
| 6861 | testCases = append(testCases, testCase{ |
| 6862 | name: "ExportKeyingMaterial-Small-" + vers.name, |
| 6863 | config: Config{ |
| 6864 | MaxVersion: vers.version, |
| 6865 | }, |
| 6866 | exportKeyingMaterial: 1, |
| 6867 | exportLabel: "label", |
| 6868 | exportContext: "context", |
| 6869 | useExportContext: true, |
| 6870 | }) |
| 6871 | } |
| 6872 | testCases = append(testCases, testCase{ |
| 6873 | name: "ExportKeyingMaterial-SSL3", |
| 6874 | config: Config{ |
| 6875 | MaxVersion: VersionSSL30, |
| 6876 | }, |
| 6877 | exportKeyingMaterial: 1024, |
| 6878 | exportLabel: "label", |
| 6879 | exportContext: "context", |
| 6880 | useExportContext: true, |
| 6881 | shouldFail: true, |
| 6882 | expectedError: "failed to export keying material", |
| 6883 | }) |
| 6884 | } |
| 6885 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6886 | func addTLSUniqueTests() { |
| 6887 | for _, isClient := range []bool{false, true} { |
| 6888 | for _, isResumption := range []bool{false, true} { |
| 6889 | for _, hasEMS := range []bool{false, true} { |
| 6890 | var suffix string |
| 6891 | if isResumption { |
| 6892 | suffix = "Resume-" |
| 6893 | } else { |
| 6894 | suffix = "Full-" |
| 6895 | } |
| 6896 | |
| 6897 | if hasEMS { |
| 6898 | suffix += "EMS-" |
| 6899 | } else { |
| 6900 | suffix += "NoEMS-" |
| 6901 | } |
| 6902 | |
| 6903 | if isClient { |
| 6904 | suffix += "Client" |
| 6905 | } else { |
| 6906 | suffix += "Server" |
| 6907 | } |
| 6908 | |
| 6909 | test := testCase{ |
| 6910 | name: "TLSUnique-" + suffix, |
| 6911 | testTLSUnique: true, |
| 6912 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6913 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6914 | Bugs: ProtocolBugs{ |
| 6915 | NoExtendedMasterSecret: !hasEMS, |
| 6916 | }, |
| 6917 | }, |
| 6918 | } |
| 6919 | |
| 6920 | if isResumption { |
| 6921 | test.resumeSession = true |
| 6922 | test.resumeConfig = &Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6923 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6924 | Bugs: ProtocolBugs{ |
| 6925 | NoExtendedMasterSecret: !hasEMS, |
| 6926 | }, |
| 6927 | } |
| 6928 | } |
| 6929 | |
| 6930 | if isResumption && !hasEMS { |
| 6931 | test.shouldFail = true |
| 6932 | test.expectedError = "failed to get tls-unique" |
| 6933 | } |
| 6934 | |
| 6935 | testCases = append(testCases, test) |
| 6936 | } |
| 6937 | } |
| 6938 | } |
| 6939 | } |
| 6940 | |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6941 | func addCustomExtensionTests() { |
| 6942 | expectedContents := "custom extension" |
| 6943 | emptyString := "" |
| 6944 | |
| 6945 | for _, isClient := range []bool{false, true} { |
| 6946 | suffix := "Server" |
| 6947 | flag := "-enable-server-custom-extension" |
| 6948 | testType := serverTest |
| 6949 | if isClient { |
| 6950 | suffix = "Client" |
| 6951 | flag = "-enable-client-custom-extension" |
| 6952 | testType = clientTest |
| 6953 | } |
| 6954 | |
| 6955 | testCases = append(testCases, testCase{ |
| 6956 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6957 | name: "CustomExtensions-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6958 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6959 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6960 | Bugs: ProtocolBugs{ |
| 6961 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6962 | ExpectedCustomExtension: &expectedContents, |
| 6963 | }, |
| 6964 | }, |
| 6965 | flags: []string{flag}, |
| 6966 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6967 | testCases = append(testCases, testCase{ |
| 6968 | testType: testType, |
| 6969 | name: "CustomExtensions-" + suffix + "-TLS13", |
| 6970 | config: Config{ |
| 6971 | MaxVersion: VersionTLS13, |
| 6972 | Bugs: ProtocolBugs{ |
| 6973 | CustomExtension: expectedContents, |
| 6974 | ExpectedCustomExtension: &expectedContents, |
| 6975 | }, |
| 6976 | }, |
| 6977 | flags: []string{flag}, |
| 6978 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6979 | |
| 6980 | // If the parse callback fails, the handshake should also fail. |
| 6981 | testCases = append(testCases, testCase{ |
| 6982 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6983 | name: "CustomExtensions-ParseError-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6984 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6985 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6986 | Bugs: ProtocolBugs{ |
| 6987 | CustomExtension: expectedContents + "foo", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6988 | ExpectedCustomExtension: &expectedContents, |
| 6989 | }, |
| 6990 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6991 | flags: []string{flag}, |
| 6992 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6993 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6994 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6995 | testCases = append(testCases, testCase{ |
| 6996 | testType: testType, |
| 6997 | name: "CustomExtensions-ParseError-" + suffix + "-TLS13", |
| 6998 | config: Config{ |
| 6999 | MaxVersion: VersionTLS13, |
| 7000 | Bugs: ProtocolBugs{ |
| 7001 | CustomExtension: expectedContents + "foo", |
| 7002 | ExpectedCustomExtension: &expectedContents, |
| 7003 | }, |
| 7004 | }, |
| 7005 | flags: []string{flag}, |
| 7006 | shouldFail: true, |
| 7007 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 7008 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7009 | |
| 7010 | // If the add callback fails, the handshake should also fail. |
| 7011 | testCases = append(testCases, testCase{ |
| 7012 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 7013 | name: "CustomExtensions-FailAdd-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7014 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7015 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 7016 | Bugs: ProtocolBugs{ |
| 7017 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7018 | ExpectedCustomExtension: &expectedContents, |
| 7019 | }, |
| 7020 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 7021 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 7022 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7023 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 7024 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7025 | testCases = append(testCases, testCase{ |
| 7026 | testType: testType, |
| 7027 | name: "CustomExtensions-FailAdd-" + suffix + "-TLS13", |
| 7028 | config: Config{ |
| 7029 | MaxVersion: VersionTLS13, |
| 7030 | Bugs: ProtocolBugs{ |
| 7031 | CustomExtension: expectedContents, |
| 7032 | ExpectedCustomExtension: &expectedContents, |
| 7033 | }, |
| 7034 | }, |
| 7035 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 7036 | shouldFail: true, |
| 7037 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 7038 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7039 | |
| 7040 | // If the add callback returns zero, no extension should be |
| 7041 | // added. |
| 7042 | skipCustomExtension := expectedContents |
| 7043 | if isClient { |
| 7044 | // For the case where the client skips sending the |
| 7045 | // custom extension, the server must not “echo” it. |
| 7046 | skipCustomExtension = "" |
| 7047 | } |
| 7048 | testCases = append(testCases, testCase{ |
| 7049 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 7050 | name: "CustomExtensions-Skip-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7051 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7052 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 7053 | Bugs: ProtocolBugs{ |
| 7054 | CustomExtension: skipCustomExtension, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7055 | ExpectedCustomExtension: &emptyString, |
| 7056 | }, |
| 7057 | }, |
| 7058 | flags: []string{flag, "-custom-extension-skip"}, |
| 7059 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7060 | testCases = append(testCases, testCase{ |
| 7061 | testType: testType, |
| 7062 | name: "CustomExtensions-Skip-" + suffix + "-TLS13", |
| 7063 | config: Config{ |
| 7064 | MaxVersion: VersionTLS13, |
| 7065 | Bugs: ProtocolBugs{ |
| 7066 | CustomExtension: skipCustomExtension, |
| 7067 | ExpectedCustomExtension: &emptyString, |
| 7068 | }, |
| 7069 | }, |
| 7070 | flags: []string{flag, "-custom-extension-skip"}, |
| 7071 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7072 | } |
| 7073 | |
| 7074 | // The custom extension add callback should not be called if the client |
| 7075 | // doesn't send the extension. |
| 7076 | testCases = append(testCases, testCase{ |
| 7077 | testType: serverTest, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 7078 | name: "CustomExtensions-NotCalled-Server", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7079 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7080 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 7081 | Bugs: ProtocolBugs{ |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7082 | ExpectedCustomExtension: &emptyString, |
| 7083 | }, |
| 7084 | }, |
| 7085 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 7086 | }) |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 7087 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7088 | testCases = append(testCases, testCase{ |
| 7089 | testType: serverTest, |
| 7090 | name: "CustomExtensions-NotCalled-Server-TLS13", |
| 7091 | config: Config{ |
| 7092 | MaxVersion: VersionTLS13, |
| 7093 | Bugs: ProtocolBugs{ |
| 7094 | ExpectedCustomExtension: &emptyString, |
| 7095 | }, |
| 7096 | }, |
| 7097 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 7098 | }) |
| 7099 | |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 7100 | // Test an unknown extension from the server. |
| 7101 | testCases = append(testCases, testCase{ |
| 7102 | testType: clientTest, |
| 7103 | name: "UnknownExtension-Client", |
| 7104 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7105 | MaxVersion: VersionTLS12, |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 7106 | Bugs: ProtocolBugs{ |
| 7107 | CustomExtension: expectedContents, |
| 7108 | }, |
| 7109 | }, |
David Benjamin | 0c40a96 | 2016-08-01 12:05:50 -0400 | [diff] [blame] | 7110 | shouldFail: true, |
| 7111 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7112 | expectedLocalError: "remote error: unsupported extension", |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 7113 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7114 | testCases = append(testCases, testCase{ |
| 7115 | testType: clientTest, |
| 7116 | name: "UnknownExtension-Client-TLS13", |
| 7117 | config: Config{ |
| 7118 | MaxVersion: VersionTLS13, |
| 7119 | Bugs: ProtocolBugs{ |
| 7120 | CustomExtension: expectedContents, |
| 7121 | }, |
| 7122 | }, |
David Benjamin | 0c40a96 | 2016-08-01 12:05:50 -0400 | [diff] [blame] | 7123 | shouldFail: true, |
| 7124 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7125 | expectedLocalError: "remote error: unsupported extension", |
| 7126 | }) |
| 7127 | |
| 7128 | // Test a known but unoffered extension from the server. |
| 7129 | testCases = append(testCases, testCase{ |
| 7130 | testType: clientTest, |
| 7131 | name: "UnofferedExtension-Client", |
| 7132 | config: Config{ |
| 7133 | MaxVersion: VersionTLS12, |
| 7134 | Bugs: ProtocolBugs{ |
| 7135 | SendALPN: "alpn", |
| 7136 | }, |
| 7137 | }, |
| 7138 | shouldFail: true, |
| 7139 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7140 | expectedLocalError: "remote error: unsupported extension", |
| 7141 | }) |
| 7142 | testCases = append(testCases, testCase{ |
| 7143 | testType: clientTest, |
| 7144 | name: "UnofferedExtension-Client-TLS13", |
| 7145 | config: Config{ |
| 7146 | MaxVersion: VersionTLS13, |
| 7147 | Bugs: ProtocolBugs{ |
| 7148 | SendALPN: "alpn", |
| 7149 | }, |
| 7150 | }, |
| 7151 | shouldFail: true, |
| 7152 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7153 | expectedLocalError: "remote error: unsupported extension", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7154 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7155 | } |
| 7156 | |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 7157 | func addRSAClientKeyExchangeTests() { |
| 7158 | for bad := RSABadValue(1); bad < NumRSABadValues; bad++ { |
| 7159 | testCases = append(testCases, testCase{ |
| 7160 | testType: serverTest, |
| 7161 | name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad), |
| 7162 | config: Config{ |
| 7163 | // Ensure the ClientHello version and final |
| 7164 | // version are different, to detect if the |
| 7165 | // server uses the wrong one. |
| 7166 | MaxVersion: VersionTLS11, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 7167 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 7168 | Bugs: ProtocolBugs{ |
| 7169 | BadRSAClientKeyExchange: bad, |
| 7170 | }, |
| 7171 | }, |
| 7172 | shouldFail: true, |
| 7173 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7174 | }) |
| 7175 | } |
David Benjamin | e63d9d7 | 2016-09-19 18:27:34 -0400 | [diff] [blame] | 7176 | |
| 7177 | // The server must compare whatever was in ClientHello.version for the |
| 7178 | // RSA premaster. |
| 7179 | testCases = append(testCases, testCase{ |
| 7180 | testType: serverTest, |
| 7181 | name: "SendClientVersion-RSA", |
| 7182 | config: Config{ |
| 7183 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 7184 | Bugs: ProtocolBugs{ |
| 7185 | SendClientVersion: 0x1234, |
| 7186 | }, |
| 7187 | }, |
| 7188 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 7189 | }) |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 7190 | } |
| 7191 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7192 | var testCurves = []struct { |
| 7193 | name string |
| 7194 | id CurveID |
| 7195 | }{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7196 | {"P-256", CurveP256}, |
| 7197 | {"P-384", CurveP384}, |
| 7198 | {"P-521", CurveP521}, |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 7199 | {"X25519", CurveX25519}, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7200 | } |
| 7201 | |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7202 | const bogusCurve = 0x1234 |
| 7203 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7204 | func addCurveTests() { |
| 7205 | for _, curve := range testCurves { |
| 7206 | testCases = append(testCases, testCase{ |
| 7207 | name: "CurveTest-Client-" + curve.name, |
| 7208 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7209 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7210 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7211 | CurvePreferences: []CurveID{curve.id}, |
| 7212 | }, |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7213 | flags: []string{ |
| 7214 | "-enable-all-curves", |
| 7215 | "-expect-curve-id", strconv.Itoa(int(curve.id)), |
| 7216 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7217 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7218 | }) |
| 7219 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7220 | name: "CurveTest-Client-" + curve.name + "-TLS13", |
| 7221 | config: Config{ |
| 7222 | MaxVersion: VersionTLS13, |
| 7223 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7224 | CurvePreferences: []CurveID{curve.id}, |
| 7225 | }, |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7226 | flags: []string{ |
| 7227 | "-enable-all-curves", |
| 7228 | "-expect-curve-id", strconv.Itoa(int(curve.id)), |
| 7229 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7230 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7231 | }) |
| 7232 | testCases = append(testCases, testCase{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7233 | testType: serverTest, |
| 7234 | name: "CurveTest-Server-" + curve.name, |
| 7235 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7236 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7237 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7238 | CurvePreferences: []CurveID{curve.id}, |
| 7239 | }, |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7240 | flags: []string{ |
| 7241 | "-enable-all-curves", |
| 7242 | "-expect-curve-id", strconv.Itoa(int(curve.id)), |
| 7243 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7244 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7245 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7246 | testCases = append(testCases, testCase{ |
| 7247 | testType: serverTest, |
| 7248 | name: "CurveTest-Server-" + curve.name + "-TLS13", |
| 7249 | config: Config{ |
| 7250 | MaxVersion: VersionTLS13, |
| 7251 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7252 | CurvePreferences: []CurveID{curve.id}, |
| 7253 | }, |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7254 | flags: []string{ |
| 7255 | "-enable-all-curves", |
| 7256 | "-expect-curve-id", strconv.Itoa(int(curve.id)), |
| 7257 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7258 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7259 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7260 | } |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 7261 | |
| 7262 | // The server must be tolerant to bogus curves. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 7263 | testCases = append(testCases, testCase{ |
| 7264 | testType: serverTest, |
| 7265 | name: "UnknownCurve", |
| 7266 | config: Config{ |
| 7267 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7268 | CurvePreferences: []CurveID{bogusCurve, CurveP256}, |
| 7269 | }, |
| 7270 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7271 | |
| 7272 | // The server must not consider ECDHE ciphers when there are no |
| 7273 | // supported curves. |
| 7274 | testCases = append(testCases, testCase{ |
| 7275 | testType: serverTest, |
| 7276 | name: "NoSupportedCurves", |
| 7277 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7278 | MaxVersion: VersionTLS12, |
| 7279 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7280 | Bugs: ProtocolBugs{ |
| 7281 | NoSupportedCurves: true, |
| 7282 | }, |
| 7283 | }, |
| 7284 | shouldFail: true, |
| 7285 | expectedError: ":NO_SHARED_CIPHER:", |
| 7286 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7287 | testCases = append(testCases, testCase{ |
| 7288 | testType: serverTest, |
| 7289 | name: "NoSupportedCurves-TLS13", |
| 7290 | config: Config{ |
| 7291 | MaxVersion: VersionTLS13, |
| 7292 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7293 | Bugs: ProtocolBugs{ |
| 7294 | NoSupportedCurves: true, |
| 7295 | }, |
| 7296 | }, |
| 7297 | shouldFail: true, |
| 7298 | expectedError: ":NO_SHARED_CIPHER:", |
| 7299 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7300 | |
| 7301 | // The server must fall back to another cipher when there are no |
| 7302 | // supported curves. |
| 7303 | testCases = append(testCases, testCase{ |
| 7304 | testType: serverTest, |
| 7305 | name: "NoCommonCurves", |
| 7306 | config: Config{ |
| 7307 | MaxVersion: VersionTLS12, |
| 7308 | CipherSuites: []uint16{ |
| 7309 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 7310 | TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 7311 | }, |
| 7312 | CurvePreferences: []CurveID{CurveP224}, |
| 7313 | }, |
| 7314 | expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 7315 | }) |
| 7316 | |
| 7317 | // The client must reject bogus curves and disabled curves. |
| 7318 | testCases = append(testCases, testCase{ |
| 7319 | name: "BadECDHECurve", |
| 7320 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7321 | MaxVersion: VersionTLS12, |
| 7322 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7323 | Bugs: ProtocolBugs{ |
| 7324 | SendCurve: bogusCurve, |
| 7325 | }, |
| 7326 | }, |
| 7327 | shouldFail: true, |
| 7328 | expectedError: ":WRONG_CURVE:", |
| 7329 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7330 | testCases = append(testCases, testCase{ |
| 7331 | name: "BadECDHECurve-TLS13", |
| 7332 | config: Config{ |
| 7333 | MaxVersion: VersionTLS13, |
| 7334 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7335 | Bugs: ProtocolBugs{ |
| 7336 | SendCurve: bogusCurve, |
| 7337 | }, |
| 7338 | }, |
| 7339 | shouldFail: true, |
| 7340 | expectedError: ":WRONG_CURVE:", |
| 7341 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7342 | |
| 7343 | testCases = append(testCases, testCase{ |
| 7344 | name: "UnsupportedCurve", |
| 7345 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7346 | MaxVersion: VersionTLS12, |
| 7347 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7348 | CurvePreferences: []CurveID{CurveP256}, |
| 7349 | Bugs: ProtocolBugs{ |
| 7350 | IgnorePeerCurvePreferences: true, |
| 7351 | }, |
| 7352 | }, |
| 7353 | flags: []string{"-p384-only"}, |
| 7354 | shouldFail: true, |
| 7355 | expectedError: ":WRONG_CURVE:", |
| 7356 | }) |
| 7357 | |
David Benjamin | 4f92157 | 2016-07-17 14:20:10 +0200 | [diff] [blame] | 7358 | testCases = append(testCases, testCase{ |
| 7359 | // TODO(davidben): Add a TLS 1.3 version where |
| 7360 | // HelloRetryRequest requests an unsupported curve. |
| 7361 | name: "UnsupportedCurve-ServerHello-TLS13", |
| 7362 | config: Config{ |
| 7363 | MaxVersion: VersionTLS12, |
| 7364 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7365 | CurvePreferences: []CurveID{CurveP384}, |
| 7366 | Bugs: ProtocolBugs{ |
| 7367 | SendCurve: CurveP256, |
| 7368 | }, |
| 7369 | }, |
| 7370 | flags: []string{"-p384-only"}, |
| 7371 | shouldFail: true, |
| 7372 | expectedError: ":WRONG_CURVE:", |
| 7373 | }) |
| 7374 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7375 | // Test invalid curve points. |
| 7376 | testCases = append(testCases, testCase{ |
| 7377 | name: "InvalidECDHPoint-Client", |
| 7378 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7379 | MaxVersion: VersionTLS12, |
| 7380 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7381 | CurvePreferences: []CurveID{CurveP256}, |
| 7382 | Bugs: ProtocolBugs{ |
| 7383 | InvalidECDHPoint: true, |
| 7384 | }, |
| 7385 | }, |
| 7386 | shouldFail: true, |
| 7387 | expectedError: ":INVALID_ENCODING:", |
| 7388 | }) |
| 7389 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7390 | name: "InvalidECDHPoint-Client-TLS13", |
| 7391 | config: Config{ |
| 7392 | MaxVersion: VersionTLS13, |
| 7393 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7394 | CurvePreferences: []CurveID{CurveP256}, |
| 7395 | Bugs: ProtocolBugs{ |
| 7396 | InvalidECDHPoint: true, |
| 7397 | }, |
| 7398 | }, |
| 7399 | shouldFail: true, |
| 7400 | expectedError: ":INVALID_ENCODING:", |
| 7401 | }) |
| 7402 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7403 | testType: serverTest, |
| 7404 | name: "InvalidECDHPoint-Server", |
| 7405 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7406 | MaxVersion: VersionTLS12, |
| 7407 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7408 | CurvePreferences: []CurveID{CurveP256}, |
| 7409 | Bugs: ProtocolBugs{ |
| 7410 | InvalidECDHPoint: true, |
| 7411 | }, |
| 7412 | }, |
| 7413 | shouldFail: true, |
| 7414 | expectedError: ":INVALID_ENCODING:", |
| 7415 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7416 | testCases = append(testCases, testCase{ |
| 7417 | testType: serverTest, |
| 7418 | name: "InvalidECDHPoint-Server-TLS13", |
| 7419 | config: Config{ |
| 7420 | MaxVersion: VersionTLS13, |
| 7421 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7422 | CurvePreferences: []CurveID{CurveP256}, |
| 7423 | Bugs: ProtocolBugs{ |
| 7424 | InvalidECDHPoint: true, |
| 7425 | }, |
| 7426 | }, |
| 7427 | shouldFail: true, |
| 7428 | expectedError: ":INVALID_ENCODING:", |
| 7429 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7430 | } |
| 7431 | |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7432 | func addCECPQ1Tests() { |
| 7433 | testCases = append(testCases, testCase{ |
| 7434 | testType: clientTest, |
| 7435 | name: "CECPQ1-Client-BadX25519Part", |
| 7436 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7437 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7438 | MinVersion: VersionTLS12, |
| 7439 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 7440 | Bugs: ProtocolBugs{ |
| 7441 | CECPQ1BadX25519Part: true, |
| 7442 | }, |
| 7443 | }, |
| 7444 | flags: []string{"-cipher", "kCECPQ1"}, |
| 7445 | shouldFail: true, |
| 7446 | expectedLocalError: "local error: bad record MAC", |
| 7447 | }) |
| 7448 | testCases = append(testCases, testCase{ |
| 7449 | testType: clientTest, |
| 7450 | name: "CECPQ1-Client-BadNewhopePart", |
| 7451 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7452 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7453 | MinVersion: VersionTLS12, |
| 7454 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 7455 | Bugs: ProtocolBugs{ |
| 7456 | CECPQ1BadNewhopePart: true, |
| 7457 | }, |
| 7458 | }, |
| 7459 | flags: []string{"-cipher", "kCECPQ1"}, |
| 7460 | shouldFail: true, |
| 7461 | expectedLocalError: "local error: bad record MAC", |
| 7462 | }) |
| 7463 | testCases = append(testCases, testCase{ |
| 7464 | testType: serverTest, |
| 7465 | name: "CECPQ1-Server-BadX25519Part", |
| 7466 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7467 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7468 | MinVersion: VersionTLS12, |
| 7469 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 7470 | Bugs: ProtocolBugs{ |
| 7471 | CECPQ1BadX25519Part: true, |
| 7472 | }, |
| 7473 | }, |
| 7474 | flags: []string{"-cipher", "kCECPQ1"}, |
| 7475 | shouldFail: true, |
| 7476 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7477 | }) |
| 7478 | testCases = append(testCases, testCase{ |
| 7479 | testType: serverTest, |
| 7480 | name: "CECPQ1-Server-BadNewhopePart", |
| 7481 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7482 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7483 | MinVersion: VersionTLS12, |
| 7484 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 7485 | Bugs: ProtocolBugs{ |
| 7486 | CECPQ1BadNewhopePart: true, |
| 7487 | }, |
| 7488 | }, |
| 7489 | flags: []string{"-cipher", "kCECPQ1"}, |
| 7490 | shouldFail: true, |
| 7491 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7492 | }) |
| 7493 | } |
| 7494 | |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7495 | func addDHEGroupSizeTests() { |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7496 | testCases = append(testCases, testCase{ |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7497 | name: "DHEGroupSize-Client", |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7498 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7499 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7500 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7501 | Bugs: ProtocolBugs{ |
| 7502 | // This is a 1234-bit prime number, generated |
| 7503 | // with: |
| 7504 | // openssl gendh 1234 | openssl asn1parse -i |
| 7505 | DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"), |
| 7506 | }, |
| 7507 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 7508 | flags: []string{"-expect-dhe-group-size", "1234"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7509 | }) |
| 7510 | testCases = append(testCases, testCase{ |
| 7511 | testType: serverTest, |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7512 | name: "DHEGroupSize-Server", |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7513 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7514 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7515 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7516 | }, |
| 7517 | // bssl_shim as a server configures a 2048-bit DHE group. |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 7518 | flags: []string{"-expect-dhe-group-size", "2048"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7519 | }) |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7520 | } |
| 7521 | |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 7522 | func addTLS13RecordTests() { |
| 7523 | testCases = append(testCases, testCase{ |
| 7524 | name: "TLS13-RecordPadding", |
| 7525 | config: Config{ |
| 7526 | MaxVersion: VersionTLS13, |
| 7527 | MinVersion: VersionTLS13, |
| 7528 | Bugs: ProtocolBugs{ |
| 7529 | RecordPadding: 10, |
| 7530 | }, |
| 7531 | }, |
| 7532 | }) |
| 7533 | |
| 7534 | testCases = append(testCases, testCase{ |
| 7535 | name: "TLS13-EmptyRecords", |
| 7536 | config: Config{ |
| 7537 | MaxVersion: VersionTLS13, |
| 7538 | MinVersion: VersionTLS13, |
| 7539 | Bugs: ProtocolBugs{ |
| 7540 | OmitRecordContents: true, |
| 7541 | }, |
| 7542 | }, |
| 7543 | shouldFail: true, |
| 7544 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7545 | }) |
| 7546 | |
| 7547 | testCases = append(testCases, testCase{ |
| 7548 | name: "TLS13-OnlyPadding", |
| 7549 | config: Config{ |
| 7550 | MaxVersion: VersionTLS13, |
| 7551 | MinVersion: VersionTLS13, |
| 7552 | Bugs: ProtocolBugs{ |
| 7553 | OmitRecordContents: true, |
| 7554 | RecordPadding: 10, |
| 7555 | }, |
| 7556 | }, |
| 7557 | shouldFail: true, |
| 7558 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7559 | }) |
| 7560 | |
| 7561 | testCases = append(testCases, testCase{ |
| 7562 | name: "TLS13-WrongOuterRecord", |
| 7563 | config: Config{ |
| 7564 | MaxVersion: VersionTLS13, |
| 7565 | MinVersion: VersionTLS13, |
| 7566 | Bugs: ProtocolBugs{ |
| 7567 | OuterRecordType: recordTypeHandshake, |
| 7568 | }, |
| 7569 | }, |
| 7570 | shouldFail: true, |
| 7571 | expectedError: ":INVALID_OUTER_RECORD_TYPE:", |
| 7572 | }) |
| 7573 | } |
| 7574 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7575 | func addChangeCipherSpecTests() { |
| 7576 | // Test missing ChangeCipherSpecs. |
| 7577 | testCases = append(testCases, testCase{ |
| 7578 | name: "SkipChangeCipherSpec-Client", |
| 7579 | config: Config{ |
| 7580 | MaxVersion: VersionTLS12, |
| 7581 | Bugs: ProtocolBugs{ |
| 7582 | SkipChangeCipherSpec: true, |
| 7583 | }, |
| 7584 | }, |
| 7585 | shouldFail: true, |
| 7586 | expectedError: ":UNEXPECTED_RECORD:", |
| 7587 | }) |
| 7588 | testCases = append(testCases, testCase{ |
| 7589 | testType: serverTest, |
| 7590 | name: "SkipChangeCipherSpec-Server", |
| 7591 | config: Config{ |
| 7592 | MaxVersion: VersionTLS12, |
| 7593 | Bugs: ProtocolBugs{ |
| 7594 | SkipChangeCipherSpec: true, |
| 7595 | }, |
| 7596 | }, |
| 7597 | shouldFail: true, |
| 7598 | expectedError: ":UNEXPECTED_RECORD:", |
| 7599 | }) |
| 7600 | testCases = append(testCases, testCase{ |
| 7601 | testType: serverTest, |
| 7602 | name: "SkipChangeCipherSpec-Server-NPN", |
| 7603 | config: Config{ |
| 7604 | MaxVersion: VersionTLS12, |
| 7605 | NextProtos: []string{"bar"}, |
| 7606 | Bugs: ProtocolBugs{ |
| 7607 | SkipChangeCipherSpec: true, |
| 7608 | }, |
| 7609 | }, |
| 7610 | flags: []string{ |
| 7611 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 7612 | }, |
| 7613 | shouldFail: true, |
| 7614 | expectedError: ":UNEXPECTED_RECORD:", |
| 7615 | }) |
| 7616 | |
| 7617 | // Test synchronization between the handshake and ChangeCipherSpec. |
| 7618 | // Partial post-CCS handshake messages before ChangeCipherSpec should be |
| 7619 | // rejected. Test both with and without handshake packing to handle both |
| 7620 | // when the partial post-CCS message is in its own record and when it is |
| 7621 | // attached to the pre-CCS message. |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7622 | for _, packed := range []bool{false, true} { |
| 7623 | var suffix string |
| 7624 | if packed { |
| 7625 | suffix = "-Packed" |
| 7626 | } |
| 7627 | |
| 7628 | testCases = append(testCases, testCase{ |
| 7629 | name: "FragmentAcrossChangeCipherSpec-Client" + suffix, |
| 7630 | config: Config{ |
| 7631 | MaxVersion: VersionTLS12, |
| 7632 | Bugs: ProtocolBugs{ |
| 7633 | FragmentAcrossChangeCipherSpec: true, |
| 7634 | PackHandshakeFlight: packed, |
| 7635 | }, |
| 7636 | }, |
| 7637 | shouldFail: true, |
| 7638 | expectedError: ":UNEXPECTED_RECORD:", |
| 7639 | }) |
| 7640 | testCases = append(testCases, testCase{ |
| 7641 | name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix, |
| 7642 | config: Config{ |
| 7643 | MaxVersion: VersionTLS12, |
| 7644 | }, |
| 7645 | resumeSession: true, |
| 7646 | resumeConfig: &Config{ |
| 7647 | MaxVersion: VersionTLS12, |
| 7648 | Bugs: ProtocolBugs{ |
| 7649 | FragmentAcrossChangeCipherSpec: true, |
| 7650 | PackHandshakeFlight: packed, |
| 7651 | }, |
| 7652 | }, |
| 7653 | shouldFail: true, |
| 7654 | expectedError: ":UNEXPECTED_RECORD:", |
| 7655 | }) |
| 7656 | testCases = append(testCases, testCase{ |
| 7657 | testType: serverTest, |
| 7658 | name: "FragmentAcrossChangeCipherSpec-Server" + suffix, |
| 7659 | config: Config{ |
| 7660 | MaxVersion: VersionTLS12, |
| 7661 | Bugs: ProtocolBugs{ |
| 7662 | FragmentAcrossChangeCipherSpec: true, |
| 7663 | PackHandshakeFlight: packed, |
| 7664 | }, |
| 7665 | }, |
| 7666 | shouldFail: true, |
| 7667 | expectedError: ":UNEXPECTED_RECORD:", |
| 7668 | }) |
| 7669 | testCases = append(testCases, testCase{ |
| 7670 | testType: serverTest, |
| 7671 | name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix, |
| 7672 | config: Config{ |
| 7673 | MaxVersion: VersionTLS12, |
| 7674 | }, |
| 7675 | resumeSession: true, |
| 7676 | resumeConfig: &Config{ |
| 7677 | MaxVersion: VersionTLS12, |
| 7678 | Bugs: ProtocolBugs{ |
| 7679 | FragmentAcrossChangeCipherSpec: true, |
| 7680 | PackHandshakeFlight: packed, |
| 7681 | }, |
| 7682 | }, |
| 7683 | shouldFail: true, |
| 7684 | expectedError: ":UNEXPECTED_RECORD:", |
| 7685 | }) |
| 7686 | testCases = append(testCases, testCase{ |
| 7687 | testType: serverTest, |
| 7688 | name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix, |
| 7689 | config: Config{ |
| 7690 | MaxVersion: VersionTLS12, |
| 7691 | NextProtos: []string{"bar"}, |
| 7692 | Bugs: ProtocolBugs{ |
| 7693 | FragmentAcrossChangeCipherSpec: true, |
| 7694 | PackHandshakeFlight: packed, |
| 7695 | }, |
| 7696 | }, |
| 7697 | flags: []string{ |
| 7698 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 7699 | }, |
| 7700 | shouldFail: true, |
| 7701 | expectedError: ":UNEXPECTED_RECORD:", |
| 7702 | }) |
| 7703 | } |
| 7704 | |
David Benjamin | 6167281 | 2016-07-14 23:10:43 -0400 | [diff] [blame] | 7705 | // Test that, in DTLS, ChangeCipherSpec is not allowed when there are |
| 7706 | // messages in the handshake queue. Do this by testing the server |
| 7707 | // reading the client Finished, reversing the flight so Finished comes |
| 7708 | // first. |
| 7709 | testCases = append(testCases, testCase{ |
| 7710 | protocol: dtls, |
| 7711 | testType: serverTest, |
| 7712 | name: "SendUnencryptedFinished-DTLS", |
| 7713 | config: Config{ |
| 7714 | MaxVersion: VersionTLS12, |
| 7715 | Bugs: ProtocolBugs{ |
| 7716 | SendUnencryptedFinished: true, |
| 7717 | ReverseHandshakeFragments: true, |
| 7718 | }, |
| 7719 | }, |
| 7720 | shouldFail: true, |
| 7721 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7722 | }) |
| 7723 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7724 | // Test synchronization between encryption changes and the handshake in |
| 7725 | // TLS 1.3, where ChangeCipherSpec is implicit. |
| 7726 | testCases = append(testCases, testCase{ |
| 7727 | name: "PartialEncryptedExtensionsWithServerHello", |
| 7728 | config: Config{ |
| 7729 | MaxVersion: VersionTLS13, |
| 7730 | Bugs: ProtocolBugs{ |
| 7731 | PartialEncryptedExtensionsWithServerHello: true, |
| 7732 | }, |
| 7733 | }, |
| 7734 | shouldFail: true, |
| 7735 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7736 | }) |
| 7737 | testCases = append(testCases, testCase{ |
| 7738 | testType: serverTest, |
| 7739 | name: "PartialClientFinishedWithClientHello", |
| 7740 | config: Config{ |
| 7741 | MaxVersion: VersionTLS13, |
| 7742 | Bugs: ProtocolBugs{ |
| 7743 | PartialClientFinishedWithClientHello: true, |
| 7744 | }, |
| 7745 | }, |
| 7746 | shouldFail: true, |
| 7747 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7748 | }) |
| 7749 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7750 | // Test that early ChangeCipherSpecs are handled correctly. |
| 7751 | testCases = append(testCases, testCase{ |
| 7752 | testType: serverTest, |
| 7753 | name: "EarlyChangeCipherSpec-server-1", |
| 7754 | config: Config{ |
| 7755 | MaxVersion: VersionTLS12, |
| 7756 | Bugs: ProtocolBugs{ |
| 7757 | EarlyChangeCipherSpec: 1, |
| 7758 | }, |
| 7759 | }, |
| 7760 | shouldFail: true, |
| 7761 | expectedError: ":UNEXPECTED_RECORD:", |
| 7762 | }) |
| 7763 | testCases = append(testCases, testCase{ |
| 7764 | testType: serverTest, |
| 7765 | name: "EarlyChangeCipherSpec-server-2", |
| 7766 | config: Config{ |
| 7767 | MaxVersion: VersionTLS12, |
| 7768 | Bugs: ProtocolBugs{ |
| 7769 | EarlyChangeCipherSpec: 2, |
| 7770 | }, |
| 7771 | }, |
| 7772 | shouldFail: true, |
| 7773 | expectedError: ":UNEXPECTED_RECORD:", |
| 7774 | }) |
| 7775 | testCases = append(testCases, testCase{ |
| 7776 | protocol: dtls, |
| 7777 | name: "StrayChangeCipherSpec", |
| 7778 | config: Config{ |
| 7779 | // TODO(davidben): Once DTLS 1.3 exists, test |
| 7780 | // that stray ChangeCipherSpec messages are |
| 7781 | // rejected. |
| 7782 | MaxVersion: VersionTLS12, |
| 7783 | Bugs: ProtocolBugs{ |
| 7784 | StrayChangeCipherSpec: true, |
| 7785 | }, |
| 7786 | }, |
| 7787 | }) |
| 7788 | |
| 7789 | // Test that the contents of ChangeCipherSpec are checked. |
| 7790 | testCases = append(testCases, testCase{ |
| 7791 | name: "BadChangeCipherSpec-1", |
| 7792 | config: Config{ |
| 7793 | MaxVersion: VersionTLS12, |
| 7794 | Bugs: ProtocolBugs{ |
| 7795 | BadChangeCipherSpec: []byte{2}, |
| 7796 | }, |
| 7797 | }, |
| 7798 | shouldFail: true, |
| 7799 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7800 | }) |
| 7801 | testCases = append(testCases, testCase{ |
| 7802 | name: "BadChangeCipherSpec-2", |
| 7803 | config: Config{ |
| 7804 | MaxVersion: VersionTLS12, |
| 7805 | Bugs: ProtocolBugs{ |
| 7806 | BadChangeCipherSpec: []byte{1, 1}, |
| 7807 | }, |
| 7808 | }, |
| 7809 | shouldFail: true, |
| 7810 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7811 | }) |
| 7812 | testCases = append(testCases, testCase{ |
| 7813 | protocol: dtls, |
| 7814 | name: "BadChangeCipherSpec-DTLS-1", |
| 7815 | config: Config{ |
| 7816 | MaxVersion: VersionTLS12, |
| 7817 | Bugs: ProtocolBugs{ |
| 7818 | BadChangeCipherSpec: []byte{2}, |
| 7819 | }, |
| 7820 | }, |
| 7821 | shouldFail: true, |
| 7822 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7823 | }) |
| 7824 | testCases = append(testCases, testCase{ |
| 7825 | protocol: dtls, |
| 7826 | name: "BadChangeCipherSpec-DTLS-2", |
| 7827 | config: Config{ |
| 7828 | MaxVersion: VersionTLS12, |
| 7829 | Bugs: ProtocolBugs{ |
| 7830 | BadChangeCipherSpec: []byte{1, 1}, |
| 7831 | }, |
| 7832 | }, |
| 7833 | shouldFail: true, |
| 7834 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7835 | }) |
| 7836 | } |
| 7837 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7838 | type perMessageTest struct { |
| 7839 | messageType uint8 |
| 7840 | test testCase |
| 7841 | } |
| 7842 | |
| 7843 | // makePerMessageTests returns a series of test templates which cover each |
| 7844 | // message in the TLS handshake. These may be used with bugs like |
| 7845 | // WrongMessageType to fully test a per-message bug. |
| 7846 | func makePerMessageTests() []perMessageTest { |
| 7847 | var ret []perMessageTest |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7848 | for _, protocol := range []protocol{tls, dtls} { |
| 7849 | var suffix string |
| 7850 | if protocol == dtls { |
| 7851 | suffix = "-DTLS" |
| 7852 | } |
| 7853 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7854 | ret = append(ret, perMessageTest{ |
| 7855 | messageType: typeClientHello, |
| 7856 | test: testCase{ |
| 7857 | protocol: protocol, |
| 7858 | testType: serverTest, |
| 7859 | name: "ClientHello" + suffix, |
| 7860 | config: Config{ |
| 7861 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7862 | }, |
| 7863 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7864 | }) |
| 7865 | |
| 7866 | if protocol == dtls { |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7867 | ret = append(ret, perMessageTest{ |
| 7868 | messageType: typeHelloVerifyRequest, |
| 7869 | test: testCase{ |
| 7870 | protocol: protocol, |
| 7871 | name: "HelloVerifyRequest" + suffix, |
| 7872 | config: Config{ |
| 7873 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7874 | }, |
| 7875 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7876 | }) |
| 7877 | } |
| 7878 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7879 | ret = append(ret, perMessageTest{ |
| 7880 | messageType: typeServerHello, |
| 7881 | test: testCase{ |
| 7882 | protocol: protocol, |
| 7883 | name: "ServerHello" + suffix, |
| 7884 | config: Config{ |
| 7885 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7886 | }, |
| 7887 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7888 | }) |
| 7889 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7890 | ret = append(ret, perMessageTest{ |
| 7891 | messageType: typeCertificate, |
| 7892 | test: testCase{ |
| 7893 | protocol: protocol, |
| 7894 | name: "ServerCertificate" + suffix, |
| 7895 | config: Config{ |
| 7896 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7897 | }, |
| 7898 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7899 | }) |
| 7900 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7901 | ret = append(ret, perMessageTest{ |
| 7902 | messageType: typeCertificateStatus, |
| 7903 | test: testCase{ |
| 7904 | protocol: protocol, |
| 7905 | name: "CertificateStatus" + suffix, |
| 7906 | config: Config{ |
| 7907 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7908 | }, |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7909 | flags: []string{"-enable-ocsp-stapling"}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7910 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7911 | }) |
| 7912 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7913 | ret = append(ret, perMessageTest{ |
| 7914 | messageType: typeServerKeyExchange, |
| 7915 | test: testCase{ |
| 7916 | protocol: protocol, |
| 7917 | name: "ServerKeyExchange" + suffix, |
| 7918 | config: Config{ |
| 7919 | MaxVersion: VersionTLS12, |
| 7920 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7921 | }, |
| 7922 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7923 | }) |
| 7924 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7925 | ret = append(ret, perMessageTest{ |
| 7926 | messageType: typeCertificateRequest, |
| 7927 | test: testCase{ |
| 7928 | protocol: protocol, |
| 7929 | name: "CertificateRequest" + suffix, |
| 7930 | config: Config{ |
| 7931 | MaxVersion: VersionTLS12, |
| 7932 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7933 | }, |
| 7934 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7935 | }) |
| 7936 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7937 | ret = append(ret, perMessageTest{ |
| 7938 | messageType: typeServerHelloDone, |
| 7939 | test: testCase{ |
| 7940 | protocol: protocol, |
| 7941 | name: "ServerHelloDone" + suffix, |
| 7942 | config: Config{ |
| 7943 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7944 | }, |
| 7945 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7946 | }) |
| 7947 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7948 | ret = append(ret, perMessageTest{ |
| 7949 | messageType: typeCertificate, |
| 7950 | test: testCase{ |
| 7951 | testType: serverTest, |
| 7952 | protocol: protocol, |
| 7953 | name: "ClientCertificate" + suffix, |
| 7954 | config: Config{ |
| 7955 | Certificates: []Certificate{rsaCertificate}, |
| 7956 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7957 | }, |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7958 | flags: []string{"-require-any-client-certificate"}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7959 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7960 | }) |
| 7961 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7962 | ret = append(ret, perMessageTest{ |
| 7963 | messageType: typeCertificateVerify, |
| 7964 | test: testCase{ |
| 7965 | testType: serverTest, |
| 7966 | protocol: protocol, |
| 7967 | name: "CertificateVerify" + suffix, |
| 7968 | config: Config{ |
| 7969 | Certificates: []Certificate{rsaCertificate}, |
| 7970 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7971 | }, |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7972 | flags: []string{"-require-any-client-certificate"}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7973 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7974 | }) |
| 7975 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7976 | ret = append(ret, perMessageTest{ |
| 7977 | messageType: typeClientKeyExchange, |
| 7978 | test: testCase{ |
| 7979 | testType: serverTest, |
| 7980 | protocol: protocol, |
| 7981 | name: "ClientKeyExchange" + suffix, |
| 7982 | config: Config{ |
| 7983 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7984 | }, |
| 7985 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7986 | }) |
| 7987 | |
| 7988 | if protocol != dtls { |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7989 | ret = append(ret, perMessageTest{ |
| 7990 | messageType: typeNextProtocol, |
| 7991 | test: testCase{ |
| 7992 | testType: serverTest, |
| 7993 | protocol: protocol, |
| 7994 | name: "NextProtocol" + suffix, |
| 7995 | config: Config{ |
| 7996 | MaxVersion: VersionTLS12, |
| 7997 | NextProtos: []string{"bar"}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7998 | }, |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7999 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8000 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8001 | }) |
| 8002 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8003 | ret = append(ret, perMessageTest{ |
| 8004 | messageType: typeChannelID, |
| 8005 | test: testCase{ |
| 8006 | testType: serverTest, |
| 8007 | protocol: protocol, |
| 8008 | name: "ChannelID" + suffix, |
| 8009 | config: Config{ |
| 8010 | MaxVersion: VersionTLS12, |
| 8011 | ChannelID: channelIDKey, |
| 8012 | }, |
| 8013 | flags: []string{ |
| 8014 | "-expect-channel-id", |
| 8015 | base64.StdEncoding.EncodeToString(channelIDBytes), |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8016 | }, |
| 8017 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8018 | }) |
| 8019 | } |
| 8020 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8021 | ret = append(ret, perMessageTest{ |
| 8022 | messageType: typeFinished, |
| 8023 | test: testCase{ |
| 8024 | testType: serverTest, |
| 8025 | protocol: protocol, |
| 8026 | name: "ClientFinished" + suffix, |
| 8027 | config: Config{ |
| 8028 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8029 | }, |
| 8030 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8031 | }) |
| 8032 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8033 | ret = append(ret, perMessageTest{ |
| 8034 | messageType: typeNewSessionTicket, |
| 8035 | test: testCase{ |
| 8036 | protocol: protocol, |
| 8037 | name: "NewSessionTicket" + suffix, |
| 8038 | config: Config{ |
| 8039 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8040 | }, |
| 8041 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8042 | }) |
| 8043 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8044 | ret = append(ret, perMessageTest{ |
| 8045 | messageType: typeFinished, |
| 8046 | test: testCase{ |
| 8047 | protocol: protocol, |
| 8048 | name: "ServerFinished" + suffix, |
| 8049 | config: Config{ |
| 8050 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8051 | }, |
| 8052 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8053 | }) |
| 8054 | |
| 8055 | } |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8056 | |
| 8057 | ret = append(ret, perMessageTest{ |
| 8058 | messageType: typeClientHello, |
| 8059 | test: testCase{ |
| 8060 | testType: serverTest, |
| 8061 | name: "TLS13-ClientHello", |
| 8062 | config: Config{ |
| 8063 | MaxVersion: VersionTLS13, |
| 8064 | }, |
| 8065 | }, |
| 8066 | }) |
| 8067 | |
| 8068 | ret = append(ret, perMessageTest{ |
| 8069 | messageType: typeServerHello, |
| 8070 | test: testCase{ |
| 8071 | name: "TLS13-ServerHello", |
| 8072 | config: Config{ |
| 8073 | MaxVersion: VersionTLS13, |
| 8074 | }, |
| 8075 | }, |
| 8076 | }) |
| 8077 | |
| 8078 | ret = append(ret, perMessageTest{ |
| 8079 | messageType: typeEncryptedExtensions, |
| 8080 | test: testCase{ |
| 8081 | name: "TLS13-EncryptedExtensions", |
| 8082 | config: Config{ |
| 8083 | MaxVersion: VersionTLS13, |
| 8084 | }, |
| 8085 | }, |
| 8086 | }) |
| 8087 | |
| 8088 | ret = append(ret, perMessageTest{ |
| 8089 | messageType: typeCertificateRequest, |
| 8090 | test: testCase{ |
| 8091 | name: "TLS13-CertificateRequest", |
| 8092 | config: Config{ |
| 8093 | MaxVersion: VersionTLS13, |
| 8094 | ClientAuth: RequireAnyClientCert, |
| 8095 | }, |
| 8096 | }, |
| 8097 | }) |
| 8098 | |
| 8099 | ret = append(ret, perMessageTest{ |
| 8100 | messageType: typeCertificate, |
| 8101 | test: testCase{ |
| 8102 | name: "TLS13-ServerCertificate", |
| 8103 | config: Config{ |
| 8104 | MaxVersion: VersionTLS13, |
| 8105 | }, |
| 8106 | }, |
| 8107 | }) |
| 8108 | |
| 8109 | ret = append(ret, perMessageTest{ |
| 8110 | messageType: typeCertificateVerify, |
| 8111 | test: testCase{ |
| 8112 | name: "TLS13-ServerCertificateVerify", |
| 8113 | config: Config{ |
| 8114 | MaxVersion: VersionTLS13, |
| 8115 | }, |
| 8116 | }, |
| 8117 | }) |
| 8118 | |
| 8119 | ret = append(ret, perMessageTest{ |
| 8120 | messageType: typeFinished, |
| 8121 | test: testCase{ |
| 8122 | name: "TLS13-ServerFinished", |
| 8123 | config: Config{ |
| 8124 | MaxVersion: VersionTLS13, |
| 8125 | }, |
| 8126 | }, |
| 8127 | }) |
| 8128 | |
| 8129 | ret = append(ret, perMessageTest{ |
| 8130 | messageType: typeCertificate, |
| 8131 | test: testCase{ |
| 8132 | testType: serverTest, |
| 8133 | name: "TLS13-ClientCertificate", |
| 8134 | config: Config{ |
| 8135 | Certificates: []Certificate{rsaCertificate}, |
| 8136 | MaxVersion: VersionTLS13, |
| 8137 | }, |
| 8138 | flags: []string{"-require-any-client-certificate"}, |
| 8139 | }, |
| 8140 | }) |
| 8141 | |
| 8142 | ret = append(ret, perMessageTest{ |
| 8143 | messageType: typeCertificateVerify, |
| 8144 | test: testCase{ |
| 8145 | testType: serverTest, |
| 8146 | name: "TLS13-ClientCertificateVerify", |
| 8147 | config: Config{ |
| 8148 | Certificates: []Certificate{rsaCertificate}, |
| 8149 | MaxVersion: VersionTLS13, |
| 8150 | }, |
| 8151 | flags: []string{"-require-any-client-certificate"}, |
| 8152 | }, |
| 8153 | }) |
| 8154 | |
| 8155 | ret = append(ret, perMessageTest{ |
| 8156 | messageType: typeFinished, |
| 8157 | test: testCase{ |
| 8158 | testType: serverTest, |
| 8159 | name: "TLS13-ClientFinished", |
| 8160 | config: Config{ |
| 8161 | MaxVersion: VersionTLS13, |
| 8162 | }, |
| 8163 | }, |
| 8164 | }) |
| 8165 | |
| 8166 | return ret |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8167 | } |
| 8168 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8169 | func addWrongMessageTypeTests() { |
| 8170 | for _, t := range makePerMessageTests() { |
| 8171 | t.test.name = "WrongMessageType-" + t.test.name |
| 8172 | t.test.config.Bugs.SendWrongMessageType = t.messageType |
| 8173 | t.test.shouldFail = true |
| 8174 | t.test.expectedError = ":UNEXPECTED_MESSAGE:" |
| 8175 | t.test.expectedLocalError = "remote error: unexpected message" |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8176 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8177 | if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello { |
| 8178 | // In TLS 1.3, a bad ServerHello means the client sends |
| 8179 | // an unencrypted alert while the server expects |
| 8180 | // encryption, so the alert is not readable by runner. |
| 8181 | t.test.expectedLocalError = "local error: bad record MAC" |
| 8182 | } |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8183 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8184 | testCases = append(testCases, t.test) |
| 8185 | } |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8186 | } |
| 8187 | |
David Benjamin | 639846e | 2016-09-09 11:41:18 -0400 | [diff] [blame] | 8188 | func addTrailingMessageDataTests() { |
| 8189 | for _, t := range makePerMessageTests() { |
| 8190 | t.test.name = "TrailingMessageData-" + t.test.name |
| 8191 | t.test.config.Bugs.SendTrailingMessageData = t.messageType |
| 8192 | t.test.shouldFail = true |
| 8193 | t.test.expectedError = ":DECODE_ERROR:" |
| 8194 | t.test.expectedLocalError = "remote error: error decoding message" |
| 8195 | |
| 8196 | if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello { |
| 8197 | // In TLS 1.3, a bad ServerHello means the client sends |
| 8198 | // an unencrypted alert while the server expects |
| 8199 | // encryption, so the alert is not readable by runner. |
| 8200 | t.test.expectedLocalError = "local error: bad record MAC" |
| 8201 | } |
| 8202 | |
| 8203 | if t.messageType == typeFinished { |
| 8204 | // Bad Finished messages read as the verify data having |
| 8205 | // the wrong length. |
| 8206 | t.test.expectedError = ":DIGEST_CHECK_FAILED:" |
| 8207 | t.test.expectedLocalError = "remote error: error decrypting message" |
| 8208 | } |
| 8209 | |
| 8210 | testCases = append(testCases, t.test) |
| 8211 | } |
| 8212 | } |
| 8213 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8214 | func addTLS13HandshakeTests() { |
| 8215 | testCases = append(testCases, testCase{ |
| 8216 | testType: clientTest, |
| 8217 | name: "MissingKeyShare-Client", |
| 8218 | config: Config{ |
| 8219 | MaxVersion: VersionTLS13, |
| 8220 | Bugs: ProtocolBugs{ |
| 8221 | MissingKeyShare: true, |
| 8222 | }, |
| 8223 | }, |
| 8224 | shouldFail: true, |
| 8225 | expectedError: ":MISSING_KEY_SHARE:", |
| 8226 | }) |
| 8227 | |
| 8228 | testCases = append(testCases, testCase{ |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 8229 | testType: serverTest, |
| 8230 | name: "MissingKeyShare-Server", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8231 | config: Config{ |
| 8232 | MaxVersion: VersionTLS13, |
| 8233 | Bugs: ProtocolBugs{ |
| 8234 | MissingKeyShare: true, |
| 8235 | }, |
| 8236 | }, |
| 8237 | shouldFail: true, |
| 8238 | expectedError: ":MISSING_KEY_SHARE:", |
| 8239 | }) |
| 8240 | |
| 8241 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8242 | testType: serverTest, |
| 8243 | name: "DuplicateKeyShares", |
| 8244 | config: Config{ |
| 8245 | MaxVersion: VersionTLS13, |
| 8246 | Bugs: ProtocolBugs{ |
| 8247 | DuplicateKeyShares: true, |
| 8248 | }, |
| 8249 | }, |
David Benjamin | 7e1f984 | 2016-09-20 19:24:40 -0400 | [diff] [blame] | 8250 | shouldFail: true, |
| 8251 | expectedError: ":DUPLICATE_KEY_SHARE:", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8252 | }) |
| 8253 | |
| 8254 | testCases = append(testCases, testCase{ |
| 8255 | testType: clientTest, |
| 8256 | name: "EmptyEncryptedExtensions", |
| 8257 | config: Config{ |
| 8258 | MaxVersion: VersionTLS13, |
| 8259 | Bugs: ProtocolBugs{ |
| 8260 | EmptyEncryptedExtensions: true, |
| 8261 | }, |
| 8262 | }, |
| 8263 | shouldFail: true, |
| 8264 | expectedLocalError: "remote error: error decoding message", |
| 8265 | }) |
| 8266 | |
| 8267 | testCases = append(testCases, testCase{ |
| 8268 | testType: clientTest, |
| 8269 | name: "EncryptedExtensionsWithKeyShare", |
| 8270 | config: Config{ |
| 8271 | MaxVersion: VersionTLS13, |
| 8272 | Bugs: ProtocolBugs{ |
| 8273 | EncryptedExtensionsWithKeyShare: true, |
| 8274 | }, |
| 8275 | }, |
| 8276 | shouldFail: true, |
| 8277 | expectedLocalError: "remote error: unsupported extension", |
| 8278 | }) |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 8279 | |
| 8280 | testCases = append(testCases, testCase{ |
| 8281 | testType: serverTest, |
| 8282 | name: "SendHelloRetryRequest", |
| 8283 | config: Config{ |
| 8284 | MaxVersion: VersionTLS13, |
| 8285 | // Require a HelloRetryRequest for every curve. |
| 8286 | DefaultCurves: []CurveID{}, |
| 8287 | }, |
| 8288 | expectedCurveID: CurveX25519, |
| 8289 | }) |
| 8290 | |
| 8291 | testCases = append(testCases, testCase{ |
| 8292 | testType: serverTest, |
| 8293 | name: "SendHelloRetryRequest-2", |
| 8294 | config: Config{ |
| 8295 | MaxVersion: VersionTLS13, |
| 8296 | DefaultCurves: []CurveID{CurveP384}, |
| 8297 | }, |
| 8298 | // Although the ClientHello did not predict our preferred curve, |
| 8299 | // we always select it whether it is predicted or not. |
| 8300 | expectedCurveID: CurveX25519, |
| 8301 | }) |
| 8302 | |
| 8303 | testCases = append(testCases, testCase{ |
| 8304 | name: "UnknownCurve-HelloRetryRequest", |
| 8305 | config: Config{ |
| 8306 | MaxVersion: VersionTLS13, |
| 8307 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8308 | CurvePreferences: []CurveID{CurveP384}, |
| 8309 | Bugs: ProtocolBugs{ |
| 8310 | SendHelloRetryRequestCurve: bogusCurve, |
| 8311 | }, |
| 8312 | }, |
| 8313 | shouldFail: true, |
| 8314 | expectedError: ":WRONG_CURVE:", |
| 8315 | }) |
| 8316 | |
| 8317 | testCases = append(testCases, testCase{ |
| 8318 | name: "DisabledCurve-HelloRetryRequest", |
| 8319 | config: Config{ |
| 8320 | MaxVersion: VersionTLS13, |
| 8321 | CurvePreferences: []CurveID{CurveP256}, |
| 8322 | Bugs: ProtocolBugs{ |
| 8323 | IgnorePeerCurvePreferences: true, |
| 8324 | }, |
| 8325 | }, |
| 8326 | flags: []string{"-p384-only"}, |
| 8327 | shouldFail: true, |
| 8328 | expectedError: ":WRONG_CURVE:", |
| 8329 | }) |
| 8330 | |
| 8331 | testCases = append(testCases, testCase{ |
| 8332 | name: "UnnecessaryHelloRetryRequest", |
| 8333 | config: Config{ |
| 8334 | MaxVersion: VersionTLS13, |
| 8335 | Bugs: ProtocolBugs{ |
| 8336 | UnnecessaryHelloRetryRequest: true, |
| 8337 | }, |
| 8338 | }, |
| 8339 | shouldFail: true, |
| 8340 | expectedError: ":WRONG_CURVE:", |
| 8341 | }) |
| 8342 | |
| 8343 | testCases = append(testCases, testCase{ |
| 8344 | name: "SecondHelloRetryRequest", |
| 8345 | config: Config{ |
| 8346 | MaxVersion: VersionTLS13, |
| 8347 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8348 | CurvePreferences: []CurveID{CurveP384}, |
| 8349 | Bugs: ProtocolBugs{ |
| 8350 | SecondHelloRetryRequest: true, |
| 8351 | }, |
| 8352 | }, |
| 8353 | shouldFail: true, |
| 8354 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 8355 | }) |
| 8356 | |
| 8357 | testCases = append(testCases, testCase{ |
| 8358 | testType: serverTest, |
| 8359 | name: "SecondClientHelloMissingKeyShare", |
| 8360 | config: Config{ |
| 8361 | MaxVersion: VersionTLS13, |
| 8362 | DefaultCurves: []CurveID{}, |
| 8363 | Bugs: ProtocolBugs{ |
| 8364 | SecondClientHelloMissingKeyShare: true, |
| 8365 | }, |
| 8366 | }, |
| 8367 | shouldFail: true, |
| 8368 | expectedError: ":MISSING_KEY_SHARE:", |
| 8369 | }) |
| 8370 | |
| 8371 | testCases = append(testCases, testCase{ |
| 8372 | testType: serverTest, |
| 8373 | name: "SecondClientHelloWrongCurve", |
| 8374 | config: Config{ |
| 8375 | MaxVersion: VersionTLS13, |
| 8376 | DefaultCurves: []CurveID{}, |
| 8377 | Bugs: ProtocolBugs{ |
| 8378 | MisinterpretHelloRetryRequestCurve: CurveP521, |
| 8379 | }, |
| 8380 | }, |
| 8381 | shouldFail: true, |
| 8382 | expectedError: ":WRONG_CURVE:", |
| 8383 | }) |
| 8384 | |
| 8385 | testCases = append(testCases, testCase{ |
| 8386 | name: "HelloRetryRequestVersionMismatch", |
| 8387 | config: Config{ |
| 8388 | MaxVersion: VersionTLS13, |
| 8389 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8390 | CurvePreferences: []CurveID{CurveP384}, |
| 8391 | Bugs: ProtocolBugs{ |
| 8392 | SendServerHelloVersion: 0x0305, |
| 8393 | }, |
| 8394 | }, |
| 8395 | shouldFail: true, |
| 8396 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 8397 | }) |
| 8398 | |
| 8399 | testCases = append(testCases, testCase{ |
| 8400 | name: "HelloRetryRequestCurveMismatch", |
| 8401 | config: Config{ |
| 8402 | MaxVersion: VersionTLS13, |
| 8403 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8404 | CurvePreferences: []CurveID{CurveP384}, |
| 8405 | Bugs: ProtocolBugs{ |
| 8406 | // Send P-384 (correct) in the HelloRetryRequest. |
| 8407 | SendHelloRetryRequestCurve: CurveP384, |
| 8408 | // But send P-256 in the ServerHello. |
| 8409 | SendCurve: CurveP256, |
| 8410 | }, |
| 8411 | }, |
| 8412 | shouldFail: true, |
| 8413 | expectedError: ":WRONG_CURVE:", |
| 8414 | }) |
| 8415 | |
| 8416 | // Test the server selecting a curve that requires a HelloRetryRequest |
| 8417 | // without sending it. |
| 8418 | testCases = append(testCases, testCase{ |
| 8419 | name: "SkipHelloRetryRequest", |
| 8420 | config: Config{ |
| 8421 | MaxVersion: VersionTLS13, |
| 8422 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8423 | CurvePreferences: []CurveID{CurveP384}, |
| 8424 | Bugs: ProtocolBugs{ |
| 8425 | SkipHelloRetryRequest: true, |
| 8426 | }, |
| 8427 | }, |
| 8428 | shouldFail: true, |
| 8429 | expectedError: ":WRONG_CURVE:", |
| 8430 | }) |
David Benjamin | 8a8349b | 2016-08-18 02:32:23 -0400 | [diff] [blame] | 8431 | |
| 8432 | testCases = append(testCases, testCase{ |
| 8433 | name: "TLS13-RequestContextInHandshake", |
| 8434 | config: Config{ |
| 8435 | MaxVersion: VersionTLS13, |
| 8436 | MinVersion: VersionTLS13, |
| 8437 | ClientAuth: RequireAnyClientCert, |
| 8438 | Bugs: ProtocolBugs{ |
| 8439 | SendRequestContext: []byte("request context"), |
| 8440 | }, |
| 8441 | }, |
| 8442 | flags: []string{ |
| 8443 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 8444 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 8445 | }, |
| 8446 | shouldFail: true, |
| 8447 | expectedError: ":DECODE_ERROR:", |
| 8448 | }) |
David Benjamin | 7e1f984 | 2016-09-20 19:24:40 -0400 | [diff] [blame] | 8449 | |
| 8450 | testCases = append(testCases, testCase{ |
| 8451 | testType: serverTest, |
| 8452 | name: "TLS13-TrailingKeyShareData", |
| 8453 | config: Config{ |
| 8454 | MaxVersion: VersionTLS13, |
| 8455 | Bugs: ProtocolBugs{ |
| 8456 | TrailingKeyShareData: true, |
| 8457 | }, |
| 8458 | }, |
| 8459 | shouldFail: true, |
| 8460 | expectedError: ":DECODE_ERROR:", |
| 8461 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8462 | } |
| 8463 | |
David Benjamin | f3fbade | 2016-09-19 13:08:16 -0400 | [diff] [blame] | 8464 | func addPeekTests() { |
| 8465 | // Test SSL_peek works, including on empty records. |
| 8466 | testCases = append(testCases, testCase{ |
| 8467 | name: "Peek-Basic", |
| 8468 | sendEmptyRecords: 1, |
| 8469 | flags: []string{"-peek-then-read"}, |
| 8470 | }) |
| 8471 | |
| 8472 | // Test SSL_peek can drive the initial handshake. |
| 8473 | testCases = append(testCases, testCase{ |
| 8474 | name: "Peek-ImplicitHandshake", |
| 8475 | flags: []string{ |
| 8476 | "-peek-then-read", |
| 8477 | "-implicit-handshake", |
| 8478 | }, |
| 8479 | }) |
| 8480 | |
| 8481 | // Test SSL_peek can discover and drive a renegotiation. |
| 8482 | testCases = append(testCases, testCase{ |
| 8483 | name: "Peek-Renegotiate", |
| 8484 | config: Config{ |
| 8485 | MaxVersion: VersionTLS12, |
| 8486 | }, |
| 8487 | renegotiate: 1, |
| 8488 | flags: []string{ |
| 8489 | "-peek-then-read", |
| 8490 | "-renegotiate-freely", |
| 8491 | "-expect-total-renegotiations", "1", |
| 8492 | }, |
| 8493 | }) |
| 8494 | |
| 8495 | // Test SSL_peek can discover a close_notify. |
| 8496 | testCases = append(testCases, testCase{ |
| 8497 | name: "Peek-Shutdown", |
| 8498 | config: Config{ |
| 8499 | Bugs: ProtocolBugs{ |
| 8500 | ExpectCloseNotify: true, |
| 8501 | }, |
| 8502 | }, |
| 8503 | flags: []string{ |
| 8504 | "-peek-then-read", |
| 8505 | "-check-close-notify", |
| 8506 | }, |
| 8507 | }) |
| 8508 | |
| 8509 | // Test SSL_peek can discover an alert. |
| 8510 | testCases = append(testCases, testCase{ |
| 8511 | name: "Peek-Alert", |
| 8512 | config: Config{ |
| 8513 | Bugs: ProtocolBugs{ |
| 8514 | SendSpuriousAlert: alertRecordOverflow, |
| 8515 | }, |
| 8516 | }, |
| 8517 | flags: []string{"-peek-then-read"}, |
| 8518 | shouldFail: true, |
| 8519 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 8520 | }) |
| 8521 | |
| 8522 | // Test SSL_peek can handle KeyUpdate. |
| 8523 | testCases = append(testCases, testCase{ |
| 8524 | name: "Peek-KeyUpdate", |
| 8525 | config: Config{ |
| 8526 | MaxVersion: VersionTLS13, |
| 8527 | Bugs: ProtocolBugs{ |
| 8528 | SendKeyUpdateBeforeEveryAppDataRecord: true, |
| 8529 | }, |
| 8530 | }, |
| 8531 | flags: []string{"-peek-then-read"}, |
| 8532 | }) |
| 8533 | } |
| 8534 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8535 | 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] | 8536 | defer wg.Done() |
| 8537 | |
| 8538 | for test := range c { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 8539 | var err error |
| 8540 | |
| 8541 | if *mallocTest < 0 { |
| 8542 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8543 | err = runTest(test, shimPath, -1) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 8544 | } else { |
| 8545 | for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ { |
| 8546 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8547 | if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 8548 | if err != nil { |
| 8549 | fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err) |
| 8550 | } |
| 8551 | break |
| 8552 | } |
| 8553 | } |
| 8554 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8555 | statusChan <- statusMsg{test: test, err: err} |
| 8556 | } |
| 8557 | } |
| 8558 | |
| 8559 | type statusMsg struct { |
| 8560 | test *testCase |
| 8561 | started bool |
| 8562 | err error |
| 8563 | } |
| 8564 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8565 | func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8566 | var started, done, failed, unimplemented, lineLen int |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8567 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8568 | testOutput := newTestOutput() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8569 | for msg := range statusChan { |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8570 | if !*pipe { |
| 8571 | // Erase the previous status line. |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 8572 | var erase string |
| 8573 | for i := 0; i < lineLen; i++ { |
| 8574 | erase += "\b \b" |
| 8575 | } |
| 8576 | fmt.Print(erase) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8577 | } |
| 8578 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8579 | if msg.started { |
| 8580 | started++ |
| 8581 | } else { |
| 8582 | done++ |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8583 | |
| 8584 | if msg.err != nil { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8585 | if msg.err == errUnimplemented { |
| 8586 | if *pipe { |
| 8587 | // Print each test instead of a status line. |
| 8588 | fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name) |
| 8589 | } |
| 8590 | unimplemented++ |
| 8591 | testOutput.addResult(msg.test.name, "UNIMPLEMENTED") |
| 8592 | } else { |
| 8593 | fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err) |
| 8594 | failed++ |
| 8595 | testOutput.addResult(msg.test.name, "FAIL") |
| 8596 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8597 | } else { |
| 8598 | if *pipe { |
| 8599 | // Print each test instead of a status line. |
| 8600 | fmt.Printf("PASSED (%s)\n", msg.test.name) |
| 8601 | } |
| 8602 | testOutput.addResult(msg.test.name, "PASS") |
| 8603 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8604 | } |
| 8605 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8606 | if !*pipe { |
| 8607 | // Print a new status line. |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8608 | 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] | 8609 | lineLen = len(line) |
| 8610 | os.Stdout.WriteString(line) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8611 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8612 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8613 | |
| 8614 | doneChan <- testOutput |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8615 | } |
| 8616 | |
| 8617 | func main() { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8618 | flag.Parse() |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8619 | *resourceDir = path.Clean(*resourceDir) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 8620 | initCertificates() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8621 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8622 | addBasicTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8623 | addCipherSuiteTests() |
| 8624 | addBadECDSASignatureTests() |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8625 | addCBCPaddingTests() |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 8626 | addCBCSplittingTests() |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 8627 | addClientAuthTests() |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 8628 | addDDoSCallbackTests() |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 8629 | addVersionNegotiationTests() |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 8630 | addMinimumVersionTests() |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 8631 | addExtensionTests() |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 8632 | addResumptionVersionTests() |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 8633 | addExtendedMasterSecretTests() |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 8634 | addRenegotiationTests() |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 8635 | addDTLSReplayTests() |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 8636 | addSignatureAlgorithmTests() |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 8637 | addDTLSRetransmitTests() |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 8638 | addExportKeyingMaterialTests() |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 8639 | addTLSUniqueTests() |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 8640 | addCustomExtensionTests() |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 8641 | addRSAClientKeyExchangeTests() |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 8642 | addCurveTests() |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 8643 | addCECPQ1Tests() |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 8644 | addDHEGroupSizeTests() |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 8645 | addTLS13RecordTests() |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 8646 | addAllStateMachineCoverageTests() |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 8647 | addChangeCipherSpecTests() |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8648 | addWrongMessageTypeTests() |
David Benjamin | 639846e | 2016-09-09 11:41:18 -0400 | [diff] [blame] | 8649 | addTrailingMessageDataTests() |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8650 | addTLS13HandshakeTests() |
David Benjamin | f3fbade | 2016-09-19 13:08:16 -0400 | [diff] [blame] | 8651 | addPeekTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8652 | |
| 8653 | var wg sync.WaitGroup |
| 8654 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8655 | statusChan := make(chan statusMsg, *numWorkers) |
| 8656 | testChan := make(chan *testCase, *numWorkers) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8657 | doneChan := make(chan *testOutput) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8658 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8659 | if len(*shimConfigFile) != 0 { |
| 8660 | encoded, err := ioutil.ReadFile(*shimConfigFile) |
| 8661 | if err != nil { |
| 8662 | fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err) |
| 8663 | os.Exit(1) |
| 8664 | } |
| 8665 | |
| 8666 | if err := json.Unmarshal(encoded, &shimConfig); err != nil { |
| 8667 | fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err) |
| 8668 | os.Exit(1) |
| 8669 | } |
| 8670 | } |
| 8671 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8672 | go statusPrinter(doneChan, statusChan, len(testCases)) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8673 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8674 | for i := 0; i < *numWorkers; i++ { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8675 | wg.Add(1) |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8676 | go worker(statusChan, testChan, *shimPath, &wg) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8677 | } |
| 8678 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8679 | var foundTest bool |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8680 | for i := range testCases { |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8681 | matched := true |
| 8682 | if len(*testToRun) != 0 { |
| 8683 | var err error |
| 8684 | matched, err = filepath.Match(*testToRun, testCases[i].name) |
| 8685 | if err != nil { |
| 8686 | fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err) |
| 8687 | os.Exit(1) |
| 8688 | } |
| 8689 | } |
| 8690 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8691 | if !*includeDisabled { |
| 8692 | for pattern := range shimConfig.DisabledTests { |
| 8693 | isDisabled, err := filepath.Match(pattern, testCases[i].name) |
| 8694 | if err != nil { |
| 8695 | fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err) |
| 8696 | os.Exit(1) |
| 8697 | } |
| 8698 | |
| 8699 | if isDisabled { |
| 8700 | matched = false |
| 8701 | break |
| 8702 | } |
| 8703 | } |
| 8704 | } |
| 8705 | |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8706 | if matched { |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8707 | foundTest = true |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8708 | testChan <- &testCases[i] |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8709 | } |
| 8710 | } |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8711 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8712 | if !foundTest { |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8713 | fmt.Fprintf(os.Stderr, "No tests run\n") |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8714 | os.Exit(1) |
| 8715 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8716 | |
| 8717 | close(testChan) |
| 8718 | wg.Wait() |
| 8719 | close(statusChan) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8720 | testOutput := <-doneChan |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8721 | |
| 8722 | fmt.Printf("\n") |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8723 | |
| 8724 | if *jsonOutput != "" { |
| 8725 | if err := testOutput.writeTo(*jsonOutput); err != nil { |
| 8726 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 8727 | } |
| 8728 | } |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 8729 | |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8730 | if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 { |
| 8731 | os.Exit(1) |
| 8732 | } |
| 8733 | |
| 8734 | if !testOutput.noneFailed { |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 8735 | os.Exit(1) |
| 8736 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8737 | } |