Adam Langley | 7fcfd3b | 2016-05-20 11:02:50 -0700 | [diff] [blame] | 1 | // Copyright (c) 2016, Google Inc. |
| 2 | // |
| 3 | // Permission to use, copy, modify, and/or distribute this software for any |
| 4 | // purpose with or without fee is hereby granted, provided that the above |
| 5 | // copyright notice and this permission notice appear in all copies. |
| 6 | // |
| 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
David Benjamin | 0d1b096 | 2016-08-01 09:50:57 -0400 | [diff] [blame] | 13 | // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Adam Langley | 7fcfd3b | 2016-05-20 11:02:50 -0700 | [diff] [blame] | 14 | |
Adam Langley | dc7e9c4 | 2015-09-29 15:21:04 -0700 | [diff] [blame] | 15 | package runner |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "bytes" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 19 | "crypto/ecdsa" |
| 20 | "crypto/elliptic" |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 21 | "crypto/x509" |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 22 | "encoding/base64" |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 23 | "encoding/json" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 24 | "encoding/pem" |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 25 | "errors" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 26 | "flag" |
| 27 | "fmt" |
| 28 | "io" |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 29 | "io/ioutil" |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 30 | "math/big" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 31 | "net" |
| 32 | "os" |
| 33 | "os/exec" |
David Benjamin | 884fdf1 | 2014-08-02 15:28:23 -0400 | [diff] [blame] | 34 | "path" |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 35 | "path/filepath" |
David Benjamin | 2bc8e6f | 2014-08-02 15:22:37 -0400 | [diff] [blame] | 36 | "runtime" |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 37 | "strconv" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 38 | "strings" |
| 39 | "sync" |
| 40 | "syscall" |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 41 | "time" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 42 | ) |
| 43 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 44 | var ( |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 45 | useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind") |
| 46 | useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb") |
| 47 | useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb") |
| 48 | flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection") |
| 49 | mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.") |
| 50 | mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.") |
| 51 | jsonOutput = flag.String("json-output", "", "The file to output JSON results to.") |
| 52 | pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.") |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 53 | testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests") |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 54 | numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.") |
| 55 | shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.") |
| 56 | resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.") |
| 57 | fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.") |
| 58 | transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.") |
| 59 | idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.") |
| 60 | deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.") |
| 61 | allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.") |
EKR | 173bf93 | 2016-07-29 15:52:49 +0200 | [diff] [blame] | 62 | looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.") |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 63 | shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.") |
| 64 | includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 65 | ) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 66 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 67 | // ShimConfigurations is used with the “json” package and represents a shim |
| 68 | // config file. |
| 69 | type ShimConfiguration struct { |
| 70 | // DisabledTests maps from a glob-based pattern to a freeform string. |
| 71 | // The glob pattern is used to exclude tests from being run and the |
| 72 | // freeform string is unparsed but expected to explain why the test is |
| 73 | // disabled. |
| 74 | DisabledTests map[string]string |
| 75 | |
| 76 | // ErrorMap maps from expected error strings to the correct error |
| 77 | // string for the shim in question. For example, it might map |
| 78 | // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something |
| 79 | // like “SSL_ERROR_NO_CYPHER_OVERLAP”. |
| 80 | ErrorMap map[string]string |
| 81 | } |
| 82 | |
| 83 | var shimConfig ShimConfiguration |
| 84 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 85 | type testCert int |
| 86 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 87 | const ( |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 88 | testCertRSA testCert = iota |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 89 | testCertRSA1024 |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 90 | testCertECDSAP256 |
| 91 | testCertECDSAP384 |
| 92 | testCertECDSAP521 |
| 93 | ) |
| 94 | |
| 95 | const ( |
| 96 | rsaCertificateFile = "cert.pem" |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 97 | rsa1024CertificateFile = "rsa_1024_cert.pem" |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 98 | ecdsaP256CertificateFile = "ecdsa_p256_cert.pem" |
| 99 | ecdsaP384CertificateFile = "ecdsa_p384_cert.pem" |
| 100 | ecdsaP521CertificateFile = "ecdsa_p521_cert.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 101 | ) |
| 102 | |
| 103 | const ( |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 104 | rsaKeyFile = "key.pem" |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 105 | rsa1024KeyFile = "rsa_1024_key.pem" |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 106 | ecdsaP256KeyFile = "ecdsa_p256_key.pem" |
| 107 | ecdsaP384KeyFile = "ecdsa_p384_key.pem" |
| 108 | ecdsaP521KeyFile = "ecdsa_p521_key.pem" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 109 | channelIDKeyFile = "channel_id_key.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 110 | ) |
| 111 | |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 112 | var ( |
| 113 | rsaCertificate Certificate |
| 114 | rsa1024Certificate Certificate |
| 115 | ecdsaP256Certificate Certificate |
| 116 | ecdsaP384Certificate Certificate |
| 117 | ecdsaP521Certificate Certificate |
| 118 | ) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 119 | |
| 120 | var testCerts = []struct { |
| 121 | id testCert |
| 122 | certFile, keyFile string |
| 123 | cert *Certificate |
| 124 | }{ |
| 125 | { |
| 126 | id: testCertRSA, |
| 127 | certFile: rsaCertificateFile, |
| 128 | keyFile: rsaKeyFile, |
| 129 | cert: &rsaCertificate, |
| 130 | }, |
| 131 | { |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 132 | id: testCertRSA1024, |
| 133 | certFile: rsa1024CertificateFile, |
| 134 | keyFile: rsa1024KeyFile, |
| 135 | cert: &rsa1024Certificate, |
| 136 | }, |
| 137 | { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 138 | id: testCertECDSAP256, |
| 139 | certFile: ecdsaP256CertificateFile, |
| 140 | keyFile: ecdsaP256KeyFile, |
| 141 | cert: &ecdsaP256Certificate, |
| 142 | }, |
| 143 | { |
| 144 | id: testCertECDSAP384, |
| 145 | certFile: ecdsaP384CertificateFile, |
| 146 | keyFile: ecdsaP384KeyFile, |
| 147 | cert: &ecdsaP384Certificate, |
| 148 | }, |
| 149 | { |
| 150 | id: testCertECDSAP521, |
| 151 | certFile: ecdsaP521CertificateFile, |
| 152 | keyFile: ecdsaP521KeyFile, |
| 153 | cert: &ecdsaP521Certificate, |
| 154 | }, |
| 155 | } |
| 156 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 157 | var channelIDKey *ecdsa.PrivateKey |
| 158 | var channelIDBytes []byte |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 159 | |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 160 | var testOCSPResponse = []byte{1, 2, 3, 4} |
| 161 | var testSCTList = []byte{5, 6, 7, 8} |
| 162 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 163 | func initCertificates() { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 164 | for i := range testCerts { |
| 165 | cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile)) |
| 166 | if err != nil { |
| 167 | panic(err) |
| 168 | } |
| 169 | cert.OCSPStaple = testOCSPResponse |
| 170 | cert.SignedCertificateTimestampList = testSCTList |
| 171 | *testCerts[i].cert = cert |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 172 | } |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 173 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 174 | channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile)) |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 175 | if err != nil { |
| 176 | panic(err) |
| 177 | } |
| 178 | channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock) |
| 179 | if channelIDDERBlock.Type != "EC PRIVATE KEY" { |
| 180 | panic("bad key type") |
| 181 | } |
| 182 | channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes) |
| 183 | if err != nil { |
| 184 | panic(err) |
| 185 | } |
| 186 | if channelIDKey.Curve != elliptic.P256() { |
| 187 | panic("bad curve") |
| 188 | } |
| 189 | |
| 190 | channelIDBytes = make([]byte, 64) |
| 191 | writeIntPadded(channelIDBytes[:32], channelIDKey.X) |
| 192 | writeIntPadded(channelIDBytes[32:], channelIDKey.Y) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 193 | } |
| 194 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 195 | func getRunnerCertificate(t testCert) Certificate { |
| 196 | for _, cert := range testCerts { |
| 197 | if cert.id == t { |
| 198 | return *cert.cert |
| 199 | } |
| 200 | } |
| 201 | panic("Unknown test certificate") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 202 | } |
| 203 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 204 | func getShimCertificate(t testCert) string { |
| 205 | for _, cert := range testCerts { |
| 206 | if cert.id == t { |
| 207 | return cert.certFile |
| 208 | } |
| 209 | } |
| 210 | panic("Unknown test certificate") |
| 211 | } |
| 212 | |
| 213 | func getShimKey(t testCert) string { |
| 214 | for _, cert := range testCerts { |
| 215 | if cert.id == t { |
| 216 | return cert.keyFile |
| 217 | } |
| 218 | } |
| 219 | panic("Unknown test certificate") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 220 | } |
| 221 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 222 | type testType int |
| 223 | |
| 224 | const ( |
| 225 | clientTest testType = iota |
| 226 | serverTest |
| 227 | ) |
| 228 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 229 | type protocol int |
| 230 | |
| 231 | const ( |
| 232 | tls protocol = iota |
| 233 | dtls |
| 234 | ) |
| 235 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 236 | const ( |
| 237 | alpn = 1 |
| 238 | npn = 2 |
| 239 | ) |
| 240 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 241 | type testCase struct { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 242 | testType testType |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 243 | protocol protocol |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 244 | name string |
| 245 | config Config |
| 246 | shouldFail bool |
| 247 | expectedError string |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 248 | // expectedLocalError, if not empty, contains a substring that must be |
| 249 | // found in the local error. |
| 250 | expectedLocalError string |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 251 | // expectedVersion, if non-zero, specifies the TLS version that must be |
| 252 | // negotiated. |
| 253 | expectedVersion uint16 |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 254 | // expectedResumeVersion, if non-zero, specifies the TLS version that |
| 255 | // must be negotiated on resumption. If zero, expectedVersion is used. |
| 256 | expectedResumeVersion uint16 |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 257 | // expectedCipher, if non-zero, specifies the TLS cipher suite that |
| 258 | // should be negotiated. |
| 259 | expectedCipher uint16 |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 260 | // expectChannelID controls whether the connection should have |
| 261 | // negotiated a Channel ID with channelIDKey. |
| 262 | expectChannelID bool |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 263 | // expectedNextProto controls whether the connection should |
| 264 | // negotiate a next protocol via NPN or ALPN. |
| 265 | expectedNextProto string |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 266 | // expectNoNextProto, if true, means that no next protocol should be |
| 267 | // negotiated. |
| 268 | expectNoNextProto bool |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 269 | // expectedNextProtoType, if non-zero, is the expected next |
| 270 | // protocol negotiation mechanism. |
| 271 | expectedNextProtoType int |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 272 | // expectedSRTPProtectionProfile is the DTLS-SRTP profile that |
| 273 | // should be negotiated. If zero, none should be negotiated. |
| 274 | expectedSRTPProtectionProfile uint16 |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 275 | // expectedOCSPResponse, if not nil, is the expected OCSP response to be received. |
| 276 | expectedOCSPResponse []uint8 |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 277 | // expectedSCTList, if not nil, is the expected SCT list to be received. |
| 278 | expectedSCTList []uint8 |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 279 | // expectedPeerSignatureAlgorithm, if not zero, is the signature |
| 280 | // algorithm that the peer should have used in the handshake. |
| 281 | expectedPeerSignatureAlgorithm signatureAlgorithm |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 282 | // expectedCurveID, if not zero, is the curve that the handshake should |
| 283 | // have used. |
| 284 | expectedCurveID CurveID |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 285 | // messageLen is the length, in bytes, of the test message that will be |
| 286 | // sent. |
| 287 | messageLen int |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 288 | // messageCount is the number of test messages that will be sent. |
| 289 | messageCount int |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 290 | // certFile is the path to the certificate to use for the server. |
| 291 | certFile string |
| 292 | // keyFile is the path to the private key to use for the server. |
| 293 | keyFile string |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 294 | // resumeSession controls whether a second connection should be tested |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 295 | // which attempts to resume the first session. |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 296 | resumeSession bool |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 297 | // expectResumeRejected, if true, specifies that the attempted |
| 298 | // resumption must be rejected by the client. This is only valid for a |
| 299 | // serverTest. |
| 300 | expectResumeRejected bool |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 301 | // resumeConfig, if not nil, points to a Config to be used on |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 302 | // resumption. Unless newSessionsOnResume is set, |
| 303 | // SessionTicketKey, ServerSessionCache, and |
| 304 | // ClientSessionCache are copied from the initial connection's |
| 305 | // config. If nil, the initial connection's config is used. |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 306 | resumeConfig *Config |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 307 | // newSessionsOnResume, if true, will cause resumeConfig to |
| 308 | // use a different session resumption context. |
| 309 | newSessionsOnResume bool |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 310 | // noSessionCache, if true, will cause the server to run without a |
| 311 | // session cache. |
| 312 | noSessionCache bool |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 313 | // sendPrefix sends a prefix on the socket before actually performing a |
| 314 | // handshake. |
| 315 | sendPrefix string |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 316 | // shimWritesFirst controls whether the shim sends an initial "hello" |
| 317 | // message before doing a roundtrip with the runner. |
| 318 | shimWritesFirst bool |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 319 | // shimShutsDown, if true, runs a test where the shim shuts down the |
| 320 | // connection immediately after the handshake rather than echoing |
| 321 | // messages from the runner. |
| 322 | shimShutsDown bool |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 323 | // renegotiate indicates the number of times the connection should be |
| 324 | // renegotiated during the exchange. |
| 325 | renegotiate int |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 326 | // sendHalfHelloRequest, if true, causes the server to send half a |
| 327 | // HelloRequest when the handshake completes. |
| 328 | sendHalfHelloRequest bool |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 329 | // renegotiateCiphers is a list of ciphersuite ids that will be |
| 330 | // switched in just before renegotiation. |
| 331 | renegotiateCiphers []uint16 |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 332 | // replayWrites, if true, configures the underlying transport |
| 333 | // to replay every write it makes in DTLS tests. |
| 334 | replayWrites bool |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 335 | // damageFirstWrite, if true, configures the underlying transport to |
| 336 | // damage the final byte of the first application data write. |
| 337 | damageFirstWrite bool |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 338 | // exportKeyingMaterial, if non-zero, configures the test to exchange |
| 339 | // keying material and verify they match. |
| 340 | exportKeyingMaterial int |
| 341 | exportLabel string |
| 342 | exportContext string |
| 343 | useExportContext bool |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 344 | // flags, if not empty, contains a list of command-line flags that will |
| 345 | // be passed to the shim program. |
| 346 | flags []string |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 347 | // testTLSUnique, if true, causes the shim to send the tls-unique value |
| 348 | // which will be compared against the expected value. |
| 349 | testTLSUnique bool |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 350 | // sendEmptyRecords is the number of consecutive empty records to send |
| 351 | // before and after the test message. |
| 352 | sendEmptyRecords int |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 353 | // sendWarningAlerts is the number of consecutive warning alerts to send |
| 354 | // before and after the test message. |
| 355 | sendWarningAlerts int |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 356 | // expectMessageDropped, if true, means the test message is expected to |
| 357 | // be dropped by the client rather than echoed back. |
| 358 | expectMessageDropped bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 361 | var testCases []testCase |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 362 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 363 | func writeTranscript(test *testCase, isResume bool, data []byte) { |
| 364 | if len(data) == 0 { |
| 365 | return |
| 366 | } |
| 367 | |
| 368 | protocol := "tls" |
| 369 | if test.protocol == dtls { |
| 370 | protocol = "dtls" |
| 371 | } |
| 372 | |
| 373 | side := "client" |
| 374 | if test.testType == serverTest { |
| 375 | side = "server" |
| 376 | } |
| 377 | |
| 378 | dir := path.Join(*transcriptDir, protocol, side) |
| 379 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 380 | fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err) |
| 381 | return |
| 382 | } |
| 383 | |
| 384 | name := test.name |
| 385 | if isResume { |
| 386 | name += "-Resume" |
| 387 | } else { |
| 388 | name += "-Normal" |
| 389 | } |
| 390 | |
| 391 | if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil { |
| 392 | fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err) |
| 393 | } |
| 394 | } |
| 395 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 396 | // A timeoutConn implements an idle timeout on each Read and Write operation. |
| 397 | type timeoutConn struct { |
| 398 | net.Conn |
| 399 | timeout time.Duration |
| 400 | } |
| 401 | |
| 402 | func (t *timeoutConn) Read(b []byte) (int, error) { |
| 403 | if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil { |
| 404 | return 0, err |
| 405 | } |
| 406 | return t.Conn.Read(b) |
| 407 | } |
| 408 | |
| 409 | func (t *timeoutConn) Write(b []byte) (int, error) { |
| 410 | if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil { |
| 411 | return 0, err |
| 412 | } |
| 413 | return t.Conn.Write(b) |
| 414 | } |
| 415 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 416 | func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error { |
David Benjamin | 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 | } |
| 439 | if *deterministic { |
| 440 | config.Rand = &deterministicRand{} |
| 441 | } |
| 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() { |
| 467 | writeTranscript(test, isResume, connDebug.Transcript()) |
| 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 | |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 618 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 619 | tlsConn.Write(nil) |
| 620 | } |
| 621 | |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 622 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 623 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 624 | } |
| 625 | |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 626 | if test.sendHalfHelloRequest { |
| 627 | tlsConn.SendHalfHelloRequest() |
| 628 | } |
| 629 | |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 630 | if test.renegotiate > 0 { |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 631 | if test.renegotiateCiphers != nil { |
| 632 | config.CipherSuites = test.renegotiateCiphers |
| 633 | } |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 634 | for i := 0; i < test.renegotiate; i++ { |
| 635 | if err := tlsConn.Renegotiate(); err != nil { |
| 636 | return err |
| 637 | } |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 638 | } |
| 639 | } else if test.renegotiateCiphers != nil { |
| 640 | panic("renegotiateCiphers without renegotiate") |
| 641 | } |
| 642 | |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 643 | if test.damageFirstWrite { |
| 644 | connDamage.setDamage(true) |
| 645 | tlsConn.Write([]byte("DAMAGED WRITE")) |
| 646 | connDamage.setDamage(false) |
| 647 | } |
| 648 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 649 | messageLen := test.messageLen |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 650 | if messageLen < 0 { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 651 | if test.protocol == dtls { |
| 652 | return fmt.Errorf("messageLen < 0 not supported for DTLS tests") |
| 653 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 654 | // Read until EOF. |
| 655 | _, err := io.Copy(ioutil.Discard, tlsConn) |
| 656 | return err |
| 657 | } |
David Benjamin | 4417d05 | 2015-04-05 04:17:25 -0400 | [diff] [blame] | 658 | if messageLen == 0 { |
| 659 | messageLen = 32 |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 660 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 661 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 662 | messageCount := test.messageCount |
| 663 | if messageCount == 0 { |
| 664 | messageCount = 1 |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 665 | } |
| 666 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 667 | for j := 0; j < messageCount; j++ { |
| 668 | testMessage := make([]byte, messageLen) |
| 669 | for i := range testMessage { |
| 670 | testMessage[i] = 0x42 ^ byte(j) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 671 | } |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 672 | tlsConn.Write(testMessage) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 673 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 674 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 675 | tlsConn.Write(nil) |
| 676 | } |
| 677 | |
| 678 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 679 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 680 | } |
| 681 | |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 682 | if test.shimShutsDown || test.expectMessageDropped { |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 683 | // The shim will not respond. |
| 684 | continue |
| 685 | } |
| 686 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 687 | buf := make([]byte, len(testMessage)) |
| 688 | if test.protocol == dtls { |
| 689 | bufTmp := make([]byte, len(buf)+1) |
| 690 | n, err := tlsConn.Read(bufTmp) |
| 691 | if err != nil { |
| 692 | return err |
| 693 | } |
| 694 | if n != len(buf) { |
| 695 | return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf)) |
| 696 | } |
| 697 | copy(buf, bufTmp) |
| 698 | } else { |
| 699 | _, err := io.ReadFull(tlsConn, buf) |
| 700 | if err != nil { |
| 701 | return err |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | for i, v := range buf { |
| 706 | if v != testMessage[i]^0xff { |
| 707 | return fmt.Errorf("bad reply contents at byte %d", i) |
| 708 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
| 712 | return nil |
| 713 | } |
| 714 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 715 | func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd { |
| 716 | valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"} |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 717 | if dbAttach { |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 718 | 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] | 719 | } |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 720 | valgrindArgs = append(valgrindArgs, path) |
| 721 | valgrindArgs = append(valgrindArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 722 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 723 | return exec.Command("valgrind", valgrindArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 724 | } |
| 725 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 726 | func gdbOf(path string, args ...string) *exec.Cmd { |
| 727 | xtermArgs := []string{"-e", "gdb", "--args"} |
| 728 | xtermArgs = append(xtermArgs, path) |
| 729 | xtermArgs = append(xtermArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 730 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 731 | return exec.Command("xterm", xtermArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 732 | } |
| 733 | |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 734 | func lldbOf(path string, args ...string) *exec.Cmd { |
| 735 | xtermArgs := []string{"-e", "lldb", "--"} |
| 736 | xtermArgs = append(xtermArgs, path) |
| 737 | xtermArgs = append(xtermArgs, args...) |
| 738 | |
| 739 | return exec.Command("xterm", xtermArgs...) |
| 740 | } |
| 741 | |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 742 | var ( |
| 743 | errMoreMallocs = errors.New("child process did not exhaust all allocation calls") |
| 744 | errUnimplemented = errors.New("child process does not implement needed flags") |
| 745 | ) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 746 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 747 | // accept accepts a connection from listener, unless waitChan signals a process |
| 748 | // exit first. |
| 749 | func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) { |
| 750 | type connOrError struct { |
| 751 | conn net.Conn |
| 752 | err error |
| 753 | } |
| 754 | connChan := make(chan connOrError, 1) |
| 755 | go func() { |
| 756 | conn, err := listener.Accept() |
| 757 | connChan <- connOrError{conn, err} |
| 758 | close(connChan) |
| 759 | }() |
| 760 | select { |
| 761 | case result := <-connChan: |
| 762 | return result.conn, result.err |
| 763 | case childErr := <-waitChan: |
| 764 | waitChan <- childErr |
| 765 | return nil, fmt.Errorf("child exited early: %s", childErr) |
| 766 | } |
| 767 | } |
| 768 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 769 | func translateExpectedError(errorStr string) string { |
| 770 | if translated, ok := shimConfig.ErrorMap[errorStr]; ok { |
| 771 | return translated |
| 772 | } |
| 773 | |
| 774 | if *looseErrors { |
| 775 | return "" |
| 776 | } |
| 777 | |
| 778 | return errorStr |
| 779 | } |
| 780 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 781 | func runTest(test *testCase, shimPath string, mallocNumToFail int64) error { |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 782 | if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) { |
| 783 | panic("Error expected without shouldFail in " + test.name) |
| 784 | } |
| 785 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 786 | if test.expectResumeRejected && !test.resumeSession { |
| 787 | panic("expectResumeRejected without resumeSession in " + test.name) |
| 788 | } |
| 789 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 790 | listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}}) |
| 791 | if err != nil { |
| 792 | panic(err) |
| 793 | } |
| 794 | defer func() { |
| 795 | if listener != nil { |
| 796 | listener.Close() |
| 797 | } |
| 798 | }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 799 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 800 | flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)} |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 801 | if test.testType == serverTest { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 802 | flags = append(flags, "-server") |
| 803 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 804 | flags = append(flags, "-key-file") |
| 805 | if test.keyFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 806 | flags = append(flags, path.Join(*resourceDir, rsaKeyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 807 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 808 | flags = append(flags, path.Join(*resourceDir, test.keyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | flags = append(flags, "-cert-file") |
| 812 | if test.certFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 813 | flags = append(flags, path.Join(*resourceDir, rsaCertificateFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 814 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 815 | flags = append(flags, path.Join(*resourceDir, test.certFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 816 | } |
| 817 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 818 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 819 | if test.protocol == dtls { |
| 820 | flags = append(flags, "-dtls") |
| 821 | } |
| 822 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 823 | if test.resumeSession { |
| 824 | flags = append(flags, "-resume") |
| 825 | } |
| 826 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 827 | if test.shimWritesFirst { |
| 828 | flags = append(flags, "-shim-writes-first") |
| 829 | } |
| 830 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 831 | if test.shimShutsDown { |
| 832 | flags = append(flags, "-shim-shuts-down") |
| 833 | } |
| 834 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 835 | if test.exportKeyingMaterial > 0 { |
| 836 | flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial)) |
| 837 | flags = append(flags, "-export-label", test.exportLabel) |
| 838 | flags = append(flags, "-export-context", test.exportContext) |
| 839 | if test.useExportContext { |
| 840 | flags = append(flags, "-use-export-context") |
| 841 | } |
| 842 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 843 | if test.expectResumeRejected { |
| 844 | flags = append(flags, "-expect-session-miss") |
| 845 | } |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 846 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 847 | if test.testTLSUnique { |
| 848 | flags = append(flags, "-tls-unique") |
| 849 | } |
| 850 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 851 | flags = append(flags, test.flags...) |
| 852 | |
| 853 | var shim *exec.Cmd |
| 854 | if *useValgrind { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 855 | shim = valgrindOf(false, shimPath, flags...) |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 856 | } else if *useGDB { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 857 | shim = gdbOf(shimPath, flags...) |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 858 | } else if *useLLDB { |
| 859 | shim = lldbOf(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 860 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 861 | shim = exec.Command(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 862 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 863 | shim.Stdin = os.Stdin |
| 864 | var stdoutBuf, stderrBuf bytes.Buffer |
| 865 | shim.Stdout = &stdoutBuf |
| 866 | shim.Stderr = &stderrBuf |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 867 | if mallocNumToFail >= 0 { |
David Benjamin | 9e128b0 | 2015-02-09 13:13:09 -0500 | [diff] [blame] | 868 | shim.Env = os.Environ() |
| 869 | 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] | 870 | if *mallocTestDebug { |
David Benjamin | 184494d | 2015-06-12 18:23:47 -0400 | [diff] [blame] | 871 | shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 872 | } |
| 873 | shim.Env = append(shim.Env, "_MALLOC_CHECK=1") |
| 874 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 875 | |
| 876 | if err := shim.Start(); err != nil { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 877 | panic(err) |
| 878 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 879 | waitChan := make(chan error, 1) |
| 880 | go func() { waitChan <- shim.Wait() }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 881 | |
| 882 | config := test.config |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 883 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 884 | conn, err := acceptOrWait(listener, waitChan) |
| 885 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 886 | err = doExchange(test, &config, conn, false /* not a resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 887 | conn.Close() |
| 888 | } |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 889 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 890 | if err == nil && test.resumeSession { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 891 | var resumeConfig Config |
| 892 | if test.resumeConfig != nil { |
| 893 | resumeConfig = *test.resumeConfig |
David Benjamin | e54af06 | 2016-08-08 19:21:18 -0400 | [diff] [blame] | 894 | if !test.newSessionsOnResume { |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 895 | resumeConfig.SessionTicketKey = config.SessionTicketKey |
| 896 | resumeConfig.ClientSessionCache = config.ClientSessionCache |
| 897 | resumeConfig.ServerSessionCache = config.ServerSessionCache |
| 898 | } |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 899 | resumeConfig.Rand = config.Rand |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 900 | } else { |
| 901 | resumeConfig = config |
| 902 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 903 | var connResume net.Conn |
| 904 | connResume, err = acceptOrWait(listener, waitChan) |
| 905 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 906 | err = doExchange(test, &resumeConfig, connResume, true /* resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 907 | connResume.Close() |
| 908 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 909 | } |
| 910 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 911 | // Close the listener now. This is to avoid hangs should the shim try to |
| 912 | // open more connections than expected. |
| 913 | listener.Close() |
| 914 | listener = nil |
| 915 | |
| 916 | childErr := <-waitChan |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 917 | if exitError, ok := childErr.(*exec.ExitError); ok { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 918 | switch exitError.Sys().(syscall.WaitStatus).ExitStatus() { |
| 919 | case 88: |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 920 | return errMoreMallocs |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 921 | case 89: |
| 922 | return errUnimplemented |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 923 | } |
| 924 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 925 | |
David Benjamin | 9bea349 | 2016-03-02 10:59:16 -0500 | [diff] [blame] | 926 | // Account for Windows line endings. |
| 927 | stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1) |
| 928 | stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1) |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 929 | |
| 930 | // Separate the errors from the shim and those from tools like |
| 931 | // AddressSanitizer. |
| 932 | var extraStderr string |
| 933 | if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 { |
| 934 | stderr = stderrParts[0] |
| 935 | extraStderr = stderrParts[1] |
| 936 | } |
| 937 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 938 | failed := err != nil || childErr != nil |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 939 | expectedError := translateExpectedError(test.expectedError) |
| 940 | correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError) |
EKR | 173bf93 | 2016-07-29 15:52:49 +0200 | [diff] [blame] | 941 | |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 942 | localError := "none" |
| 943 | if err != nil { |
| 944 | localError = err.Error() |
| 945 | } |
| 946 | if len(test.expectedLocalError) != 0 { |
| 947 | correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError) |
| 948 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 949 | |
| 950 | if failed != test.shouldFail || failed && !correctFailure { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 951 | childError := "none" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 952 | if childErr != nil { |
| 953 | childError = childErr.Error() |
| 954 | } |
| 955 | |
| 956 | var msg string |
| 957 | switch { |
| 958 | case failed && !test.shouldFail: |
| 959 | msg = "unexpected failure" |
| 960 | case !failed && test.shouldFail: |
| 961 | msg = "unexpected success" |
| 962 | case failed && !correctFailure: |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 963 | msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 964 | default: |
| 965 | panic("internal error") |
| 966 | } |
| 967 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 968 | return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 969 | } |
| 970 | |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 971 | if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) { |
| 972 | return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | return nil |
| 976 | } |
| 977 | |
| 978 | var tlsVersions = []struct { |
| 979 | name string |
| 980 | version uint16 |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 981 | flag string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 982 | hasDTLS bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 983 | }{ |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 984 | {"SSL3", VersionSSL30, "-no-ssl3", false}, |
| 985 | {"TLS1", VersionTLS10, "-no-tls1", true}, |
| 986 | {"TLS11", VersionTLS11, "-no-tls11", false}, |
| 987 | {"TLS12", VersionTLS12, "-no-tls12", true}, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 988 | {"TLS13", VersionTLS13, "-no-tls13", false}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | var testCipherSuites = []struct { |
| 992 | name string |
| 993 | id uint16 |
| 994 | }{ |
| 995 | {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 996 | {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 997 | {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 998 | {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 999 | {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1000 | {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1001 | {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1002 | {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1003 | {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1004 | {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1005 | {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384}, |
| 1006 | {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1007 | {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1008 | {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1009 | {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1010 | {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}, |
| 1011 | {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1012 | {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1013 | {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1014 | {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 1015 | {"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] | 1016 | {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1017 | {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1018 | {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1019 | {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1020 | {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1021 | {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1022 | {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1023 | {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 1024 | {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1025 | {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA}, |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 1026 | {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 1027 | {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 1028 | {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 1029 | {"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] | 1030 | {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 1031 | {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA}, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 1032 | {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 1033 | {"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] | 1034 | {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256}, |
Steven Valdez | 3084e7b | 2016-06-02 12:07:20 -0400 | [diff] [blame] | 1035 | {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256}, |
| 1036 | {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384}, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1037 | {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1038 | {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1039 | {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA}, |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1040 | {"NULL-SHA", TLS_RSA_WITH_NULL_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1043 | func hasComponent(suiteName, component string) bool { |
| 1044 | return strings.Contains("-"+suiteName+"-", "-"+component+"-") |
| 1045 | } |
| 1046 | |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1047 | func isTLS12Only(suiteName string) bool { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1048 | return hasComponent(suiteName, "GCM") || |
| 1049 | hasComponent(suiteName, "SHA256") || |
David Benjamin | e9a80ff | 2015-04-07 00:46:46 -0400 | [diff] [blame] | 1050 | hasComponent(suiteName, "SHA384") || |
| 1051 | hasComponent(suiteName, "POLY1305") |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1052 | } |
| 1053 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1054 | func isTLS13Suite(suiteName string) bool { |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 1055 | // Only AEADs. |
| 1056 | if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") { |
| 1057 | return false |
| 1058 | } |
| 1059 | // No old CHACHA20_POLY1305. |
| 1060 | if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") { |
| 1061 | return false |
| 1062 | } |
| 1063 | // Must have ECDHE. |
| 1064 | // TODO(davidben,svaldez): Add pure PSK support. |
| 1065 | if !hasComponent(suiteName, "ECDHE") { |
| 1066 | return false |
| 1067 | } |
| 1068 | // TODO(davidben,svaldez): Add PSK support. |
| 1069 | if hasComponent(suiteName, "PSK") { |
| 1070 | return false |
| 1071 | } |
| 1072 | return true |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1075 | func isDTLSCipher(suiteName string) bool { |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1076 | return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL") |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1077 | } |
| 1078 | |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 1079 | func bigFromHex(hex string) *big.Int { |
| 1080 | ret, ok := new(big.Int).SetString(hex, 16) |
| 1081 | if !ok { |
| 1082 | panic("failed to parse hex number 0x" + hex) |
| 1083 | } |
| 1084 | return ret |
| 1085 | } |
| 1086 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1087 | func addBasicTests() { |
| 1088 | basicTests := []testCase{ |
| 1089 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1090 | name: "NoFallbackSCSV", |
| 1091 | config: Config{ |
| 1092 | Bugs: ProtocolBugs{ |
| 1093 | FailIfNotFallbackSCSV: true, |
| 1094 | }, |
| 1095 | }, |
| 1096 | shouldFail: true, |
| 1097 | expectedLocalError: "no fallback SCSV found", |
| 1098 | }, |
| 1099 | { |
| 1100 | name: "SendFallbackSCSV", |
| 1101 | config: Config{ |
| 1102 | Bugs: ProtocolBugs{ |
| 1103 | FailIfNotFallbackSCSV: true, |
| 1104 | }, |
| 1105 | }, |
| 1106 | flags: []string{"-fallback-scsv"}, |
| 1107 | }, |
| 1108 | { |
| 1109 | name: "ClientCertificateTypes", |
| 1110 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1111 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1112 | ClientAuth: RequestClientCert, |
| 1113 | ClientCertificateTypes: []byte{ |
| 1114 | CertTypeDSSSign, |
| 1115 | CertTypeRSASign, |
| 1116 | CertTypeECDSASign, |
| 1117 | }, |
| 1118 | }, |
| 1119 | flags: []string{ |
| 1120 | "-expect-certificate-types", |
| 1121 | base64.StdEncoding.EncodeToString([]byte{ |
| 1122 | CertTypeDSSSign, |
| 1123 | CertTypeRSASign, |
| 1124 | CertTypeECDSASign, |
| 1125 | }), |
| 1126 | }, |
| 1127 | }, |
| 1128 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1129 | name: "UnauthenticatedECDH", |
| 1130 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1131 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1132 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1133 | Bugs: ProtocolBugs{ |
| 1134 | UnauthenticatedECDH: true, |
| 1135 | }, |
| 1136 | }, |
| 1137 | shouldFail: true, |
| 1138 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1139 | }, |
| 1140 | { |
| 1141 | name: "SkipCertificateStatus", |
| 1142 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1143 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1144 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1145 | Bugs: ProtocolBugs{ |
| 1146 | SkipCertificateStatus: true, |
| 1147 | }, |
| 1148 | }, |
| 1149 | flags: []string{ |
| 1150 | "-enable-ocsp-stapling", |
| 1151 | }, |
| 1152 | }, |
| 1153 | { |
| 1154 | name: "SkipServerKeyExchange", |
| 1155 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1156 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1157 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1158 | Bugs: ProtocolBugs{ |
| 1159 | SkipServerKeyExchange: true, |
| 1160 | }, |
| 1161 | }, |
| 1162 | shouldFail: true, |
| 1163 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1164 | }, |
| 1165 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1166 | testType: serverTest, |
| 1167 | name: "Alert", |
| 1168 | config: Config{ |
| 1169 | Bugs: ProtocolBugs{ |
| 1170 | SendSpuriousAlert: alertRecordOverflow, |
| 1171 | }, |
| 1172 | }, |
| 1173 | shouldFail: true, |
| 1174 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1175 | }, |
| 1176 | { |
| 1177 | protocol: dtls, |
| 1178 | testType: serverTest, |
| 1179 | name: "Alert-DTLS", |
| 1180 | config: Config{ |
| 1181 | Bugs: ProtocolBugs{ |
| 1182 | SendSpuriousAlert: alertRecordOverflow, |
| 1183 | }, |
| 1184 | }, |
| 1185 | shouldFail: true, |
| 1186 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1187 | }, |
| 1188 | { |
| 1189 | testType: serverTest, |
| 1190 | name: "FragmentAlert", |
| 1191 | config: Config{ |
| 1192 | Bugs: ProtocolBugs{ |
| 1193 | FragmentAlert: true, |
| 1194 | SendSpuriousAlert: alertRecordOverflow, |
| 1195 | }, |
| 1196 | }, |
| 1197 | shouldFail: true, |
| 1198 | expectedError: ":BAD_ALERT:", |
| 1199 | }, |
| 1200 | { |
| 1201 | protocol: dtls, |
| 1202 | testType: serverTest, |
| 1203 | name: "FragmentAlert-DTLS", |
| 1204 | config: Config{ |
| 1205 | Bugs: ProtocolBugs{ |
| 1206 | FragmentAlert: true, |
| 1207 | SendSpuriousAlert: alertRecordOverflow, |
| 1208 | }, |
| 1209 | }, |
| 1210 | shouldFail: true, |
| 1211 | expectedError: ":BAD_ALERT:", |
| 1212 | }, |
| 1213 | { |
| 1214 | testType: serverTest, |
David Benjamin | 0d3a8c6 | 2016-03-11 22:25:18 -0500 | [diff] [blame] | 1215 | name: "DoubleAlert", |
| 1216 | config: Config{ |
| 1217 | Bugs: ProtocolBugs{ |
| 1218 | DoubleAlert: true, |
| 1219 | SendSpuriousAlert: alertRecordOverflow, |
| 1220 | }, |
| 1221 | }, |
| 1222 | shouldFail: true, |
| 1223 | expectedError: ":BAD_ALERT:", |
| 1224 | }, |
| 1225 | { |
| 1226 | protocol: dtls, |
| 1227 | testType: serverTest, |
| 1228 | name: "DoubleAlert-DTLS", |
| 1229 | config: Config{ |
| 1230 | Bugs: ProtocolBugs{ |
| 1231 | DoubleAlert: true, |
| 1232 | SendSpuriousAlert: alertRecordOverflow, |
| 1233 | }, |
| 1234 | }, |
| 1235 | shouldFail: true, |
| 1236 | expectedError: ":BAD_ALERT:", |
| 1237 | }, |
| 1238 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1239 | name: "SkipNewSessionTicket", |
| 1240 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1241 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1242 | Bugs: ProtocolBugs{ |
| 1243 | SkipNewSessionTicket: true, |
| 1244 | }, |
| 1245 | }, |
| 1246 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1247 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1248 | }, |
| 1249 | { |
| 1250 | testType: serverTest, |
| 1251 | name: "FallbackSCSV", |
| 1252 | config: Config{ |
| 1253 | MaxVersion: VersionTLS11, |
| 1254 | Bugs: ProtocolBugs{ |
| 1255 | SendFallbackSCSV: true, |
| 1256 | }, |
| 1257 | }, |
| 1258 | shouldFail: true, |
| 1259 | expectedError: ":INAPPROPRIATE_FALLBACK:", |
| 1260 | }, |
| 1261 | { |
| 1262 | testType: serverTest, |
| 1263 | name: "FallbackSCSV-VersionMatch", |
| 1264 | config: Config{ |
| 1265 | Bugs: ProtocolBugs{ |
| 1266 | SendFallbackSCSV: true, |
| 1267 | }, |
| 1268 | }, |
| 1269 | }, |
| 1270 | { |
| 1271 | testType: serverTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1272 | name: "FallbackSCSV-VersionMatch-TLS12", |
| 1273 | config: Config{ |
| 1274 | MaxVersion: VersionTLS12, |
| 1275 | Bugs: ProtocolBugs{ |
| 1276 | SendFallbackSCSV: true, |
| 1277 | }, |
| 1278 | }, |
| 1279 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 1280 | }, |
| 1281 | { |
| 1282 | testType: serverTest, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1283 | name: "FragmentedClientVersion", |
| 1284 | config: Config{ |
| 1285 | Bugs: ProtocolBugs{ |
| 1286 | MaxHandshakeRecordLength: 1, |
| 1287 | FragmentClientVersion: true, |
| 1288 | }, |
| 1289 | }, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1290 | expectedVersion: VersionTLS13, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1291 | }, |
| 1292 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1293 | testType: serverTest, |
| 1294 | name: "HttpGET", |
| 1295 | sendPrefix: "GET / HTTP/1.0\n", |
| 1296 | shouldFail: true, |
| 1297 | expectedError: ":HTTP_REQUEST:", |
| 1298 | }, |
| 1299 | { |
| 1300 | testType: serverTest, |
| 1301 | name: "HttpPOST", |
| 1302 | sendPrefix: "POST / HTTP/1.0\n", |
| 1303 | shouldFail: true, |
| 1304 | expectedError: ":HTTP_REQUEST:", |
| 1305 | }, |
| 1306 | { |
| 1307 | testType: serverTest, |
| 1308 | name: "HttpHEAD", |
| 1309 | sendPrefix: "HEAD / HTTP/1.0\n", |
| 1310 | shouldFail: true, |
| 1311 | expectedError: ":HTTP_REQUEST:", |
| 1312 | }, |
| 1313 | { |
| 1314 | testType: serverTest, |
| 1315 | name: "HttpPUT", |
| 1316 | sendPrefix: "PUT / HTTP/1.0\n", |
| 1317 | shouldFail: true, |
| 1318 | expectedError: ":HTTP_REQUEST:", |
| 1319 | }, |
| 1320 | { |
| 1321 | testType: serverTest, |
| 1322 | name: "HttpCONNECT", |
| 1323 | sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n", |
| 1324 | shouldFail: true, |
| 1325 | expectedError: ":HTTPS_PROXY_REQUEST:", |
| 1326 | }, |
| 1327 | { |
| 1328 | testType: serverTest, |
| 1329 | name: "Garbage", |
| 1330 | sendPrefix: "blah", |
| 1331 | shouldFail: true, |
David Benjamin | 97760d5 | 2015-07-24 23:02:49 -0400 | [diff] [blame] | 1332 | expectedError: ":WRONG_VERSION_NUMBER:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1333 | }, |
| 1334 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1335 | name: "RSAEphemeralKey", |
| 1336 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1337 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1338 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 1339 | Bugs: ProtocolBugs{ |
| 1340 | RSAEphemeralKey: true, |
| 1341 | }, |
| 1342 | }, |
| 1343 | shouldFail: true, |
| 1344 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1345 | }, |
| 1346 | { |
| 1347 | name: "DisableEverything", |
Steven Valdez | 4f94b1c | 2016-05-24 12:31:07 -0400 | [diff] [blame] | 1348 | flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1349 | shouldFail: true, |
| 1350 | expectedError: ":WRONG_SSL_VERSION:", |
| 1351 | }, |
| 1352 | { |
| 1353 | protocol: dtls, |
| 1354 | name: "DisableEverything-DTLS", |
| 1355 | flags: []string{"-no-tls12", "-no-tls1"}, |
| 1356 | shouldFail: true, |
| 1357 | expectedError: ":WRONG_SSL_VERSION:", |
| 1358 | }, |
| 1359 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1360 | protocol: dtls, |
| 1361 | testType: serverTest, |
| 1362 | name: "MTU", |
| 1363 | config: Config{ |
| 1364 | Bugs: ProtocolBugs{ |
| 1365 | MaxPacketLength: 256, |
| 1366 | }, |
| 1367 | }, |
| 1368 | flags: []string{"-mtu", "256"}, |
| 1369 | }, |
| 1370 | { |
| 1371 | protocol: dtls, |
| 1372 | testType: serverTest, |
| 1373 | name: "MTUExceeded", |
| 1374 | config: Config{ |
| 1375 | Bugs: ProtocolBugs{ |
| 1376 | MaxPacketLength: 255, |
| 1377 | }, |
| 1378 | }, |
| 1379 | flags: []string{"-mtu", "256"}, |
| 1380 | shouldFail: true, |
| 1381 | expectedLocalError: "dtls: exceeded maximum packet length", |
| 1382 | }, |
| 1383 | { |
| 1384 | name: "CertMismatchRSA", |
| 1385 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1386 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1387 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1388 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1389 | Bugs: ProtocolBugs{ |
| 1390 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1391 | }, |
| 1392 | }, |
| 1393 | shouldFail: true, |
| 1394 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1395 | }, |
| 1396 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1397 | name: "CertMismatchRSA-TLS13", |
| 1398 | config: Config{ |
| 1399 | MaxVersion: VersionTLS13, |
| 1400 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1401 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 1402 | Bugs: ProtocolBugs{ |
| 1403 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1404 | }, |
| 1405 | }, |
| 1406 | shouldFail: true, |
| 1407 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1408 | }, |
| 1409 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1410 | name: "CertMismatchECDSA", |
| 1411 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1412 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1413 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1414 | Certificates: []Certificate{rsaCertificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1415 | Bugs: ProtocolBugs{ |
| 1416 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1417 | }, |
| 1418 | }, |
| 1419 | shouldFail: true, |
| 1420 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1421 | }, |
| 1422 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1423 | name: "CertMismatchECDSA-TLS13", |
| 1424 | config: Config{ |
| 1425 | MaxVersion: VersionTLS13, |
| 1426 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1427 | Certificates: []Certificate{rsaCertificate}, |
| 1428 | Bugs: ProtocolBugs{ |
| 1429 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1430 | }, |
| 1431 | }, |
| 1432 | shouldFail: true, |
| 1433 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1434 | }, |
| 1435 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1436 | name: "EmptyCertificateList", |
| 1437 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1438 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1439 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1440 | Bugs: ProtocolBugs{ |
| 1441 | EmptyCertificateList: true, |
| 1442 | }, |
| 1443 | }, |
| 1444 | shouldFail: true, |
| 1445 | expectedError: ":DECODE_ERROR:", |
| 1446 | }, |
| 1447 | { |
David Benjamin | 9ec1c75 | 2016-07-14 12:45:01 -0400 | [diff] [blame] | 1448 | name: "EmptyCertificateList-TLS13", |
| 1449 | config: Config{ |
| 1450 | MaxVersion: VersionTLS13, |
| 1451 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1452 | Bugs: ProtocolBugs{ |
| 1453 | EmptyCertificateList: true, |
| 1454 | }, |
| 1455 | }, |
| 1456 | shouldFail: true, |
David Benjamin | 4087df9 | 2016-08-01 20:16:31 -0400 | [diff] [blame] | 1457 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
David Benjamin | 9ec1c75 | 2016-07-14 12:45:01 -0400 | [diff] [blame] | 1458 | }, |
| 1459 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1460 | name: "TLSFatalBadPackets", |
| 1461 | damageFirstWrite: true, |
| 1462 | shouldFail: true, |
| 1463 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 1464 | }, |
| 1465 | { |
| 1466 | protocol: dtls, |
| 1467 | name: "DTLSIgnoreBadPackets", |
| 1468 | damageFirstWrite: true, |
| 1469 | }, |
| 1470 | { |
| 1471 | protocol: dtls, |
| 1472 | name: "DTLSIgnoreBadPackets-Async", |
| 1473 | damageFirstWrite: true, |
| 1474 | flags: []string{"-async"}, |
| 1475 | }, |
| 1476 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1477 | name: "AppDataBeforeHandshake", |
| 1478 | config: Config{ |
| 1479 | Bugs: ProtocolBugs{ |
| 1480 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1481 | }, |
| 1482 | }, |
| 1483 | shouldFail: true, |
| 1484 | expectedError: ":UNEXPECTED_RECORD:", |
| 1485 | }, |
| 1486 | { |
| 1487 | name: "AppDataBeforeHandshake-Empty", |
| 1488 | config: Config{ |
| 1489 | Bugs: ProtocolBugs{ |
| 1490 | AppDataBeforeHandshake: []byte{}, |
| 1491 | }, |
| 1492 | }, |
| 1493 | shouldFail: true, |
| 1494 | expectedError: ":UNEXPECTED_RECORD:", |
| 1495 | }, |
| 1496 | { |
| 1497 | protocol: dtls, |
| 1498 | name: "AppDataBeforeHandshake-DTLS", |
| 1499 | config: Config{ |
| 1500 | Bugs: ProtocolBugs{ |
| 1501 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1502 | }, |
| 1503 | }, |
| 1504 | shouldFail: true, |
| 1505 | expectedError: ":UNEXPECTED_RECORD:", |
| 1506 | }, |
| 1507 | { |
| 1508 | protocol: dtls, |
| 1509 | name: "AppDataBeforeHandshake-DTLS-Empty", |
| 1510 | config: Config{ |
| 1511 | Bugs: ProtocolBugs{ |
| 1512 | AppDataBeforeHandshake: []byte{}, |
| 1513 | }, |
| 1514 | }, |
| 1515 | shouldFail: true, |
| 1516 | expectedError: ":UNEXPECTED_RECORD:", |
| 1517 | }, |
| 1518 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1519 | name: "AppDataAfterChangeCipherSpec", |
| 1520 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1521 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1522 | Bugs: ProtocolBugs{ |
| 1523 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1524 | }, |
| 1525 | }, |
| 1526 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1527 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1528 | }, |
| 1529 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1530 | name: "AppDataAfterChangeCipherSpec-Empty", |
| 1531 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1532 | MaxVersion: VersionTLS12, |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1533 | Bugs: ProtocolBugs{ |
| 1534 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1535 | }, |
| 1536 | }, |
| 1537 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1538 | expectedError: ":UNEXPECTED_RECORD:", |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1539 | }, |
| 1540 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1541 | protocol: dtls, |
| 1542 | name: "AppDataAfterChangeCipherSpec-DTLS", |
| 1543 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1544 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1545 | Bugs: ProtocolBugs{ |
| 1546 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1547 | }, |
| 1548 | }, |
| 1549 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1550 | // application data. |
| 1551 | }, |
| 1552 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1553 | protocol: dtls, |
| 1554 | name: "AppDataAfterChangeCipherSpec-DTLS-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 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1562 | // application data. |
| 1563 | }, |
| 1564 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1565 | name: "AlertAfterChangeCipherSpec", |
| 1566 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1567 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1568 | Bugs: ProtocolBugs{ |
| 1569 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1570 | }, |
| 1571 | }, |
| 1572 | shouldFail: true, |
| 1573 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1574 | }, |
| 1575 | { |
| 1576 | protocol: dtls, |
| 1577 | name: "AlertAfterChangeCipherSpec-DTLS", |
| 1578 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1579 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1580 | Bugs: ProtocolBugs{ |
| 1581 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1582 | }, |
| 1583 | }, |
| 1584 | shouldFail: true, |
| 1585 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1586 | }, |
| 1587 | { |
| 1588 | protocol: dtls, |
| 1589 | name: "ReorderHandshakeFragments-Small-DTLS", |
| 1590 | config: Config{ |
| 1591 | Bugs: ProtocolBugs{ |
| 1592 | ReorderHandshakeFragments: true, |
| 1593 | // Small enough that every handshake message is |
| 1594 | // fragmented. |
| 1595 | MaxHandshakeRecordLength: 2, |
| 1596 | }, |
| 1597 | }, |
| 1598 | }, |
| 1599 | { |
| 1600 | protocol: dtls, |
| 1601 | name: "ReorderHandshakeFragments-Large-DTLS", |
| 1602 | config: Config{ |
| 1603 | Bugs: ProtocolBugs{ |
| 1604 | ReorderHandshakeFragments: true, |
| 1605 | // Large enough that no handshake message is |
| 1606 | // fragmented. |
| 1607 | MaxHandshakeRecordLength: 2048, |
| 1608 | }, |
| 1609 | }, |
| 1610 | }, |
| 1611 | { |
| 1612 | protocol: dtls, |
| 1613 | name: "MixCompleteMessageWithFragments-DTLS", |
| 1614 | config: Config{ |
| 1615 | Bugs: ProtocolBugs{ |
| 1616 | ReorderHandshakeFragments: true, |
| 1617 | MixCompleteMessageWithFragments: true, |
| 1618 | MaxHandshakeRecordLength: 2, |
| 1619 | }, |
| 1620 | }, |
| 1621 | }, |
| 1622 | { |
| 1623 | name: "SendInvalidRecordType", |
| 1624 | config: Config{ |
| 1625 | Bugs: ProtocolBugs{ |
| 1626 | SendInvalidRecordType: true, |
| 1627 | }, |
| 1628 | }, |
| 1629 | shouldFail: true, |
| 1630 | expectedError: ":UNEXPECTED_RECORD:", |
| 1631 | }, |
| 1632 | { |
| 1633 | protocol: dtls, |
| 1634 | name: "SendInvalidRecordType-DTLS", |
| 1635 | config: Config{ |
| 1636 | Bugs: ProtocolBugs{ |
| 1637 | SendInvalidRecordType: true, |
| 1638 | }, |
| 1639 | }, |
| 1640 | shouldFail: true, |
| 1641 | expectedError: ":UNEXPECTED_RECORD:", |
| 1642 | }, |
| 1643 | { |
| 1644 | name: "FalseStart-SkipServerSecondLeg", |
| 1645 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1646 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1647 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1648 | NextProtos: []string{"foo"}, |
| 1649 | Bugs: ProtocolBugs{ |
| 1650 | SkipNewSessionTicket: true, |
| 1651 | SkipChangeCipherSpec: true, |
| 1652 | SkipFinished: true, |
| 1653 | ExpectFalseStart: true, |
| 1654 | }, |
| 1655 | }, |
| 1656 | flags: []string{ |
| 1657 | "-false-start", |
| 1658 | "-handshake-never-done", |
| 1659 | "-advertise-alpn", "\x03foo", |
| 1660 | }, |
| 1661 | shimWritesFirst: true, |
| 1662 | shouldFail: true, |
| 1663 | expectedError: ":UNEXPECTED_RECORD:", |
| 1664 | }, |
| 1665 | { |
| 1666 | name: "FalseStart-SkipServerSecondLeg-Implicit", |
| 1667 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1668 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1669 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1670 | NextProtos: []string{"foo"}, |
| 1671 | Bugs: ProtocolBugs{ |
| 1672 | SkipNewSessionTicket: true, |
| 1673 | SkipChangeCipherSpec: true, |
| 1674 | SkipFinished: true, |
| 1675 | }, |
| 1676 | }, |
| 1677 | flags: []string{ |
| 1678 | "-implicit-handshake", |
| 1679 | "-false-start", |
| 1680 | "-handshake-never-done", |
| 1681 | "-advertise-alpn", "\x03foo", |
| 1682 | }, |
| 1683 | shouldFail: true, |
| 1684 | expectedError: ":UNEXPECTED_RECORD:", |
| 1685 | }, |
| 1686 | { |
| 1687 | testType: serverTest, |
| 1688 | name: "FailEarlyCallback", |
| 1689 | flags: []string{"-fail-early-callback"}, |
| 1690 | shouldFail: true, |
| 1691 | expectedError: ":CONNECTION_REJECTED:", |
| 1692 | expectedLocalError: "remote error: access denied", |
| 1693 | }, |
| 1694 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1695 | protocol: dtls, |
| 1696 | name: "FragmentMessageTypeMismatch-DTLS", |
| 1697 | config: Config{ |
| 1698 | Bugs: ProtocolBugs{ |
| 1699 | MaxHandshakeRecordLength: 2, |
| 1700 | FragmentMessageTypeMismatch: true, |
| 1701 | }, |
| 1702 | }, |
| 1703 | shouldFail: true, |
| 1704 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1705 | }, |
| 1706 | { |
| 1707 | protocol: dtls, |
| 1708 | name: "FragmentMessageLengthMismatch-DTLS", |
| 1709 | config: Config{ |
| 1710 | Bugs: ProtocolBugs{ |
| 1711 | MaxHandshakeRecordLength: 2, |
| 1712 | FragmentMessageLengthMismatch: true, |
| 1713 | }, |
| 1714 | }, |
| 1715 | shouldFail: true, |
| 1716 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1717 | }, |
| 1718 | { |
| 1719 | protocol: dtls, |
| 1720 | name: "SplitFragments-Header-DTLS", |
| 1721 | config: Config{ |
| 1722 | Bugs: ProtocolBugs{ |
| 1723 | SplitFragments: 2, |
| 1724 | }, |
| 1725 | }, |
| 1726 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1727 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1728 | }, |
| 1729 | { |
| 1730 | protocol: dtls, |
| 1731 | name: "SplitFragments-Boundary-DTLS", |
| 1732 | config: Config{ |
| 1733 | Bugs: ProtocolBugs{ |
| 1734 | SplitFragments: dtlsRecordHeaderLen, |
| 1735 | }, |
| 1736 | }, |
| 1737 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1738 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1739 | }, |
| 1740 | { |
| 1741 | protocol: dtls, |
| 1742 | name: "SplitFragments-Body-DTLS", |
| 1743 | config: Config{ |
| 1744 | Bugs: ProtocolBugs{ |
| 1745 | SplitFragments: dtlsRecordHeaderLen + 1, |
| 1746 | }, |
| 1747 | }, |
| 1748 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1749 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1750 | }, |
| 1751 | { |
| 1752 | protocol: dtls, |
| 1753 | name: "SendEmptyFragments-DTLS", |
| 1754 | config: Config{ |
| 1755 | Bugs: ProtocolBugs{ |
| 1756 | SendEmptyFragments: true, |
| 1757 | }, |
| 1758 | }, |
| 1759 | }, |
| 1760 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1761 | name: "BadFinished-Client", |
| 1762 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1763 | MaxVersion: VersionTLS12, |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1764 | Bugs: ProtocolBugs{ |
| 1765 | BadFinished: true, |
| 1766 | }, |
| 1767 | }, |
| 1768 | shouldFail: true, |
| 1769 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1770 | }, |
| 1771 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1772 | name: "BadFinished-Client-TLS13", |
| 1773 | config: Config{ |
| 1774 | MaxVersion: VersionTLS13, |
| 1775 | Bugs: ProtocolBugs{ |
| 1776 | BadFinished: true, |
| 1777 | }, |
| 1778 | }, |
| 1779 | shouldFail: true, |
| 1780 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1781 | }, |
| 1782 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1783 | testType: serverTest, |
| 1784 | name: "BadFinished-Server", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1785 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1786 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1787 | Bugs: ProtocolBugs{ |
| 1788 | BadFinished: true, |
| 1789 | }, |
| 1790 | }, |
| 1791 | shouldFail: true, |
| 1792 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1793 | }, |
| 1794 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1795 | testType: serverTest, |
| 1796 | name: "BadFinished-Server-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 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1807 | name: "FalseStart-BadFinished", |
| 1808 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1809 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1810 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1811 | NextProtos: []string{"foo"}, |
| 1812 | Bugs: ProtocolBugs{ |
| 1813 | BadFinished: true, |
| 1814 | ExpectFalseStart: true, |
| 1815 | }, |
| 1816 | }, |
| 1817 | flags: []string{ |
| 1818 | "-false-start", |
| 1819 | "-handshake-never-done", |
| 1820 | "-advertise-alpn", "\x03foo", |
| 1821 | }, |
| 1822 | shimWritesFirst: true, |
| 1823 | shouldFail: true, |
| 1824 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1825 | }, |
| 1826 | { |
| 1827 | name: "NoFalseStart-NoALPN", |
| 1828 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1829 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1830 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1831 | Bugs: ProtocolBugs{ |
| 1832 | ExpectFalseStart: true, |
| 1833 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1834 | }, |
| 1835 | }, |
| 1836 | flags: []string{ |
| 1837 | "-false-start", |
| 1838 | }, |
| 1839 | shimWritesFirst: true, |
| 1840 | shouldFail: true, |
| 1841 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1842 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1843 | }, |
| 1844 | { |
| 1845 | name: "NoFalseStart-NoAEAD", |
| 1846 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1847 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1848 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1849 | NextProtos: []string{"foo"}, |
| 1850 | Bugs: ProtocolBugs{ |
| 1851 | ExpectFalseStart: true, |
| 1852 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1853 | }, |
| 1854 | }, |
| 1855 | flags: []string{ |
| 1856 | "-false-start", |
| 1857 | "-advertise-alpn", "\x03foo", |
| 1858 | }, |
| 1859 | shimWritesFirst: true, |
| 1860 | shouldFail: true, |
| 1861 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1862 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1863 | }, |
| 1864 | { |
| 1865 | name: "NoFalseStart-RSA", |
| 1866 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1867 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1868 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1869 | NextProtos: []string{"foo"}, |
| 1870 | Bugs: ProtocolBugs{ |
| 1871 | ExpectFalseStart: true, |
| 1872 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1873 | }, |
| 1874 | }, |
| 1875 | flags: []string{ |
| 1876 | "-false-start", |
| 1877 | "-advertise-alpn", "\x03foo", |
| 1878 | }, |
| 1879 | shimWritesFirst: true, |
| 1880 | shouldFail: true, |
| 1881 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1882 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1883 | }, |
| 1884 | { |
| 1885 | name: "NoFalseStart-DHE_RSA", |
| 1886 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1887 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1888 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1889 | NextProtos: []string{"foo"}, |
| 1890 | Bugs: ProtocolBugs{ |
| 1891 | ExpectFalseStart: true, |
| 1892 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1893 | }, |
| 1894 | }, |
| 1895 | flags: []string{ |
| 1896 | "-false-start", |
| 1897 | "-advertise-alpn", "\x03foo", |
| 1898 | }, |
| 1899 | shimWritesFirst: true, |
| 1900 | shouldFail: true, |
| 1901 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1902 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1903 | }, |
| 1904 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1905 | protocol: dtls, |
| 1906 | name: "SendSplitAlert-Sync", |
| 1907 | config: Config{ |
| 1908 | Bugs: ProtocolBugs{ |
| 1909 | SendSplitAlert: true, |
| 1910 | }, |
| 1911 | }, |
| 1912 | }, |
| 1913 | { |
| 1914 | protocol: dtls, |
| 1915 | name: "SendSplitAlert-Async", |
| 1916 | config: Config{ |
| 1917 | Bugs: ProtocolBugs{ |
| 1918 | SendSplitAlert: true, |
| 1919 | }, |
| 1920 | }, |
| 1921 | flags: []string{"-async"}, |
| 1922 | }, |
| 1923 | { |
| 1924 | protocol: dtls, |
| 1925 | name: "PackDTLSHandshake", |
| 1926 | config: Config{ |
| 1927 | Bugs: ProtocolBugs{ |
| 1928 | MaxHandshakeRecordLength: 2, |
| 1929 | PackHandshakeFragments: 20, |
| 1930 | PackHandshakeRecords: 200, |
| 1931 | }, |
| 1932 | }, |
| 1933 | }, |
| 1934 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1935 | name: "SendEmptyRecords-Pass", |
| 1936 | sendEmptyRecords: 32, |
| 1937 | }, |
| 1938 | { |
| 1939 | name: "SendEmptyRecords", |
| 1940 | sendEmptyRecords: 33, |
| 1941 | shouldFail: true, |
| 1942 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1943 | }, |
| 1944 | { |
| 1945 | name: "SendEmptyRecords-Async", |
| 1946 | sendEmptyRecords: 33, |
| 1947 | flags: []string{"-async"}, |
| 1948 | shouldFail: true, |
| 1949 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1950 | }, |
| 1951 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 1952 | name: "SendWarningAlerts-Pass", |
| 1953 | config: Config{ |
| 1954 | MaxVersion: VersionTLS12, |
| 1955 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1956 | sendWarningAlerts: 4, |
| 1957 | }, |
| 1958 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 1959 | protocol: dtls, |
| 1960 | name: "SendWarningAlerts-DTLS-Pass", |
| 1961 | config: Config{ |
| 1962 | MaxVersion: VersionTLS12, |
| 1963 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1964 | sendWarningAlerts: 4, |
| 1965 | }, |
| 1966 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 1967 | name: "SendWarningAlerts-TLS13", |
| 1968 | config: Config{ |
| 1969 | MaxVersion: VersionTLS13, |
| 1970 | }, |
| 1971 | sendWarningAlerts: 4, |
| 1972 | shouldFail: true, |
| 1973 | expectedError: ":BAD_ALERT:", |
| 1974 | expectedLocalError: "remote error: error decoding message", |
| 1975 | }, |
| 1976 | { |
| 1977 | name: "SendWarningAlerts", |
| 1978 | config: Config{ |
| 1979 | MaxVersion: VersionTLS12, |
| 1980 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1981 | sendWarningAlerts: 5, |
| 1982 | shouldFail: true, |
| 1983 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 1984 | }, |
| 1985 | { |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 1986 | name: "SendWarningAlerts-Async", |
| 1987 | config: Config{ |
| 1988 | MaxVersion: VersionTLS12, |
| 1989 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1990 | sendWarningAlerts: 5, |
| 1991 | flags: []string{"-async"}, |
| 1992 | shouldFail: true, |
| 1993 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 1994 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 1995 | { |
| 1996 | name: "EmptySessionID", |
| 1997 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1998 | MaxVersion: VersionTLS12, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 1999 | SessionTicketsDisabled: true, |
| 2000 | }, |
| 2001 | noSessionCache: true, |
| 2002 | flags: []string{"-expect-no-session"}, |
| 2003 | }, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 2004 | { |
| 2005 | name: "Unclean-Shutdown", |
| 2006 | config: Config{ |
| 2007 | Bugs: ProtocolBugs{ |
| 2008 | NoCloseNotify: true, |
| 2009 | ExpectCloseNotify: true, |
| 2010 | }, |
| 2011 | }, |
| 2012 | shimShutsDown: true, |
| 2013 | flags: []string{"-check-close-notify"}, |
| 2014 | shouldFail: true, |
| 2015 | expectedError: "Unexpected SSL_shutdown result: -1 != 1", |
| 2016 | }, |
| 2017 | { |
| 2018 | name: "Unclean-Shutdown-Ignored", |
| 2019 | config: Config{ |
| 2020 | Bugs: ProtocolBugs{ |
| 2021 | NoCloseNotify: true, |
| 2022 | }, |
| 2023 | }, |
| 2024 | shimShutsDown: true, |
| 2025 | }, |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 2026 | { |
David Benjamin | fa214e4 | 2016-05-10 17:03:10 -0400 | [diff] [blame] | 2027 | name: "Unclean-Shutdown-Alert", |
| 2028 | config: Config{ |
| 2029 | Bugs: ProtocolBugs{ |
| 2030 | SendAlertOnShutdown: alertDecompressionFailure, |
| 2031 | ExpectCloseNotify: true, |
| 2032 | }, |
| 2033 | }, |
| 2034 | shimShutsDown: true, |
| 2035 | flags: []string{"-check-close-notify"}, |
| 2036 | shouldFail: true, |
| 2037 | expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:", |
| 2038 | }, |
| 2039 | { |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 2040 | name: "LargePlaintext", |
| 2041 | config: Config{ |
| 2042 | Bugs: ProtocolBugs{ |
| 2043 | SendLargeRecords: true, |
| 2044 | }, |
| 2045 | }, |
| 2046 | messageLen: maxPlaintext + 1, |
| 2047 | shouldFail: true, |
| 2048 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2049 | }, |
| 2050 | { |
| 2051 | protocol: dtls, |
| 2052 | name: "LargePlaintext-DTLS", |
| 2053 | config: Config{ |
| 2054 | Bugs: ProtocolBugs{ |
| 2055 | SendLargeRecords: true, |
| 2056 | }, |
| 2057 | }, |
| 2058 | messageLen: maxPlaintext + 1, |
| 2059 | shouldFail: true, |
| 2060 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2061 | }, |
| 2062 | { |
| 2063 | name: "LargeCiphertext", |
| 2064 | config: Config{ |
| 2065 | Bugs: ProtocolBugs{ |
| 2066 | SendLargeRecords: true, |
| 2067 | }, |
| 2068 | }, |
| 2069 | messageLen: maxPlaintext * 2, |
| 2070 | shouldFail: true, |
| 2071 | expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:", |
| 2072 | }, |
| 2073 | { |
| 2074 | protocol: dtls, |
| 2075 | name: "LargeCiphertext-DTLS", |
| 2076 | config: Config{ |
| 2077 | Bugs: ProtocolBugs{ |
| 2078 | SendLargeRecords: true, |
| 2079 | }, |
| 2080 | }, |
| 2081 | messageLen: maxPlaintext * 2, |
| 2082 | // Unlike the other four cases, DTLS drops records which |
| 2083 | // are invalid before authentication, so the connection |
| 2084 | // does not fail. |
| 2085 | expectMessageDropped: true, |
| 2086 | }, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2087 | { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2088 | // In TLS 1.2 and below, empty NewSessionTicket messages |
| 2089 | // mean the server changed its mind on sending a ticket. |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2090 | name: "SendEmptySessionTicket", |
| 2091 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2092 | MaxVersion: VersionTLS12, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2093 | Bugs: ProtocolBugs{ |
| 2094 | SendEmptySessionTicket: true, |
| 2095 | FailIfSessionOffered: true, |
| 2096 | }, |
| 2097 | }, |
| 2098 | flags: []string{"-expect-no-session"}, |
| 2099 | resumeSession: true, |
| 2100 | expectResumeRejected: true, |
| 2101 | }, |
David Benjamin | 99fdfb9 | 2015-11-02 12:11:35 -0500 | [diff] [blame] | 2102 | { |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2103 | name: "BadHelloRequest-1", |
| 2104 | renegotiate: 1, |
| 2105 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2106 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2107 | Bugs: ProtocolBugs{ |
| 2108 | BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1}, |
| 2109 | }, |
| 2110 | }, |
| 2111 | flags: []string{ |
| 2112 | "-renegotiate-freely", |
| 2113 | "-expect-total-renegotiations", "1", |
| 2114 | }, |
| 2115 | shouldFail: true, |
David Benjamin | 163f29a | 2016-07-28 11:05:58 -0400 | [diff] [blame] | 2116 | expectedError: ":EXCESSIVE_MESSAGE_SIZE:", |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2117 | }, |
| 2118 | { |
| 2119 | name: "BadHelloRequest-2", |
| 2120 | renegotiate: 1, |
| 2121 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2122 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2123 | Bugs: ProtocolBugs{ |
| 2124 | BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0}, |
| 2125 | }, |
| 2126 | }, |
| 2127 | flags: []string{ |
| 2128 | "-renegotiate-freely", |
| 2129 | "-expect-total-renegotiations", "1", |
| 2130 | }, |
| 2131 | shouldFail: true, |
| 2132 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2133 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2134 | { |
| 2135 | testType: serverTest, |
| 2136 | name: "SupportTicketsWithSessionID", |
| 2137 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2138 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2139 | SessionTicketsDisabled: true, |
| 2140 | }, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2141 | resumeConfig: &Config{ |
| 2142 | MaxVersion: VersionTLS12, |
| 2143 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2144 | resumeSession: true, |
| 2145 | }, |
David Benjamin | 02edcd0 | 2016-07-27 17:40:37 -0400 | [diff] [blame] | 2146 | { |
| 2147 | protocol: dtls, |
| 2148 | name: "DTLS-SendExtraFinished", |
| 2149 | config: Config{ |
| 2150 | Bugs: ProtocolBugs{ |
| 2151 | SendExtraFinished: true, |
| 2152 | }, |
| 2153 | }, |
| 2154 | shouldFail: true, |
| 2155 | expectedError: ":UNEXPECTED_RECORD:", |
| 2156 | }, |
| 2157 | { |
| 2158 | protocol: dtls, |
| 2159 | name: "DTLS-SendExtraFinished-Reordered", |
| 2160 | config: Config{ |
| 2161 | Bugs: ProtocolBugs{ |
| 2162 | MaxHandshakeRecordLength: 2, |
| 2163 | ReorderHandshakeFragments: true, |
| 2164 | SendExtraFinished: true, |
| 2165 | }, |
| 2166 | }, |
| 2167 | shouldFail: true, |
| 2168 | expectedError: ":UNEXPECTED_RECORD:", |
| 2169 | }, |
David Benjamin | e97fb48 | 2016-07-29 09:23:07 -0400 | [diff] [blame] | 2170 | { |
| 2171 | testType: serverTest, |
| 2172 | name: "V2ClientHello-EmptyRecordPrefix", |
| 2173 | config: Config{ |
| 2174 | // Choose a cipher suite that does not involve |
| 2175 | // elliptic curves, so no extensions are |
| 2176 | // involved. |
| 2177 | MaxVersion: VersionTLS12, |
| 2178 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2179 | Bugs: ProtocolBugs{ |
| 2180 | SendV2ClientHello: true, |
| 2181 | }, |
| 2182 | }, |
| 2183 | sendPrefix: string([]byte{ |
| 2184 | byte(recordTypeHandshake), |
| 2185 | 3, 1, // version |
| 2186 | 0, 0, // length |
| 2187 | }), |
| 2188 | // A no-op empty record may not be sent before V2ClientHello. |
| 2189 | shouldFail: true, |
| 2190 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 2191 | }, |
| 2192 | { |
| 2193 | testType: serverTest, |
| 2194 | name: "V2ClientHello-WarningAlertPrefix", |
| 2195 | config: Config{ |
| 2196 | // Choose a cipher suite that does not involve |
| 2197 | // elliptic curves, so no extensions are |
| 2198 | // involved. |
| 2199 | MaxVersion: VersionTLS12, |
| 2200 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2201 | Bugs: ProtocolBugs{ |
| 2202 | SendV2ClientHello: true, |
| 2203 | }, |
| 2204 | }, |
| 2205 | sendPrefix: string([]byte{ |
| 2206 | byte(recordTypeAlert), |
| 2207 | 3, 1, // version |
| 2208 | 0, 2, // length |
| 2209 | alertLevelWarning, byte(alertDecompressionFailure), |
| 2210 | }), |
| 2211 | // A no-op warning alert may not be sent before V2ClientHello. |
| 2212 | shouldFail: true, |
| 2213 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 2214 | }, |
Steven Valdez | 1dc53d2 | 2016-07-26 12:27:38 -0400 | [diff] [blame] | 2215 | { |
| 2216 | testType: clientTest, |
| 2217 | name: "KeyUpdate", |
| 2218 | config: Config{ |
| 2219 | MaxVersion: VersionTLS13, |
| 2220 | Bugs: ProtocolBugs{ |
| 2221 | SendKeyUpdateBeforeEveryAppDataRecord: true, |
| 2222 | }, |
| 2223 | }, |
| 2224 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2225 | } |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2226 | testCases = append(testCases, basicTests...) |
| 2227 | } |
| 2228 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2229 | func addCipherSuiteTests() { |
David Benjamin | e470e66 | 2016-07-18 15:47:32 +0200 | [diff] [blame] | 2230 | const bogusCipher = 0xfe00 |
| 2231 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2232 | for _, suite := range testCipherSuites { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2233 | const psk = "12345" |
| 2234 | const pskIdentity = "luggage combo" |
| 2235 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2236 | var cert Certificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2237 | var certFile string |
| 2238 | var keyFile string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2239 | if hasComponent(suite.name, "ECDSA") { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2240 | cert = ecdsaP256Certificate |
| 2241 | certFile = ecdsaP256CertificateFile |
| 2242 | keyFile = ecdsaP256KeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2243 | } else { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2244 | cert = rsaCertificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2245 | certFile = rsaCertificateFile |
| 2246 | keyFile = rsaKeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2249 | var flags []string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2250 | if hasComponent(suite.name, "PSK") { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2251 | flags = append(flags, |
| 2252 | "-psk", psk, |
| 2253 | "-psk-identity", pskIdentity) |
| 2254 | } |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 2255 | if hasComponent(suite.name, "NULL") { |
| 2256 | // NULL ciphers must be explicitly enabled. |
| 2257 | flags = append(flags, "-cipher", "DEFAULT:NULL-SHA") |
| 2258 | } |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 2259 | if hasComponent(suite.name, "CECPQ1") { |
| 2260 | // CECPQ1 ciphers must be explicitly enabled. |
| 2261 | flags = append(flags, "-cipher", "DEFAULT:kCECPQ1") |
| 2262 | } |
David Benjamin | 881f196 | 2016-08-10 18:29:12 -0400 | [diff] [blame] | 2263 | if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") { |
| 2264 | // ECDHE_PSK AES_GCM ciphers must be explicitly enabled |
| 2265 | // for now. |
| 2266 | flags = append(flags, "-cipher", suite.name) |
| 2267 | } |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2268 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2269 | for _, ver := range tlsVersions { |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2270 | for _, protocol := range []protocol{tls, dtls} { |
| 2271 | var prefix string |
| 2272 | if protocol == dtls { |
| 2273 | if !ver.hasDTLS { |
| 2274 | continue |
| 2275 | } |
| 2276 | prefix = "D" |
| 2277 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2278 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2279 | var shouldServerFail, shouldClientFail bool |
| 2280 | if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 { |
| 2281 | // BoringSSL clients accept ECDHE on SSLv3, but |
| 2282 | // a BoringSSL server will never select it |
| 2283 | // because the extension is missing. |
| 2284 | shouldServerFail = true |
| 2285 | } |
| 2286 | if isTLS12Only(suite.name) && ver.version < VersionTLS12 { |
| 2287 | shouldClientFail = true |
| 2288 | shouldServerFail = true |
| 2289 | } |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 2290 | if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2291 | shouldClientFail = true |
| 2292 | shouldServerFail = true |
| 2293 | } |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2294 | if !isDTLSCipher(suite.name) && protocol == dtls { |
| 2295 | shouldClientFail = true |
| 2296 | shouldServerFail = true |
| 2297 | } |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 2298 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2299 | var expectedServerError, expectedClientError string |
| 2300 | if shouldServerFail { |
| 2301 | expectedServerError = ":NO_SHARED_CIPHER:" |
| 2302 | } |
| 2303 | if shouldClientFail { |
| 2304 | expectedClientError = ":WRONG_CIPHER_RETURNED:" |
| 2305 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2306 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2307 | testCases = append(testCases, testCase{ |
| 2308 | testType: serverTest, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2309 | protocol: protocol, |
| 2310 | |
| 2311 | name: prefix + ver.name + "-" + suite.name + "-server", |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2312 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2313 | MinVersion: ver.version, |
| 2314 | MaxVersion: ver.version, |
| 2315 | CipherSuites: []uint16{suite.id}, |
| 2316 | Certificates: []Certificate{cert}, |
| 2317 | PreSharedKey: []byte(psk), |
| 2318 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2319 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2320 | EnableAllCiphers: shouldServerFail, |
| 2321 | IgnorePeerCipherPreferences: shouldServerFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2322 | }, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2323 | }, |
| 2324 | certFile: certFile, |
| 2325 | keyFile: keyFile, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2326 | flags: flags, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 2327 | resumeSession: true, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2328 | shouldFail: shouldServerFail, |
| 2329 | expectedError: expectedServerError, |
| 2330 | }) |
| 2331 | |
| 2332 | testCases = append(testCases, testCase{ |
| 2333 | testType: clientTest, |
| 2334 | protocol: protocol, |
| 2335 | name: prefix + ver.name + "-" + suite.name + "-client", |
| 2336 | config: Config{ |
| 2337 | MinVersion: ver.version, |
| 2338 | MaxVersion: ver.version, |
| 2339 | CipherSuites: []uint16{suite.id}, |
| 2340 | Certificates: []Certificate{cert}, |
| 2341 | PreSharedKey: []byte(psk), |
| 2342 | PreSharedKeyIdentity: pskIdentity, |
| 2343 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2344 | EnableAllCiphers: shouldClientFail, |
| 2345 | IgnorePeerCipherPreferences: shouldClientFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2346 | }, |
| 2347 | }, |
| 2348 | flags: flags, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 2349 | resumeSession: true, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2350 | shouldFail: shouldClientFail, |
| 2351 | expectedError: expectedClientError, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2352 | }) |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2353 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2354 | if !shouldClientFail { |
| 2355 | // Ensure the maximum record size is accepted. |
| 2356 | testCases = append(testCases, testCase{ |
| 2357 | name: prefix + ver.name + "-" + suite.name + "-LargeRecord", |
| 2358 | config: Config{ |
| 2359 | MinVersion: ver.version, |
| 2360 | MaxVersion: ver.version, |
| 2361 | CipherSuites: []uint16{suite.id}, |
| 2362 | Certificates: []Certificate{cert}, |
| 2363 | PreSharedKey: []byte(psk), |
| 2364 | PreSharedKeyIdentity: pskIdentity, |
| 2365 | }, |
| 2366 | flags: flags, |
| 2367 | messageLen: maxPlaintext, |
| 2368 | }) |
| 2369 | } |
| 2370 | } |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2371 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2372 | } |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2373 | |
| 2374 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2375 | name: "NoSharedCipher", |
| 2376 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2377 | MaxVersion: VersionTLS12, |
| 2378 | CipherSuites: []uint16{}, |
| 2379 | }, |
| 2380 | shouldFail: true, |
| 2381 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2382 | }) |
| 2383 | |
| 2384 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2385 | name: "NoSharedCipher-TLS13", |
| 2386 | config: Config{ |
| 2387 | MaxVersion: VersionTLS13, |
| 2388 | CipherSuites: []uint16{}, |
| 2389 | }, |
| 2390 | shouldFail: true, |
| 2391 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2392 | }) |
| 2393 | |
| 2394 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2395 | name: "UnsupportedCipherSuite", |
| 2396 | config: Config{ |
| 2397 | MaxVersion: VersionTLS12, |
| 2398 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2399 | Bugs: ProtocolBugs{ |
| 2400 | IgnorePeerCipherPreferences: true, |
| 2401 | }, |
| 2402 | }, |
| 2403 | flags: []string{"-cipher", "DEFAULT:!RC4"}, |
| 2404 | shouldFail: true, |
| 2405 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 2406 | }) |
| 2407 | |
| 2408 | testCases = append(testCases, testCase{ |
David Benjamin | e470e66 | 2016-07-18 15:47:32 +0200 | [diff] [blame] | 2409 | name: "ServerHelloBogusCipher", |
| 2410 | config: Config{ |
| 2411 | MaxVersion: VersionTLS12, |
| 2412 | Bugs: ProtocolBugs{ |
| 2413 | SendCipherSuite: bogusCipher, |
| 2414 | }, |
| 2415 | }, |
| 2416 | shouldFail: true, |
| 2417 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2418 | }) |
| 2419 | testCases = append(testCases, testCase{ |
| 2420 | name: "ServerHelloBogusCipher-TLS13", |
| 2421 | config: Config{ |
| 2422 | MaxVersion: VersionTLS13, |
| 2423 | Bugs: ProtocolBugs{ |
| 2424 | SendCipherSuite: bogusCipher, |
| 2425 | }, |
| 2426 | }, |
| 2427 | shouldFail: true, |
| 2428 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2429 | }) |
| 2430 | |
| 2431 | testCases = append(testCases, testCase{ |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2432 | name: "WeakDH", |
| 2433 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2434 | MaxVersion: VersionTLS12, |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2435 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2436 | Bugs: ProtocolBugs{ |
| 2437 | // This is a 1023-bit prime number, generated |
| 2438 | // with: |
| 2439 | // openssl gendh 1023 | openssl asn1parse -i |
| 2440 | DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"), |
| 2441 | }, |
| 2442 | }, |
| 2443 | shouldFail: true, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2444 | expectedError: ":BAD_DH_P_LENGTH:", |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2445 | }) |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2446 | |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2447 | testCases = append(testCases, testCase{ |
| 2448 | name: "SillyDH", |
| 2449 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2450 | MaxVersion: VersionTLS12, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2451 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2452 | Bugs: ProtocolBugs{ |
| 2453 | // This is a 4097-bit prime number, generated |
| 2454 | // with: |
| 2455 | // openssl gendh 4097 | openssl asn1parse -i |
| 2456 | DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"), |
| 2457 | }, |
| 2458 | }, |
| 2459 | shouldFail: true, |
| 2460 | expectedError: ":DH_P_TOO_LONG:", |
| 2461 | }) |
| 2462 | |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2463 | // This test ensures that Diffie-Hellman public values are padded with |
| 2464 | // zeros so that they're the same length as the prime. This is to avoid |
| 2465 | // hitting a bug in yaSSL. |
| 2466 | testCases = append(testCases, testCase{ |
| 2467 | testType: serverTest, |
| 2468 | name: "DHPublicValuePadded", |
| 2469 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2470 | MaxVersion: VersionTLS12, |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2471 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2472 | Bugs: ProtocolBugs{ |
| 2473 | RequireDHPublicValueLen: (1025 + 7) / 8, |
| 2474 | }, |
| 2475 | }, |
| 2476 | flags: []string{"-use-sparse-dh-prime"}, |
| 2477 | }) |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2478 | |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2479 | // The server must be tolerant to bogus ciphers. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2480 | testCases = append(testCases, testCase{ |
| 2481 | testType: serverTest, |
| 2482 | name: "UnknownCipher", |
| 2483 | config: Config{ |
| 2484 | CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2485 | }, |
| 2486 | }) |
| 2487 | |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2488 | // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS |
| 2489 | // 1.1 specific cipher suite settings. A server is setup with the given |
| 2490 | // cipher lists and then a connection is made for each member of |
| 2491 | // expectations. The cipher suite that the server selects must match |
| 2492 | // the specified one. |
| 2493 | var versionSpecificCiphersTest = []struct { |
| 2494 | ciphersDefault, ciphersTLS10, ciphersTLS11 string |
| 2495 | // expectations is a map from TLS version to cipher suite id. |
| 2496 | expectations map[uint16]uint16 |
| 2497 | }{ |
| 2498 | { |
| 2499 | // Test that the null case (where no version-specific ciphers are set) |
| 2500 | // works as expected. |
| 2501 | "RC4-SHA:AES128-SHA", // default ciphers |
| 2502 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2503 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2504 | map[uint16]uint16{ |
| 2505 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2506 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2507 | VersionTLS11: TLS_RSA_WITH_RC4_128_SHA, |
| 2508 | VersionTLS12: TLS_RSA_WITH_RC4_128_SHA, |
| 2509 | }, |
| 2510 | }, |
| 2511 | { |
| 2512 | // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different |
| 2513 | // cipher. |
| 2514 | "RC4-SHA:AES128-SHA", // default |
| 2515 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2516 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2517 | map[uint16]uint16{ |
| 2518 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2519 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2520 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2521 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2522 | }, |
| 2523 | }, |
| 2524 | { |
| 2525 | // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different |
| 2526 | // cipher. |
| 2527 | "RC4-SHA:AES128-SHA", // default |
| 2528 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2529 | "AES128-SHA", // these ciphers for TLS ≥ 1.1 |
| 2530 | map[uint16]uint16{ |
| 2531 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2532 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2533 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2534 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2535 | }, |
| 2536 | }, |
| 2537 | { |
| 2538 | // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should |
| 2539 | // mask ciphers_tls10 for TLS 1.1 and 1.2. |
| 2540 | "RC4-SHA:AES128-SHA", // default |
| 2541 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2542 | "AES256-SHA", // these ciphers for TLS ≥ 1.1 |
| 2543 | map[uint16]uint16{ |
| 2544 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2545 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2546 | VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2547 | VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2548 | }, |
| 2549 | }, |
| 2550 | } |
| 2551 | |
| 2552 | for i, test := range versionSpecificCiphersTest { |
| 2553 | for version, expectedCipherSuite := range test.expectations { |
| 2554 | flags := []string{"-cipher", test.ciphersDefault} |
| 2555 | if len(test.ciphersTLS10) > 0 { |
| 2556 | flags = append(flags, "-cipher-tls10", test.ciphersTLS10) |
| 2557 | } |
| 2558 | if len(test.ciphersTLS11) > 0 { |
| 2559 | flags = append(flags, "-cipher-tls11", test.ciphersTLS11) |
| 2560 | } |
| 2561 | |
| 2562 | testCases = append(testCases, testCase{ |
| 2563 | testType: serverTest, |
| 2564 | name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version), |
| 2565 | config: Config{ |
| 2566 | MaxVersion: version, |
| 2567 | MinVersion: version, |
| 2568 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA}, |
| 2569 | }, |
| 2570 | flags: flags, |
| 2571 | expectedCipher: expectedCipherSuite, |
| 2572 | }) |
| 2573 | } |
| 2574 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | func addBadECDSASignatureTests() { |
| 2578 | for badR := BadValue(1); badR < NumBadValues; badR++ { |
| 2579 | for badS := BadValue(1); badS < NumBadValues; badS++ { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2580 | testCases = append(testCases, testCase{ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2581 | name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS), |
| 2582 | config: Config{ |
| 2583 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2584 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2585 | Bugs: ProtocolBugs{ |
| 2586 | BadECDSAR: badR, |
| 2587 | BadECDSAS: badS, |
| 2588 | }, |
| 2589 | }, |
| 2590 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2591 | expectedError: ":BAD_SIGNATURE:", |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2592 | }) |
| 2593 | } |
| 2594 | } |
| 2595 | } |
| 2596 | |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2597 | func addCBCPaddingTests() { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2598 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2599 | name: "MaxCBCPadding", |
| 2600 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2601 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2602 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2603 | Bugs: ProtocolBugs{ |
| 2604 | MaxPadding: true, |
| 2605 | }, |
| 2606 | }, |
| 2607 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2608 | }) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2609 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2610 | name: "BadCBCPadding", |
| 2611 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2612 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2613 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2614 | Bugs: ProtocolBugs{ |
| 2615 | PaddingFirstByteBad: true, |
| 2616 | }, |
| 2617 | }, |
| 2618 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2619 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2620 | }) |
| 2621 | // OpenSSL previously had an issue where the first byte of padding in |
| 2622 | // 255 bytes of padding wasn't checked. |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2623 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2624 | name: "BadCBCPadding255", |
| 2625 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2626 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2627 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2628 | Bugs: ProtocolBugs{ |
| 2629 | MaxPadding: true, |
| 2630 | PaddingFirstByteBadIf255: true, |
| 2631 | }, |
| 2632 | }, |
| 2633 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2634 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2635 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2636 | }) |
| 2637 | } |
| 2638 | |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2639 | func addCBCSplittingTests() { |
| 2640 | testCases = append(testCases, testCase{ |
| 2641 | name: "CBCRecordSplitting", |
| 2642 | config: Config{ |
| 2643 | MaxVersion: VersionTLS10, |
| 2644 | MinVersion: VersionTLS10, |
| 2645 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2646 | }, |
David Benjamin | ac8302a | 2015-09-01 17:18:15 -0400 | [diff] [blame] | 2647 | messageLen: -1, // read until EOF |
| 2648 | resumeSession: true, |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2649 | flags: []string{ |
| 2650 | "-async", |
| 2651 | "-write-different-record-sizes", |
| 2652 | "-cbc-record-splitting", |
| 2653 | }, |
David Benjamin | a8e3e0e | 2014-08-06 22:11:10 -0400 | [diff] [blame] | 2654 | }) |
| 2655 | testCases = append(testCases, testCase{ |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2656 | name: "CBCRecordSplittingPartialWrite", |
| 2657 | config: Config{ |
| 2658 | MaxVersion: VersionTLS10, |
| 2659 | MinVersion: VersionTLS10, |
| 2660 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2661 | }, |
| 2662 | messageLen: -1, // read until EOF |
| 2663 | flags: []string{ |
| 2664 | "-async", |
| 2665 | "-write-different-record-sizes", |
| 2666 | "-cbc-record-splitting", |
| 2667 | "-partial-write", |
| 2668 | }, |
| 2669 | }) |
| 2670 | } |
| 2671 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2672 | func addClientAuthTests() { |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 2673 | // Add a dummy cert pool to stress certificate authority parsing. |
| 2674 | // TODO(davidben): Add tests that those values parse out correctly. |
| 2675 | certPool := x509.NewCertPool() |
| 2676 | cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0]) |
| 2677 | if err != nil { |
| 2678 | panic(err) |
| 2679 | } |
| 2680 | certPool.AddCert(cert) |
| 2681 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2682 | for _, ver := range tlsVersions { |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2683 | testCases = append(testCases, testCase{ |
| 2684 | testType: clientTest, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2685 | name: ver.name + "-Client-ClientAuth-RSA", |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2686 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2687 | MinVersion: ver.version, |
| 2688 | MaxVersion: ver.version, |
| 2689 | ClientAuth: RequireAnyClientCert, |
| 2690 | ClientCAs: certPool, |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2691 | }, |
| 2692 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2693 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2694 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2695 | }, |
| 2696 | }) |
| 2697 | testCases = append(testCases, testCase{ |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2698 | testType: serverTest, |
| 2699 | name: ver.name + "-Server-ClientAuth-RSA", |
| 2700 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2701 | MinVersion: ver.version, |
| 2702 | MaxVersion: ver.version, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2703 | Certificates: []Certificate{rsaCertificate}, |
| 2704 | }, |
| 2705 | flags: []string{"-require-any-client-certificate"}, |
| 2706 | }) |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2707 | if ver.version != VersionSSL30 { |
| 2708 | testCases = append(testCases, testCase{ |
| 2709 | testType: serverTest, |
| 2710 | name: ver.name + "-Server-ClientAuth-ECDSA", |
| 2711 | config: Config{ |
| 2712 | MinVersion: ver.version, |
| 2713 | MaxVersion: ver.version, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2714 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2715 | }, |
| 2716 | flags: []string{"-require-any-client-certificate"}, |
| 2717 | }) |
| 2718 | testCases = append(testCases, testCase{ |
| 2719 | testType: clientTest, |
| 2720 | name: ver.name + "-Client-ClientAuth-ECDSA", |
| 2721 | config: Config{ |
| 2722 | MinVersion: ver.version, |
| 2723 | MaxVersion: ver.version, |
| 2724 | ClientAuth: RequireAnyClientCert, |
| 2725 | ClientCAs: certPool, |
| 2726 | }, |
| 2727 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2728 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 2729 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2730 | }, |
| 2731 | }) |
| 2732 | } |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2733 | } |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2734 | |
| 2735 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2736 | name: "NoClientCertificate", |
| 2737 | config: Config{ |
| 2738 | MaxVersion: VersionTLS12, |
| 2739 | ClientAuth: RequireAnyClientCert, |
| 2740 | }, |
| 2741 | shouldFail: true, |
| 2742 | expectedLocalError: "client didn't provide a certificate", |
| 2743 | }) |
| 2744 | |
| 2745 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2746 | name: "NoClientCertificate-TLS13", |
| 2747 | config: Config{ |
| 2748 | MaxVersion: VersionTLS13, |
| 2749 | ClientAuth: RequireAnyClientCert, |
| 2750 | }, |
| 2751 | shouldFail: true, |
| 2752 | expectedLocalError: "client didn't provide a certificate", |
| 2753 | }) |
| 2754 | |
| 2755 | testCases = append(testCases, testCase{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2756 | testType: serverTest, |
| 2757 | name: "RequireAnyClientCertificate", |
| 2758 | config: Config{ |
| 2759 | MaxVersion: VersionTLS12, |
| 2760 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2761 | flags: []string{"-require-any-client-certificate"}, |
| 2762 | shouldFail: true, |
| 2763 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2764 | }) |
| 2765 | |
| 2766 | testCases = append(testCases, testCase{ |
| 2767 | testType: serverTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2768 | name: "RequireAnyClientCertificate-TLS13", |
| 2769 | config: Config{ |
| 2770 | MaxVersion: VersionTLS13, |
| 2771 | }, |
| 2772 | flags: []string{"-require-any-client-certificate"}, |
| 2773 | shouldFail: true, |
| 2774 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2775 | }) |
| 2776 | |
| 2777 | testCases = append(testCases, testCase{ |
| 2778 | testType: serverTest, |
David Benjamin | df28c3a | 2016-03-10 16:11:51 -0500 | [diff] [blame] | 2779 | name: "RequireAnyClientCertificate-SSL3", |
| 2780 | config: Config{ |
| 2781 | MaxVersion: VersionSSL30, |
| 2782 | }, |
| 2783 | flags: []string{"-require-any-client-certificate"}, |
| 2784 | shouldFail: true, |
| 2785 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2786 | }) |
| 2787 | |
| 2788 | testCases = append(testCases, testCase{ |
| 2789 | testType: serverTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2790 | name: "SkipClientCertificate", |
| 2791 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2792 | MaxVersion: VersionTLS12, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2793 | Bugs: ProtocolBugs{ |
| 2794 | SkipClientCertificate: true, |
| 2795 | }, |
| 2796 | }, |
| 2797 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2798 | flags: []string{"-verify-peer"}, |
| 2799 | shouldFail: true, |
David Benjamin | df28c3a | 2016-03-10 16:11:51 -0500 | [diff] [blame] | 2800 | expectedError: ":UNEXPECTED_MESSAGE:", |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2801 | }) |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2802 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2803 | testCases = append(testCases, testCase{ |
| 2804 | testType: serverTest, |
| 2805 | name: "SkipClientCertificate-TLS13", |
| 2806 | config: Config{ |
| 2807 | MaxVersion: VersionTLS13, |
| 2808 | Bugs: ProtocolBugs{ |
| 2809 | SkipClientCertificate: true, |
| 2810 | }, |
| 2811 | }, |
| 2812 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2813 | flags: []string{"-verify-peer"}, |
| 2814 | shouldFail: true, |
| 2815 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2816 | }) |
| 2817 | |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2818 | // Client auth is only legal in certificate-based ciphers. |
| 2819 | testCases = append(testCases, testCase{ |
| 2820 | testType: clientTest, |
| 2821 | name: "ClientAuth-PSK", |
| 2822 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2823 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2824 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 2825 | PreSharedKey: []byte("secret"), |
| 2826 | ClientAuth: RequireAnyClientCert, |
| 2827 | }, |
| 2828 | flags: []string{ |
| 2829 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2830 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2831 | "-psk", "secret", |
| 2832 | }, |
| 2833 | shouldFail: true, |
| 2834 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2835 | }) |
| 2836 | testCases = append(testCases, testCase{ |
| 2837 | testType: clientTest, |
| 2838 | name: "ClientAuth-ECDHE_PSK", |
| 2839 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2840 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2841 | CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 2842 | PreSharedKey: []byte("secret"), |
| 2843 | ClientAuth: RequireAnyClientCert, |
| 2844 | }, |
| 2845 | flags: []string{ |
| 2846 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2847 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2848 | "-psk", "secret", |
| 2849 | }, |
| 2850 | shouldFail: true, |
| 2851 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2852 | }) |
David Benjamin | 2f8935d | 2016-07-13 19:47:39 -0400 | [diff] [blame] | 2853 | |
| 2854 | // Regression test for a bug where the client CA list, if explicitly |
| 2855 | // set to NULL, was mis-encoded. |
| 2856 | testCases = append(testCases, testCase{ |
| 2857 | testType: serverTest, |
| 2858 | name: "Null-Client-CA-List", |
| 2859 | config: Config{ |
| 2860 | MaxVersion: VersionTLS12, |
| 2861 | Certificates: []Certificate{rsaCertificate}, |
| 2862 | }, |
| 2863 | flags: []string{ |
| 2864 | "-require-any-client-certificate", |
| 2865 | "-use-null-client-ca-list", |
| 2866 | }, |
| 2867 | }) |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2868 | } |
| 2869 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2870 | func addExtendedMasterSecretTests() { |
| 2871 | const expectEMSFlag = "-expect-extended-master-secret" |
| 2872 | |
| 2873 | for _, with := range []bool{false, true} { |
| 2874 | prefix := "No" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2875 | if with { |
| 2876 | prefix = "" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | for _, isClient := range []bool{false, true} { |
| 2880 | suffix := "-Server" |
| 2881 | testType := serverTest |
| 2882 | if isClient { |
| 2883 | suffix = "-Client" |
| 2884 | testType = clientTest |
| 2885 | } |
| 2886 | |
| 2887 | for _, ver := range tlsVersions { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2888 | // In TLS 1.3, the extension is irrelevant and |
| 2889 | // always reports as enabled. |
| 2890 | var flags []string |
| 2891 | if with || ver.version >= VersionTLS13 { |
| 2892 | flags = []string{expectEMSFlag} |
| 2893 | } |
| 2894 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2895 | test := testCase{ |
| 2896 | testType: testType, |
| 2897 | name: prefix + "ExtendedMasterSecret-" + ver.name + suffix, |
| 2898 | config: Config{ |
| 2899 | MinVersion: ver.version, |
| 2900 | MaxVersion: ver.version, |
| 2901 | Bugs: ProtocolBugs{ |
| 2902 | NoExtendedMasterSecret: !with, |
| 2903 | RequireExtendedMasterSecret: with, |
| 2904 | }, |
| 2905 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2906 | flags: flags, |
| 2907 | shouldFail: ver.version == VersionSSL30 && with, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2908 | } |
| 2909 | if test.shouldFail { |
| 2910 | test.expectedLocalError = "extended master secret required but not supported by peer" |
| 2911 | } |
| 2912 | testCases = append(testCases, test) |
| 2913 | } |
| 2914 | } |
| 2915 | } |
| 2916 | |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2917 | for _, isClient := range []bool{false, true} { |
| 2918 | for _, supportedInFirstConnection := range []bool{false, true} { |
| 2919 | for _, supportedInResumeConnection := range []bool{false, true} { |
| 2920 | boolToWord := func(b bool) string { |
| 2921 | if b { |
| 2922 | return "Yes" |
| 2923 | } |
| 2924 | return "No" |
| 2925 | } |
| 2926 | suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-" |
| 2927 | if isClient { |
| 2928 | suffix += "Client" |
| 2929 | } else { |
| 2930 | suffix += "Server" |
| 2931 | } |
| 2932 | |
| 2933 | supportedConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2934 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2935 | Bugs: ProtocolBugs{ |
| 2936 | RequireExtendedMasterSecret: true, |
| 2937 | }, |
| 2938 | } |
| 2939 | |
| 2940 | noSupportConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2941 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2942 | Bugs: ProtocolBugs{ |
| 2943 | NoExtendedMasterSecret: true, |
| 2944 | }, |
| 2945 | } |
| 2946 | |
| 2947 | test := testCase{ |
| 2948 | name: "ExtendedMasterSecret-" + suffix, |
| 2949 | resumeSession: true, |
| 2950 | } |
| 2951 | |
| 2952 | if !isClient { |
| 2953 | test.testType = serverTest |
| 2954 | } |
| 2955 | |
| 2956 | if supportedInFirstConnection { |
| 2957 | test.config = supportedConfig |
| 2958 | } else { |
| 2959 | test.config = noSupportConfig |
| 2960 | } |
| 2961 | |
| 2962 | if supportedInResumeConnection { |
| 2963 | test.resumeConfig = &supportedConfig |
| 2964 | } else { |
| 2965 | test.resumeConfig = &noSupportConfig |
| 2966 | } |
| 2967 | |
| 2968 | switch suffix { |
| 2969 | case "YesToYes-Client", "YesToYes-Server": |
| 2970 | // When a session is resumed, it should |
| 2971 | // still be aware that its master |
| 2972 | // secret was generated via EMS and |
| 2973 | // thus it's safe to use tls-unique. |
| 2974 | test.flags = []string{expectEMSFlag} |
| 2975 | case "NoToYes-Server": |
| 2976 | // If an original connection did not |
| 2977 | // contain EMS, but a resumption |
| 2978 | // handshake does, then a server should |
| 2979 | // not resume the session. |
| 2980 | test.expectResumeRejected = true |
| 2981 | case "YesToNo-Server": |
| 2982 | // Resuming an EMS session without the |
| 2983 | // EMS extension should cause the |
| 2984 | // server to abort the connection. |
| 2985 | test.shouldFail = true |
| 2986 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 2987 | case "NoToYes-Client": |
| 2988 | // A client should abort a connection |
| 2989 | // where the server resumed a non-EMS |
| 2990 | // session but echoed the EMS |
| 2991 | // extension. |
| 2992 | test.shouldFail = true |
| 2993 | test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:" |
| 2994 | case "YesToNo-Client": |
| 2995 | // A client should abort a connection |
| 2996 | // where the server didn't echo EMS |
| 2997 | // when the session used it. |
| 2998 | test.shouldFail = true |
| 2999 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 3000 | } |
| 3001 | |
| 3002 | testCases = append(testCases, test) |
| 3003 | } |
| 3004 | } |
| 3005 | } |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3008 | type stateMachineTestConfig struct { |
| 3009 | protocol protocol |
| 3010 | async bool |
| 3011 | splitHandshake, packHandshakeFlight bool |
| 3012 | } |
| 3013 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 3014 | // Adds tests that try to cover the range of the handshake state machine, under |
| 3015 | // various conditions. Some of these are redundant with other tests, but they |
| 3016 | // only cover the synchronous case. |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3017 | func addAllStateMachineCoverageTests() { |
| 3018 | for _, async := range []bool{false, true} { |
| 3019 | for _, protocol := range []protocol{tls, dtls} { |
| 3020 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3021 | protocol: protocol, |
| 3022 | async: async, |
| 3023 | }) |
| 3024 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3025 | protocol: protocol, |
| 3026 | async: async, |
| 3027 | splitHandshake: true, |
| 3028 | }) |
| 3029 | if protocol == tls { |
| 3030 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 3031 | protocol: protocol, |
| 3032 | async: async, |
| 3033 | packHandshakeFlight: true, |
| 3034 | }) |
| 3035 | } |
| 3036 | } |
| 3037 | } |
| 3038 | } |
| 3039 | |
| 3040 | func addStateMachineCoverageTests(config stateMachineTestConfig) { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3041 | var tests []testCase |
| 3042 | |
| 3043 | // Basic handshake, with resumption. Client and server, |
| 3044 | // session ID and session ticket. |
| 3045 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3046 | name: "Basic-Client", |
| 3047 | config: Config{ |
| 3048 | MaxVersion: VersionTLS12, |
| 3049 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3050 | resumeSession: true, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3051 | // Ensure session tickets are used, not session IDs. |
| 3052 | noSessionCache: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3053 | }) |
| 3054 | tests = append(tests, testCase{ |
| 3055 | name: "Basic-Client-RenewTicket", |
| 3056 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3057 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3058 | Bugs: ProtocolBugs{ |
| 3059 | RenewTicketOnResume: true, |
| 3060 | }, |
| 3061 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 3062 | flags: []string{"-expect-ticket-renewal"}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3063 | resumeSession: true, |
| 3064 | }) |
| 3065 | tests = append(tests, testCase{ |
| 3066 | name: "Basic-Client-NoTicket", |
| 3067 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3068 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3069 | SessionTicketsDisabled: true, |
| 3070 | }, |
| 3071 | resumeSession: true, |
| 3072 | }) |
| 3073 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3074 | name: "Basic-Client-Implicit", |
| 3075 | config: Config{ |
| 3076 | MaxVersion: VersionTLS12, |
| 3077 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3078 | flags: []string{"-implicit-handshake"}, |
| 3079 | resumeSession: true, |
| 3080 | }) |
| 3081 | tests = append(tests, testCase{ |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3082 | testType: serverTest, |
| 3083 | name: "Basic-Server", |
| 3084 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3085 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3086 | Bugs: ProtocolBugs{ |
| 3087 | RequireSessionTickets: true, |
| 3088 | }, |
| 3089 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3090 | resumeSession: true, |
| 3091 | }) |
| 3092 | tests = append(tests, testCase{ |
| 3093 | testType: serverTest, |
| 3094 | name: "Basic-Server-NoTickets", |
| 3095 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3096 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3097 | SessionTicketsDisabled: true, |
| 3098 | }, |
| 3099 | resumeSession: true, |
| 3100 | }) |
| 3101 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3102 | testType: serverTest, |
| 3103 | name: "Basic-Server-Implicit", |
| 3104 | config: Config{ |
| 3105 | MaxVersion: VersionTLS12, |
| 3106 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3107 | flags: []string{"-implicit-handshake"}, |
| 3108 | resumeSession: true, |
| 3109 | }) |
| 3110 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3111 | testType: serverTest, |
| 3112 | name: "Basic-Server-EarlyCallback", |
| 3113 | config: Config{ |
| 3114 | MaxVersion: VersionTLS12, |
| 3115 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3116 | flags: []string{"-use-early-callback"}, |
| 3117 | resumeSession: true, |
| 3118 | }) |
| 3119 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3120 | // TLS 1.3 basic handshake shapes. |
David Benjamin | e73c7f4 | 2016-08-17 00:29:33 -0400 | [diff] [blame] | 3121 | if config.protocol == tls { |
| 3122 | tests = append(tests, testCase{ |
| 3123 | name: "TLS13-1RTT-Client", |
| 3124 | config: Config{ |
| 3125 | MaxVersion: VersionTLS13, |
| 3126 | MinVersion: VersionTLS13, |
| 3127 | }, |
David Benjamin | 8a8349b | 2016-08-18 02:32:23 -0400 | [diff] [blame] | 3128 | resumeSession: true, |
David Benjamin | e73c7f4 | 2016-08-17 00:29:33 -0400 | [diff] [blame] | 3129 | }) |
| 3130 | |
| 3131 | tests = append(tests, testCase{ |
| 3132 | testType: serverTest, |
| 3133 | name: "TLS13-1RTT-Server", |
| 3134 | config: Config{ |
| 3135 | MaxVersion: VersionTLS13, |
| 3136 | MinVersion: VersionTLS13, |
| 3137 | }, |
David Benjamin | 8a8349b | 2016-08-18 02:32:23 -0400 | [diff] [blame] | 3138 | resumeSession: true, |
David Benjamin | e73c7f4 | 2016-08-17 00:29:33 -0400 | [diff] [blame] | 3139 | }) |
| 3140 | |
| 3141 | tests = append(tests, testCase{ |
| 3142 | name: "TLS13-HelloRetryRequest-Client", |
| 3143 | config: Config{ |
| 3144 | MaxVersion: VersionTLS13, |
| 3145 | MinVersion: VersionTLS13, |
| 3146 | // P-384 requires a HelloRetryRequest against |
| 3147 | // BoringSSL's default configuration. Assert |
| 3148 | // that we do indeed test this with |
| 3149 | // ExpectMissingKeyShare. |
| 3150 | CurvePreferences: []CurveID{CurveP384}, |
| 3151 | Bugs: ProtocolBugs{ |
| 3152 | ExpectMissingKeyShare: true, |
| 3153 | }, |
| 3154 | }, |
| 3155 | // Cover HelloRetryRequest during an ECDHE-PSK resumption. |
| 3156 | resumeSession: true, |
| 3157 | }) |
| 3158 | |
| 3159 | tests = append(tests, testCase{ |
| 3160 | testType: serverTest, |
| 3161 | name: "TLS13-HelloRetryRequest-Server", |
| 3162 | config: Config{ |
| 3163 | MaxVersion: VersionTLS13, |
| 3164 | MinVersion: VersionTLS13, |
| 3165 | // Require a HelloRetryRequest for every curve. |
| 3166 | DefaultCurves: []CurveID{}, |
| 3167 | }, |
| 3168 | // Cover HelloRetryRequest during an ECDHE-PSK resumption. |
| 3169 | resumeSession: true, |
| 3170 | }) |
| 3171 | } |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3172 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3173 | // TLS client auth. |
| 3174 | tests = append(tests, testCase{ |
| 3175 | testType: clientTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3176 | name: "ClientAuth-NoCertificate-Client", |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3177 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3178 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3179 | ClientAuth: RequestClientCert, |
| 3180 | }, |
| 3181 | }) |
| 3182 | tests = append(tests, testCase{ |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3183 | testType: serverTest, |
| 3184 | name: "ClientAuth-NoCertificate-Server", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3185 | config: Config{ |
| 3186 | MaxVersion: VersionTLS12, |
| 3187 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3188 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3189 | flags: []string{"-verify-peer"}, |
| 3190 | }) |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3191 | if config.protocol == tls { |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3192 | tests = append(tests, testCase{ |
| 3193 | testType: clientTest, |
| 3194 | name: "ClientAuth-NoCertificate-Client-SSL3", |
| 3195 | config: Config{ |
| 3196 | MaxVersion: VersionSSL30, |
| 3197 | ClientAuth: RequestClientCert, |
| 3198 | }, |
| 3199 | }) |
| 3200 | tests = append(tests, testCase{ |
| 3201 | testType: serverTest, |
| 3202 | name: "ClientAuth-NoCertificate-Server-SSL3", |
| 3203 | config: Config{ |
| 3204 | MaxVersion: VersionSSL30, |
| 3205 | }, |
| 3206 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3207 | flags: []string{"-verify-peer"}, |
| 3208 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3209 | tests = append(tests, testCase{ |
| 3210 | testType: clientTest, |
| 3211 | name: "ClientAuth-NoCertificate-Client-TLS13", |
| 3212 | config: Config{ |
| 3213 | MaxVersion: VersionTLS13, |
| 3214 | ClientAuth: RequestClientCert, |
| 3215 | }, |
| 3216 | }) |
| 3217 | tests = append(tests, testCase{ |
| 3218 | testType: serverTest, |
| 3219 | name: "ClientAuth-NoCertificate-Server-TLS13", |
| 3220 | config: Config{ |
| 3221 | MaxVersion: VersionTLS13, |
| 3222 | }, |
| 3223 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3224 | flags: []string{"-verify-peer"}, |
| 3225 | }) |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3226 | } |
| 3227 | tests = append(tests, testCase{ |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3228 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3229 | name: "ClientAuth-RSA-Client", |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3230 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3231 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3232 | ClientAuth: RequireAnyClientCert, |
| 3233 | }, |
| 3234 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3235 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3236 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3237 | }, |
| 3238 | }) |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3239 | tests = append(tests, testCase{ |
| 3240 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3241 | name: "ClientAuth-RSA-Client-TLS13", |
| 3242 | config: Config{ |
| 3243 | MaxVersion: VersionTLS13, |
| 3244 | ClientAuth: RequireAnyClientCert, |
| 3245 | }, |
| 3246 | flags: []string{ |
| 3247 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3248 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3249 | }, |
| 3250 | }) |
| 3251 | tests = append(tests, testCase{ |
| 3252 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3253 | name: "ClientAuth-ECDSA-Client", |
| 3254 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3255 | MaxVersion: VersionTLS12, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3256 | ClientAuth: RequireAnyClientCert, |
| 3257 | }, |
| 3258 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3259 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3260 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3261 | }, |
| 3262 | }) |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3263 | tests = append(tests, testCase{ |
| 3264 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3265 | name: "ClientAuth-ECDSA-Client-TLS13", |
| 3266 | config: Config{ |
| 3267 | MaxVersion: VersionTLS13, |
| 3268 | ClientAuth: RequireAnyClientCert, |
| 3269 | }, |
| 3270 | flags: []string{ |
| 3271 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3272 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 3273 | }, |
| 3274 | }) |
| 3275 | tests = append(tests, testCase{ |
| 3276 | testType: clientTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3277 | name: "ClientAuth-NoCertificate-OldCallback", |
| 3278 | config: Config{ |
| 3279 | MaxVersion: VersionTLS12, |
| 3280 | ClientAuth: RequestClientCert, |
| 3281 | }, |
| 3282 | flags: []string{"-use-old-client-cert-callback"}, |
| 3283 | }) |
| 3284 | tests = append(tests, testCase{ |
| 3285 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3286 | name: "ClientAuth-NoCertificate-OldCallback-TLS13", |
| 3287 | config: Config{ |
| 3288 | MaxVersion: VersionTLS13, |
| 3289 | ClientAuth: RequestClientCert, |
| 3290 | }, |
| 3291 | flags: []string{"-use-old-client-cert-callback"}, |
| 3292 | }) |
| 3293 | tests = append(tests, testCase{ |
| 3294 | testType: clientTest, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3295 | name: "ClientAuth-OldCallback", |
| 3296 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3297 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3298 | ClientAuth: RequireAnyClientCert, |
| 3299 | }, |
| 3300 | flags: []string{ |
| 3301 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3302 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3303 | "-use-old-client-cert-callback", |
| 3304 | }, |
| 3305 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3306 | tests = append(tests, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3307 | testType: clientTest, |
| 3308 | name: "ClientAuth-OldCallback-TLS13", |
| 3309 | config: Config{ |
| 3310 | MaxVersion: VersionTLS13, |
| 3311 | ClientAuth: RequireAnyClientCert, |
| 3312 | }, |
| 3313 | flags: []string{ |
| 3314 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3315 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3316 | "-use-old-client-cert-callback", |
| 3317 | }, |
| 3318 | }) |
| 3319 | tests = append(tests, testCase{ |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3320 | testType: serverTest, |
| 3321 | name: "ClientAuth-Server", |
| 3322 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3323 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3324 | Certificates: []Certificate{rsaCertificate}, |
| 3325 | }, |
| 3326 | flags: []string{"-require-any-client-certificate"}, |
| 3327 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3328 | tests = append(tests, testCase{ |
| 3329 | testType: serverTest, |
| 3330 | name: "ClientAuth-Server-TLS13", |
| 3331 | config: Config{ |
| 3332 | MaxVersion: VersionTLS13, |
| 3333 | Certificates: []Certificate{rsaCertificate}, |
| 3334 | }, |
| 3335 | flags: []string{"-require-any-client-certificate"}, |
| 3336 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3337 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3338 | // Test each key exchange on the server side for async keys. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3339 | tests = append(tests, testCase{ |
| 3340 | testType: serverTest, |
| 3341 | name: "Basic-Server-RSA", |
| 3342 | config: Config{ |
| 3343 | MaxVersion: VersionTLS12, |
| 3344 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 3345 | }, |
| 3346 | flags: []string{ |
| 3347 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3348 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3349 | }, |
| 3350 | }) |
| 3351 | tests = append(tests, testCase{ |
| 3352 | testType: serverTest, |
| 3353 | name: "Basic-Server-ECDHE-RSA", |
| 3354 | config: Config{ |
| 3355 | MaxVersion: VersionTLS12, |
| 3356 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3357 | }, |
| 3358 | flags: []string{ |
| 3359 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3360 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3361 | }, |
| 3362 | }) |
| 3363 | tests = append(tests, testCase{ |
| 3364 | testType: serverTest, |
| 3365 | name: "Basic-Server-ECDHE-ECDSA", |
| 3366 | config: Config{ |
| 3367 | MaxVersion: VersionTLS12, |
| 3368 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 3369 | }, |
| 3370 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3371 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3372 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3373 | }, |
| 3374 | }) |
| 3375 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3376 | // No session ticket support; server doesn't send NewSessionTicket. |
| 3377 | tests = append(tests, testCase{ |
| 3378 | name: "SessionTicketsDisabled-Client", |
| 3379 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3380 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3381 | SessionTicketsDisabled: true, |
| 3382 | }, |
| 3383 | }) |
| 3384 | tests = append(tests, testCase{ |
| 3385 | testType: serverTest, |
| 3386 | name: "SessionTicketsDisabled-Server", |
| 3387 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3388 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3389 | SessionTicketsDisabled: true, |
| 3390 | }, |
| 3391 | }) |
| 3392 | |
| 3393 | // Skip ServerKeyExchange in PSK key exchange if there's no |
| 3394 | // identity hint. |
| 3395 | tests = append(tests, testCase{ |
| 3396 | name: "EmptyPSKHint-Client", |
| 3397 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3398 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3399 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3400 | PreSharedKey: []byte("secret"), |
| 3401 | }, |
| 3402 | flags: []string{"-psk", "secret"}, |
| 3403 | }) |
| 3404 | tests = append(tests, testCase{ |
| 3405 | testType: serverTest, |
| 3406 | name: "EmptyPSKHint-Server", |
| 3407 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3408 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3409 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3410 | PreSharedKey: []byte("secret"), |
| 3411 | }, |
| 3412 | flags: []string{"-psk", "secret"}, |
| 3413 | }) |
| 3414 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3415 | // OCSP stapling tests. |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3416 | tests = append(tests, testCase{ |
| 3417 | testType: clientTest, |
| 3418 | name: "OCSPStapling-Client", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3419 | config: Config{ |
| 3420 | MaxVersion: VersionTLS12, |
| 3421 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3422 | flags: []string{ |
| 3423 | "-enable-ocsp-stapling", |
| 3424 | "-expect-ocsp-response", |
| 3425 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3426 | "-verify-peer", |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3427 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3428 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3429 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3430 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3431 | testType: serverTest, |
| 3432 | name: "OCSPStapling-Server", |
| 3433 | config: Config{ |
| 3434 | MaxVersion: VersionTLS12, |
| 3435 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3436 | expectedOCSPResponse: testOCSPResponse, |
| 3437 | flags: []string{ |
| 3438 | "-ocsp-response", |
| 3439 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3440 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3441 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3442 | }) |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3443 | tests = append(tests, testCase{ |
| 3444 | testType: clientTest, |
| 3445 | name: "OCSPStapling-Client-TLS13", |
| 3446 | config: Config{ |
| 3447 | MaxVersion: VersionTLS13, |
| 3448 | }, |
| 3449 | flags: []string{ |
| 3450 | "-enable-ocsp-stapling", |
| 3451 | "-expect-ocsp-response", |
| 3452 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3453 | "-verify-peer", |
| 3454 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3455 | resumeSession: true, |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3456 | }) |
| 3457 | tests = append(tests, testCase{ |
| 3458 | testType: serverTest, |
| 3459 | name: "OCSPStapling-Server-TLS13", |
| 3460 | config: Config{ |
| 3461 | MaxVersion: VersionTLS13, |
| 3462 | }, |
| 3463 | expectedOCSPResponse: testOCSPResponse, |
| 3464 | flags: []string{ |
| 3465 | "-ocsp-response", |
| 3466 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3467 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3468 | resumeSession: true, |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3469 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3470 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3471 | // Certificate verification tests. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3472 | for _, vers := range tlsVersions { |
| 3473 | if config.protocol == dtls && !vers.hasDTLS { |
| 3474 | continue |
| 3475 | } |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3476 | for _, testType := range []testType{clientTest, serverTest} { |
| 3477 | suffix := "-Client" |
| 3478 | if testType == serverTest { |
| 3479 | suffix = "-Server" |
| 3480 | } |
| 3481 | suffix += "-" + vers.name |
| 3482 | |
| 3483 | flag := "-verify-peer" |
| 3484 | if testType == serverTest { |
| 3485 | flag = "-require-any-client-certificate" |
| 3486 | } |
| 3487 | |
| 3488 | tests = append(tests, testCase{ |
| 3489 | testType: testType, |
| 3490 | name: "CertificateVerificationSucceed" + suffix, |
| 3491 | config: Config{ |
| 3492 | MaxVersion: vers.version, |
| 3493 | Certificates: []Certificate{rsaCertificate}, |
| 3494 | }, |
| 3495 | flags: []string{ |
| 3496 | flag, |
| 3497 | "-expect-verify-result", |
| 3498 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3499 | resumeSession: true, |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3500 | }) |
| 3501 | tests = append(tests, testCase{ |
| 3502 | testType: testType, |
| 3503 | name: "CertificateVerificationFail" + suffix, |
| 3504 | config: Config{ |
| 3505 | MaxVersion: vers.version, |
| 3506 | Certificates: []Certificate{rsaCertificate}, |
| 3507 | }, |
| 3508 | flags: []string{ |
| 3509 | flag, |
| 3510 | "-verify-fail", |
| 3511 | }, |
| 3512 | shouldFail: true, |
| 3513 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 3514 | }) |
| 3515 | } |
| 3516 | |
| 3517 | // By default, the client is in a soft fail mode where the peer |
| 3518 | // certificate is verified but failures are non-fatal. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3519 | tests = append(tests, testCase{ |
| 3520 | testType: clientTest, |
| 3521 | name: "CertificateVerificationSoftFail-" + vers.name, |
| 3522 | config: Config{ |
David Benjamin | bb9e36e | 2016-08-03 14:14:47 -0400 | [diff] [blame] | 3523 | MaxVersion: vers.version, |
| 3524 | Certificates: []Certificate{rsaCertificate}, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3525 | }, |
| 3526 | flags: []string{ |
| 3527 | "-verify-fail", |
| 3528 | "-expect-verify-result", |
| 3529 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3530 | resumeSession: true, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3531 | }) |
| 3532 | } |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3533 | |
David Benjamin | 1d4f4c0 | 2016-07-26 18:03:08 -0400 | [diff] [blame] | 3534 | tests = append(tests, testCase{ |
| 3535 | name: "ShimSendAlert", |
| 3536 | flags: []string{"-send-alert"}, |
| 3537 | shimWritesFirst: true, |
| 3538 | shouldFail: true, |
| 3539 | expectedLocalError: "remote error: decompression failure", |
| 3540 | }) |
| 3541 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3542 | if config.protocol == tls { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3543 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3544 | name: "Renegotiate-Client", |
| 3545 | config: Config{ |
| 3546 | MaxVersion: VersionTLS12, |
| 3547 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 3548 | renegotiate: 1, |
| 3549 | flags: []string{ |
| 3550 | "-renegotiate-freely", |
| 3551 | "-expect-total-renegotiations", "1", |
| 3552 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3553 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3554 | |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 3555 | tests = append(tests, testCase{ |
| 3556 | name: "SendHalfHelloRequest", |
| 3557 | config: Config{ |
| 3558 | MaxVersion: VersionTLS12, |
| 3559 | Bugs: ProtocolBugs{ |
| 3560 | PackHelloRequestWithFinished: config.packHandshakeFlight, |
| 3561 | }, |
| 3562 | }, |
| 3563 | sendHalfHelloRequest: true, |
| 3564 | flags: []string{"-renegotiate-ignore"}, |
| 3565 | shouldFail: true, |
| 3566 | expectedError: ":UNEXPECTED_RECORD:", |
| 3567 | }) |
| 3568 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3569 | // NPN on client and server; results in post-handshake message. |
| 3570 | tests = append(tests, testCase{ |
| 3571 | name: "NPN-Client", |
| 3572 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3573 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3574 | NextProtos: []string{"foo"}, |
| 3575 | }, |
| 3576 | flags: []string{"-select-next-proto", "foo"}, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3577 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3578 | expectedNextProto: "foo", |
| 3579 | expectedNextProtoType: npn, |
| 3580 | }) |
| 3581 | tests = append(tests, testCase{ |
| 3582 | testType: serverTest, |
| 3583 | name: "NPN-Server", |
| 3584 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3585 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3586 | NextProtos: []string{"bar"}, |
| 3587 | }, |
| 3588 | flags: []string{ |
| 3589 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3590 | "-expect-next-proto", "bar", |
| 3591 | }, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3592 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3593 | expectedNextProto: "bar", |
| 3594 | expectedNextProtoType: npn, |
| 3595 | }) |
| 3596 | |
| 3597 | // TODO(davidben): Add tests for when False Start doesn't trigger. |
| 3598 | |
| 3599 | // Client does False Start and negotiates NPN. |
| 3600 | tests = append(tests, testCase{ |
| 3601 | name: "FalseStart", |
| 3602 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3603 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3604 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3605 | NextProtos: []string{"foo"}, |
| 3606 | Bugs: ProtocolBugs{ |
| 3607 | ExpectFalseStart: true, |
| 3608 | }, |
| 3609 | }, |
| 3610 | flags: []string{ |
| 3611 | "-false-start", |
| 3612 | "-select-next-proto", "foo", |
| 3613 | }, |
| 3614 | shimWritesFirst: true, |
| 3615 | resumeSession: true, |
| 3616 | }) |
| 3617 | |
| 3618 | // Client does False Start and negotiates ALPN. |
| 3619 | tests = append(tests, testCase{ |
| 3620 | name: "FalseStart-ALPN", |
| 3621 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3622 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3623 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3624 | NextProtos: []string{"foo"}, |
| 3625 | Bugs: ProtocolBugs{ |
| 3626 | ExpectFalseStart: true, |
| 3627 | }, |
| 3628 | }, |
| 3629 | flags: []string{ |
| 3630 | "-false-start", |
| 3631 | "-advertise-alpn", "\x03foo", |
| 3632 | }, |
| 3633 | shimWritesFirst: true, |
| 3634 | resumeSession: true, |
| 3635 | }) |
| 3636 | |
| 3637 | // Client does False Start but doesn't explicitly call |
| 3638 | // SSL_connect. |
| 3639 | tests = append(tests, testCase{ |
| 3640 | name: "FalseStart-Implicit", |
| 3641 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3642 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3643 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3644 | NextProtos: []string{"foo"}, |
| 3645 | }, |
| 3646 | flags: []string{ |
| 3647 | "-implicit-handshake", |
| 3648 | "-false-start", |
| 3649 | "-advertise-alpn", "\x03foo", |
| 3650 | }, |
| 3651 | }) |
| 3652 | |
| 3653 | // False Start without session tickets. |
| 3654 | tests = append(tests, testCase{ |
| 3655 | name: "FalseStart-SessionTicketsDisabled", |
| 3656 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3657 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3658 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3659 | NextProtos: []string{"foo"}, |
| 3660 | SessionTicketsDisabled: true, |
| 3661 | Bugs: ProtocolBugs{ |
| 3662 | ExpectFalseStart: true, |
| 3663 | }, |
| 3664 | }, |
| 3665 | flags: []string{ |
| 3666 | "-false-start", |
| 3667 | "-select-next-proto", "foo", |
| 3668 | }, |
| 3669 | shimWritesFirst: true, |
| 3670 | }) |
| 3671 | |
Adam Langley | df759b5 | 2016-07-11 15:24:37 -0700 | [diff] [blame] | 3672 | tests = append(tests, testCase{ |
| 3673 | name: "FalseStart-CECPQ1", |
| 3674 | config: Config{ |
| 3675 | MaxVersion: VersionTLS12, |
| 3676 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 3677 | NextProtos: []string{"foo"}, |
| 3678 | Bugs: ProtocolBugs{ |
| 3679 | ExpectFalseStart: true, |
| 3680 | }, |
| 3681 | }, |
| 3682 | flags: []string{ |
| 3683 | "-false-start", |
| 3684 | "-cipher", "DEFAULT:kCECPQ1", |
| 3685 | "-select-next-proto", "foo", |
| 3686 | }, |
| 3687 | shimWritesFirst: true, |
| 3688 | resumeSession: true, |
| 3689 | }) |
| 3690 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3691 | // Server parses a V2ClientHello. |
| 3692 | tests = append(tests, testCase{ |
| 3693 | testType: serverTest, |
| 3694 | name: "SendV2ClientHello", |
| 3695 | config: Config{ |
| 3696 | // Choose a cipher suite that does not involve |
| 3697 | // elliptic curves, so no extensions are |
| 3698 | // involved. |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3699 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3700 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 3701 | Bugs: ProtocolBugs{ |
| 3702 | SendV2ClientHello: true, |
| 3703 | }, |
| 3704 | }, |
| 3705 | }) |
| 3706 | |
| 3707 | // Client sends a Channel ID. |
| 3708 | tests = append(tests, testCase{ |
| 3709 | name: "ChannelID-Client", |
| 3710 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3711 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3712 | RequestChannelID: true, |
| 3713 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3714 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3715 | resumeSession: true, |
| 3716 | expectChannelID: true, |
| 3717 | }) |
| 3718 | |
| 3719 | // Server accepts a Channel ID. |
| 3720 | tests = append(tests, testCase{ |
| 3721 | testType: serverTest, |
| 3722 | name: "ChannelID-Server", |
| 3723 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3724 | MaxVersion: VersionTLS12, |
| 3725 | ChannelID: channelIDKey, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3726 | }, |
| 3727 | flags: []string{ |
| 3728 | "-expect-channel-id", |
| 3729 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3730 | }, |
| 3731 | resumeSession: true, |
| 3732 | expectChannelID: true, |
| 3733 | }) |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3734 | |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3735 | // Channel ID and NPN at the same time, to ensure their relative |
| 3736 | // ordering is correct. |
| 3737 | tests = append(tests, testCase{ |
| 3738 | name: "ChannelID-NPN-Client", |
| 3739 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3740 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3741 | RequestChannelID: true, |
| 3742 | NextProtos: []string{"foo"}, |
| 3743 | }, |
| 3744 | flags: []string{ |
| 3745 | "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile), |
| 3746 | "-select-next-proto", "foo", |
| 3747 | }, |
| 3748 | resumeSession: true, |
| 3749 | expectChannelID: true, |
| 3750 | expectedNextProto: "foo", |
| 3751 | expectedNextProtoType: npn, |
| 3752 | }) |
| 3753 | tests = append(tests, testCase{ |
| 3754 | testType: serverTest, |
| 3755 | name: "ChannelID-NPN-Server", |
| 3756 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3757 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3758 | ChannelID: channelIDKey, |
| 3759 | NextProtos: []string{"bar"}, |
| 3760 | }, |
| 3761 | flags: []string{ |
| 3762 | "-expect-channel-id", |
| 3763 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3764 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3765 | "-expect-next-proto", "bar", |
| 3766 | }, |
| 3767 | resumeSession: true, |
| 3768 | expectChannelID: true, |
| 3769 | expectedNextProto: "bar", |
| 3770 | expectedNextProtoType: npn, |
| 3771 | }) |
| 3772 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3773 | // Bidirectional shutdown with the runner initiating. |
| 3774 | tests = append(tests, testCase{ |
| 3775 | name: "Shutdown-Runner", |
| 3776 | config: Config{ |
| 3777 | Bugs: ProtocolBugs{ |
| 3778 | ExpectCloseNotify: true, |
| 3779 | }, |
| 3780 | }, |
| 3781 | flags: []string{"-check-close-notify"}, |
| 3782 | }) |
| 3783 | |
| 3784 | // Bidirectional shutdown with the shim initiating. The runner, |
| 3785 | // in the meantime, sends garbage before the close_notify which |
| 3786 | // the shim must ignore. |
| 3787 | tests = append(tests, testCase{ |
| 3788 | name: "Shutdown-Shim", |
| 3789 | config: Config{ |
David Benjamin | e8e84b9 | 2016-08-03 15:39:47 -0400 | [diff] [blame] | 3790 | MaxVersion: VersionTLS12, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3791 | Bugs: ProtocolBugs{ |
| 3792 | ExpectCloseNotify: true, |
| 3793 | }, |
| 3794 | }, |
| 3795 | shimShutsDown: true, |
| 3796 | sendEmptyRecords: 1, |
| 3797 | sendWarningAlerts: 1, |
| 3798 | flags: []string{"-check-close-notify"}, |
| 3799 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3800 | } else { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3801 | // TODO(davidben): DTLS 1.3 will want a similar thing for |
| 3802 | // HelloRetryRequest. |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3803 | tests = append(tests, testCase{ |
| 3804 | name: "SkipHelloVerifyRequest", |
| 3805 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3806 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3807 | Bugs: ProtocolBugs{ |
| 3808 | SkipHelloVerifyRequest: true, |
| 3809 | }, |
| 3810 | }, |
| 3811 | }) |
| 3812 | } |
| 3813 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3814 | for _, test := range tests { |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3815 | test.protocol = config.protocol |
| 3816 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3817 | test.name += "-DTLS" |
| 3818 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3819 | if config.async { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3820 | test.name += "-Async" |
| 3821 | test.flags = append(test.flags, "-async") |
| 3822 | } else { |
| 3823 | test.name += "-Sync" |
| 3824 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3825 | if config.splitHandshake { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3826 | test.name += "-SplitHandshakeRecords" |
| 3827 | test.config.Bugs.MaxHandshakeRecordLength = 1 |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3828 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3829 | test.config.Bugs.MaxPacketLength = 256 |
| 3830 | test.flags = append(test.flags, "-mtu", "256") |
| 3831 | } |
| 3832 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3833 | if config.packHandshakeFlight { |
| 3834 | test.name += "-PackHandshakeFlight" |
| 3835 | test.config.Bugs.PackHandshakeFlight = true |
| 3836 | } |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3837 | testCases = append(testCases, test) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 3838 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 3839 | } |
| 3840 | |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3841 | func addDDoSCallbackTests() { |
| 3842 | // DDoS callback. |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3843 | for _, resume := range []bool{false, true} { |
| 3844 | suffix := "Resume" |
| 3845 | if resume { |
| 3846 | suffix = "No" + suffix |
| 3847 | } |
| 3848 | |
| 3849 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3850 | testType: serverTest, |
| 3851 | name: "Server-DDoS-OK-" + suffix, |
| 3852 | config: Config{ |
| 3853 | MaxVersion: VersionTLS12, |
| 3854 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3855 | flags: []string{"-install-ddos-callback"}, |
| 3856 | resumeSession: resume, |
| 3857 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3858 | testCases = append(testCases, testCase{ |
| 3859 | testType: serverTest, |
| 3860 | name: "Server-DDoS-OK-" + suffix + "-TLS13", |
| 3861 | config: Config{ |
| 3862 | MaxVersion: VersionTLS13, |
| 3863 | }, |
| 3864 | flags: []string{"-install-ddos-callback"}, |
| 3865 | resumeSession: resume, |
| 3866 | }) |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3867 | |
| 3868 | failFlag := "-fail-ddos-callback" |
| 3869 | if resume { |
| 3870 | failFlag = "-fail-second-ddos-callback" |
| 3871 | } |
| 3872 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3873 | testType: serverTest, |
| 3874 | name: "Server-DDoS-Reject-" + suffix, |
| 3875 | config: Config{ |
| 3876 | MaxVersion: VersionTLS12, |
| 3877 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3878 | flags: []string{"-install-ddos-callback", failFlag}, |
| 3879 | resumeSession: resume, |
| 3880 | shouldFail: true, |
| 3881 | expectedError: ":CONNECTION_REJECTED:", |
| 3882 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 3883 | testCases = append(testCases, testCase{ |
| 3884 | testType: serverTest, |
| 3885 | name: "Server-DDoS-Reject-" + suffix + "-TLS13", |
| 3886 | config: Config{ |
| 3887 | MaxVersion: VersionTLS13, |
| 3888 | }, |
| 3889 | flags: []string{"-install-ddos-callback", failFlag}, |
| 3890 | resumeSession: resume, |
| 3891 | shouldFail: true, |
| 3892 | expectedError: ":CONNECTION_REJECTED:", |
| 3893 | }) |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3894 | } |
| 3895 | } |
| 3896 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3897 | func addVersionNegotiationTests() { |
| 3898 | for i, shimVers := range tlsVersions { |
| 3899 | // Assemble flags to disable all newer versions on the shim. |
| 3900 | var flags []string |
| 3901 | for _, vers := range tlsVersions[i+1:] { |
| 3902 | flags = append(flags, vers.flag) |
| 3903 | } |
| 3904 | |
| 3905 | for _, runnerVers := range tlsVersions { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3906 | protocols := []protocol{tls} |
| 3907 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 3908 | protocols = append(protocols, dtls) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3909 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3910 | for _, protocol := range protocols { |
| 3911 | expectedVersion := shimVers.version |
| 3912 | if runnerVers.version < shimVers.version { |
| 3913 | expectedVersion = runnerVers.version |
| 3914 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3915 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3916 | suffix := shimVers.name + "-" + runnerVers.name |
| 3917 | if protocol == dtls { |
| 3918 | suffix += "-DTLS" |
| 3919 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3920 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3921 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 3922 | |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3923 | clientVers := shimVers.version |
| 3924 | if clientVers > VersionTLS10 { |
| 3925 | clientVers = VersionTLS10 |
| 3926 | } |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3927 | serverVers := expectedVersion |
| 3928 | if expectedVersion >= VersionTLS13 { |
| 3929 | serverVers = VersionTLS10 |
| 3930 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3931 | testCases = append(testCases, testCase{ |
| 3932 | protocol: protocol, |
| 3933 | testType: clientTest, |
| 3934 | name: "VersionNegotiation-Client-" + suffix, |
| 3935 | config: Config{ |
| 3936 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3937 | Bugs: ProtocolBugs{ |
| 3938 | ExpectInitialRecordVersion: clientVers, |
| 3939 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3940 | }, |
| 3941 | flags: flags, |
| 3942 | expectedVersion: expectedVersion, |
| 3943 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3944 | testCases = append(testCases, testCase{ |
| 3945 | protocol: protocol, |
| 3946 | testType: clientTest, |
| 3947 | name: "VersionNegotiation-Client2-" + suffix, |
| 3948 | config: Config{ |
| 3949 | MaxVersion: runnerVers.version, |
| 3950 | Bugs: ProtocolBugs{ |
| 3951 | ExpectInitialRecordVersion: clientVers, |
| 3952 | }, |
| 3953 | }, |
| 3954 | flags: []string{"-max-version", shimVersFlag}, |
| 3955 | expectedVersion: expectedVersion, |
| 3956 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3957 | |
| 3958 | testCases = append(testCases, testCase{ |
| 3959 | protocol: protocol, |
| 3960 | testType: serverTest, |
| 3961 | name: "VersionNegotiation-Server-" + suffix, |
| 3962 | config: Config{ |
| 3963 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3964 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3965 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3966 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3967 | }, |
| 3968 | flags: flags, |
| 3969 | expectedVersion: expectedVersion, |
| 3970 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3971 | testCases = append(testCases, testCase{ |
| 3972 | protocol: protocol, |
| 3973 | testType: serverTest, |
| 3974 | name: "VersionNegotiation-Server2-" + suffix, |
| 3975 | config: Config{ |
| 3976 | MaxVersion: runnerVers.version, |
| 3977 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3978 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3979 | }, |
| 3980 | }, |
| 3981 | flags: []string{"-max-version", shimVersFlag}, |
| 3982 | expectedVersion: expectedVersion, |
| 3983 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3984 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3985 | } |
| 3986 | } |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 3987 | |
| 3988 | // Test for version tolerance. |
| 3989 | testCases = append(testCases, testCase{ |
| 3990 | testType: serverTest, |
| 3991 | name: "MinorVersionTolerance", |
| 3992 | config: Config{ |
| 3993 | Bugs: ProtocolBugs{ |
| 3994 | SendClientVersion: 0x03ff, |
| 3995 | }, |
| 3996 | }, |
| 3997 | expectedVersion: VersionTLS13, |
| 3998 | }) |
| 3999 | testCases = append(testCases, testCase{ |
| 4000 | testType: serverTest, |
| 4001 | name: "MajorVersionTolerance", |
| 4002 | config: Config{ |
| 4003 | Bugs: ProtocolBugs{ |
| 4004 | SendClientVersion: 0x0400, |
| 4005 | }, |
| 4006 | }, |
| 4007 | expectedVersion: VersionTLS13, |
| 4008 | }) |
| 4009 | testCases = append(testCases, testCase{ |
| 4010 | protocol: dtls, |
| 4011 | testType: serverTest, |
| 4012 | name: "MinorVersionTolerance-DTLS", |
| 4013 | config: Config{ |
| 4014 | Bugs: ProtocolBugs{ |
| 4015 | SendClientVersion: 0x03ff, |
| 4016 | }, |
| 4017 | }, |
| 4018 | expectedVersion: VersionTLS12, |
| 4019 | }) |
| 4020 | testCases = append(testCases, testCase{ |
| 4021 | protocol: dtls, |
| 4022 | testType: serverTest, |
| 4023 | name: "MajorVersionTolerance-DTLS", |
| 4024 | config: Config{ |
| 4025 | Bugs: ProtocolBugs{ |
| 4026 | SendClientVersion: 0x0400, |
| 4027 | }, |
| 4028 | }, |
| 4029 | expectedVersion: VersionTLS12, |
| 4030 | }) |
| 4031 | |
| 4032 | // Test that versions below 3.0 are rejected. |
| 4033 | testCases = append(testCases, testCase{ |
| 4034 | testType: serverTest, |
| 4035 | name: "VersionTooLow", |
| 4036 | config: Config{ |
| 4037 | Bugs: ProtocolBugs{ |
| 4038 | SendClientVersion: 0x0200, |
| 4039 | }, |
| 4040 | }, |
| 4041 | shouldFail: true, |
| 4042 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4043 | }) |
| 4044 | testCases = append(testCases, testCase{ |
| 4045 | protocol: dtls, |
| 4046 | testType: serverTest, |
| 4047 | name: "VersionTooLow-DTLS", |
| 4048 | config: Config{ |
| 4049 | Bugs: ProtocolBugs{ |
| 4050 | // 0x0201 is the lowest version expressable in |
| 4051 | // DTLS. |
| 4052 | SendClientVersion: 0x0201, |
| 4053 | }, |
| 4054 | }, |
| 4055 | shouldFail: true, |
| 4056 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4057 | }) |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 4058 | |
| 4059 | // Test TLS 1.3's downgrade signal. |
| 4060 | testCases = append(testCases, testCase{ |
| 4061 | name: "Downgrade-TLS12-Client", |
| 4062 | config: Config{ |
| 4063 | Bugs: ProtocolBugs{ |
| 4064 | NegotiateVersion: VersionTLS12, |
| 4065 | }, |
| 4066 | }, |
| 4067 | shouldFail: true, |
| 4068 | expectedError: ":DOWNGRADE_DETECTED:", |
| 4069 | }) |
| 4070 | testCases = append(testCases, testCase{ |
| 4071 | testType: serverTest, |
| 4072 | name: "Downgrade-TLS12-Server", |
| 4073 | config: Config{ |
| 4074 | Bugs: ProtocolBugs{ |
| 4075 | SendClientVersion: VersionTLS12, |
| 4076 | }, |
| 4077 | }, |
| 4078 | shouldFail: true, |
| 4079 | expectedLocalError: "tls: downgrade from TLS 1.3 detected", |
| 4080 | }) |
David Benjamin | 5e7e7cc | 2016-07-21 12:55:28 +0200 | [diff] [blame] | 4081 | |
| 4082 | // Test that FALLBACK_SCSV is sent and that the downgrade signal works |
| 4083 | // behave correctly when both real maximum and fallback versions are |
| 4084 | // set. |
| 4085 | testCases = append(testCases, testCase{ |
| 4086 | name: "Downgrade-TLS12-Client-Fallback", |
| 4087 | config: Config{ |
| 4088 | Bugs: ProtocolBugs{ |
| 4089 | FailIfNotFallbackSCSV: true, |
| 4090 | }, |
| 4091 | }, |
| 4092 | flags: []string{ |
| 4093 | "-max-version", strconv.Itoa(VersionTLS13), |
| 4094 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 4095 | }, |
| 4096 | shouldFail: true, |
| 4097 | expectedError: ":DOWNGRADE_DETECTED:", |
| 4098 | }) |
| 4099 | testCases = append(testCases, testCase{ |
| 4100 | name: "Downgrade-TLS12-Client-FallbackEqualsMax", |
| 4101 | flags: []string{ |
| 4102 | "-max-version", strconv.Itoa(VersionTLS12), |
| 4103 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 4104 | }, |
| 4105 | }) |
| 4106 | |
| 4107 | // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather |
| 4108 | // just have such connections fail than risk getting confused because we |
| 4109 | // didn't sent the 1.3 ClientHello.) |
| 4110 | testCases = append(testCases, testCase{ |
| 4111 | name: "Downgrade-TLS12-Fallback-CheckVersion", |
| 4112 | config: Config{ |
| 4113 | Bugs: ProtocolBugs{ |
| 4114 | NegotiateVersion: VersionTLS13, |
| 4115 | FailIfNotFallbackSCSV: true, |
| 4116 | }, |
| 4117 | }, |
| 4118 | flags: []string{ |
| 4119 | "-max-version", strconv.Itoa(VersionTLS13), |
| 4120 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 4121 | }, |
| 4122 | shouldFail: true, |
| 4123 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4124 | }) |
| 4125 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4126 | } |
| 4127 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4128 | func addMinimumVersionTests() { |
| 4129 | for i, shimVers := range tlsVersions { |
| 4130 | // Assemble flags to disable all older versions on the shim. |
| 4131 | var flags []string |
| 4132 | for _, vers := range tlsVersions[:i] { |
| 4133 | flags = append(flags, vers.flag) |
| 4134 | } |
| 4135 | |
| 4136 | for _, runnerVers := range tlsVersions { |
| 4137 | protocols := []protocol{tls} |
| 4138 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 4139 | protocols = append(protocols, dtls) |
| 4140 | } |
| 4141 | for _, protocol := range protocols { |
| 4142 | suffix := shimVers.name + "-" + runnerVers.name |
| 4143 | if protocol == dtls { |
| 4144 | suffix += "-DTLS" |
| 4145 | } |
| 4146 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 4147 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4148 | var expectedVersion uint16 |
| 4149 | var shouldFail bool |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4150 | var expectedClientError, expectedServerError string |
| 4151 | var expectedClientLocalError, expectedServerLocalError string |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4152 | if runnerVers.version >= shimVers.version { |
| 4153 | expectedVersion = runnerVers.version |
| 4154 | } else { |
| 4155 | shouldFail = true |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4156 | expectedServerError = ":UNSUPPORTED_PROTOCOL:" |
| 4157 | expectedServerLocalError = "remote error: protocol version not supported" |
| 4158 | if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 { |
| 4159 | // If the client's minimum version is TLS 1.3 and the runner's |
| 4160 | // maximum is below TLS 1.2, the runner will fail to select a |
| 4161 | // cipher before the shim rejects the selected version. |
| 4162 | expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:" |
| 4163 | expectedClientLocalError = "tls: no cipher suite supported by both client and server" |
| 4164 | } else { |
| 4165 | expectedClientError = expectedServerError |
| 4166 | expectedClientLocalError = expectedServerLocalError |
| 4167 | } |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | testCases = append(testCases, testCase{ |
| 4171 | protocol: protocol, |
| 4172 | testType: clientTest, |
| 4173 | name: "MinimumVersion-Client-" + suffix, |
| 4174 | config: Config{ |
| 4175 | MaxVersion: runnerVers.version, |
| 4176 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4177 | flags: flags, |
| 4178 | expectedVersion: expectedVersion, |
| 4179 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4180 | expectedError: expectedClientError, |
| 4181 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4182 | }) |
| 4183 | testCases = append(testCases, testCase{ |
| 4184 | protocol: protocol, |
| 4185 | testType: clientTest, |
| 4186 | name: "MinimumVersion-Client2-" + suffix, |
| 4187 | config: Config{ |
| 4188 | MaxVersion: runnerVers.version, |
| 4189 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4190 | flags: []string{"-min-version", shimVersFlag}, |
| 4191 | expectedVersion: expectedVersion, |
| 4192 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4193 | expectedError: expectedClientError, |
| 4194 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4195 | }) |
| 4196 | |
| 4197 | testCases = append(testCases, testCase{ |
| 4198 | protocol: protocol, |
| 4199 | testType: serverTest, |
| 4200 | name: "MinimumVersion-Server-" + suffix, |
| 4201 | config: Config{ |
| 4202 | MaxVersion: runnerVers.version, |
| 4203 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4204 | flags: flags, |
| 4205 | expectedVersion: expectedVersion, |
| 4206 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4207 | expectedError: expectedServerError, |
| 4208 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4209 | }) |
| 4210 | testCases = append(testCases, testCase{ |
| 4211 | protocol: protocol, |
| 4212 | testType: serverTest, |
| 4213 | name: "MinimumVersion-Server2-" + suffix, |
| 4214 | config: Config{ |
| 4215 | MaxVersion: runnerVers.version, |
| 4216 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4217 | flags: []string{"-min-version", shimVersFlag}, |
| 4218 | expectedVersion: expectedVersion, |
| 4219 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4220 | expectedError: expectedServerError, |
| 4221 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4222 | }) |
| 4223 | } |
| 4224 | } |
| 4225 | } |
| 4226 | } |
| 4227 | |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4228 | func addExtensionTests() { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4229 | // TODO(davidben): Extensions, where applicable, all move their server |
| 4230 | // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these |
| 4231 | // tests for both. Also test interaction with 0-RTT when implemented. |
| 4232 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4233 | // Repeat extensions tests all versions except SSL 3.0. |
| 4234 | for _, ver := range tlsVersions { |
| 4235 | if ver.version == VersionSSL30 { |
| 4236 | continue |
| 4237 | } |
| 4238 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4239 | // Test that duplicate extensions are rejected. |
| 4240 | testCases = append(testCases, testCase{ |
| 4241 | testType: clientTest, |
| 4242 | name: "DuplicateExtensionClient-" + ver.name, |
| 4243 | config: Config{ |
| 4244 | MaxVersion: ver.version, |
| 4245 | Bugs: ProtocolBugs{ |
| 4246 | DuplicateExtension: true, |
| 4247 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4248 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4249 | shouldFail: true, |
| 4250 | expectedLocalError: "remote error: error decoding message", |
| 4251 | }) |
| 4252 | testCases = append(testCases, testCase{ |
| 4253 | testType: serverTest, |
| 4254 | name: "DuplicateExtensionServer-" + ver.name, |
| 4255 | config: Config{ |
| 4256 | MaxVersion: ver.version, |
| 4257 | Bugs: ProtocolBugs{ |
| 4258 | DuplicateExtension: true, |
| 4259 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4260 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4261 | shouldFail: true, |
| 4262 | expectedLocalError: "remote error: error decoding message", |
| 4263 | }) |
| 4264 | |
| 4265 | // Test SNI. |
| 4266 | testCases = append(testCases, testCase{ |
| 4267 | testType: clientTest, |
| 4268 | name: "ServerNameExtensionClient-" + ver.name, |
| 4269 | config: Config{ |
| 4270 | MaxVersion: ver.version, |
| 4271 | Bugs: ProtocolBugs{ |
| 4272 | ExpectServerName: "example.com", |
| 4273 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4274 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4275 | flags: []string{"-host-name", "example.com"}, |
| 4276 | }) |
| 4277 | testCases = append(testCases, testCase{ |
| 4278 | testType: clientTest, |
| 4279 | name: "ServerNameExtensionClientMismatch-" + ver.name, |
| 4280 | config: Config{ |
| 4281 | MaxVersion: ver.version, |
| 4282 | Bugs: ProtocolBugs{ |
| 4283 | ExpectServerName: "mismatch.com", |
| 4284 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4285 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4286 | flags: []string{"-host-name", "example.com"}, |
| 4287 | shouldFail: true, |
| 4288 | expectedLocalError: "tls: unexpected server name", |
| 4289 | }) |
| 4290 | testCases = append(testCases, testCase{ |
| 4291 | testType: clientTest, |
| 4292 | name: "ServerNameExtensionClientMissing-" + ver.name, |
| 4293 | config: Config{ |
| 4294 | MaxVersion: ver.version, |
| 4295 | Bugs: ProtocolBugs{ |
| 4296 | ExpectServerName: "missing.com", |
| 4297 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4298 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4299 | shouldFail: true, |
| 4300 | expectedLocalError: "tls: unexpected server name", |
| 4301 | }) |
| 4302 | testCases = append(testCases, testCase{ |
| 4303 | testType: serverTest, |
| 4304 | name: "ServerNameExtensionServer-" + ver.name, |
| 4305 | config: Config{ |
| 4306 | MaxVersion: ver.version, |
| 4307 | ServerName: "example.com", |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 4308 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4309 | flags: []string{"-expect-server-name", "example.com"}, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4310 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4311 | }) |
| 4312 | |
| 4313 | // Test ALPN. |
| 4314 | testCases = append(testCases, testCase{ |
| 4315 | testType: clientTest, |
| 4316 | name: "ALPNClient-" + ver.name, |
| 4317 | config: Config{ |
| 4318 | MaxVersion: ver.version, |
| 4319 | NextProtos: []string{"foo"}, |
| 4320 | }, |
| 4321 | flags: []string{ |
| 4322 | "-advertise-alpn", "\x03foo\x03bar\x03baz", |
| 4323 | "-expect-alpn", "foo", |
| 4324 | }, |
| 4325 | expectedNextProto: "foo", |
| 4326 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4327 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4328 | }) |
| 4329 | testCases = append(testCases, testCase{ |
David Benjamin | 3e51757 | 2016-08-11 11:52:23 -0400 | [diff] [blame] | 4330 | testType: clientTest, |
| 4331 | name: "ALPNClient-Mismatch-" + ver.name, |
| 4332 | config: Config{ |
| 4333 | MaxVersion: ver.version, |
| 4334 | Bugs: ProtocolBugs{ |
| 4335 | SendALPN: "baz", |
| 4336 | }, |
| 4337 | }, |
| 4338 | flags: []string{ |
| 4339 | "-advertise-alpn", "\x03foo\x03bar", |
| 4340 | }, |
| 4341 | shouldFail: true, |
| 4342 | expectedError: ":INVALID_ALPN_PROTOCOL:", |
| 4343 | expectedLocalError: "remote error: illegal parameter", |
| 4344 | }) |
| 4345 | testCases = append(testCases, testCase{ |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4346 | testType: serverTest, |
| 4347 | name: "ALPNServer-" + ver.name, |
| 4348 | config: Config{ |
| 4349 | MaxVersion: ver.version, |
| 4350 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4351 | }, |
| 4352 | flags: []string{ |
| 4353 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4354 | "-select-alpn", "foo", |
| 4355 | }, |
| 4356 | expectedNextProto: "foo", |
| 4357 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4358 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4359 | }) |
| 4360 | testCases = append(testCases, testCase{ |
| 4361 | testType: serverTest, |
| 4362 | name: "ALPNServer-Decline-" + ver.name, |
| 4363 | config: Config{ |
| 4364 | MaxVersion: ver.version, |
| 4365 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4366 | }, |
| 4367 | flags: []string{"-decline-alpn"}, |
| 4368 | expectNoNextProto: true, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4369 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4370 | }) |
| 4371 | |
David Benjamin | 25fe85b | 2016-08-09 20:00:32 -0400 | [diff] [blame] | 4372 | // Test ALPN in async mode as well to ensure that extensions callbacks are only |
| 4373 | // called once. |
| 4374 | testCases = append(testCases, testCase{ |
| 4375 | testType: serverTest, |
| 4376 | name: "ALPNServer-Async-" + ver.name, |
| 4377 | config: Config{ |
| 4378 | MaxVersion: ver.version, |
| 4379 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4380 | }, |
| 4381 | flags: []string{ |
| 4382 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4383 | "-select-alpn", "foo", |
| 4384 | "-async", |
| 4385 | }, |
| 4386 | expectedNextProto: "foo", |
| 4387 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4388 | resumeSession: true, |
David Benjamin | 25fe85b | 2016-08-09 20:00:32 -0400 | [diff] [blame] | 4389 | }) |
| 4390 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4391 | var emptyString string |
| 4392 | testCases = append(testCases, testCase{ |
| 4393 | testType: clientTest, |
| 4394 | name: "ALPNClient-EmptyProtocolName-" + ver.name, |
| 4395 | config: Config{ |
| 4396 | MaxVersion: ver.version, |
| 4397 | NextProtos: []string{""}, |
| 4398 | Bugs: ProtocolBugs{ |
| 4399 | // A server returning an empty ALPN protocol |
| 4400 | // should be rejected. |
| 4401 | ALPNProtocol: &emptyString, |
| 4402 | }, |
| 4403 | }, |
| 4404 | flags: []string{ |
| 4405 | "-advertise-alpn", "\x03foo", |
| 4406 | }, |
| 4407 | shouldFail: true, |
| 4408 | expectedError: ":PARSE_TLSEXT:", |
| 4409 | }) |
| 4410 | testCases = append(testCases, testCase{ |
| 4411 | testType: serverTest, |
| 4412 | name: "ALPNServer-EmptyProtocolName-" + ver.name, |
| 4413 | config: Config{ |
| 4414 | MaxVersion: ver.version, |
| 4415 | // A ClientHello containing an empty ALPN protocol |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4416 | // should be rejected. |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4417 | NextProtos: []string{"foo", "", "baz"}, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4418 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4419 | flags: []string{ |
| 4420 | "-select-alpn", "foo", |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 4421 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4422 | shouldFail: true, |
| 4423 | expectedError: ":PARSE_TLSEXT:", |
| 4424 | }) |
| 4425 | |
| 4426 | // Test NPN and the interaction with ALPN. |
| 4427 | if ver.version < VersionTLS13 { |
| 4428 | // Test that the server prefers ALPN over NPN. |
| 4429 | testCases = append(testCases, testCase{ |
| 4430 | testType: serverTest, |
| 4431 | name: "ALPNServer-Preferred-" + ver.name, |
| 4432 | config: Config{ |
| 4433 | MaxVersion: ver.version, |
| 4434 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4435 | }, |
| 4436 | flags: []string{ |
| 4437 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4438 | "-select-alpn", "foo", |
| 4439 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4440 | }, |
| 4441 | expectedNextProto: "foo", |
| 4442 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4443 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4444 | }) |
| 4445 | testCases = append(testCases, testCase{ |
| 4446 | testType: serverTest, |
| 4447 | name: "ALPNServer-Preferred-Swapped-" + ver.name, |
| 4448 | config: Config{ |
| 4449 | MaxVersion: ver.version, |
| 4450 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4451 | Bugs: ProtocolBugs{ |
| 4452 | SwapNPNAndALPN: true, |
| 4453 | }, |
| 4454 | }, |
| 4455 | flags: []string{ |
| 4456 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4457 | "-select-alpn", "foo", |
| 4458 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4459 | }, |
| 4460 | expectedNextProto: "foo", |
| 4461 | expectedNextProtoType: alpn, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4462 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4463 | }) |
| 4464 | |
| 4465 | // Test that negotiating both NPN and ALPN is forbidden. |
| 4466 | testCases = append(testCases, testCase{ |
| 4467 | name: "NegotiateALPNAndNPN-" + ver.name, |
| 4468 | config: Config{ |
| 4469 | MaxVersion: ver.version, |
| 4470 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4471 | Bugs: ProtocolBugs{ |
| 4472 | NegotiateALPNAndNPN: true, |
| 4473 | }, |
| 4474 | }, |
| 4475 | flags: []string{ |
| 4476 | "-advertise-alpn", "\x03foo", |
| 4477 | "-select-next-proto", "foo", |
| 4478 | }, |
| 4479 | shouldFail: true, |
| 4480 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4481 | }) |
| 4482 | testCases = append(testCases, testCase{ |
| 4483 | name: "NegotiateALPNAndNPN-Swapped-" + ver.name, |
| 4484 | config: Config{ |
| 4485 | MaxVersion: ver.version, |
| 4486 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4487 | Bugs: ProtocolBugs{ |
| 4488 | NegotiateALPNAndNPN: true, |
| 4489 | SwapNPNAndALPN: true, |
| 4490 | }, |
| 4491 | }, |
| 4492 | flags: []string{ |
| 4493 | "-advertise-alpn", "\x03foo", |
| 4494 | "-select-next-proto", "foo", |
| 4495 | }, |
| 4496 | shouldFail: true, |
| 4497 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4498 | }) |
| 4499 | |
| 4500 | // Test that NPN can be disabled with SSL_OP_DISABLE_NPN. |
| 4501 | testCases = append(testCases, testCase{ |
| 4502 | name: "DisableNPN-" + ver.name, |
| 4503 | config: Config{ |
| 4504 | MaxVersion: ver.version, |
| 4505 | NextProtos: []string{"foo"}, |
| 4506 | }, |
| 4507 | flags: []string{ |
| 4508 | "-select-next-proto", "foo", |
| 4509 | "-disable-npn", |
| 4510 | }, |
| 4511 | expectNoNextProto: true, |
| 4512 | }) |
| 4513 | } |
| 4514 | |
| 4515 | // Test ticket behavior. |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4516 | |
| 4517 | // Resume with a corrupt ticket. |
| 4518 | testCases = append(testCases, testCase{ |
| 4519 | testType: serverTest, |
| 4520 | name: "CorruptTicket-" + ver.name, |
| 4521 | config: Config{ |
| 4522 | MaxVersion: ver.version, |
| 4523 | Bugs: ProtocolBugs{ |
| 4524 | CorruptTicket: true, |
| 4525 | }, |
| 4526 | }, |
| 4527 | resumeSession: true, |
| 4528 | expectResumeRejected: true, |
| 4529 | }) |
| 4530 | // Test the ticket callback, with and without renewal. |
| 4531 | testCases = append(testCases, testCase{ |
| 4532 | testType: serverTest, |
| 4533 | name: "TicketCallback-" + ver.name, |
| 4534 | config: Config{ |
| 4535 | MaxVersion: ver.version, |
| 4536 | }, |
| 4537 | resumeSession: true, |
| 4538 | flags: []string{"-use-ticket-callback"}, |
| 4539 | }) |
| 4540 | testCases = append(testCases, testCase{ |
| 4541 | testType: serverTest, |
| 4542 | name: "TicketCallback-Renew-" + ver.name, |
| 4543 | config: Config{ |
| 4544 | MaxVersion: ver.version, |
| 4545 | Bugs: ProtocolBugs{ |
| 4546 | ExpectNewTicket: true, |
| 4547 | }, |
| 4548 | }, |
| 4549 | flags: []string{"-use-ticket-callback", "-renew-ticket"}, |
| 4550 | resumeSession: true, |
| 4551 | }) |
| 4552 | |
| 4553 | // Test that the ticket callback is only called once when everything before |
| 4554 | // it in the ClientHello is asynchronous. This corrupts the ticket so |
| 4555 | // certificate selection callbacks run. |
| 4556 | testCases = append(testCases, testCase{ |
| 4557 | testType: serverTest, |
| 4558 | name: "TicketCallback-SingleCall-" + ver.name, |
| 4559 | config: Config{ |
| 4560 | MaxVersion: ver.version, |
| 4561 | Bugs: ProtocolBugs{ |
| 4562 | CorruptTicket: true, |
| 4563 | }, |
| 4564 | }, |
| 4565 | resumeSession: true, |
| 4566 | expectResumeRejected: true, |
| 4567 | flags: []string{ |
| 4568 | "-use-ticket-callback", |
| 4569 | "-async", |
| 4570 | }, |
| 4571 | }) |
| 4572 | |
| 4573 | // Resume with an oversized session id. |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4574 | if ver.version < VersionTLS13 { |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4575 | testCases = append(testCases, testCase{ |
| 4576 | testType: serverTest, |
| 4577 | name: "OversizedSessionId-" + ver.name, |
| 4578 | config: Config{ |
| 4579 | MaxVersion: ver.version, |
| 4580 | Bugs: ProtocolBugs{ |
| 4581 | OversizedSessionId: true, |
| 4582 | }, |
| 4583 | }, |
| 4584 | resumeSession: true, |
| 4585 | shouldFail: true, |
| 4586 | expectedError: ":DECODE_ERROR:", |
| 4587 | }) |
| 4588 | } |
| 4589 | |
| 4590 | // Basic DTLS-SRTP tests. Include fake profiles to ensure they |
| 4591 | // are ignored. |
| 4592 | if ver.hasDTLS { |
| 4593 | testCases = append(testCases, testCase{ |
| 4594 | protocol: dtls, |
| 4595 | name: "SRTP-Client-" + ver.name, |
| 4596 | config: Config{ |
| 4597 | MaxVersion: ver.version, |
| 4598 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4599 | }, |
| 4600 | flags: []string{ |
| 4601 | "-srtp-profiles", |
| 4602 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4603 | }, |
| 4604 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4605 | }) |
| 4606 | testCases = append(testCases, testCase{ |
| 4607 | protocol: dtls, |
| 4608 | testType: serverTest, |
| 4609 | name: "SRTP-Server-" + ver.name, |
| 4610 | config: Config{ |
| 4611 | MaxVersion: ver.version, |
| 4612 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4613 | }, |
| 4614 | flags: []string{ |
| 4615 | "-srtp-profiles", |
| 4616 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4617 | }, |
| 4618 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4619 | }) |
| 4620 | // Test that the MKI is ignored. |
| 4621 | testCases = append(testCases, testCase{ |
| 4622 | protocol: dtls, |
| 4623 | testType: serverTest, |
| 4624 | name: "SRTP-Server-IgnoreMKI-" + ver.name, |
| 4625 | config: Config{ |
| 4626 | MaxVersion: ver.version, |
| 4627 | SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80}, |
| 4628 | Bugs: ProtocolBugs{ |
| 4629 | SRTPMasterKeyIdentifer: "bogus", |
| 4630 | }, |
| 4631 | }, |
| 4632 | flags: []string{ |
| 4633 | "-srtp-profiles", |
| 4634 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4635 | }, |
| 4636 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4637 | }) |
| 4638 | // Test that SRTP isn't negotiated on the server if there were |
| 4639 | // no matching profiles. |
| 4640 | testCases = append(testCases, testCase{ |
| 4641 | protocol: dtls, |
| 4642 | testType: serverTest, |
| 4643 | name: "SRTP-Server-NoMatch-" + ver.name, |
| 4644 | config: Config{ |
| 4645 | MaxVersion: ver.version, |
| 4646 | SRTPProtectionProfiles: []uint16{100, 101, 102}, |
| 4647 | }, |
| 4648 | flags: []string{ |
| 4649 | "-srtp-profiles", |
| 4650 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4651 | }, |
| 4652 | expectedSRTPProtectionProfile: 0, |
| 4653 | }) |
| 4654 | // Test that the server returning an invalid SRTP profile is |
| 4655 | // flagged as an error by the client. |
| 4656 | testCases = append(testCases, testCase{ |
| 4657 | protocol: dtls, |
| 4658 | name: "SRTP-Client-NoMatch-" + ver.name, |
| 4659 | config: Config{ |
| 4660 | MaxVersion: ver.version, |
| 4661 | Bugs: ProtocolBugs{ |
| 4662 | SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32, |
| 4663 | }, |
| 4664 | }, |
| 4665 | flags: []string{ |
| 4666 | "-srtp-profiles", |
| 4667 | "SRTP_AES128_CM_SHA1_80", |
| 4668 | }, |
| 4669 | shouldFail: true, |
| 4670 | expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:", |
| 4671 | }) |
| 4672 | } |
| 4673 | |
| 4674 | // Test SCT list. |
| 4675 | testCases = append(testCases, testCase{ |
| 4676 | name: "SignedCertificateTimestampList-Client-" + ver.name, |
| 4677 | testType: clientTest, |
| 4678 | config: Config{ |
| 4679 | MaxVersion: ver.version, |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 4680 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4681 | flags: []string{ |
| 4682 | "-enable-signed-cert-timestamps", |
| 4683 | "-expect-signed-cert-timestamps", |
| 4684 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 4685 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4686 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4687 | }) |
| 4688 | testCases = append(testCases, testCase{ |
| 4689 | name: "SendSCTListOnResume-" + ver.name, |
| 4690 | config: Config{ |
| 4691 | MaxVersion: ver.version, |
| 4692 | Bugs: ProtocolBugs{ |
| 4693 | SendSCTListOnResume: []byte("bogus"), |
| 4694 | }, |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 4695 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4696 | flags: []string{ |
| 4697 | "-enable-signed-cert-timestamps", |
| 4698 | "-expect-signed-cert-timestamps", |
| 4699 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 4700 | }, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4701 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4702 | }) |
| 4703 | testCases = append(testCases, testCase{ |
| 4704 | name: "SignedCertificateTimestampList-Server-" + ver.name, |
| 4705 | testType: serverTest, |
| 4706 | config: Config{ |
| 4707 | MaxVersion: ver.version, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4708 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4709 | flags: []string{ |
| 4710 | "-signed-cert-timestamps", |
| 4711 | base64.StdEncoding.EncodeToString(testSCTList), |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4712 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4713 | expectedSCTList: testSCTList, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4714 | resumeSession: true, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4715 | }) |
| 4716 | } |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4717 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 4718 | testCases = append(testCases, testCase{ |
Adam Langley | 33ad2b5 | 2015-07-20 17:43:53 -0700 | [diff] [blame] | 4719 | testType: clientTest, |
| 4720 | name: "ClientHelloPadding", |
| 4721 | config: Config{ |
| 4722 | Bugs: ProtocolBugs{ |
| 4723 | RequireClientHelloSize: 512, |
| 4724 | }, |
| 4725 | }, |
| 4726 | // This hostname just needs to be long enough to push the |
| 4727 | // ClientHello into F5's danger zone between 256 and 511 bytes |
| 4728 | // long. |
| 4729 | flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"}, |
| 4730 | }) |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 4731 | |
| 4732 | // Extensions should not function in SSL 3.0. |
| 4733 | testCases = append(testCases, testCase{ |
| 4734 | testType: serverTest, |
| 4735 | name: "SSLv3Extensions-NoALPN", |
| 4736 | config: Config{ |
| 4737 | MaxVersion: VersionSSL30, |
| 4738 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4739 | }, |
| 4740 | flags: []string{ |
| 4741 | "-select-alpn", "foo", |
| 4742 | }, |
| 4743 | expectNoNextProto: true, |
| 4744 | }) |
| 4745 | |
| 4746 | // Test session tickets separately as they follow a different codepath. |
| 4747 | testCases = append(testCases, testCase{ |
| 4748 | testType: serverTest, |
| 4749 | name: "SSLv3Extensions-NoTickets", |
| 4750 | config: Config{ |
| 4751 | MaxVersion: VersionSSL30, |
| 4752 | Bugs: ProtocolBugs{ |
| 4753 | // Historically, session tickets in SSL 3.0 |
| 4754 | // failed in different ways depending on whether |
| 4755 | // the client supported renegotiation_info. |
| 4756 | NoRenegotiationInfo: true, |
| 4757 | }, |
| 4758 | }, |
| 4759 | resumeSession: true, |
| 4760 | }) |
| 4761 | testCases = append(testCases, testCase{ |
| 4762 | testType: serverTest, |
| 4763 | name: "SSLv3Extensions-NoTickets2", |
| 4764 | config: Config{ |
| 4765 | MaxVersion: VersionSSL30, |
| 4766 | }, |
| 4767 | resumeSession: true, |
| 4768 | }) |
| 4769 | |
| 4770 | // But SSL 3.0 does send and process renegotiation_info. |
| 4771 | testCases = append(testCases, testCase{ |
| 4772 | testType: serverTest, |
| 4773 | name: "SSLv3Extensions-RenegotiationInfo", |
| 4774 | config: Config{ |
| 4775 | MaxVersion: VersionSSL30, |
| 4776 | Bugs: ProtocolBugs{ |
| 4777 | RequireRenegotiationInfo: true, |
| 4778 | }, |
| 4779 | }, |
| 4780 | }) |
| 4781 | testCases = append(testCases, testCase{ |
| 4782 | testType: serverTest, |
| 4783 | name: "SSLv3Extensions-RenegotiationInfo-SCSV", |
| 4784 | config: Config{ |
| 4785 | MaxVersion: VersionSSL30, |
| 4786 | Bugs: ProtocolBugs{ |
| 4787 | NoRenegotiationInfo: true, |
| 4788 | SendRenegotiationSCSV: true, |
| 4789 | RequireRenegotiationInfo: true, |
| 4790 | }, |
| 4791 | }, |
| 4792 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 4793 | |
| 4794 | // Test that illegal extensions in TLS 1.3 are rejected by the client if |
| 4795 | // in ServerHello. |
| 4796 | testCases = append(testCases, testCase{ |
| 4797 | name: "NPN-Forbidden-TLS13", |
| 4798 | config: Config{ |
| 4799 | MaxVersion: VersionTLS13, |
| 4800 | NextProtos: []string{"foo"}, |
| 4801 | Bugs: ProtocolBugs{ |
| 4802 | NegotiateNPNAtAllVersions: true, |
| 4803 | }, |
| 4804 | }, |
| 4805 | flags: []string{"-select-next-proto", "foo"}, |
| 4806 | shouldFail: true, |
| 4807 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4808 | }) |
| 4809 | testCases = append(testCases, testCase{ |
| 4810 | name: "EMS-Forbidden-TLS13", |
| 4811 | config: Config{ |
| 4812 | MaxVersion: VersionTLS13, |
| 4813 | Bugs: ProtocolBugs{ |
| 4814 | NegotiateEMSAtAllVersions: true, |
| 4815 | }, |
| 4816 | }, |
| 4817 | shouldFail: true, |
| 4818 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4819 | }) |
| 4820 | testCases = append(testCases, testCase{ |
| 4821 | name: "RenegotiationInfo-Forbidden-TLS13", |
| 4822 | config: Config{ |
| 4823 | MaxVersion: VersionTLS13, |
| 4824 | Bugs: ProtocolBugs{ |
| 4825 | NegotiateRenegotiationInfoAtAllVersions: true, |
| 4826 | }, |
| 4827 | }, |
| 4828 | shouldFail: true, |
| 4829 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4830 | }) |
| 4831 | testCases = append(testCases, testCase{ |
| 4832 | name: "ChannelID-Forbidden-TLS13", |
| 4833 | config: Config{ |
| 4834 | MaxVersion: VersionTLS13, |
| 4835 | RequestChannelID: true, |
| 4836 | Bugs: ProtocolBugs{ |
| 4837 | NegotiateChannelIDAtAllVersions: true, |
| 4838 | }, |
| 4839 | }, |
| 4840 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
| 4841 | shouldFail: true, |
| 4842 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4843 | }) |
| 4844 | testCases = append(testCases, testCase{ |
| 4845 | name: "Ticket-Forbidden-TLS13", |
| 4846 | config: Config{ |
| 4847 | MaxVersion: VersionTLS12, |
| 4848 | }, |
| 4849 | resumeConfig: &Config{ |
| 4850 | MaxVersion: VersionTLS13, |
| 4851 | Bugs: ProtocolBugs{ |
| 4852 | AdvertiseTicketExtension: true, |
| 4853 | }, |
| 4854 | }, |
| 4855 | resumeSession: true, |
| 4856 | shouldFail: true, |
| 4857 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4858 | }) |
| 4859 | |
| 4860 | // Test that illegal extensions in TLS 1.3 are declined by the server if |
| 4861 | // offered in ClientHello. The runner's server will fail if this occurs, |
| 4862 | // so we exercise the offering path. (EMS and Renegotiation Info are |
| 4863 | // implicit in every test.) |
| 4864 | testCases = append(testCases, testCase{ |
| 4865 | testType: serverTest, |
| 4866 | name: "ChannelID-Declined-TLS13", |
| 4867 | config: Config{ |
| 4868 | MaxVersion: VersionTLS13, |
| 4869 | ChannelID: channelIDKey, |
| 4870 | }, |
| 4871 | flags: []string{"-enable-channel-id"}, |
| 4872 | }) |
| 4873 | testCases = append(testCases, testCase{ |
| 4874 | testType: serverTest, |
| 4875 | name: "NPN-Server", |
| 4876 | config: Config{ |
| 4877 | MaxVersion: VersionTLS13, |
| 4878 | NextProtos: []string{"bar"}, |
| 4879 | }, |
| 4880 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 4881 | }) |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4882 | } |
| 4883 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4884 | func addResumptionVersionTests() { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4885 | for _, sessionVers := range tlsVersions { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4886 | for _, resumeVers := range tlsVersions { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4887 | cipher := TLS_RSA_WITH_AES_128_CBC_SHA |
| 4888 | if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 { |
| 4889 | // TLS 1.3 only shares ciphers with TLS 1.2, so |
| 4890 | // we skip certain combinations and use a |
| 4891 | // different cipher to test with. |
| 4892 | cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
| 4893 | if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 { |
| 4894 | continue |
| 4895 | } |
| 4896 | } |
| 4897 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4898 | protocols := []protocol{tls} |
| 4899 | if sessionVers.hasDTLS && resumeVers.hasDTLS { |
| 4900 | protocols = append(protocols, dtls) |
David Benjamin | bdf5e72 | 2014-11-11 00:52:15 -0500 | [diff] [blame] | 4901 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4902 | for _, protocol := range protocols { |
| 4903 | suffix := "-" + sessionVers.name + "-" + resumeVers.name |
| 4904 | if protocol == dtls { |
| 4905 | suffix += "-DTLS" |
| 4906 | } |
| 4907 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4908 | if sessionVers.version == resumeVers.version { |
| 4909 | testCases = append(testCases, testCase{ |
| 4910 | protocol: protocol, |
| 4911 | name: "Resume-Client" + suffix, |
| 4912 | resumeSession: true, |
| 4913 | config: Config{ |
| 4914 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4915 | CipherSuites: []uint16{cipher}, |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 4916 | Bugs: ProtocolBugs{ |
| 4917 | ExpectNoTLS12Session: sessionVers.version >= VersionTLS13, |
| 4918 | ExpectNoTLS13PSK: sessionVers.version < VersionTLS13, |
| 4919 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4920 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4921 | expectedVersion: sessionVers.version, |
| 4922 | expectedResumeVersion: resumeVers.version, |
| 4923 | }) |
| 4924 | } else { |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 4925 | error := ":OLD_SESSION_VERSION_NOT_RETURNED:" |
| 4926 | |
| 4927 | // Offering a TLS 1.3 session sends an empty session ID, so |
| 4928 | // there is no way to convince a non-lookahead client the |
| 4929 | // session was resumed. It will appear to the client that a |
| 4930 | // stray ChangeCipherSpec was sent. |
| 4931 | if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 { |
| 4932 | error = ":UNEXPECTED_RECORD:" |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4933 | } |
| 4934 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4935 | testCases = append(testCases, testCase{ |
| 4936 | protocol: protocol, |
| 4937 | name: "Resume-Client-Mismatch" + suffix, |
| 4938 | resumeSession: true, |
| 4939 | config: Config{ |
| 4940 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4941 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4942 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4943 | expectedVersion: sessionVers.version, |
| 4944 | resumeConfig: &Config{ |
| 4945 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4946 | CipherSuites: []uint16{cipher}, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4947 | Bugs: ProtocolBugs{ |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 4948 | AcceptAnySession: true, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4949 | }, |
| 4950 | }, |
| 4951 | expectedResumeVersion: resumeVers.version, |
| 4952 | shouldFail: true, |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 4953 | expectedError: error, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4954 | }) |
| 4955 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4956 | |
| 4957 | testCases = append(testCases, testCase{ |
| 4958 | protocol: protocol, |
| 4959 | name: "Resume-Client-NoResume" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4960 | resumeSession: true, |
| 4961 | config: Config{ |
| 4962 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4963 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4964 | }, |
| 4965 | expectedVersion: sessionVers.version, |
| 4966 | resumeConfig: &Config{ |
| 4967 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4968 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4969 | }, |
| 4970 | newSessionsOnResume: true, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 4971 | expectResumeRejected: true, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4972 | expectedResumeVersion: resumeVers.version, |
| 4973 | }) |
| 4974 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4975 | testCases = append(testCases, testCase{ |
| 4976 | protocol: protocol, |
| 4977 | testType: serverTest, |
| 4978 | name: "Resume-Server" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4979 | resumeSession: true, |
| 4980 | config: Config{ |
| 4981 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4982 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4983 | }, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 4984 | expectedVersion: sessionVers.version, |
| 4985 | expectResumeRejected: sessionVers.version != resumeVers.version, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4986 | resumeConfig: &Config{ |
| 4987 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4988 | CipherSuites: []uint16{cipher}, |
David Benjamin | 405da48 | 2016-08-08 17:25:07 -0400 | [diff] [blame] | 4989 | Bugs: ProtocolBugs{ |
| 4990 | SendBothTickets: true, |
| 4991 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4992 | }, |
| 4993 | expectedResumeVersion: resumeVers.version, |
| 4994 | }) |
| 4995 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4996 | } |
| 4997 | } |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4998 | |
| 4999 | testCases = append(testCases, testCase{ |
| 5000 | name: "Resume-Client-CipherMismatch", |
| 5001 | resumeSession: true, |
| 5002 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5003 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5004 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 5005 | }, |
| 5006 | resumeConfig: &Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5007 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 5008 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 5009 | Bugs: ProtocolBugs{ |
| 5010 | SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 5011 | }, |
| 5012 | }, |
| 5013 | shouldFail: true, |
| 5014 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 5015 | }) |
Steven Valdez | 4aa154e | 2016-07-29 14:32:55 -0400 | [diff] [blame] | 5016 | |
| 5017 | testCases = append(testCases, testCase{ |
| 5018 | name: "Resume-Client-CipherMismatch-TLS13", |
| 5019 | resumeSession: true, |
| 5020 | config: Config{ |
| 5021 | MaxVersion: VersionTLS13, |
| 5022 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5023 | }, |
| 5024 | resumeConfig: &Config{ |
| 5025 | MaxVersion: VersionTLS13, |
| 5026 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5027 | Bugs: ProtocolBugs{ |
| 5028 | SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, |
| 5029 | }, |
| 5030 | }, |
| 5031 | shouldFail: true, |
| 5032 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 5033 | }) |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 5034 | } |
| 5035 | |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 5036 | func addRenegotiationTests() { |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 5037 | // Servers cannot renegotiate. |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5038 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5039 | testType: serverTest, |
| 5040 | name: "Renegotiate-Server-Forbidden", |
| 5041 | config: Config{ |
| 5042 | MaxVersion: VersionTLS12, |
| 5043 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5044 | renegotiate: 1, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5045 | shouldFail: true, |
| 5046 | expectedError: ":NO_RENEGOTIATION:", |
| 5047 | expectedLocalError: "remote error: no renegotiation", |
| 5048 | }) |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5049 | // The server shouldn't echo the renegotiation extension unless |
| 5050 | // requested by the client. |
| 5051 | testCases = append(testCases, testCase{ |
| 5052 | testType: serverTest, |
| 5053 | name: "Renegotiate-Server-NoExt", |
| 5054 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5055 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5056 | Bugs: ProtocolBugs{ |
| 5057 | NoRenegotiationInfo: true, |
| 5058 | RequireRenegotiationInfo: true, |
| 5059 | }, |
| 5060 | }, |
| 5061 | shouldFail: true, |
| 5062 | expectedLocalError: "renegotiation extension missing", |
| 5063 | }) |
| 5064 | // The renegotiation SCSV should be sufficient for the server to echo |
| 5065 | // the extension. |
| 5066 | testCases = append(testCases, testCase{ |
| 5067 | testType: serverTest, |
| 5068 | name: "Renegotiate-Server-NoExt-SCSV", |
| 5069 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5070 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 5071 | Bugs: ProtocolBugs{ |
| 5072 | NoRenegotiationInfo: true, |
| 5073 | SendRenegotiationSCSV: true, |
| 5074 | RequireRenegotiationInfo: true, |
| 5075 | }, |
| 5076 | }, |
| 5077 | }) |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5078 | testCases = append(testCases, testCase{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 5079 | name: "Renegotiate-Client", |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5080 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5081 | MaxVersion: VersionTLS12, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5082 | Bugs: ProtocolBugs{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 5083 | FailIfResumeOnRenego: true, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5084 | }, |
| 5085 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5086 | renegotiate: 1, |
| 5087 | flags: []string{ |
| 5088 | "-renegotiate-freely", |
| 5089 | "-expect-total-renegotiations", "1", |
| 5090 | }, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 5091 | }) |
| 5092 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5093 | name: "Renegotiate-Client-EmptyExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5094 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5095 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5096 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5097 | Bugs: ProtocolBugs{ |
| 5098 | EmptyRenegotiationInfo: true, |
| 5099 | }, |
| 5100 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5101 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5102 | shouldFail: true, |
| 5103 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5104 | }) |
| 5105 | testCases = append(testCases, testCase{ |
| 5106 | name: "Renegotiate-Client-BadExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5107 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5108 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5109 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5110 | Bugs: ProtocolBugs{ |
| 5111 | BadRenegotiationInfo: true, |
| 5112 | }, |
| 5113 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5114 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5115 | shouldFail: true, |
| 5116 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5117 | }) |
| 5118 | testCases = append(testCases, testCase{ |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5119 | name: "Renegotiate-Client-Downgrade", |
| 5120 | renegotiate: 1, |
| 5121 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5122 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5123 | Bugs: ProtocolBugs{ |
| 5124 | NoRenegotiationInfoAfterInitial: true, |
| 5125 | }, |
| 5126 | }, |
| 5127 | flags: []string{"-renegotiate-freely"}, |
| 5128 | shouldFail: true, |
| 5129 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5130 | }) |
| 5131 | testCases = append(testCases, testCase{ |
| 5132 | name: "Renegotiate-Client-Upgrade", |
| 5133 | renegotiate: 1, |
| 5134 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5135 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 5136 | Bugs: ProtocolBugs{ |
| 5137 | NoRenegotiationInfoInInitial: true, |
| 5138 | }, |
| 5139 | }, |
| 5140 | flags: []string{"-renegotiate-freely"}, |
| 5141 | shouldFail: true, |
| 5142 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 5143 | }) |
| 5144 | testCases = append(testCases, testCase{ |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5145 | name: "Renegotiate-Client-NoExt-Allowed", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5146 | renegotiate: 1, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5147 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5148 | MaxVersion: VersionTLS12, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5149 | Bugs: ProtocolBugs{ |
| 5150 | NoRenegotiationInfo: true, |
| 5151 | }, |
| 5152 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5153 | flags: []string{ |
| 5154 | "-renegotiate-freely", |
| 5155 | "-expect-total-renegotiations", "1", |
| 5156 | }, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5157 | }) |
David Benjamin | e7e36aa | 2016-08-08 12:39:41 -0400 | [diff] [blame] | 5158 | |
| 5159 | // Test that the server may switch ciphers on renegotiation without |
| 5160 | // problems. |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 5161 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5162 | name: "Renegotiate-Client-SwitchCiphers", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5163 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5164 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5165 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5166 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 5167 | }, |
| 5168 | renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5169 | flags: []string{ |
| 5170 | "-renegotiate-freely", |
| 5171 | "-expect-total-renegotiations", "1", |
| 5172 | }, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5173 | }) |
| 5174 | testCases = append(testCases, testCase{ |
| 5175 | name: "Renegotiate-Client-SwitchCiphers2", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5176 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5177 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5178 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5179 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5180 | }, |
| 5181 | renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5182 | flags: []string{ |
| 5183 | "-renegotiate-freely", |
| 5184 | "-expect-total-renegotiations", "1", |
| 5185 | }, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5186 | }) |
David Benjamin | e7e36aa | 2016-08-08 12:39:41 -0400 | [diff] [blame] | 5187 | |
| 5188 | // Test that the server may not switch versions on renegotiation. |
| 5189 | testCases = append(testCases, testCase{ |
| 5190 | name: "Renegotiate-Client-SwitchVersion", |
| 5191 | config: Config{ |
| 5192 | MaxVersion: VersionTLS12, |
| 5193 | // Pick a cipher which exists at both versions. |
| 5194 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 5195 | Bugs: ProtocolBugs{ |
| 5196 | NegotiateVersionOnRenego: VersionTLS11, |
| 5197 | }, |
| 5198 | }, |
| 5199 | renegotiate: 1, |
| 5200 | flags: []string{ |
| 5201 | "-renegotiate-freely", |
| 5202 | "-expect-total-renegotiations", "1", |
| 5203 | }, |
| 5204 | shouldFail: true, |
| 5205 | expectedError: ":WRONG_SSL_VERSION:", |
| 5206 | }) |
| 5207 | |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5208 | testCases = append(testCases, testCase{ |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5209 | name: "Renegotiate-SameClientVersion", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5210 | renegotiate: 1, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5211 | config: Config{ |
| 5212 | MaxVersion: VersionTLS10, |
| 5213 | Bugs: ProtocolBugs{ |
| 5214 | RequireSameRenegoClientVersion: true, |
| 5215 | }, |
| 5216 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5217 | flags: []string{ |
| 5218 | "-renegotiate-freely", |
| 5219 | "-expect-total-renegotiations", "1", |
| 5220 | }, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5221 | }) |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5222 | testCases = append(testCases, testCase{ |
| 5223 | name: "Renegotiate-FalseStart", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5224 | renegotiate: 1, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5225 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5226 | MaxVersion: VersionTLS12, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5227 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5228 | NextProtos: []string{"foo"}, |
| 5229 | }, |
| 5230 | flags: []string{ |
| 5231 | "-false-start", |
| 5232 | "-select-next-proto", "foo", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5233 | "-renegotiate-freely", |
David Benjamin | 324dce4 | 2015-10-12 19:49:00 -0400 | [diff] [blame] | 5234 | "-expect-total-renegotiations", "1", |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5235 | }, |
| 5236 | shimWritesFirst: true, |
| 5237 | }) |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5238 | |
| 5239 | // Client-side renegotiation controls. |
| 5240 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5241 | name: "Renegotiate-Client-Forbidden-1", |
| 5242 | config: Config{ |
| 5243 | MaxVersion: VersionTLS12, |
| 5244 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5245 | renegotiate: 1, |
| 5246 | shouldFail: true, |
| 5247 | expectedError: ":NO_RENEGOTIATION:", |
| 5248 | expectedLocalError: "remote error: no renegotiation", |
| 5249 | }) |
| 5250 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5251 | name: "Renegotiate-Client-Once-1", |
| 5252 | config: Config{ |
| 5253 | MaxVersion: VersionTLS12, |
| 5254 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5255 | renegotiate: 1, |
| 5256 | flags: []string{ |
| 5257 | "-renegotiate-once", |
| 5258 | "-expect-total-renegotiations", "1", |
| 5259 | }, |
| 5260 | }) |
| 5261 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5262 | name: "Renegotiate-Client-Freely-1", |
| 5263 | config: Config{ |
| 5264 | MaxVersion: VersionTLS12, |
| 5265 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5266 | renegotiate: 1, |
| 5267 | flags: []string{ |
| 5268 | "-renegotiate-freely", |
| 5269 | "-expect-total-renegotiations", "1", |
| 5270 | }, |
| 5271 | }) |
| 5272 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5273 | name: "Renegotiate-Client-Once-2", |
| 5274 | config: Config{ |
| 5275 | MaxVersion: VersionTLS12, |
| 5276 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5277 | renegotiate: 2, |
| 5278 | flags: []string{"-renegotiate-once"}, |
| 5279 | shouldFail: true, |
| 5280 | expectedError: ":NO_RENEGOTIATION:", |
| 5281 | expectedLocalError: "remote error: no renegotiation", |
| 5282 | }) |
| 5283 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5284 | name: "Renegotiate-Client-Freely-2", |
| 5285 | config: Config{ |
| 5286 | MaxVersion: VersionTLS12, |
| 5287 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5288 | renegotiate: 2, |
| 5289 | flags: []string{ |
| 5290 | "-renegotiate-freely", |
| 5291 | "-expect-total-renegotiations", "2", |
| 5292 | }, |
| 5293 | }) |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5294 | testCases = append(testCases, testCase{ |
| 5295 | name: "Renegotiate-Client-NoIgnore", |
| 5296 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5297 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5298 | Bugs: ProtocolBugs{ |
| 5299 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5300 | }, |
| 5301 | }, |
| 5302 | shouldFail: true, |
| 5303 | expectedError: ":NO_RENEGOTIATION:", |
| 5304 | }) |
| 5305 | testCases = append(testCases, testCase{ |
| 5306 | name: "Renegotiate-Client-Ignore", |
| 5307 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5308 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5309 | Bugs: ProtocolBugs{ |
| 5310 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5311 | }, |
| 5312 | }, |
| 5313 | flags: []string{ |
| 5314 | "-renegotiate-ignore", |
| 5315 | "-expect-total-renegotiations", "0", |
| 5316 | }, |
| 5317 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5318 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5319 | // Stray HelloRequests during the handshake are ignored in TLS 1.2. |
David Benjamin | 71dd666 | 2016-07-08 14:10:48 -0700 | [diff] [blame] | 5320 | testCases = append(testCases, testCase{ |
| 5321 | name: "StrayHelloRequest", |
| 5322 | config: Config{ |
| 5323 | MaxVersion: VersionTLS12, |
| 5324 | Bugs: ProtocolBugs{ |
| 5325 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5326 | }, |
| 5327 | }, |
| 5328 | }) |
| 5329 | testCases = append(testCases, testCase{ |
| 5330 | name: "StrayHelloRequest-Packed", |
| 5331 | config: Config{ |
| 5332 | MaxVersion: VersionTLS12, |
| 5333 | Bugs: ProtocolBugs{ |
| 5334 | PackHandshakeFlight: true, |
| 5335 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5336 | }, |
| 5337 | }, |
| 5338 | }) |
| 5339 | |
David Benjamin | 12d2c48 | 2016-07-24 10:56:51 -0400 | [diff] [blame] | 5340 | // Test renegotiation works if HelloRequest and server Finished come in |
| 5341 | // the same record. |
| 5342 | testCases = append(testCases, testCase{ |
| 5343 | name: "Renegotiate-Client-Packed", |
| 5344 | config: Config{ |
| 5345 | MaxVersion: VersionTLS12, |
| 5346 | Bugs: ProtocolBugs{ |
| 5347 | PackHandshakeFlight: true, |
| 5348 | PackHelloRequestWithFinished: true, |
| 5349 | }, |
| 5350 | }, |
| 5351 | renegotiate: 1, |
| 5352 | flags: []string{ |
| 5353 | "-renegotiate-freely", |
| 5354 | "-expect-total-renegotiations", "1", |
| 5355 | }, |
| 5356 | }) |
| 5357 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5358 | // Renegotiation is forbidden in TLS 1.3. |
| 5359 | testCases = append(testCases, testCase{ |
| 5360 | name: "Renegotiate-Client-TLS13", |
| 5361 | config: Config{ |
| 5362 | MaxVersion: VersionTLS13, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5363 | Bugs: ProtocolBugs{ |
| 5364 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5365 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5366 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5367 | flags: []string{ |
| 5368 | "-renegotiate-freely", |
| 5369 | }, |
Steven Valdez | 8e1c7be | 2016-07-26 12:39:22 -0400 | [diff] [blame] | 5370 | shouldFail: true, |
| 5371 | expectedError: ":UNEXPECTED_MESSAGE:", |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5372 | }) |
| 5373 | |
| 5374 | // Stray HelloRequests during the handshake are forbidden in TLS 1.3. |
| 5375 | testCases = append(testCases, testCase{ |
| 5376 | name: "StrayHelloRequest-TLS13", |
| 5377 | config: Config{ |
| 5378 | MaxVersion: VersionTLS13, |
| 5379 | Bugs: ProtocolBugs{ |
| 5380 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5381 | }, |
| 5382 | }, |
| 5383 | shouldFail: true, |
| 5384 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 5385 | }) |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 5386 | } |
| 5387 | |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5388 | func addDTLSReplayTests() { |
| 5389 | // Test that sequence number replays are detected. |
| 5390 | testCases = append(testCases, testCase{ |
| 5391 | protocol: dtls, |
| 5392 | name: "DTLS-Replay", |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5393 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5394 | replayWrites: true, |
| 5395 | }) |
| 5396 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5397 | // Test the incoming sequence number skipping by values larger |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5398 | // than the retransmit window. |
| 5399 | testCases = append(testCases, testCase{ |
| 5400 | protocol: dtls, |
| 5401 | name: "DTLS-Replay-LargeGaps", |
| 5402 | config: Config{ |
| 5403 | Bugs: ProtocolBugs{ |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5404 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5405 | return in * 127 |
| 5406 | }, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5407 | }, |
| 5408 | }, |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5409 | messageCount: 200, |
| 5410 | replayWrites: true, |
| 5411 | }) |
| 5412 | |
| 5413 | // Test the incoming sequence number changing non-monotonically. |
| 5414 | testCases = append(testCases, testCase{ |
| 5415 | protocol: dtls, |
| 5416 | name: "DTLS-Replay-NonMonotonic", |
| 5417 | config: Config{ |
| 5418 | Bugs: ProtocolBugs{ |
| 5419 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5420 | return in ^ 31 |
| 5421 | }, |
| 5422 | }, |
| 5423 | }, |
| 5424 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5425 | replayWrites: true, |
| 5426 | }) |
| 5427 | } |
| 5428 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5429 | var testSignatureAlgorithms = []struct { |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5430 | name string |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5431 | id signatureAlgorithm |
| 5432 | cert testCert |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5433 | }{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5434 | {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA}, |
| 5435 | {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA}, |
| 5436 | {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA}, |
| 5437 | {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5438 | {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5439 | {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256}, |
| 5440 | {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384}, |
| 5441 | {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521}, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5442 | {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA}, |
| 5443 | {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA}, |
| 5444 | {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5445 | // Tests for key types prior to TLS 1.2. |
| 5446 | {"RSA", 0, testCertRSA}, |
| 5447 | {"ECDSA", 0, testCertECDSAP256}, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5448 | } |
| 5449 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5450 | const fakeSigAlg1 signatureAlgorithm = 0x2a01 |
| 5451 | const fakeSigAlg2 signatureAlgorithm = 0xff01 |
| 5452 | |
| 5453 | func addSignatureAlgorithmTests() { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5454 | // Not all ciphers involve a signature. Advertise a list which gives all |
| 5455 | // versions a signing cipher. |
| 5456 | signingCiphers := []uint16{ |
| 5457 | TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 5458 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 5459 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 5460 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 5461 | TLS_DHE_RSA_WITH_AES_128_CBC_SHA, |
| 5462 | } |
| 5463 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5464 | var allAlgorithms []signatureAlgorithm |
| 5465 | for _, alg := range testSignatureAlgorithms { |
| 5466 | if alg.id != 0 { |
| 5467 | allAlgorithms = append(allAlgorithms, alg.id) |
| 5468 | } |
| 5469 | } |
| 5470 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5471 | // Make sure each signature algorithm works. Include some fake values in |
| 5472 | // the list and ensure they're ignored. |
| 5473 | for _, alg := range testSignatureAlgorithms { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5474 | for _, ver := range tlsVersions { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5475 | if (ver.version < VersionTLS12) != (alg.id == 0) { |
| 5476 | continue |
| 5477 | } |
| 5478 | |
| 5479 | // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing |
| 5480 | // or remove it in C. |
| 5481 | if ver.version == VersionSSL30 && alg.cert != testCertRSA { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5482 | continue |
| 5483 | } |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5484 | |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5485 | var shouldFail bool |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5486 | // ecdsa_sha1 does not exist in TLS 1.3. |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5487 | if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 { |
| 5488 | shouldFail = true |
| 5489 | } |
| 5490 | // RSA-PSS does not exist in TLS 1.2. |
| 5491 | if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") { |
| 5492 | shouldFail = true |
| 5493 | } |
| 5494 | |
| 5495 | var signError, verifyError string |
| 5496 | if shouldFail { |
| 5497 | signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:" |
| 5498 | verifyError = ":WRONG_SIGNATURE_TYPE:" |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5499 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5500 | |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5501 | suffix := "-" + alg.name + "-" + ver.name |
David Benjamin | 6e80765 | 2015-11-02 12:02:20 -0500 | [diff] [blame] | 5502 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5503 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5504 | name: "ClientAuth-Sign" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5505 | config: Config{ |
| 5506 | MaxVersion: ver.version, |
| 5507 | ClientAuth: RequireAnyClientCert, |
| 5508 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5509 | fakeSigAlg1, |
| 5510 | alg.id, |
| 5511 | fakeSigAlg2, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5512 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5513 | }, |
| 5514 | flags: []string{ |
| 5515 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5516 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5517 | "-enable-all-curves", |
| 5518 | }, |
| 5519 | shouldFail: shouldFail, |
| 5520 | expectedError: signError, |
| 5521 | expectedPeerSignatureAlgorithm: alg.id, |
| 5522 | }) |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5523 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5524 | testCases = append(testCases, testCase{ |
| 5525 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5526 | name: "ClientAuth-Verify" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5527 | config: Config{ |
| 5528 | MaxVersion: ver.version, |
| 5529 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5530 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5531 | alg.id, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5532 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5533 | Bugs: ProtocolBugs{ |
| 5534 | SkipECDSACurveCheck: shouldFail, |
| 5535 | IgnoreSignatureVersionChecks: shouldFail, |
| 5536 | // The client won't advertise 1.3-only algorithms after |
| 5537 | // version negotiation. |
| 5538 | IgnorePeerSignatureAlgorithmPreferences: shouldFail, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5539 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5540 | }, |
| 5541 | flags: []string{ |
| 5542 | "-require-any-client-certificate", |
| 5543 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5544 | "-enable-all-curves", |
| 5545 | }, |
| 5546 | shouldFail: shouldFail, |
| 5547 | expectedError: verifyError, |
| 5548 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5549 | |
| 5550 | testCases = append(testCases, testCase{ |
| 5551 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5552 | name: "ServerAuth-Sign" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5553 | config: Config{ |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5554 | MaxVersion: ver.version, |
| 5555 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5556 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5557 | fakeSigAlg1, |
| 5558 | alg.id, |
| 5559 | fakeSigAlg2, |
| 5560 | }, |
| 5561 | }, |
| 5562 | flags: []string{ |
| 5563 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5564 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5565 | "-enable-all-curves", |
| 5566 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5567 | shouldFail: shouldFail, |
| 5568 | expectedError: signError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5569 | expectedPeerSignatureAlgorithm: alg.id, |
| 5570 | }) |
| 5571 | |
| 5572 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5573 | name: "ServerAuth-Verify" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5574 | config: Config{ |
| 5575 | MaxVersion: ver.version, |
| 5576 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5577 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5578 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5579 | alg.id, |
| 5580 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5581 | Bugs: ProtocolBugs{ |
| 5582 | SkipECDSACurveCheck: shouldFail, |
| 5583 | IgnoreSignatureVersionChecks: shouldFail, |
| 5584 | }, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5585 | }, |
| 5586 | flags: []string{ |
| 5587 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5588 | "-enable-all-curves", |
| 5589 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5590 | shouldFail: shouldFail, |
| 5591 | expectedError: verifyError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5592 | }) |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5593 | |
| 5594 | if !shouldFail { |
| 5595 | testCases = append(testCases, testCase{ |
| 5596 | testType: serverTest, |
| 5597 | name: "ClientAuth-InvalidSignature" + suffix, |
| 5598 | config: Config{ |
| 5599 | MaxVersion: ver.version, |
| 5600 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5601 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5602 | alg.id, |
| 5603 | }, |
| 5604 | Bugs: ProtocolBugs{ |
| 5605 | InvalidSignature: true, |
| 5606 | }, |
| 5607 | }, |
| 5608 | flags: []string{ |
| 5609 | "-require-any-client-certificate", |
| 5610 | "-enable-all-curves", |
| 5611 | }, |
| 5612 | shouldFail: true, |
| 5613 | expectedError: ":BAD_SIGNATURE:", |
| 5614 | }) |
| 5615 | |
| 5616 | testCases = append(testCases, testCase{ |
| 5617 | name: "ServerAuth-InvalidSignature" + suffix, |
| 5618 | config: Config{ |
| 5619 | MaxVersion: ver.version, |
| 5620 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5621 | CipherSuites: signingCiphers, |
| 5622 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5623 | alg.id, |
| 5624 | }, |
| 5625 | Bugs: ProtocolBugs{ |
| 5626 | InvalidSignature: true, |
| 5627 | }, |
| 5628 | }, |
| 5629 | flags: []string{"-enable-all-curves"}, |
| 5630 | shouldFail: true, |
| 5631 | expectedError: ":BAD_SIGNATURE:", |
| 5632 | }) |
| 5633 | } |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5634 | |
| 5635 | if ver.version >= VersionTLS12 && !shouldFail { |
| 5636 | testCases = append(testCases, testCase{ |
| 5637 | name: "ClientAuth-Sign-Negotiate" + suffix, |
| 5638 | config: Config{ |
| 5639 | MaxVersion: ver.version, |
| 5640 | ClientAuth: RequireAnyClientCert, |
| 5641 | VerifySignatureAlgorithms: allAlgorithms, |
| 5642 | }, |
| 5643 | flags: []string{ |
| 5644 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5645 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5646 | "-enable-all-curves", |
| 5647 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 5648 | }, |
| 5649 | expectedPeerSignatureAlgorithm: alg.id, |
| 5650 | }) |
| 5651 | |
| 5652 | testCases = append(testCases, testCase{ |
| 5653 | testType: serverTest, |
| 5654 | name: "ServerAuth-Sign-Negotiate" + suffix, |
| 5655 | config: Config{ |
| 5656 | MaxVersion: ver.version, |
| 5657 | CipherSuites: signingCiphers, |
| 5658 | VerifySignatureAlgorithms: allAlgorithms, |
| 5659 | }, |
| 5660 | flags: []string{ |
| 5661 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5662 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5663 | "-enable-all-curves", |
| 5664 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 5665 | }, |
| 5666 | expectedPeerSignatureAlgorithm: alg.id, |
| 5667 | }) |
| 5668 | } |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5669 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5670 | } |
| 5671 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5672 | // Test that algorithm selection takes the key type into account. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5673 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5674 | name: "ClientAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5675 | config: Config{ |
| 5676 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5677 | MaxVersion: VersionTLS12, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5678 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5679 | signatureECDSAWithP521AndSHA512, |
| 5680 | signatureRSAPKCS1WithSHA384, |
| 5681 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5682 | }, |
| 5683 | }, |
| 5684 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5685 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5686 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5687 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5688 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5689 | }) |
| 5690 | |
| 5691 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5692 | name: "ClientAuth-SignatureType-TLS13", |
| 5693 | config: Config{ |
| 5694 | ClientAuth: RequireAnyClientCert, |
| 5695 | MaxVersion: VersionTLS13, |
| 5696 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5697 | signatureECDSAWithP521AndSHA512, |
| 5698 | signatureRSAPKCS1WithSHA384, |
| 5699 | signatureRSAPSSWithSHA384, |
| 5700 | signatureECDSAWithSHA1, |
| 5701 | }, |
| 5702 | }, |
| 5703 | flags: []string{ |
| 5704 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5705 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5706 | }, |
| 5707 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 5708 | }) |
| 5709 | |
| 5710 | testCases = append(testCases, testCase{ |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5711 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5712 | name: "ServerAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5713 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5714 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5715 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5716 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5717 | signatureECDSAWithP521AndSHA512, |
| 5718 | signatureRSAPKCS1WithSHA384, |
| 5719 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5720 | }, |
| 5721 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5722 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5723 | }) |
| 5724 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5725 | testCases = append(testCases, testCase{ |
| 5726 | testType: serverTest, |
| 5727 | name: "ServerAuth-SignatureType-TLS13", |
| 5728 | config: Config{ |
| 5729 | MaxVersion: VersionTLS13, |
| 5730 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5731 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5732 | signatureECDSAWithP521AndSHA512, |
| 5733 | signatureRSAPKCS1WithSHA384, |
| 5734 | signatureRSAPSSWithSHA384, |
| 5735 | signatureECDSAWithSHA1, |
| 5736 | }, |
| 5737 | }, |
| 5738 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 5739 | }) |
| 5740 | |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5741 | // Test that signature verification takes the key type into account. |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5742 | testCases = append(testCases, testCase{ |
| 5743 | testType: serverTest, |
| 5744 | name: "Verify-ClientAuth-SignatureType", |
| 5745 | config: Config{ |
| 5746 | MaxVersion: VersionTLS12, |
| 5747 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5748 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5749 | signatureRSAPKCS1WithSHA256, |
| 5750 | }, |
| 5751 | Bugs: ProtocolBugs{ |
| 5752 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5753 | }, |
| 5754 | }, |
| 5755 | flags: []string{ |
| 5756 | "-require-any-client-certificate", |
| 5757 | }, |
| 5758 | shouldFail: true, |
| 5759 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5760 | }) |
| 5761 | |
| 5762 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5763 | testType: serverTest, |
| 5764 | name: "Verify-ClientAuth-SignatureType-TLS13", |
| 5765 | config: Config{ |
| 5766 | MaxVersion: VersionTLS13, |
| 5767 | Certificates: []Certificate{rsaCertificate}, |
| 5768 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5769 | signatureRSAPSSWithSHA256, |
| 5770 | }, |
| 5771 | Bugs: ProtocolBugs{ |
| 5772 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5773 | }, |
| 5774 | }, |
| 5775 | flags: []string{ |
| 5776 | "-require-any-client-certificate", |
| 5777 | }, |
| 5778 | shouldFail: true, |
| 5779 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5780 | }) |
| 5781 | |
| 5782 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5783 | name: "Verify-ServerAuth-SignatureType", |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5784 | config: Config{ |
| 5785 | MaxVersion: VersionTLS12, |
| 5786 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5787 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5788 | signatureRSAPKCS1WithSHA256, |
| 5789 | }, |
| 5790 | Bugs: ProtocolBugs{ |
| 5791 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5792 | }, |
| 5793 | }, |
| 5794 | shouldFail: true, |
| 5795 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5796 | }) |
| 5797 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5798 | testCases = append(testCases, testCase{ |
| 5799 | name: "Verify-ServerAuth-SignatureType-TLS13", |
| 5800 | config: Config{ |
| 5801 | MaxVersion: VersionTLS13, |
| 5802 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5803 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5804 | signatureRSAPSSWithSHA256, |
| 5805 | }, |
| 5806 | Bugs: ProtocolBugs{ |
| 5807 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5808 | }, |
| 5809 | }, |
| 5810 | shouldFail: true, |
| 5811 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5812 | }) |
| 5813 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5814 | // Test that, if the list is missing, the peer falls back to SHA-1 in |
| 5815 | // TLS 1.2, but not TLS 1.3. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5816 | testCases = append(testCases, testCase{ |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 5817 | name: "ClientAuth-SHA1-Fallback-RSA", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5818 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5819 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5820 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5821 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5822 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5823 | }, |
| 5824 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5825 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5826 | }, |
| 5827 | }, |
| 5828 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5829 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5830 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5831 | }, |
| 5832 | }) |
| 5833 | |
| 5834 | testCases = append(testCases, testCase{ |
| 5835 | testType: serverTest, |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 5836 | name: "ServerAuth-SHA1-Fallback-RSA", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5837 | config: Config{ |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 5838 | MaxVersion: VersionTLS12, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5839 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5840 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5841 | }, |
| 5842 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5843 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5844 | }, |
| 5845 | }, |
David Benjamin | ee32bea | 2016-08-17 13:36:44 -0400 | [diff] [blame] | 5846 | flags: []string{ |
| 5847 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5848 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5849 | }, |
| 5850 | }) |
| 5851 | |
| 5852 | testCases = append(testCases, testCase{ |
| 5853 | name: "ClientAuth-SHA1-Fallback-ECDSA", |
| 5854 | config: Config{ |
| 5855 | MaxVersion: VersionTLS12, |
| 5856 | ClientAuth: RequireAnyClientCert, |
| 5857 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5858 | signatureECDSAWithSHA1, |
| 5859 | }, |
| 5860 | Bugs: ProtocolBugs{ |
| 5861 | NoSignatureAlgorithms: true, |
| 5862 | }, |
| 5863 | }, |
| 5864 | flags: []string{ |
| 5865 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 5866 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 5867 | }, |
| 5868 | }) |
| 5869 | |
| 5870 | testCases = append(testCases, testCase{ |
| 5871 | testType: serverTest, |
| 5872 | name: "ServerAuth-SHA1-Fallback-ECDSA", |
| 5873 | config: Config{ |
| 5874 | MaxVersion: VersionTLS12, |
| 5875 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5876 | signatureECDSAWithSHA1, |
| 5877 | }, |
| 5878 | Bugs: ProtocolBugs{ |
| 5879 | NoSignatureAlgorithms: true, |
| 5880 | }, |
| 5881 | }, |
| 5882 | flags: []string{ |
| 5883 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 5884 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 5885 | }, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5886 | }) |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5887 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5888 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5889 | name: "ClientAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5890 | config: Config{ |
| 5891 | MaxVersion: VersionTLS13, |
| 5892 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5893 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5894 | signatureRSAPKCS1WithSHA1, |
| 5895 | }, |
| 5896 | Bugs: ProtocolBugs{ |
| 5897 | NoSignatureAlgorithms: true, |
| 5898 | }, |
| 5899 | }, |
| 5900 | flags: []string{ |
| 5901 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5902 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5903 | }, |
David Benjamin | 4890165 | 2016-08-01 12:12:47 -0400 | [diff] [blame] | 5904 | shouldFail: true, |
| 5905 | // An empty CertificateRequest signature algorithm list is a |
| 5906 | // syntax error in TLS 1.3. |
| 5907 | expectedError: ":DECODE_ERROR:", |
| 5908 | expectedLocalError: "remote error: error decoding message", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5909 | }) |
| 5910 | |
| 5911 | testCases = append(testCases, testCase{ |
| 5912 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5913 | name: "ServerAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5914 | config: Config{ |
| 5915 | MaxVersion: VersionTLS13, |
| 5916 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5917 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5918 | signatureRSAPKCS1WithSHA1, |
| 5919 | }, |
| 5920 | Bugs: ProtocolBugs{ |
| 5921 | NoSignatureAlgorithms: true, |
| 5922 | }, |
| 5923 | }, |
| 5924 | shouldFail: true, |
| 5925 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5926 | }) |
| 5927 | |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 5928 | // Test that hash preferences are enforced. BoringSSL does not implement |
| 5929 | // MD5 signatures. |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5930 | testCases = append(testCases, testCase{ |
| 5931 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5932 | name: "ClientAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5933 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5934 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5935 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5936 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5937 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5938 | }, |
| 5939 | Bugs: ProtocolBugs{ |
| 5940 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5941 | }, |
| 5942 | }, |
| 5943 | flags: []string{"-require-any-client-certificate"}, |
| 5944 | shouldFail: true, |
| 5945 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5946 | }) |
| 5947 | |
| 5948 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5949 | name: "ServerAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5950 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5951 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5952 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5953 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5954 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5955 | }, |
| 5956 | Bugs: ProtocolBugs{ |
| 5957 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5958 | }, |
| 5959 | }, |
| 5960 | shouldFail: true, |
| 5961 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5962 | }) |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 5963 | testCases = append(testCases, testCase{ |
| 5964 | testType: serverTest, |
| 5965 | name: "ClientAuth-Enforced-TLS13", |
| 5966 | config: Config{ |
| 5967 | MaxVersion: VersionTLS13, |
| 5968 | Certificates: []Certificate{rsaCertificate}, |
| 5969 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5970 | signatureRSAPKCS1WithMD5, |
| 5971 | }, |
| 5972 | Bugs: ProtocolBugs{ |
| 5973 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5974 | IgnoreSignatureVersionChecks: true, |
| 5975 | }, |
| 5976 | }, |
| 5977 | flags: []string{"-require-any-client-certificate"}, |
| 5978 | shouldFail: true, |
| 5979 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5980 | }) |
| 5981 | |
| 5982 | testCases = append(testCases, testCase{ |
| 5983 | name: "ServerAuth-Enforced-TLS13", |
| 5984 | config: Config{ |
| 5985 | MaxVersion: VersionTLS13, |
| 5986 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5987 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5988 | signatureRSAPKCS1WithMD5, |
| 5989 | }, |
| 5990 | Bugs: ProtocolBugs{ |
| 5991 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5992 | IgnoreSignatureVersionChecks: true, |
| 5993 | }, |
| 5994 | }, |
| 5995 | shouldFail: true, |
| 5996 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5997 | }) |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5998 | |
| 5999 | // Test that the agreed upon digest respects the client preferences and |
| 6000 | // the server digests. |
| 6001 | testCases = append(testCases, testCase{ |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6002 | name: "NoCommonAlgorithms-Digests", |
| 6003 | config: Config{ |
| 6004 | MaxVersion: VersionTLS12, |
| 6005 | ClientAuth: RequireAnyClientCert, |
| 6006 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6007 | signatureRSAPKCS1WithSHA512, |
| 6008 | signatureRSAPKCS1WithSHA1, |
| 6009 | }, |
| 6010 | }, |
| 6011 | flags: []string{ |
| 6012 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6013 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6014 | "-digest-prefs", "SHA256", |
| 6015 | }, |
| 6016 | shouldFail: true, |
| 6017 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6018 | }) |
| 6019 | testCases = append(testCases, testCase{ |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 6020 | name: "NoCommonAlgorithms", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6021 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6022 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6023 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6024 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6025 | signatureRSAPKCS1WithSHA512, |
| 6026 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6027 | }, |
| 6028 | }, |
| 6029 | flags: []string{ |
| 6030 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6031 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6032 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6033 | }, |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6034 | shouldFail: true, |
| 6035 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6036 | }) |
| 6037 | testCases = append(testCases, testCase{ |
| 6038 | name: "NoCommonAlgorithms-TLS13", |
| 6039 | config: Config{ |
| 6040 | MaxVersion: VersionTLS13, |
| 6041 | ClientAuth: RequireAnyClientCert, |
| 6042 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6043 | signatureRSAPSSWithSHA512, |
| 6044 | signatureRSAPSSWithSHA384, |
| 6045 | }, |
| 6046 | }, |
| 6047 | flags: []string{ |
| 6048 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6049 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6050 | "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)), |
| 6051 | }, |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 6052 | shouldFail: true, |
| 6053 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6054 | }) |
| 6055 | testCases = append(testCases, testCase{ |
| 6056 | name: "Agree-Digest-SHA256", |
| 6057 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6058 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6059 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6060 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6061 | signatureRSAPKCS1WithSHA1, |
| 6062 | signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6063 | }, |
| 6064 | }, |
| 6065 | flags: []string{ |
| 6066 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6067 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6068 | "-digest-prefs", "SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6069 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6070 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6071 | }) |
| 6072 | testCases = append(testCases, testCase{ |
| 6073 | name: "Agree-Digest-SHA1", |
| 6074 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6075 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6076 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6077 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6078 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6079 | }, |
| 6080 | }, |
| 6081 | flags: []string{ |
| 6082 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6083 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6084 | "-digest-prefs", "SHA512,SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6085 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6086 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6087 | }) |
| 6088 | testCases = append(testCases, testCase{ |
| 6089 | name: "Agree-Digest-Default", |
| 6090 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6091 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6092 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6093 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6094 | signatureRSAPKCS1WithSHA256, |
| 6095 | signatureECDSAWithP256AndSHA256, |
| 6096 | signatureRSAPKCS1WithSHA1, |
| 6097 | signatureECDSAWithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6098 | }, |
| 6099 | }, |
| 6100 | flags: []string{ |
| 6101 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6102 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6103 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6104 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 6105 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6106 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 6107 | // Test that the signing preference list may include extra algorithms |
| 6108 | // without negotiation problems. |
| 6109 | testCases = append(testCases, testCase{ |
| 6110 | testType: serverTest, |
| 6111 | name: "FilterExtraAlgorithms", |
| 6112 | config: Config{ |
| 6113 | MaxVersion: VersionTLS12, |
| 6114 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6115 | signatureRSAPKCS1WithSHA256, |
| 6116 | }, |
| 6117 | }, |
| 6118 | flags: []string{ |
| 6119 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 6120 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 6121 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)), |
| 6122 | "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)), |
| 6123 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
| 6124 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)), |
| 6125 | }, |
| 6126 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
| 6127 | }) |
| 6128 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6129 | // In TLS 1.2 and below, ECDSA uses the curve list rather than the |
| 6130 | // signature algorithms. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6131 | testCases = append(testCases, testCase{ |
| 6132 | name: "CheckLeafCurve", |
| 6133 | config: Config{ |
| 6134 | MaxVersion: VersionTLS12, |
| 6135 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 6136 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6137 | }, |
| 6138 | flags: []string{"-p384-only"}, |
| 6139 | shouldFail: true, |
| 6140 | expectedError: ":BAD_ECC_CERT:", |
| 6141 | }) |
David Benjamin | 75ea5bb | 2016-07-08 17:43:29 -0700 | [diff] [blame] | 6142 | |
| 6143 | // In TLS 1.3, ECDSA does not use the ECDHE curve list. |
| 6144 | testCases = append(testCases, testCase{ |
| 6145 | name: "CheckLeafCurve-TLS13", |
| 6146 | config: Config{ |
| 6147 | MaxVersion: VersionTLS13, |
| 6148 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6149 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 6150 | }, |
| 6151 | flags: []string{"-p384-only"}, |
| 6152 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6153 | |
| 6154 | // In TLS 1.2, the ECDSA curve is not in the signature algorithm. |
| 6155 | testCases = append(testCases, testCase{ |
| 6156 | name: "ECDSACurveMismatch-Verify-TLS12", |
| 6157 | config: Config{ |
| 6158 | MaxVersion: VersionTLS12, |
| 6159 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6160 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6161 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6162 | signatureECDSAWithP384AndSHA384, |
| 6163 | }, |
| 6164 | }, |
| 6165 | }) |
| 6166 | |
| 6167 | // In TLS 1.3, the ECDSA curve comes from the signature algorithm. |
| 6168 | testCases = append(testCases, testCase{ |
| 6169 | name: "ECDSACurveMismatch-Verify-TLS13", |
| 6170 | config: Config{ |
| 6171 | MaxVersion: VersionTLS13, |
| 6172 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 6173 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6174 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6175 | signatureECDSAWithP384AndSHA384, |
| 6176 | }, |
| 6177 | Bugs: ProtocolBugs{ |
| 6178 | SkipECDSACurveCheck: true, |
| 6179 | }, |
| 6180 | }, |
| 6181 | shouldFail: true, |
| 6182 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 6183 | }) |
| 6184 | |
| 6185 | // Signature algorithm selection in TLS 1.3 should take the curve into |
| 6186 | // account. |
| 6187 | testCases = append(testCases, testCase{ |
| 6188 | testType: serverTest, |
| 6189 | name: "ECDSACurveMismatch-Sign-TLS13", |
| 6190 | config: Config{ |
| 6191 | MaxVersion: VersionTLS13, |
| 6192 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 6193 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 6194 | signatureECDSAWithP384AndSHA384, |
| 6195 | signatureECDSAWithP256AndSHA256, |
| 6196 | }, |
| 6197 | }, |
| 6198 | flags: []string{ |
| 6199 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 6200 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 6201 | }, |
| 6202 | expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 6203 | }) |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 6204 | |
| 6205 | // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the |
| 6206 | // server does not attempt to sign in that case. |
| 6207 | testCases = append(testCases, testCase{ |
| 6208 | testType: serverTest, |
| 6209 | name: "RSA-PSS-Large", |
| 6210 | config: Config{ |
| 6211 | MaxVersion: VersionTLS13, |
| 6212 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 6213 | signatureRSAPSSWithSHA512, |
| 6214 | }, |
| 6215 | }, |
| 6216 | flags: []string{ |
| 6217 | "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile), |
| 6218 | "-key-file", path.Join(*resourceDir, rsa1024KeyFile), |
| 6219 | }, |
| 6220 | shouldFail: true, |
| 6221 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 6222 | }) |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 6223 | } |
| 6224 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6225 | // timeouts is the retransmit schedule for BoringSSL. It doubles and |
| 6226 | // caps at 60 seconds. On the 13th timeout, it gives up. |
| 6227 | var timeouts = []time.Duration{ |
| 6228 | 1 * time.Second, |
| 6229 | 2 * time.Second, |
| 6230 | 4 * time.Second, |
| 6231 | 8 * time.Second, |
| 6232 | 16 * time.Second, |
| 6233 | 32 * time.Second, |
| 6234 | 60 * time.Second, |
| 6235 | 60 * time.Second, |
| 6236 | 60 * time.Second, |
| 6237 | 60 * time.Second, |
| 6238 | 60 * time.Second, |
| 6239 | 60 * time.Second, |
| 6240 | 60 * time.Second, |
| 6241 | } |
| 6242 | |
Taylor Brandstetter | 376a0fe | 2016-05-10 19:30:28 -0700 | [diff] [blame] | 6243 | // shortTimeouts is an alternate set of timeouts which would occur if the |
| 6244 | // initial timeout duration was set to 250ms. |
| 6245 | var shortTimeouts = []time.Duration{ |
| 6246 | 250 * time.Millisecond, |
| 6247 | 500 * time.Millisecond, |
| 6248 | 1 * time.Second, |
| 6249 | 2 * time.Second, |
| 6250 | 4 * time.Second, |
| 6251 | 8 * time.Second, |
| 6252 | 16 * time.Second, |
| 6253 | 32 * time.Second, |
| 6254 | 60 * time.Second, |
| 6255 | 60 * time.Second, |
| 6256 | 60 * time.Second, |
| 6257 | 60 * time.Second, |
| 6258 | 60 * time.Second, |
| 6259 | } |
| 6260 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6261 | func addDTLSRetransmitTests() { |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6262 | // These tests work by coordinating some behavior on both the shim and |
| 6263 | // the runner. |
| 6264 | // |
| 6265 | // TimeoutSchedule configures the runner to send a series of timeout |
| 6266 | // opcodes to the shim (see packetAdaptor) immediately before reading |
| 6267 | // each peer handshake flight N. The timeout opcode both simulates a |
| 6268 | // timeout in the shim and acts as a synchronization point to help the |
| 6269 | // runner bracket each handshake flight. |
| 6270 | // |
| 6271 | // We assume the shim does not read from the channel eagerly. It must |
| 6272 | // first wait until it has sent flight N and is ready to receive |
| 6273 | // handshake flight N+1. At this point, it will process the timeout |
| 6274 | // opcode. It must then immediately respond with a timeout ACK and act |
| 6275 | // as if the shim was idle for the specified amount of time. |
| 6276 | // |
| 6277 | // The runner then drops all packets received before the ACK and |
| 6278 | // continues waiting for flight N. This ordering results in one attempt |
| 6279 | // at sending flight N to be dropped. For the test to complete, the |
| 6280 | // shim must send flight N again, testing that the shim implements DTLS |
| 6281 | // retransmit on a timeout. |
| 6282 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6283 | // TODO(davidben): Add DTLS 1.3 versions of these tests. There will |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6284 | // likely be more epochs to cross and the final message's retransmit may |
| 6285 | // be more complex. |
| 6286 | |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6287 | for _, async := range []bool{true, false} { |
| 6288 | var tests []testCase |
| 6289 | |
| 6290 | // Test that this is indeed the timeout schedule. Stress all |
| 6291 | // four patterns of handshake. |
| 6292 | for i := 1; i < len(timeouts); i++ { |
| 6293 | number := strconv.Itoa(i) |
| 6294 | tests = append(tests, testCase{ |
| 6295 | protocol: dtls, |
| 6296 | name: "DTLS-Retransmit-Client-" + number, |
| 6297 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6298 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6299 | Bugs: ProtocolBugs{ |
| 6300 | TimeoutSchedule: timeouts[:i], |
| 6301 | }, |
| 6302 | }, |
| 6303 | resumeSession: true, |
| 6304 | }) |
| 6305 | tests = append(tests, testCase{ |
| 6306 | protocol: dtls, |
| 6307 | testType: serverTest, |
| 6308 | name: "DTLS-Retransmit-Server-" + number, |
| 6309 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6310 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6311 | Bugs: ProtocolBugs{ |
| 6312 | TimeoutSchedule: timeouts[:i], |
| 6313 | }, |
| 6314 | }, |
| 6315 | resumeSession: true, |
| 6316 | }) |
| 6317 | } |
| 6318 | |
| 6319 | // Test that exceeding the timeout schedule hits a read |
| 6320 | // timeout. |
| 6321 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6322 | protocol: dtls, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6323 | name: "DTLS-Retransmit-Timeout", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6324 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6325 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6326 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6327 | TimeoutSchedule: timeouts, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6328 | }, |
| 6329 | }, |
| 6330 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6331 | shouldFail: true, |
| 6332 | expectedError: ":READ_TIMEOUT_EXPIRED:", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6333 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6334 | |
| 6335 | if async { |
| 6336 | // Test that timeout handling has a fudge factor, due to API |
| 6337 | // problems. |
| 6338 | tests = append(tests, testCase{ |
| 6339 | protocol: dtls, |
| 6340 | name: "DTLS-Retransmit-Fudge", |
| 6341 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6342 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6343 | Bugs: ProtocolBugs{ |
| 6344 | TimeoutSchedule: []time.Duration{ |
| 6345 | timeouts[0] - 10*time.Millisecond, |
| 6346 | }, |
| 6347 | }, |
| 6348 | }, |
| 6349 | resumeSession: true, |
| 6350 | }) |
| 6351 | } |
| 6352 | |
| 6353 | // Test that the final Finished retransmitting isn't |
| 6354 | // duplicated if the peer badly fragments everything. |
| 6355 | tests = append(tests, testCase{ |
| 6356 | testType: serverTest, |
| 6357 | protocol: dtls, |
| 6358 | name: "DTLS-Retransmit-Fragmented", |
| 6359 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6360 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6361 | Bugs: ProtocolBugs{ |
| 6362 | TimeoutSchedule: []time.Duration{timeouts[0]}, |
| 6363 | MaxHandshakeRecordLength: 2, |
| 6364 | }, |
| 6365 | }, |
| 6366 | }) |
| 6367 | |
| 6368 | // Test the timeout schedule when a shorter initial timeout duration is set. |
| 6369 | tests = append(tests, testCase{ |
| 6370 | protocol: dtls, |
| 6371 | name: "DTLS-Retransmit-Short-Client", |
| 6372 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6373 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6374 | Bugs: ProtocolBugs{ |
| 6375 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
| 6376 | }, |
| 6377 | }, |
| 6378 | resumeSession: true, |
| 6379 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
| 6380 | }) |
| 6381 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6382 | protocol: dtls, |
| 6383 | testType: serverTest, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6384 | name: "DTLS-Retransmit-Short-Server", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6385 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6386 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6387 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6388 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6389 | }, |
| 6390 | }, |
| 6391 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6392 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6393 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6394 | |
| 6395 | for _, test := range tests { |
| 6396 | if async { |
| 6397 | test.name += "-Async" |
| 6398 | test.flags = append(test.flags, "-async") |
| 6399 | } |
| 6400 | |
| 6401 | testCases = append(testCases, test) |
| 6402 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6403 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6404 | } |
| 6405 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 6406 | func addExportKeyingMaterialTests() { |
| 6407 | for _, vers := range tlsVersions { |
| 6408 | if vers.version == VersionSSL30 { |
| 6409 | continue |
| 6410 | } |
| 6411 | testCases = append(testCases, testCase{ |
| 6412 | name: "ExportKeyingMaterial-" + vers.name, |
| 6413 | config: Config{ |
| 6414 | MaxVersion: vers.version, |
| 6415 | }, |
| 6416 | exportKeyingMaterial: 1024, |
| 6417 | exportLabel: "label", |
| 6418 | exportContext: "context", |
| 6419 | useExportContext: true, |
| 6420 | }) |
| 6421 | testCases = append(testCases, testCase{ |
| 6422 | name: "ExportKeyingMaterial-NoContext-" + vers.name, |
| 6423 | config: Config{ |
| 6424 | MaxVersion: vers.version, |
| 6425 | }, |
| 6426 | exportKeyingMaterial: 1024, |
| 6427 | }) |
| 6428 | testCases = append(testCases, testCase{ |
| 6429 | name: "ExportKeyingMaterial-EmptyContext-" + vers.name, |
| 6430 | config: Config{ |
| 6431 | MaxVersion: vers.version, |
| 6432 | }, |
| 6433 | exportKeyingMaterial: 1024, |
| 6434 | useExportContext: true, |
| 6435 | }) |
| 6436 | testCases = append(testCases, testCase{ |
| 6437 | name: "ExportKeyingMaterial-Small-" + vers.name, |
| 6438 | config: Config{ |
| 6439 | MaxVersion: vers.version, |
| 6440 | }, |
| 6441 | exportKeyingMaterial: 1, |
| 6442 | exportLabel: "label", |
| 6443 | exportContext: "context", |
| 6444 | useExportContext: true, |
| 6445 | }) |
| 6446 | } |
| 6447 | testCases = append(testCases, testCase{ |
| 6448 | name: "ExportKeyingMaterial-SSL3", |
| 6449 | config: Config{ |
| 6450 | MaxVersion: VersionSSL30, |
| 6451 | }, |
| 6452 | exportKeyingMaterial: 1024, |
| 6453 | exportLabel: "label", |
| 6454 | exportContext: "context", |
| 6455 | useExportContext: true, |
| 6456 | shouldFail: true, |
| 6457 | expectedError: "failed to export keying material", |
| 6458 | }) |
| 6459 | } |
| 6460 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6461 | func addTLSUniqueTests() { |
| 6462 | for _, isClient := range []bool{false, true} { |
| 6463 | for _, isResumption := range []bool{false, true} { |
| 6464 | for _, hasEMS := range []bool{false, true} { |
| 6465 | var suffix string |
| 6466 | if isResumption { |
| 6467 | suffix = "Resume-" |
| 6468 | } else { |
| 6469 | suffix = "Full-" |
| 6470 | } |
| 6471 | |
| 6472 | if hasEMS { |
| 6473 | suffix += "EMS-" |
| 6474 | } else { |
| 6475 | suffix += "NoEMS-" |
| 6476 | } |
| 6477 | |
| 6478 | if isClient { |
| 6479 | suffix += "Client" |
| 6480 | } else { |
| 6481 | suffix += "Server" |
| 6482 | } |
| 6483 | |
| 6484 | test := testCase{ |
| 6485 | name: "TLSUnique-" + suffix, |
| 6486 | testTLSUnique: true, |
| 6487 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6488 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6489 | Bugs: ProtocolBugs{ |
| 6490 | NoExtendedMasterSecret: !hasEMS, |
| 6491 | }, |
| 6492 | }, |
| 6493 | } |
| 6494 | |
| 6495 | if isResumption { |
| 6496 | test.resumeSession = true |
| 6497 | test.resumeConfig = &Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6498 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6499 | Bugs: ProtocolBugs{ |
| 6500 | NoExtendedMasterSecret: !hasEMS, |
| 6501 | }, |
| 6502 | } |
| 6503 | } |
| 6504 | |
| 6505 | if isResumption && !hasEMS { |
| 6506 | test.shouldFail = true |
| 6507 | test.expectedError = "failed to get tls-unique" |
| 6508 | } |
| 6509 | |
| 6510 | testCases = append(testCases, test) |
| 6511 | } |
| 6512 | } |
| 6513 | } |
| 6514 | } |
| 6515 | |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6516 | func addCustomExtensionTests() { |
| 6517 | expectedContents := "custom extension" |
| 6518 | emptyString := "" |
| 6519 | |
| 6520 | for _, isClient := range []bool{false, true} { |
| 6521 | suffix := "Server" |
| 6522 | flag := "-enable-server-custom-extension" |
| 6523 | testType := serverTest |
| 6524 | if isClient { |
| 6525 | suffix = "Client" |
| 6526 | flag = "-enable-client-custom-extension" |
| 6527 | testType = clientTest |
| 6528 | } |
| 6529 | |
| 6530 | testCases = append(testCases, testCase{ |
| 6531 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6532 | name: "CustomExtensions-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6533 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6534 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6535 | Bugs: ProtocolBugs{ |
| 6536 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6537 | ExpectedCustomExtension: &expectedContents, |
| 6538 | }, |
| 6539 | }, |
| 6540 | flags: []string{flag}, |
| 6541 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6542 | testCases = append(testCases, testCase{ |
| 6543 | testType: testType, |
| 6544 | name: "CustomExtensions-" + suffix + "-TLS13", |
| 6545 | config: Config{ |
| 6546 | MaxVersion: VersionTLS13, |
| 6547 | Bugs: ProtocolBugs{ |
| 6548 | CustomExtension: expectedContents, |
| 6549 | ExpectedCustomExtension: &expectedContents, |
| 6550 | }, |
| 6551 | }, |
| 6552 | flags: []string{flag}, |
| 6553 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6554 | |
| 6555 | // If the parse callback fails, the handshake should also fail. |
| 6556 | testCases = append(testCases, testCase{ |
| 6557 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6558 | name: "CustomExtensions-ParseError-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6559 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6560 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6561 | Bugs: ProtocolBugs{ |
| 6562 | CustomExtension: expectedContents + "foo", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6563 | ExpectedCustomExtension: &expectedContents, |
| 6564 | }, |
| 6565 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6566 | flags: []string{flag}, |
| 6567 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6568 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6569 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6570 | testCases = append(testCases, testCase{ |
| 6571 | testType: testType, |
| 6572 | name: "CustomExtensions-ParseError-" + suffix + "-TLS13", |
| 6573 | config: Config{ |
| 6574 | MaxVersion: VersionTLS13, |
| 6575 | Bugs: ProtocolBugs{ |
| 6576 | CustomExtension: expectedContents + "foo", |
| 6577 | ExpectedCustomExtension: &expectedContents, |
| 6578 | }, |
| 6579 | }, |
| 6580 | flags: []string{flag}, |
| 6581 | shouldFail: true, |
| 6582 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6583 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6584 | |
| 6585 | // If the add callback fails, the handshake should also fail. |
| 6586 | testCases = append(testCases, testCase{ |
| 6587 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6588 | name: "CustomExtensions-FailAdd-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6589 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6590 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6591 | Bugs: ProtocolBugs{ |
| 6592 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6593 | ExpectedCustomExtension: &expectedContents, |
| 6594 | }, |
| 6595 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6596 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 6597 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6598 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6599 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6600 | testCases = append(testCases, testCase{ |
| 6601 | testType: testType, |
| 6602 | name: "CustomExtensions-FailAdd-" + suffix + "-TLS13", |
| 6603 | config: Config{ |
| 6604 | MaxVersion: VersionTLS13, |
| 6605 | Bugs: ProtocolBugs{ |
| 6606 | CustomExtension: expectedContents, |
| 6607 | ExpectedCustomExtension: &expectedContents, |
| 6608 | }, |
| 6609 | }, |
| 6610 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 6611 | shouldFail: true, |
| 6612 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6613 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6614 | |
| 6615 | // If the add callback returns zero, no extension should be |
| 6616 | // added. |
| 6617 | skipCustomExtension := expectedContents |
| 6618 | if isClient { |
| 6619 | // For the case where the client skips sending the |
| 6620 | // custom extension, the server must not “echo” it. |
| 6621 | skipCustomExtension = "" |
| 6622 | } |
| 6623 | testCases = append(testCases, testCase{ |
| 6624 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6625 | name: "CustomExtensions-Skip-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6626 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6627 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6628 | Bugs: ProtocolBugs{ |
| 6629 | CustomExtension: skipCustomExtension, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6630 | ExpectedCustomExtension: &emptyString, |
| 6631 | }, |
| 6632 | }, |
| 6633 | flags: []string{flag, "-custom-extension-skip"}, |
| 6634 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6635 | testCases = append(testCases, testCase{ |
| 6636 | testType: testType, |
| 6637 | name: "CustomExtensions-Skip-" + suffix + "-TLS13", |
| 6638 | config: Config{ |
| 6639 | MaxVersion: VersionTLS13, |
| 6640 | Bugs: ProtocolBugs{ |
| 6641 | CustomExtension: skipCustomExtension, |
| 6642 | ExpectedCustomExtension: &emptyString, |
| 6643 | }, |
| 6644 | }, |
| 6645 | flags: []string{flag, "-custom-extension-skip"}, |
| 6646 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | // The custom extension add callback should not be called if the client |
| 6650 | // doesn't send the extension. |
| 6651 | testCases = append(testCases, testCase{ |
| 6652 | testType: serverTest, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6653 | name: "CustomExtensions-NotCalled-Server", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6654 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6655 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6656 | Bugs: ProtocolBugs{ |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6657 | ExpectedCustomExtension: &emptyString, |
| 6658 | }, |
| 6659 | }, |
| 6660 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 6661 | }) |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6662 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6663 | testCases = append(testCases, testCase{ |
| 6664 | testType: serverTest, |
| 6665 | name: "CustomExtensions-NotCalled-Server-TLS13", |
| 6666 | config: Config{ |
| 6667 | MaxVersion: VersionTLS13, |
| 6668 | Bugs: ProtocolBugs{ |
| 6669 | ExpectedCustomExtension: &emptyString, |
| 6670 | }, |
| 6671 | }, |
| 6672 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 6673 | }) |
| 6674 | |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6675 | // Test an unknown extension from the server. |
| 6676 | testCases = append(testCases, testCase{ |
| 6677 | testType: clientTest, |
| 6678 | name: "UnknownExtension-Client", |
| 6679 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6680 | MaxVersion: VersionTLS12, |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6681 | Bugs: ProtocolBugs{ |
| 6682 | CustomExtension: expectedContents, |
| 6683 | }, |
| 6684 | }, |
David Benjamin | 0c40a96 | 2016-08-01 12:05:50 -0400 | [diff] [blame] | 6685 | shouldFail: true, |
| 6686 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6687 | expectedLocalError: "remote error: unsupported extension", |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6688 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6689 | testCases = append(testCases, testCase{ |
| 6690 | testType: clientTest, |
| 6691 | name: "UnknownExtension-Client-TLS13", |
| 6692 | config: Config{ |
| 6693 | MaxVersion: VersionTLS13, |
| 6694 | Bugs: ProtocolBugs{ |
| 6695 | CustomExtension: expectedContents, |
| 6696 | }, |
| 6697 | }, |
David Benjamin | 0c40a96 | 2016-08-01 12:05:50 -0400 | [diff] [blame] | 6698 | shouldFail: true, |
| 6699 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6700 | expectedLocalError: "remote error: unsupported extension", |
| 6701 | }) |
| 6702 | |
| 6703 | // Test a known but unoffered extension from the server. |
| 6704 | testCases = append(testCases, testCase{ |
| 6705 | testType: clientTest, |
| 6706 | name: "UnofferedExtension-Client", |
| 6707 | config: Config{ |
| 6708 | MaxVersion: VersionTLS12, |
| 6709 | Bugs: ProtocolBugs{ |
| 6710 | SendALPN: "alpn", |
| 6711 | }, |
| 6712 | }, |
| 6713 | shouldFail: true, |
| 6714 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6715 | expectedLocalError: "remote error: unsupported extension", |
| 6716 | }) |
| 6717 | testCases = append(testCases, testCase{ |
| 6718 | testType: clientTest, |
| 6719 | name: "UnofferedExtension-Client-TLS13", |
| 6720 | config: Config{ |
| 6721 | MaxVersion: VersionTLS13, |
| 6722 | Bugs: ProtocolBugs{ |
| 6723 | SendALPN: "alpn", |
| 6724 | }, |
| 6725 | }, |
| 6726 | shouldFail: true, |
| 6727 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6728 | expectedLocalError: "remote error: unsupported extension", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6729 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6730 | } |
| 6731 | |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 6732 | func addRSAClientKeyExchangeTests() { |
| 6733 | for bad := RSABadValue(1); bad < NumRSABadValues; bad++ { |
| 6734 | testCases = append(testCases, testCase{ |
| 6735 | testType: serverTest, |
| 6736 | name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad), |
| 6737 | config: Config{ |
| 6738 | // Ensure the ClientHello version and final |
| 6739 | // version are different, to detect if the |
| 6740 | // server uses the wrong one. |
| 6741 | MaxVersion: VersionTLS11, |
| 6742 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 6743 | Bugs: ProtocolBugs{ |
| 6744 | BadRSAClientKeyExchange: bad, |
| 6745 | }, |
| 6746 | }, |
| 6747 | shouldFail: true, |
| 6748 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6749 | }) |
| 6750 | } |
| 6751 | } |
| 6752 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6753 | var testCurves = []struct { |
| 6754 | name string |
| 6755 | id CurveID |
| 6756 | }{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6757 | {"P-256", CurveP256}, |
| 6758 | {"P-384", CurveP384}, |
| 6759 | {"P-521", CurveP521}, |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 6760 | {"X25519", CurveX25519}, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6761 | } |
| 6762 | |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6763 | const bogusCurve = 0x1234 |
| 6764 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6765 | func addCurveTests() { |
| 6766 | for _, curve := range testCurves { |
| 6767 | testCases = append(testCases, testCase{ |
| 6768 | name: "CurveTest-Client-" + curve.name, |
| 6769 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6770 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6771 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6772 | CurvePreferences: []CurveID{curve.id}, |
| 6773 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6774 | flags: []string{"-enable-all-curves"}, |
| 6775 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6776 | }) |
| 6777 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6778 | name: "CurveTest-Client-" + curve.name + "-TLS13", |
| 6779 | config: Config{ |
| 6780 | MaxVersion: VersionTLS13, |
| 6781 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6782 | CurvePreferences: []CurveID{curve.id}, |
| 6783 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6784 | flags: []string{"-enable-all-curves"}, |
| 6785 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6786 | }) |
| 6787 | testCases = append(testCases, testCase{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6788 | testType: serverTest, |
| 6789 | name: "CurveTest-Server-" + curve.name, |
| 6790 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6791 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6792 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6793 | CurvePreferences: []CurveID{curve.id}, |
| 6794 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6795 | flags: []string{"-enable-all-curves"}, |
| 6796 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6797 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6798 | testCases = append(testCases, testCase{ |
| 6799 | testType: serverTest, |
| 6800 | name: "CurveTest-Server-" + curve.name + "-TLS13", |
| 6801 | config: Config{ |
| 6802 | MaxVersion: VersionTLS13, |
| 6803 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6804 | CurvePreferences: []CurveID{curve.id}, |
| 6805 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6806 | flags: []string{"-enable-all-curves"}, |
| 6807 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6808 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6809 | } |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 6810 | |
| 6811 | // The server must be tolerant to bogus curves. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 6812 | testCases = append(testCases, testCase{ |
| 6813 | testType: serverTest, |
| 6814 | name: "UnknownCurve", |
| 6815 | config: Config{ |
| 6816 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6817 | CurvePreferences: []CurveID{bogusCurve, CurveP256}, |
| 6818 | }, |
| 6819 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6820 | |
| 6821 | // The server must not consider ECDHE ciphers when there are no |
| 6822 | // supported curves. |
| 6823 | testCases = append(testCases, testCase{ |
| 6824 | testType: serverTest, |
| 6825 | name: "NoSupportedCurves", |
| 6826 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6827 | MaxVersion: VersionTLS12, |
| 6828 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6829 | Bugs: ProtocolBugs{ |
| 6830 | NoSupportedCurves: true, |
| 6831 | }, |
| 6832 | }, |
| 6833 | shouldFail: true, |
| 6834 | expectedError: ":NO_SHARED_CIPHER:", |
| 6835 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6836 | testCases = append(testCases, testCase{ |
| 6837 | testType: serverTest, |
| 6838 | name: "NoSupportedCurves-TLS13", |
| 6839 | config: Config{ |
| 6840 | MaxVersion: VersionTLS13, |
| 6841 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6842 | Bugs: ProtocolBugs{ |
| 6843 | NoSupportedCurves: true, |
| 6844 | }, |
| 6845 | }, |
| 6846 | shouldFail: true, |
| 6847 | expectedError: ":NO_SHARED_CIPHER:", |
| 6848 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6849 | |
| 6850 | // The server must fall back to another cipher when there are no |
| 6851 | // supported curves. |
| 6852 | testCases = append(testCases, testCase{ |
| 6853 | testType: serverTest, |
| 6854 | name: "NoCommonCurves", |
| 6855 | config: Config{ |
| 6856 | MaxVersion: VersionTLS12, |
| 6857 | CipherSuites: []uint16{ |
| 6858 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6859 | TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6860 | }, |
| 6861 | CurvePreferences: []CurveID{CurveP224}, |
| 6862 | }, |
| 6863 | expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6864 | }) |
| 6865 | |
| 6866 | // The client must reject bogus curves and disabled curves. |
| 6867 | testCases = append(testCases, testCase{ |
| 6868 | name: "BadECDHECurve", |
| 6869 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6870 | MaxVersion: VersionTLS12, |
| 6871 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6872 | Bugs: ProtocolBugs{ |
| 6873 | SendCurve: bogusCurve, |
| 6874 | }, |
| 6875 | }, |
| 6876 | shouldFail: true, |
| 6877 | expectedError: ":WRONG_CURVE:", |
| 6878 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6879 | testCases = append(testCases, testCase{ |
| 6880 | name: "BadECDHECurve-TLS13", |
| 6881 | config: Config{ |
| 6882 | MaxVersion: VersionTLS13, |
| 6883 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6884 | Bugs: ProtocolBugs{ |
| 6885 | SendCurve: bogusCurve, |
| 6886 | }, |
| 6887 | }, |
| 6888 | shouldFail: true, |
| 6889 | expectedError: ":WRONG_CURVE:", |
| 6890 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6891 | |
| 6892 | testCases = append(testCases, testCase{ |
| 6893 | name: "UnsupportedCurve", |
| 6894 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6895 | MaxVersion: VersionTLS12, |
| 6896 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6897 | CurvePreferences: []CurveID{CurveP256}, |
| 6898 | Bugs: ProtocolBugs{ |
| 6899 | IgnorePeerCurvePreferences: true, |
| 6900 | }, |
| 6901 | }, |
| 6902 | flags: []string{"-p384-only"}, |
| 6903 | shouldFail: true, |
| 6904 | expectedError: ":WRONG_CURVE:", |
| 6905 | }) |
| 6906 | |
David Benjamin | 4f92157 | 2016-07-17 14:20:10 +0200 | [diff] [blame] | 6907 | testCases = append(testCases, testCase{ |
| 6908 | // TODO(davidben): Add a TLS 1.3 version where |
| 6909 | // HelloRetryRequest requests an unsupported curve. |
| 6910 | name: "UnsupportedCurve-ServerHello-TLS13", |
| 6911 | config: Config{ |
| 6912 | MaxVersion: VersionTLS12, |
| 6913 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6914 | CurvePreferences: []CurveID{CurveP384}, |
| 6915 | Bugs: ProtocolBugs{ |
| 6916 | SendCurve: CurveP256, |
| 6917 | }, |
| 6918 | }, |
| 6919 | flags: []string{"-p384-only"}, |
| 6920 | shouldFail: true, |
| 6921 | expectedError: ":WRONG_CURVE:", |
| 6922 | }) |
| 6923 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6924 | // Test invalid curve points. |
| 6925 | testCases = append(testCases, testCase{ |
| 6926 | name: "InvalidECDHPoint-Client", |
| 6927 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6928 | MaxVersion: VersionTLS12, |
| 6929 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6930 | CurvePreferences: []CurveID{CurveP256}, |
| 6931 | Bugs: ProtocolBugs{ |
| 6932 | InvalidECDHPoint: true, |
| 6933 | }, |
| 6934 | }, |
| 6935 | shouldFail: true, |
| 6936 | expectedError: ":INVALID_ENCODING:", |
| 6937 | }) |
| 6938 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6939 | name: "InvalidECDHPoint-Client-TLS13", |
| 6940 | config: Config{ |
| 6941 | MaxVersion: VersionTLS13, |
| 6942 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6943 | CurvePreferences: []CurveID{CurveP256}, |
| 6944 | Bugs: ProtocolBugs{ |
| 6945 | InvalidECDHPoint: true, |
| 6946 | }, |
| 6947 | }, |
| 6948 | shouldFail: true, |
| 6949 | expectedError: ":INVALID_ENCODING:", |
| 6950 | }) |
| 6951 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6952 | testType: serverTest, |
| 6953 | name: "InvalidECDHPoint-Server", |
| 6954 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6955 | MaxVersion: VersionTLS12, |
| 6956 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6957 | CurvePreferences: []CurveID{CurveP256}, |
| 6958 | Bugs: ProtocolBugs{ |
| 6959 | InvalidECDHPoint: true, |
| 6960 | }, |
| 6961 | }, |
| 6962 | shouldFail: true, |
| 6963 | expectedError: ":INVALID_ENCODING:", |
| 6964 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6965 | testCases = append(testCases, testCase{ |
| 6966 | testType: serverTest, |
| 6967 | name: "InvalidECDHPoint-Server-TLS13", |
| 6968 | config: Config{ |
| 6969 | MaxVersion: VersionTLS13, |
| 6970 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6971 | CurvePreferences: []CurveID{CurveP256}, |
| 6972 | Bugs: ProtocolBugs{ |
| 6973 | InvalidECDHPoint: true, |
| 6974 | }, |
| 6975 | }, |
| 6976 | shouldFail: true, |
| 6977 | expectedError: ":INVALID_ENCODING:", |
| 6978 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6979 | } |
| 6980 | |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6981 | func addCECPQ1Tests() { |
| 6982 | testCases = append(testCases, testCase{ |
| 6983 | testType: clientTest, |
| 6984 | name: "CECPQ1-Client-BadX25519Part", |
| 6985 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6986 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6987 | MinVersion: VersionTLS12, |
| 6988 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6989 | Bugs: ProtocolBugs{ |
| 6990 | CECPQ1BadX25519Part: true, |
| 6991 | }, |
| 6992 | }, |
| 6993 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6994 | shouldFail: true, |
| 6995 | expectedLocalError: "local error: bad record MAC", |
| 6996 | }) |
| 6997 | testCases = append(testCases, testCase{ |
| 6998 | testType: clientTest, |
| 6999 | name: "CECPQ1-Client-BadNewhopePart", |
| 7000 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7001 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7002 | MinVersion: VersionTLS12, |
| 7003 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 7004 | Bugs: ProtocolBugs{ |
| 7005 | CECPQ1BadNewhopePart: true, |
| 7006 | }, |
| 7007 | }, |
| 7008 | flags: []string{"-cipher", "kCECPQ1"}, |
| 7009 | shouldFail: true, |
| 7010 | expectedLocalError: "local error: bad record MAC", |
| 7011 | }) |
| 7012 | testCases = append(testCases, testCase{ |
| 7013 | testType: serverTest, |
| 7014 | name: "CECPQ1-Server-BadX25519Part", |
| 7015 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7016 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7017 | MinVersion: VersionTLS12, |
| 7018 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 7019 | Bugs: ProtocolBugs{ |
| 7020 | CECPQ1BadX25519Part: true, |
| 7021 | }, |
| 7022 | }, |
| 7023 | flags: []string{"-cipher", "kCECPQ1"}, |
| 7024 | shouldFail: true, |
| 7025 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7026 | }) |
| 7027 | testCases = append(testCases, testCase{ |
| 7028 | testType: serverTest, |
| 7029 | name: "CECPQ1-Server-BadNewhopePart", |
| 7030 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7031 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7032 | MinVersion: VersionTLS12, |
| 7033 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 7034 | Bugs: ProtocolBugs{ |
| 7035 | CECPQ1BadNewhopePart: true, |
| 7036 | }, |
| 7037 | }, |
| 7038 | flags: []string{"-cipher", "kCECPQ1"}, |
| 7039 | shouldFail: true, |
| 7040 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7041 | }) |
| 7042 | } |
| 7043 | |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7044 | func addKeyExchangeInfoTests() { |
| 7045 | testCases = append(testCases, testCase{ |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7046 | name: "KeyExchangeInfo-DHE-Client", |
| 7047 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7048 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7049 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7050 | Bugs: ProtocolBugs{ |
| 7051 | // This is a 1234-bit prime number, generated |
| 7052 | // with: |
| 7053 | // openssl gendh 1234 | openssl asn1parse -i |
| 7054 | DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"), |
| 7055 | }, |
| 7056 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 7057 | flags: []string{"-expect-dhe-group-size", "1234"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7058 | }) |
| 7059 | testCases = append(testCases, testCase{ |
| 7060 | testType: serverTest, |
| 7061 | name: "KeyExchangeInfo-DHE-Server", |
| 7062 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7063 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7064 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7065 | }, |
| 7066 | // bssl_shim as a server configures a 2048-bit DHE group. |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 7067 | flags: []string{"-expect-dhe-group-size", "2048"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7068 | }) |
| 7069 | |
| 7070 | testCases = append(testCases, testCase{ |
| 7071 | name: "KeyExchangeInfo-ECDHE-Client", |
| 7072 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7073 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7074 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7075 | CurvePreferences: []CurveID{CurveX25519}, |
| 7076 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 7077 | flags: []string{"-expect-curve-id", "29", "-enable-all-curves"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7078 | }) |
| 7079 | testCases = append(testCases, testCase{ |
| 7080 | testType: serverTest, |
| 7081 | name: "KeyExchangeInfo-ECDHE-Server", |
| 7082 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 7083 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7084 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7085 | CurvePreferences: []CurveID{CurveX25519}, |
| 7086 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 7087 | flags: []string{"-expect-curve-id", "29", "-enable-all-curves"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7088 | }) |
| 7089 | } |
| 7090 | |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 7091 | func addTLS13RecordTests() { |
| 7092 | testCases = append(testCases, testCase{ |
| 7093 | name: "TLS13-RecordPadding", |
| 7094 | config: Config{ |
| 7095 | MaxVersion: VersionTLS13, |
| 7096 | MinVersion: VersionTLS13, |
| 7097 | Bugs: ProtocolBugs{ |
| 7098 | RecordPadding: 10, |
| 7099 | }, |
| 7100 | }, |
| 7101 | }) |
| 7102 | |
| 7103 | testCases = append(testCases, testCase{ |
| 7104 | name: "TLS13-EmptyRecords", |
| 7105 | config: Config{ |
| 7106 | MaxVersion: VersionTLS13, |
| 7107 | MinVersion: VersionTLS13, |
| 7108 | Bugs: ProtocolBugs{ |
| 7109 | OmitRecordContents: true, |
| 7110 | }, |
| 7111 | }, |
| 7112 | shouldFail: true, |
| 7113 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7114 | }) |
| 7115 | |
| 7116 | testCases = append(testCases, testCase{ |
| 7117 | name: "TLS13-OnlyPadding", |
| 7118 | config: Config{ |
| 7119 | MaxVersion: VersionTLS13, |
| 7120 | MinVersion: VersionTLS13, |
| 7121 | Bugs: ProtocolBugs{ |
| 7122 | OmitRecordContents: true, |
| 7123 | RecordPadding: 10, |
| 7124 | }, |
| 7125 | }, |
| 7126 | shouldFail: true, |
| 7127 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 7128 | }) |
| 7129 | |
| 7130 | testCases = append(testCases, testCase{ |
| 7131 | name: "TLS13-WrongOuterRecord", |
| 7132 | config: Config{ |
| 7133 | MaxVersion: VersionTLS13, |
| 7134 | MinVersion: VersionTLS13, |
| 7135 | Bugs: ProtocolBugs{ |
| 7136 | OuterRecordType: recordTypeHandshake, |
| 7137 | }, |
| 7138 | }, |
| 7139 | shouldFail: true, |
| 7140 | expectedError: ":INVALID_OUTER_RECORD_TYPE:", |
| 7141 | }) |
| 7142 | } |
| 7143 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7144 | func addChangeCipherSpecTests() { |
| 7145 | // Test missing ChangeCipherSpecs. |
| 7146 | testCases = append(testCases, testCase{ |
| 7147 | name: "SkipChangeCipherSpec-Client", |
| 7148 | config: Config{ |
| 7149 | MaxVersion: VersionTLS12, |
| 7150 | Bugs: ProtocolBugs{ |
| 7151 | SkipChangeCipherSpec: true, |
| 7152 | }, |
| 7153 | }, |
| 7154 | shouldFail: true, |
| 7155 | expectedError: ":UNEXPECTED_RECORD:", |
| 7156 | }) |
| 7157 | testCases = append(testCases, testCase{ |
| 7158 | testType: serverTest, |
| 7159 | name: "SkipChangeCipherSpec-Server", |
| 7160 | config: Config{ |
| 7161 | MaxVersion: VersionTLS12, |
| 7162 | Bugs: ProtocolBugs{ |
| 7163 | SkipChangeCipherSpec: true, |
| 7164 | }, |
| 7165 | }, |
| 7166 | shouldFail: true, |
| 7167 | expectedError: ":UNEXPECTED_RECORD:", |
| 7168 | }) |
| 7169 | testCases = append(testCases, testCase{ |
| 7170 | testType: serverTest, |
| 7171 | name: "SkipChangeCipherSpec-Server-NPN", |
| 7172 | config: Config{ |
| 7173 | MaxVersion: VersionTLS12, |
| 7174 | NextProtos: []string{"bar"}, |
| 7175 | Bugs: ProtocolBugs{ |
| 7176 | SkipChangeCipherSpec: true, |
| 7177 | }, |
| 7178 | }, |
| 7179 | flags: []string{ |
| 7180 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 7181 | }, |
| 7182 | shouldFail: true, |
| 7183 | expectedError: ":UNEXPECTED_RECORD:", |
| 7184 | }) |
| 7185 | |
| 7186 | // Test synchronization between the handshake and ChangeCipherSpec. |
| 7187 | // Partial post-CCS handshake messages before ChangeCipherSpec should be |
| 7188 | // rejected. Test both with and without handshake packing to handle both |
| 7189 | // when the partial post-CCS message is in its own record and when it is |
| 7190 | // attached to the pre-CCS message. |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7191 | for _, packed := range []bool{false, true} { |
| 7192 | var suffix string |
| 7193 | if packed { |
| 7194 | suffix = "-Packed" |
| 7195 | } |
| 7196 | |
| 7197 | testCases = append(testCases, testCase{ |
| 7198 | name: "FragmentAcrossChangeCipherSpec-Client" + suffix, |
| 7199 | config: Config{ |
| 7200 | MaxVersion: VersionTLS12, |
| 7201 | Bugs: ProtocolBugs{ |
| 7202 | FragmentAcrossChangeCipherSpec: true, |
| 7203 | PackHandshakeFlight: packed, |
| 7204 | }, |
| 7205 | }, |
| 7206 | shouldFail: true, |
| 7207 | expectedError: ":UNEXPECTED_RECORD:", |
| 7208 | }) |
| 7209 | testCases = append(testCases, testCase{ |
| 7210 | name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix, |
| 7211 | config: Config{ |
| 7212 | MaxVersion: VersionTLS12, |
| 7213 | }, |
| 7214 | resumeSession: true, |
| 7215 | resumeConfig: &Config{ |
| 7216 | MaxVersion: VersionTLS12, |
| 7217 | Bugs: ProtocolBugs{ |
| 7218 | FragmentAcrossChangeCipherSpec: true, |
| 7219 | PackHandshakeFlight: packed, |
| 7220 | }, |
| 7221 | }, |
| 7222 | shouldFail: true, |
| 7223 | expectedError: ":UNEXPECTED_RECORD:", |
| 7224 | }) |
| 7225 | testCases = append(testCases, testCase{ |
| 7226 | testType: serverTest, |
| 7227 | name: "FragmentAcrossChangeCipherSpec-Server" + suffix, |
| 7228 | config: Config{ |
| 7229 | MaxVersion: VersionTLS12, |
| 7230 | Bugs: ProtocolBugs{ |
| 7231 | FragmentAcrossChangeCipherSpec: true, |
| 7232 | PackHandshakeFlight: packed, |
| 7233 | }, |
| 7234 | }, |
| 7235 | shouldFail: true, |
| 7236 | expectedError: ":UNEXPECTED_RECORD:", |
| 7237 | }) |
| 7238 | testCases = append(testCases, testCase{ |
| 7239 | testType: serverTest, |
| 7240 | name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix, |
| 7241 | config: Config{ |
| 7242 | MaxVersion: VersionTLS12, |
| 7243 | }, |
| 7244 | resumeSession: true, |
| 7245 | resumeConfig: &Config{ |
| 7246 | MaxVersion: VersionTLS12, |
| 7247 | Bugs: ProtocolBugs{ |
| 7248 | FragmentAcrossChangeCipherSpec: true, |
| 7249 | PackHandshakeFlight: packed, |
| 7250 | }, |
| 7251 | }, |
| 7252 | shouldFail: true, |
| 7253 | expectedError: ":UNEXPECTED_RECORD:", |
| 7254 | }) |
| 7255 | testCases = append(testCases, testCase{ |
| 7256 | testType: serverTest, |
| 7257 | name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix, |
| 7258 | config: Config{ |
| 7259 | MaxVersion: VersionTLS12, |
| 7260 | NextProtos: []string{"bar"}, |
| 7261 | Bugs: ProtocolBugs{ |
| 7262 | FragmentAcrossChangeCipherSpec: true, |
| 7263 | PackHandshakeFlight: packed, |
| 7264 | }, |
| 7265 | }, |
| 7266 | flags: []string{ |
| 7267 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 7268 | }, |
| 7269 | shouldFail: true, |
| 7270 | expectedError: ":UNEXPECTED_RECORD:", |
| 7271 | }) |
| 7272 | } |
| 7273 | |
David Benjamin | 6167281 | 2016-07-14 23:10:43 -0400 | [diff] [blame] | 7274 | // Test that, in DTLS, ChangeCipherSpec is not allowed when there are |
| 7275 | // messages in the handshake queue. Do this by testing the server |
| 7276 | // reading the client Finished, reversing the flight so Finished comes |
| 7277 | // first. |
| 7278 | testCases = append(testCases, testCase{ |
| 7279 | protocol: dtls, |
| 7280 | testType: serverTest, |
| 7281 | name: "SendUnencryptedFinished-DTLS", |
| 7282 | config: Config{ |
| 7283 | MaxVersion: VersionTLS12, |
| 7284 | Bugs: ProtocolBugs{ |
| 7285 | SendUnencryptedFinished: true, |
| 7286 | ReverseHandshakeFragments: true, |
| 7287 | }, |
| 7288 | }, |
| 7289 | shouldFail: true, |
| 7290 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7291 | }) |
| 7292 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7293 | // Test synchronization between encryption changes and the handshake in |
| 7294 | // TLS 1.3, where ChangeCipherSpec is implicit. |
| 7295 | testCases = append(testCases, testCase{ |
| 7296 | name: "PartialEncryptedExtensionsWithServerHello", |
| 7297 | config: Config{ |
| 7298 | MaxVersion: VersionTLS13, |
| 7299 | Bugs: ProtocolBugs{ |
| 7300 | PartialEncryptedExtensionsWithServerHello: true, |
| 7301 | }, |
| 7302 | }, |
| 7303 | shouldFail: true, |
| 7304 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7305 | }) |
| 7306 | testCases = append(testCases, testCase{ |
| 7307 | testType: serverTest, |
| 7308 | name: "PartialClientFinishedWithClientHello", |
| 7309 | config: Config{ |
| 7310 | MaxVersion: VersionTLS13, |
| 7311 | Bugs: ProtocolBugs{ |
| 7312 | PartialClientFinishedWithClientHello: true, |
| 7313 | }, |
| 7314 | }, |
| 7315 | shouldFail: true, |
| 7316 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7317 | }) |
| 7318 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7319 | // Test that early ChangeCipherSpecs are handled correctly. |
| 7320 | testCases = append(testCases, testCase{ |
| 7321 | testType: serverTest, |
| 7322 | name: "EarlyChangeCipherSpec-server-1", |
| 7323 | config: Config{ |
| 7324 | MaxVersion: VersionTLS12, |
| 7325 | Bugs: ProtocolBugs{ |
| 7326 | EarlyChangeCipherSpec: 1, |
| 7327 | }, |
| 7328 | }, |
| 7329 | shouldFail: true, |
| 7330 | expectedError: ":UNEXPECTED_RECORD:", |
| 7331 | }) |
| 7332 | testCases = append(testCases, testCase{ |
| 7333 | testType: serverTest, |
| 7334 | name: "EarlyChangeCipherSpec-server-2", |
| 7335 | config: Config{ |
| 7336 | MaxVersion: VersionTLS12, |
| 7337 | Bugs: ProtocolBugs{ |
| 7338 | EarlyChangeCipherSpec: 2, |
| 7339 | }, |
| 7340 | }, |
| 7341 | shouldFail: true, |
| 7342 | expectedError: ":UNEXPECTED_RECORD:", |
| 7343 | }) |
| 7344 | testCases = append(testCases, testCase{ |
| 7345 | protocol: dtls, |
| 7346 | name: "StrayChangeCipherSpec", |
| 7347 | config: Config{ |
| 7348 | // TODO(davidben): Once DTLS 1.3 exists, test |
| 7349 | // that stray ChangeCipherSpec messages are |
| 7350 | // rejected. |
| 7351 | MaxVersion: VersionTLS12, |
| 7352 | Bugs: ProtocolBugs{ |
| 7353 | StrayChangeCipherSpec: true, |
| 7354 | }, |
| 7355 | }, |
| 7356 | }) |
| 7357 | |
| 7358 | // Test that the contents of ChangeCipherSpec are checked. |
| 7359 | testCases = append(testCases, testCase{ |
| 7360 | name: "BadChangeCipherSpec-1", |
| 7361 | config: Config{ |
| 7362 | MaxVersion: VersionTLS12, |
| 7363 | Bugs: ProtocolBugs{ |
| 7364 | BadChangeCipherSpec: []byte{2}, |
| 7365 | }, |
| 7366 | }, |
| 7367 | shouldFail: true, |
| 7368 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7369 | }) |
| 7370 | testCases = append(testCases, testCase{ |
| 7371 | name: "BadChangeCipherSpec-2", |
| 7372 | config: Config{ |
| 7373 | MaxVersion: VersionTLS12, |
| 7374 | Bugs: ProtocolBugs{ |
| 7375 | BadChangeCipherSpec: []byte{1, 1}, |
| 7376 | }, |
| 7377 | }, |
| 7378 | shouldFail: true, |
| 7379 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7380 | }) |
| 7381 | testCases = append(testCases, testCase{ |
| 7382 | protocol: dtls, |
| 7383 | name: "BadChangeCipherSpec-DTLS-1", |
| 7384 | config: Config{ |
| 7385 | MaxVersion: VersionTLS12, |
| 7386 | Bugs: ProtocolBugs{ |
| 7387 | BadChangeCipherSpec: []byte{2}, |
| 7388 | }, |
| 7389 | }, |
| 7390 | shouldFail: true, |
| 7391 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7392 | }) |
| 7393 | testCases = append(testCases, testCase{ |
| 7394 | protocol: dtls, |
| 7395 | name: "BadChangeCipherSpec-DTLS-2", |
| 7396 | config: Config{ |
| 7397 | MaxVersion: VersionTLS12, |
| 7398 | Bugs: ProtocolBugs{ |
| 7399 | BadChangeCipherSpec: []byte{1, 1}, |
| 7400 | }, |
| 7401 | }, |
| 7402 | shouldFail: true, |
| 7403 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7404 | }) |
| 7405 | } |
| 7406 | |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7407 | func addWrongMessageTypeTests() { |
| 7408 | for _, protocol := range []protocol{tls, dtls} { |
| 7409 | var suffix string |
| 7410 | if protocol == dtls { |
| 7411 | suffix = "-DTLS" |
| 7412 | } |
| 7413 | |
| 7414 | testCases = append(testCases, testCase{ |
| 7415 | protocol: protocol, |
| 7416 | testType: serverTest, |
| 7417 | name: "WrongMessageType-ClientHello" + suffix, |
| 7418 | config: Config{ |
| 7419 | MaxVersion: VersionTLS12, |
| 7420 | Bugs: ProtocolBugs{ |
| 7421 | SendWrongMessageType: typeClientHello, |
| 7422 | }, |
| 7423 | }, |
| 7424 | shouldFail: true, |
| 7425 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7426 | expectedLocalError: "remote error: unexpected message", |
| 7427 | }) |
| 7428 | |
| 7429 | if protocol == dtls { |
| 7430 | testCases = append(testCases, testCase{ |
| 7431 | protocol: protocol, |
| 7432 | name: "WrongMessageType-HelloVerifyRequest" + suffix, |
| 7433 | config: Config{ |
| 7434 | MaxVersion: VersionTLS12, |
| 7435 | Bugs: ProtocolBugs{ |
| 7436 | SendWrongMessageType: typeHelloVerifyRequest, |
| 7437 | }, |
| 7438 | }, |
| 7439 | shouldFail: true, |
| 7440 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7441 | expectedLocalError: "remote error: unexpected message", |
| 7442 | }) |
| 7443 | } |
| 7444 | |
| 7445 | testCases = append(testCases, testCase{ |
| 7446 | protocol: protocol, |
| 7447 | name: "WrongMessageType-ServerHello" + suffix, |
| 7448 | config: Config{ |
| 7449 | MaxVersion: VersionTLS12, |
| 7450 | Bugs: ProtocolBugs{ |
| 7451 | SendWrongMessageType: typeServerHello, |
| 7452 | }, |
| 7453 | }, |
| 7454 | shouldFail: true, |
| 7455 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7456 | expectedLocalError: "remote error: unexpected message", |
| 7457 | }) |
| 7458 | |
| 7459 | testCases = append(testCases, testCase{ |
| 7460 | protocol: protocol, |
| 7461 | name: "WrongMessageType-ServerCertificate" + suffix, |
| 7462 | config: Config{ |
| 7463 | MaxVersion: VersionTLS12, |
| 7464 | Bugs: ProtocolBugs{ |
| 7465 | SendWrongMessageType: typeCertificate, |
| 7466 | }, |
| 7467 | }, |
| 7468 | shouldFail: true, |
| 7469 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7470 | expectedLocalError: "remote error: unexpected message", |
| 7471 | }) |
| 7472 | |
| 7473 | testCases = append(testCases, testCase{ |
| 7474 | protocol: protocol, |
| 7475 | name: "WrongMessageType-CertificateStatus" + suffix, |
| 7476 | config: Config{ |
| 7477 | MaxVersion: VersionTLS12, |
| 7478 | Bugs: ProtocolBugs{ |
| 7479 | SendWrongMessageType: typeCertificateStatus, |
| 7480 | }, |
| 7481 | }, |
| 7482 | flags: []string{"-enable-ocsp-stapling"}, |
| 7483 | shouldFail: true, |
| 7484 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7485 | expectedLocalError: "remote error: unexpected message", |
| 7486 | }) |
| 7487 | |
| 7488 | testCases = append(testCases, testCase{ |
| 7489 | protocol: protocol, |
| 7490 | name: "WrongMessageType-ServerKeyExchange" + suffix, |
| 7491 | config: Config{ |
| 7492 | MaxVersion: VersionTLS12, |
| 7493 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7494 | Bugs: ProtocolBugs{ |
| 7495 | SendWrongMessageType: typeServerKeyExchange, |
| 7496 | }, |
| 7497 | }, |
| 7498 | shouldFail: true, |
| 7499 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7500 | expectedLocalError: "remote error: unexpected message", |
| 7501 | }) |
| 7502 | |
| 7503 | testCases = append(testCases, testCase{ |
| 7504 | protocol: protocol, |
| 7505 | name: "WrongMessageType-CertificateRequest" + suffix, |
| 7506 | config: Config{ |
| 7507 | MaxVersion: VersionTLS12, |
| 7508 | ClientAuth: RequireAnyClientCert, |
| 7509 | Bugs: ProtocolBugs{ |
| 7510 | SendWrongMessageType: typeCertificateRequest, |
| 7511 | }, |
| 7512 | }, |
| 7513 | shouldFail: true, |
| 7514 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7515 | expectedLocalError: "remote error: unexpected message", |
| 7516 | }) |
| 7517 | |
| 7518 | testCases = append(testCases, testCase{ |
| 7519 | protocol: protocol, |
| 7520 | name: "WrongMessageType-ServerHelloDone" + suffix, |
| 7521 | config: Config{ |
| 7522 | MaxVersion: VersionTLS12, |
| 7523 | Bugs: ProtocolBugs{ |
| 7524 | SendWrongMessageType: typeServerHelloDone, |
| 7525 | }, |
| 7526 | }, |
| 7527 | shouldFail: true, |
| 7528 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7529 | expectedLocalError: "remote error: unexpected message", |
| 7530 | }) |
| 7531 | |
| 7532 | testCases = append(testCases, testCase{ |
| 7533 | testType: serverTest, |
| 7534 | protocol: protocol, |
| 7535 | name: "WrongMessageType-ClientCertificate" + suffix, |
| 7536 | config: Config{ |
| 7537 | Certificates: []Certificate{rsaCertificate}, |
| 7538 | MaxVersion: VersionTLS12, |
| 7539 | Bugs: ProtocolBugs{ |
| 7540 | SendWrongMessageType: typeCertificate, |
| 7541 | }, |
| 7542 | }, |
| 7543 | flags: []string{"-require-any-client-certificate"}, |
| 7544 | shouldFail: true, |
| 7545 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7546 | expectedLocalError: "remote error: unexpected message", |
| 7547 | }) |
| 7548 | |
| 7549 | testCases = append(testCases, testCase{ |
| 7550 | testType: serverTest, |
| 7551 | protocol: protocol, |
| 7552 | name: "WrongMessageType-CertificateVerify" + suffix, |
| 7553 | config: Config{ |
| 7554 | Certificates: []Certificate{rsaCertificate}, |
| 7555 | MaxVersion: VersionTLS12, |
| 7556 | Bugs: ProtocolBugs{ |
| 7557 | SendWrongMessageType: typeCertificateVerify, |
| 7558 | }, |
| 7559 | }, |
| 7560 | flags: []string{"-require-any-client-certificate"}, |
| 7561 | shouldFail: true, |
| 7562 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7563 | expectedLocalError: "remote error: unexpected message", |
| 7564 | }) |
| 7565 | |
| 7566 | testCases = append(testCases, testCase{ |
| 7567 | testType: serverTest, |
| 7568 | protocol: protocol, |
| 7569 | name: "WrongMessageType-ClientKeyExchange" + suffix, |
| 7570 | config: Config{ |
| 7571 | MaxVersion: VersionTLS12, |
| 7572 | Bugs: ProtocolBugs{ |
| 7573 | SendWrongMessageType: typeClientKeyExchange, |
| 7574 | }, |
| 7575 | }, |
| 7576 | shouldFail: true, |
| 7577 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7578 | expectedLocalError: "remote error: unexpected message", |
| 7579 | }) |
| 7580 | |
| 7581 | if protocol != dtls { |
| 7582 | testCases = append(testCases, testCase{ |
| 7583 | testType: serverTest, |
| 7584 | protocol: protocol, |
| 7585 | name: "WrongMessageType-NextProtocol" + suffix, |
| 7586 | config: Config{ |
| 7587 | MaxVersion: VersionTLS12, |
| 7588 | NextProtos: []string{"bar"}, |
| 7589 | Bugs: ProtocolBugs{ |
| 7590 | SendWrongMessageType: typeNextProtocol, |
| 7591 | }, |
| 7592 | }, |
| 7593 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 7594 | shouldFail: true, |
| 7595 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7596 | expectedLocalError: "remote error: unexpected message", |
| 7597 | }) |
| 7598 | |
| 7599 | testCases = append(testCases, testCase{ |
| 7600 | testType: serverTest, |
| 7601 | protocol: protocol, |
| 7602 | name: "WrongMessageType-ChannelID" + suffix, |
| 7603 | config: Config{ |
| 7604 | MaxVersion: VersionTLS12, |
| 7605 | ChannelID: channelIDKey, |
| 7606 | Bugs: ProtocolBugs{ |
| 7607 | SendWrongMessageType: typeChannelID, |
| 7608 | }, |
| 7609 | }, |
| 7610 | flags: []string{ |
| 7611 | "-expect-channel-id", |
| 7612 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 7613 | }, |
| 7614 | shouldFail: true, |
| 7615 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7616 | expectedLocalError: "remote error: unexpected message", |
| 7617 | }) |
| 7618 | } |
| 7619 | |
| 7620 | testCases = append(testCases, testCase{ |
| 7621 | testType: serverTest, |
| 7622 | protocol: protocol, |
| 7623 | name: "WrongMessageType-ClientFinished" + suffix, |
| 7624 | config: Config{ |
| 7625 | MaxVersion: VersionTLS12, |
| 7626 | Bugs: ProtocolBugs{ |
| 7627 | SendWrongMessageType: typeFinished, |
| 7628 | }, |
| 7629 | }, |
| 7630 | shouldFail: true, |
| 7631 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7632 | expectedLocalError: "remote error: unexpected message", |
| 7633 | }) |
| 7634 | |
| 7635 | testCases = append(testCases, testCase{ |
| 7636 | protocol: protocol, |
| 7637 | name: "WrongMessageType-NewSessionTicket" + suffix, |
| 7638 | config: Config{ |
| 7639 | MaxVersion: VersionTLS12, |
| 7640 | Bugs: ProtocolBugs{ |
| 7641 | SendWrongMessageType: typeNewSessionTicket, |
| 7642 | }, |
| 7643 | }, |
| 7644 | shouldFail: true, |
| 7645 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7646 | expectedLocalError: "remote error: unexpected message", |
| 7647 | }) |
| 7648 | |
| 7649 | testCases = append(testCases, testCase{ |
| 7650 | protocol: protocol, |
| 7651 | name: "WrongMessageType-ServerFinished" + suffix, |
| 7652 | config: Config{ |
| 7653 | MaxVersion: VersionTLS12, |
| 7654 | Bugs: ProtocolBugs{ |
| 7655 | SendWrongMessageType: typeFinished, |
| 7656 | }, |
| 7657 | }, |
| 7658 | shouldFail: true, |
| 7659 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7660 | expectedLocalError: "remote error: unexpected message", |
| 7661 | }) |
| 7662 | |
| 7663 | } |
| 7664 | } |
| 7665 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7666 | func addTLS13WrongMessageTypeTests() { |
| 7667 | testCases = append(testCases, testCase{ |
| 7668 | testType: serverTest, |
| 7669 | name: "WrongMessageType-TLS13-ClientHello", |
| 7670 | config: Config{ |
| 7671 | MaxVersion: VersionTLS13, |
| 7672 | Bugs: ProtocolBugs{ |
| 7673 | SendWrongMessageType: typeClientHello, |
| 7674 | }, |
| 7675 | }, |
| 7676 | shouldFail: true, |
| 7677 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7678 | expectedLocalError: "remote error: unexpected message", |
| 7679 | }) |
| 7680 | |
| 7681 | testCases = append(testCases, testCase{ |
| 7682 | name: "WrongMessageType-TLS13-ServerHello", |
| 7683 | config: Config{ |
| 7684 | MaxVersion: VersionTLS13, |
| 7685 | Bugs: ProtocolBugs{ |
| 7686 | SendWrongMessageType: typeServerHello, |
| 7687 | }, |
| 7688 | }, |
| 7689 | shouldFail: true, |
| 7690 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7691 | // The alert comes in with the wrong encryption. |
| 7692 | expectedLocalError: "local error: bad record MAC", |
| 7693 | }) |
| 7694 | |
| 7695 | testCases = append(testCases, testCase{ |
| 7696 | name: "WrongMessageType-TLS13-EncryptedExtensions", |
| 7697 | config: Config{ |
| 7698 | MaxVersion: VersionTLS13, |
| 7699 | Bugs: ProtocolBugs{ |
| 7700 | SendWrongMessageType: typeEncryptedExtensions, |
| 7701 | }, |
| 7702 | }, |
| 7703 | shouldFail: true, |
| 7704 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7705 | expectedLocalError: "remote error: unexpected message", |
| 7706 | }) |
| 7707 | |
| 7708 | testCases = append(testCases, testCase{ |
| 7709 | name: "WrongMessageType-TLS13-CertificateRequest", |
| 7710 | config: Config{ |
| 7711 | MaxVersion: VersionTLS13, |
| 7712 | ClientAuth: RequireAnyClientCert, |
| 7713 | Bugs: ProtocolBugs{ |
| 7714 | SendWrongMessageType: typeCertificateRequest, |
| 7715 | }, |
| 7716 | }, |
| 7717 | shouldFail: true, |
| 7718 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7719 | expectedLocalError: "remote error: unexpected message", |
| 7720 | }) |
| 7721 | |
| 7722 | testCases = append(testCases, testCase{ |
| 7723 | name: "WrongMessageType-TLS13-ServerCertificate", |
| 7724 | config: Config{ |
| 7725 | MaxVersion: VersionTLS13, |
| 7726 | Bugs: ProtocolBugs{ |
| 7727 | SendWrongMessageType: typeCertificate, |
| 7728 | }, |
| 7729 | }, |
| 7730 | shouldFail: true, |
| 7731 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7732 | expectedLocalError: "remote error: unexpected message", |
| 7733 | }) |
| 7734 | |
| 7735 | testCases = append(testCases, testCase{ |
| 7736 | name: "WrongMessageType-TLS13-ServerCertificateVerify", |
| 7737 | config: Config{ |
| 7738 | MaxVersion: VersionTLS13, |
| 7739 | Bugs: ProtocolBugs{ |
| 7740 | SendWrongMessageType: typeCertificateVerify, |
| 7741 | }, |
| 7742 | }, |
| 7743 | shouldFail: true, |
| 7744 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7745 | expectedLocalError: "remote error: unexpected message", |
| 7746 | }) |
| 7747 | |
| 7748 | testCases = append(testCases, testCase{ |
| 7749 | name: "WrongMessageType-TLS13-ServerFinished", |
| 7750 | config: Config{ |
| 7751 | MaxVersion: VersionTLS13, |
| 7752 | Bugs: ProtocolBugs{ |
| 7753 | SendWrongMessageType: typeFinished, |
| 7754 | }, |
| 7755 | }, |
| 7756 | shouldFail: true, |
| 7757 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7758 | expectedLocalError: "remote error: unexpected message", |
| 7759 | }) |
| 7760 | |
| 7761 | testCases = append(testCases, testCase{ |
| 7762 | testType: serverTest, |
| 7763 | name: "WrongMessageType-TLS13-ClientCertificate", |
| 7764 | config: Config{ |
| 7765 | Certificates: []Certificate{rsaCertificate}, |
| 7766 | MaxVersion: VersionTLS13, |
| 7767 | Bugs: ProtocolBugs{ |
| 7768 | SendWrongMessageType: typeCertificate, |
| 7769 | }, |
| 7770 | }, |
| 7771 | flags: []string{"-require-any-client-certificate"}, |
| 7772 | shouldFail: true, |
| 7773 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7774 | expectedLocalError: "remote error: unexpected message", |
| 7775 | }) |
| 7776 | |
| 7777 | testCases = append(testCases, testCase{ |
| 7778 | testType: serverTest, |
| 7779 | name: "WrongMessageType-TLS13-ClientCertificateVerify", |
| 7780 | config: Config{ |
| 7781 | Certificates: []Certificate{rsaCertificate}, |
| 7782 | MaxVersion: VersionTLS13, |
| 7783 | Bugs: ProtocolBugs{ |
| 7784 | SendWrongMessageType: typeCertificateVerify, |
| 7785 | }, |
| 7786 | }, |
| 7787 | flags: []string{"-require-any-client-certificate"}, |
| 7788 | shouldFail: true, |
| 7789 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7790 | expectedLocalError: "remote error: unexpected message", |
| 7791 | }) |
| 7792 | |
| 7793 | testCases = append(testCases, testCase{ |
| 7794 | testType: serverTest, |
| 7795 | name: "WrongMessageType-TLS13-ClientFinished", |
| 7796 | config: Config{ |
| 7797 | MaxVersion: VersionTLS13, |
| 7798 | Bugs: ProtocolBugs{ |
| 7799 | SendWrongMessageType: typeFinished, |
| 7800 | }, |
| 7801 | }, |
| 7802 | shouldFail: true, |
| 7803 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7804 | expectedLocalError: "remote error: unexpected message", |
| 7805 | }) |
| 7806 | } |
| 7807 | |
| 7808 | func addTLS13HandshakeTests() { |
| 7809 | testCases = append(testCases, testCase{ |
| 7810 | testType: clientTest, |
| 7811 | name: "MissingKeyShare-Client", |
| 7812 | config: Config{ |
| 7813 | MaxVersion: VersionTLS13, |
| 7814 | Bugs: ProtocolBugs{ |
| 7815 | MissingKeyShare: true, |
| 7816 | }, |
| 7817 | }, |
| 7818 | shouldFail: true, |
| 7819 | expectedError: ":MISSING_KEY_SHARE:", |
| 7820 | }) |
| 7821 | |
| 7822 | testCases = append(testCases, testCase{ |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7823 | testType: serverTest, |
| 7824 | name: "MissingKeyShare-Server", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7825 | config: Config{ |
| 7826 | MaxVersion: VersionTLS13, |
| 7827 | Bugs: ProtocolBugs{ |
| 7828 | MissingKeyShare: true, |
| 7829 | }, |
| 7830 | }, |
| 7831 | shouldFail: true, |
| 7832 | expectedError: ":MISSING_KEY_SHARE:", |
| 7833 | }) |
| 7834 | |
| 7835 | testCases = append(testCases, testCase{ |
| 7836 | testType: clientTest, |
| 7837 | name: "ClientHelloMissingKeyShare", |
| 7838 | config: Config{ |
| 7839 | MaxVersion: VersionTLS13, |
| 7840 | Bugs: ProtocolBugs{ |
| 7841 | MissingKeyShare: true, |
| 7842 | }, |
| 7843 | }, |
| 7844 | shouldFail: true, |
| 7845 | expectedError: ":MISSING_KEY_SHARE:", |
| 7846 | }) |
| 7847 | |
| 7848 | testCases = append(testCases, testCase{ |
| 7849 | testType: clientTest, |
| 7850 | name: "MissingKeyShare", |
| 7851 | config: Config{ |
| 7852 | MaxVersion: VersionTLS13, |
| 7853 | Bugs: ProtocolBugs{ |
| 7854 | MissingKeyShare: true, |
| 7855 | }, |
| 7856 | }, |
| 7857 | shouldFail: true, |
| 7858 | expectedError: ":MISSING_KEY_SHARE:", |
| 7859 | }) |
| 7860 | |
| 7861 | testCases = append(testCases, testCase{ |
| 7862 | testType: serverTest, |
| 7863 | name: "DuplicateKeyShares", |
| 7864 | config: Config{ |
| 7865 | MaxVersion: VersionTLS13, |
| 7866 | Bugs: ProtocolBugs{ |
| 7867 | DuplicateKeyShares: true, |
| 7868 | }, |
| 7869 | }, |
| 7870 | }) |
| 7871 | |
| 7872 | testCases = append(testCases, testCase{ |
| 7873 | testType: clientTest, |
| 7874 | name: "EmptyEncryptedExtensions", |
| 7875 | config: Config{ |
| 7876 | MaxVersion: VersionTLS13, |
| 7877 | Bugs: ProtocolBugs{ |
| 7878 | EmptyEncryptedExtensions: true, |
| 7879 | }, |
| 7880 | }, |
| 7881 | shouldFail: true, |
| 7882 | expectedLocalError: "remote error: error decoding message", |
| 7883 | }) |
| 7884 | |
| 7885 | testCases = append(testCases, testCase{ |
| 7886 | testType: clientTest, |
| 7887 | name: "EncryptedExtensionsWithKeyShare", |
| 7888 | config: Config{ |
| 7889 | MaxVersion: VersionTLS13, |
| 7890 | Bugs: ProtocolBugs{ |
| 7891 | EncryptedExtensionsWithKeyShare: true, |
| 7892 | }, |
| 7893 | }, |
| 7894 | shouldFail: true, |
| 7895 | expectedLocalError: "remote error: unsupported extension", |
| 7896 | }) |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7897 | |
| 7898 | testCases = append(testCases, testCase{ |
| 7899 | testType: serverTest, |
| 7900 | name: "SendHelloRetryRequest", |
| 7901 | config: Config{ |
| 7902 | MaxVersion: VersionTLS13, |
| 7903 | // Require a HelloRetryRequest for every curve. |
| 7904 | DefaultCurves: []CurveID{}, |
| 7905 | }, |
| 7906 | expectedCurveID: CurveX25519, |
| 7907 | }) |
| 7908 | |
| 7909 | testCases = append(testCases, testCase{ |
| 7910 | testType: serverTest, |
| 7911 | name: "SendHelloRetryRequest-2", |
| 7912 | config: Config{ |
| 7913 | MaxVersion: VersionTLS13, |
| 7914 | DefaultCurves: []CurveID{CurveP384}, |
| 7915 | }, |
| 7916 | // Although the ClientHello did not predict our preferred curve, |
| 7917 | // we always select it whether it is predicted or not. |
| 7918 | expectedCurveID: CurveX25519, |
| 7919 | }) |
| 7920 | |
| 7921 | testCases = append(testCases, testCase{ |
| 7922 | name: "UnknownCurve-HelloRetryRequest", |
| 7923 | config: Config{ |
| 7924 | MaxVersion: VersionTLS13, |
| 7925 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7926 | CurvePreferences: []CurveID{CurveP384}, |
| 7927 | Bugs: ProtocolBugs{ |
| 7928 | SendHelloRetryRequestCurve: bogusCurve, |
| 7929 | }, |
| 7930 | }, |
| 7931 | shouldFail: true, |
| 7932 | expectedError: ":WRONG_CURVE:", |
| 7933 | }) |
| 7934 | |
| 7935 | testCases = append(testCases, testCase{ |
| 7936 | name: "DisabledCurve-HelloRetryRequest", |
| 7937 | config: Config{ |
| 7938 | MaxVersion: VersionTLS13, |
| 7939 | CurvePreferences: []CurveID{CurveP256}, |
| 7940 | Bugs: ProtocolBugs{ |
| 7941 | IgnorePeerCurvePreferences: true, |
| 7942 | }, |
| 7943 | }, |
| 7944 | flags: []string{"-p384-only"}, |
| 7945 | shouldFail: true, |
| 7946 | expectedError: ":WRONG_CURVE:", |
| 7947 | }) |
| 7948 | |
| 7949 | testCases = append(testCases, testCase{ |
| 7950 | name: "UnnecessaryHelloRetryRequest", |
| 7951 | config: Config{ |
| 7952 | MaxVersion: VersionTLS13, |
| 7953 | Bugs: ProtocolBugs{ |
| 7954 | UnnecessaryHelloRetryRequest: true, |
| 7955 | }, |
| 7956 | }, |
| 7957 | shouldFail: true, |
| 7958 | expectedError: ":WRONG_CURVE:", |
| 7959 | }) |
| 7960 | |
| 7961 | testCases = append(testCases, testCase{ |
| 7962 | name: "SecondHelloRetryRequest", |
| 7963 | config: Config{ |
| 7964 | MaxVersion: VersionTLS13, |
| 7965 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7966 | CurvePreferences: []CurveID{CurveP384}, |
| 7967 | Bugs: ProtocolBugs{ |
| 7968 | SecondHelloRetryRequest: true, |
| 7969 | }, |
| 7970 | }, |
| 7971 | shouldFail: true, |
| 7972 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7973 | }) |
| 7974 | |
| 7975 | testCases = append(testCases, testCase{ |
| 7976 | testType: serverTest, |
| 7977 | name: "SecondClientHelloMissingKeyShare", |
| 7978 | config: Config{ |
| 7979 | MaxVersion: VersionTLS13, |
| 7980 | DefaultCurves: []CurveID{}, |
| 7981 | Bugs: ProtocolBugs{ |
| 7982 | SecondClientHelloMissingKeyShare: true, |
| 7983 | }, |
| 7984 | }, |
| 7985 | shouldFail: true, |
| 7986 | expectedError: ":MISSING_KEY_SHARE:", |
| 7987 | }) |
| 7988 | |
| 7989 | testCases = append(testCases, testCase{ |
| 7990 | testType: serverTest, |
| 7991 | name: "SecondClientHelloWrongCurve", |
| 7992 | config: Config{ |
| 7993 | MaxVersion: VersionTLS13, |
| 7994 | DefaultCurves: []CurveID{}, |
| 7995 | Bugs: ProtocolBugs{ |
| 7996 | MisinterpretHelloRetryRequestCurve: CurveP521, |
| 7997 | }, |
| 7998 | }, |
| 7999 | shouldFail: true, |
| 8000 | expectedError: ":WRONG_CURVE:", |
| 8001 | }) |
| 8002 | |
| 8003 | testCases = append(testCases, testCase{ |
| 8004 | name: "HelloRetryRequestVersionMismatch", |
| 8005 | config: Config{ |
| 8006 | MaxVersion: VersionTLS13, |
| 8007 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8008 | CurvePreferences: []CurveID{CurveP384}, |
| 8009 | Bugs: ProtocolBugs{ |
| 8010 | SendServerHelloVersion: 0x0305, |
| 8011 | }, |
| 8012 | }, |
| 8013 | shouldFail: true, |
| 8014 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 8015 | }) |
| 8016 | |
| 8017 | testCases = append(testCases, testCase{ |
| 8018 | name: "HelloRetryRequestCurveMismatch", |
| 8019 | config: Config{ |
| 8020 | MaxVersion: VersionTLS13, |
| 8021 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8022 | CurvePreferences: []CurveID{CurveP384}, |
| 8023 | Bugs: ProtocolBugs{ |
| 8024 | // Send P-384 (correct) in the HelloRetryRequest. |
| 8025 | SendHelloRetryRequestCurve: CurveP384, |
| 8026 | // But send P-256 in the ServerHello. |
| 8027 | SendCurve: CurveP256, |
| 8028 | }, |
| 8029 | }, |
| 8030 | shouldFail: true, |
| 8031 | expectedError: ":WRONG_CURVE:", |
| 8032 | }) |
| 8033 | |
| 8034 | // Test the server selecting a curve that requires a HelloRetryRequest |
| 8035 | // without sending it. |
| 8036 | testCases = append(testCases, testCase{ |
| 8037 | name: "SkipHelloRetryRequest", |
| 8038 | config: Config{ |
| 8039 | MaxVersion: VersionTLS13, |
| 8040 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 8041 | CurvePreferences: []CurveID{CurveP384}, |
| 8042 | Bugs: ProtocolBugs{ |
| 8043 | SkipHelloRetryRequest: true, |
| 8044 | }, |
| 8045 | }, |
| 8046 | shouldFail: true, |
| 8047 | expectedError: ":WRONG_CURVE:", |
| 8048 | }) |
David Benjamin | 8a8349b | 2016-08-18 02:32:23 -0400 | [diff] [blame] | 8049 | |
| 8050 | testCases = append(testCases, testCase{ |
| 8051 | name: "TLS13-RequestContextInHandshake", |
| 8052 | config: Config{ |
| 8053 | MaxVersion: VersionTLS13, |
| 8054 | MinVersion: VersionTLS13, |
| 8055 | ClientAuth: RequireAnyClientCert, |
| 8056 | Bugs: ProtocolBugs{ |
| 8057 | SendRequestContext: []byte("request context"), |
| 8058 | }, |
| 8059 | }, |
| 8060 | flags: []string{ |
| 8061 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 8062 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 8063 | }, |
| 8064 | shouldFail: true, |
| 8065 | expectedError: ":DECODE_ERROR:", |
| 8066 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8067 | } |
| 8068 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8069 | 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] | 8070 | defer wg.Done() |
| 8071 | |
| 8072 | for test := range c { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 8073 | var err error |
| 8074 | |
| 8075 | if *mallocTest < 0 { |
| 8076 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8077 | err = runTest(test, shimPath, -1) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 8078 | } else { |
| 8079 | for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ { |
| 8080 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8081 | if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 8082 | if err != nil { |
| 8083 | fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err) |
| 8084 | } |
| 8085 | break |
| 8086 | } |
| 8087 | } |
| 8088 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8089 | statusChan <- statusMsg{test: test, err: err} |
| 8090 | } |
| 8091 | } |
| 8092 | |
| 8093 | type statusMsg struct { |
| 8094 | test *testCase |
| 8095 | started bool |
| 8096 | err error |
| 8097 | } |
| 8098 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8099 | func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8100 | var started, done, failed, unimplemented, lineLen int |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8101 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8102 | testOutput := newTestOutput() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8103 | for msg := range statusChan { |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8104 | if !*pipe { |
| 8105 | // Erase the previous status line. |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 8106 | var erase string |
| 8107 | for i := 0; i < lineLen; i++ { |
| 8108 | erase += "\b \b" |
| 8109 | } |
| 8110 | fmt.Print(erase) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8111 | } |
| 8112 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8113 | if msg.started { |
| 8114 | started++ |
| 8115 | } else { |
| 8116 | done++ |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8117 | |
| 8118 | if msg.err != nil { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8119 | if msg.err == errUnimplemented { |
| 8120 | if *pipe { |
| 8121 | // Print each test instead of a status line. |
| 8122 | fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name) |
| 8123 | } |
| 8124 | unimplemented++ |
| 8125 | testOutput.addResult(msg.test.name, "UNIMPLEMENTED") |
| 8126 | } else { |
| 8127 | fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err) |
| 8128 | failed++ |
| 8129 | testOutput.addResult(msg.test.name, "FAIL") |
| 8130 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8131 | } else { |
| 8132 | if *pipe { |
| 8133 | // Print each test instead of a status line. |
| 8134 | fmt.Printf("PASSED (%s)\n", msg.test.name) |
| 8135 | } |
| 8136 | testOutput.addResult(msg.test.name, "PASS") |
| 8137 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8138 | } |
| 8139 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8140 | if !*pipe { |
| 8141 | // Print a new status line. |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8142 | 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] | 8143 | lineLen = len(line) |
| 8144 | os.Stdout.WriteString(line) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8145 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8146 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8147 | |
| 8148 | doneChan <- testOutput |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8149 | } |
| 8150 | |
| 8151 | func main() { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8152 | flag.Parse() |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8153 | *resourceDir = path.Clean(*resourceDir) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 8154 | initCertificates() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8155 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8156 | addBasicTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8157 | addCipherSuiteTests() |
| 8158 | addBadECDSASignatureTests() |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8159 | addCBCPaddingTests() |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 8160 | addCBCSplittingTests() |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 8161 | addClientAuthTests() |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 8162 | addDDoSCallbackTests() |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 8163 | addVersionNegotiationTests() |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 8164 | addMinimumVersionTests() |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 8165 | addExtensionTests() |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 8166 | addResumptionVersionTests() |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 8167 | addExtendedMasterSecretTests() |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 8168 | addRenegotiationTests() |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 8169 | addDTLSReplayTests() |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 8170 | addSignatureAlgorithmTests() |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 8171 | addDTLSRetransmitTests() |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 8172 | addExportKeyingMaterialTests() |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 8173 | addTLSUniqueTests() |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 8174 | addCustomExtensionTests() |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 8175 | addRSAClientKeyExchangeTests() |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 8176 | addCurveTests() |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 8177 | addCECPQ1Tests() |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 8178 | addKeyExchangeInfoTests() |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 8179 | addTLS13RecordTests() |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 8180 | addAllStateMachineCoverageTests() |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 8181 | addChangeCipherSpecTests() |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 8182 | addWrongMessageTypeTests() |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 8183 | addTLS13WrongMessageTypeTests() |
| 8184 | addTLS13HandshakeTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8185 | |
| 8186 | var wg sync.WaitGroup |
| 8187 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8188 | statusChan := make(chan statusMsg, *numWorkers) |
| 8189 | testChan := make(chan *testCase, *numWorkers) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8190 | doneChan := make(chan *testOutput) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8191 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8192 | if len(*shimConfigFile) != 0 { |
| 8193 | encoded, err := ioutil.ReadFile(*shimConfigFile) |
| 8194 | if err != nil { |
| 8195 | fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err) |
| 8196 | os.Exit(1) |
| 8197 | } |
| 8198 | |
| 8199 | if err := json.Unmarshal(encoded, &shimConfig); err != nil { |
| 8200 | fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err) |
| 8201 | os.Exit(1) |
| 8202 | } |
| 8203 | } |
| 8204 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8205 | go statusPrinter(doneChan, statusChan, len(testCases)) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8206 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8207 | for i := 0; i < *numWorkers; i++ { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8208 | wg.Add(1) |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 8209 | go worker(statusChan, testChan, *shimPath, &wg) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8210 | } |
| 8211 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8212 | var foundTest bool |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8213 | for i := range testCases { |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8214 | matched := true |
| 8215 | if len(*testToRun) != 0 { |
| 8216 | var err error |
| 8217 | matched, err = filepath.Match(*testToRun, testCases[i].name) |
| 8218 | if err != nil { |
| 8219 | fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err) |
| 8220 | os.Exit(1) |
| 8221 | } |
| 8222 | } |
| 8223 | |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8224 | if !*includeDisabled { |
| 8225 | for pattern := range shimConfig.DisabledTests { |
| 8226 | isDisabled, err := filepath.Match(pattern, testCases[i].name) |
| 8227 | if err != nil { |
| 8228 | fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err) |
| 8229 | os.Exit(1) |
| 8230 | } |
| 8231 | |
| 8232 | if isDisabled { |
| 8233 | matched = false |
| 8234 | break |
| 8235 | } |
| 8236 | } |
| 8237 | } |
| 8238 | |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8239 | if matched { |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8240 | foundTest = true |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 8241 | testChan <- &testCases[i] |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8242 | } |
| 8243 | } |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 8244 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8245 | if !foundTest { |
EKR | f71d7ed | 2016-08-06 13:25:12 -0700 | [diff] [blame] | 8246 | fmt.Fprintf(os.Stderr, "No tests run\n") |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 8247 | os.Exit(1) |
| 8248 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8249 | |
| 8250 | close(testChan) |
| 8251 | wg.Wait() |
| 8252 | close(statusChan) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8253 | testOutput := <-doneChan |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8254 | |
| 8255 | fmt.Printf("\n") |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 8256 | |
| 8257 | if *jsonOutput != "" { |
| 8258 | if err := testOutput.writeTo(*jsonOutput); err != nil { |
| 8259 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 8260 | } |
| 8261 | } |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 8262 | |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 8263 | if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 { |
| 8264 | os.Exit(1) |
| 8265 | } |
| 8266 | |
| 8267 | if !testOutput.noneFailed { |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 8268 | os.Exit(1) |
| 8269 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 8270 | } |