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 | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2448 | var expectedServerError, expectedClientError string |
| 2449 | if shouldServerFail { |
| 2450 | expectedServerError = ":NO_SHARED_CIPHER:" |
| 2451 | } |
| 2452 | if shouldClientFail { |
| 2453 | expectedClientError = ":WRONG_CIPHER_RETURNED:" |
| 2454 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2455 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2456 | testCases = append(testCases, testCase{ |
| 2457 | testType: serverTest, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2458 | protocol: protocol, |
| 2459 | |
| 2460 | name: prefix + ver.name + "-" + suite.name + "-server", |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2461 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2462 | MinVersion: ver.version, |
| 2463 | MaxVersion: ver.version, |
| 2464 | CipherSuites: []uint16{suite.id}, |
| 2465 | Certificates: []Certificate{cert}, |
| 2466 | PreSharedKey: []byte(psk), |
| 2467 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2468 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2469 | EnableAllCiphers: shouldServerFail, |
| 2470 | IgnorePeerCipherPreferences: shouldServerFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2471 | }, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2472 | }, |
| 2473 | certFile: certFile, |
| 2474 | keyFile: keyFile, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2475 | flags: flags, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 2476 | resumeSession: true, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2477 | shouldFail: shouldServerFail, |
| 2478 | expectedError: expectedServerError, |
| 2479 | }) |
| 2480 | |
| 2481 | testCases = append(testCases, testCase{ |
| 2482 | testType: clientTest, |
| 2483 | protocol: protocol, |
| 2484 | name: prefix + ver.name + "-" + suite.name + "-client", |
| 2485 | config: Config{ |
| 2486 | MinVersion: ver.version, |
| 2487 | MaxVersion: ver.version, |
| 2488 | CipherSuites: []uint16{suite.id}, |
| 2489 | Certificates: []Certificate{cert}, |
| 2490 | PreSharedKey: []byte(psk), |
| 2491 | PreSharedKeyIdentity: pskIdentity, |
| 2492 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2493 | EnableAllCiphers: shouldClientFail, |
| 2494 | IgnorePeerCipherPreferences: shouldClientFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2495 | }, |
| 2496 | }, |
| 2497 | flags: flags, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 2498 | resumeSession: true, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2499 | shouldFail: shouldClientFail, |
| 2500 | expectedError: expectedClientError, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2501 | }) |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2502 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2503 | if !shouldClientFail { |
| 2504 | // Ensure the maximum record size is accepted. |
| 2505 | testCases = append(testCases, testCase{ |
| 2506 | name: prefix + ver.name + "-" + suite.name + "-LargeRecord", |
| 2507 | config: Config{ |
| 2508 | MinVersion: ver.version, |
| 2509 | MaxVersion: ver.version, |
| 2510 | CipherSuites: []uint16{suite.id}, |
| 2511 | Certificates: []Certificate{cert}, |
| 2512 | PreSharedKey: []byte(psk), |
| 2513 | PreSharedKeyIdentity: pskIdentity, |
| 2514 | }, |
| 2515 | flags: flags, |
| 2516 | messageLen: maxPlaintext, |
| 2517 | }) |
| 2518 | } |
| 2519 | } |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2520 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2521 | } |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2522 | |
| 2523 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2524 | name: "NoSharedCipher", |
| 2525 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2526 | MaxVersion: VersionTLS12, |
| 2527 | CipherSuites: []uint16{}, |
| 2528 | }, |
| 2529 | shouldFail: true, |
| 2530 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2531 | }) |
| 2532 | |
| 2533 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2534 | name: "NoSharedCipher-TLS13", |
| 2535 | config: Config{ |
| 2536 | MaxVersion: VersionTLS13, |
| 2537 | CipherSuites: []uint16{}, |
| 2538 | }, |
| 2539 | shouldFail: true, |
| 2540 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2541 | }) |
| 2542 | |
| 2543 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2544 | name: "UnsupportedCipherSuite", |
| 2545 | config: Config{ |
| 2546 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 9c8c418 | 2016-08-24 14:36:54 -0700 | [diff] [blame] | 2547 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2548 | Bugs: ProtocolBugs{ |
| 2549 | IgnorePeerCipherPreferences: true, |
| 2550 | }, |
| 2551 | }, |
Matt Braithwaite | 9c8c418 | 2016-08-24 14:36:54 -0700 | [diff] [blame] | 2552 | flags: []string{"-cipher", "DEFAULT:!AES"}, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2553 | shouldFail: true, |
| 2554 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 2555 | }) |
| 2556 | |
| 2557 | testCases = append(testCases, testCase{ |
David Benjamin | e470e66 | 2016-07-18 15:47:32 +0200 | [diff] [blame] | 2558 | name: "ServerHelloBogusCipher", |
| 2559 | config: Config{ |
| 2560 | MaxVersion: VersionTLS12, |
| 2561 | Bugs: ProtocolBugs{ |
| 2562 | SendCipherSuite: bogusCipher, |
| 2563 | }, |
| 2564 | }, |
| 2565 | shouldFail: true, |
| 2566 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2567 | }) |
| 2568 | testCases = append(testCases, testCase{ |
| 2569 | name: "ServerHelloBogusCipher-TLS13", |
| 2570 | config: Config{ |
| 2571 | MaxVersion: VersionTLS13, |
| 2572 | Bugs: ProtocolBugs{ |
| 2573 | SendCipherSuite: bogusCipher, |
| 2574 | }, |
| 2575 | }, |
| 2576 | shouldFail: true, |
| 2577 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2578 | }) |
| 2579 | |
| 2580 | testCases = append(testCases, testCase{ |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2581 | name: "WeakDH", |
| 2582 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2583 | MaxVersion: VersionTLS12, |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2584 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2585 | Bugs: ProtocolBugs{ |
| 2586 | // This is a 1023-bit prime number, generated |
| 2587 | // with: |
| 2588 | // openssl gendh 1023 | openssl asn1parse -i |
| 2589 | DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"), |
| 2590 | }, |
| 2591 | }, |
| 2592 | shouldFail: true, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2593 | expectedError: ":BAD_DH_P_LENGTH:", |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2594 | }) |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2595 | |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2596 | testCases = append(testCases, testCase{ |
| 2597 | name: "SillyDH", |
| 2598 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2599 | MaxVersion: VersionTLS12, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2600 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2601 | Bugs: ProtocolBugs{ |
| 2602 | // This is a 4097-bit prime number, generated |
| 2603 | // with: |
| 2604 | // openssl gendh 4097 | openssl asn1parse -i |
| 2605 | DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"), |
| 2606 | }, |
| 2607 | }, |
| 2608 | shouldFail: true, |
| 2609 | expectedError: ":DH_P_TOO_LONG:", |
| 2610 | }) |
| 2611 | |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2612 | // This test ensures that Diffie-Hellman public values are padded with |
| 2613 | // zeros so that they're the same length as the prime. This is to avoid |
| 2614 | // hitting a bug in yaSSL. |
| 2615 | testCases = append(testCases, testCase{ |
| 2616 | testType: serverTest, |
| 2617 | name: "DHPublicValuePadded", |
| 2618 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2619 | MaxVersion: VersionTLS12, |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2620 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2621 | Bugs: ProtocolBugs{ |
| 2622 | RequireDHPublicValueLen: (1025 + 7) / 8, |
| 2623 | }, |
| 2624 | }, |
| 2625 | flags: []string{"-use-sparse-dh-prime"}, |
| 2626 | }) |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2627 | |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2628 | // The server must be tolerant to bogus ciphers. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2629 | testCases = append(testCases, testCase{ |
| 2630 | testType: serverTest, |
| 2631 | name: "UnknownCipher", |
| 2632 | config: Config{ |
| 2633 | CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2634 | }, |
| 2635 | }) |
| 2636 | |
David Benjamin | 7867934 | 2016-09-16 19:42:05 -0400 | [diff] [blame] | 2637 | // Test empty ECDHE_PSK identity hints work as expected. |
| 2638 | testCases = append(testCases, testCase{ |
| 2639 | name: "EmptyECDHEPSKHint", |
| 2640 | config: Config{ |
| 2641 | MaxVersion: VersionTLS12, |
| 2642 | CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 2643 | PreSharedKey: []byte("secret"), |
| 2644 | }, |
| 2645 | flags: []string{"-psk", "secret"}, |
| 2646 | }) |
| 2647 | |
| 2648 | // Test empty PSK identity hints work as expected, even if an explicit |
| 2649 | // ServerKeyExchange is sent. |
| 2650 | testCases = append(testCases, testCase{ |
| 2651 | name: "ExplicitEmptyPSKHint", |
| 2652 | config: Config{ |
| 2653 | MaxVersion: VersionTLS12, |
| 2654 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 2655 | PreSharedKey: []byte("secret"), |
| 2656 | Bugs: ProtocolBugs{ |
| 2657 | AlwaysSendPreSharedKeyIdentityHint: true, |
| 2658 | }, |
| 2659 | }, |
| 2660 | flags: []string{"-psk", "secret"}, |
| 2661 | }) |
| 2662 | |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2663 | // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS |
| 2664 | // 1.1 specific cipher suite settings. A server is setup with the given |
| 2665 | // cipher lists and then a connection is made for each member of |
| 2666 | // expectations. The cipher suite that the server selects must match |
| 2667 | // the specified one. |
| 2668 | var versionSpecificCiphersTest = []struct { |
| 2669 | ciphersDefault, ciphersTLS10, ciphersTLS11 string |
| 2670 | // expectations is a map from TLS version to cipher suite id. |
| 2671 | expectations map[uint16]uint16 |
| 2672 | }{ |
| 2673 | { |
| 2674 | // Test that the null case (where no version-specific ciphers are set) |
| 2675 | // works as expected. |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2676 | "DES-CBC3-SHA:AES128-SHA", // default ciphers |
| 2677 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2678 | "", // no ciphers specifically for TLS ≥ 1.1 |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2679 | map[uint16]uint16{ |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2680 | VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
| 2681 | VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
| 2682 | VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
| 2683 | VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2684 | }, |
| 2685 | }, |
| 2686 | { |
| 2687 | // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different |
| 2688 | // cipher. |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2689 | "DES-CBC3-SHA:AES128-SHA", // default |
| 2690 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2691 | "", // no ciphers specifically for TLS ≥ 1.1 |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2692 | map[uint16]uint16{ |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2693 | VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2694 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2695 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2696 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2697 | }, |
| 2698 | }, |
| 2699 | { |
| 2700 | // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different |
| 2701 | // cipher. |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2702 | "DES-CBC3-SHA:AES128-SHA", // default |
| 2703 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2704 | "AES128-SHA", // these ciphers for TLS ≥ 1.1 |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2705 | map[uint16]uint16{ |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2706 | VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
| 2707 | VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2708 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2709 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2710 | }, |
| 2711 | }, |
| 2712 | { |
| 2713 | // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should |
| 2714 | // mask ciphers_tls10 for TLS 1.1 and 1.2. |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2715 | "DES-CBC3-SHA:AES128-SHA", // default |
| 2716 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2717 | "AES256-SHA", // these ciphers for TLS ≥ 1.1 |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2718 | map[uint16]uint16{ |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2719 | VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA, |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2720 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2721 | VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2722 | VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2723 | }, |
| 2724 | }, |
| 2725 | } |
| 2726 | |
| 2727 | for i, test := range versionSpecificCiphersTest { |
| 2728 | for version, expectedCipherSuite := range test.expectations { |
| 2729 | flags := []string{"-cipher", test.ciphersDefault} |
| 2730 | if len(test.ciphersTLS10) > 0 { |
| 2731 | flags = append(flags, "-cipher-tls10", test.ciphersTLS10) |
| 2732 | } |
| 2733 | if len(test.ciphersTLS11) > 0 { |
| 2734 | flags = append(flags, "-cipher-tls11", test.ciphersTLS11) |
| 2735 | } |
| 2736 | |
| 2737 | testCases = append(testCases, testCase{ |
| 2738 | testType: serverTest, |
| 2739 | name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version), |
| 2740 | config: Config{ |
| 2741 | MaxVersion: version, |
| 2742 | MinVersion: version, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 2743 | 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] | 2744 | }, |
| 2745 | flags: flags, |
| 2746 | expectedCipher: expectedCipherSuite, |
| 2747 | }) |
| 2748 | } |
| 2749 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | func addBadECDSASignatureTests() { |
| 2753 | for badR := BadValue(1); badR < NumBadValues; badR++ { |
| 2754 | for badS := BadValue(1); badS < NumBadValues; badS++ { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2755 | testCases = append(testCases, testCase{ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2756 | name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS), |
| 2757 | config: Config{ |
| 2758 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2759 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2760 | Bugs: ProtocolBugs{ |
| 2761 | BadECDSAR: badR, |
| 2762 | BadECDSAS: badS, |
| 2763 | }, |
| 2764 | }, |
| 2765 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2766 | expectedError: ":BAD_SIGNATURE:", |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2767 | }) |
| 2768 | } |
| 2769 | } |
| 2770 | } |
| 2771 | |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2772 | func addCBCPaddingTests() { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2773 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2774 | name: "MaxCBCPadding", |
| 2775 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2776 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2777 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2778 | Bugs: ProtocolBugs{ |
| 2779 | MaxPadding: true, |
| 2780 | }, |
| 2781 | }, |
| 2782 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2783 | }) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2784 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2785 | name: "BadCBCPadding", |
| 2786 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2787 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2788 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2789 | Bugs: ProtocolBugs{ |
| 2790 | PaddingFirstByteBad: true, |
| 2791 | }, |
| 2792 | }, |
| 2793 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2794 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2795 | }) |
| 2796 | // OpenSSL previously had an issue where the first byte of padding in |
| 2797 | // 255 bytes of padding wasn't checked. |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2798 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2799 | name: "BadCBCPadding255", |
| 2800 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2801 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2802 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2803 | Bugs: ProtocolBugs{ |
| 2804 | MaxPadding: true, |
| 2805 | PaddingFirstByteBadIf255: true, |
| 2806 | }, |
| 2807 | }, |
| 2808 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2809 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2810 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2811 | }) |
| 2812 | } |
| 2813 | |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2814 | func addCBCSplittingTests() { |
| 2815 | testCases = append(testCases, testCase{ |
| 2816 | name: "CBCRecordSplitting", |
| 2817 | config: Config{ |
| 2818 | MaxVersion: VersionTLS10, |
| 2819 | MinVersion: VersionTLS10, |
| 2820 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2821 | }, |
David Benjamin | ac8302a | 2015-09-01 17:18:15 -0400 | [diff] [blame] | 2822 | messageLen: -1, // read until EOF |
| 2823 | resumeSession: true, |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2824 | flags: []string{ |
| 2825 | "-async", |
| 2826 | "-write-different-record-sizes", |
| 2827 | "-cbc-record-splitting", |
| 2828 | }, |
David Benjamin | a8e3e0e | 2014-08-06 22:11:10 -0400 | [diff] [blame] | 2829 | }) |
| 2830 | testCases = append(testCases, testCase{ |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2831 | name: "CBCRecordSplittingPartialWrite", |
| 2832 | config: Config{ |
| 2833 | MaxVersion: VersionTLS10, |
| 2834 | MinVersion: VersionTLS10, |
| 2835 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2836 | }, |
| 2837 | messageLen: -1, // read until EOF |
| 2838 | flags: []string{ |
| 2839 | "-async", |
| 2840 | "-write-different-record-sizes", |
| 2841 | "-cbc-record-splitting", |
| 2842 | "-partial-write", |
| 2843 | }, |
| 2844 | }) |
| 2845 | } |
| 2846 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2847 | func addClientAuthTests() { |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 2848 | // Add a dummy cert pool to stress certificate authority parsing. |
| 2849 | // TODO(davidben): Add tests that those values parse out correctly. |
| 2850 | certPool := x509.NewCertPool() |
| 2851 | cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0]) |
| 2852 | if err != nil { |
| 2853 | panic(err) |
| 2854 | } |
| 2855 | certPool.AddCert(cert) |
| 2856 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2857 | for _, ver := range tlsVersions { |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2858 | testCases = append(testCases, testCase{ |
| 2859 | testType: clientTest, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2860 | name: ver.name + "-Client-ClientAuth-RSA", |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2861 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2862 | MinVersion: ver.version, |
| 2863 | MaxVersion: ver.version, |
| 2864 | ClientAuth: RequireAnyClientCert, |
| 2865 | ClientCAs: certPool, |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2866 | }, |
| 2867 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2868 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2869 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2870 | }, |
| 2871 | }) |
| 2872 | testCases = append(testCases, testCase{ |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2873 | testType: serverTest, |
| 2874 | name: ver.name + "-Server-ClientAuth-RSA", |
| 2875 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2876 | MinVersion: ver.version, |
| 2877 | MaxVersion: ver.version, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2878 | Certificates: []Certificate{rsaCertificate}, |
| 2879 | }, |
| 2880 | flags: []string{"-require-any-client-certificate"}, |
| 2881 | }) |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2882 | if ver.version != VersionSSL30 { |
| 2883 | testCases = append(testCases, testCase{ |
| 2884 | testType: serverTest, |
| 2885 | name: ver.name + "-Server-ClientAuth-ECDSA", |
| 2886 | config: Config{ |
| 2887 | MinVersion: ver.version, |
| 2888 | MaxVersion: ver.version, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2889 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2890 | }, |
| 2891 | flags: []string{"-require-any-client-certificate"}, |
| 2892 | }) |
| 2893 | testCases = append(testCases, testCase{ |
| 2894 | testType: clientTest, |
| 2895 | name: ver.name + "-Client-ClientAuth-ECDSA", |
| 2896 | config: Config{ |
| 2897 | MinVersion: ver.version, |
| 2898 | MaxVersion: ver.version, |
| 2899 | ClientAuth: RequireAnyClientCert, |
| 2900 | ClientCAs: certPool, |
| 2901 | }, |
| 2902 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2903 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 2904 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2905 | }, |
| 2906 | }) |
| 2907 | } |
Adam Langley | 3764683 | 2016-08-01 16:16:46 -0700 | [diff] [blame] | 2908 | |
| 2909 | testCases = append(testCases, testCase{ |
| 2910 | name: "NoClientCertificate-" + ver.name, |
| 2911 | config: Config{ |
| 2912 | MinVersion: ver.version, |
| 2913 | MaxVersion: ver.version, |
| 2914 | ClientAuth: RequireAnyClientCert, |
| 2915 | }, |
| 2916 | shouldFail: true, |
| 2917 | expectedLocalError: "client didn't provide a certificate", |
| 2918 | }) |
| 2919 | |
| 2920 | testCases = append(testCases, testCase{ |
| 2921 | // Even if not configured to expect a certificate, OpenSSL will |
| 2922 | // return X509_V_OK as the verify_result. |
| 2923 | testType: serverTest, |
| 2924 | name: "NoClientCertificateRequested-Server-" + ver.name, |
| 2925 | config: Config{ |
| 2926 | MinVersion: ver.version, |
| 2927 | MaxVersion: ver.version, |
| 2928 | }, |
| 2929 | flags: []string{ |
| 2930 | "-expect-verify-result", |
| 2931 | }, |
| 2932 | // TODO(davidben): Switch this to true when TLS 1.3 |
| 2933 | // supports session resumption. |
| 2934 | resumeSession: ver.version < VersionTLS13, |
| 2935 | }) |
| 2936 | |
| 2937 | testCases = append(testCases, testCase{ |
| 2938 | // If a client certificate is not provided, OpenSSL will still |
| 2939 | // return X509_V_OK as the verify_result. |
| 2940 | testType: serverTest, |
| 2941 | name: "NoClientCertificate-Server-" + ver.name, |
| 2942 | config: Config{ |
| 2943 | MinVersion: ver.version, |
| 2944 | MaxVersion: ver.version, |
| 2945 | }, |
| 2946 | flags: []string{ |
| 2947 | "-expect-verify-result", |
| 2948 | "-verify-peer", |
| 2949 | }, |
| 2950 | // TODO(davidben): Switch this to true when TLS 1.3 |
| 2951 | // supports session resumption. |
| 2952 | resumeSession: ver.version < VersionTLS13, |
| 2953 | }) |
| 2954 | |
| 2955 | testCases = append(testCases, testCase{ |
| 2956 | testType: serverTest, |
| 2957 | name: "RequireAnyClientCertificate-" + ver.name, |
| 2958 | config: Config{ |
| 2959 | MinVersion: ver.version, |
| 2960 | MaxVersion: ver.version, |
| 2961 | }, |
| 2962 | flags: []string{"-require-any-client-certificate"}, |
| 2963 | shouldFail: true, |
| 2964 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2965 | }) |
| 2966 | |
| 2967 | if ver.version != VersionSSL30 { |
| 2968 | testCases = append(testCases, testCase{ |
| 2969 | testType: serverTest, |
| 2970 | name: "SkipClientCertificate-" + ver.name, |
| 2971 | config: Config{ |
| 2972 | MinVersion: ver.version, |
| 2973 | MaxVersion: ver.version, |
| 2974 | Bugs: ProtocolBugs{ |
| 2975 | SkipClientCertificate: true, |
| 2976 | }, |
| 2977 | }, |
| 2978 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2979 | flags: []string{"-verify-peer"}, |
| 2980 | shouldFail: true, |
| 2981 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2982 | }) |
| 2983 | } |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2984 | } |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2985 | |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2986 | // Client auth is only legal in certificate-based ciphers. |
| 2987 | testCases = append(testCases, testCase{ |
| 2988 | testType: clientTest, |
| 2989 | name: "ClientAuth-PSK", |
| 2990 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2991 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2992 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 2993 | PreSharedKey: []byte("secret"), |
| 2994 | ClientAuth: RequireAnyClientCert, |
| 2995 | }, |
| 2996 | flags: []string{ |
| 2997 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2998 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2999 | "-psk", "secret", |
| 3000 | }, |
| 3001 | shouldFail: true, |
| 3002 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 3003 | }) |
| 3004 | testCases = append(testCases, testCase{ |
| 3005 | testType: clientTest, |
| 3006 | name: "ClientAuth-ECDHE_PSK", |
| 3007 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3008 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 3009 | CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 3010 | PreSharedKey: []byte("secret"), |
| 3011 | ClientAuth: RequireAnyClientCert, |
| 3012 | }, |
| 3013 | flags: []string{ |
| 3014 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3015 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3016 | "-psk", "secret", |
| 3017 | }, |
| 3018 | shouldFail: true, |
| 3019 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 3020 | }) |
David Benjamin | 2f8935d | 2016-07-13 19:47:39 -0400 | [diff] [blame] | 3021 | |
| 3022 | // Regression test for a bug where the client CA list, if explicitly |
| 3023 | // set to NULL, was mis-encoded. |
| 3024 | testCases = append(testCases, testCase{ |
| 3025 | testType: serverTest, |
| 3026 | name: "Null-Client-CA-List", |
| 3027 | config: Config{ |
| 3028 | MaxVersion: VersionTLS12, |
| 3029 | Certificates: []Certificate{rsaCertificate}, |
| 3030 | }, |
| 3031 | flags: []string{ |
| 3032 | "-require-any-client-certificate", |
| 3033 | "-use-null-client-ca-list", |
| 3034 | }, |
| 3035 | }) |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 3036 | } |
| 3037 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3038 | func addExtendedMasterSecretTests() { |
| 3039 | const expectEMSFlag = "-expect-extended-master-secret" |
| 3040 | |
| 3041 | for _, with := range []bool{false, true} { |
| 3042 | prefix := "No" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3043 | if with { |
| 3044 | prefix = "" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | for _, isClient := range []bool{false, true} { |
| 3048 | suffix := "-Server" |
| 3049 | testType := serverTest |
| 3050 | if isClient { |
| 3051 | suffix = "-Client" |
| 3052 | testType = clientTest |
| 3053 | } |
| 3054 | |
| 3055 | for _, ver := range tlsVersions { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3056 | // In TLS 1.3, the extension is irrelevant and |
| 3057 | // always reports as enabled. |
| 3058 | var flags []string |
| 3059 | if with || ver.version >= VersionTLS13 { |
| 3060 | flags = []string{expectEMSFlag} |
| 3061 | } |
| 3062 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3063 | test := testCase{ |
| 3064 | testType: testType, |
| 3065 | name: prefix + "ExtendedMasterSecret-" + ver.name + suffix, |
| 3066 | config: Config{ |
| 3067 | MinVersion: ver.version, |
| 3068 | MaxVersion: ver.version, |
| 3069 | Bugs: ProtocolBugs{ |
| 3070 | NoExtendedMasterSecret: !with, |
| 3071 | RequireExtendedMasterSecret: with, |
| 3072 | }, |
| 3073 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 3074 | flags: flags, |
| 3075 | shouldFail: ver.version == VersionSSL30 && with, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3076 | } |
| 3077 | if test.shouldFail { |
| 3078 | test.expectedLocalError = "extended master secret required but not supported by peer" |
| 3079 | } |
| 3080 | testCases = append(testCases, test) |
| 3081 | } |
| 3082 | } |
| 3083 | } |
| 3084 | |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 3085 | for _, isClient := range []bool{false, true} { |
| 3086 | for _, supportedInFirstConnection := range []bool{false, true} { |
| 3087 | for _, supportedInResumeConnection := range []bool{false, true} { |
| 3088 | boolToWord := func(b bool) string { |
| 3089 | if b { |
| 3090 | return "Yes" |
| 3091 | } |
| 3092 | return "No" |
| 3093 | } |
| 3094 | suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-" |
| 3095 | if isClient { |
| 3096 | suffix += "Client" |
| 3097 | } else { |
| 3098 | suffix += "Server" |
| 3099 | } |
| 3100 | |
| 3101 | supportedConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3102 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 3103 | Bugs: ProtocolBugs{ |
| 3104 | RequireExtendedMasterSecret: true, |
| 3105 | }, |
| 3106 | } |
| 3107 | |
| 3108 | noSupportConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3109 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 3110 | Bugs: ProtocolBugs{ |
| 3111 | NoExtendedMasterSecret: true, |
| 3112 | }, |
| 3113 | } |
| 3114 | |
| 3115 | test := testCase{ |
| 3116 | name: "ExtendedMasterSecret-" + suffix, |
| 3117 | resumeSession: true, |
| 3118 | } |
| 3119 | |
| 3120 | if !isClient { |
| 3121 | test.testType = serverTest |
| 3122 | } |
| 3123 | |
| 3124 | if supportedInFirstConnection { |
| 3125 | test.config = supportedConfig |
| 3126 | } else { |
| 3127 | test.config = noSupportConfig |
| 3128 | } |
| 3129 | |
| 3130 | if supportedInResumeConnection { |
| 3131 | test.resumeConfig = &supportedConfig |
| 3132 | } else { |
| 3133 | test.resumeConfig = &noSupportConfig |
| 3134 | } |
| 3135 | |
| 3136 | switch suffix { |
| 3137 | case "YesToYes-Client", "YesToYes-Server": |
| 3138 | // When a session is resumed, it should |
| 3139 | // still be aware that its master |
| 3140 | // secret was generated via EMS and |
| 3141 | // thus it's safe to use tls-unique. |
| 3142 | test.flags = []string{expectEMSFlag} |
| 3143 | case "NoToYes-Server": |
| 3144 | // If an original connection did not |
| 3145 | // contain EMS, but a resumption |
| 3146 | // handshake does, then a server should |
| 3147 | // not resume the session. |
| 3148 | test.expectResumeRejected = true |
| 3149 | case "YesToNo-Server": |
| 3150 | // Resuming an EMS session without the |
| 3151 | // EMS extension should cause the |
| 3152 | // server to abort the connection. |
| 3153 | test.shouldFail = true |
| 3154 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 3155 | case "NoToYes-Client": |
| 3156 | // A client should abort a connection |
| 3157 | // where the server resumed a non-EMS |
| 3158 | // session but echoed the EMS |
| 3159 | // extension. |
| 3160 | test.shouldFail = true |
| 3161 | test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:" |
| 3162 | case "YesToNo-Client": |
| 3163 | // A client should abort a connection |
| 3164 | // where the server didn't echo EMS |
| 3165 | // when the session used it. |
| 3166 | test.shouldFail = true |
| 3167 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 3168 | } |
| 3169 | |
| 3170 | testCases = append(testCases, test) |
| 3171 | } |
| 3172 | } |
| 3173 | } |
David Benjamin | 163c956 | 2016-08-29 23:14:17 -0400 | [diff] [blame] | 3174 | |
| 3175 | // Switching EMS on renegotiation is forbidden. |
| 3176 | testCases = append(testCases, testCase{ |
| 3177 | name: "ExtendedMasterSecret-Renego-NoEMS", |
| 3178 | config: Config{ |
| 3179 | MaxVersion: VersionTLS12, |
| 3180 | Bugs: ProtocolBugs{ |
| 3181 | NoExtendedMasterSecret: true, |
| 3182 | NoExtendedMasterSecretOnRenegotiation: true, |
| 3183 | }, |
| 3184 | }, |
| 3185 | renegotiate: 1, |
| 3186 | flags: []string{ |
| 3187 | "-renegotiate-freely", |
| 3188 | "-expect-total-renegotiations", "1", |
| 3189 | }, |
| 3190 | }) |
| 3191 | |
| 3192 | testCases = append(testCases, testCase{ |
| 3193 | name: "ExtendedMasterSecret-Renego-Upgrade", |
| 3194 | config: Config{ |
| 3195 | MaxVersion: VersionTLS12, |
| 3196 | Bugs: ProtocolBugs{ |
| 3197 | NoExtendedMasterSecret: true, |
| 3198 | }, |
| 3199 | }, |
| 3200 | renegotiate: 1, |
| 3201 | flags: []string{ |
| 3202 | "-renegotiate-freely", |
| 3203 | "-expect-total-renegotiations", "1", |
| 3204 | }, |
| 3205 | shouldFail: true, |
| 3206 | expectedError: ":RENEGOTIATION_EMS_MISMATCH:", |
| 3207 | }) |
| 3208 | |
| 3209 | testCases = append(testCases, testCase{ |
| 3210 | name: "ExtendedMasterSecret-Renego-Downgrade", |
| 3211 | config: Config{ |
| 3212 | MaxVersion: VersionTLS12, |
| 3213 | Bugs: ProtocolBugs{ |
| 3214 | NoExtendedMasterSecretOnRenegotiation: true, |
| 3215 | }, |
| 3216 | }, |
| 3217 | renegotiate: 1, |
| 3218 | flags: []string{ |
| 3219 | "-renegotiate-freely", |
| 3220 | "-expect-total-renegotiations", "1", |
| 3221 | }, |
| 3222 | shouldFail: true, |
| 3223 | expectedError: ":RENEGOTIATION_EMS_MISMATCH:", |
| 3224 | }) |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3225 | } |
| 3226 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3227 | type stateMachineTestConfig struct { |
| 3228 | protocol protocol |
| 3229 | async bool |
| 3230 | splitHandshake, packHandshakeFlight bool |
| 3231 | } |
| 3232 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 3233 | // Adds tests that try to cover the range of the handshake state machine, under |
| 3234 | // various conditions. Some of these are redundant with other tests, but they |
| 3235 | // only cover the synchronous case. |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3236 | func addAllStateMachineCoverageTests() { |
| 3237 | for _, async := range []bool{false, true} { |
| 3238 | for _, protocol := range []protocol{tls, dtls} { |
| 3239 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3240 | protocol: protocol, |
| 3241 | async: async, |
| 3242 | }) |
| 3243 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3244 | protocol: protocol, |
| 3245 | async: async, |
| 3246 | splitHandshake: true, |
| 3247 | }) |
| 3248 | if protocol == tls { |
| 3249 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3250 | protocol: protocol, |
| 3251 | async: async, |
| 3252 | packHandshakeFlight: true, |
| 3253 | }) |
| 3254 | } |
| 3255 | } |
| 3256 | } |
| 3257 | } |
| 3258 | |
| 3259 | func addStateMachineCoverageTests(config stateMachineTestConfig) { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3260 | var tests []testCase |
| 3261 | |
| 3262 | // Basic handshake, with resumption. Client and server, |
| 3263 | // session ID and session ticket. |
| 3264 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3265 | name: "Basic-Client", |
| 3266 | config: Config{ |
| 3267 | MaxVersion: VersionTLS12, |
| 3268 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3269 | resumeSession: true, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3270 | // Ensure session tickets are used, not session IDs. |
| 3271 | noSessionCache: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3272 | }) |
| 3273 | tests = append(tests, testCase{ |
| 3274 | name: "Basic-Client-RenewTicket", |
| 3275 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3276 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3277 | Bugs: ProtocolBugs{ |
| 3278 | RenewTicketOnResume: true, |
| 3279 | }, |
| 3280 | }, |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 3281 | flags: []string{"-expect-ticket-renewal"}, |
| 3282 | resumeSession: true, |
| 3283 | resumeRenewedSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3284 | }) |
| 3285 | tests = append(tests, testCase{ |
| 3286 | name: "Basic-Client-NoTicket", |
| 3287 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3288 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3289 | SessionTicketsDisabled: true, |
| 3290 | }, |
| 3291 | resumeSession: true, |
| 3292 | }) |
| 3293 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3294 | name: "Basic-Client-Implicit", |
| 3295 | config: Config{ |
| 3296 | MaxVersion: VersionTLS12, |
| 3297 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3298 | flags: []string{"-implicit-handshake"}, |
| 3299 | resumeSession: true, |
| 3300 | }) |
| 3301 | tests = append(tests, testCase{ |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3302 | testType: serverTest, |
| 3303 | name: "Basic-Server", |
| 3304 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3305 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3306 | Bugs: ProtocolBugs{ |
| 3307 | RequireSessionTickets: true, |
| 3308 | }, |
| 3309 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3310 | resumeSession: true, |
| 3311 | }) |
| 3312 | tests = append(tests, testCase{ |
| 3313 | testType: serverTest, |
| 3314 | name: "Basic-Server-NoTickets", |
| 3315 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3316 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3317 | SessionTicketsDisabled: true, |
| 3318 | }, |
| 3319 | resumeSession: true, |
| 3320 | }) |
| 3321 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3322 | testType: serverTest, |
| 3323 | name: "Basic-Server-Implicit", |
| 3324 | config: Config{ |
| 3325 | MaxVersion: VersionTLS12, |
| 3326 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3327 | flags: []string{"-implicit-handshake"}, |
| 3328 | resumeSession: true, |
| 3329 | }) |
| 3330 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3331 | testType: serverTest, |
| 3332 | name: "Basic-Server-EarlyCallback", |
| 3333 | config: Config{ |
| 3334 | MaxVersion: VersionTLS12, |
| 3335 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3336 | flags: []string{"-use-early-callback"}, |
| 3337 | resumeSession: true, |
| 3338 | }) |
| 3339 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3340 | // TLS 1.3 basic handshake shapes. |
David Benjamin | e73c7f4 | 2016-08-17 00:29:33 -0400 | [diff] [blame] | 3341 | if config.protocol == tls { |
| 3342 | tests = append(tests, testCase{ |
| 3343 | name: "TLS13-1RTT-Client", |
| 3344 | config: Config{ |
| 3345 | MaxVersion: VersionTLS13, |
| 3346 | MinVersion: VersionTLS13, |
| 3347 | }, |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 3348 | resumeSession: true, |
| 3349 | resumeRenewedSession: true, |
David Benjamin | e73c7f4 | 2016-08-17 00:29:33 -0400 | [diff] [blame] | 3350 | }) |
| 3351 | |
| 3352 | tests = append(tests, testCase{ |
| 3353 | testType: serverTest, |
| 3354 | name: "TLS13-1RTT-Server", |
| 3355 | config: Config{ |
| 3356 | MaxVersion: VersionTLS13, |
| 3357 | MinVersion: VersionTLS13, |
| 3358 | }, |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 3359 | resumeSession: true, |
| 3360 | resumeRenewedSession: true, |
David Benjamin | e73c7f4 | 2016-08-17 00:29:33 -0400 | [diff] [blame] | 3361 | }) |
| 3362 | |
| 3363 | tests = append(tests, testCase{ |
| 3364 | name: "TLS13-HelloRetryRequest-Client", |
| 3365 | config: Config{ |
| 3366 | MaxVersion: VersionTLS13, |
| 3367 | MinVersion: VersionTLS13, |
| 3368 | // P-384 requires a HelloRetryRequest against |
| 3369 | // BoringSSL's default configuration. Assert |
| 3370 | // that we do indeed test this with |
| 3371 | // ExpectMissingKeyShare. |
| 3372 | CurvePreferences: []CurveID{CurveP384}, |
| 3373 | Bugs: ProtocolBugs{ |
| 3374 | ExpectMissingKeyShare: true, |
| 3375 | }, |
| 3376 | }, |
| 3377 | // Cover HelloRetryRequest during an ECDHE-PSK resumption. |
| 3378 | resumeSession: true, |
| 3379 | }) |
| 3380 | |
| 3381 | tests = append(tests, testCase{ |
| 3382 | testType: serverTest, |
| 3383 | name: "TLS13-HelloRetryRequest-Server", |
| 3384 | config: Config{ |
| 3385 | MaxVersion: VersionTLS13, |
| 3386 | MinVersion: VersionTLS13, |
| 3387 | // Require a HelloRetryRequest for every curve. |
| 3388 | DefaultCurves: []CurveID{}, |
| 3389 | }, |
| 3390 | // Cover HelloRetryRequest during an ECDHE-PSK resumption. |
| 3391 | resumeSession: true, |
| 3392 | }) |
| 3393 | } |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3394 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3395 | // TLS client auth. |
| 3396 | tests = append(tests, testCase{ |
| 3397 | testType: clientTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3398 | name: "ClientAuth-NoCertificate-Client", |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3399 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3400 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3401 | ClientAuth: RequestClientCert, |
| 3402 | }, |
| 3403 | }) |
| 3404 | tests = append(tests, testCase{ |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3405 | testType: serverTest, |
| 3406 | name: "ClientAuth-NoCertificate-Server", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3407 | config: Config{ |
| 3408 | MaxVersion: VersionTLS12, |
| 3409 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3410 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3411 | flags: []string{"-verify-peer"}, |
| 3412 | }) |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3413 | if config.protocol == tls { |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3414 | tests = append(tests, testCase{ |
| 3415 | testType: clientTest, |
| 3416 | name: "ClientAuth-NoCertificate-Client-SSL3", |
| 3417 | config: Config{ |
| 3418 | MaxVersion: VersionSSL30, |
| 3419 | ClientAuth: RequestClientCert, |
| 3420 | }, |
| 3421 | }) |
| 3422 | tests = append(tests, testCase{ |
| 3423 | testType: serverTest, |
| 3424 | name: "ClientAuth-NoCertificate-Server-SSL3", |
| 3425 | config: Config{ |
| 3426 | MaxVersion: VersionSSL30, |
| 3427 | }, |
| 3428 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3429 | flags: []string{"-verify-peer"}, |
| 3430 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3431 | tests = append(tests, testCase{ |
| 3432 | testType: clientTest, |
| 3433 | name: "ClientAuth-NoCertificate-Client-TLS13", |
| 3434 | config: Config{ |
| 3435 | MaxVersion: VersionTLS13, |
| 3436 | ClientAuth: RequestClientCert, |
| 3437 | }, |
| 3438 | }) |
| 3439 | tests = append(tests, testCase{ |
| 3440 | testType: serverTest, |
| 3441 | name: "ClientAuth-NoCertificate-Server-TLS13", |
| 3442 | config: Config{ |
| 3443 | MaxVersion: VersionTLS13, |
| 3444 | }, |
| 3445 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3446 | flags: []string{"-verify-peer"}, |
| 3447 | }) |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3448 | } |
| 3449 | tests = append(tests, testCase{ |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3450 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3451 | name: "ClientAuth-RSA-Client", |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3452 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3453 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3454 | ClientAuth: RequireAnyClientCert, |
| 3455 | }, |
| 3456 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3457 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3458 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3459 | }, |
| 3460 | }) |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3461 | tests = append(tests, testCase{ |
| 3462 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3463 | name: "ClientAuth-RSA-Client-TLS13", |
| 3464 | config: Config{ |
| 3465 | MaxVersion: VersionTLS13, |
| 3466 | ClientAuth: RequireAnyClientCert, |
| 3467 | }, |
| 3468 | flags: []string{ |
| 3469 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3470 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3471 | }, |
| 3472 | }) |
| 3473 | tests = append(tests, testCase{ |
| 3474 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3475 | name: "ClientAuth-ECDSA-Client", |
| 3476 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3477 | MaxVersion: VersionTLS12, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3478 | ClientAuth: RequireAnyClientCert, |
| 3479 | }, |
| 3480 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3481 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3482 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3483 | }, |
| 3484 | }) |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3485 | tests = append(tests, testCase{ |
| 3486 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3487 | name: "ClientAuth-ECDSA-Client-TLS13", |
| 3488 | config: Config{ |
| 3489 | MaxVersion: VersionTLS13, |
| 3490 | ClientAuth: RequireAnyClientCert, |
| 3491 | }, |
| 3492 | flags: []string{ |
| 3493 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3494 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 3495 | }, |
| 3496 | }) |
| 3497 | tests = append(tests, testCase{ |
| 3498 | testType: clientTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3499 | name: "ClientAuth-NoCertificate-OldCallback", |
| 3500 | config: Config{ |
| 3501 | MaxVersion: VersionTLS12, |
| 3502 | ClientAuth: RequestClientCert, |
| 3503 | }, |
| 3504 | flags: []string{"-use-old-client-cert-callback"}, |
| 3505 | }) |
| 3506 | tests = append(tests, testCase{ |
| 3507 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3508 | name: "ClientAuth-NoCertificate-OldCallback-TLS13", |
| 3509 | config: Config{ |
| 3510 | MaxVersion: VersionTLS13, |
| 3511 | ClientAuth: RequestClientCert, |
| 3512 | }, |
| 3513 | flags: []string{"-use-old-client-cert-callback"}, |
| 3514 | }) |
| 3515 | tests = append(tests, testCase{ |
| 3516 | testType: clientTest, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3517 | name: "ClientAuth-OldCallback", |
| 3518 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3519 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3520 | ClientAuth: RequireAnyClientCert, |
| 3521 | }, |
| 3522 | flags: []string{ |
| 3523 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3524 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3525 | "-use-old-client-cert-callback", |
| 3526 | }, |
| 3527 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3528 | tests = append(tests, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3529 | testType: clientTest, |
| 3530 | name: "ClientAuth-OldCallback-TLS13", |
| 3531 | config: Config{ |
| 3532 | MaxVersion: VersionTLS13, |
| 3533 | ClientAuth: RequireAnyClientCert, |
| 3534 | }, |
| 3535 | flags: []string{ |
| 3536 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3537 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3538 | "-use-old-client-cert-callback", |
| 3539 | }, |
| 3540 | }) |
| 3541 | tests = append(tests, testCase{ |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3542 | testType: serverTest, |
| 3543 | name: "ClientAuth-Server", |
| 3544 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3545 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3546 | Certificates: []Certificate{rsaCertificate}, |
| 3547 | }, |
| 3548 | flags: []string{"-require-any-client-certificate"}, |
| 3549 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3550 | tests = append(tests, testCase{ |
| 3551 | testType: serverTest, |
| 3552 | name: "ClientAuth-Server-TLS13", |
| 3553 | config: Config{ |
| 3554 | MaxVersion: VersionTLS13, |
| 3555 | Certificates: []Certificate{rsaCertificate}, |
| 3556 | }, |
| 3557 | flags: []string{"-require-any-client-certificate"}, |
| 3558 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3559 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3560 | // Test each key exchange on the server side for async keys. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3561 | tests = append(tests, testCase{ |
| 3562 | testType: serverTest, |
| 3563 | name: "Basic-Server-RSA", |
| 3564 | config: Config{ |
| 3565 | MaxVersion: VersionTLS12, |
| 3566 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 3567 | }, |
| 3568 | flags: []string{ |
| 3569 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3570 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3571 | }, |
| 3572 | }) |
| 3573 | tests = append(tests, testCase{ |
| 3574 | testType: serverTest, |
| 3575 | name: "Basic-Server-ECDHE-RSA", |
| 3576 | config: Config{ |
| 3577 | MaxVersion: VersionTLS12, |
| 3578 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3579 | }, |
| 3580 | flags: []string{ |
| 3581 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3582 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3583 | }, |
| 3584 | }) |
| 3585 | tests = append(tests, testCase{ |
| 3586 | testType: serverTest, |
| 3587 | name: "Basic-Server-ECDHE-ECDSA", |
| 3588 | config: Config{ |
| 3589 | MaxVersion: VersionTLS12, |
| 3590 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 3591 | }, |
| 3592 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3593 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3594 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3595 | }, |
| 3596 | }) |
| 3597 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3598 | // No session ticket support; server doesn't send NewSessionTicket. |
| 3599 | tests = append(tests, testCase{ |
| 3600 | name: "SessionTicketsDisabled-Client", |
| 3601 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3602 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3603 | SessionTicketsDisabled: true, |
| 3604 | }, |
| 3605 | }) |
| 3606 | tests = append(tests, testCase{ |
| 3607 | testType: serverTest, |
| 3608 | name: "SessionTicketsDisabled-Server", |
| 3609 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3610 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3611 | SessionTicketsDisabled: true, |
| 3612 | }, |
| 3613 | }) |
| 3614 | |
| 3615 | // Skip ServerKeyExchange in PSK key exchange if there's no |
| 3616 | // identity hint. |
| 3617 | tests = append(tests, testCase{ |
| 3618 | name: "EmptyPSKHint-Client", |
| 3619 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3620 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3621 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3622 | PreSharedKey: []byte("secret"), |
| 3623 | }, |
| 3624 | flags: []string{"-psk", "secret"}, |
| 3625 | }) |
| 3626 | tests = append(tests, testCase{ |
| 3627 | testType: serverTest, |
| 3628 | name: "EmptyPSKHint-Server", |
| 3629 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3630 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3631 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3632 | PreSharedKey: []byte("secret"), |
| 3633 | }, |
| 3634 | flags: []string{"-psk", "secret"}, |
| 3635 | }) |
| 3636 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3637 | // OCSP stapling tests. |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3638 | tests = append(tests, testCase{ |
| 3639 | testType: clientTest, |
| 3640 | name: "OCSPStapling-Client", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3641 | config: Config{ |
| 3642 | MaxVersion: VersionTLS12, |
| 3643 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3644 | flags: []string{ |
| 3645 | "-enable-ocsp-stapling", |
| 3646 | "-expect-ocsp-response", |
| 3647 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3648 | "-verify-peer", |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3649 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3650 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3651 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3652 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3653 | testType: serverTest, |
| 3654 | name: "OCSPStapling-Server", |
| 3655 | config: Config{ |
| 3656 | MaxVersion: VersionTLS12, |
| 3657 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3658 | expectedOCSPResponse: testOCSPResponse, |
| 3659 | flags: []string{ |
| 3660 | "-ocsp-response", |
| 3661 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3662 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3663 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3664 | }) |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3665 | tests = append(tests, testCase{ |
| 3666 | testType: clientTest, |
| 3667 | name: "OCSPStapling-Client-TLS13", |
| 3668 | config: Config{ |
| 3669 | MaxVersion: VersionTLS13, |
| 3670 | }, |
| 3671 | flags: []string{ |
| 3672 | "-enable-ocsp-stapling", |
| 3673 | "-expect-ocsp-response", |
| 3674 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3675 | "-verify-peer", |
| 3676 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3677 | resumeSession: true, |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3678 | }) |
| 3679 | tests = append(tests, testCase{ |
| 3680 | testType: serverTest, |
| 3681 | name: "OCSPStapling-Server-TLS13", |
| 3682 | config: Config{ |
| 3683 | MaxVersion: VersionTLS13, |
| 3684 | }, |
| 3685 | expectedOCSPResponse: testOCSPResponse, |
| 3686 | flags: []string{ |
| 3687 | "-ocsp-response", |
| 3688 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3689 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3690 | resumeSession: true, |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3691 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3692 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3693 | // Certificate verification tests. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3694 | for _, vers := range tlsVersions { |
| 3695 | if config.protocol == dtls && !vers.hasDTLS { |
| 3696 | continue |
| 3697 | } |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3698 | for _, testType := range []testType{clientTest, serverTest} { |
| 3699 | suffix := "-Client" |
| 3700 | if testType == serverTest { |
| 3701 | suffix = "-Server" |
| 3702 | } |
| 3703 | suffix += "-" + vers.name |
| 3704 | |
| 3705 | flag := "-verify-peer" |
| 3706 | if testType == serverTest { |
| 3707 | flag = "-require-any-client-certificate" |
| 3708 | } |
| 3709 | |
| 3710 | tests = append(tests, testCase{ |
| 3711 | testType: testType, |
| 3712 | name: "CertificateVerificationSucceed" + suffix, |
| 3713 | config: Config{ |
| 3714 | MaxVersion: vers.version, |
| 3715 | Certificates: []Certificate{rsaCertificate}, |
| 3716 | }, |
| 3717 | flags: []string{ |
| 3718 | flag, |
| 3719 | "-expect-verify-result", |
| 3720 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3721 | resumeSession: true, |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3722 | }) |
| 3723 | tests = append(tests, testCase{ |
| 3724 | testType: testType, |
| 3725 | name: "CertificateVerificationFail" + suffix, |
| 3726 | config: Config{ |
| 3727 | MaxVersion: vers.version, |
| 3728 | Certificates: []Certificate{rsaCertificate}, |
| 3729 | }, |
| 3730 | flags: []string{ |
| 3731 | flag, |
| 3732 | "-verify-fail", |
| 3733 | }, |
| 3734 | shouldFail: true, |
| 3735 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 3736 | }) |
| 3737 | } |
| 3738 | |
| 3739 | // By default, the client is in a soft fail mode where the peer |
| 3740 | // certificate is verified but failures are non-fatal. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3741 | tests = append(tests, testCase{ |
| 3742 | testType: clientTest, |
| 3743 | name: "CertificateVerificationSoftFail-" + vers.name, |
| 3744 | config: Config{ |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3745 | MaxVersion: vers.version, |
| 3746 | Certificates: []Certificate{rsaCertificate}, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3747 | }, |
| 3748 | flags: []string{ |
| 3749 | "-verify-fail", |
| 3750 | "-expect-verify-result", |
| 3751 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3752 | resumeSession: true, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3753 | }) |
| 3754 | } |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3755 | |
David Benjamin | 1d4f4c0 | 2016-07-26 18:03:08 -0400 | [diff] [blame] | 3756 | tests = append(tests, testCase{ |
| 3757 | name: "ShimSendAlert", |
| 3758 | flags: []string{"-send-alert"}, |
| 3759 | shimWritesFirst: true, |
| 3760 | shouldFail: true, |
| 3761 | expectedLocalError: "remote error: decompression failure", |
| 3762 | }) |
| 3763 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3764 | if config.protocol == tls { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3765 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3766 | name: "Renegotiate-Client", |
| 3767 | config: Config{ |
| 3768 | MaxVersion: VersionTLS12, |
| 3769 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 3770 | renegotiate: 1, |
| 3771 | flags: []string{ |
| 3772 | "-renegotiate-freely", |
| 3773 | "-expect-total-renegotiations", "1", |
| 3774 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3775 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3776 | |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 3777 | tests = append(tests, testCase{ |
| 3778 | name: "SendHalfHelloRequest", |
| 3779 | config: Config{ |
| 3780 | MaxVersion: VersionTLS12, |
| 3781 | Bugs: ProtocolBugs{ |
| 3782 | PackHelloRequestWithFinished: config.packHandshakeFlight, |
| 3783 | }, |
| 3784 | }, |
| 3785 | sendHalfHelloRequest: true, |
| 3786 | flags: []string{"-renegotiate-ignore"}, |
| 3787 | shouldFail: true, |
| 3788 | expectedError: ":UNEXPECTED_RECORD:", |
| 3789 | }) |
| 3790 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3791 | // NPN on client and server; results in post-handshake message. |
| 3792 | tests = append(tests, testCase{ |
| 3793 | name: "NPN-Client", |
| 3794 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3795 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3796 | NextProtos: []string{"foo"}, |
| 3797 | }, |
| 3798 | flags: []string{"-select-next-proto", "foo"}, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3799 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3800 | expectedNextProto: "foo", |
| 3801 | expectedNextProtoType: npn, |
| 3802 | }) |
| 3803 | tests = append(tests, testCase{ |
| 3804 | testType: serverTest, |
| 3805 | name: "NPN-Server", |
| 3806 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3807 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3808 | NextProtos: []string{"bar"}, |
| 3809 | }, |
| 3810 | flags: []string{ |
| 3811 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3812 | "-expect-next-proto", "bar", |
| 3813 | }, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3814 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3815 | expectedNextProto: "bar", |
| 3816 | expectedNextProtoType: npn, |
| 3817 | }) |
| 3818 | |
| 3819 | // TODO(davidben): Add tests for when False Start doesn't trigger. |
| 3820 | |
| 3821 | // Client does False Start and negotiates NPN. |
| 3822 | tests = append(tests, testCase{ |
| 3823 | name: "FalseStart", |
| 3824 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3825 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3826 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3827 | NextProtos: []string{"foo"}, |
| 3828 | Bugs: ProtocolBugs{ |
| 3829 | ExpectFalseStart: true, |
| 3830 | }, |
| 3831 | }, |
| 3832 | flags: []string{ |
| 3833 | "-false-start", |
| 3834 | "-select-next-proto", "foo", |
| 3835 | }, |
| 3836 | shimWritesFirst: true, |
| 3837 | resumeSession: true, |
| 3838 | }) |
| 3839 | |
| 3840 | // Client does False Start and negotiates ALPN. |
| 3841 | tests = append(tests, testCase{ |
| 3842 | name: "FalseStart-ALPN", |
| 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 | "-advertise-alpn", "\x03foo", |
| 3854 | }, |
| 3855 | shimWritesFirst: true, |
| 3856 | resumeSession: true, |
| 3857 | }) |
| 3858 | |
| 3859 | // Client does False Start but doesn't explicitly call |
| 3860 | // SSL_connect. |
| 3861 | tests = append(tests, testCase{ |
| 3862 | name: "FalseStart-Implicit", |
| 3863 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3864 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3865 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3866 | NextProtos: []string{"foo"}, |
| 3867 | }, |
| 3868 | flags: []string{ |
| 3869 | "-implicit-handshake", |
| 3870 | "-false-start", |
| 3871 | "-advertise-alpn", "\x03foo", |
| 3872 | }, |
| 3873 | }) |
| 3874 | |
| 3875 | // False Start without session tickets. |
| 3876 | tests = append(tests, testCase{ |
| 3877 | name: "FalseStart-SessionTicketsDisabled", |
| 3878 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3879 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3880 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3881 | NextProtos: []string{"foo"}, |
| 3882 | SessionTicketsDisabled: true, |
| 3883 | Bugs: ProtocolBugs{ |
| 3884 | ExpectFalseStart: true, |
| 3885 | }, |
| 3886 | }, |
| 3887 | flags: []string{ |
| 3888 | "-false-start", |
| 3889 | "-select-next-proto", "foo", |
| 3890 | }, |
| 3891 | shimWritesFirst: true, |
| 3892 | }) |
| 3893 | |
Adam Langley | df759b5 | 2016-07-11 15:24:37 -0700 | [diff] [blame] | 3894 | tests = append(tests, testCase{ |
| 3895 | name: "FalseStart-CECPQ1", |
| 3896 | config: Config{ |
| 3897 | MaxVersion: VersionTLS12, |
| 3898 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 3899 | NextProtos: []string{"foo"}, |
| 3900 | Bugs: ProtocolBugs{ |
| 3901 | ExpectFalseStart: true, |
| 3902 | }, |
| 3903 | }, |
| 3904 | flags: []string{ |
| 3905 | "-false-start", |
| 3906 | "-cipher", "DEFAULT:kCECPQ1", |
| 3907 | "-select-next-proto", "foo", |
| 3908 | }, |
| 3909 | shimWritesFirst: true, |
| 3910 | resumeSession: true, |
| 3911 | }) |
| 3912 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3913 | // Server parses a V2ClientHello. |
| 3914 | tests = append(tests, testCase{ |
| 3915 | testType: serverTest, |
| 3916 | name: "SendV2ClientHello", |
| 3917 | config: Config{ |
| 3918 | // Choose a cipher suite that does not involve |
| 3919 | // elliptic curves, so no extensions are |
| 3920 | // involved. |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3921 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 3922 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3923 | Bugs: ProtocolBugs{ |
| 3924 | SendV2ClientHello: true, |
| 3925 | }, |
| 3926 | }, |
| 3927 | }) |
| 3928 | |
| 3929 | // Client sends a Channel ID. |
| 3930 | tests = append(tests, testCase{ |
| 3931 | name: "ChannelID-Client", |
| 3932 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3933 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3934 | RequestChannelID: true, |
| 3935 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3936 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3937 | resumeSession: true, |
| 3938 | expectChannelID: true, |
| 3939 | }) |
| 3940 | |
| 3941 | // Server accepts a Channel ID. |
| 3942 | tests = append(tests, testCase{ |
| 3943 | testType: serverTest, |
| 3944 | name: "ChannelID-Server", |
| 3945 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3946 | MaxVersion: VersionTLS12, |
| 3947 | ChannelID: channelIDKey, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3948 | }, |
| 3949 | flags: []string{ |
| 3950 | "-expect-channel-id", |
| 3951 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3952 | }, |
| 3953 | resumeSession: true, |
| 3954 | expectChannelID: true, |
| 3955 | }) |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3956 | |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3957 | // Channel ID and NPN at the same time, to ensure their relative |
| 3958 | // ordering is correct. |
| 3959 | tests = append(tests, testCase{ |
| 3960 | name: "ChannelID-NPN-Client", |
| 3961 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3962 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3963 | RequestChannelID: true, |
| 3964 | NextProtos: []string{"foo"}, |
| 3965 | }, |
| 3966 | flags: []string{ |
| 3967 | "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile), |
| 3968 | "-select-next-proto", "foo", |
| 3969 | }, |
| 3970 | resumeSession: true, |
| 3971 | expectChannelID: true, |
| 3972 | expectedNextProto: "foo", |
| 3973 | expectedNextProtoType: npn, |
| 3974 | }) |
| 3975 | tests = append(tests, testCase{ |
| 3976 | testType: serverTest, |
| 3977 | name: "ChannelID-NPN-Server", |
| 3978 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3979 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3980 | ChannelID: channelIDKey, |
| 3981 | NextProtos: []string{"bar"}, |
| 3982 | }, |
| 3983 | flags: []string{ |
| 3984 | "-expect-channel-id", |
| 3985 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3986 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3987 | "-expect-next-proto", "bar", |
| 3988 | }, |
| 3989 | resumeSession: true, |
| 3990 | expectChannelID: true, |
| 3991 | expectedNextProto: "bar", |
| 3992 | expectedNextProtoType: npn, |
| 3993 | }) |
| 3994 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3995 | // Bidirectional shutdown with the runner initiating. |
| 3996 | tests = append(tests, testCase{ |
| 3997 | name: "Shutdown-Runner", |
| 3998 | config: Config{ |
| 3999 | Bugs: ProtocolBugs{ |
| 4000 | ExpectCloseNotify: true, |
| 4001 | }, |
| 4002 | }, |
| 4003 | flags: []string{"-check-close-notify"}, |
| 4004 | }) |
| 4005 | |
| 4006 | // Bidirectional shutdown with the shim initiating. The runner, |
| 4007 | // in the meantime, sends garbage before the close_notify which |
| 4008 | // the shim must ignore. |
| 4009 | tests = append(tests, testCase{ |
| 4010 | name: "Shutdown-Shim", |
| 4011 | config: Config{ |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 4012 | MaxVersion: VersionTLS12, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 4013 | Bugs: ProtocolBugs{ |
| 4014 | ExpectCloseNotify: true, |
| 4015 | }, |
| 4016 | }, |
| 4017 | shimShutsDown: true, |
| 4018 | sendEmptyRecords: 1, |
| 4019 | sendWarningAlerts: 1, |
| 4020 | flags: []string{"-check-close-notify"}, |
| 4021 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 4022 | } else { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4023 | // TODO(davidben): DTLS 1.3 will want a similar thing for |
| 4024 | // HelloRetryRequest. |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 4025 | tests = append(tests, testCase{ |
| 4026 | name: "SkipHelloVerifyRequest", |
| 4027 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4028 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 4029 | Bugs: ProtocolBugs{ |
| 4030 | SkipHelloVerifyRequest: true, |
| 4031 | }, |
| 4032 | }, |
| 4033 | }) |
| 4034 | } |
| 4035 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 4036 | for _, test := range tests { |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 4037 | test.protocol = config.protocol |
| 4038 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 4039 | test.name += "-DTLS" |
| 4040 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 4041 | if config.async { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 4042 | test.name += "-Async" |
| 4043 | test.flags = append(test.flags, "-async") |
| 4044 | } else { |
| 4045 | test.name += "-Sync" |
| 4046 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 4047 | if config.splitHandshake { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 4048 | test.name += "-SplitHandshakeRecords" |
| 4049 | test.config.Bugs.MaxHandshakeRecordLength = 1 |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 4050 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 4051 | test.config.Bugs.MaxPacketLength = 256 |
| 4052 | test.flags = append(test.flags, "-mtu", "256") |
| 4053 | } |
| 4054 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 4055 | if config.packHandshakeFlight { |
| 4056 | test.name += "-PackHandshakeFlight" |
| 4057 | test.config.Bugs.PackHandshakeFlight = true |
| 4058 | } |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 4059 | testCases = append(testCases, test) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 4060 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 4061 | } |
| 4062 | |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4063 | func addDDoSCallbackTests() { |
| 4064 | // DDoS callback. |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4065 | for _, resume := range []bool{false, true} { |
| 4066 | suffix := "Resume" |
| 4067 | if resume { |
| 4068 | suffix = "No" + suffix |
| 4069 | } |
| 4070 | |
| 4071 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4072 | testType: serverTest, |
| 4073 | name: "Server-DDoS-OK-" + suffix, |
| 4074 | config: Config{ |
| 4075 | MaxVersion: VersionTLS12, |
| 4076 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4077 | flags: []string{"-install-ddos-callback"}, |
| 4078 | resumeSession: resume, |
| 4079 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4080 | testCases = append(testCases, testCase{ |
| 4081 | testType: serverTest, |
| 4082 | name: "Server-DDoS-OK-" + suffix + "-TLS13", |
| 4083 | config: Config{ |
| 4084 | MaxVersion: VersionTLS13, |
| 4085 | }, |
| 4086 | flags: []string{"-install-ddos-callback"}, |
| 4087 | resumeSession: resume, |
| 4088 | }) |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4089 | |
| 4090 | failFlag := "-fail-ddos-callback" |
| 4091 | if resume { |
| 4092 | failFlag = "-fail-second-ddos-callback" |
| 4093 | } |
| 4094 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4095 | testType: serverTest, |
| 4096 | name: "Server-DDoS-Reject-" + suffix, |
| 4097 | config: Config{ |
| 4098 | MaxVersion: VersionTLS12, |
| 4099 | }, |
David Benjamin | 2c66e07 | 2016-09-16 15:58:00 -0400 | [diff] [blame] | 4100 | flags: []string{"-install-ddos-callback", failFlag}, |
| 4101 | resumeSession: resume, |
| 4102 | shouldFail: true, |
| 4103 | expectedError: ":CONNECTION_REJECTED:", |
| 4104 | expectedLocalError: "remote error: internal error", |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4105 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4106 | testCases = append(testCases, testCase{ |
| 4107 | testType: serverTest, |
| 4108 | name: "Server-DDoS-Reject-" + suffix + "-TLS13", |
| 4109 | config: Config{ |
| 4110 | MaxVersion: VersionTLS13, |
| 4111 | }, |
David Benjamin | 2c66e07 | 2016-09-16 15:58:00 -0400 | [diff] [blame] | 4112 | flags: []string{"-install-ddos-callback", failFlag}, |
| 4113 | resumeSession: resume, |
| 4114 | shouldFail: true, |
| 4115 | expectedError: ":CONNECTION_REJECTED:", |
| 4116 | expectedLocalError: "remote error: internal error", |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4117 | }) |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 4118 | } |
| 4119 | } |
| 4120 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4121 | func addVersionNegotiationTests() { |
| 4122 | for i, shimVers := range tlsVersions { |
| 4123 | // Assemble flags to disable all newer versions on the shim. |
| 4124 | var flags []string |
| 4125 | for _, vers := range tlsVersions[i+1:] { |
| 4126 | flags = append(flags, vers.flag) |
| 4127 | } |
| 4128 | |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4129 | // Test configuring the runner's maximum version. |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4130 | for _, runnerVers := range tlsVersions { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4131 | protocols := []protocol{tls} |
| 4132 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 4133 | protocols = append(protocols, dtls) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4134 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4135 | for _, protocol := range protocols { |
| 4136 | expectedVersion := shimVers.version |
| 4137 | if runnerVers.version < shimVers.version { |
| 4138 | expectedVersion = runnerVers.version |
| 4139 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4140 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4141 | suffix := shimVers.name + "-" + runnerVers.name |
| 4142 | if protocol == dtls { |
| 4143 | suffix += "-DTLS" |
| 4144 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4145 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 4146 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 4147 | |
David Benjamin | b1dd8cd | 2016-09-26 19:20:48 -0400 | [diff] [blame] | 4148 | // Determine the expected initial record-layer versions. |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 4149 | clientVers := shimVers.version |
| 4150 | if clientVers > VersionTLS10 { |
| 4151 | clientVers = VersionTLS10 |
| 4152 | } |
David Benjamin | b1dd8cd | 2016-09-26 19:20:48 -0400 | [diff] [blame] | 4153 | clientVers = versionToWire(clientVers, protocol == dtls) |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4154 | serverVers := expectedVersion |
| 4155 | if expectedVersion >= VersionTLS13 { |
| 4156 | serverVers = VersionTLS10 |
| 4157 | } |
David Benjamin | b1dd8cd | 2016-09-26 19:20:48 -0400 | [diff] [blame] | 4158 | serverVers = versionToWire(serverVers, protocol == dtls) |
| 4159 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4160 | testCases = append(testCases, testCase{ |
| 4161 | protocol: protocol, |
| 4162 | testType: clientTest, |
| 4163 | name: "VersionNegotiation-Client-" + suffix, |
| 4164 | config: Config{ |
| 4165 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 4166 | Bugs: ProtocolBugs{ |
| 4167 | ExpectInitialRecordVersion: clientVers, |
| 4168 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4169 | }, |
| 4170 | flags: flags, |
| 4171 | expectedVersion: expectedVersion, |
| 4172 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 4173 | testCases = append(testCases, testCase{ |
| 4174 | protocol: protocol, |
| 4175 | testType: clientTest, |
| 4176 | name: "VersionNegotiation-Client2-" + suffix, |
| 4177 | config: Config{ |
| 4178 | MaxVersion: runnerVers.version, |
| 4179 | Bugs: ProtocolBugs{ |
| 4180 | ExpectInitialRecordVersion: clientVers, |
| 4181 | }, |
| 4182 | }, |
| 4183 | flags: []string{"-max-version", shimVersFlag}, |
| 4184 | expectedVersion: expectedVersion, |
| 4185 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4186 | |
| 4187 | testCases = append(testCases, testCase{ |
| 4188 | protocol: protocol, |
| 4189 | testType: serverTest, |
| 4190 | name: "VersionNegotiation-Server-" + suffix, |
| 4191 | config: Config{ |
| 4192 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 4193 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4194 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 4195 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4196 | }, |
| 4197 | flags: flags, |
| 4198 | expectedVersion: expectedVersion, |
| 4199 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 4200 | testCases = append(testCases, testCase{ |
| 4201 | protocol: protocol, |
| 4202 | testType: serverTest, |
| 4203 | name: "VersionNegotiation-Server2-" + suffix, |
| 4204 | config: Config{ |
| 4205 | MaxVersion: runnerVers.version, |
| 4206 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4207 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 4208 | }, |
| 4209 | }, |
| 4210 | flags: []string{"-max-version", shimVersFlag}, |
| 4211 | expectedVersion: expectedVersion, |
| 4212 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4213 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4214 | } |
| 4215 | } |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4216 | |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4217 | // Test the version extension at all versions. |
| 4218 | for _, vers := range tlsVersions { |
| 4219 | protocols := []protocol{tls} |
| 4220 | if vers.hasDTLS { |
| 4221 | protocols = append(protocols, dtls) |
| 4222 | } |
| 4223 | for _, protocol := range protocols { |
| 4224 | suffix := vers.name |
| 4225 | if protocol == dtls { |
| 4226 | suffix += "-DTLS" |
| 4227 | } |
| 4228 | |
| 4229 | wireVersion := versionToWire(vers.version, protocol == dtls) |
| 4230 | testCases = append(testCases, testCase{ |
| 4231 | protocol: protocol, |
| 4232 | testType: serverTest, |
| 4233 | name: "VersionNegotiationExtension-" + suffix, |
| 4234 | config: Config{ |
| 4235 | Bugs: ProtocolBugs{ |
| 4236 | SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222}, |
| 4237 | }, |
| 4238 | }, |
| 4239 | expectedVersion: vers.version, |
| 4240 | }) |
| 4241 | } |
| 4242 | |
| 4243 | } |
| 4244 | |
| 4245 | // If all versions are unknown, negotiation fails. |
| 4246 | testCases = append(testCases, testCase{ |
| 4247 | testType: serverTest, |
| 4248 | name: "NoSupportedVersions", |
| 4249 | config: Config{ |
| 4250 | Bugs: ProtocolBugs{ |
| 4251 | SendSupportedVersions: []uint16{0x1111}, |
| 4252 | }, |
| 4253 | }, |
| 4254 | shouldFail: true, |
| 4255 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4256 | }) |
| 4257 | testCases = append(testCases, testCase{ |
| 4258 | protocol: dtls, |
| 4259 | testType: serverTest, |
| 4260 | name: "NoSupportedVersions-DTLS", |
| 4261 | config: Config{ |
| 4262 | Bugs: ProtocolBugs{ |
| 4263 | SendSupportedVersions: []uint16{0x1111}, |
| 4264 | }, |
| 4265 | }, |
| 4266 | shouldFail: true, |
| 4267 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4268 | }) |
| 4269 | |
| 4270 | testCases = append(testCases, testCase{ |
| 4271 | testType: serverTest, |
| 4272 | name: "ClientHelloVersionTooHigh", |
| 4273 | config: Config{ |
| 4274 | MaxVersion: VersionTLS13, |
| 4275 | Bugs: ProtocolBugs{ |
| 4276 | SendClientVersion: 0x0304, |
| 4277 | OmitSupportedVersions: true, |
| 4278 | }, |
| 4279 | }, |
| 4280 | expectedVersion: VersionTLS12, |
| 4281 | }) |
| 4282 | |
| 4283 | testCases = append(testCases, testCase{ |
| 4284 | testType: serverTest, |
| 4285 | name: "ConflictingVersionNegotiation", |
| 4286 | config: Config{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4287 | Bugs: ProtocolBugs{ |
David Benjamin | ad75a66 | 2016-09-30 15:42:59 -0400 | [diff] [blame^] | 4288 | SendClientVersion: VersionTLS12, |
| 4289 | SendSupportedVersions: []uint16{VersionTLS11}, |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4290 | }, |
| 4291 | }, |
David Benjamin | ad75a66 | 2016-09-30 15:42:59 -0400 | [diff] [blame^] | 4292 | // The extension takes precedence over the ClientHello version. |
| 4293 | expectedVersion: VersionTLS11, |
| 4294 | }) |
| 4295 | |
| 4296 | testCases = append(testCases, testCase{ |
| 4297 | testType: serverTest, |
| 4298 | name: "ConflictingVersionNegotiation-2", |
| 4299 | config: Config{ |
| 4300 | Bugs: ProtocolBugs{ |
| 4301 | SendClientVersion: VersionTLS11, |
| 4302 | SendSupportedVersions: []uint16{VersionTLS12}, |
| 4303 | }, |
| 4304 | }, |
| 4305 | // The extension takes precedence over the ClientHello version. |
| 4306 | expectedVersion: VersionTLS12, |
| 4307 | }) |
| 4308 | |
| 4309 | testCases = append(testCases, testCase{ |
| 4310 | testType: serverTest, |
| 4311 | name: "RejectFinalTLS13", |
| 4312 | config: Config{ |
| 4313 | Bugs: ProtocolBugs{ |
| 4314 | SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12}, |
| 4315 | }, |
| 4316 | }, |
| 4317 | // We currently implement a draft TLS 1.3 version. Ensure that |
| 4318 | // the true TLS 1.3 value is ignored for now. |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4319 | expectedVersion: VersionTLS12, |
| 4320 | }) |
| 4321 | |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4322 | // Test for version tolerance. |
| 4323 | testCases = append(testCases, testCase{ |
| 4324 | testType: serverTest, |
| 4325 | name: "MinorVersionTolerance", |
| 4326 | config: Config{ |
| 4327 | Bugs: ProtocolBugs{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4328 | SendClientVersion: 0x03ff, |
| 4329 | OmitSupportedVersions: true, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4330 | }, |
| 4331 | }, |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4332 | expectedVersion: VersionTLS12, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4333 | }) |
| 4334 | testCases = append(testCases, testCase{ |
| 4335 | testType: serverTest, |
| 4336 | name: "MajorVersionTolerance", |
| 4337 | config: Config{ |
| 4338 | Bugs: ProtocolBugs{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4339 | SendClientVersion: 0x0400, |
| 4340 | OmitSupportedVersions: true, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4341 | }, |
| 4342 | }, |
David Benjamin | ad75a66 | 2016-09-30 15:42:59 -0400 | [diff] [blame^] | 4343 | // TLS 1.3 must be negotiated with the supported_versions |
| 4344 | // extension, not ClientHello.version. |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4345 | expectedVersion: VersionTLS12, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4346 | }) |
David Benjamin | ad75a66 | 2016-09-30 15:42:59 -0400 | [diff] [blame^] | 4347 | testCases = append(testCases, testCase{ |
| 4348 | testType: serverTest, |
| 4349 | name: "VersionTolerance-TLS13", |
| 4350 | config: Config{ |
| 4351 | Bugs: ProtocolBugs{ |
| 4352 | // Although TLS 1.3 does not use |
| 4353 | // ClientHello.version, it still tolerates high |
| 4354 | // values there. |
| 4355 | SendClientVersion: 0x0400, |
| 4356 | }, |
| 4357 | }, |
| 4358 | expectedVersion: VersionTLS13, |
| 4359 | }) |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4360 | |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4361 | testCases = append(testCases, testCase{ |
| 4362 | protocol: dtls, |
| 4363 | testType: serverTest, |
| 4364 | name: "MinorVersionTolerance-DTLS", |
| 4365 | config: Config{ |
| 4366 | Bugs: ProtocolBugs{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4367 | SendClientVersion: 0xfe00, |
| 4368 | OmitSupportedVersions: true, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4369 | }, |
| 4370 | }, |
| 4371 | expectedVersion: VersionTLS12, |
| 4372 | }) |
| 4373 | testCases = append(testCases, testCase{ |
| 4374 | protocol: dtls, |
| 4375 | testType: serverTest, |
| 4376 | name: "MajorVersionTolerance-DTLS", |
| 4377 | config: Config{ |
| 4378 | Bugs: ProtocolBugs{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4379 | SendClientVersion: 0xfdff, |
| 4380 | OmitSupportedVersions: true, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4381 | }, |
| 4382 | }, |
| 4383 | expectedVersion: VersionTLS12, |
| 4384 | }) |
| 4385 | |
| 4386 | // Test that versions below 3.0 are rejected. |
| 4387 | testCases = append(testCases, testCase{ |
| 4388 | testType: serverTest, |
| 4389 | name: "VersionTooLow", |
| 4390 | config: Config{ |
| 4391 | Bugs: ProtocolBugs{ |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4392 | SendClientVersion: 0x0200, |
| 4393 | OmitSupportedVersions: true, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4394 | }, |
| 4395 | }, |
| 4396 | shouldFail: true, |
| 4397 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4398 | }) |
| 4399 | testCases = append(testCases, testCase{ |
| 4400 | protocol: dtls, |
| 4401 | testType: serverTest, |
| 4402 | name: "VersionTooLow-DTLS", |
| 4403 | config: Config{ |
| 4404 | Bugs: ProtocolBugs{ |
David Benjamin | 3c6a1ea | 2016-09-26 18:30:05 -0400 | [diff] [blame] | 4405 | SendClientVersion: 0xffff, |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 4406 | }, |
| 4407 | }, |
| 4408 | shouldFail: true, |
| 4409 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4410 | }) |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4411 | |
David Benjamin | 2dc0204 | 2016-09-19 19:57:37 -0400 | [diff] [blame] | 4412 | testCases = append(testCases, testCase{ |
| 4413 | name: "ServerBogusVersion", |
| 4414 | config: Config{ |
| 4415 | Bugs: ProtocolBugs{ |
| 4416 | SendServerHelloVersion: 0x1234, |
| 4417 | }, |
| 4418 | }, |
| 4419 | shouldFail: true, |
| 4420 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4421 | }) |
| 4422 | |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4423 | // Test TLS 1.3's downgrade signal. |
| 4424 | testCases = append(testCases, testCase{ |
| 4425 | name: "Downgrade-TLS12-Client", |
| 4426 | config: Config{ |
| 4427 | Bugs: ProtocolBugs{ |
| 4428 | NegotiateVersion: VersionTLS12, |
| 4429 | }, |
| 4430 | }, |
David Benjamin | 592b532 | 2016-09-30 15:15:01 -0400 | [diff] [blame] | 4431 | expectedVersion: VersionTLS12, |
David Benjamin | 5510863 | 2016-08-11 22:01:18 -0400 | [diff] [blame] | 4432 | // TODO(davidben): This test should fail once TLS 1.3 is final |
| 4433 | // and the fallback signal restored. |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4434 | }) |
| 4435 | testCases = append(testCases, testCase{ |
| 4436 | testType: serverTest, |
| 4437 | name: "Downgrade-TLS12-Server", |
| 4438 | config: Config{ |
| 4439 | Bugs: ProtocolBugs{ |
David Benjamin | 592b532 | 2016-09-30 15:15:01 -0400 | [diff] [blame] | 4440 | SendSupportedVersions: []uint16{VersionTLS12}, |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4441 | }, |
| 4442 | }, |
David Benjamin | 592b532 | 2016-09-30 15:15:01 -0400 | [diff] [blame] | 4443 | expectedVersion: VersionTLS12, |
David Benjamin | 5510863 | 2016-08-11 22:01:18 -0400 | [diff] [blame] | 4444 | // TODO(davidben): This test should fail once TLS 1.3 is final |
| 4445 | // and the fallback signal restored. |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4446 | }) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4447 | } |
| 4448 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4449 | func addMinimumVersionTests() { |
| 4450 | for i, shimVers := range tlsVersions { |
| 4451 | // Assemble flags to disable all older versions on the shim. |
| 4452 | var flags []string |
| 4453 | for _, vers := range tlsVersions[:i] { |
| 4454 | flags = append(flags, vers.flag) |
| 4455 | } |
| 4456 | |
| 4457 | for _, runnerVers := range tlsVersions { |
| 4458 | protocols := []protocol{tls} |
| 4459 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 4460 | protocols = append(protocols, dtls) |
| 4461 | } |
| 4462 | for _, protocol := range protocols { |
| 4463 | suffix := shimVers.name + "-" + runnerVers.name |
| 4464 | if protocol == dtls { |
| 4465 | suffix += "-DTLS" |
| 4466 | } |
| 4467 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 4468 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4469 | var expectedVersion uint16 |
| 4470 | var shouldFail bool |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4471 | var expectedClientError, expectedServerError string |
| 4472 | var expectedClientLocalError, expectedServerLocalError string |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4473 | if runnerVers.version >= shimVers.version { |
| 4474 | expectedVersion = runnerVers.version |
| 4475 | } else { |
| 4476 | shouldFail = true |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4477 | expectedServerError = ":UNSUPPORTED_PROTOCOL:" |
| 4478 | expectedServerLocalError = "remote error: protocol version not supported" |
| 4479 | if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 { |
| 4480 | // If the client's minimum version is TLS 1.3 and the runner's |
| 4481 | // maximum is below TLS 1.2, the runner will fail to select a |
| 4482 | // cipher before the shim rejects the selected version. |
| 4483 | expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:" |
| 4484 | expectedClientLocalError = "tls: no cipher suite supported by both client and server" |
| 4485 | } else { |
| 4486 | expectedClientError = expectedServerError |
| 4487 | expectedClientLocalError = expectedServerLocalError |
| 4488 | } |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4489 | } |
| 4490 | |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4491 | // Test the client enforces minimum |
| 4492 | // versions. Use the NegotiateVersion bug to |
| 4493 | // ensure the server does not decline to select |
| 4494 | // a version first. This may occur if the |
| 4495 | // versions extension is used. |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4496 | testCases = append(testCases, testCase{ |
| 4497 | protocol: protocol, |
| 4498 | testType: clientTest, |
| 4499 | name: "MinimumVersion-Client-" + suffix, |
| 4500 | config: Config{ |
| 4501 | MaxVersion: runnerVers.version, |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4502 | Bugs: ProtocolBugs{ |
| 4503 | NegotiateVersion: runnerVers.version, |
| 4504 | }, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4505 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4506 | flags: flags, |
| 4507 | expectedVersion: expectedVersion, |
| 4508 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4509 | expectedError: expectedClientError, |
| 4510 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4511 | }) |
| 4512 | testCases = append(testCases, testCase{ |
| 4513 | protocol: protocol, |
| 4514 | testType: clientTest, |
| 4515 | name: "MinimumVersion-Client2-" + suffix, |
| 4516 | config: Config{ |
| 4517 | MaxVersion: runnerVers.version, |
Steven Valdez | fdd1099 | 2016-09-15 16:27:05 -0400 | [diff] [blame] | 4518 | Bugs: ProtocolBugs{ |
| 4519 | NegotiateVersion: runnerVers.version, |
| 4520 | }, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4521 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4522 | flags: []string{"-min-version", shimVersFlag}, |
| 4523 | expectedVersion: expectedVersion, |
| 4524 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4525 | expectedError: expectedClientError, |
| 4526 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4527 | }) |
| 4528 | |
| 4529 | testCases = append(testCases, testCase{ |
| 4530 | protocol: protocol, |
| 4531 | testType: serverTest, |
| 4532 | name: "MinimumVersion-Server-" + suffix, |
| 4533 | config: Config{ |
| 4534 | MaxVersion: runnerVers.version, |
| 4535 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4536 | flags: flags, |
| 4537 | expectedVersion: expectedVersion, |
| 4538 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4539 | expectedError: expectedServerError, |
| 4540 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4541 | }) |
| 4542 | testCases = append(testCases, testCase{ |
| 4543 | protocol: protocol, |
| 4544 | testType: serverTest, |
| 4545 | name: "MinimumVersion-Server2-" + suffix, |
| 4546 | config: Config{ |
| 4547 | MaxVersion: runnerVers.version, |
| 4548 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4549 | flags: []string{"-min-version", shimVersFlag}, |
| 4550 | expectedVersion: expectedVersion, |
| 4551 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4552 | expectedError: expectedServerError, |
| 4553 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4554 | }) |
| 4555 | } |
| 4556 | } |
| 4557 | } |
| 4558 | } |
| 4559 | |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4560 | func addExtensionTests() { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4561 | // TODO(davidben): Extensions, where applicable, all move their server |
| 4562 | // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these |
| 4563 | // tests for both. Also test interaction with 0-RTT when implemented. |
| 4564 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4565 | // Repeat extensions tests all versions except SSL 3.0. |
| 4566 | for _, ver := range tlsVersions { |
| 4567 | if ver.version == VersionSSL30 { |
| 4568 | continue |
| 4569 | } |
| 4570 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4571 | // Test that duplicate extensions are rejected. |
| 4572 | testCases = append(testCases, testCase{ |
| 4573 | testType: clientTest, |
| 4574 | name: "DuplicateExtensionClient-" + ver.name, |
| 4575 | config: Config{ |
| 4576 | MaxVersion: ver.version, |
| 4577 | Bugs: ProtocolBugs{ |
| 4578 | DuplicateExtension: true, |
| 4579 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4580 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4581 | shouldFail: true, |
| 4582 | expectedLocalError: "remote error: error decoding message", |
| 4583 | }) |
| 4584 | testCases = append(testCases, testCase{ |
| 4585 | testType: serverTest, |
| 4586 | name: "DuplicateExtensionServer-" + ver.name, |
| 4587 | config: Config{ |
| 4588 | MaxVersion: ver.version, |
| 4589 | Bugs: ProtocolBugs{ |
| 4590 | DuplicateExtension: true, |
| 4591 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4592 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4593 | shouldFail: true, |
| 4594 | expectedLocalError: "remote error: error decoding message", |
| 4595 | }) |
| 4596 | |
| 4597 | // Test SNI. |
| 4598 | testCases = append(testCases, testCase{ |
| 4599 | testType: clientTest, |
| 4600 | name: "ServerNameExtensionClient-" + ver.name, |
| 4601 | config: Config{ |
| 4602 | MaxVersion: ver.version, |
| 4603 | Bugs: ProtocolBugs{ |
| 4604 | ExpectServerName: "example.com", |
| 4605 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4606 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4607 | flags: []string{"-host-name", "example.com"}, |
| 4608 | }) |
| 4609 | testCases = append(testCases, testCase{ |
| 4610 | testType: clientTest, |
| 4611 | name: "ServerNameExtensionClientMismatch-" + ver.name, |
| 4612 | config: Config{ |
| 4613 | MaxVersion: ver.version, |
| 4614 | Bugs: ProtocolBugs{ |
| 4615 | ExpectServerName: "mismatch.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 | shouldFail: true, |
| 4620 | expectedLocalError: "tls: unexpected server name", |
| 4621 | }) |
| 4622 | testCases = append(testCases, testCase{ |
| 4623 | testType: clientTest, |
| 4624 | name: "ServerNameExtensionClientMissing-" + ver.name, |
| 4625 | config: Config{ |
| 4626 | MaxVersion: ver.version, |
| 4627 | Bugs: ProtocolBugs{ |
| 4628 | ExpectServerName: "missing.com", |
| 4629 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4630 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4631 | shouldFail: true, |
| 4632 | expectedLocalError: "tls: unexpected server name", |
| 4633 | }) |
| 4634 | testCases = append(testCases, testCase{ |
| 4635 | testType: serverTest, |
| 4636 | name: "ServerNameExtensionServer-" + ver.name, |
| 4637 | config: Config{ |
| 4638 | MaxVersion: ver.version, |
| 4639 | ServerName: "example.com", |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 4640 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4641 | flags: []string{"-expect-server-name", "example.com"}, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4642 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4643 | }) |
| 4644 | |
| 4645 | // Test ALPN. |
| 4646 | testCases = append(testCases, testCase{ |
| 4647 | testType: clientTest, |
| 4648 | name: "ALPNClient-" + ver.name, |
| 4649 | config: Config{ |
| 4650 | MaxVersion: ver.version, |
| 4651 | NextProtos: []string{"foo"}, |
| 4652 | }, |
| 4653 | flags: []string{ |
| 4654 | "-advertise-alpn", "\x03foo\x03bar\x03baz", |
| 4655 | "-expect-alpn", "foo", |
| 4656 | }, |
| 4657 | expectedNextProto: "foo", |
| 4658 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4659 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4660 | }) |
| 4661 | testCases = append(testCases, testCase{ |
David Benjamin | 3e51757 | 2016-08-11 11:52:23 -0400 | [diff] [blame] | 4662 | testType: clientTest, |
| 4663 | name: "ALPNClient-Mismatch-" + ver.name, |
| 4664 | config: Config{ |
| 4665 | MaxVersion: ver.version, |
| 4666 | Bugs: ProtocolBugs{ |
| 4667 | SendALPN: "baz", |
| 4668 | }, |
| 4669 | }, |
| 4670 | flags: []string{ |
| 4671 | "-advertise-alpn", "\x03foo\x03bar", |
| 4672 | }, |
| 4673 | shouldFail: true, |
| 4674 | expectedError: ":INVALID_ALPN_PROTOCOL:", |
| 4675 | expectedLocalError: "remote error: illegal parameter", |
| 4676 | }) |
| 4677 | testCases = append(testCases, testCase{ |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4678 | testType: serverTest, |
| 4679 | name: "ALPNServer-" + ver.name, |
| 4680 | config: Config{ |
| 4681 | MaxVersion: ver.version, |
| 4682 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4683 | }, |
| 4684 | flags: []string{ |
| 4685 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4686 | "-select-alpn", "foo", |
| 4687 | }, |
| 4688 | expectedNextProto: "foo", |
| 4689 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4690 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4691 | }) |
| 4692 | testCases = append(testCases, testCase{ |
| 4693 | testType: serverTest, |
| 4694 | name: "ALPNServer-Decline-" + ver.name, |
| 4695 | config: Config{ |
| 4696 | MaxVersion: ver.version, |
| 4697 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4698 | }, |
| 4699 | flags: []string{"-decline-alpn"}, |
| 4700 | expectNoNextProto: true, |
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 | |
David Benjamin | 25fe85b | 2016-08-09 20:00:32 -0400 | [diff] [blame] | 4704 | // Test ALPN in async mode as well to ensure that extensions callbacks are only |
| 4705 | // called once. |
| 4706 | testCases = append(testCases, testCase{ |
| 4707 | testType: serverTest, |
| 4708 | name: "ALPNServer-Async-" + ver.name, |
| 4709 | config: Config{ |
| 4710 | MaxVersion: ver.version, |
| 4711 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4712 | }, |
| 4713 | flags: []string{ |
| 4714 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4715 | "-select-alpn", "foo", |
| 4716 | "-async", |
| 4717 | }, |
| 4718 | expectedNextProto: "foo", |
| 4719 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4720 | resumeSession: true, |
David Benjamin | 25fe85b | 2016-08-09 20:00:32 -0400 | [diff] [blame] | 4721 | }) |
| 4722 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4723 | var emptyString string |
| 4724 | testCases = append(testCases, testCase{ |
| 4725 | testType: clientTest, |
| 4726 | name: "ALPNClient-EmptyProtocolName-" + ver.name, |
| 4727 | config: Config{ |
| 4728 | MaxVersion: ver.version, |
| 4729 | NextProtos: []string{""}, |
| 4730 | Bugs: ProtocolBugs{ |
| 4731 | // A server returning an empty ALPN protocol |
| 4732 | // should be rejected. |
| 4733 | ALPNProtocol: &emptyString, |
| 4734 | }, |
| 4735 | }, |
| 4736 | flags: []string{ |
| 4737 | "-advertise-alpn", "\x03foo", |
| 4738 | }, |
| 4739 | shouldFail: true, |
| 4740 | expectedError: ":PARSE_TLSEXT:", |
| 4741 | }) |
| 4742 | testCases = append(testCases, testCase{ |
| 4743 | testType: serverTest, |
| 4744 | name: "ALPNServer-EmptyProtocolName-" + ver.name, |
| 4745 | config: Config{ |
| 4746 | MaxVersion: ver.version, |
| 4747 | // A ClientHello containing an empty ALPN protocol |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4748 | // should be rejected. |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4749 | NextProtos: []string{"foo", "", "baz"}, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4750 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4751 | flags: []string{ |
| 4752 | "-select-alpn", "foo", |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 4753 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4754 | shouldFail: true, |
| 4755 | expectedError: ":PARSE_TLSEXT:", |
| 4756 | }) |
| 4757 | |
| 4758 | // Test NPN and the interaction with ALPN. |
| 4759 | if ver.version < VersionTLS13 { |
| 4760 | // Test that the server prefers ALPN over NPN. |
| 4761 | testCases = append(testCases, testCase{ |
| 4762 | testType: serverTest, |
| 4763 | name: "ALPNServer-Preferred-" + ver.name, |
| 4764 | config: Config{ |
| 4765 | MaxVersion: ver.version, |
| 4766 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4767 | }, |
| 4768 | flags: []string{ |
| 4769 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4770 | "-select-alpn", "foo", |
| 4771 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4772 | }, |
| 4773 | expectedNextProto: "foo", |
| 4774 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4775 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4776 | }) |
| 4777 | testCases = append(testCases, testCase{ |
| 4778 | testType: serverTest, |
| 4779 | name: "ALPNServer-Preferred-Swapped-" + ver.name, |
| 4780 | config: Config{ |
| 4781 | MaxVersion: ver.version, |
| 4782 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4783 | Bugs: ProtocolBugs{ |
| 4784 | SwapNPNAndALPN: true, |
| 4785 | }, |
| 4786 | }, |
| 4787 | flags: []string{ |
| 4788 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4789 | "-select-alpn", "foo", |
| 4790 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4791 | }, |
| 4792 | expectedNextProto: "foo", |
| 4793 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4794 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4795 | }) |
| 4796 | |
| 4797 | // Test that negotiating both NPN and ALPN is forbidden. |
| 4798 | testCases = append(testCases, testCase{ |
| 4799 | name: "NegotiateALPNAndNPN-" + ver.name, |
| 4800 | config: Config{ |
| 4801 | MaxVersion: ver.version, |
| 4802 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4803 | Bugs: ProtocolBugs{ |
| 4804 | NegotiateALPNAndNPN: true, |
| 4805 | }, |
| 4806 | }, |
| 4807 | flags: []string{ |
| 4808 | "-advertise-alpn", "\x03foo", |
| 4809 | "-select-next-proto", "foo", |
| 4810 | }, |
| 4811 | shouldFail: true, |
| 4812 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4813 | }) |
| 4814 | testCases = append(testCases, testCase{ |
| 4815 | name: "NegotiateALPNAndNPN-Swapped-" + ver.name, |
| 4816 | config: Config{ |
| 4817 | MaxVersion: ver.version, |
| 4818 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4819 | Bugs: ProtocolBugs{ |
| 4820 | NegotiateALPNAndNPN: true, |
| 4821 | SwapNPNAndALPN: true, |
| 4822 | }, |
| 4823 | }, |
| 4824 | flags: []string{ |
| 4825 | "-advertise-alpn", "\x03foo", |
| 4826 | "-select-next-proto", "foo", |
| 4827 | }, |
| 4828 | shouldFail: true, |
| 4829 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4830 | }) |
| 4831 | |
| 4832 | // Test that NPN can be disabled with SSL_OP_DISABLE_NPN. |
| 4833 | testCases = append(testCases, testCase{ |
| 4834 | name: "DisableNPN-" + ver.name, |
| 4835 | config: Config{ |
| 4836 | MaxVersion: ver.version, |
| 4837 | NextProtos: []string{"foo"}, |
| 4838 | }, |
| 4839 | flags: []string{ |
| 4840 | "-select-next-proto", "foo", |
| 4841 | "-disable-npn", |
| 4842 | }, |
| 4843 | expectNoNextProto: true, |
| 4844 | }) |
| 4845 | } |
| 4846 | |
| 4847 | // Test ticket behavior. |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4848 | |
| 4849 | // Resume with a corrupt ticket. |
| 4850 | testCases = append(testCases, testCase{ |
| 4851 | testType: serverTest, |
| 4852 | name: "CorruptTicket-" + ver.name, |
| 4853 | config: Config{ |
| 4854 | MaxVersion: ver.version, |
| 4855 | Bugs: ProtocolBugs{ |
| 4856 | CorruptTicket: true, |
| 4857 | }, |
| 4858 | }, |
| 4859 | resumeSession: true, |
| 4860 | expectResumeRejected: true, |
| 4861 | }) |
| 4862 | // Test the ticket callback, with and without renewal. |
| 4863 | testCases = append(testCases, testCase{ |
| 4864 | testType: serverTest, |
| 4865 | name: "TicketCallback-" + ver.name, |
| 4866 | config: Config{ |
| 4867 | MaxVersion: ver.version, |
| 4868 | }, |
| 4869 | resumeSession: true, |
| 4870 | flags: []string{"-use-ticket-callback"}, |
| 4871 | }) |
| 4872 | testCases = append(testCases, testCase{ |
| 4873 | testType: serverTest, |
| 4874 | name: "TicketCallback-Renew-" + ver.name, |
| 4875 | config: Config{ |
| 4876 | MaxVersion: ver.version, |
| 4877 | Bugs: ProtocolBugs{ |
| 4878 | ExpectNewTicket: true, |
| 4879 | }, |
| 4880 | }, |
| 4881 | flags: []string{"-use-ticket-callback", "-renew-ticket"}, |
| 4882 | resumeSession: true, |
| 4883 | }) |
| 4884 | |
| 4885 | // Test that the ticket callback is only called once when everything before |
| 4886 | // it in the ClientHello is asynchronous. This corrupts the ticket so |
| 4887 | // certificate selection callbacks run. |
| 4888 | testCases = append(testCases, testCase{ |
| 4889 | testType: serverTest, |
| 4890 | name: "TicketCallback-SingleCall-" + ver.name, |
| 4891 | config: Config{ |
| 4892 | MaxVersion: ver.version, |
| 4893 | Bugs: ProtocolBugs{ |
| 4894 | CorruptTicket: true, |
| 4895 | }, |
| 4896 | }, |
| 4897 | resumeSession: true, |
| 4898 | expectResumeRejected: true, |
| 4899 | flags: []string{ |
| 4900 | "-use-ticket-callback", |
| 4901 | "-async", |
| 4902 | }, |
| 4903 | }) |
| 4904 | |
| 4905 | // Resume with an oversized session id. |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4906 | if ver.version < VersionTLS13 { |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4907 | testCases = append(testCases, testCase{ |
| 4908 | testType: serverTest, |
| 4909 | name: "OversizedSessionId-" + ver.name, |
| 4910 | config: Config{ |
| 4911 | MaxVersion: ver.version, |
| 4912 | Bugs: ProtocolBugs{ |
| 4913 | OversizedSessionId: true, |
| 4914 | }, |
| 4915 | }, |
| 4916 | resumeSession: true, |
| 4917 | shouldFail: true, |
| 4918 | expectedError: ":DECODE_ERROR:", |
| 4919 | }) |
| 4920 | } |
| 4921 | |
| 4922 | // Basic DTLS-SRTP tests. Include fake profiles to ensure they |
| 4923 | // are ignored. |
| 4924 | if ver.hasDTLS { |
| 4925 | testCases = append(testCases, testCase{ |
| 4926 | protocol: dtls, |
| 4927 | name: "SRTP-Client-" + ver.name, |
| 4928 | config: Config{ |
| 4929 | MaxVersion: ver.version, |
| 4930 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4931 | }, |
| 4932 | flags: []string{ |
| 4933 | "-srtp-profiles", |
| 4934 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4935 | }, |
| 4936 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4937 | }) |
| 4938 | testCases = append(testCases, testCase{ |
| 4939 | protocol: dtls, |
| 4940 | testType: serverTest, |
| 4941 | name: "SRTP-Server-" + ver.name, |
| 4942 | config: Config{ |
| 4943 | MaxVersion: ver.version, |
| 4944 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4945 | }, |
| 4946 | flags: []string{ |
| 4947 | "-srtp-profiles", |
| 4948 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4949 | }, |
| 4950 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4951 | }) |
| 4952 | // Test that the MKI is ignored. |
| 4953 | testCases = append(testCases, testCase{ |
| 4954 | protocol: dtls, |
| 4955 | testType: serverTest, |
| 4956 | name: "SRTP-Server-IgnoreMKI-" + ver.name, |
| 4957 | config: Config{ |
| 4958 | MaxVersion: ver.version, |
| 4959 | SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80}, |
| 4960 | Bugs: ProtocolBugs{ |
| 4961 | SRTPMasterKeyIdentifer: "bogus", |
| 4962 | }, |
| 4963 | }, |
| 4964 | flags: []string{ |
| 4965 | "-srtp-profiles", |
| 4966 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4967 | }, |
| 4968 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4969 | }) |
| 4970 | // Test that SRTP isn't negotiated on the server if there were |
| 4971 | // no matching profiles. |
| 4972 | testCases = append(testCases, testCase{ |
| 4973 | protocol: dtls, |
| 4974 | testType: serverTest, |
| 4975 | name: "SRTP-Server-NoMatch-" + ver.name, |
| 4976 | config: Config{ |
| 4977 | MaxVersion: ver.version, |
| 4978 | SRTPProtectionProfiles: []uint16{100, 101, 102}, |
| 4979 | }, |
| 4980 | flags: []string{ |
| 4981 | "-srtp-profiles", |
| 4982 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4983 | }, |
| 4984 | expectedSRTPProtectionProfile: 0, |
| 4985 | }) |
| 4986 | // Test that the server returning an invalid SRTP profile is |
| 4987 | // flagged as an error by the client. |
| 4988 | testCases = append(testCases, testCase{ |
| 4989 | protocol: dtls, |
| 4990 | name: "SRTP-Client-NoMatch-" + ver.name, |
| 4991 | config: Config{ |
| 4992 | MaxVersion: ver.version, |
| 4993 | Bugs: ProtocolBugs{ |
| 4994 | SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32, |
| 4995 | }, |
| 4996 | }, |
| 4997 | flags: []string{ |
| 4998 | "-srtp-profiles", |
| 4999 | "SRTP_AES128_CM_SHA1_80", |
| 5000 | }, |
| 5001 | shouldFail: true, |
| 5002 | expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:", |
| 5003 | }) |
| 5004 | } |
| 5005 | |
| 5006 | // Test SCT list. |
| 5007 | testCases = append(testCases, testCase{ |
| 5008 | name: "SignedCertificateTimestampList-Client-" + ver.name, |
| 5009 | testType: clientTest, |
| 5010 | config: Config{ |
| 5011 | MaxVersion: ver.version, |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 5012 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5013 | flags: []string{ |
| 5014 | "-enable-signed-cert-timestamps", |
| 5015 | "-expect-signed-cert-timestamps", |
| 5016 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 5017 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5018 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5019 | }) |
| 5020 | testCases = append(testCases, testCase{ |
| 5021 | name: "SendSCTListOnResume-" + ver.name, |
| 5022 | config: Config{ |
| 5023 | MaxVersion: ver.version, |
| 5024 | Bugs: ProtocolBugs{ |
| 5025 | SendSCTListOnResume: []byte("bogus"), |
| 5026 | }, |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 5027 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5028 | flags: []string{ |
| 5029 | "-enable-signed-cert-timestamps", |
| 5030 | "-expect-signed-cert-timestamps", |
| 5031 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 5032 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5033 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5034 | }) |
| 5035 | testCases = append(testCases, testCase{ |
| 5036 | name: "SignedCertificateTimestampList-Server-" + ver.name, |
| 5037 | testType: serverTest, |
| 5038 | config: Config{ |
| 5039 | MaxVersion: ver.version, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 5040 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5041 | flags: []string{ |
| 5042 | "-signed-cert-timestamps", |
| 5043 | base64.StdEncoding.EncodeToString(testSCTList), |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 5044 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5045 | expectedSCTList: testSCTList, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5046 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 5047 | }) |
| 5048 | } |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5049 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 5050 | testCases = append(testCases, testCase{ |
Adam Langley | 33ad2b5 | 2015-07-20 17:43:53 -0700 | [diff] [blame] | 5051 | testType: clientTest, |
| 5052 | name: "ClientHelloPadding", |
| 5053 | config: Config{ |
| 5054 | Bugs: ProtocolBugs{ |
| 5055 | RequireClientHelloSize: 512, |
| 5056 | }, |
| 5057 | }, |
| 5058 | // This hostname just needs to be long enough to push the |
| 5059 | // ClientHello into F5's danger zone between 256 and 511 bytes |
| 5060 | // long. |
| 5061 | flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"}, |
| 5062 | }) |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 5063 | |
| 5064 | // Extensions should not function in SSL 3.0. |
| 5065 | testCases = append(testCases, testCase{ |
| 5066 | testType: serverTest, |
| 5067 | name: "SSLv3Extensions-NoALPN", |
| 5068 | config: Config{ |
| 5069 | MaxVersion: VersionSSL30, |
| 5070 | NextProtos: []string{"foo", "bar", "baz"}, |
| 5071 | }, |
| 5072 | flags: []string{ |
| 5073 | "-select-alpn", "foo", |
| 5074 | }, |
| 5075 | expectNoNextProto: true, |
| 5076 | }) |
| 5077 | |
| 5078 | // Test session tickets separately as they follow a different codepath. |
| 5079 | testCases = append(testCases, testCase{ |
| 5080 | testType: serverTest, |
| 5081 | name: "SSLv3Extensions-NoTickets", |
| 5082 | config: Config{ |
| 5083 | MaxVersion: VersionSSL30, |
| 5084 | Bugs: ProtocolBugs{ |
| 5085 | // Historically, session tickets in SSL 3.0 |
| 5086 | // failed in different ways depending on whether |
| 5087 | // the client supported renegotiation_info. |
| 5088 | NoRenegotiationInfo: true, |
| 5089 | }, |
| 5090 | }, |
| 5091 | resumeSession: true, |
| 5092 | }) |
| 5093 | testCases = append(testCases, testCase{ |
| 5094 | testType: serverTest, |
| 5095 | name: "SSLv3Extensions-NoTickets2", |
| 5096 | config: Config{ |
| 5097 | MaxVersion: VersionSSL30, |
| 5098 | }, |
| 5099 | resumeSession: true, |
| 5100 | }) |
| 5101 | |
| 5102 | // But SSL 3.0 does send and process renegotiation_info. |
| 5103 | testCases = append(testCases, testCase{ |
| 5104 | testType: serverTest, |
| 5105 | name: "SSLv3Extensions-RenegotiationInfo", |
| 5106 | config: Config{ |
| 5107 | MaxVersion: VersionSSL30, |
| 5108 | Bugs: ProtocolBugs{ |
| 5109 | RequireRenegotiationInfo: true, |
| 5110 | }, |
| 5111 | }, |
| 5112 | }) |
| 5113 | testCases = append(testCases, testCase{ |
| 5114 | testType: serverTest, |
| 5115 | name: "SSLv3Extensions-RenegotiationInfo-SCSV", |
| 5116 | config: Config{ |
| 5117 | MaxVersion: VersionSSL30, |
| 5118 | Bugs: ProtocolBugs{ |
| 5119 | NoRenegotiationInfo: true, |
| 5120 | SendRenegotiationSCSV: true, |
| 5121 | RequireRenegotiationInfo: true, |
| 5122 | }, |
| 5123 | }, |
| 5124 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5125 | |
| 5126 | // Test that illegal extensions in TLS 1.3 are rejected by the client if |
| 5127 | // in ServerHello. |
| 5128 | testCases = append(testCases, testCase{ |
| 5129 | name: "NPN-Forbidden-TLS13", |
| 5130 | config: Config{ |
| 5131 | MaxVersion: VersionTLS13, |
| 5132 | NextProtos: []string{"foo"}, |
| 5133 | Bugs: ProtocolBugs{ |
| 5134 | NegotiateNPNAtAllVersions: true, |
| 5135 | }, |
| 5136 | }, |
| 5137 | flags: []string{"-select-next-proto", "foo"}, |
| 5138 | shouldFail: true, |
| 5139 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 5140 | }) |
| 5141 | testCases = append(testCases, testCase{ |
| 5142 | name: "EMS-Forbidden-TLS13", |
| 5143 | config: Config{ |
| 5144 | MaxVersion: VersionTLS13, |
| 5145 | Bugs: ProtocolBugs{ |
| 5146 | NegotiateEMSAtAllVersions: true, |
| 5147 | }, |
| 5148 | }, |
| 5149 | shouldFail: true, |
| 5150 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 5151 | }) |
| 5152 | testCases = append(testCases, testCase{ |
| 5153 | name: "RenegotiationInfo-Forbidden-TLS13", |
| 5154 | config: Config{ |
| 5155 | MaxVersion: VersionTLS13, |
| 5156 | Bugs: ProtocolBugs{ |
| 5157 | NegotiateRenegotiationInfoAtAllVersions: true, |
| 5158 | }, |
| 5159 | }, |
| 5160 | shouldFail: true, |
| 5161 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 5162 | }) |
| 5163 | testCases = append(testCases, testCase{ |
| 5164 | name: "ChannelID-Forbidden-TLS13", |
| 5165 | config: Config{ |
| 5166 | MaxVersion: VersionTLS13, |
| 5167 | RequestChannelID: true, |
| 5168 | Bugs: ProtocolBugs{ |
| 5169 | NegotiateChannelIDAtAllVersions: true, |
| 5170 | }, |
| 5171 | }, |
| 5172 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
| 5173 | shouldFail: true, |
| 5174 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 5175 | }) |
| 5176 | testCases = append(testCases, testCase{ |
| 5177 | name: "Ticket-Forbidden-TLS13", |
| 5178 | config: Config{ |
| 5179 | MaxVersion: VersionTLS12, |
| 5180 | }, |
| 5181 | resumeConfig: &Config{ |
| 5182 | MaxVersion: VersionTLS13, |
| 5183 | Bugs: ProtocolBugs{ |
| 5184 | AdvertiseTicketExtension: true, |
| 5185 | }, |
| 5186 | }, |
| 5187 | resumeSession: true, |
| 5188 | shouldFail: true, |
| 5189 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 5190 | }) |
| 5191 | |
| 5192 | // Test that illegal extensions in TLS 1.3 are declined by the server if |
| 5193 | // offered in ClientHello. The runner's server will fail if this occurs, |
| 5194 | // so we exercise the offering path. (EMS and Renegotiation Info are |
| 5195 | // implicit in every test.) |
| 5196 | testCases = append(testCases, testCase{ |
| 5197 | testType: serverTest, |
| 5198 | name: "ChannelID-Declined-TLS13", |
| 5199 | config: Config{ |
| 5200 | MaxVersion: VersionTLS13, |
| 5201 | ChannelID: channelIDKey, |
| 5202 | }, |
| 5203 | flags: []string{"-enable-channel-id"}, |
| 5204 | }) |
| 5205 | testCases = append(testCases, testCase{ |
| 5206 | testType: serverTest, |
David Benjamin | 7364719 | 2016-09-22 16:24:04 -0400 | [diff] [blame] | 5207 | name: "NPN-Declined-TLS13", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5208 | config: Config{ |
| 5209 | MaxVersion: VersionTLS13, |
| 5210 | NextProtos: []string{"bar"}, |
| 5211 | }, |
| 5212 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 5213 | }) |
David Benjamin | 196df5b | 2016-09-21 16:23:27 -0400 | [diff] [blame] | 5214 | |
| 5215 | testCases = append(testCases, testCase{ |
| 5216 | testType: serverTest, |
| 5217 | name: "InvalidChannelIDSignature", |
| 5218 | config: Config{ |
| 5219 | MaxVersion: VersionTLS12, |
| 5220 | ChannelID: channelIDKey, |
| 5221 | Bugs: ProtocolBugs{ |
| 5222 | InvalidChannelIDSignature: true, |
| 5223 | }, |
| 5224 | }, |
| 5225 | flags: []string{"-enable-channel-id"}, |
| 5226 | shouldFail: true, |
| 5227 | expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:", |
| 5228 | expectedLocalError: "remote error: error decrypting message", |
| 5229 | }) |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 5230 | } |
| 5231 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5232 | func addResumptionVersionTests() { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5233 | for _, sessionVers := range tlsVersions { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5234 | for _, resumeVers := range tlsVersions { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5235 | cipher := TLS_RSA_WITH_AES_128_CBC_SHA |
| 5236 | if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 { |
| 5237 | // TLS 1.3 only shares ciphers with TLS 1.2, so |
| 5238 | // we skip certain combinations and use a |
| 5239 | // different cipher to test with. |
| 5240 | cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
| 5241 | if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 { |
| 5242 | continue |
| 5243 | } |
| 5244 | } |
| 5245 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5246 | protocols := []protocol{tls} |
| 5247 | if sessionVers.hasDTLS && resumeVers.hasDTLS { |
| 5248 | protocols = append(protocols, dtls) |
David Benjamin | bdf5e72 | 2014-11-11 00:52:15 -0500 | [diff] [blame] | 5249 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5250 | for _, protocol := range protocols { |
| 5251 | suffix := "-" + sessionVers.name + "-" + resumeVers.name |
| 5252 | if protocol == dtls { |
| 5253 | suffix += "-DTLS" |
| 5254 | } |
| 5255 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5256 | if sessionVers.version == resumeVers.version { |
| 5257 | testCases = append(testCases, testCase{ |
| 5258 | protocol: protocol, |
| 5259 | name: "Resume-Client" + suffix, |
| 5260 | resumeSession: true, |
| 5261 | config: Config{ |
| 5262 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5263 | CipherSuites: []uint16{cipher}, |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 5264 | Bugs: ProtocolBugs{ |
| 5265 | ExpectNoTLS12Session: sessionVers.version >= VersionTLS13, |
| 5266 | ExpectNoTLS13PSK: sessionVers.version < VersionTLS13, |
| 5267 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5268 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5269 | expectedVersion: sessionVers.version, |
| 5270 | expectedResumeVersion: resumeVers.version, |
| 5271 | }) |
| 5272 | } else { |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 5273 | error := ":OLD_SESSION_VERSION_NOT_RETURNED:" |
| 5274 | |
| 5275 | // Offering a TLS 1.3 session sends an empty session ID, so |
| 5276 | // there is no way to convince a non-lookahead client the |
| 5277 | // session was resumed. It will appear to the client that a |
| 5278 | // stray ChangeCipherSpec was sent. |
| 5279 | if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 { |
| 5280 | error = ":UNEXPECTED_RECORD:" |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5281 | } |
| 5282 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5283 | testCases = append(testCases, testCase{ |
| 5284 | protocol: protocol, |
| 5285 | name: "Resume-Client-Mismatch" + suffix, |
| 5286 | resumeSession: true, |
| 5287 | config: Config{ |
| 5288 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5289 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5290 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5291 | expectedVersion: sessionVers.version, |
| 5292 | resumeConfig: &Config{ |
| 5293 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5294 | CipherSuites: []uint16{cipher}, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5295 | Bugs: ProtocolBugs{ |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 5296 | AcceptAnySession: true, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5297 | }, |
| 5298 | }, |
| 5299 | expectedResumeVersion: resumeVers.version, |
| 5300 | shouldFail: true, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5301 | expectedError: error, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5302 | }) |
| 5303 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5304 | |
| 5305 | testCases = append(testCases, testCase{ |
| 5306 | protocol: protocol, |
| 5307 | name: "Resume-Client-NoResume" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5308 | resumeSession: true, |
| 5309 | config: Config{ |
| 5310 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5311 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5312 | }, |
| 5313 | expectedVersion: sessionVers.version, |
| 5314 | resumeConfig: &Config{ |
| 5315 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5316 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5317 | }, |
| 5318 | newSessionsOnResume: true, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 5319 | expectResumeRejected: true, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5320 | expectedResumeVersion: resumeVers.version, |
| 5321 | }) |
| 5322 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5323 | testCases = append(testCases, testCase{ |
| 5324 | protocol: protocol, |
| 5325 | testType: serverTest, |
| 5326 | name: "Resume-Server" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5327 | resumeSession: true, |
| 5328 | config: Config{ |
| 5329 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5330 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5331 | }, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 5332 | expectedVersion: sessionVers.version, |
| 5333 | expectResumeRejected: sessionVers.version != resumeVers.version, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5334 | resumeConfig: &Config{ |
| 5335 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5336 | CipherSuites: []uint16{cipher}, |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 5337 | Bugs: ProtocolBugs{ |
| 5338 | SendBothTickets: true, |
| 5339 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 5340 | }, |
| 5341 | expectedResumeVersion: resumeVers.version, |
| 5342 | }) |
| 5343 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5344 | } |
| 5345 | } |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5346 | |
| 5347 | testCases = append(testCases, testCase{ |
| 5348 | name: "Resume-Client-CipherMismatch", |
| 5349 | resumeSession: true, |
| 5350 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5351 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5352 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 5353 | }, |
| 5354 | resumeConfig: &Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5355 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5356 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 5357 | Bugs: ProtocolBugs{ |
| 5358 | SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 5359 | }, |
| 5360 | }, |
| 5361 | shouldFail: true, |
| 5362 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 5363 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5364 | |
| 5365 | testCases = append(testCases, testCase{ |
| 5366 | name: "Resume-Client-CipherMismatch-TLS13", |
| 5367 | resumeSession: true, |
| 5368 | config: Config{ |
| 5369 | MaxVersion: VersionTLS13, |
| 5370 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5371 | }, |
| 5372 | resumeConfig: &Config{ |
| 5373 | MaxVersion: VersionTLS13, |
| 5374 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5375 | Bugs: ProtocolBugs{ |
| 5376 | SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, |
| 5377 | }, |
| 5378 | }, |
| 5379 | shouldFail: true, |
| 5380 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 5381 | }) |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5382 | } |
| 5383 | |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 5384 | func addRenegotiationTests() { |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 5385 | // Servers cannot renegotiate. |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5386 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5387 | testType: serverTest, |
| 5388 | name: "Renegotiate-Server-Forbidden", |
| 5389 | config: Config{ |
| 5390 | MaxVersion: VersionTLS12, |
| 5391 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5392 | renegotiate: 1, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5393 | shouldFail: true, |
| 5394 | expectedError: ":NO_RENEGOTIATION:", |
| 5395 | expectedLocalError: "remote error: no renegotiation", |
| 5396 | }) |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5397 | // The server shouldn't echo the renegotiation extension unless |
| 5398 | // requested by the client. |
| 5399 | testCases = append(testCases, testCase{ |
| 5400 | testType: serverTest, |
| 5401 | name: "Renegotiate-Server-NoExt", |
| 5402 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5403 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5404 | Bugs: ProtocolBugs{ |
| 5405 | NoRenegotiationInfo: true, |
| 5406 | RequireRenegotiationInfo: true, |
| 5407 | }, |
| 5408 | }, |
| 5409 | shouldFail: true, |
| 5410 | expectedLocalError: "renegotiation extension missing", |
| 5411 | }) |
| 5412 | // The renegotiation SCSV should be sufficient for the server to echo |
| 5413 | // the extension. |
| 5414 | testCases = append(testCases, testCase{ |
| 5415 | testType: serverTest, |
| 5416 | name: "Renegotiate-Server-NoExt-SCSV", |
| 5417 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5418 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5419 | Bugs: ProtocolBugs{ |
| 5420 | NoRenegotiationInfo: true, |
| 5421 | SendRenegotiationSCSV: true, |
| 5422 | RequireRenegotiationInfo: true, |
| 5423 | }, |
| 5424 | }, |
| 5425 | }) |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5426 | testCases = append(testCases, testCase{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 5427 | name: "Renegotiate-Client", |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5428 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5429 | MaxVersion: VersionTLS12, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5430 | Bugs: ProtocolBugs{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 5431 | FailIfResumeOnRenego: true, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5432 | }, |
| 5433 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5434 | renegotiate: 1, |
| 5435 | flags: []string{ |
| 5436 | "-renegotiate-freely", |
| 5437 | "-expect-total-renegotiations", "1", |
| 5438 | }, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5439 | }) |
| 5440 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5441 | name: "Renegotiate-Client-EmptyExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5442 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5443 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5444 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5445 | Bugs: ProtocolBugs{ |
| 5446 | EmptyRenegotiationInfo: true, |
| 5447 | }, |
| 5448 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5449 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5450 | shouldFail: true, |
| 5451 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5452 | }) |
| 5453 | testCases = append(testCases, testCase{ |
| 5454 | name: "Renegotiate-Client-BadExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5455 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5456 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5457 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5458 | Bugs: ProtocolBugs{ |
| 5459 | BadRenegotiationInfo: true, |
| 5460 | }, |
| 5461 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5462 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5463 | shouldFail: true, |
| 5464 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5465 | }) |
| 5466 | testCases = append(testCases, testCase{ |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5467 | name: "Renegotiate-Client-Downgrade", |
| 5468 | renegotiate: 1, |
| 5469 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5470 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5471 | Bugs: ProtocolBugs{ |
| 5472 | NoRenegotiationInfoAfterInitial: true, |
| 5473 | }, |
| 5474 | }, |
| 5475 | flags: []string{"-renegotiate-freely"}, |
| 5476 | shouldFail: true, |
| 5477 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5478 | }) |
| 5479 | testCases = append(testCases, testCase{ |
| 5480 | name: "Renegotiate-Client-Upgrade", |
| 5481 | renegotiate: 1, |
| 5482 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5483 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5484 | Bugs: ProtocolBugs{ |
| 5485 | NoRenegotiationInfoInInitial: true, |
| 5486 | }, |
| 5487 | }, |
| 5488 | flags: []string{"-renegotiate-freely"}, |
| 5489 | shouldFail: true, |
| 5490 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5491 | }) |
| 5492 | testCases = append(testCases, testCase{ |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5493 | name: "Renegotiate-Client-NoExt-Allowed", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5494 | renegotiate: 1, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5495 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5496 | MaxVersion: VersionTLS12, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5497 | Bugs: ProtocolBugs{ |
| 5498 | NoRenegotiationInfo: true, |
| 5499 | }, |
| 5500 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5501 | flags: []string{ |
| 5502 | "-renegotiate-freely", |
| 5503 | "-expect-total-renegotiations", "1", |
| 5504 | }, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5505 | }) |
David Benjamin | e7e36aa | 2016-08-08 12:39:41 -0400 | [diff] [blame] | 5506 | |
| 5507 | // Test that the server may switch ciphers on renegotiation without |
| 5508 | // problems. |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5509 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5510 | name: "Renegotiate-Client-SwitchCiphers", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5511 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5512 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5513 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 5514 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5515 | }, |
| 5516 | renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5517 | flags: []string{ |
| 5518 | "-renegotiate-freely", |
| 5519 | "-expect-total-renegotiations", "1", |
| 5520 | }, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5521 | }) |
| 5522 | testCases = append(testCases, testCase{ |
| 5523 | name: "Renegotiate-Client-SwitchCiphers2", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5524 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5525 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5526 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5527 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5528 | }, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 5529 | renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5530 | flags: []string{ |
| 5531 | "-renegotiate-freely", |
| 5532 | "-expect-total-renegotiations", "1", |
| 5533 | }, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5534 | }) |
David Benjamin | e7e36aa | 2016-08-08 12:39:41 -0400 | [diff] [blame] | 5535 | |
| 5536 | // Test that the server may not switch versions on renegotiation. |
| 5537 | testCases = append(testCases, testCase{ |
| 5538 | name: "Renegotiate-Client-SwitchVersion", |
| 5539 | config: Config{ |
| 5540 | MaxVersion: VersionTLS12, |
| 5541 | // Pick a cipher which exists at both versions. |
| 5542 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 5543 | Bugs: ProtocolBugs{ |
| 5544 | NegotiateVersionOnRenego: VersionTLS11, |
| 5545 | }, |
| 5546 | }, |
| 5547 | renegotiate: 1, |
| 5548 | flags: []string{ |
| 5549 | "-renegotiate-freely", |
| 5550 | "-expect-total-renegotiations", "1", |
| 5551 | }, |
| 5552 | shouldFail: true, |
| 5553 | expectedError: ":WRONG_SSL_VERSION:", |
| 5554 | }) |
| 5555 | |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5556 | testCases = append(testCases, testCase{ |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5557 | name: "Renegotiate-SameClientVersion", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5558 | renegotiate: 1, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5559 | config: Config{ |
| 5560 | MaxVersion: VersionTLS10, |
| 5561 | Bugs: ProtocolBugs{ |
| 5562 | RequireSameRenegoClientVersion: true, |
| 5563 | }, |
| 5564 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5565 | flags: []string{ |
| 5566 | "-renegotiate-freely", |
| 5567 | "-expect-total-renegotiations", "1", |
| 5568 | }, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5569 | }) |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5570 | testCases = append(testCases, testCase{ |
| 5571 | name: "Renegotiate-FalseStart", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5572 | renegotiate: 1, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5573 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5574 | MaxVersion: VersionTLS12, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5575 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5576 | NextProtos: []string{"foo"}, |
| 5577 | }, |
| 5578 | flags: []string{ |
| 5579 | "-false-start", |
| 5580 | "-select-next-proto", "foo", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5581 | "-renegotiate-freely", |
David Benjamin | 324dce4 | 2015-10-12 19:49:00 -0400 | [diff] [blame] | 5582 | "-expect-total-renegotiations", "1", |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5583 | }, |
| 5584 | shimWritesFirst: true, |
| 5585 | }) |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5586 | |
| 5587 | // Client-side renegotiation controls. |
| 5588 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5589 | name: "Renegotiate-Client-Forbidden-1", |
| 5590 | config: Config{ |
| 5591 | MaxVersion: VersionTLS12, |
| 5592 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5593 | renegotiate: 1, |
| 5594 | shouldFail: true, |
| 5595 | expectedError: ":NO_RENEGOTIATION:", |
| 5596 | expectedLocalError: "remote error: no renegotiation", |
| 5597 | }) |
| 5598 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5599 | name: "Renegotiate-Client-Once-1", |
| 5600 | config: Config{ |
| 5601 | MaxVersion: VersionTLS12, |
| 5602 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5603 | renegotiate: 1, |
| 5604 | flags: []string{ |
| 5605 | "-renegotiate-once", |
| 5606 | "-expect-total-renegotiations", "1", |
| 5607 | }, |
| 5608 | }) |
| 5609 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5610 | name: "Renegotiate-Client-Freely-1", |
| 5611 | config: Config{ |
| 5612 | MaxVersion: VersionTLS12, |
| 5613 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5614 | renegotiate: 1, |
| 5615 | flags: []string{ |
| 5616 | "-renegotiate-freely", |
| 5617 | "-expect-total-renegotiations", "1", |
| 5618 | }, |
| 5619 | }) |
| 5620 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5621 | name: "Renegotiate-Client-Once-2", |
| 5622 | config: Config{ |
| 5623 | MaxVersion: VersionTLS12, |
| 5624 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5625 | renegotiate: 2, |
| 5626 | flags: []string{"-renegotiate-once"}, |
| 5627 | shouldFail: true, |
| 5628 | expectedError: ":NO_RENEGOTIATION:", |
| 5629 | expectedLocalError: "remote error: no renegotiation", |
| 5630 | }) |
| 5631 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5632 | name: "Renegotiate-Client-Freely-2", |
| 5633 | config: Config{ |
| 5634 | MaxVersion: VersionTLS12, |
| 5635 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5636 | renegotiate: 2, |
| 5637 | flags: []string{ |
| 5638 | "-renegotiate-freely", |
| 5639 | "-expect-total-renegotiations", "2", |
| 5640 | }, |
| 5641 | }) |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5642 | testCases = append(testCases, testCase{ |
| 5643 | name: "Renegotiate-Client-NoIgnore", |
| 5644 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5645 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5646 | Bugs: ProtocolBugs{ |
| 5647 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5648 | }, |
| 5649 | }, |
| 5650 | shouldFail: true, |
| 5651 | expectedError: ":NO_RENEGOTIATION:", |
| 5652 | }) |
| 5653 | testCases = append(testCases, testCase{ |
| 5654 | name: "Renegotiate-Client-Ignore", |
| 5655 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5656 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5657 | Bugs: ProtocolBugs{ |
| 5658 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5659 | }, |
| 5660 | }, |
| 5661 | flags: []string{ |
| 5662 | "-renegotiate-ignore", |
| 5663 | "-expect-total-renegotiations", "0", |
| 5664 | }, |
| 5665 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5666 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5667 | // Stray HelloRequests during the handshake are ignored in TLS 1.2. |
David Benjamin | 71dd666 | 2016-07-08 14:10:48 -0700 | [diff] [blame] | 5668 | testCases = append(testCases, testCase{ |
| 5669 | name: "StrayHelloRequest", |
| 5670 | config: Config{ |
| 5671 | MaxVersion: VersionTLS12, |
| 5672 | Bugs: ProtocolBugs{ |
| 5673 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5674 | }, |
| 5675 | }, |
| 5676 | }) |
| 5677 | testCases = append(testCases, testCase{ |
| 5678 | name: "StrayHelloRequest-Packed", |
| 5679 | config: Config{ |
| 5680 | MaxVersion: VersionTLS12, |
| 5681 | Bugs: ProtocolBugs{ |
| 5682 | PackHandshakeFlight: true, |
| 5683 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5684 | }, |
| 5685 | }, |
| 5686 | }) |
| 5687 | |
David Benjamin | 12d2c48 | 2016-07-24 10:56:51 -0400 | [diff] [blame] | 5688 | // Test renegotiation works if HelloRequest and server Finished come in |
| 5689 | // the same record. |
| 5690 | testCases = append(testCases, testCase{ |
| 5691 | name: "Renegotiate-Client-Packed", |
| 5692 | config: Config{ |
| 5693 | MaxVersion: VersionTLS12, |
| 5694 | Bugs: ProtocolBugs{ |
| 5695 | PackHandshakeFlight: true, |
| 5696 | PackHelloRequestWithFinished: true, |
| 5697 | }, |
| 5698 | }, |
| 5699 | renegotiate: 1, |
| 5700 | flags: []string{ |
| 5701 | "-renegotiate-freely", |
| 5702 | "-expect-total-renegotiations", "1", |
| 5703 | }, |
| 5704 | }) |
| 5705 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5706 | // Renegotiation is forbidden in TLS 1.3. |
| 5707 | testCases = append(testCases, testCase{ |
| 5708 | name: "Renegotiate-Client-TLS13", |
| 5709 | config: Config{ |
| 5710 | MaxVersion: VersionTLS13, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5711 | Bugs: ProtocolBugs{ |
| 5712 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5713 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5714 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5715 | flags: []string{ |
| 5716 | "-renegotiate-freely", |
| 5717 | }, |
Steven Valdez | 8e1c7be | 2016-07-26 12:39:22 -0400 | [diff] [blame] | 5718 | shouldFail: true, |
| 5719 | expectedError: ":UNEXPECTED_MESSAGE:", |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5720 | }) |
| 5721 | |
| 5722 | // Stray HelloRequests during the handshake are forbidden in TLS 1.3. |
| 5723 | testCases = append(testCases, testCase{ |
| 5724 | name: "StrayHelloRequest-TLS13", |
| 5725 | config: Config{ |
| 5726 | MaxVersion: VersionTLS13, |
| 5727 | Bugs: ProtocolBugs{ |
| 5728 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5729 | }, |
| 5730 | }, |
| 5731 | shouldFail: true, |
| 5732 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 5733 | }) |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 5734 | } |
| 5735 | |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5736 | func addDTLSReplayTests() { |
| 5737 | // Test that sequence number replays are detected. |
| 5738 | testCases = append(testCases, testCase{ |
| 5739 | protocol: dtls, |
| 5740 | name: "DTLS-Replay", |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5741 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5742 | replayWrites: true, |
| 5743 | }) |
| 5744 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5745 | // Test the incoming sequence number skipping by values larger |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5746 | // than the retransmit window. |
| 5747 | testCases = append(testCases, testCase{ |
| 5748 | protocol: dtls, |
| 5749 | name: "DTLS-Replay-LargeGaps", |
| 5750 | config: Config{ |
| 5751 | Bugs: ProtocolBugs{ |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5752 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5753 | return in * 127 |
| 5754 | }, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5755 | }, |
| 5756 | }, |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5757 | messageCount: 200, |
| 5758 | replayWrites: true, |
| 5759 | }) |
| 5760 | |
| 5761 | // Test the incoming sequence number changing non-monotonically. |
| 5762 | testCases = append(testCases, testCase{ |
| 5763 | protocol: dtls, |
| 5764 | name: "DTLS-Replay-NonMonotonic", |
| 5765 | config: Config{ |
| 5766 | Bugs: ProtocolBugs{ |
| 5767 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5768 | return in ^ 31 |
| 5769 | }, |
| 5770 | }, |
| 5771 | }, |
| 5772 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5773 | replayWrites: true, |
| 5774 | }) |
| 5775 | } |
| 5776 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5777 | var testSignatureAlgorithms = []struct { |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5778 | name string |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5779 | id signatureAlgorithm |
| 5780 | cert testCert |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5781 | }{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5782 | {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA}, |
| 5783 | {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA}, |
| 5784 | {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA}, |
| 5785 | {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5786 | {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5787 | {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256}, |
| 5788 | {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384}, |
| 5789 | {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521}, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5790 | {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA}, |
| 5791 | {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA}, |
| 5792 | {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5793 | // Tests for key types prior to TLS 1.2. |
| 5794 | {"RSA", 0, testCertRSA}, |
| 5795 | {"ECDSA", 0, testCertECDSAP256}, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5796 | } |
| 5797 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5798 | const fakeSigAlg1 signatureAlgorithm = 0x2a01 |
| 5799 | const fakeSigAlg2 signatureAlgorithm = 0xff01 |
| 5800 | |
| 5801 | func addSignatureAlgorithmTests() { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5802 | // Not all ciphers involve a signature. Advertise a list which gives all |
| 5803 | // versions a signing cipher. |
| 5804 | signingCiphers := []uint16{ |
| 5805 | TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 5806 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 5807 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 5808 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 5809 | TLS_DHE_RSA_WITH_AES_128_CBC_SHA, |
| 5810 | } |
| 5811 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5812 | var allAlgorithms []signatureAlgorithm |
| 5813 | for _, alg := range testSignatureAlgorithms { |
| 5814 | if alg.id != 0 { |
| 5815 | allAlgorithms = append(allAlgorithms, alg.id) |
| 5816 | } |
| 5817 | } |
| 5818 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5819 | // Make sure each signature algorithm works. Include some fake values in |
| 5820 | // the list and ensure they're ignored. |
| 5821 | for _, alg := range testSignatureAlgorithms { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5822 | for _, ver := range tlsVersions { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5823 | if (ver.version < VersionTLS12) != (alg.id == 0) { |
| 5824 | continue |
| 5825 | } |
| 5826 | |
| 5827 | // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing |
| 5828 | // or remove it in C. |
| 5829 | if ver.version == VersionSSL30 && alg.cert != testCertRSA { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5830 | continue |
| 5831 | } |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5832 | |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5833 | var shouldFail bool |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5834 | // ecdsa_sha1 does not exist in TLS 1.3. |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5835 | if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 { |
| 5836 | shouldFail = true |
| 5837 | } |
Steven Valdez | 54ed58e | 2016-08-18 14:03:49 -0400 | [diff] [blame] | 5838 | // RSA-PKCS1 does not exist in TLS 1.3. |
| 5839 | if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") { |
| 5840 | shouldFail = true |
| 5841 | } |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5842 | |
| 5843 | var signError, verifyError string |
| 5844 | if shouldFail { |
| 5845 | signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:" |
| 5846 | verifyError = ":WRONG_SIGNATURE_TYPE:" |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5847 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5848 | |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5849 | suffix := "-" + alg.name + "-" + ver.name |
David Benjamin | 6e80765 | 2015-11-02 12:02:20 -0500 | [diff] [blame] | 5850 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5851 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5852 | name: "ClientAuth-Sign" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5853 | config: Config{ |
| 5854 | MaxVersion: ver.version, |
| 5855 | ClientAuth: RequireAnyClientCert, |
| 5856 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5857 | fakeSigAlg1, |
| 5858 | alg.id, |
| 5859 | fakeSigAlg2, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5860 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5861 | }, |
| 5862 | flags: []string{ |
| 5863 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5864 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5865 | "-enable-all-curves", |
| 5866 | }, |
| 5867 | shouldFail: shouldFail, |
| 5868 | expectedError: signError, |
| 5869 | expectedPeerSignatureAlgorithm: alg.id, |
| 5870 | }) |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5871 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5872 | testCases = append(testCases, testCase{ |
| 5873 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5874 | name: "ClientAuth-Verify" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5875 | config: Config{ |
| 5876 | MaxVersion: ver.version, |
| 5877 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5878 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5879 | alg.id, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5880 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5881 | Bugs: ProtocolBugs{ |
| 5882 | SkipECDSACurveCheck: shouldFail, |
| 5883 | IgnoreSignatureVersionChecks: shouldFail, |
| 5884 | // The client won't advertise 1.3-only algorithms after |
| 5885 | // version negotiation. |
| 5886 | IgnorePeerSignatureAlgorithmPreferences: shouldFail, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5887 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5888 | }, |
| 5889 | flags: []string{ |
| 5890 | "-require-any-client-certificate", |
| 5891 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5892 | "-enable-all-curves", |
| 5893 | }, |
| 5894 | shouldFail: shouldFail, |
| 5895 | expectedError: verifyError, |
| 5896 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5897 | |
| 5898 | testCases = append(testCases, testCase{ |
| 5899 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5900 | name: "ServerAuth-Sign" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5901 | config: Config{ |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5902 | MaxVersion: ver.version, |
| 5903 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5904 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5905 | fakeSigAlg1, |
| 5906 | alg.id, |
| 5907 | fakeSigAlg2, |
| 5908 | }, |
| 5909 | }, |
| 5910 | flags: []string{ |
| 5911 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5912 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5913 | "-enable-all-curves", |
| 5914 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5915 | shouldFail: shouldFail, |
| 5916 | expectedError: signError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5917 | expectedPeerSignatureAlgorithm: alg.id, |
| 5918 | }) |
| 5919 | |
| 5920 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5921 | name: "ServerAuth-Verify" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5922 | config: Config{ |
| 5923 | MaxVersion: ver.version, |
| 5924 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5925 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5926 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5927 | alg.id, |
| 5928 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5929 | Bugs: ProtocolBugs{ |
| 5930 | SkipECDSACurveCheck: shouldFail, |
| 5931 | IgnoreSignatureVersionChecks: shouldFail, |
| 5932 | }, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5933 | }, |
| 5934 | flags: []string{ |
| 5935 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5936 | "-enable-all-curves", |
| 5937 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5938 | shouldFail: shouldFail, |
| 5939 | expectedError: verifyError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5940 | }) |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5941 | |
| 5942 | if !shouldFail { |
| 5943 | testCases = append(testCases, testCase{ |
| 5944 | testType: serverTest, |
| 5945 | name: "ClientAuth-InvalidSignature" + suffix, |
| 5946 | config: Config{ |
| 5947 | MaxVersion: ver.version, |
| 5948 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5949 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5950 | alg.id, |
| 5951 | }, |
| 5952 | Bugs: ProtocolBugs{ |
| 5953 | InvalidSignature: true, |
| 5954 | }, |
| 5955 | }, |
| 5956 | flags: []string{ |
| 5957 | "-require-any-client-certificate", |
| 5958 | "-enable-all-curves", |
| 5959 | }, |
| 5960 | shouldFail: true, |
| 5961 | expectedError: ":BAD_SIGNATURE:", |
| 5962 | }) |
| 5963 | |
| 5964 | testCases = append(testCases, testCase{ |
| 5965 | name: "ServerAuth-InvalidSignature" + suffix, |
| 5966 | config: Config{ |
| 5967 | MaxVersion: ver.version, |
| 5968 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5969 | CipherSuites: signingCiphers, |
| 5970 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5971 | alg.id, |
| 5972 | }, |
| 5973 | Bugs: ProtocolBugs{ |
| 5974 | InvalidSignature: true, |
| 5975 | }, |
| 5976 | }, |
| 5977 | flags: []string{"-enable-all-curves"}, |
| 5978 | shouldFail: true, |
| 5979 | expectedError: ":BAD_SIGNATURE:", |
| 5980 | }) |
| 5981 | } |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5982 | |
| 5983 | if ver.version >= VersionTLS12 && !shouldFail { |
| 5984 | testCases = append(testCases, testCase{ |
| 5985 | name: "ClientAuth-Sign-Negotiate" + suffix, |
| 5986 | config: Config{ |
| 5987 | MaxVersion: ver.version, |
| 5988 | ClientAuth: RequireAnyClientCert, |
| 5989 | VerifySignatureAlgorithms: allAlgorithms, |
| 5990 | }, |
| 5991 | flags: []string{ |
| 5992 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5993 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5994 | "-enable-all-curves", |
| 5995 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 5996 | }, |
| 5997 | expectedPeerSignatureAlgorithm: alg.id, |
| 5998 | }) |
| 5999 | |
| 6000 | testCases = append(testCases, testCase{ |
| 6001 | testType: serverTest, |
| 6002 | name: "ServerAuth-Sign-Negotiate" + suffix, |
| 6003 | config: Config{ |
| 6004 | MaxVersion: ver.version, |
| 6005 | CipherSuites: signingCiphers, |
| 6006 | VerifySignatureAlgorithms: allAlgorithms, |
| 6007 | }, |
| 6008 | flags: []string{ |
| 6009 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 6010 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 6011 | "-enable-all-curves", |
| 6012 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 6013 | }, |
| 6014 | expectedPeerSignatureAlgorithm: alg.id, |
| 6015 | }) |
| 6016 | } |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6017 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6018 | } |
| 6019 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6020 | // Test that algorithm selection takes the key type into account. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6021 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6022 | name: "ClientAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6023 | config: Config{ |
| 6024 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6025 | MaxVersion: VersionTLS12, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6026 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6027 | signatureECDSAWithP521AndSHA512, |
| 6028 | signatureRSAPKCS1WithSHA384, |
| 6029 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6030 | }, |
| 6031 | }, |
| 6032 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6033 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6034 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6035 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6036 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6037 | }) |
| 6038 | |
| 6039 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6040 | name: "ClientAuth-SignatureType-TLS13", |
| 6041 | config: Config{ |
| 6042 | ClientAuth: RequireAnyClientCert, |
| 6043 | MaxVersion: VersionTLS13, |
| 6044 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6045 | signatureECDSAWithP521AndSHA512, |
| 6046 | signatureRSAPKCS1WithSHA384, |
| 6047 | signatureRSAPSSWithSHA384, |
| 6048 | signatureECDSAWithSHA1, |
| 6049 | }, |
| 6050 | }, |
| 6051 | flags: []string{ |
| 6052 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6053 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6054 | }, |
| 6055 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 6056 | }) |
| 6057 | |
| 6058 | testCases = append(testCases, testCase{ |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6059 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6060 | name: "ServerAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6061 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6062 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6063 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6064 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6065 | signatureECDSAWithP521AndSHA512, |
| 6066 | signatureRSAPKCS1WithSHA384, |
| 6067 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6068 | }, |
| 6069 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6070 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6071 | }) |
| 6072 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6073 | testCases = append(testCases, testCase{ |
| 6074 | testType: serverTest, |
| 6075 | name: "ServerAuth-SignatureType-TLS13", |
| 6076 | config: Config{ |
| 6077 | MaxVersion: VersionTLS13, |
| 6078 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6079 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6080 | signatureECDSAWithP521AndSHA512, |
| 6081 | signatureRSAPKCS1WithSHA384, |
| 6082 | signatureRSAPSSWithSHA384, |
| 6083 | signatureECDSAWithSHA1, |
| 6084 | }, |
| 6085 | }, |
| 6086 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 6087 | }) |
| 6088 | |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 6089 | // Test that signature verification takes the key type into account. |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 6090 | testCases = append(testCases, testCase{ |
| 6091 | testType: serverTest, |
| 6092 | name: "Verify-ClientAuth-SignatureType", |
| 6093 | config: Config{ |
| 6094 | MaxVersion: VersionTLS12, |
| 6095 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6096 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 6097 | signatureRSAPKCS1WithSHA256, |
| 6098 | }, |
| 6099 | Bugs: ProtocolBugs{ |
| 6100 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6101 | }, |
| 6102 | }, |
| 6103 | flags: []string{ |
| 6104 | "-require-any-client-certificate", |
| 6105 | }, |
| 6106 | shouldFail: true, |
| 6107 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6108 | }) |
| 6109 | |
| 6110 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6111 | testType: serverTest, |
| 6112 | name: "Verify-ClientAuth-SignatureType-TLS13", |
| 6113 | config: Config{ |
| 6114 | MaxVersion: VersionTLS13, |
| 6115 | Certificates: []Certificate{rsaCertificate}, |
| 6116 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6117 | signatureRSAPSSWithSHA256, |
| 6118 | }, |
| 6119 | Bugs: ProtocolBugs{ |
| 6120 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6121 | }, |
| 6122 | }, |
| 6123 | flags: []string{ |
| 6124 | "-require-any-client-certificate", |
| 6125 | }, |
| 6126 | shouldFail: true, |
| 6127 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6128 | }) |
| 6129 | |
| 6130 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6131 | name: "Verify-ServerAuth-SignatureType", |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 6132 | config: Config{ |
| 6133 | MaxVersion: VersionTLS12, |
| 6134 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6135 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 6136 | signatureRSAPKCS1WithSHA256, |
| 6137 | }, |
| 6138 | Bugs: ProtocolBugs{ |
| 6139 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6140 | }, |
| 6141 | }, |
| 6142 | shouldFail: true, |
| 6143 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6144 | }) |
| 6145 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6146 | testCases = append(testCases, testCase{ |
| 6147 | name: "Verify-ServerAuth-SignatureType-TLS13", |
| 6148 | config: Config{ |
| 6149 | MaxVersion: VersionTLS13, |
| 6150 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6151 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6152 | signatureRSAPSSWithSHA256, |
| 6153 | }, |
| 6154 | Bugs: ProtocolBugs{ |
| 6155 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6156 | }, |
| 6157 | }, |
| 6158 | shouldFail: true, |
| 6159 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6160 | }) |
| 6161 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6162 | // Test that, if the list is missing, the peer falls back to SHA-1 in |
| 6163 | // TLS 1.2, but not TLS 1.3. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6164 | testCases = append(testCases, testCase{ |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 6165 | name: "ClientAuth-SHA1-Fallback-RSA", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6166 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6167 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6168 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6169 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6170 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6171 | }, |
| 6172 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6173 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6174 | }, |
| 6175 | }, |
| 6176 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6177 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6178 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6179 | }, |
| 6180 | }) |
| 6181 | |
| 6182 | testCases = append(testCases, testCase{ |
| 6183 | testType: serverTest, |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 6184 | name: "ServerAuth-SHA1-Fallback-RSA", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6185 | config: Config{ |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 6186 | MaxVersion: VersionTLS12, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6187 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6188 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6189 | }, |
| 6190 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6191 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6192 | }, |
| 6193 | }, |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 6194 | flags: []string{ |
| 6195 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6196 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6197 | }, |
| 6198 | }) |
| 6199 | |
| 6200 | testCases = append(testCases, testCase{ |
| 6201 | name: "ClientAuth-SHA1-Fallback-ECDSA", |
| 6202 | config: Config{ |
| 6203 | MaxVersion: VersionTLS12, |
| 6204 | ClientAuth: RequireAnyClientCert, |
| 6205 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6206 | signatureECDSAWithSHA1, |
| 6207 | }, |
| 6208 | Bugs: ProtocolBugs{ |
| 6209 | NoSignatureAlgorithms: true, |
| 6210 | }, |
| 6211 | }, |
| 6212 | flags: []string{ |
| 6213 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 6214 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 6215 | }, |
| 6216 | }) |
| 6217 | |
| 6218 | testCases = append(testCases, testCase{ |
| 6219 | testType: serverTest, |
| 6220 | name: "ServerAuth-SHA1-Fallback-ECDSA", |
| 6221 | config: Config{ |
| 6222 | MaxVersion: VersionTLS12, |
| 6223 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6224 | signatureECDSAWithSHA1, |
| 6225 | }, |
| 6226 | Bugs: ProtocolBugs{ |
| 6227 | NoSignatureAlgorithms: true, |
| 6228 | }, |
| 6229 | }, |
| 6230 | flags: []string{ |
| 6231 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 6232 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 6233 | }, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6234 | }) |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6235 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6236 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6237 | name: "ClientAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6238 | config: Config{ |
| 6239 | MaxVersion: VersionTLS13, |
| 6240 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6241 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6242 | signatureRSAPKCS1WithSHA1, |
| 6243 | }, |
| 6244 | Bugs: ProtocolBugs{ |
| 6245 | NoSignatureAlgorithms: true, |
| 6246 | }, |
| 6247 | }, |
| 6248 | flags: []string{ |
| 6249 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6250 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6251 | }, |
David Benjamin | 4890165 | 2016-08-01 12:12:47 -0400 | [diff] [blame] | 6252 | shouldFail: true, |
| 6253 | // An empty CertificateRequest signature algorithm list is a |
| 6254 | // syntax error in TLS 1.3. |
| 6255 | expectedError: ":DECODE_ERROR:", |
| 6256 | expectedLocalError: "remote error: error decoding message", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6257 | }) |
| 6258 | |
| 6259 | testCases = append(testCases, testCase{ |
| 6260 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6261 | name: "ServerAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6262 | config: Config{ |
| 6263 | MaxVersion: VersionTLS13, |
| 6264 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6265 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 6266 | signatureRSAPKCS1WithSHA1, |
| 6267 | }, |
| 6268 | Bugs: ProtocolBugs{ |
| 6269 | NoSignatureAlgorithms: true, |
| 6270 | }, |
| 6271 | }, |
| 6272 | shouldFail: true, |
| 6273 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6274 | }) |
| 6275 | |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 6276 | // Test that hash preferences are enforced. BoringSSL does not implement |
| 6277 | // MD5 signatures. |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6278 | testCases = append(testCases, testCase{ |
| 6279 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6280 | name: "ClientAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6281 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6282 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6283 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6284 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6285 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6286 | }, |
| 6287 | Bugs: ProtocolBugs{ |
| 6288 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 6289 | }, |
| 6290 | }, |
| 6291 | flags: []string{"-require-any-client-certificate"}, |
| 6292 | shouldFail: true, |
| 6293 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6294 | }) |
| 6295 | |
| 6296 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 6297 | name: "ServerAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6298 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6299 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6300 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6301 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6302 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 6303 | }, |
| 6304 | Bugs: ProtocolBugs{ |
| 6305 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 6306 | }, |
| 6307 | }, |
| 6308 | shouldFail: true, |
| 6309 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6310 | }) |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 6311 | testCases = append(testCases, testCase{ |
| 6312 | testType: serverTest, |
| 6313 | name: "ClientAuth-Enforced-TLS13", |
| 6314 | config: Config{ |
| 6315 | MaxVersion: VersionTLS13, |
| 6316 | Certificates: []Certificate{rsaCertificate}, |
| 6317 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6318 | signatureRSAPKCS1WithMD5, |
| 6319 | }, |
| 6320 | Bugs: ProtocolBugs{ |
| 6321 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 6322 | IgnoreSignatureVersionChecks: true, |
| 6323 | }, |
| 6324 | }, |
| 6325 | flags: []string{"-require-any-client-certificate"}, |
| 6326 | shouldFail: true, |
| 6327 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6328 | }) |
| 6329 | |
| 6330 | testCases = append(testCases, testCase{ |
| 6331 | name: "ServerAuth-Enforced-TLS13", |
| 6332 | config: Config{ |
| 6333 | MaxVersion: VersionTLS13, |
| 6334 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6335 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6336 | signatureRSAPKCS1WithMD5, |
| 6337 | }, |
| 6338 | Bugs: ProtocolBugs{ |
| 6339 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 6340 | IgnoreSignatureVersionChecks: true, |
| 6341 | }, |
| 6342 | }, |
| 6343 | shouldFail: true, |
| 6344 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6345 | }) |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6346 | |
| 6347 | // Test that the agreed upon digest respects the client preferences and |
| 6348 | // the server digests. |
| 6349 | testCases = append(testCases, testCase{ |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6350 | name: "NoCommonAlgorithms-Digests", |
| 6351 | config: Config{ |
| 6352 | MaxVersion: VersionTLS12, |
| 6353 | ClientAuth: RequireAnyClientCert, |
| 6354 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6355 | signatureRSAPKCS1WithSHA512, |
| 6356 | signatureRSAPKCS1WithSHA1, |
| 6357 | }, |
| 6358 | }, |
| 6359 | flags: []string{ |
| 6360 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6361 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6362 | "-digest-prefs", "SHA256", |
| 6363 | }, |
| 6364 | shouldFail: true, |
| 6365 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6366 | }) |
| 6367 | testCases = append(testCases, testCase{ |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 6368 | name: "NoCommonAlgorithms", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6369 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6370 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6371 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6372 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6373 | signatureRSAPKCS1WithSHA512, |
| 6374 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6375 | }, |
| 6376 | }, |
| 6377 | flags: []string{ |
| 6378 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6379 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6380 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6381 | }, |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6382 | shouldFail: true, |
| 6383 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6384 | }) |
| 6385 | testCases = append(testCases, testCase{ |
| 6386 | name: "NoCommonAlgorithms-TLS13", |
| 6387 | config: Config{ |
| 6388 | MaxVersion: VersionTLS13, |
| 6389 | ClientAuth: RequireAnyClientCert, |
| 6390 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6391 | signatureRSAPSSWithSHA512, |
| 6392 | signatureRSAPSSWithSHA384, |
| 6393 | }, |
| 6394 | }, |
| 6395 | flags: []string{ |
| 6396 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6397 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6398 | "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)), |
| 6399 | }, |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 6400 | shouldFail: true, |
| 6401 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6402 | }) |
| 6403 | testCases = append(testCases, testCase{ |
| 6404 | name: "Agree-Digest-SHA256", |
| 6405 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6406 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6407 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6408 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6409 | signatureRSAPKCS1WithSHA1, |
| 6410 | signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6411 | }, |
| 6412 | }, |
| 6413 | flags: []string{ |
| 6414 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6415 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6416 | "-digest-prefs", "SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6417 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6418 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6419 | }) |
| 6420 | testCases = append(testCases, testCase{ |
| 6421 | name: "Agree-Digest-SHA1", |
| 6422 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6423 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6424 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6425 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 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 | "-digest-prefs", "SHA512,SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6433 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6434 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6435 | }) |
| 6436 | testCases = append(testCases, testCase{ |
| 6437 | name: "Agree-Digest-Default", |
| 6438 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6439 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6440 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6441 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6442 | signatureRSAPKCS1WithSHA256, |
| 6443 | signatureECDSAWithP256AndSHA256, |
| 6444 | signatureRSAPKCS1WithSHA1, |
| 6445 | signatureECDSAWithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6446 | }, |
| 6447 | }, |
| 6448 | flags: []string{ |
| 6449 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6450 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6451 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6452 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6453 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6454 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6455 | // Test that the signing preference list may include extra algorithms |
| 6456 | // without negotiation problems. |
| 6457 | testCases = append(testCases, testCase{ |
| 6458 | testType: serverTest, |
| 6459 | name: "FilterExtraAlgorithms", |
| 6460 | config: Config{ |
| 6461 | MaxVersion: VersionTLS12, |
| 6462 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6463 | signatureRSAPKCS1WithSHA256, |
| 6464 | }, |
| 6465 | }, |
| 6466 | flags: []string{ |
| 6467 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6468 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6469 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)), |
| 6470 | "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)), |
| 6471 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
| 6472 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)), |
| 6473 | }, |
| 6474 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
| 6475 | }) |
| 6476 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6477 | // In TLS 1.2 and below, ECDSA uses the curve list rather than the |
| 6478 | // signature algorithms. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6479 | testCases = append(testCases, testCase{ |
| 6480 | name: "CheckLeafCurve", |
| 6481 | config: Config{ |
| 6482 | MaxVersion: VersionTLS12, |
| 6483 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 6484 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6485 | }, |
| 6486 | flags: []string{"-p384-only"}, |
| 6487 | shouldFail: true, |
| 6488 | expectedError: ":BAD_ECC_CERT:", |
| 6489 | }) |
David Benjamin | 75ea5bb | 2016-07-08 17:43:29 -0700 | [diff] [blame] | 6490 | |
| 6491 | // In TLS 1.3, ECDSA does not use the ECDHE curve list. |
| 6492 | testCases = append(testCases, testCase{ |
| 6493 | name: "CheckLeafCurve-TLS13", |
| 6494 | config: Config{ |
| 6495 | MaxVersion: VersionTLS13, |
| 6496 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6497 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 6498 | }, |
| 6499 | flags: []string{"-p384-only"}, |
| 6500 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6501 | |
| 6502 | // In TLS 1.2, the ECDSA curve is not in the signature algorithm. |
| 6503 | testCases = append(testCases, testCase{ |
| 6504 | name: "ECDSACurveMismatch-Verify-TLS12", |
| 6505 | config: Config{ |
| 6506 | MaxVersion: VersionTLS12, |
| 6507 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6508 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6509 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6510 | signatureECDSAWithP384AndSHA384, |
| 6511 | }, |
| 6512 | }, |
| 6513 | }) |
| 6514 | |
| 6515 | // In TLS 1.3, the ECDSA curve comes from the signature algorithm. |
| 6516 | testCases = append(testCases, testCase{ |
| 6517 | name: "ECDSACurveMismatch-Verify-TLS13", |
| 6518 | config: Config{ |
| 6519 | MaxVersion: VersionTLS13, |
| 6520 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6521 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6522 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6523 | signatureECDSAWithP384AndSHA384, |
| 6524 | }, |
| 6525 | Bugs: ProtocolBugs{ |
| 6526 | SkipECDSACurveCheck: true, |
| 6527 | }, |
| 6528 | }, |
| 6529 | shouldFail: true, |
| 6530 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6531 | }) |
| 6532 | |
| 6533 | // Signature algorithm selection in TLS 1.3 should take the curve into |
| 6534 | // account. |
| 6535 | testCases = append(testCases, testCase{ |
| 6536 | testType: serverTest, |
| 6537 | name: "ECDSACurveMismatch-Sign-TLS13", |
| 6538 | config: Config{ |
| 6539 | MaxVersion: VersionTLS13, |
| 6540 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6541 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6542 | signatureECDSAWithP384AndSHA384, |
| 6543 | signatureECDSAWithP256AndSHA256, |
| 6544 | }, |
| 6545 | }, |
| 6546 | flags: []string{ |
| 6547 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 6548 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 6549 | }, |
| 6550 | expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6551 | }) |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 6552 | |
| 6553 | // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the |
| 6554 | // server does not attempt to sign in that case. |
| 6555 | testCases = append(testCases, testCase{ |
| 6556 | testType: serverTest, |
| 6557 | name: "RSA-PSS-Large", |
| 6558 | config: Config{ |
| 6559 | MaxVersion: VersionTLS13, |
| 6560 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6561 | signatureRSAPSSWithSHA512, |
| 6562 | }, |
| 6563 | }, |
| 6564 | flags: []string{ |
| 6565 | "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile), |
| 6566 | "-key-file", path.Join(*resourceDir, rsa1024KeyFile), |
| 6567 | }, |
| 6568 | shouldFail: true, |
| 6569 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6570 | }) |
David Benjamin | 57e929f | 2016-08-30 00:30:38 -0400 | [diff] [blame] | 6571 | |
| 6572 | // Test that RSA-PSS is enabled by default for TLS 1.2. |
| 6573 | testCases = append(testCases, testCase{ |
| 6574 | testType: clientTest, |
| 6575 | name: "RSA-PSS-Default-Verify", |
| 6576 | config: Config{ |
| 6577 | MaxVersion: VersionTLS12, |
| 6578 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 6579 | signatureRSAPSSWithSHA256, |
| 6580 | }, |
| 6581 | }, |
| 6582 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 6583 | }) |
| 6584 | |
| 6585 | testCases = append(testCases, testCase{ |
| 6586 | testType: serverTest, |
| 6587 | name: "RSA-PSS-Default-Sign", |
| 6588 | config: Config{ |
| 6589 | MaxVersion: VersionTLS12, |
| 6590 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6591 | signatureRSAPSSWithSHA256, |
| 6592 | }, |
| 6593 | }, |
| 6594 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 6595 | }) |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6596 | } |
| 6597 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6598 | // timeouts is the retransmit schedule for BoringSSL. It doubles and |
| 6599 | // caps at 60 seconds. On the 13th timeout, it gives up. |
| 6600 | var timeouts = []time.Duration{ |
| 6601 | 1 * time.Second, |
| 6602 | 2 * time.Second, |
| 6603 | 4 * time.Second, |
| 6604 | 8 * time.Second, |
| 6605 | 16 * time.Second, |
| 6606 | 32 * time.Second, |
| 6607 | 60 * time.Second, |
| 6608 | 60 * time.Second, |
| 6609 | 60 * time.Second, |
| 6610 | 60 * time.Second, |
| 6611 | 60 * time.Second, |
| 6612 | 60 * time.Second, |
| 6613 | 60 * time.Second, |
| 6614 | } |
| 6615 | |
Taylor Brandstetter | 376a0fe | 2016-05-10 19:30:28 -0700 | [diff] [blame] | 6616 | // shortTimeouts is an alternate set of timeouts which would occur if the |
| 6617 | // initial timeout duration was set to 250ms. |
| 6618 | var shortTimeouts = []time.Duration{ |
| 6619 | 250 * time.Millisecond, |
| 6620 | 500 * time.Millisecond, |
| 6621 | 1 * time.Second, |
| 6622 | 2 * time.Second, |
| 6623 | 4 * time.Second, |
| 6624 | 8 * time.Second, |
| 6625 | 16 * time.Second, |
| 6626 | 32 * time.Second, |
| 6627 | 60 * time.Second, |
| 6628 | 60 * time.Second, |
| 6629 | 60 * time.Second, |
| 6630 | 60 * time.Second, |
| 6631 | 60 * time.Second, |
| 6632 | } |
| 6633 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6634 | func addDTLSRetransmitTests() { |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6635 | // These tests work by coordinating some behavior on both the shim and |
| 6636 | // the runner. |
| 6637 | // |
| 6638 | // TimeoutSchedule configures the runner to send a series of timeout |
| 6639 | // opcodes to the shim (see packetAdaptor) immediately before reading |
| 6640 | // each peer handshake flight N. The timeout opcode both simulates a |
| 6641 | // timeout in the shim and acts as a synchronization point to help the |
| 6642 | // runner bracket each handshake flight. |
| 6643 | // |
| 6644 | // We assume the shim does not read from the channel eagerly. It must |
| 6645 | // first wait until it has sent flight N and is ready to receive |
| 6646 | // handshake flight N+1. At this point, it will process the timeout |
| 6647 | // opcode. It must then immediately respond with a timeout ACK and act |
| 6648 | // as if the shim was idle for the specified amount of time. |
| 6649 | // |
| 6650 | // The runner then drops all packets received before the ACK and |
| 6651 | // continues waiting for flight N. This ordering results in one attempt |
| 6652 | // at sending flight N to be dropped. For the test to complete, the |
| 6653 | // shim must send flight N again, testing that the shim implements DTLS |
| 6654 | // retransmit on a timeout. |
| 6655 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6656 | // TODO(davidben): Add DTLS 1.3 versions of these tests. There will |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6657 | // likely be more epochs to cross and the final message's retransmit may |
| 6658 | // be more complex. |
| 6659 | |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6660 | for _, async := range []bool{true, false} { |
| 6661 | var tests []testCase |
| 6662 | |
| 6663 | // Test that this is indeed the timeout schedule. Stress all |
| 6664 | // four patterns of handshake. |
| 6665 | for i := 1; i < len(timeouts); i++ { |
| 6666 | number := strconv.Itoa(i) |
| 6667 | tests = append(tests, testCase{ |
| 6668 | protocol: dtls, |
| 6669 | name: "DTLS-Retransmit-Client-" + number, |
| 6670 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6671 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6672 | Bugs: ProtocolBugs{ |
| 6673 | TimeoutSchedule: timeouts[:i], |
| 6674 | }, |
| 6675 | }, |
| 6676 | resumeSession: true, |
| 6677 | }) |
| 6678 | tests = append(tests, testCase{ |
| 6679 | protocol: dtls, |
| 6680 | testType: serverTest, |
| 6681 | name: "DTLS-Retransmit-Server-" + number, |
| 6682 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6683 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6684 | Bugs: ProtocolBugs{ |
| 6685 | TimeoutSchedule: timeouts[:i], |
| 6686 | }, |
| 6687 | }, |
| 6688 | resumeSession: true, |
| 6689 | }) |
| 6690 | } |
| 6691 | |
| 6692 | // Test that exceeding the timeout schedule hits a read |
| 6693 | // timeout. |
| 6694 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6695 | protocol: dtls, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6696 | name: "DTLS-Retransmit-Timeout", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6697 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6698 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6699 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6700 | TimeoutSchedule: timeouts, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6701 | }, |
| 6702 | }, |
| 6703 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6704 | shouldFail: true, |
| 6705 | expectedError: ":READ_TIMEOUT_EXPIRED:", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6706 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6707 | |
| 6708 | if async { |
| 6709 | // Test that timeout handling has a fudge factor, due to API |
| 6710 | // problems. |
| 6711 | tests = append(tests, testCase{ |
| 6712 | protocol: dtls, |
| 6713 | name: "DTLS-Retransmit-Fudge", |
| 6714 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6715 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6716 | Bugs: ProtocolBugs{ |
| 6717 | TimeoutSchedule: []time.Duration{ |
| 6718 | timeouts[0] - 10*time.Millisecond, |
| 6719 | }, |
| 6720 | }, |
| 6721 | }, |
| 6722 | resumeSession: true, |
| 6723 | }) |
| 6724 | } |
| 6725 | |
| 6726 | // Test that the final Finished retransmitting isn't |
| 6727 | // duplicated if the peer badly fragments everything. |
| 6728 | tests = append(tests, testCase{ |
| 6729 | testType: serverTest, |
| 6730 | protocol: dtls, |
| 6731 | name: "DTLS-Retransmit-Fragmented", |
| 6732 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6733 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6734 | Bugs: ProtocolBugs{ |
| 6735 | TimeoutSchedule: []time.Duration{timeouts[0]}, |
| 6736 | MaxHandshakeRecordLength: 2, |
| 6737 | }, |
| 6738 | }, |
| 6739 | }) |
| 6740 | |
| 6741 | // Test the timeout schedule when a shorter initial timeout duration is set. |
| 6742 | tests = append(tests, testCase{ |
| 6743 | protocol: dtls, |
| 6744 | name: "DTLS-Retransmit-Short-Client", |
| 6745 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6746 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6747 | Bugs: ProtocolBugs{ |
| 6748 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
| 6749 | }, |
| 6750 | }, |
| 6751 | resumeSession: true, |
| 6752 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
| 6753 | }) |
| 6754 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6755 | protocol: dtls, |
| 6756 | testType: serverTest, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6757 | name: "DTLS-Retransmit-Short-Server", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6758 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6759 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6760 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6761 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6762 | }, |
| 6763 | }, |
| 6764 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6765 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6766 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6767 | |
| 6768 | for _, test := range tests { |
| 6769 | if async { |
| 6770 | test.name += "-Async" |
| 6771 | test.flags = append(test.flags, "-async") |
| 6772 | } |
| 6773 | |
| 6774 | testCases = append(testCases, test) |
| 6775 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6776 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6777 | } |
| 6778 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 6779 | func addExportKeyingMaterialTests() { |
| 6780 | for _, vers := range tlsVersions { |
| 6781 | if vers.version == VersionSSL30 { |
| 6782 | continue |
| 6783 | } |
| 6784 | testCases = append(testCases, testCase{ |
| 6785 | name: "ExportKeyingMaterial-" + vers.name, |
| 6786 | config: Config{ |
| 6787 | MaxVersion: vers.version, |
| 6788 | }, |
| 6789 | exportKeyingMaterial: 1024, |
| 6790 | exportLabel: "label", |
| 6791 | exportContext: "context", |
| 6792 | useExportContext: true, |
| 6793 | }) |
| 6794 | testCases = append(testCases, testCase{ |
| 6795 | name: "ExportKeyingMaterial-NoContext-" + vers.name, |
| 6796 | config: Config{ |
| 6797 | MaxVersion: vers.version, |
| 6798 | }, |
| 6799 | exportKeyingMaterial: 1024, |
| 6800 | }) |
| 6801 | testCases = append(testCases, testCase{ |
| 6802 | name: "ExportKeyingMaterial-EmptyContext-" + vers.name, |
| 6803 | config: Config{ |
| 6804 | MaxVersion: vers.version, |
| 6805 | }, |
| 6806 | exportKeyingMaterial: 1024, |
| 6807 | useExportContext: true, |
| 6808 | }) |
| 6809 | testCases = append(testCases, testCase{ |
| 6810 | name: "ExportKeyingMaterial-Small-" + vers.name, |
| 6811 | config: Config{ |
| 6812 | MaxVersion: vers.version, |
| 6813 | }, |
| 6814 | exportKeyingMaterial: 1, |
| 6815 | exportLabel: "label", |
| 6816 | exportContext: "context", |
| 6817 | useExportContext: true, |
| 6818 | }) |
| 6819 | } |
| 6820 | testCases = append(testCases, testCase{ |
| 6821 | name: "ExportKeyingMaterial-SSL3", |
| 6822 | config: Config{ |
| 6823 | MaxVersion: VersionSSL30, |
| 6824 | }, |
| 6825 | exportKeyingMaterial: 1024, |
| 6826 | exportLabel: "label", |
| 6827 | exportContext: "context", |
| 6828 | useExportContext: true, |
| 6829 | shouldFail: true, |
| 6830 | expectedError: "failed to export keying material", |
| 6831 | }) |
| 6832 | } |
| 6833 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6834 | func addTLSUniqueTests() { |
| 6835 | for _, isClient := range []bool{false, true} { |
| 6836 | for _, isResumption := range []bool{false, true} { |
| 6837 | for _, hasEMS := range []bool{false, true} { |
| 6838 | var suffix string |
| 6839 | if isResumption { |
| 6840 | suffix = "Resume-" |
| 6841 | } else { |
| 6842 | suffix = "Full-" |
| 6843 | } |
| 6844 | |
| 6845 | if hasEMS { |
| 6846 | suffix += "EMS-" |
| 6847 | } else { |
| 6848 | suffix += "NoEMS-" |
| 6849 | } |
| 6850 | |
| 6851 | if isClient { |
| 6852 | suffix += "Client" |
| 6853 | } else { |
| 6854 | suffix += "Server" |
| 6855 | } |
| 6856 | |
| 6857 | test := testCase{ |
| 6858 | name: "TLSUnique-" + suffix, |
| 6859 | testTLSUnique: true, |
| 6860 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6861 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6862 | Bugs: ProtocolBugs{ |
| 6863 | NoExtendedMasterSecret: !hasEMS, |
| 6864 | }, |
| 6865 | }, |
| 6866 | } |
| 6867 | |
| 6868 | if isResumption { |
| 6869 | test.resumeSession = true |
| 6870 | test.resumeConfig = &Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6871 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6872 | Bugs: ProtocolBugs{ |
| 6873 | NoExtendedMasterSecret: !hasEMS, |
| 6874 | }, |
| 6875 | } |
| 6876 | } |
| 6877 | |
| 6878 | if isResumption && !hasEMS { |
| 6879 | test.shouldFail = true |
| 6880 | test.expectedError = "failed to get tls-unique" |
| 6881 | } |
| 6882 | |
| 6883 | testCases = append(testCases, test) |
| 6884 | } |
| 6885 | } |
| 6886 | } |
| 6887 | } |
| 6888 | |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6889 | func addCustomExtensionTests() { |
| 6890 | expectedContents := "custom extension" |
| 6891 | emptyString := "" |
| 6892 | |
| 6893 | for _, isClient := range []bool{false, true} { |
| 6894 | suffix := "Server" |
| 6895 | flag := "-enable-server-custom-extension" |
| 6896 | testType := serverTest |
| 6897 | if isClient { |
| 6898 | suffix = "Client" |
| 6899 | flag = "-enable-client-custom-extension" |
| 6900 | testType = clientTest |
| 6901 | } |
| 6902 | |
| 6903 | testCases = append(testCases, testCase{ |
| 6904 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6905 | name: "CustomExtensions-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6906 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6907 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6908 | Bugs: ProtocolBugs{ |
| 6909 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6910 | ExpectedCustomExtension: &expectedContents, |
| 6911 | }, |
| 6912 | }, |
| 6913 | flags: []string{flag}, |
| 6914 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6915 | testCases = append(testCases, testCase{ |
| 6916 | testType: testType, |
| 6917 | name: "CustomExtensions-" + suffix + "-TLS13", |
| 6918 | config: Config{ |
| 6919 | MaxVersion: VersionTLS13, |
| 6920 | Bugs: ProtocolBugs{ |
| 6921 | CustomExtension: expectedContents, |
| 6922 | ExpectedCustomExtension: &expectedContents, |
| 6923 | }, |
| 6924 | }, |
| 6925 | flags: []string{flag}, |
| 6926 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6927 | |
| 6928 | // If the parse callback fails, the handshake should also fail. |
| 6929 | testCases = append(testCases, testCase{ |
| 6930 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6931 | name: "CustomExtensions-ParseError-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6932 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6933 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6934 | Bugs: ProtocolBugs{ |
| 6935 | CustomExtension: expectedContents + "foo", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6936 | ExpectedCustomExtension: &expectedContents, |
| 6937 | }, |
| 6938 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6939 | flags: []string{flag}, |
| 6940 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6941 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6942 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6943 | testCases = append(testCases, testCase{ |
| 6944 | testType: testType, |
| 6945 | name: "CustomExtensions-ParseError-" + suffix + "-TLS13", |
| 6946 | config: Config{ |
| 6947 | MaxVersion: VersionTLS13, |
| 6948 | Bugs: ProtocolBugs{ |
| 6949 | CustomExtension: expectedContents + "foo", |
| 6950 | ExpectedCustomExtension: &expectedContents, |
| 6951 | }, |
| 6952 | }, |
| 6953 | flags: []string{flag}, |
| 6954 | shouldFail: true, |
| 6955 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6956 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6957 | |
| 6958 | // If the add callback fails, the handshake should also fail. |
| 6959 | testCases = append(testCases, testCase{ |
| 6960 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6961 | name: "CustomExtensions-FailAdd-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6962 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6963 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6964 | Bugs: ProtocolBugs{ |
| 6965 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6966 | ExpectedCustomExtension: &expectedContents, |
| 6967 | }, |
| 6968 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6969 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 6970 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6971 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6972 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6973 | testCases = append(testCases, testCase{ |
| 6974 | testType: testType, |
| 6975 | name: "CustomExtensions-FailAdd-" + suffix + "-TLS13", |
| 6976 | config: Config{ |
| 6977 | MaxVersion: VersionTLS13, |
| 6978 | Bugs: ProtocolBugs{ |
| 6979 | CustomExtension: expectedContents, |
| 6980 | ExpectedCustomExtension: &expectedContents, |
| 6981 | }, |
| 6982 | }, |
| 6983 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 6984 | shouldFail: true, |
| 6985 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6986 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6987 | |
| 6988 | // If the add callback returns zero, no extension should be |
| 6989 | // added. |
| 6990 | skipCustomExtension := expectedContents |
| 6991 | if isClient { |
| 6992 | // For the case where the client skips sending the |
| 6993 | // custom extension, the server must not “echo” it. |
| 6994 | skipCustomExtension = "" |
| 6995 | } |
| 6996 | testCases = append(testCases, testCase{ |
| 6997 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6998 | name: "CustomExtensions-Skip-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6999 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7000 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 7001 | Bugs: ProtocolBugs{ |
| 7002 | CustomExtension: skipCustomExtension, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7003 | ExpectedCustomExtension: &emptyString, |
| 7004 | }, |
| 7005 | }, |
| 7006 | flags: []string{flag, "-custom-extension-skip"}, |
| 7007 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7008 | testCases = append(testCases, testCase{ |
| 7009 | testType: testType, |
| 7010 | name: "CustomExtensions-Skip-" + suffix + "-TLS13", |
| 7011 | config: Config{ |
| 7012 | MaxVersion: VersionTLS13, |
| 7013 | Bugs: ProtocolBugs{ |
| 7014 | CustomExtension: skipCustomExtension, |
| 7015 | ExpectedCustomExtension: &emptyString, |
| 7016 | }, |
| 7017 | }, |
| 7018 | flags: []string{flag, "-custom-extension-skip"}, |
| 7019 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7020 | } |
| 7021 | |
| 7022 | // The custom extension add callback should not be called if the client |
| 7023 | // doesn't send the extension. |
| 7024 | testCases = append(testCases, testCase{ |
| 7025 | testType: serverTest, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 7026 | name: "CustomExtensions-NotCalled-Server", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7027 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7028 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 7029 | Bugs: ProtocolBugs{ |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7030 | ExpectedCustomExtension: &emptyString, |
| 7031 | }, |
| 7032 | }, |
| 7033 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 7034 | }) |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 7035 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7036 | testCases = append(testCases, testCase{ |
| 7037 | testType: serverTest, |
| 7038 | name: "CustomExtensions-NotCalled-Server-TLS13", |
| 7039 | config: Config{ |
| 7040 | MaxVersion: VersionTLS13, |
| 7041 | Bugs: ProtocolBugs{ |
| 7042 | ExpectedCustomExtension: &emptyString, |
| 7043 | }, |
| 7044 | }, |
| 7045 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 7046 | }) |
| 7047 | |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 7048 | // Test an unknown extension from the server. |
| 7049 | testCases = append(testCases, testCase{ |
| 7050 | testType: clientTest, |
| 7051 | name: "UnknownExtension-Client", |
| 7052 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7053 | MaxVersion: VersionTLS12, |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 7054 | Bugs: ProtocolBugs{ |
| 7055 | CustomExtension: expectedContents, |
| 7056 | }, |
| 7057 | }, |
David Benjamin | 0c40a96 | 2016-08-01 12:05:50 -0400 | [diff] [blame] | 7058 | shouldFail: true, |
| 7059 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7060 | expectedLocalError: "remote error: unsupported extension", |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 7061 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7062 | testCases = append(testCases, testCase{ |
| 7063 | testType: clientTest, |
| 7064 | name: "UnknownExtension-Client-TLS13", |
| 7065 | config: Config{ |
| 7066 | MaxVersion: VersionTLS13, |
| 7067 | Bugs: ProtocolBugs{ |
| 7068 | CustomExtension: expectedContents, |
| 7069 | }, |
| 7070 | }, |
David Benjamin | 0c40a96 | 2016-08-01 12:05:50 -0400 | [diff] [blame] | 7071 | shouldFail: true, |
| 7072 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7073 | expectedLocalError: "remote error: unsupported extension", |
| 7074 | }) |
| 7075 | |
| 7076 | // Test a known but unoffered extension from the server. |
| 7077 | testCases = append(testCases, testCase{ |
| 7078 | testType: clientTest, |
| 7079 | name: "UnofferedExtension-Client", |
| 7080 | config: Config{ |
| 7081 | MaxVersion: VersionTLS12, |
| 7082 | Bugs: ProtocolBugs{ |
| 7083 | SendALPN: "alpn", |
| 7084 | }, |
| 7085 | }, |
| 7086 | shouldFail: true, |
| 7087 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7088 | expectedLocalError: "remote error: unsupported extension", |
| 7089 | }) |
| 7090 | testCases = append(testCases, testCase{ |
| 7091 | testType: clientTest, |
| 7092 | name: "UnofferedExtension-Client-TLS13", |
| 7093 | config: Config{ |
| 7094 | MaxVersion: VersionTLS13, |
| 7095 | Bugs: ProtocolBugs{ |
| 7096 | SendALPN: "alpn", |
| 7097 | }, |
| 7098 | }, |
| 7099 | shouldFail: true, |
| 7100 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7101 | expectedLocalError: "remote error: unsupported extension", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7102 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7103 | } |
| 7104 | |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 7105 | func addRSAClientKeyExchangeTests() { |
| 7106 | for bad := RSABadValue(1); bad < NumRSABadValues; bad++ { |
| 7107 | testCases = append(testCases, testCase{ |
| 7108 | testType: serverTest, |
| 7109 | name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad), |
| 7110 | config: Config{ |
| 7111 | // Ensure the ClientHello version and final |
| 7112 | // version are different, to detect if the |
| 7113 | // server uses the wrong one. |
| 7114 | MaxVersion: VersionTLS11, |
Matt Braithwaite | 07e7806 | 2016-08-21 14:50:43 -0700 | [diff] [blame] | 7115 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 7116 | Bugs: ProtocolBugs{ |
| 7117 | BadRSAClientKeyExchange: bad, |
| 7118 | }, |
| 7119 | }, |
| 7120 | shouldFail: true, |
| 7121 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7122 | }) |
| 7123 | } |
David Benjamin | e63d9d7 | 2016-09-19 18:27:34 -0400 | [diff] [blame] | 7124 | |
| 7125 | // The server must compare whatever was in ClientHello.version for the |
| 7126 | // RSA premaster. |
| 7127 | testCases = append(testCases, testCase{ |
| 7128 | testType: serverTest, |
| 7129 | name: "SendClientVersion-RSA", |
| 7130 | config: Config{ |
| 7131 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 7132 | Bugs: ProtocolBugs{ |
| 7133 | SendClientVersion: 0x1234, |
| 7134 | }, |
| 7135 | }, |
| 7136 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 7137 | }) |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 7138 | } |
| 7139 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7140 | var testCurves = []struct { |
| 7141 | name string |
| 7142 | id CurveID |
| 7143 | }{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7144 | {"P-256", CurveP256}, |
| 7145 | {"P-384", CurveP384}, |
| 7146 | {"P-521", CurveP521}, |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 7147 | {"X25519", CurveX25519}, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7148 | } |
| 7149 | |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7150 | const bogusCurve = 0x1234 |
| 7151 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7152 | func addCurveTests() { |
| 7153 | for _, curve := range testCurves { |
| 7154 | testCases = append(testCases, testCase{ |
| 7155 | name: "CurveTest-Client-" + curve.name, |
| 7156 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7157 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7158 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7159 | CurvePreferences: []CurveID{curve.id}, |
| 7160 | }, |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7161 | flags: []string{ |
| 7162 | "-enable-all-curves", |
| 7163 | "-expect-curve-id", strconv.Itoa(int(curve.id)), |
| 7164 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7165 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7166 | }) |
| 7167 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7168 | name: "CurveTest-Client-" + curve.name + "-TLS13", |
| 7169 | config: Config{ |
| 7170 | MaxVersion: VersionTLS13, |
| 7171 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7172 | CurvePreferences: []CurveID{curve.id}, |
| 7173 | }, |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7174 | flags: []string{ |
| 7175 | "-enable-all-curves", |
| 7176 | "-expect-curve-id", strconv.Itoa(int(curve.id)), |
| 7177 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7178 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7179 | }) |
| 7180 | testCases = append(testCases, testCase{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7181 | testType: serverTest, |
| 7182 | name: "CurveTest-Server-" + curve.name, |
| 7183 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7184 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7185 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7186 | CurvePreferences: []CurveID{curve.id}, |
| 7187 | }, |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7188 | flags: []string{ |
| 7189 | "-enable-all-curves", |
| 7190 | "-expect-curve-id", strconv.Itoa(int(curve.id)), |
| 7191 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7192 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7193 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7194 | testCases = append(testCases, testCase{ |
| 7195 | testType: serverTest, |
| 7196 | name: "CurveTest-Server-" + curve.name + "-TLS13", |
| 7197 | config: Config{ |
| 7198 | MaxVersion: VersionTLS13, |
| 7199 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7200 | CurvePreferences: []CurveID{curve.id}, |
| 7201 | }, |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7202 | flags: []string{ |
| 7203 | "-enable-all-curves", |
| 7204 | "-expect-curve-id", strconv.Itoa(int(curve.id)), |
| 7205 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7206 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7207 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7208 | } |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 7209 | |
| 7210 | // The server must be tolerant to bogus curves. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 7211 | testCases = append(testCases, testCase{ |
| 7212 | testType: serverTest, |
| 7213 | name: "UnknownCurve", |
| 7214 | config: Config{ |
| 7215 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7216 | CurvePreferences: []CurveID{bogusCurve, CurveP256}, |
| 7217 | }, |
| 7218 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7219 | |
| 7220 | // The server must not consider ECDHE ciphers when there are no |
| 7221 | // supported curves. |
| 7222 | testCases = append(testCases, testCase{ |
| 7223 | testType: serverTest, |
| 7224 | name: "NoSupportedCurves", |
| 7225 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7226 | MaxVersion: VersionTLS12, |
| 7227 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7228 | Bugs: ProtocolBugs{ |
| 7229 | NoSupportedCurves: true, |
| 7230 | }, |
| 7231 | }, |
| 7232 | shouldFail: true, |
| 7233 | expectedError: ":NO_SHARED_CIPHER:", |
| 7234 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7235 | testCases = append(testCases, testCase{ |
| 7236 | testType: serverTest, |
| 7237 | name: "NoSupportedCurves-TLS13", |
| 7238 | config: Config{ |
| 7239 | MaxVersion: VersionTLS13, |
| 7240 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7241 | Bugs: ProtocolBugs{ |
| 7242 | NoSupportedCurves: true, |
| 7243 | }, |
| 7244 | }, |
| 7245 | shouldFail: true, |
| 7246 | expectedError: ":NO_SHARED_CIPHER:", |
| 7247 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7248 | |
| 7249 | // The server must fall back to another cipher when there are no |
| 7250 | // supported curves. |
| 7251 | testCases = append(testCases, testCase{ |
| 7252 | testType: serverTest, |
| 7253 | name: "NoCommonCurves", |
| 7254 | config: Config{ |
| 7255 | MaxVersion: VersionTLS12, |
| 7256 | CipherSuites: []uint16{ |
| 7257 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 7258 | TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 7259 | }, |
| 7260 | CurvePreferences: []CurveID{CurveP224}, |
| 7261 | }, |
| 7262 | expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 7263 | }) |
| 7264 | |
| 7265 | // The client must reject bogus curves and disabled curves. |
| 7266 | testCases = append(testCases, testCase{ |
| 7267 | name: "BadECDHECurve", |
| 7268 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7269 | MaxVersion: VersionTLS12, |
| 7270 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7271 | Bugs: ProtocolBugs{ |
| 7272 | SendCurve: bogusCurve, |
| 7273 | }, |
| 7274 | }, |
| 7275 | shouldFail: true, |
| 7276 | expectedError: ":WRONG_CURVE:", |
| 7277 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7278 | testCases = append(testCases, testCase{ |
| 7279 | name: "BadECDHECurve-TLS13", |
| 7280 | config: Config{ |
| 7281 | MaxVersion: VersionTLS13, |
| 7282 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7283 | Bugs: ProtocolBugs{ |
| 7284 | SendCurve: bogusCurve, |
| 7285 | }, |
| 7286 | }, |
| 7287 | shouldFail: true, |
| 7288 | expectedError: ":WRONG_CURVE:", |
| 7289 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7290 | |
| 7291 | testCases = append(testCases, testCase{ |
| 7292 | name: "UnsupportedCurve", |
| 7293 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7294 | MaxVersion: VersionTLS12, |
| 7295 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7296 | CurvePreferences: []CurveID{CurveP256}, |
| 7297 | Bugs: ProtocolBugs{ |
| 7298 | IgnorePeerCurvePreferences: true, |
| 7299 | }, |
| 7300 | }, |
| 7301 | flags: []string{"-p384-only"}, |
| 7302 | shouldFail: true, |
| 7303 | expectedError: ":WRONG_CURVE:", |
| 7304 | }) |
| 7305 | |
David Benjamin | 4f92157 | 2016-07-17 14:20:10 +0200 | [diff] [blame] | 7306 | testCases = append(testCases, testCase{ |
| 7307 | // TODO(davidben): Add a TLS 1.3 version where |
| 7308 | // HelloRetryRequest requests an unsupported curve. |
| 7309 | name: "UnsupportedCurve-ServerHello-TLS13", |
| 7310 | config: Config{ |
| 7311 | MaxVersion: VersionTLS12, |
| 7312 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7313 | CurvePreferences: []CurveID{CurveP384}, |
| 7314 | Bugs: ProtocolBugs{ |
| 7315 | SendCurve: CurveP256, |
| 7316 | }, |
| 7317 | }, |
| 7318 | flags: []string{"-p384-only"}, |
| 7319 | shouldFail: true, |
| 7320 | expectedError: ":WRONG_CURVE:", |
| 7321 | }) |
| 7322 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7323 | // Test invalid curve points. |
| 7324 | testCases = append(testCases, testCase{ |
| 7325 | name: "InvalidECDHPoint-Client", |
| 7326 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7327 | MaxVersion: VersionTLS12, |
| 7328 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7329 | CurvePreferences: []CurveID{CurveP256}, |
| 7330 | Bugs: ProtocolBugs{ |
| 7331 | InvalidECDHPoint: true, |
| 7332 | }, |
| 7333 | }, |
| 7334 | shouldFail: true, |
| 7335 | expectedError: ":INVALID_ENCODING:", |
| 7336 | }) |
| 7337 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7338 | name: "InvalidECDHPoint-Client-TLS13", |
| 7339 | config: Config{ |
| 7340 | MaxVersion: VersionTLS13, |
| 7341 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7342 | CurvePreferences: []CurveID{CurveP256}, |
| 7343 | Bugs: ProtocolBugs{ |
| 7344 | InvalidECDHPoint: true, |
| 7345 | }, |
| 7346 | }, |
| 7347 | shouldFail: true, |
| 7348 | expectedError: ":INVALID_ENCODING:", |
| 7349 | }) |
| 7350 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7351 | testType: serverTest, |
| 7352 | name: "InvalidECDHPoint-Server", |
| 7353 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 7354 | MaxVersion: VersionTLS12, |
| 7355 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7356 | CurvePreferences: []CurveID{CurveP256}, |
| 7357 | Bugs: ProtocolBugs{ |
| 7358 | InvalidECDHPoint: true, |
| 7359 | }, |
| 7360 | }, |
| 7361 | shouldFail: true, |
| 7362 | expectedError: ":INVALID_ENCODING:", |
| 7363 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7364 | testCases = append(testCases, testCase{ |
| 7365 | testType: serverTest, |
| 7366 | name: "InvalidECDHPoint-Server-TLS13", |
| 7367 | config: Config{ |
| 7368 | MaxVersion: VersionTLS13, |
| 7369 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7370 | CurvePreferences: []CurveID{CurveP256}, |
| 7371 | Bugs: ProtocolBugs{ |
| 7372 | InvalidECDHPoint: true, |
| 7373 | }, |
| 7374 | }, |
| 7375 | shouldFail: true, |
| 7376 | expectedError: ":INVALID_ENCODING:", |
| 7377 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7378 | } |
| 7379 | |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7380 | func addCECPQ1Tests() { |
| 7381 | testCases = append(testCases, testCase{ |
| 7382 | testType: clientTest, |
| 7383 | name: "CECPQ1-Client-BadX25519Part", |
| 7384 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7385 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7386 | MinVersion: VersionTLS12, |
| 7387 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 7388 | Bugs: ProtocolBugs{ |
| 7389 | CECPQ1BadX25519Part: true, |
| 7390 | }, |
| 7391 | }, |
| 7392 | flags: []string{"-cipher", "kCECPQ1"}, |
| 7393 | shouldFail: true, |
| 7394 | expectedLocalError: "local error: bad record MAC", |
| 7395 | }) |
| 7396 | testCases = append(testCases, testCase{ |
| 7397 | testType: clientTest, |
| 7398 | name: "CECPQ1-Client-BadNewhopePart", |
| 7399 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7400 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7401 | MinVersion: VersionTLS12, |
| 7402 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 7403 | Bugs: ProtocolBugs{ |
| 7404 | CECPQ1BadNewhopePart: true, |
| 7405 | }, |
| 7406 | }, |
| 7407 | flags: []string{"-cipher", "kCECPQ1"}, |
| 7408 | shouldFail: true, |
| 7409 | expectedLocalError: "local error: bad record MAC", |
| 7410 | }) |
| 7411 | testCases = append(testCases, testCase{ |
| 7412 | testType: serverTest, |
| 7413 | name: "CECPQ1-Server-BadX25519Part", |
| 7414 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7415 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7416 | MinVersion: VersionTLS12, |
| 7417 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 7418 | Bugs: ProtocolBugs{ |
| 7419 | CECPQ1BadX25519Part: true, |
| 7420 | }, |
| 7421 | }, |
| 7422 | flags: []string{"-cipher", "kCECPQ1"}, |
| 7423 | shouldFail: true, |
| 7424 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7425 | }) |
| 7426 | testCases = append(testCases, testCase{ |
| 7427 | testType: serverTest, |
| 7428 | name: "CECPQ1-Server-BadNewhopePart", |
| 7429 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7430 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7431 | MinVersion: VersionTLS12, |
| 7432 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 7433 | Bugs: ProtocolBugs{ |
| 7434 | CECPQ1BadNewhopePart: true, |
| 7435 | }, |
| 7436 | }, |
| 7437 | flags: []string{"-cipher", "kCECPQ1"}, |
| 7438 | shouldFail: true, |
| 7439 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7440 | }) |
| 7441 | } |
| 7442 | |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7443 | func addDHEGroupSizeTests() { |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7444 | testCases = append(testCases, testCase{ |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7445 | name: "DHEGroupSize-Client", |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7446 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7447 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7448 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7449 | Bugs: ProtocolBugs{ |
| 7450 | // This is a 1234-bit prime number, generated |
| 7451 | // with: |
| 7452 | // openssl gendh 1234 | openssl asn1parse -i |
| 7453 | DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"), |
| 7454 | }, |
| 7455 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 7456 | flags: []string{"-expect-dhe-group-size", "1234"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7457 | }) |
| 7458 | testCases = append(testCases, testCase{ |
| 7459 | testType: serverTest, |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 7460 | name: "DHEGroupSize-Server", |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7461 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7462 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7463 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7464 | }, |
| 7465 | // bssl_shim as a server configures a 2048-bit DHE group. |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 7466 | flags: []string{"-expect-dhe-group-size", "2048"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7467 | }) |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7468 | } |
| 7469 | |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 7470 | func addTLS13RecordTests() { |
| 7471 | testCases = append(testCases, testCase{ |
| 7472 | name: "TLS13-RecordPadding", |
| 7473 | config: Config{ |
| 7474 | MaxVersion: VersionTLS13, |
| 7475 | MinVersion: VersionTLS13, |
| 7476 | Bugs: ProtocolBugs{ |
| 7477 | RecordPadding: 10, |
| 7478 | }, |
| 7479 | }, |
| 7480 | }) |
| 7481 | |
| 7482 | testCases = append(testCases, testCase{ |
| 7483 | name: "TLS13-EmptyRecords", |
| 7484 | config: Config{ |
| 7485 | MaxVersion: VersionTLS13, |
| 7486 | MinVersion: VersionTLS13, |
| 7487 | Bugs: ProtocolBugs{ |
| 7488 | OmitRecordContents: true, |
| 7489 | }, |
| 7490 | }, |
| 7491 | shouldFail: true, |
| 7492 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7493 | }) |
| 7494 | |
| 7495 | testCases = append(testCases, testCase{ |
| 7496 | name: "TLS13-OnlyPadding", |
| 7497 | config: Config{ |
| 7498 | MaxVersion: VersionTLS13, |
| 7499 | MinVersion: VersionTLS13, |
| 7500 | Bugs: ProtocolBugs{ |
| 7501 | OmitRecordContents: true, |
| 7502 | RecordPadding: 10, |
| 7503 | }, |
| 7504 | }, |
| 7505 | shouldFail: true, |
| 7506 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7507 | }) |
| 7508 | |
| 7509 | testCases = append(testCases, testCase{ |
| 7510 | name: "TLS13-WrongOuterRecord", |
| 7511 | config: Config{ |
| 7512 | MaxVersion: VersionTLS13, |
| 7513 | MinVersion: VersionTLS13, |
| 7514 | Bugs: ProtocolBugs{ |
| 7515 | OuterRecordType: recordTypeHandshake, |
| 7516 | }, |
| 7517 | }, |
| 7518 | shouldFail: true, |
| 7519 | expectedError: ":INVALID_OUTER_RECORD_TYPE:", |
| 7520 | }) |
| 7521 | } |
| 7522 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7523 | func addChangeCipherSpecTests() { |
| 7524 | // Test missing ChangeCipherSpecs. |
| 7525 | testCases = append(testCases, testCase{ |
| 7526 | name: "SkipChangeCipherSpec-Client", |
| 7527 | config: Config{ |
| 7528 | MaxVersion: VersionTLS12, |
| 7529 | Bugs: ProtocolBugs{ |
| 7530 | SkipChangeCipherSpec: true, |
| 7531 | }, |
| 7532 | }, |
| 7533 | shouldFail: true, |
| 7534 | expectedError: ":UNEXPECTED_RECORD:", |
| 7535 | }) |
| 7536 | testCases = append(testCases, testCase{ |
| 7537 | testType: serverTest, |
| 7538 | name: "SkipChangeCipherSpec-Server", |
| 7539 | config: Config{ |
| 7540 | MaxVersion: VersionTLS12, |
| 7541 | Bugs: ProtocolBugs{ |
| 7542 | SkipChangeCipherSpec: true, |
| 7543 | }, |
| 7544 | }, |
| 7545 | shouldFail: true, |
| 7546 | expectedError: ":UNEXPECTED_RECORD:", |
| 7547 | }) |
| 7548 | testCases = append(testCases, testCase{ |
| 7549 | testType: serverTest, |
| 7550 | name: "SkipChangeCipherSpec-Server-NPN", |
| 7551 | config: Config{ |
| 7552 | MaxVersion: VersionTLS12, |
| 7553 | NextProtos: []string{"bar"}, |
| 7554 | Bugs: ProtocolBugs{ |
| 7555 | SkipChangeCipherSpec: true, |
| 7556 | }, |
| 7557 | }, |
| 7558 | flags: []string{ |
| 7559 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 7560 | }, |
| 7561 | shouldFail: true, |
| 7562 | expectedError: ":UNEXPECTED_RECORD:", |
| 7563 | }) |
| 7564 | |
| 7565 | // Test synchronization between the handshake and ChangeCipherSpec. |
| 7566 | // Partial post-CCS handshake messages before ChangeCipherSpec should be |
| 7567 | // rejected. Test both with and without handshake packing to handle both |
| 7568 | // when the partial post-CCS message is in its own record and when it is |
| 7569 | // attached to the pre-CCS message. |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7570 | for _, packed := range []bool{false, true} { |
| 7571 | var suffix string |
| 7572 | if packed { |
| 7573 | suffix = "-Packed" |
| 7574 | } |
| 7575 | |
| 7576 | testCases = append(testCases, testCase{ |
| 7577 | name: "FragmentAcrossChangeCipherSpec-Client" + suffix, |
| 7578 | config: Config{ |
| 7579 | MaxVersion: VersionTLS12, |
| 7580 | Bugs: ProtocolBugs{ |
| 7581 | FragmentAcrossChangeCipherSpec: true, |
| 7582 | PackHandshakeFlight: packed, |
| 7583 | }, |
| 7584 | }, |
| 7585 | shouldFail: true, |
| 7586 | expectedError: ":UNEXPECTED_RECORD:", |
| 7587 | }) |
| 7588 | testCases = append(testCases, testCase{ |
| 7589 | name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix, |
| 7590 | config: Config{ |
| 7591 | MaxVersion: VersionTLS12, |
| 7592 | }, |
| 7593 | resumeSession: true, |
| 7594 | resumeConfig: &Config{ |
| 7595 | MaxVersion: VersionTLS12, |
| 7596 | Bugs: ProtocolBugs{ |
| 7597 | FragmentAcrossChangeCipherSpec: true, |
| 7598 | PackHandshakeFlight: packed, |
| 7599 | }, |
| 7600 | }, |
| 7601 | shouldFail: true, |
| 7602 | expectedError: ":UNEXPECTED_RECORD:", |
| 7603 | }) |
| 7604 | testCases = append(testCases, testCase{ |
| 7605 | testType: serverTest, |
| 7606 | name: "FragmentAcrossChangeCipherSpec-Server" + suffix, |
| 7607 | config: Config{ |
| 7608 | MaxVersion: VersionTLS12, |
| 7609 | Bugs: ProtocolBugs{ |
| 7610 | FragmentAcrossChangeCipherSpec: true, |
| 7611 | PackHandshakeFlight: packed, |
| 7612 | }, |
| 7613 | }, |
| 7614 | shouldFail: true, |
| 7615 | expectedError: ":UNEXPECTED_RECORD:", |
| 7616 | }) |
| 7617 | testCases = append(testCases, testCase{ |
| 7618 | testType: serverTest, |
| 7619 | name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix, |
| 7620 | config: Config{ |
| 7621 | MaxVersion: VersionTLS12, |
| 7622 | }, |
| 7623 | resumeSession: true, |
| 7624 | resumeConfig: &Config{ |
| 7625 | MaxVersion: VersionTLS12, |
| 7626 | Bugs: ProtocolBugs{ |
| 7627 | FragmentAcrossChangeCipherSpec: true, |
| 7628 | PackHandshakeFlight: packed, |
| 7629 | }, |
| 7630 | }, |
| 7631 | shouldFail: true, |
| 7632 | expectedError: ":UNEXPECTED_RECORD:", |
| 7633 | }) |
| 7634 | testCases = append(testCases, testCase{ |
| 7635 | testType: serverTest, |
| 7636 | name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix, |
| 7637 | config: Config{ |
| 7638 | MaxVersion: VersionTLS12, |
| 7639 | NextProtos: []string{"bar"}, |
| 7640 | Bugs: ProtocolBugs{ |
| 7641 | FragmentAcrossChangeCipherSpec: true, |
| 7642 | PackHandshakeFlight: packed, |
| 7643 | }, |
| 7644 | }, |
| 7645 | flags: []string{ |
| 7646 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 7647 | }, |
| 7648 | shouldFail: true, |
| 7649 | expectedError: ":UNEXPECTED_RECORD:", |
| 7650 | }) |
| 7651 | } |
| 7652 | |
David Benjamin | 6167281 | 2016-07-14 23:10:43 -0400 | [diff] [blame] | 7653 | // Test that, in DTLS, ChangeCipherSpec is not allowed when there are |
| 7654 | // messages in the handshake queue. Do this by testing the server |
| 7655 | // reading the client Finished, reversing the flight so Finished comes |
| 7656 | // first. |
| 7657 | testCases = append(testCases, testCase{ |
| 7658 | protocol: dtls, |
| 7659 | testType: serverTest, |
| 7660 | name: "SendUnencryptedFinished-DTLS", |
| 7661 | config: Config{ |
| 7662 | MaxVersion: VersionTLS12, |
| 7663 | Bugs: ProtocolBugs{ |
| 7664 | SendUnencryptedFinished: true, |
| 7665 | ReverseHandshakeFragments: true, |
| 7666 | }, |
| 7667 | }, |
| 7668 | shouldFail: true, |
| 7669 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7670 | }) |
| 7671 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7672 | // Test synchronization between encryption changes and the handshake in |
| 7673 | // TLS 1.3, where ChangeCipherSpec is implicit. |
| 7674 | testCases = append(testCases, testCase{ |
| 7675 | name: "PartialEncryptedExtensionsWithServerHello", |
| 7676 | config: Config{ |
| 7677 | MaxVersion: VersionTLS13, |
| 7678 | Bugs: ProtocolBugs{ |
| 7679 | PartialEncryptedExtensionsWithServerHello: true, |
| 7680 | }, |
| 7681 | }, |
| 7682 | shouldFail: true, |
| 7683 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7684 | }) |
| 7685 | testCases = append(testCases, testCase{ |
| 7686 | testType: serverTest, |
| 7687 | name: "PartialClientFinishedWithClientHello", |
| 7688 | config: Config{ |
| 7689 | MaxVersion: VersionTLS13, |
| 7690 | Bugs: ProtocolBugs{ |
| 7691 | PartialClientFinishedWithClientHello: true, |
| 7692 | }, |
| 7693 | }, |
| 7694 | shouldFail: true, |
| 7695 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7696 | }) |
| 7697 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7698 | // Test that early ChangeCipherSpecs are handled correctly. |
| 7699 | testCases = append(testCases, testCase{ |
| 7700 | testType: serverTest, |
| 7701 | name: "EarlyChangeCipherSpec-server-1", |
| 7702 | config: Config{ |
| 7703 | MaxVersion: VersionTLS12, |
| 7704 | Bugs: ProtocolBugs{ |
| 7705 | EarlyChangeCipherSpec: 1, |
| 7706 | }, |
| 7707 | }, |
| 7708 | shouldFail: true, |
| 7709 | expectedError: ":UNEXPECTED_RECORD:", |
| 7710 | }) |
| 7711 | testCases = append(testCases, testCase{ |
| 7712 | testType: serverTest, |
| 7713 | name: "EarlyChangeCipherSpec-server-2", |
| 7714 | config: Config{ |
| 7715 | MaxVersion: VersionTLS12, |
| 7716 | Bugs: ProtocolBugs{ |
| 7717 | EarlyChangeCipherSpec: 2, |
| 7718 | }, |
| 7719 | }, |
| 7720 | shouldFail: true, |
| 7721 | expectedError: ":UNEXPECTED_RECORD:", |
| 7722 | }) |
| 7723 | testCases = append(testCases, testCase{ |
| 7724 | protocol: dtls, |
| 7725 | name: "StrayChangeCipherSpec", |
| 7726 | config: Config{ |
| 7727 | // TODO(davidben): Once DTLS 1.3 exists, test |
| 7728 | // that stray ChangeCipherSpec messages are |
| 7729 | // rejected. |
| 7730 | MaxVersion: VersionTLS12, |
| 7731 | Bugs: ProtocolBugs{ |
| 7732 | StrayChangeCipherSpec: true, |
| 7733 | }, |
| 7734 | }, |
| 7735 | }) |
| 7736 | |
| 7737 | // Test that the contents of ChangeCipherSpec are checked. |
| 7738 | testCases = append(testCases, testCase{ |
| 7739 | name: "BadChangeCipherSpec-1", |
| 7740 | config: Config{ |
| 7741 | MaxVersion: VersionTLS12, |
| 7742 | Bugs: ProtocolBugs{ |
| 7743 | BadChangeCipherSpec: []byte{2}, |
| 7744 | }, |
| 7745 | }, |
| 7746 | shouldFail: true, |
| 7747 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7748 | }) |
| 7749 | testCases = append(testCases, testCase{ |
| 7750 | name: "BadChangeCipherSpec-2", |
| 7751 | config: Config{ |
| 7752 | MaxVersion: VersionTLS12, |
| 7753 | Bugs: ProtocolBugs{ |
| 7754 | BadChangeCipherSpec: []byte{1, 1}, |
| 7755 | }, |
| 7756 | }, |
| 7757 | shouldFail: true, |
| 7758 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7759 | }) |
| 7760 | testCases = append(testCases, testCase{ |
| 7761 | protocol: dtls, |
| 7762 | name: "BadChangeCipherSpec-DTLS-1", |
| 7763 | config: Config{ |
| 7764 | MaxVersion: VersionTLS12, |
| 7765 | Bugs: ProtocolBugs{ |
| 7766 | BadChangeCipherSpec: []byte{2}, |
| 7767 | }, |
| 7768 | }, |
| 7769 | shouldFail: true, |
| 7770 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7771 | }) |
| 7772 | testCases = append(testCases, testCase{ |
| 7773 | protocol: dtls, |
| 7774 | name: "BadChangeCipherSpec-DTLS-2", |
| 7775 | config: Config{ |
| 7776 | MaxVersion: VersionTLS12, |
| 7777 | Bugs: ProtocolBugs{ |
| 7778 | BadChangeCipherSpec: []byte{1, 1}, |
| 7779 | }, |
| 7780 | }, |
| 7781 | shouldFail: true, |
| 7782 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7783 | }) |
| 7784 | } |
| 7785 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7786 | type perMessageTest struct { |
| 7787 | messageType uint8 |
| 7788 | test testCase |
| 7789 | } |
| 7790 | |
| 7791 | // makePerMessageTests returns a series of test templates which cover each |
| 7792 | // message in the TLS handshake. These may be used with bugs like |
| 7793 | // WrongMessageType to fully test a per-message bug. |
| 7794 | func makePerMessageTests() []perMessageTest { |
| 7795 | var ret []perMessageTest |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7796 | for _, protocol := range []protocol{tls, dtls} { |
| 7797 | var suffix string |
| 7798 | if protocol == dtls { |
| 7799 | suffix = "-DTLS" |
| 7800 | } |
| 7801 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7802 | ret = append(ret, perMessageTest{ |
| 7803 | messageType: typeClientHello, |
| 7804 | test: testCase{ |
| 7805 | protocol: protocol, |
| 7806 | testType: serverTest, |
| 7807 | name: "ClientHello" + suffix, |
| 7808 | config: Config{ |
| 7809 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7810 | }, |
| 7811 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7812 | }) |
| 7813 | |
| 7814 | if protocol == dtls { |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7815 | ret = append(ret, perMessageTest{ |
| 7816 | messageType: typeHelloVerifyRequest, |
| 7817 | test: testCase{ |
| 7818 | protocol: protocol, |
| 7819 | name: "HelloVerifyRequest" + suffix, |
| 7820 | config: Config{ |
| 7821 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7822 | }, |
| 7823 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7824 | }) |
| 7825 | } |
| 7826 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7827 | ret = append(ret, perMessageTest{ |
| 7828 | messageType: typeServerHello, |
| 7829 | test: testCase{ |
| 7830 | protocol: protocol, |
| 7831 | name: "ServerHello" + suffix, |
| 7832 | config: Config{ |
| 7833 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7834 | }, |
| 7835 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7836 | }) |
| 7837 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7838 | ret = append(ret, perMessageTest{ |
| 7839 | messageType: typeCertificate, |
| 7840 | test: testCase{ |
| 7841 | protocol: protocol, |
| 7842 | name: "ServerCertificate" + suffix, |
| 7843 | config: Config{ |
| 7844 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7845 | }, |
| 7846 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7847 | }) |
| 7848 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7849 | ret = append(ret, perMessageTest{ |
| 7850 | messageType: typeCertificateStatus, |
| 7851 | test: testCase{ |
| 7852 | protocol: protocol, |
| 7853 | name: "CertificateStatus" + suffix, |
| 7854 | config: Config{ |
| 7855 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7856 | }, |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7857 | flags: []string{"-enable-ocsp-stapling"}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7858 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7859 | }) |
| 7860 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7861 | ret = append(ret, perMessageTest{ |
| 7862 | messageType: typeServerKeyExchange, |
| 7863 | test: testCase{ |
| 7864 | protocol: protocol, |
| 7865 | name: "ServerKeyExchange" + suffix, |
| 7866 | config: Config{ |
| 7867 | MaxVersion: VersionTLS12, |
| 7868 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7869 | }, |
| 7870 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7871 | }) |
| 7872 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7873 | ret = append(ret, perMessageTest{ |
| 7874 | messageType: typeCertificateRequest, |
| 7875 | test: testCase{ |
| 7876 | protocol: protocol, |
| 7877 | name: "CertificateRequest" + suffix, |
| 7878 | config: Config{ |
| 7879 | MaxVersion: VersionTLS12, |
| 7880 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7881 | }, |
| 7882 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7883 | }) |
| 7884 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7885 | ret = append(ret, perMessageTest{ |
| 7886 | messageType: typeServerHelloDone, |
| 7887 | test: testCase{ |
| 7888 | protocol: protocol, |
| 7889 | name: "ServerHelloDone" + suffix, |
| 7890 | config: Config{ |
| 7891 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7892 | }, |
| 7893 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7894 | }) |
| 7895 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7896 | ret = append(ret, perMessageTest{ |
| 7897 | messageType: typeCertificate, |
| 7898 | test: testCase{ |
| 7899 | testType: serverTest, |
| 7900 | protocol: protocol, |
| 7901 | name: "ClientCertificate" + suffix, |
| 7902 | config: Config{ |
| 7903 | Certificates: []Certificate{rsaCertificate}, |
| 7904 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7905 | }, |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7906 | flags: []string{"-require-any-client-certificate"}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7907 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7908 | }) |
| 7909 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7910 | ret = append(ret, perMessageTest{ |
| 7911 | messageType: typeCertificateVerify, |
| 7912 | test: testCase{ |
| 7913 | testType: serverTest, |
| 7914 | protocol: protocol, |
| 7915 | name: "CertificateVerify" + suffix, |
| 7916 | config: Config{ |
| 7917 | Certificates: []Certificate{rsaCertificate}, |
| 7918 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7919 | }, |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7920 | flags: []string{"-require-any-client-certificate"}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7921 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7922 | }) |
| 7923 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7924 | ret = append(ret, perMessageTest{ |
| 7925 | messageType: typeClientKeyExchange, |
| 7926 | test: testCase{ |
| 7927 | testType: serverTest, |
| 7928 | protocol: protocol, |
| 7929 | name: "ClientKeyExchange" + suffix, |
| 7930 | config: Config{ |
| 7931 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7932 | }, |
| 7933 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7934 | }) |
| 7935 | |
| 7936 | if protocol != dtls { |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7937 | ret = append(ret, perMessageTest{ |
| 7938 | messageType: typeNextProtocol, |
| 7939 | test: testCase{ |
| 7940 | testType: serverTest, |
| 7941 | protocol: protocol, |
| 7942 | name: "NextProtocol" + suffix, |
| 7943 | config: Config{ |
| 7944 | MaxVersion: VersionTLS12, |
| 7945 | NextProtos: []string{"bar"}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7946 | }, |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7947 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7948 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7949 | }) |
| 7950 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7951 | ret = append(ret, perMessageTest{ |
| 7952 | messageType: typeChannelID, |
| 7953 | test: testCase{ |
| 7954 | testType: serverTest, |
| 7955 | protocol: protocol, |
| 7956 | name: "ChannelID" + suffix, |
| 7957 | config: Config{ |
| 7958 | MaxVersion: VersionTLS12, |
| 7959 | ChannelID: channelIDKey, |
| 7960 | }, |
| 7961 | flags: []string{ |
| 7962 | "-expect-channel-id", |
| 7963 | base64.StdEncoding.EncodeToString(channelIDBytes), |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7964 | }, |
| 7965 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7966 | }) |
| 7967 | } |
| 7968 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7969 | ret = append(ret, perMessageTest{ |
| 7970 | messageType: typeFinished, |
| 7971 | test: testCase{ |
| 7972 | testType: serverTest, |
| 7973 | protocol: protocol, |
| 7974 | name: "ClientFinished" + suffix, |
| 7975 | config: Config{ |
| 7976 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7977 | }, |
| 7978 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7979 | }) |
| 7980 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7981 | ret = append(ret, perMessageTest{ |
| 7982 | messageType: typeNewSessionTicket, |
| 7983 | test: testCase{ |
| 7984 | protocol: protocol, |
| 7985 | name: "NewSessionTicket" + suffix, |
| 7986 | config: Config{ |
| 7987 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7988 | }, |
| 7989 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7990 | }) |
| 7991 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 7992 | ret = append(ret, perMessageTest{ |
| 7993 | messageType: typeFinished, |
| 7994 | test: testCase{ |
| 7995 | protocol: protocol, |
| 7996 | name: "ServerFinished" + suffix, |
| 7997 | config: Config{ |
| 7998 | MaxVersion: VersionTLS12, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7999 | }, |
| 8000 | }, |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8001 | }) |
| 8002 | |
| 8003 | } |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8004 | |
| 8005 | ret = append(ret, perMessageTest{ |
| 8006 | messageType: typeClientHello, |
| 8007 | test: testCase{ |
| 8008 | testType: serverTest, |
| 8009 | name: "TLS13-ClientHello", |
| 8010 | config: Config{ |
| 8011 | MaxVersion: VersionTLS13, |
| 8012 | }, |
| 8013 | }, |
| 8014 | }) |
| 8015 | |
| 8016 | ret = append(ret, perMessageTest{ |
| 8017 | messageType: typeServerHello, |
| 8018 | test: testCase{ |
| 8019 | name: "TLS13-ServerHello", |
| 8020 | config: Config{ |
| 8021 | MaxVersion: VersionTLS13, |
| 8022 | }, |
| 8023 | }, |
| 8024 | }) |
| 8025 | |
| 8026 | ret = append(ret, perMessageTest{ |
| 8027 | messageType: typeEncryptedExtensions, |
| 8028 | test: testCase{ |
| 8029 | name: "TLS13-EncryptedExtensions", |
| 8030 | config: Config{ |
| 8031 | MaxVersion: VersionTLS13, |
| 8032 | }, |
| 8033 | }, |
| 8034 | }) |
| 8035 | |
| 8036 | ret = append(ret, perMessageTest{ |
| 8037 | messageType: typeCertificateRequest, |
| 8038 | test: testCase{ |
| 8039 | name: "TLS13-CertificateRequest", |
| 8040 | config: Config{ |
| 8041 | MaxVersion: VersionTLS13, |
| 8042 | ClientAuth: RequireAnyClientCert, |
| 8043 | }, |
| 8044 | }, |
| 8045 | }) |
| 8046 | |
| 8047 | ret = append(ret, perMessageTest{ |
| 8048 | messageType: typeCertificate, |
| 8049 | test: testCase{ |
| 8050 | name: "TLS13-ServerCertificate", |
| 8051 | config: Config{ |
| 8052 | MaxVersion: VersionTLS13, |
| 8053 | }, |
| 8054 | }, |
| 8055 | }) |
| 8056 | |
| 8057 | ret = append(ret, perMessageTest{ |
| 8058 | messageType: typeCertificateVerify, |
| 8059 | test: testCase{ |
| 8060 | name: "TLS13-ServerCertificateVerify", |
| 8061 | config: Config{ |
| 8062 | MaxVersion: VersionTLS13, |
| 8063 | }, |
| 8064 | }, |
| 8065 | }) |
| 8066 | |
| 8067 | ret = append(ret, perMessageTest{ |
| 8068 | messageType: typeFinished, |
| 8069 | test: testCase{ |
| 8070 | name: "TLS13-ServerFinished", |
| 8071 | config: Config{ |
| 8072 | MaxVersion: VersionTLS13, |
| 8073 | }, |
| 8074 | }, |
| 8075 | }) |
| 8076 | |
| 8077 | ret = append(ret, perMessageTest{ |
| 8078 | messageType: typeCertificate, |
| 8079 | test: testCase{ |
| 8080 | testType: serverTest, |
| 8081 | name: "TLS13-ClientCertificate", |
| 8082 | config: Config{ |
| 8083 | Certificates: []Certificate{rsaCertificate}, |
| 8084 | MaxVersion: VersionTLS13, |
| 8085 | }, |
| 8086 | flags: []string{"-require-any-client-certificate"}, |
| 8087 | }, |
| 8088 | }) |
| 8089 | |
| 8090 | ret = append(ret, perMessageTest{ |
| 8091 | messageType: typeCertificateVerify, |
| 8092 | test: testCase{ |
| 8093 | testType: serverTest, |
| 8094 | name: "TLS13-ClientCertificateVerify", |
| 8095 | config: Config{ |
| 8096 | Certificates: []Certificate{rsaCertificate}, |
| 8097 | MaxVersion: VersionTLS13, |
| 8098 | }, |
| 8099 | flags: []string{"-require-any-client-certificate"}, |
| 8100 | }, |
| 8101 | }) |
| 8102 | |
| 8103 | ret = append(ret, perMessageTest{ |
| 8104 | messageType: typeFinished, |
| 8105 | test: testCase{ |
| 8106 | testType: serverTest, |
| 8107 | name: "TLS13-ClientFinished", |
| 8108 | config: Config{ |
| 8109 | MaxVersion: VersionTLS13, |
| 8110 | }, |
| 8111 | }, |
| 8112 | }) |
| 8113 | |
| 8114 | return ret |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8115 | } |
| 8116 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8117 | func addWrongMessageTypeTests() { |
| 8118 | for _, t := range makePerMessageTests() { |
| 8119 | t.test.name = "WrongMessageType-" + t.test.name |
| 8120 | t.test.config.Bugs.SendWrongMessageType = t.messageType |
| 8121 | t.test.shouldFail = true |
| 8122 | t.test.expectedError = ":UNEXPECTED_MESSAGE:" |
| 8123 | t.test.expectedLocalError = "remote error: unexpected message" |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8124 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8125 | if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello { |
| 8126 | // In TLS 1.3, a bad ServerHello means the client sends |
| 8127 | // an unencrypted alert while the server expects |
| 8128 | // encryption, so the alert is not readable by runner. |
| 8129 | t.test.expectedLocalError = "local error: bad record MAC" |
| 8130 | } |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8131 | |
David Benjamin | cd2c806 | 2016-09-09 11:28:16 -0400 | [diff] [blame] | 8132 | testCases = append(testCases, t.test) |
| 8133 | } |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8134 | } |
| 8135 | |
David Benjamin | 639846e | 2016-09-09 11:41:18 -0400 | [diff] [blame] | 8136 | func addTrailingMessageDataTests() { |
| 8137 | for _, t := range makePerMessageTests() { |
| 8138 | t.test.name = "TrailingMessageData-" + t.test.name |
| 8139 | t.test.config.Bugs.SendTrailingMessageData = t.messageType |
| 8140 | t.test.shouldFail = true |
| 8141 | t.test.expectedError = ":DECODE_ERROR:" |
| 8142 | t.test.expectedLocalError = "remote error: error decoding message" |
| 8143 | |
| 8144 | if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello { |
| 8145 | // In TLS 1.3, a bad ServerHello means the client sends |
| 8146 | // an unencrypted alert while the server expects |
| 8147 | // encryption, so the alert is not readable by runner. |
| 8148 | t.test.expectedLocalError = "local error: bad record MAC" |
| 8149 | } |
| 8150 | |
| 8151 | if t.messageType == typeFinished { |
| 8152 | // Bad Finished messages read as the verify data having |
| 8153 | // the wrong length. |
| 8154 | t.test.expectedError = ":DIGEST_CHECK_FAILED:" |
| 8155 | t.test.expectedLocalError = "remote error: error decrypting message" |
| 8156 | } |
| 8157 | |
| 8158 | testCases = append(testCases, t.test) |
| 8159 | } |
| 8160 | } |
| 8161 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8162 | func addTLS13HandshakeTests() { |
| 8163 | testCases = append(testCases, testCase{ |
| 8164 | testType: clientTest, |
| 8165 | name: "MissingKeyShare-Client", |
| 8166 | config: Config{ |
| 8167 | MaxVersion: VersionTLS13, |
| 8168 | Bugs: ProtocolBugs{ |
| 8169 | MissingKeyShare: true, |
| 8170 | }, |
| 8171 | }, |
| 8172 | shouldFail: true, |
| 8173 | expectedError: ":MISSING_KEY_SHARE:", |
| 8174 | }) |
| 8175 | |
| 8176 | testCases = append(testCases, testCase{ |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 8177 | testType: serverTest, |
| 8178 | name: "MissingKeyShare-Server", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8179 | config: Config{ |
| 8180 | MaxVersion: VersionTLS13, |
| 8181 | Bugs: ProtocolBugs{ |
| 8182 | MissingKeyShare: true, |
| 8183 | }, |
| 8184 | }, |
| 8185 | shouldFail: true, |
| 8186 | expectedError: ":MISSING_KEY_SHARE:", |
| 8187 | }) |
| 8188 | |
| 8189 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8190 | testType: serverTest, |
| 8191 | name: "DuplicateKeyShares", |
| 8192 | config: Config{ |
| 8193 | MaxVersion: VersionTLS13, |
| 8194 | Bugs: ProtocolBugs{ |
| 8195 | DuplicateKeyShares: true, |
| 8196 | }, |
| 8197 | }, |
David Benjamin | 7e1f984 | 2016-09-20 19:24:40 -0400 | [diff] [blame] | 8198 | shouldFail: true, |
| 8199 | expectedError: ":DUPLICATE_KEY_SHARE:", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8200 | }) |
| 8201 | |
| 8202 | testCases = append(testCases, testCase{ |
| 8203 | testType: clientTest, |
| 8204 | name: "EmptyEncryptedExtensions", |
| 8205 | config: Config{ |
| 8206 | MaxVersion: VersionTLS13, |
| 8207 | Bugs: ProtocolBugs{ |
| 8208 | EmptyEncryptedExtensions: true, |
| 8209 | }, |
| 8210 | }, |
| 8211 | shouldFail: true, |
| 8212 | expectedLocalError: "remote error: error decoding message", |
| 8213 | }) |
| 8214 | |
| 8215 | testCases = append(testCases, testCase{ |
| 8216 | testType: clientTest, |
| 8217 | name: "EncryptedExtensionsWithKeyShare", |
| 8218 | config: Config{ |
| 8219 | MaxVersion: VersionTLS13, |
| 8220 | Bugs: ProtocolBugs{ |
| 8221 | EncryptedExtensionsWithKeyShare: true, |
| 8222 | }, |
| 8223 | }, |
| 8224 | shouldFail: true, |
| 8225 | expectedLocalError: "remote error: unsupported extension", |
| 8226 | }) |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 8227 | |
| 8228 | testCases = append(testCases, testCase{ |
| 8229 | testType: serverTest, |
| 8230 | name: "SendHelloRetryRequest", |
| 8231 | config: Config{ |
| 8232 | MaxVersion: VersionTLS13, |
| 8233 | // Require a HelloRetryRequest for every curve. |
| 8234 | DefaultCurves: []CurveID{}, |
| 8235 | }, |
| 8236 | expectedCurveID: CurveX25519, |
| 8237 | }) |
| 8238 | |
| 8239 | testCases = append(testCases, testCase{ |
| 8240 | testType: serverTest, |
| 8241 | name: "SendHelloRetryRequest-2", |
| 8242 | config: Config{ |
| 8243 | MaxVersion: VersionTLS13, |
| 8244 | DefaultCurves: []CurveID{CurveP384}, |
| 8245 | }, |
| 8246 | // Although the ClientHello did not predict our preferred curve, |
| 8247 | // we always select it whether it is predicted or not. |
| 8248 | expectedCurveID: CurveX25519, |
| 8249 | }) |
| 8250 | |
| 8251 | testCases = append(testCases, testCase{ |
| 8252 | name: "UnknownCurve-HelloRetryRequest", |
| 8253 | config: Config{ |
| 8254 | MaxVersion: VersionTLS13, |
| 8255 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8256 | CurvePreferences: []CurveID{CurveP384}, |
| 8257 | Bugs: ProtocolBugs{ |
| 8258 | SendHelloRetryRequestCurve: bogusCurve, |
| 8259 | }, |
| 8260 | }, |
| 8261 | shouldFail: true, |
| 8262 | expectedError: ":WRONG_CURVE:", |
| 8263 | }) |
| 8264 | |
| 8265 | testCases = append(testCases, testCase{ |
| 8266 | name: "DisabledCurve-HelloRetryRequest", |
| 8267 | config: Config{ |
| 8268 | MaxVersion: VersionTLS13, |
| 8269 | CurvePreferences: []CurveID{CurveP256}, |
| 8270 | Bugs: ProtocolBugs{ |
| 8271 | IgnorePeerCurvePreferences: true, |
| 8272 | }, |
| 8273 | }, |
| 8274 | flags: []string{"-p384-only"}, |
| 8275 | shouldFail: true, |
| 8276 | expectedError: ":WRONG_CURVE:", |
| 8277 | }) |
| 8278 | |
| 8279 | testCases = append(testCases, testCase{ |
| 8280 | name: "UnnecessaryHelloRetryRequest", |
| 8281 | config: Config{ |
| 8282 | MaxVersion: VersionTLS13, |
| 8283 | Bugs: ProtocolBugs{ |
| 8284 | UnnecessaryHelloRetryRequest: true, |
| 8285 | }, |
| 8286 | }, |
| 8287 | shouldFail: true, |
| 8288 | expectedError: ":WRONG_CURVE:", |
| 8289 | }) |
| 8290 | |
| 8291 | testCases = append(testCases, testCase{ |
| 8292 | name: "SecondHelloRetryRequest", |
| 8293 | config: Config{ |
| 8294 | MaxVersion: VersionTLS13, |
| 8295 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8296 | CurvePreferences: []CurveID{CurveP384}, |
| 8297 | Bugs: ProtocolBugs{ |
| 8298 | SecondHelloRetryRequest: true, |
| 8299 | }, |
| 8300 | }, |
| 8301 | shouldFail: true, |
| 8302 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 8303 | }) |
| 8304 | |
| 8305 | testCases = append(testCases, testCase{ |
| 8306 | testType: serverTest, |
| 8307 | name: "SecondClientHelloMissingKeyShare", |
| 8308 | config: Config{ |
| 8309 | MaxVersion: VersionTLS13, |
| 8310 | DefaultCurves: []CurveID{}, |
| 8311 | Bugs: ProtocolBugs{ |
| 8312 | SecondClientHelloMissingKeyShare: true, |
| 8313 | }, |
| 8314 | }, |
| 8315 | shouldFail: true, |
| 8316 | expectedError: ":MISSING_KEY_SHARE:", |
| 8317 | }) |
| 8318 | |
| 8319 | testCases = append(testCases, testCase{ |
| 8320 | testType: serverTest, |
| 8321 | name: "SecondClientHelloWrongCurve", |
| 8322 | config: Config{ |
| 8323 | MaxVersion: VersionTLS13, |
| 8324 | DefaultCurves: []CurveID{}, |
| 8325 | Bugs: ProtocolBugs{ |
| 8326 | MisinterpretHelloRetryRequestCurve: CurveP521, |
| 8327 | }, |
| 8328 | }, |
| 8329 | shouldFail: true, |
| 8330 | expectedError: ":WRONG_CURVE:", |
| 8331 | }) |
| 8332 | |
| 8333 | testCases = append(testCases, testCase{ |
| 8334 | name: "HelloRetryRequestVersionMismatch", |
| 8335 | config: Config{ |
| 8336 | MaxVersion: VersionTLS13, |
| 8337 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8338 | CurvePreferences: []CurveID{CurveP384}, |
| 8339 | Bugs: ProtocolBugs{ |
| 8340 | SendServerHelloVersion: 0x0305, |
| 8341 | }, |
| 8342 | }, |
| 8343 | shouldFail: true, |
| 8344 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 8345 | }) |
| 8346 | |
| 8347 | testCases = append(testCases, testCase{ |
| 8348 | name: "HelloRetryRequestCurveMismatch", |
| 8349 | config: Config{ |
| 8350 | MaxVersion: VersionTLS13, |
| 8351 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8352 | CurvePreferences: []CurveID{CurveP384}, |
| 8353 | Bugs: ProtocolBugs{ |
| 8354 | // Send P-384 (correct) in the HelloRetryRequest. |
| 8355 | SendHelloRetryRequestCurve: CurveP384, |
| 8356 | // But send P-256 in the ServerHello. |
| 8357 | SendCurve: CurveP256, |
| 8358 | }, |
| 8359 | }, |
| 8360 | shouldFail: true, |
| 8361 | expectedError: ":WRONG_CURVE:", |
| 8362 | }) |
| 8363 | |
| 8364 | // Test the server selecting a curve that requires a HelloRetryRequest |
| 8365 | // without sending it. |
| 8366 | testCases = append(testCases, testCase{ |
| 8367 | name: "SkipHelloRetryRequest", |
| 8368 | config: Config{ |
| 8369 | MaxVersion: VersionTLS13, |
| 8370 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8371 | CurvePreferences: []CurveID{CurveP384}, |
| 8372 | Bugs: ProtocolBugs{ |
| 8373 | SkipHelloRetryRequest: true, |
| 8374 | }, |
| 8375 | }, |
| 8376 | shouldFail: true, |
| 8377 | expectedError: ":WRONG_CURVE:", |
| 8378 | }) |
David Benjamin | 8a8349b | 2016-08-18 02:32:23 -0400 | [diff] [blame] | 8379 | |
| 8380 | testCases = append(testCases, testCase{ |
| 8381 | name: "TLS13-RequestContextInHandshake", |
| 8382 | config: Config{ |
| 8383 | MaxVersion: VersionTLS13, |
| 8384 | MinVersion: VersionTLS13, |
| 8385 | ClientAuth: RequireAnyClientCert, |
| 8386 | Bugs: ProtocolBugs{ |
| 8387 | SendRequestContext: []byte("request context"), |
| 8388 | }, |
| 8389 | }, |
| 8390 | flags: []string{ |
| 8391 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 8392 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 8393 | }, |
| 8394 | shouldFail: true, |
| 8395 | expectedError: ":DECODE_ERROR:", |
| 8396 | }) |
David Benjamin | 7e1f984 | 2016-09-20 19:24:40 -0400 | [diff] [blame] | 8397 | |
| 8398 | testCases = append(testCases, testCase{ |
| 8399 | testType: serverTest, |
| 8400 | name: "TLS13-TrailingKeyShareData", |
| 8401 | config: Config{ |
| 8402 | MaxVersion: VersionTLS13, |
| 8403 | Bugs: ProtocolBugs{ |
| 8404 | TrailingKeyShareData: true, |
| 8405 | }, |
| 8406 | }, |
| 8407 | shouldFail: true, |
| 8408 | expectedError: ":DECODE_ERROR:", |
| 8409 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8410 | } |
| 8411 | |
David Benjamin | f3fbade | 2016-09-19 13:08:16 -0400 | [diff] [blame] | 8412 | func addPeekTests() { |
| 8413 | // Test SSL_peek works, including on empty records. |
| 8414 | testCases = append(testCases, testCase{ |
| 8415 | name: "Peek-Basic", |
| 8416 | sendEmptyRecords: 1, |
| 8417 | flags: []string{"-peek-then-read"}, |
| 8418 | }) |
| 8419 | |
| 8420 | // Test SSL_peek can drive the initial handshake. |
| 8421 | testCases = append(testCases, testCase{ |
| 8422 | name: "Peek-ImplicitHandshake", |
| 8423 | flags: []string{ |
| 8424 | "-peek-then-read", |
| 8425 | "-implicit-handshake", |
| 8426 | }, |
| 8427 | }) |
| 8428 | |
| 8429 | // Test SSL_peek can discover and drive a renegotiation. |
| 8430 | testCases = append(testCases, testCase{ |
| 8431 | name: "Peek-Renegotiate", |
| 8432 | config: Config{ |
| 8433 | MaxVersion: VersionTLS12, |
| 8434 | }, |
| 8435 | renegotiate: 1, |
| 8436 | flags: []string{ |
| 8437 | "-peek-then-read", |
| 8438 | "-renegotiate-freely", |
| 8439 | "-expect-total-renegotiations", "1", |
| 8440 | }, |
| 8441 | }) |
| 8442 | |
| 8443 | // Test SSL_peek can discover a close_notify. |
| 8444 | testCases = append(testCases, testCase{ |
| 8445 | name: "Peek-Shutdown", |
| 8446 | config: Config{ |
| 8447 | Bugs: ProtocolBugs{ |
| 8448 | ExpectCloseNotify: true, |
| 8449 | }, |
| 8450 | }, |
| 8451 | flags: []string{ |
| 8452 | "-peek-then-read", |
| 8453 | "-check-close-notify", |
| 8454 | }, |
| 8455 | }) |
| 8456 | |
| 8457 | // Test SSL_peek can discover an alert. |
| 8458 | testCases = append(testCases, testCase{ |
| 8459 | name: "Peek-Alert", |
| 8460 | config: Config{ |
| 8461 | Bugs: ProtocolBugs{ |
| 8462 | SendSpuriousAlert: alertRecordOverflow, |
| 8463 | }, |
| 8464 | }, |
| 8465 | flags: []string{"-peek-then-read"}, |
| 8466 | shouldFail: true, |
| 8467 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 8468 | }) |
| 8469 | |
| 8470 | // Test SSL_peek can handle KeyUpdate. |
| 8471 | testCases = append(testCases, testCase{ |
| 8472 | name: "Peek-KeyUpdate", |
| 8473 | config: Config{ |
| 8474 | MaxVersion: VersionTLS13, |
| 8475 | Bugs: ProtocolBugs{ |
| 8476 | SendKeyUpdateBeforeEveryAppDataRecord: true, |
| 8477 | }, |
| 8478 | }, |
| 8479 | flags: []string{"-peek-then-read"}, |
| 8480 | }) |
| 8481 | } |
| 8482 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8483 | 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] | 8484 | defer wg.Done() |
| 8485 | |
| 8486 | for test := range c { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 8487 | var err error |
| 8488 | |
| 8489 | if *mallocTest < 0 { |
| 8490 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8491 | err = runTest(test, shimPath, -1) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 8492 | } else { |
| 8493 | for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ { |
| 8494 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8495 | if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 8496 | if err != nil { |
| 8497 | fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err) |
| 8498 | } |
| 8499 | break |
| 8500 | } |
| 8501 | } |
| 8502 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8503 | statusChan <- statusMsg{test: test, err: err} |
| 8504 | } |
| 8505 | } |
| 8506 | |
| 8507 | type statusMsg struct { |
| 8508 | test *testCase |
| 8509 | started bool |
| 8510 | err error |
| 8511 | } |
| 8512 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8513 | func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8514 | var started, done, failed, unimplemented, lineLen int |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8515 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8516 | testOutput := newTestOutput() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8517 | for msg := range statusChan { |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8518 | if !*pipe { |
| 8519 | // Erase the previous status line. |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 8520 | var erase string |
| 8521 | for i := 0; i < lineLen; i++ { |
| 8522 | erase += "\b \b" |
| 8523 | } |
| 8524 | fmt.Print(erase) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8525 | } |
| 8526 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8527 | if msg.started { |
| 8528 | started++ |
| 8529 | } else { |
| 8530 | done++ |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8531 | |
| 8532 | if msg.err != nil { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8533 | if msg.err == errUnimplemented { |
| 8534 | if *pipe { |
| 8535 | // Print each test instead of a status line. |
| 8536 | fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name) |
| 8537 | } |
| 8538 | unimplemented++ |
| 8539 | testOutput.addResult(msg.test.name, "UNIMPLEMENTED") |
| 8540 | } else { |
| 8541 | fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err) |
| 8542 | failed++ |
| 8543 | testOutput.addResult(msg.test.name, "FAIL") |
| 8544 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8545 | } else { |
| 8546 | if *pipe { |
| 8547 | // Print each test instead of a status line. |
| 8548 | fmt.Printf("PASSED (%s)\n", msg.test.name) |
| 8549 | } |
| 8550 | testOutput.addResult(msg.test.name, "PASS") |
| 8551 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8552 | } |
| 8553 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8554 | if !*pipe { |
| 8555 | // Print a new status line. |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8556 | 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] | 8557 | lineLen = len(line) |
| 8558 | os.Stdout.WriteString(line) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8559 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8560 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8561 | |
| 8562 | doneChan <- testOutput |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8563 | } |
| 8564 | |
| 8565 | func main() { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8566 | flag.Parse() |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8567 | *resourceDir = path.Clean(*resourceDir) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 8568 | initCertificates() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8569 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8570 | addBasicTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8571 | addCipherSuiteTests() |
| 8572 | addBadECDSASignatureTests() |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8573 | addCBCPaddingTests() |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 8574 | addCBCSplittingTests() |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 8575 | addClientAuthTests() |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 8576 | addDDoSCallbackTests() |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 8577 | addVersionNegotiationTests() |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 8578 | addMinimumVersionTests() |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 8579 | addExtensionTests() |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 8580 | addResumptionVersionTests() |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 8581 | addExtendedMasterSecretTests() |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 8582 | addRenegotiationTests() |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 8583 | addDTLSReplayTests() |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 8584 | addSignatureAlgorithmTests() |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 8585 | addDTLSRetransmitTests() |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 8586 | addExportKeyingMaterialTests() |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 8587 | addTLSUniqueTests() |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 8588 | addCustomExtensionTests() |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 8589 | addRSAClientKeyExchangeTests() |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 8590 | addCurveTests() |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 8591 | addCECPQ1Tests() |
David Benjamin | 5c4e857 | 2016-08-19 17:44:53 -0400 | [diff] [blame] | 8592 | addDHEGroupSizeTests() |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 8593 | addTLS13RecordTests() |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 8594 | addAllStateMachineCoverageTests() |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 8595 | addChangeCipherSpecTests() |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8596 | addWrongMessageTypeTests() |
David Benjamin | 639846e | 2016-09-09 11:41:18 -0400 | [diff] [blame] | 8597 | addTrailingMessageDataTests() |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8598 | addTLS13HandshakeTests() |
David Benjamin | f3fbade | 2016-09-19 13:08:16 -0400 | [diff] [blame] | 8599 | addPeekTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8600 | |
| 8601 | var wg sync.WaitGroup |
| 8602 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8603 | statusChan := make(chan statusMsg, *numWorkers) |
| 8604 | testChan := make(chan *testCase, *numWorkers) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8605 | doneChan := make(chan *testOutput) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8606 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8607 | if len(*shimConfigFile) != 0 { |
| 8608 | encoded, err := ioutil.ReadFile(*shimConfigFile) |
| 8609 | if err != nil { |
| 8610 | fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err) |
| 8611 | os.Exit(1) |
| 8612 | } |
| 8613 | |
| 8614 | if err := json.Unmarshal(encoded, &shimConfig); err != nil { |
| 8615 | fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err) |
| 8616 | os.Exit(1) |
| 8617 | } |
| 8618 | } |
| 8619 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8620 | go statusPrinter(doneChan, statusChan, len(testCases)) |
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 | for i := 0; i < *numWorkers; i++ { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8623 | wg.Add(1) |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8624 | go worker(statusChan, testChan, *shimPath, &wg) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8625 | } |
| 8626 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8627 | var foundTest bool |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8628 | for i := range testCases { |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8629 | matched := true |
| 8630 | if len(*testToRun) != 0 { |
| 8631 | var err error |
| 8632 | matched, err = filepath.Match(*testToRun, testCases[i].name) |
| 8633 | if err != nil { |
| 8634 | fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err) |
| 8635 | os.Exit(1) |
| 8636 | } |
| 8637 | } |
| 8638 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8639 | if !*includeDisabled { |
| 8640 | for pattern := range shimConfig.DisabledTests { |
| 8641 | isDisabled, err := filepath.Match(pattern, testCases[i].name) |
| 8642 | if err != nil { |
| 8643 | fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err) |
| 8644 | os.Exit(1) |
| 8645 | } |
| 8646 | |
| 8647 | if isDisabled { |
| 8648 | matched = false |
| 8649 | break |
| 8650 | } |
| 8651 | } |
| 8652 | } |
| 8653 | |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8654 | if matched { |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8655 | foundTest = true |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8656 | testChan <- &testCases[i] |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8657 | } |
| 8658 | } |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8659 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8660 | if !foundTest { |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8661 | fmt.Fprintf(os.Stderr, "No tests run\n") |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8662 | os.Exit(1) |
| 8663 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8664 | |
| 8665 | close(testChan) |
| 8666 | wg.Wait() |
| 8667 | close(statusChan) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8668 | testOutput := <-doneChan |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8669 | |
| 8670 | fmt.Printf("\n") |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8671 | |
| 8672 | if *jsonOutput != "" { |
| 8673 | if err := testOutput.writeTo(*jsonOutput); err != nil { |
| 8674 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 8675 | } |
| 8676 | } |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 8677 | |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8678 | if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 { |
| 8679 | os.Exit(1) |
| 8680 | } |
| 8681 | |
| 8682 | if !testOutput.noneFailed { |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 8683 | os.Exit(1) |
| 8684 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8685 | } |