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" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 23 | "encoding/pem" |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 24 | "errors" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 25 | "flag" |
| 26 | "fmt" |
| 27 | "io" |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 28 | "io/ioutil" |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 29 | "math/big" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 30 | "net" |
| 31 | "os" |
| 32 | "os/exec" |
David Benjamin | 884fdf1 | 2014-08-02 15:28:23 -0400 | [diff] [blame] | 33 | "path" |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 34 | "path/filepath" |
David Benjamin | 2bc8e6f | 2014-08-02 15:22:37 -0400 | [diff] [blame] | 35 | "runtime" |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 36 | "strconv" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 37 | "strings" |
| 38 | "sync" |
| 39 | "syscall" |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 40 | "time" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 41 | ) |
| 42 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 43 | var ( |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 44 | useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind") |
| 45 | useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb") |
| 46 | useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb") |
| 47 | flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection") |
| 48 | mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.") |
| 49 | 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.") |
| 50 | jsonOutput = flag.String("json-output", "", "The file to output JSON results to.") |
| 51 | 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] | 52 | 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] | 53 | numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.") |
| 54 | shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.") |
| 55 | resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.") |
| 56 | fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.") |
| 57 | transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.") |
| 58 | idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.") |
| 59 | deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.") |
| 60 | 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] | 61 | looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 62 | ) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 63 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 64 | type testCert int |
| 65 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 66 | const ( |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 67 | testCertRSA testCert = iota |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 68 | testCertRSA1024 |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 69 | testCertECDSAP256 |
| 70 | testCertECDSAP384 |
| 71 | testCertECDSAP521 |
| 72 | ) |
| 73 | |
| 74 | const ( |
| 75 | rsaCertificateFile = "cert.pem" |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 76 | rsa1024CertificateFile = "rsa_1024_cert.pem" |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 77 | ecdsaP256CertificateFile = "ecdsa_p256_cert.pem" |
| 78 | ecdsaP384CertificateFile = "ecdsa_p384_cert.pem" |
| 79 | ecdsaP521CertificateFile = "ecdsa_p521_cert.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 80 | ) |
| 81 | |
| 82 | const ( |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 83 | rsaKeyFile = "key.pem" |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 84 | rsa1024KeyFile = "rsa_1024_key.pem" |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 85 | ecdsaP256KeyFile = "ecdsa_p256_key.pem" |
| 86 | ecdsaP384KeyFile = "ecdsa_p384_key.pem" |
| 87 | ecdsaP521KeyFile = "ecdsa_p521_key.pem" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 88 | channelIDKeyFile = "channel_id_key.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 89 | ) |
| 90 | |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 91 | var ( |
| 92 | rsaCertificate Certificate |
| 93 | rsa1024Certificate Certificate |
| 94 | ecdsaP256Certificate Certificate |
| 95 | ecdsaP384Certificate Certificate |
| 96 | ecdsaP521Certificate Certificate |
| 97 | ) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 98 | |
| 99 | var testCerts = []struct { |
| 100 | id testCert |
| 101 | certFile, keyFile string |
| 102 | cert *Certificate |
| 103 | }{ |
| 104 | { |
| 105 | id: testCertRSA, |
| 106 | certFile: rsaCertificateFile, |
| 107 | keyFile: rsaKeyFile, |
| 108 | cert: &rsaCertificate, |
| 109 | }, |
| 110 | { |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 111 | id: testCertRSA1024, |
| 112 | certFile: rsa1024CertificateFile, |
| 113 | keyFile: rsa1024KeyFile, |
| 114 | cert: &rsa1024Certificate, |
| 115 | }, |
| 116 | { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 117 | id: testCertECDSAP256, |
| 118 | certFile: ecdsaP256CertificateFile, |
| 119 | keyFile: ecdsaP256KeyFile, |
| 120 | cert: &ecdsaP256Certificate, |
| 121 | }, |
| 122 | { |
| 123 | id: testCertECDSAP384, |
| 124 | certFile: ecdsaP384CertificateFile, |
| 125 | keyFile: ecdsaP384KeyFile, |
| 126 | cert: &ecdsaP384Certificate, |
| 127 | }, |
| 128 | { |
| 129 | id: testCertECDSAP521, |
| 130 | certFile: ecdsaP521CertificateFile, |
| 131 | keyFile: ecdsaP521KeyFile, |
| 132 | cert: &ecdsaP521Certificate, |
| 133 | }, |
| 134 | } |
| 135 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 136 | var channelIDKey *ecdsa.PrivateKey |
| 137 | var channelIDBytes []byte |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 138 | |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 139 | var testOCSPResponse = []byte{1, 2, 3, 4} |
| 140 | var testSCTList = []byte{5, 6, 7, 8} |
| 141 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 142 | func initCertificates() { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 143 | for i := range testCerts { |
| 144 | cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile)) |
| 145 | if err != nil { |
| 146 | panic(err) |
| 147 | } |
| 148 | cert.OCSPStaple = testOCSPResponse |
| 149 | cert.SignedCertificateTimestampList = testSCTList |
| 150 | *testCerts[i].cert = cert |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 151 | } |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 152 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 153 | channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile)) |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 154 | if err != nil { |
| 155 | panic(err) |
| 156 | } |
| 157 | channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock) |
| 158 | if channelIDDERBlock.Type != "EC PRIVATE KEY" { |
| 159 | panic("bad key type") |
| 160 | } |
| 161 | channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes) |
| 162 | if err != nil { |
| 163 | panic(err) |
| 164 | } |
| 165 | if channelIDKey.Curve != elliptic.P256() { |
| 166 | panic("bad curve") |
| 167 | } |
| 168 | |
| 169 | channelIDBytes = make([]byte, 64) |
| 170 | writeIntPadded(channelIDBytes[:32], channelIDKey.X) |
| 171 | writeIntPadded(channelIDBytes[32:], channelIDKey.Y) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 172 | } |
| 173 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 174 | func getRunnerCertificate(t testCert) Certificate { |
| 175 | for _, cert := range testCerts { |
| 176 | if cert.id == t { |
| 177 | return *cert.cert |
| 178 | } |
| 179 | } |
| 180 | panic("Unknown test certificate") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 181 | } |
| 182 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 183 | func getShimCertificate(t testCert) string { |
| 184 | for _, cert := range testCerts { |
| 185 | if cert.id == t { |
| 186 | return cert.certFile |
| 187 | } |
| 188 | } |
| 189 | panic("Unknown test certificate") |
| 190 | } |
| 191 | |
| 192 | func getShimKey(t testCert) string { |
| 193 | for _, cert := range testCerts { |
| 194 | if cert.id == t { |
| 195 | return cert.keyFile |
| 196 | } |
| 197 | } |
| 198 | panic("Unknown test certificate") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 199 | } |
| 200 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 201 | type testType int |
| 202 | |
| 203 | const ( |
| 204 | clientTest testType = iota |
| 205 | serverTest |
| 206 | ) |
| 207 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 208 | type protocol int |
| 209 | |
| 210 | const ( |
| 211 | tls protocol = iota |
| 212 | dtls |
| 213 | ) |
| 214 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 215 | const ( |
| 216 | alpn = 1 |
| 217 | npn = 2 |
| 218 | ) |
| 219 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 220 | type testCase struct { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 221 | testType testType |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 222 | protocol protocol |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 223 | name string |
| 224 | config Config |
| 225 | shouldFail bool |
| 226 | expectedError string |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 227 | // expectedLocalError, if not empty, contains a substring that must be |
| 228 | // found in the local error. |
| 229 | expectedLocalError string |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 230 | // expectedVersion, if non-zero, specifies the TLS version that must be |
| 231 | // negotiated. |
| 232 | expectedVersion uint16 |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 233 | // expectedResumeVersion, if non-zero, specifies the TLS version that |
| 234 | // must be negotiated on resumption. If zero, expectedVersion is used. |
| 235 | expectedResumeVersion uint16 |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 236 | // expectedCipher, if non-zero, specifies the TLS cipher suite that |
| 237 | // should be negotiated. |
| 238 | expectedCipher uint16 |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 239 | // expectChannelID controls whether the connection should have |
| 240 | // negotiated a Channel ID with channelIDKey. |
| 241 | expectChannelID bool |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 242 | // expectedNextProto controls whether the connection should |
| 243 | // negotiate a next protocol via NPN or ALPN. |
| 244 | expectedNextProto string |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 245 | // expectNoNextProto, if true, means that no next protocol should be |
| 246 | // negotiated. |
| 247 | expectNoNextProto bool |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 248 | // expectedNextProtoType, if non-zero, is the expected next |
| 249 | // protocol negotiation mechanism. |
| 250 | expectedNextProtoType int |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 251 | // expectedSRTPProtectionProfile is the DTLS-SRTP profile that |
| 252 | // should be negotiated. If zero, none should be negotiated. |
| 253 | expectedSRTPProtectionProfile uint16 |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 254 | // expectedOCSPResponse, if not nil, is the expected OCSP response to be received. |
| 255 | expectedOCSPResponse []uint8 |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 256 | // expectedSCTList, if not nil, is the expected SCT list to be received. |
| 257 | expectedSCTList []uint8 |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 258 | // expectedPeerSignatureAlgorithm, if not zero, is the signature |
| 259 | // algorithm that the peer should have used in the handshake. |
| 260 | expectedPeerSignatureAlgorithm signatureAlgorithm |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 261 | // expectedCurveID, if not zero, is the curve that the handshake should |
| 262 | // have used. |
| 263 | expectedCurveID CurveID |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 264 | // messageLen is the length, in bytes, of the test message that will be |
| 265 | // sent. |
| 266 | messageLen int |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 267 | // messageCount is the number of test messages that will be sent. |
| 268 | messageCount int |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 269 | // certFile is the path to the certificate to use for the server. |
| 270 | certFile string |
| 271 | // keyFile is the path to the private key to use for the server. |
| 272 | keyFile string |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 273 | // resumeSession controls whether a second connection should be tested |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 274 | // which attempts to resume the first session. |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 275 | resumeSession bool |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 276 | // expectResumeRejected, if true, specifies that the attempted |
| 277 | // resumption must be rejected by the client. This is only valid for a |
| 278 | // serverTest. |
| 279 | expectResumeRejected bool |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 280 | // resumeConfig, if not nil, points to a Config to be used on |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 281 | // resumption. Unless newSessionsOnResume is set, |
| 282 | // SessionTicketKey, ServerSessionCache, and |
| 283 | // ClientSessionCache are copied from the initial connection's |
| 284 | // config. If nil, the initial connection's config is used. |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 285 | resumeConfig *Config |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 286 | // newSessionsOnResume, if true, will cause resumeConfig to |
| 287 | // use a different session resumption context. |
| 288 | newSessionsOnResume bool |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 289 | // noSessionCache, if true, will cause the server to run without a |
| 290 | // session cache. |
| 291 | noSessionCache bool |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 292 | // sendPrefix sends a prefix on the socket before actually performing a |
| 293 | // handshake. |
| 294 | sendPrefix string |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 295 | // shimWritesFirst controls whether the shim sends an initial "hello" |
| 296 | // message before doing a roundtrip with the runner. |
| 297 | shimWritesFirst bool |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 298 | // shimShutsDown, if true, runs a test where the shim shuts down the |
| 299 | // connection immediately after the handshake rather than echoing |
| 300 | // messages from the runner. |
| 301 | shimShutsDown bool |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 302 | // renegotiate indicates the number of times the connection should be |
| 303 | // renegotiated during the exchange. |
| 304 | renegotiate int |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 305 | // sendHalfHelloRequest, if true, causes the server to send half a |
| 306 | // HelloRequest when the handshake completes. |
| 307 | sendHalfHelloRequest bool |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 308 | // renegotiateCiphers is a list of ciphersuite ids that will be |
| 309 | // switched in just before renegotiation. |
| 310 | renegotiateCiphers []uint16 |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 311 | // replayWrites, if true, configures the underlying transport |
| 312 | // to replay every write it makes in DTLS tests. |
| 313 | replayWrites bool |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 314 | // damageFirstWrite, if true, configures the underlying transport to |
| 315 | // damage the final byte of the first application data write. |
| 316 | damageFirstWrite bool |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 317 | // exportKeyingMaterial, if non-zero, configures the test to exchange |
| 318 | // keying material and verify they match. |
| 319 | exportKeyingMaterial int |
| 320 | exportLabel string |
| 321 | exportContext string |
| 322 | useExportContext bool |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 323 | // flags, if not empty, contains a list of command-line flags that will |
| 324 | // be passed to the shim program. |
| 325 | flags []string |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 326 | // testTLSUnique, if true, causes the shim to send the tls-unique value |
| 327 | // which will be compared against the expected value. |
| 328 | testTLSUnique bool |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 329 | // sendEmptyRecords is the number of consecutive empty records to send |
| 330 | // before and after the test message. |
| 331 | sendEmptyRecords int |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 332 | // sendWarningAlerts is the number of consecutive warning alerts to send |
| 333 | // before and after the test message. |
| 334 | sendWarningAlerts int |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 335 | // expectMessageDropped, if true, means the test message is expected to |
| 336 | // be dropped by the client rather than echoed back. |
| 337 | expectMessageDropped bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 340 | var testCases []testCase |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 341 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 342 | func writeTranscript(test *testCase, isResume bool, data []byte) { |
| 343 | if len(data) == 0 { |
| 344 | return |
| 345 | } |
| 346 | |
| 347 | protocol := "tls" |
| 348 | if test.protocol == dtls { |
| 349 | protocol = "dtls" |
| 350 | } |
| 351 | |
| 352 | side := "client" |
| 353 | if test.testType == serverTest { |
| 354 | side = "server" |
| 355 | } |
| 356 | |
| 357 | dir := path.Join(*transcriptDir, protocol, side) |
| 358 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 359 | fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err) |
| 360 | return |
| 361 | } |
| 362 | |
| 363 | name := test.name |
| 364 | if isResume { |
| 365 | name += "-Resume" |
| 366 | } else { |
| 367 | name += "-Normal" |
| 368 | } |
| 369 | |
| 370 | if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil { |
| 371 | fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err) |
| 372 | } |
| 373 | } |
| 374 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 375 | // A timeoutConn implements an idle timeout on each Read and Write operation. |
| 376 | type timeoutConn struct { |
| 377 | net.Conn |
| 378 | timeout time.Duration |
| 379 | } |
| 380 | |
| 381 | func (t *timeoutConn) Read(b []byte) (int, error) { |
| 382 | if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil { |
| 383 | return 0, err |
| 384 | } |
| 385 | return t.Conn.Read(b) |
| 386 | } |
| 387 | |
| 388 | func (t *timeoutConn) Write(b []byte) (int, error) { |
| 389 | if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil { |
| 390 | return 0, err |
| 391 | } |
| 392 | return t.Conn.Write(b) |
| 393 | } |
| 394 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 395 | func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error { |
David Benjamin | 01784b4 | 2016-06-07 18:00:52 -0400 | [diff] [blame] | 396 | conn = &timeoutConn{conn, *idleTimeout} |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 397 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 398 | if test.protocol == dtls { |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 399 | config.Bugs.PacketAdaptor = newPacketAdaptor(conn) |
| 400 | conn = config.Bugs.PacketAdaptor |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 401 | } |
| 402 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 403 | if *flagDebug || len(*transcriptDir) != 0 { |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 404 | local, peer := "client", "server" |
| 405 | if test.testType == clientTest { |
| 406 | local, peer = peer, local |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 407 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 408 | connDebug := &recordingConn{ |
| 409 | Conn: conn, |
| 410 | isDatagram: test.protocol == dtls, |
| 411 | local: local, |
| 412 | peer: peer, |
| 413 | } |
| 414 | conn = connDebug |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 415 | if *flagDebug { |
| 416 | defer connDebug.WriteTo(os.Stdout) |
| 417 | } |
| 418 | if len(*transcriptDir) != 0 { |
| 419 | defer func() { |
| 420 | writeTranscript(test, isResume, connDebug.Transcript()) |
| 421 | }() |
| 422 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 423 | |
| 424 | if config.Bugs.PacketAdaptor != nil { |
| 425 | config.Bugs.PacketAdaptor.debug = connDebug |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | if test.replayWrites { |
| 430 | conn = newReplayAdaptor(conn) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 431 | } |
| 432 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 433 | var connDamage *damageAdaptor |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 434 | if test.damageFirstWrite { |
| 435 | connDamage = newDamageAdaptor(conn) |
| 436 | conn = connDamage |
| 437 | } |
| 438 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 439 | if test.sendPrefix != "" { |
| 440 | if _, err := conn.Write([]byte(test.sendPrefix)); err != nil { |
| 441 | return err |
| 442 | } |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 443 | } |
| 444 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 445 | var tlsConn *Conn |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 446 | if test.testType == clientTest { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 447 | if test.protocol == dtls { |
| 448 | tlsConn = DTLSServer(conn, config) |
| 449 | } else { |
| 450 | tlsConn = Server(conn, config) |
| 451 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 452 | } else { |
| 453 | config.InsecureSkipVerify = true |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 454 | if test.protocol == dtls { |
| 455 | tlsConn = DTLSClient(conn, config) |
| 456 | } else { |
| 457 | tlsConn = Client(conn, config) |
| 458 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 459 | } |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 460 | defer tlsConn.Close() |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 461 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 462 | if err := tlsConn.Handshake(); err != nil { |
| 463 | return err |
| 464 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 465 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 466 | // TODO(davidben): move all per-connection expectations into a dedicated |
| 467 | // expectations struct that can be specified separately for the two |
| 468 | // legs. |
| 469 | expectedVersion := test.expectedVersion |
| 470 | if isResume && test.expectedResumeVersion != 0 { |
| 471 | expectedVersion = test.expectedResumeVersion |
| 472 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 473 | connState := tlsConn.ConnectionState() |
| 474 | if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 475 | return fmt.Errorf("got version %x, expected %x", vers, expectedVersion) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 476 | } |
| 477 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 478 | if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher { |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 479 | return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher) |
| 480 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 481 | if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected { |
| 482 | return fmt.Errorf("didResume is %t, but we expected the opposite", didResume) |
| 483 | } |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 484 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 485 | if test.expectChannelID { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 486 | channelID := connState.ChannelID |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 487 | if channelID == nil { |
| 488 | return fmt.Errorf("no channel ID negotiated") |
| 489 | } |
| 490 | if channelID.Curve != channelIDKey.Curve || |
| 491 | channelIDKey.X.Cmp(channelIDKey.X) != 0 || |
| 492 | channelIDKey.Y.Cmp(channelIDKey.Y) != 0 { |
| 493 | return fmt.Errorf("incorrect channel ID") |
| 494 | } |
| 495 | } |
| 496 | |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 497 | if expected := test.expectedNextProto; expected != "" { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 498 | if actual := connState.NegotiatedProtocol; actual != expected { |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 499 | return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected) |
| 500 | } |
| 501 | } |
| 502 | |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 503 | if test.expectNoNextProto { |
| 504 | if actual := connState.NegotiatedProtocol; actual != "" { |
| 505 | return fmt.Errorf("got unexpected next proto %s", actual) |
| 506 | } |
| 507 | } |
| 508 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 509 | if test.expectedNextProtoType != 0 { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 510 | if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN { |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 511 | return fmt.Errorf("next proto type mismatch") |
| 512 | } |
| 513 | } |
| 514 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 515 | if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile { |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 516 | return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile) |
| 517 | } |
| 518 | |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 519 | if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) { |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 520 | 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] | 521 | } |
| 522 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 523 | if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) { |
| 524 | return fmt.Errorf("SCT list mismatch") |
| 525 | } |
| 526 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 527 | if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm { |
| 528 | 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] | 529 | } |
| 530 | |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 531 | if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID { |
| 532 | return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID) |
| 533 | } |
| 534 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 535 | if test.exportKeyingMaterial > 0 { |
| 536 | actual := make([]byte, test.exportKeyingMaterial) |
| 537 | if _, err := io.ReadFull(tlsConn, actual); err != nil { |
| 538 | return err |
| 539 | } |
| 540 | expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext) |
| 541 | if err != nil { |
| 542 | return err |
| 543 | } |
| 544 | if !bytes.Equal(actual, expected) { |
| 545 | return fmt.Errorf("keying material mismatch") |
| 546 | } |
| 547 | } |
| 548 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 549 | if test.testTLSUnique { |
| 550 | var peersValue [12]byte |
| 551 | if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil { |
| 552 | return err |
| 553 | } |
| 554 | expected := tlsConn.ConnectionState().TLSUnique |
| 555 | if !bytes.Equal(peersValue[:], expected) { |
| 556 | return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected) |
| 557 | } |
| 558 | } |
| 559 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 560 | if test.shimWritesFirst { |
| 561 | var buf [5]byte |
| 562 | _, err := io.ReadFull(tlsConn, buf[:]) |
| 563 | if err != nil { |
| 564 | return err |
| 565 | } |
| 566 | if string(buf[:]) != "hello" { |
| 567 | return fmt.Errorf("bad initial message") |
| 568 | } |
| 569 | } |
| 570 | |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 571 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 572 | tlsConn.Write(nil) |
| 573 | } |
| 574 | |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 575 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 576 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 577 | } |
| 578 | |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 579 | if test.sendHalfHelloRequest { |
| 580 | tlsConn.SendHalfHelloRequest() |
| 581 | } |
| 582 | |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 583 | if test.renegotiate > 0 { |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 584 | if test.renegotiateCiphers != nil { |
| 585 | config.CipherSuites = test.renegotiateCiphers |
| 586 | } |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 587 | for i := 0; i < test.renegotiate; i++ { |
| 588 | if err := tlsConn.Renegotiate(); err != nil { |
| 589 | return err |
| 590 | } |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 591 | } |
| 592 | } else if test.renegotiateCiphers != nil { |
| 593 | panic("renegotiateCiphers without renegotiate") |
| 594 | } |
| 595 | |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 596 | if test.damageFirstWrite { |
| 597 | connDamage.setDamage(true) |
| 598 | tlsConn.Write([]byte("DAMAGED WRITE")) |
| 599 | connDamage.setDamage(false) |
| 600 | } |
| 601 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 602 | messageLen := test.messageLen |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 603 | if messageLen < 0 { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 604 | if test.protocol == dtls { |
| 605 | return fmt.Errorf("messageLen < 0 not supported for DTLS tests") |
| 606 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 607 | // Read until EOF. |
| 608 | _, err := io.Copy(ioutil.Discard, tlsConn) |
| 609 | return err |
| 610 | } |
David Benjamin | 4417d05 | 2015-04-05 04:17:25 -0400 | [diff] [blame] | 611 | if messageLen == 0 { |
| 612 | messageLen = 32 |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 613 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 614 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 615 | messageCount := test.messageCount |
| 616 | if messageCount == 0 { |
| 617 | messageCount = 1 |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 618 | } |
| 619 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 620 | for j := 0; j < messageCount; j++ { |
| 621 | testMessage := make([]byte, messageLen) |
| 622 | for i := range testMessage { |
| 623 | testMessage[i] = 0x42 ^ byte(j) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 624 | } |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 625 | tlsConn.Write(testMessage) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 626 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 627 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 628 | tlsConn.Write(nil) |
| 629 | } |
| 630 | |
| 631 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 632 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 633 | } |
| 634 | |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 635 | if test.shimShutsDown || test.expectMessageDropped { |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 636 | // The shim will not respond. |
| 637 | continue |
| 638 | } |
| 639 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 640 | buf := make([]byte, len(testMessage)) |
| 641 | if test.protocol == dtls { |
| 642 | bufTmp := make([]byte, len(buf)+1) |
| 643 | n, err := tlsConn.Read(bufTmp) |
| 644 | if err != nil { |
| 645 | return err |
| 646 | } |
| 647 | if n != len(buf) { |
| 648 | return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf)) |
| 649 | } |
| 650 | copy(buf, bufTmp) |
| 651 | } else { |
| 652 | _, err := io.ReadFull(tlsConn, buf) |
| 653 | if err != nil { |
| 654 | return err |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | for i, v := range buf { |
| 659 | if v != testMessage[i]^0xff { |
| 660 | return fmt.Errorf("bad reply contents at byte %d", i) |
| 661 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
| 665 | return nil |
| 666 | } |
| 667 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 668 | func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd { |
| 669 | valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"} |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 670 | if dbAttach { |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 671 | 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] | 672 | } |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 673 | valgrindArgs = append(valgrindArgs, path) |
| 674 | valgrindArgs = append(valgrindArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 675 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 676 | return exec.Command("valgrind", valgrindArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 677 | } |
| 678 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 679 | func gdbOf(path string, args ...string) *exec.Cmd { |
| 680 | xtermArgs := []string{"-e", "gdb", "--args"} |
| 681 | xtermArgs = append(xtermArgs, path) |
| 682 | xtermArgs = append(xtermArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 683 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 684 | return exec.Command("xterm", xtermArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 685 | } |
| 686 | |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 687 | func lldbOf(path string, args ...string) *exec.Cmd { |
| 688 | xtermArgs := []string{"-e", "lldb", "--"} |
| 689 | xtermArgs = append(xtermArgs, path) |
| 690 | xtermArgs = append(xtermArgs, args...) |
| 691 | |
| 692 | return exec.Command("xterm", xtermArgs...) |
| 693 | } |
| 694 | |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 695 | var ( |
| 696 | errMoreMallocs = errors.New("child process did not exhaust all allocation calls") |
| 697 | errUnimplemented = errors.New("child process does not implement needed flags") |
| 698 | ) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 699 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 700 | // accept accepts a connection from listener, unless waitChan signals a process |
| 701 | // exit first. |
| 702 | func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) { |
| 703 | type connOrError struct { |
| 704 | conn net.Conn |
| 705 | err error |
| 706 | } |
| 707 | connChan := make(chan connOrError, 1) |
| 708 | go func() { |
| 709 | conn, err := listener.Accept() |
| 710 | connChan <- connOrError{conn, err} |
| 711 | close(connChan) |
| 712 | }() |
| 713 | select { |
| 714 | case result := <-connChan: |
| 715 | return result.conn, result.err |
| 716 | case childErr := <-waitChan: |
| 717 | waitChan <- childErr |
| 718 | return nil, fmt.Errorf("child exited early: %s", childErr) |
| 719 | } |
| 720 | } |
| 721 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 722 | func runTest(test *testCase, shimPath string, mallocNumToFail int64) error { |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 723 | if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) { |
| 724 | panic("Error expected without shouldFail in " + test.name) |
| 725 | } |
| 726 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 727 | if test.expectResumeRejected && !test.resumeSession { |
| 728 | panic("expectResumeRejected without resumeSession in " + test.name) |
| 729 | } |
| 730 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 731 | listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}}) |
| 732 | if err != nil { |
| 733 | panic(err) |
| 734 | } |
| 735 | defer func() { |
| 736 | if listener != nil { |
| 737 | listener.Close() |
| 738 | } |
| 739 | }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 740 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 741 | flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)} |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 742 | if test.testType == serverTest { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 743 | flags = append(flags, "-server") |
| 744 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 745 | flags = append(flags, "-key-file") |
| 746 | if test.keyFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 747 | flags = append(flags, path.Join(*resourceDir, rsaKeyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 748 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 749 | flags = append(flags, path.Join(*resourceDir, test.keyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | flags = append(flags, "-cert-file") |
| 753 | if test.certFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 754 | flags = append(flags, path.Join(*resourceDir, rsaCertificateFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 755 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 756 | flags = append(flags, path.Join(*resourceDir, test.certFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 757 | } |
| 758 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 759 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 760 | if test.protocol == dtls { |
| 761 | flags = append(flags, "-dtls") |
| 762 | } |
| 763 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 764 | if test.resumeSession { |
| 765 | flags = append(flags, "-resume") |
| 766 | } |
| 767 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 768 | if test.shimWritesFirst { |
| 769 | flags = append(flags, "-shim-writes-first") |
| 770 | } |
| 771 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 772 | if test.shimShutsDown { |
| 773 | flags = append(flags, "-shim-shuts-down") |
| 774 | } |
| 775 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 776 | if test.exportKeyingMaterial > 0 { |
| 777 | flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial)) |
| 778 | flags = append(flags, "-export-label", test.exportLabel) |
| 779 | flags = append(flags, "-export-context", test.exportContext) |
| 780 | if test.useExportContext { |
| 781 | flags = append(flags, "-use-export-context") |
| 782 | } |
| 783 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 784 | if test.expectResumeRejected { |
| 785 | flags = append(flags, "-expect-session-miss") |
| 786 | } |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 787 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 788 | if test.testTLSUnique { |
| 789 | flags = append(flags, "-tls-unique") |
| 790 | } |
| 791 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 792 | flags = append(flags, test.flags...) |
| 793 | |
| 794 | var shim *exec.Cmd |
| 795 | if *useValgrind { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 796 | shim = valgrindOf(false, shimPath, flags...) |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 797 | } else if *useGDB { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 798 | shim = gdbOf(shimPath, flags...) |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 799 | } else if *useLLDB { |
| 800 | shim = lldbOf(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 801 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 802 | shim = exec.Command(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 803 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 804 | shim.Stdin = os.Stdin |
| 805 | var stdoutBuf, stderrBuf bytes.Buffer |
| 806 | shim.Stdout = &stdoutBuf |
| 807 | shim.Stderr = &stderrBuf |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 808 | if mallocNumToFail >= 0 { |
David Benjamin | 9e128b0 | 2015-02-09 13:13:09 -0500 | [diff] [blame] | 809 | shim.Env = os.Environ() |
| 810 | 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] | 811 | if *mallocTestDebug { |
David Benjamin | 184494d | 2015-06-12 18:23:47 -0400 | [diff] [blame] | 812 | shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 813 | } |
| 814 | shim.Env = append(shim.Env, "_MALLOC_CHECK=1") |
| 815 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 816 | |
| 817 | if err := shim.Start(); err != nil { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 818 | panic(err) |
| 819 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 820 | waitChan := make(chan error, 1) |
| 821 | go func() { waitChan <- shim.Wait() }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 822 | |
| 823 | config := test.config |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 824 | if !test.noSessionCache { |
| 825 | config.ClientSessionCache = NewLRUClientSessionCache(1) |
| 826 | config.ServerSessionCache = NewLRUServerSessionCache(1) |
| 827 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 828 | if test.testType == clientTest { |
| 829 | if len(config.Certificates) == 0 { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 830 | config.Certificates = []Certificate{rsaCertificate} |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 831 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 832 | } else { |
| 833 | // Supply a ServerName to ensure a constant session cache key, |
| 834 | // rather than falling back to net.Conn.RemoteAddr. |
| 835 | if len(config.ServerName) == 0 { |
| 836 | config.ServerName = "test" |
| 837 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 838 | } |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 839 | if *fuzzer { |
| 840 | config.Bugs.NullAllCiphers = true |
| 841 | } |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 842 | if *deterministic { |
| 843 | config.Rand = &deterministicRand{} |
| 844 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 845 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 846 | conn, err := acceptOrWait(listener, waitChan) |
| 847 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 848 | err = doExchange(test, &config, conn, false /* not a resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 849 | conn.Close() |
| 850 | } |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 851 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 852 | if err == nil && test.resumeSession { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 853 | var resumeConfig Config |
| 854 | if test.resumeConfig != nil { |
| 855 | resumeConfig = *test.resumeConfig |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 856 | if len(resumeConfig.ServerName) == 0 { |
| 857 | resumeConfig.ServerName = config.ServerName |
| 858 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 859 | if len(resumeConfig.Certificates) == 0 { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 860 | resumeConfig.Certificates = []Certificate{rsaCertificate} |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 861 | } |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 862 | if test.newSessionsOnResume { |
| 863 | if !test.noSessionCache { |
| 864 | resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1) |
| 865 | resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1) |
| 866 | } |
| 867 | } else { |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 868 | resumeConfig.SessionTicketKey = config.SessionTicketKey |
| 869 | resumeConfig.ClientSessionCache = config.ClientSessionCache |
| 870 | resumeConfig.ServerSessionCache = config.ServerSessionCache |
| 871 | } |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 872 | if *fuzzer { |
| 873 | resumeConfig.Bugs.NullAllCiphers = true |
| 874 | } |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 875 | resumeConfig.Rand = config.Rand |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 876 | } else { |
| 877 | resumeConfig = config |
| 878 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 879 | var connResume net.Conn |
| 880 | connResume, err = acceptOrWait(listener, waitChan) |
| 881 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 882 | err = doExchange(test, &resumeConfig, connResume, true /* resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 883 | connResume.Close() |
| 884 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 885 | } |
| 886 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 887 | // Close the listener now. This is to avoid hangs should the shim try to |
| 888 | // open more connections than expected. |
| 889 | listener.Close() |
| 890 | listener = nil |
| 891 | |
| 892 | childErr := <-waitChan |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 893 | if exitError, ok := childErr.(*exec.ExitError); ok { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 894 | switch exitError.Sys().(syscall.WaitStatus).ExitStatus() { |
| 895 | case 88: |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 896 | return errMoreMallocs |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 897 | case 89: |
| 898 | return errUnimplemented |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 899 | } |
| 900 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 901 | |
David Benjamin | 9bea349 | 2016-03-02 10:59:16 -0500 | [diff] [blame] | 902 | // Account for Windows line endings. |
| 903 | stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1) |
| 904 | stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1) |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 905 | |
| 906 | // Separate the errors from the shim and those from tools like |
| 907 | // AddressSanitizer. |
| 908 | var extraStderr string |
| 909 | if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 { |
| 910 | stderr = stderrParts[0] |
| 911 | extraStderr = stderrParts[1] |
| 912 | } |
| 913 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 914 | failed := err != nil || childErr != nil |
EKR | 173bf93 | 2016-07-29 15:52:49 +0200 | [diff] [blame] | 915 | correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError) || |
| 916 | (*looseErrors && strings.Contains(stderr, "UNTRANSLATED_ERROR")) |
| 917 | |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 918 | localError := "none" |
| 919 | if err != nil { |
| 920 | localError = err.Error() |
| 921 | } |
| 922 | if len(test.expectedLocalError) != 0 { |
| 923 | correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError) |
| 924 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 925 | |
| 926 | if failed != test.shouldFail || failed && !correctFailure { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 927 | childError := "none" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 928 | if childErr != nil { |
| 929 | childError = childErr.Error() |
| 930 | } |
| 931 | |
| 932 | var msg string |
| 933 | switch { |
| 934 | case failed && !test.shouldFail: |
| 935 | msg = "unexpected failure" |
| 936 | case !failed && test.shouldFail: |
| 937 | msg = "unexpected success" |
| 938 | case failed && !correctFailure: |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 939 | msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 940 | default: |
| 941 | panic("internal error") |
| 942 | } |
| 943 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 944 | 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] | 945 | } |
| 946 | |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 947 | if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) { |
| 948 | return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | return nil |
| 952 | } |
| 953 | |
| 954 | var tlsVersions = []struct { |
| 955 | name string |
| 956 | version uint16 |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 957 | flag string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 958 | hasDTLS bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 959 | }{ |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 960 | {"SSL3", VersionSSL30, "-no-ssl3", false}, |
| 961 | {"TLS1", VersionTLS10, "-no-tls1", true}, |
| 962 | {"TLS11", VersionTLS11, "-no-tls11", false}, |
| 963 | {"TLS12", VersionTLS12, "-no-tls12", true}, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 964 | {"TLS13", VersionTLS13, "-no-tls13", false}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | var testCipherSuites = []struct { |
| 968 | name string |
| 969 | id uint16 |
| 970 | }{ |
| 971 | {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 972 | {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 973 | {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 974 | {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 975 | {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 976 | {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 977 | {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 978 | {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 979 | {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 980 | {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 981 | {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384}, |
| 982 | {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 983 | {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 984 | {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 985 | {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 986 | {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}, |
| 987 | {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 988 | {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 989 | {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 990 | {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 991 | {"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] | 992 | {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 993 | {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 994 | {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 995 | {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 996 | {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 997 | {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 998 | {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 999 | {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 1000 | {"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] | 1001 | {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA}, |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 1002 | {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 1003 | {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 1004 | {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 1005 | {"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] | 1006 | {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 1007 | {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA}, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 1008 | {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 1009 | {"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] | 1010 | {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256}, |
Steven Valdez | 3084e7b | 2016-06-02 12:07:20 -0400 | [diff] [blame] | 1011 | {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256}, |
| 1012 | {"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] | 1013 | {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1014 | {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1015 | {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA}, |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1016 | {"NULL-SHA", TLS_RSA_WITH_NULL_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1019 | func hasComponent(suiteName, component string) bool { |
| 1020 | return strings.Contains("-"+suiteName+"-", "-"+component+"-") |
| 1021 | } |
| 1022 | |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1023 | func isTLS12Only(suiteName string) bool { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1024 | return hasComponent(suiteName, "GCM") || |
| 1025 | hasComponent(suiteName, "SHA256") || |
David Benjamin | e9a80ff | 2015-04-07 00:46:46 -0400 | [diff] [blame] | 1026 | hasComponent(suiteName, "SHA384") || |
| 1027 | hasComponent(suiteName, "POLY1305") |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1028 | } |
| 1029 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1030 | func isTLS13Suite(suiteName string) bool { |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 1031 | // Only AEADs. |
| 1032 | if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") { |
| 1033 | return false |
| 1034 | } |
| 1035 | // No old CHACHA20_POLY1305. |
| 1036 | if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") { |
| 1037 | return false |
| 1038 | } |
| 1039 | // Must have ECDHE. |
| 1040 | // TODO(davidben,svaldez): Add pure PSK support. |
| 1041 | if !hasComponent(suiteName, "ECDHE") { |
| 1042 | return false |
| 1043 | } |
| 1044 | // TODO(davidben,svaldez): Add PSK support. |
| 1045 | if hasComponent(suiteName, "PSK") { |
| 1046 | return false |
| 1047 | } |
| 1048 | return true |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1051 | func isDTLSCipher(suiteName string) bool { |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1052 | return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL") |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 1055 | func bigFromHex(hex string) *big.Int { |
| 1056 | ret, ok := new(big.Int).SetString(hex, 16) |
| 1057 | if !ok { |
| 1058 | panic("failed to parse hex number 0x" + hex) |
| 1059 | } |
| 1060 | return ret |
| 1061 | } |
| 1062 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1063 | func addBasicTests() { |
| 1064 | basicTests := []testCase{ |
| 1065 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1066 | name: "NoFallbackSCSV", |
| 1067 | config: Config{ |
| 1068 | Bugs: ProtocolBugs{ |
| 1069 | FailIfNotFallbackSCSV: true, |
| 1070 | }, |
| 1071 | }, |
| 1072 | shouldFail: true, |
| 1073 | expectedLocalError: "no fallback SCSV found", |
| 1074 | }, |
| 1075 | { |
| 1076 | name: "SendFallbackSCSV", |
| 1077 | config: Config{ |
| 1078 | Bugs: ProtocolBugs{ |
| 1079 | FailIfNotFallbackSCSV: true, |
| 1080 | }, |
| 1081 | }, |
| 1082 | flags: []string{"-fallback-scsv"}, |
| 1083 | }, |
| 1084 | { |
| 1085 | name: "ClientCertificateTypes", |
| 1086 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1087 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1088 | ClientAuth: RequestClientCert, |
| 1089 | ClientCertificateTypes: []byte{ |
| 1090 | CertTypeDSSSign, |
| 1091 | CertTypeRSASign, |
| 1092 | CertTypeECDSASign, |
| 1093 | }, |
| 1094 | }, |
| 1095 | flags: []string{ |
| 1096 | "-expect-certificate-types", |
| 1097 | base64.StdEncoding.EncodeToString([]byte{ |
| 1098 | CertTypeDSSSign, |
| 1099 | CertTypeRSASign, |
| 1100 | CertTypeECDSASign, |
| 1101 | }), |
| 1102 | }, |
| 1103 | }, |
| 1104 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1105 | name: "UnauthenticatedECDH", |
| 1106 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1107 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1108 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1109 | Bugs: ProtocolBugs{ |
| 1110 | UnauthenticatedECDH: true, |
| 1111 | }, |
| 1112 | }, |
| 1113 | shouldFail: true, |
| 1114 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1115 | }, |
| 1116 | { |
| 1117 | name: "SkipCertificateStatus", |
| 1118 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1119 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1120 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1121 | Bugs: ProtocolBugs{ |
| 1122 | SkipCertificateStatus: true, |
| 1123 | }, |
| 1124 | }, |
| 1125 | flags: []string{ |
| 1126 | "-enable-ocsp-stapling", |
| 1127 | }, |
| 1128 | }, |
| 1129 | { |
| 1130 | name: "SkipServerKeyExchange", |
| 1131 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1132 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1133 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1134 | Bugs: ProtocolBugs{ |
| 1135 | SkipServerKeyExchange: true, |
| 1136 | }, |
| 1137 | }, |
| 1138 | shouldFail: true, |
| 1139 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1140 | }, |
| 1141 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1142 | testType: serverTest, |
| 1143 | name: "Alert", |
| 1144 | config: Config{ |
| 1145 | Bugs: ProtocolBugs{ |
| 1146 | SendSpuriousAlert: alertRecordOverflow, |
| 1147 | }, |
| 1148 | }, |
| 1149 | shouldFail: true, |
| 1150 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1151 | }, |
| 1152 | { |
| 1153 | protocol: dtls, |
| 1154 | testType: serverTest, |
| 1155 | name: "Alert-DTLS", |
| 1156 | config: Config{ |
| 1157 | Bugs: ProtocolBugs{ |
| 1158 | SendSpuriousAlert: alertRecordOverflow, |
| 1159 | }, |
| 1160 | }, |
| 1161 | shouldFail: true, |
| 1162 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1163 | }, |
| 1164 | { |
| 1165 | testType: serverTest, |
| 1166 | name: "FragmentAlert", |
| 1167 | config: Config{ |
| 1168 | Bugs: ProtocolBugs{ |
| 1169 | FragmentAlert: true, |
| 1170 | SendSpuriousAlert: alertRecordOverflow, |
| 1171 | }, |
| 1172 | }, |
| 1173 | shouldFail: true, |
| 1174 | expectedError: ":BAD_ALERT:", |
| 1175 | }, |
| 1176 | { |
| 1177 | protocol: dtls, |
| 1178 | testType: serverTest, |
| 1179 | name: "FragmentAlert-DTLS", |
| 1180 | config: Config{ |
| 1181 | Bugs: ProtocolBugs{ |
| 1182 | FragmentAlert: true, |
| 1183 | SendSpuriousAlert: alertRecordOverflow, |
| 1184 | }, |
| 1185 | }, |
| 1186 | shouldFail: true, |
| 1187 | expectedError: ":BAD_ALERT:", |
| 1188 | }, |
| 1189 | { |
| 1190 | testType: serverTest, |
David Benjamin | 0d3a8c6 | 2016-03-11 22:25:18 -0500 | [diff] [blame] | 1191 | name: "DoubleAlert", |
| 1192 | config: Config{ |
| 1193 | Bugs: ProtocolBugs{ |
| 1194 | DoubleAlert: true, |
| 1195 | SendSpuriousAlert: alertRecordOverflow, |
| 1196 | }, |
| 1197 | }, |
| 1198 | shouldFail: true, |
| 1199 | expectedError: ":BAD_ALERT:", |
| 1200 | }, |
| 1201 | { |
| 1202 | protocol: dtls, |
| 1203 | testType: serverTest, |
| 1204 | name: "DoubleAlert-DTLS", |
| 1205 | config: Config{ |
| 1206 | Bugs: ProtocolBugs{ |
| 1207 | DoubleAlert: true, |
| 1208 | SendSpuriousAlert: alertRecordOverflow, |
| 1209 | }, |
| 1210 | }, |
| 1211 | shouldFail: true, |
| 1212 | expectedError: ":BAD_ALERT:", |
| 1213 | }, |
| 1214 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1215 | name: "SkipNewSessionTicket", |
| 1216 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1217 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1218 | Bugs: ProtocolBugs{ |
| 1219 | SkipNewSessionTicket: true, |
| 1220 | }, |
| 1221 | }, |
| 1222 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1223 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1224 | }, |
| 1225 | { |
| 1226 | testType: serverTest, |
| 1227 | name: "FallbackSCSV", |
| 1228 | config: Config{ |
| 1229 | MaxVersion: VersionTLS11, |
| 1230 | Bugs: ProtocolBugs{ |
| 1231 | SendFallbackSCSV: true, |
| 1232 | }, |
| 1233 | }, |
| 1234 | shouldFail: true, |
| 1235 | expectedError: ":INAPPROPRIATE_FALLBACK:", |
| 1236 | }, |
| 1237 | { |
| 1238 | testType: serverTest, |
| 1239 | name: "FallbackSCSV-VersionMatch", |
| 1240 | config: Config{ |
| 1241 | Bugs: ProtocolBugs{ |
| 1242 | SendFallbackSCSV: true, |
| 1243 | }, |
| 1244 | }, |
| 1245 | }, |
| 1246 | { |
| 1247 | testType: serverTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1248 | name: "FallbackSCSV-VersionMatch-TLS12", |
| 1249 | config: Config{ |
| 1250 | MaxVersion: VersionTLS12, |
| 1251 | Bugs: ProtocolBugs{ |
| 1252 | SendFallbackSCSV: true, |
| 1253 | }, |
| 1254 | }, |
| 1255 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 1256 | }, |
| 1257 | { |
| 1258 | testType: serverTest, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1259 | name: "FragmentedClientVersion", |
| 1260 | config: Config{ |
| 1261 | Bugs: ProtocolBugs{ |
| 1262 | MaxHandshakeRecordLength: 1, |
| 1263 | FragmentClientVersion: true, |
| 1264 | }, |
| 1265 | }, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1266 | expectedVersion: VersionTLS13, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1267 | }, |
| 1268 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1269 | testType: serverTest, |
| 1270 | name: "HttpGET", |
| 1271 | sendPrefix: "GET / HTTP/1.0\n", |
| 1272 | shouldFail: true, |
| 1273 | expectedError: ":HTTP_REQUEST:", |
| 1274 | }, |
| 1275 | { |
| 1276 | testType: serverTest, |
| 1277 | name: "HttpPOST", |
| 1278 | sendPrefix: "POST / HTTP/1.0\n", |
| 1279 | shouldFail: true, |
| 1280 | expectedError: ":HTTP_REQUEST:", |
| 1281 | }, |
| 1282 | { |
| 1283 | testType: serverTest, |
| 1284 | name: "HttpHEAD", |
| 1285 | sendPrefix: "HEAD / HTTP/1.0\n", |
| 1286 | shouldFail: true, |
| 1287 | expectedError: ":HTTP_REQUEST:", |
| 1288 | }, |
| 1289 | { |
| 1290 | testType: serverTest, |
| 1291 | name: "HttpPUT", |
| 1292 | sendPrefix: "PUT / HTTP/1.0\n", |
| 1293 | shouldFail: true, |
| 1294 | expectedError: ":HTTP_REQUEST:", |
| 1295 | }, |
| 1296 | { |
| 1297 | testType: serverTest, |
| 1298 | name: "HttpCONNECT", |
| 1299 | sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n", |
| 1300 | shouldFail: true, |
| 1301 | expectedError: ":HTTPS_PROXY_REQUEST:", |
| 1302 | }, |
| 1303 | { |
| 1304 | testType: serverTest, |
| 1305 | name: "Garbage", |
| 1306 | sendPrefix: "blah", |
| 1307 | shouldFail: true, |
David Benjamin | 97760d5 | 2015-07-24 23:02:49 -0400 | [diff] [blame] | 1308 | expectedError: ":WRONG_VERSION_NUMBER:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1309 | }, |
| 1310 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1311 | name: "RSAEphemeralKey", |
| 1312 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1313 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1314 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 1315 | Bugs: ProtocolBugs{ |
| 1316 | RSAEphemeralKey: true, |
| 1317 | }, |
| 1318 | }, |
| 1319 | shouldFail: true, |
| 1320 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1321 | }, |
| 1322 | { |
| 1323 | name: "DisableEverything", |
Steven Valdez | 4f94b1c | 2016-05-24 12:31:07 -0400 | [diff] [blame] | 1324 | flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1325 | shouldFail: true, |
| 1326 | expectedError: ":WRONG_SSL_VERSION:", |
| 1327 | }, |
| 1328 | { |
| 1329 | protocol: dtls, |
| 1330 | name: "DisableEverything-DTLS", |
| 1331 | flags: []string{"-no-tls12", "-no-tls1"}, |
| 1332 | shouldFail: true, |
| 1333 | expectedError: ":WRONG_SSL_VERSION:", |
| 1334 | }, |
| 1335 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1336 | protocol: dtls, |
| 1337 | testType: serverTest, |
| 1338 | name: "MTU", |
| 1339 | config: Config{ |
| 1340 | Bugs: ProtocolBugs{ |
| 1341 | MaxPacketLength: 256, |
| 1342 | }, |
| 1343 | }, |
| 1344 | flags: []string{"-mtu", "256"}, |
| 1345 | }, |
| 1346 | { |
| 1347 | protocol: dtls, |
| 1348 | testType: serverTest, |
| 1349 | name: "MTUExceeded", |
| 1350 | config: Config{ |
| 1351 | Bugs: ProtocolBugs{ |
| 1352 | MaxPacketLength: 255, |
| 1353 | }, |
| 1354 | }, |
| 1355 | flags: []string{"-mtu", "256"}, |
| 1356 | shouldFail: true, |
| 1357 | expectedLocalError: "dtls: exceeded maximum packet length", |
| 1358 | }, |
| 1359 | { |
| 1360 | name: "CertMismatchRSA", |
| 1361 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1362 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1363 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1364 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1365 | Bugs: ProtocolBugs{ |
| 1366 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1367 | }, |
| 1368 | }, |
| 1369 | shouldFail: true, |
| 1370 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1371 | }, |
| 1372 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1373 | name: "CertMismatchRSA-TLS13", |
| 1374 | config: Config{ |
| 1375 | MaxVersion: VersionTLS13, |
| 1376 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1377 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 1378 | Bugs: ProtocolBugs{ |
| 1379 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1380 | }, |
| 1381 | }, |
| 1382 | shouldFail: true, |
| 1383 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1384 | }, |
| 1385 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1386 | name: "CertMismatchECDSA", |
| 1387 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1388 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1389 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1390 | Certificates: []Certificate{rsaCertificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1391 | Bugs: ProtocolBugs{ |
| 1392 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1393 | }, |
| 1394 | }, |
| 1395 | shouldFail: true, |
| 1396 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1397 | }, |
| 1398 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1399 | name: "CertMismatchECDSA-TLS13", |
| 1400 | config: Config{ |
| 1401 | MaxVersion: VersionTLS13, |
| 1402 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1403 | Certificates: []Certificate{rsaCertificate}, |
| 1404 | Bugs: ProtocolBugs{ |
| 1405 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1406 | }, |
| 1407 | }, |
| 1408 | shouldFail: true, |
| 1409 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1410 | }, |
| 1411 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1412 | name: "EmptyCertificateList", |
| 1413 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1414 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1415 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1416 | Bugs: ProtocolBugs{ |
| 1417 | EmptyCertificateList: true, |
| 1418 | }, |
| 1419 | }, |
| 1420 | shouldFail: true, |
| 1421 | expectedError: ":DECODE_ERROR:", |
| 1422 | }, |
| 1423 | { |
David Benjamin | 9ec1c75 | 2016-07-14 12:45:01 -0400 | [diff] [blame] | 1424 | name: "EmptyCertificateList-TLS13", |
| 1425 | config: Config{ |
| 1426 | MaxVersion: VersionTLS13, |
| 1427 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1428 | Bugs: ProtocolBugs{ |
| 1429 | EmptyCertificateList: true, |
| 1430 | }, |
| 1431 | }, |
| 1432 | shouldFail: true, |
| 1433 | expectedError: ":DECODE_ERROR:", |
| 1434 | }, |
| 1435 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1436 | name: "TLSFatalBadPackets", |
| 1437 | damageFirstWrite: true, |
| 1438 | shouldFail: true, |
| 1439 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 1440 | }, |
| 1441 | { |
| 1442 | protocol: dtls, |
| 1443 | name: "DTLSIgnoreBadPackets", |
| 1444 | damageFirstWrite: true, |
| 1445 | }, |
| 1446 | { |
| 1447 | protocol: dtls, |
| 1448 | name: "DTLSIgnoreBadPackets-Async", |
| 1449 | damageFirstWrite: true, |
| 1450 | flags: []string{"-async"}, |
| 1451 | }, |
| 1452 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1453 | name: "AppDataBeforeHandshake", |
| 1454 | config: Config{ |
| 1455 | Bugs: ProtocolBugs{ |
| 1456 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1457 | }, |
| 1458 | }, |
| 1459 | shouldFail: true, |
| 1460 | expectedError: ":UNEXPECTED_RECORD:", |
| 1461 | }, |
| 1462 | { |
| 1463 | name: "AppDataBeforeHandshake-Empty", |
| 1464 | config: Config{ |
| 1465 | Bugs: ProtocolBugs{ |
| 1466 | AppDataBeforeHandshake: []byte{}, |
| 1467 | }, |
| 1468 | }, |
| 1469 | shouldFail: true, |
| 1470 | expectedError: ":UNEXPECTED_RECORD:", |
| 1471 | }, |
| 1472 | { |
| 1473 | protocol: dtls, |
| 1474 | name: "AppDataBeforeHandshake-DTLS", |
| 1475 | config: Config{ |
| 1476 | Bugs: ProtocolBugs{ |
| 1477 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1478 | }, |
| 1479 | }, |
| 1480 | shouldFail: true, |
| 1481 | expectedError: ":UNEXPECTED_RECORD:", |
| 1482 | }, |
| 1483 | { |
| 1484 | protocol: dtls, |
| 1485 | name: "AppDataBeforeHandshake-DTLS-Empty", |
| 1486 | config: Config{ |
| 1487 | Bugs: ProtocolBugs{ |
| 1488 | AppDataBeforeHandshake: []byte{}, |
| 1489 | }, |
| 1490 | }, |
| 1491 | shouldFail: true, |
| 1492 | expectedError: ":UNEXPECTED_RECORD:", |
| 1493 | }, |
| 1494 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1495 | name: "AppDataAfterChangeCipherSpec", |
| 1496 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1497 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1498 | Bugs: ProtocolBugs{ |
| 1499 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1500 | }, |
| 1501 | }, |
| 1502 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1503 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1504 | }, |
| 1505 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1506 | name: "AppDataAfterChangeCipherSpec-Empty", |
| 1507 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1508 | MaxVersion: VersionTLS12, |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1509 | Bugs: ProtocolBugs{ |
| 1510 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1511 | }, |
| 1512 | }, |
| 1513 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1514 | expectedError: ":UNEXPECTED_RECORD:", |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1515 | }, |
| 1516 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1517 | protocol: dtls, |
| 1518 | name: "AppDataAfterChangeCipherSpec-DTLS", |
| 1519 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1520 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1521 | Bugs: ProtocolBugs{ |
| 1522 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1523 | }, |
| 1524 | }, |
| 1525 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1526 | // application data. |
| 1527 | }, |
| 1528 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1529 | protocol: dtls, |
| 1530 | name: "AppDataAfterChangeCipherSpec-DTLS-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 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1538 | // application data. |
| 1539 | }, |
| 1540 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1541 | name: "AlertAfterChangeCipherSpec", |
| 1542 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1543 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1544 | Bugs: ProtocolBugs{ |
| 1545 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1546 | }, |
| 1547 | }, |
| 1548 | shouldFail: true, |
| 1549 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1550 | }, |
| 1551 | { |
| 1552 | protocol: dtls, |
| 1553 | name: "AlertAfterChangeCipherSpec-DTLS", |
| 1554 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1555 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1556 | Bugs: ProtocolBugs{ |
| 1557 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1558 | }, |
| 1559 | }, |
| 1560 | shouldFail: true, |
| 1561 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1562 | }, |
| 1563 | { |
| 1564 | protocol: dtls, |
| 1565 | name: "ReorderHandshakeFragments-Small-DTLS", |
| 1566 | config: Config{ |
| 1567 | Bugs: ProtocolBugs{ |
| 1568 | ReorderHandshakeFragments: true, |
| 1569 | // Small enough that every handshake message is |
| 1570 | // fragmented. |
| 1571 | MaxHandshakeRecordLength: 2, |
| 1572 | }, |
| 1573 | }, |
| 1574 | }, |
| 1575 | { |
| 1576 | protocol: dtls, |
| 1577 | name: "ReorderHandshakeFragments-Large-DTLS", |
| 1578 | config: Config{ |
| 1579 | Bugs: ProtocolBugs{ |
| 1580 | ReorderHandshakeFragments: true, |
| 1581 | // Large enough that no handshake message is |
| 1582 | // fragmented. |
| 1583 | MaxHandshakeRecordLength: 2048, |
| 1584 | }, |
| 1585 | }, |
| 1586 | }, |
| 1587 | { |
| 1588 | protocol: dtls, |
| 1589 | name: "MixCompleteMessageWithFragments-DTLS", |
| 1590 | config: Config{ |
| 1591 | Bugs: ProtocolBugs{ |
| 1592 | ReorderHandshakeFragments: true, |
| 1593 | MixCompleteMessageWithFragments: true, |
| 1594 | MaxHandshakeRecordLength: 2, |
| 1595 | }, |
| 1596 | }, |
| 1597 | }, |
| 1598 | { |
| 1599 | name: "SendInvalidRecordType", |
| 1600 | config: Config{ |
| 1601 | Bugs: ProtocolBugs{ |
| 1602 | SendInvalidRecordType: true, |
| 1603 | }, |
| 1604 | }, |
| 1605 | shouldFail: true, |
| 1606 | expectedError: ":UNEXPECTED_RECORD:", |
| 1607 | }, |
| 1608 | { |
| 1609 | protocol: dtls, |
| 1610 | name: "SendInvalidRecordType-DTLS", |
| 1611 | config: Config{ |
| 1612 | Bugs: ProtocolBugs{ |
| 1613 | SendInvalidRecordType: true, |
| 1614 | }, |
| 1615 | }, |
| 1616 | shouldFail: true, |
| 1617 | expectedError: ":UNEXPECTED_RECORD:", |
| 1618 | }, |
| 1619 | { |
| 1620 | name: "FalseStart-SkipServerSecondLeg", |
| 1621 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1622 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1623 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1624 | NextProtos: []string{"foo"}, |
| 1625 | Bugs: ProtocolBugs{ |
| 1626 | SkipNewSessionTicket: true, |
| 1627 | SkipChangeCipherSpec: true, |
| 1628 | SkipFinished: true, |
| 1629 | ExpectFalseStart: true, |
| 1630 | }, |
| 1631 | }, |
| 1632 | flags: []string{ |
| 1633 | "-false-start", |
| 1634 | "-handshake-never-done", |
| 1635 | "-advertise-alpn", "\x03foo", |
| 1636 | }, |
| 1637 | shimWritesFirst: true, |
| 1638 | shouldFail: true, |
| 1639 | expectedError: ":UNEXPECTED_RECORD:", |
| 1640 | }, |
| 1641 | { |
| 1642 | name: "FalseStart-SkipServerSecondLeg-Implicit", |
| 1643 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1644 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1645 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1646 | NextProtos: []string{"foo"}, |
| 1647 | Bugs: ProtocolBugs{ |
| 1648 | SkipNewSessionTicket: true, |
| 1649 | SkipChangeCipherSpec: true, |
| 1650 | SkipFinished: true, |
| 1651 | }, |
| 1652 | }, |
| 1653 | flags: []string{ |
| 1654 | "-implicit-handshake", |
| 1655 | "-false-start", |
| 1656 | "-handshake-never-done", |
| 1657 | "-advertise-alpn", "\x03foo", |
| 1658 | }, |
| 1659 | shouldFail: true, |
| 1660 | expectedError: ":UNEXPECTED_RECORD:", |
| 1661 | }, |
| 1662 | { |
| 1663 | testType: serverTest, |
| 1664 | name: "FailEarlyCallback", |
| 1665 | flags: []string{"-fail-early-callback"}, |
| 1666 | shouldFail: true, |
| 1667 | expectedError: ":CONNECTION_REJECTED:", |
| 1668 | expectedLocalError: "remote error: access denied", |
| 1669 | }, |
| 1670 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1671 | protocol: dtls, |
| 1672 | name: "FragmentMessageTypeMismatch-DTLS", |
| 1673 | config: Config{ |
| 1674 | Bugs: ProtocolBugs{ |
| 1675 | MaxHandshakeRecordLength: 2, |
| 1676 | FragmentMessageTypeMismatch: true, |
| 1677 | }, |
| 1678 | }, |
| 1679 | shouldFail: true, |
| 1680 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1681 | }, |
| 1682 | { |
| 1683 | protocol: dtls, |
| 1684 | name: "FragmentMessageLengthMismatch-DTLS", |
| 1685 | config: Config{ |
| 1686 | Bugs: ProtocolBugs{ |
| 1687 | MaxHandshakeRecordLength: 2, |
| 1688 | FragmentMessageLengthMismatch: true, |
| 1689 | }, |
| 1690 | }, |
| 1691 | shouldFail: true, |
| 1692 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1693 | }, |
| 1694 | { |
| 1695 | protocol: dtls, |
| 1696 | name: "SplitFragments-Header-DTLS", |
| 1697 | config: Config{ |
| 1698 | Bugs: ProtocolBugs{ |
| 1699 | SplitFragments: 2, |
| 1700 | }, |
| 1701 | }, |
| 1702 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1703 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1704 | }, |
| 1705 | { |
| 1706 | protocol: dtls, |
| 1707 | name: "SplitFragments-Boundary-DTLS", |
| 1708 | config: Config{ |
| 1709 | Bugs: ProtocolBugs{ |
| 1710 | SplitFragments: dtlsRecordHeaderLen, |
| 1711 | }, |
| 1712 | }, |
| 1713 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1714 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1715 | }, |
| 1716 | { |
| 1717 | protocol: dtls, |
| 1718 | name: "SplitFragments-Body-DTLS", |
| 1719 | config: Config{ |
| 1720 | Bugs: ProtocolBugs{ |
| 1721 | SplitFragments: dtlsRecordHeaderLen + 1, |
| 1722 | }, |
| 1723 | }, |
| 1724 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1725 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1726 | }, |
| 1727 | { |
| 1728 | protocol: dtls, |
| 1729 | name: "SendEmptyFragments-DTLS", |
| 1730 | config: Config{ |
| 1731 | Bugs: ProtocolBugs{ |
| 1732 | SendEmptyFragments: true, |
| 1733 | }, |
| 1734 | }, |
| 1735 | }, |
| 1736 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1737 | name: "BadFinished-Client", |
| 1738 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1739 | MaxVersion: VersionTLS12, |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1740 | Bugs: ProtocolBugs{ |
| 1741 | BadFinished: true, |
| 1742 | }, |
| 1743 | }, |
| 1744 | shouldFail: true, |
| 1745 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1746 | }, |
| 1747 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1748 | name: "BadFinished-Client-TLS13", |
| 1749 | config: Config{ |
| 1750 | MaxVersion: VersionTLS13, |
| 1751 | Bugs: ProtocolBugs{ |
| 1752 | BadFinished: true, |
| 1753 | }, |
| 1754 | }, |
| 1755 | shouldFail: true, |
| 1756 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1757 | }, |
| 1758 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1759 | testType: serverTest, |
| 1760 | name: "BadFinished-Server", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1761 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1762 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1763 | Bugs: ProtocolBugs{ |
| 1764 | BadFinished: true, |
| 1765 | }, |
| 1766 | }, |
| 1767 | shouldFail: true, |
| 1768 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1769 | }, |
| 1770 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1771 | testType: serverTest, |
| 1772 | name: "BadFinished-Server-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 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1783 | name: "FalseStart-BadFinished", |
| 1784 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1785 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1786 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1787 | NextProtos: []string{"foo"}, |
| 1788 | Bugs: ProtocolBugs{ |
| 1789 | BadFinished: true, |
| 1790 | ExpectFalseStart: true, |
| 1791 | }, |
| 1792 | }, |
| 1793 | flags: []string{ |
| 1794 | "-false-start", |
| 1795 | "-handshake-never-done", |
| 1796 | "-advertise-alpn", "\x03foo", |
| 1797 | }, |
| 1798 | shimWritesFirst: true, |
| 1799 | shouldFail: true, |
| 1800 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1801 | }, |
| 1802 | { |
| 1803 | name: "NoFalseStart-NoALPN", |
| 1804 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1805 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1806 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1807 | Bugs: ProtocolBugs{ |
| 1808 | ExpectFalseStart: true, |
| 1809 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1810 | }, |
| 1811 | }, |
| 1812 | flags: []string{ |
| 1813 | "-false-start", |
| 1814 | }, |
| 1815 | shimWritesFirst: true, |
| 1816 | shouldFail: true, |
| 1817 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1818 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1819 | }, |
| 1820 | { |
| 1821 | name: "NoFalseStart-NoAEAD", |
| 1822 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1823 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1824 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1825 | NextProtos: []string{"foo"}, |
| 1826 | Bugs: ProtocolBugs{ |
| 1827 | ExpectFalseStart: true, |
| 1828 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1829 | }, |
| 1830 | }, |
| 1831 | flags: []string{ |
| 1832 | "-false-start", |
| 1833 | "-advertise-alpn", "\x03foo", |
| 1834 | }, |
| 1835 | shimWritesFirst: true, |
| 1836 | shouldFail: true, |
| 1837 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1838 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1839 | }, |
| 1840 | { |
| 1841 | name: "NoFalseStart-RSA", |
| 1842 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1843 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1844 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1845 | NextProtos: []string{"foo"}, |
| 1846 | Bugs: ProtocolBugs{ |
| 1847 | ExpectFalseStart: true, |
| 1848 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1849 | }, |
| 1850 | }, |
| 1851 | flags: []string{ |
| 1852 | "-false-start", |
| 1853 | "-advertise-alpn", "\x03foo", |
| 1854 | }, |
| 1855 | shimWritesFirst: true, |
| 1856 | shouldFail: true, |
| 1857 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1858 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1859 | }, |
| 1860 | { |
| 1861 | name: "NoFalseStart-DHE_RSA", |
| 1862 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1863 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1864 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1865 | NextProtos: []string{"foo"}, |
| 1866 | Bugs: ProtocolBugs{ |
| 1867 | ExpectFalseStart: true, |
| 1868 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1869 | }, |
| 1870 | }, |
| 1871 | flags: []string{ |
| 1872 | "-false-start", |
| 1873 | "-advertise-alpn", "\x03foo", |
| 1874 | }, |
| 1875 | shimWritesFirst: true, |
| 1876 | shouldFail: true, |
| 1877 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1878 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1879 | }, |
| 1880 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1881 | protocol: dtls, |
| 1882 | name: "SendSplitAlert-Sync", |
| 1883 | config: Config{ |
| 1884 | Bugs: ProtocolBugs{ |
| 1885 | SendSplitAlert: true, |
| 1886 | }, |
| 1887 | }, |
| 1888 | }, |
| 1889 | { |
| 1890 | protocol: dtls, |
| 1891 | name: "SendSplitAlert-Async", |
| 1892 | config: Config{ |
| 1893 | Bugs: ProtocolBugs{ |
| 1894 | SendSplitAlert: true, |
| 1895 | }, |
| 1896 | }, |
| 1897 | flags: []string{"-async"}, |
| 1898 | }, |
| 1899 | { |
| 1900 | protocol: dtls, |
| 1901 | name: "PackDTLSHandshake", |
| 1902 | config: Config{ |
| 1903 | Bugs: ProtocolBugs{ |
| 1904 | MaxHandshakeRecordLength: 2, |
| 1905 | PackHandshakeFragments: 20, |
| 1906 | PackHandshakeRecords: 200, |
| 1907 | }, |
| 1908 | }, |
| 1909 | }, |
| 1910 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1911 | name: "SendEmptyRecords-Pass", |
| 1912 | sendEmptyRecords: 32, |
| 1913 | }, |
| 1914 | { |
| 1915 | name: "SendEmptyRecords", |
| 1916 | sendEmptyRecords: 33, |
| 1917 | shouldFail: true, |
| 1918 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1919 | }, |
| 1920 | { |
| 1921 | name: "SendEmptyRecords-Async", |
| 1922 | sendEmptyRecords: 33, |
| 1923 | flags: []string{"-async"}, |
| 1924 | shouldFail: true, |
| 1925 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1926 | }, |
| 1927 | { |
| 1928 | name: "SendWarningAlerts-Pass", |
| 1929 | sendWarningAlerts: 4, |
| 1930 | }, |
| 1931 | { |
| 1932 | protocol: dtls, |
| 1933 | name: "SendWarningAlerts-DTLS-Pass", |
| 1934 | sendWarningAlerts: 4, |
| 1935 | }, |
| 1936 | { |
| 1937 | name: "SendWarningAlerts", |
| 1938 | sendWarningAlerts: 5, |
| 1939 | shouldFail: true, |
| 1940 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 1941 | }, |
| 1942 | { |
| 1943 | name: "SendWarningAlerts-Async", |
| 1944 | sendWarningAlerts: 5, |
| 1945 | flags: []string{"-async"}, |
| 1946 | shouldFail: true, |
| 1947 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 1948 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 1949 | { |
| 1950 | name: "EmptySessionID", |
| 1951 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1952 | MaxVersion: VersionTLS12, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 1953 | SessionTicketsDisabled: true, |
| 1954 | }, |
| 1955 | noSessionCache: true, |
| 1956 | flags: []string{"-expect-no-session"}, |
| 1957 | }, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 1958 | { |
| 1959 | name: "Unclean-Shutdown", |
| 1960 | config: Config{ |
| 1961 | Bugs: ProtocolBugs{ |
| 1962 | NoCloseNotify: true, |
| 1963 | ExpectCloseNotify: true, |
| 1964 | }, |
| 1965 | }, |
| 1966 | shimShutsDown: true, |
| 1967 | flags: []string{"-check-close-notify"}, |
| 1968 | shouldFail: true, |
| 1969 | expectedError: "Unexpected SSL_shutdown result: -1 != 1", |
| 1970 | }, |
| 1971 | { |
| 1972 | name: "Unclean-Shutdown-Ignored", |
| 1973 | config: Config{ |
| 1974 | Bugs: ProtocolBugs{ |
| 1975 | NoCloseNotify: true, |
| 1976 | }, |
| 1977 | }, |
| 1978 | shimShutsDown: true, |
| 1979 | }, |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 1980 | { |
David Benjamin | fa214e4 | 2016-05-10 17:03:10 -0400 | [diff] [blame] | 1981 | name: "Unclean-Shutdown-Alert", |
| 1982 | config: Config{ |
| 1983 | Bugs: ProtocolBugs{ |
| 1984 | SendAlertOnShutdown: alertDecompressionFailure, |
| 1985 | ExpectCloseNotify: true, |
| 1986 | }, |
| 1987 | }, |
| 1988 | shimShutsDown: true, |
| 1989 | flags: []string{"-check-close-notify"}, |
| 1990 | shouldFail: true, |
| 1991 | expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:", |
| 1992 | }, |
| 1993 | { |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 1994 | name: "LargePlaintext", |
| 1995 | config: Config{ |
| 1996 | Bugs: ProtocolBugs{ |
| 1997 | SendLargeRecords: true, |
| 1998 | }, |
| 1999 | }, |
| 2000 | messageLen: maxPlaintext + 1, |
| 2001 | shouldFail: true, |
| 2002 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2003 | }, |
| 2004 | { |
| 2005 | protocol: dtls, |
| 2006 | name: "LargePlaintext-DTLS", |
| 2007 | config: Config{ |
| 2008 | Bugs: ProtocolBugs{ |
| 2009 | SendLargeRecords: true, |
| 2010 | }, |
| 2011 | }, |
| 2012 | messageLen: maxPlaintext + 1, |
| 2013 | shouldFail: true, |
| 2014 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2015 | }, |
| 2016 | { |
| 2017 | name: "LargeCiphertext", |
| 2018 | config: Config{ |
| 2019 | Bugs: ProtocolBugs{ |
| 2020 | SendLargeRecords: true, |
| 2021 | }, |
| 2022 | }, |
| 2023 | messageLen: maxPlaintext * 2, |
| 2024 | shouldFail: true, |
| 2025 | expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:", |
| 2026 | }, |
| 2027 | { |
| 2028 | protocol: dtls, |
| 2029 | name: "LargeCiphertext-DTLS", |
| 2030 | config: Config{ |
| 2031 | Bugs: ProtocolBugs{ |
| 2032 | SendLargeRecords: true, |
| 2033 | }, |
| 2034 | }, |
| 2035 | messageLen: maxPlaintext * 2, |
| 2036 | // Unlike the other four cases, DTLS drops records which |
| 2037 | // are invalid before authentication, so the connection |
| 2038 | // does not fail. |
| 2039 | expectMessageDropped: true, |
| 2040 | }, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2041 | { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2042 | // In TLS 1.2 and below, empty NewSessionTicket messages |
| 2043 | // mean the server changed its mind on sending a ticket. |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2044 | name: "SendEmptySessionTicket", |
| 2045 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2046 | MaxVersion: VersionTLS12, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2047 | Bugs: ProtocolBugs{ |
| 2048 | SendEmptySessionTicket: true, |
| 2049 | FailIfSessionOffered: true, |
| 2050 | }, |
| 2051 | }, |
| 2052 | flags: []string{"-expect-no-session"}, |
| 2053 | resumeSession: true, |
| 2054 | expectResumeRejected: true, |
| 2055 | }, |
David Benjamin | 99fdfb9 | 2015-11-02 12:11:35 -0500 | [diff] [blame] | 2056 | { |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2057 | name: "BadHelloRequest-1", |
| 2058 | renegotiate: 1, |
| 2059 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2060 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2061 | Bugs: ProtocolBugs{ |
| 2062 | BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1}, |
| 2063 | }, |
| 2064 | }, |
| 2065 | flags: []string{ |
| 2066 | "-renegotiate-freely", |
| 2067 | "-expect-total-renegotiations", "1", |
| 2068 | }, |
| 2069 | shouldFail: true, |
David Benjamin | 163f29a | 2016-07-28 11:05:58 -0400 | [diff] [blame] | 2070 | expectedError: ":EXCESSIVE_MESSAGE_SIZE:", |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2071 | }, |
| 2072 | { |
| 2073 | name: "BadHelloRequest-2", |
| 2074 | renegotiate: 1, |
| 2075 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2076 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2077 | Bugs: ProtocolBugs{ |
| 2078 | BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0}, |
| 2079 | }, |
| 2080 | }, |
| 2081 | flags: []string{ |
| 2082 | "-renegotiate-freely", |
| 2083 | "-expect-total-renegotiations", "1", |
| 2084 | }, |
| 2085 | shouldFail: true, |
| 2086 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2087 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2088 | { |
| 2089 | testType: serverTest, |
| 2090 | name: "SupportTicketsWithSessionID", |
| 2091 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2092 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2093 | SessionTicketsDisabled: true, |
| 2094 | }, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2095 | resumeConfig: &Config{ |
| 2096 | MaxVersion: VersionTLS12, |
| 2097 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2098 | resumeSession: true, |
| 2099 | }, |
David Benjamin | 02edcd0 | 2016-07-27 17:40:37 -0400 | [diff] [blame] | 2100 | { |
| 2101 | protocol: dtls, |
| 2102 | name: "DTLS-SendExtraFinished", |
| 2103 | config: Config{ |
| 2104 | Bugs: ProtocolBugs{ |
| 2105 | SendExtraFinished: true, |
| 2106 | }, |
| 2107 | }, |
| 2108 | shouldFail: true, |
| 2109 | expectedError: ":UNEXPECTED_RECORD:", |
| 2110 | }, |
| 2111 | { |
| 2112 | protocol: dtls, |
| 2113 | name: "DTLS-SendExtraFinished-Reordered", |
| 2114 | config: Config{ |
| 2115 | Bugs: ProtocolBugs{ |
| 2116 | MaxHandshakeRecordLength: 2, |
| 2117 | ReorderHandshakeFragments: true, |
| 2118 | SendExtraFinished: true, |
| 2119 | }, |
| 2120 | }, |
| 2121 | shouldFail: true, |
| 2122 | expectedError: ":UNEXPECTED_RECORD:", |
| 2123 | }, |
David Benjamin | e97fb48 | 2016-07-29 09:23:07 -0400 | [diff] [blame] | 2124 | { |
| 2125 | testType: serverTest, |
| 2126 | name: "V2ClientHello-EmptyRecordPrefix", |
| 2127 | config: Config{ |
| 2128 | // Choose a cipher suite that does not involve |
| 2129 | // elliptic curves, so no extensions are |
| 2130 | // involved. |
| 2131 | MaxVersion: VersionTLS12, |
| 2132 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2133 | Bugs: ProtocolBugs{ |
| 2134 | SendV2ClientHello: true, |
| 2135 | }, |
| 2136 | }, |
| 2137 | sendPrefix: string([]byte{ |
| 2138 | byte(recordTypeHandshake), |
| 2139 | 3, 1, // version |
| 2140 | 0, 0, // length |
| 2141 | }), |
| 2142 | // A no-op empty record may not be sent before V2ClientHello. |
| 2143 | shouldFail: true, |
| 2144 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 2145 | }, |
| 2146 | { |
| 2147 | testType: serverTest, |
| 2148 | name: "V2ClientHello-WarningAlertPrefix", |
| 2149 | config: Config{ |
| 2150 | // Choose a cipher suite that does not involve |
| 2151 | // elliptic curves, so no extensions are |
| 2152 | // involved. |
| 2153 | MaxVersion: VersionTLS12, |
| 2154 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2155 | Bugs: ProtocolBugs{ |
| 2156 | SendV2ClientHello: true, |
| 2157 | }, |
| 2158 | }, |
| 2159 | sendPrefix: string([]byte{ |
| 2160 | byte(recordTypeAlert), |
| 2161 | 3, 1, // version |
| 2162 | 0, 2, // length |
| 2163 | alertLevelWarning, byte(alertDecompressionFailure), |
| 2164 | }), |
| 2165 | // A no-op warning alert may not be sent before V2ClientHello. |
| 2166 | shouldFail: true, |
| 2167 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 2168 | }, |
Steven Valdez | 1dc53d2 | 2016-07-26 12:27:38 -0400 | [diff] [blame] | 2169 | { |
| 2170 | testType: clientTest, |
| 2171 | name: "KeyUpdate", |
| 2172 | config: Config{ |
| 2173 | MaxVersion: VersionTLS13, |
| 2174 | Bugs: ProtocolBugs{ |
| 2175 | SendKeyUpdateBeforeEveryAppDataRecord: true, |
| 2176 | }, |
| 2177 | }, |
| 2178 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2179 | } |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2180 | testCases = append(testCases, basicTests...) |
| 2181 | } |
| 2182 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2183 | func addCipherSuiteTests() { |
David Benjamin | e470e66 | 2016-07-18 15:47:32 +0200 | [diff] [blame] | 2184 | const bogusCipher = 0xfe00 |
| 2185 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2186 | for _, suite := range testCipherSuites { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2187 | const psk = "12345" |
| 2188 | const pskIdentity = "luggage combo" |
| 2189 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2190 | var cert Certificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2191 | var certFile string |
| 2192 | var keyFile string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2193 | if hasComponent(suite.name, "ECDSA") { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2194 | cert = ecdsaP256Certificate |
| 2195 | certFile = ecdsaP256CertificateFile |
| 2196 | keyFile = ecdsaP256KeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2197 | } else { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2198 | cert = rsaCertificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2199 | certFile = rsaCertificateFile |
| 2200 | keyFile = rsaKeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2203 | var flags []string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2204 | if hasComponent(suite.name, "PSK") { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2205 | flags = append(flags, |
| 2206 | "-psk", psk, |
| 2207 | "-psk-identity", pskIdentity) |
| 2208 | } |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 2209 | if hasComponent(suite.name, "NULL") { |
| 2210 | // NULL ciphers must be explicitly enabled. |
| 2211 | flags = append(flags, "-cipher", "DEFAULT:NULL-SHA") |
| 2212 | } |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 2213 | if hasComponent(suite.name, "CECPQ1") { |
| 2214 | // CECPQ1 ciphers must be explicitly enabled. |
| 2215 | flags = append(flags, "-cipher", "DEFAULT:kCECPQ1") |
| 2216 | } |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2217 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2218 | for _, ver := range tlsVersions { |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2219 | for _, protocol := range []protocol{tls, dtls} { |
| 2220 | var prefix string |
| 2221 | if protocol == dtls { |
| 2222 | if !ver.hasDTLS { |
| 2223 | continue |
| 2224 | } |
| 2225 | prefix = "D" |
| 2226 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2227 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2228 | var shouldServerFail, shouldClientFail bool |
| 2229 | if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 { |
| 2230 | // BoringSSL clients accept ECDHE on SSLv3, but |
| 2231 | // a BoringSSL server will never select it |
| 2232 | // because the extension is missing. |
| 2233 | shouldServerFail = true |
| 2234 | } |
| 2235 | if isTLS12Only(suite.name) && ver.version < VersionTLS12 { |
| 2236 | shouldClientFail = true |
| 2237 | shouldServerFail = true |
| 2238 | } |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 2239 | if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2240 | shouldClientFail = true |
| 2241 | shouldServerFail = true |
| 2242 | } |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2243 | if !isDTLSCipher(suite.name) && protocol == dtls { |
| 2244 | shouldClientFail = true |
| 2245 | shouldServerFail = true |
| 2246 | } |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 2247 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2248 | var expectedServerError, expectedClientError string |
| 2249 | if shouldServerFail { |
| 2250 | expectedServerError = ":NO_SHARED_CIPHER:" |
| 2251 | } |
| 2252 | if shouldClientFail { |
| 2253 | expectedClientError = ":WRONG_CIPHER_RETURNED:" |
| 2254 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2255 | |
David Benjamin | 9deb117 | 2016-07-13 17:13:49 -0400 | [diff] [blame] | 2256 | // TODO(davidben,svaldez): Implement resumption for TLS 1.3. |
| 2257 | resumeSession := ver.version < VersionTLS13 |
| 2258 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2259 | testCases = append(testCases, testCase{ |
| 2260 | testType: serverTest, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2261 | protocol: protocol, |
| 2262 | |
| 2263 | name: prefix + ver.name + "-" + suite.name + "-server", |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2264 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2265 | MinVersion: ver.version, |
| 2266 | MaxVersion: ver.version, |
| 2267 | CipherSuites: []uint16{suite.id}, |
| 2268 | Certificates: []Certificate{cert}, |
| 2269 | PreSharedKey: []byte(psk), |
| 2270 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2271 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2272 | EnableAllCiphers: shouldServerFail, |
| 2273 | IgnorePeerCipherPreferences: shouldServerFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2274 | }, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2275 | }, |
| 2276 | certFile: certFile, |
| 2277 | keyFile: keyFile, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2278 | flags: flags, |
David Benjamin | 9deb117 | 2016-07-13 17:13:49 -0400 | [diff] [blame] | 2279 | resumeSession: resumeSession, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2280 | shouldFail: shouldServerFail, |
| 2281 | expectedError: expectedServerError, |
| 2282 | }) |
| 2283 | |
| 2284 | testCases = append(testCases, testCase{ |
| 2285 | testType: clientTest, |
| 2286 | protocol: protocol, |
| 2287 | name: prefix + ver.name + "-" + suite.name + "-client", |
| 2288 | config: Config{ |
| 2289 | MinVersion: ver.version, |
| 2290 | MaxVersion: ver.version, |
| 2291 | CipherSuites: []uint16{suite.id}, |
| 2292 | Certificates: []Certificate{cert}, |
| 2293 | PreSharedKey: []byte(psk), |
| 2294 | PreSharedKeyIdentity: pskIdentity, |
| 2295 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2296 | EnableAllCiphers: shouldClientFail, |
| 2297 | IgnorePeerCipherPreferences: shouldClientFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2298 | }, |
| 2299 | }, |
| 2300 | flags: flags, |
David Benjamin | 9deb117 | 2016-07-13 17:13:49 -0400 | [diff] [blame] | 2301 | resumeSession: resumeSession, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2302 | shouldFail: shouldClientFail, |
| 2303 | expectedError: expectedClientError, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2304 | }) |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2305 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2306 | if !shouldClientFail { |
| 2307 | // Ensure the maximum record size is accepted. |
| 2308 | testCases = append(testCases, testCase{ |
| 2309 | name: prefix + ver.name + "-" + suite.name + "-LargeRecord", |
| 2310 | config: Config{ |
| 2311 | MinVersion: ver.version, |
| 2312 | MaxVersion: ver.version, |
| 2313 | CipherSuites: []uint16{suite.id}, |
| 2314 | Certificates: []Certificate{cert}, |
| 2315 | PreSharedKey: []byte(psk), |
| 2316 | PreSharedKeyIdentity: pskIdentity, |
| 2317 | }, |
| 2318 | flags: flags, |
| 2319 | messageLen: maxPlaintext, |
| 2320 | }) |
| 2321 | } |
| 2322 | } |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2323 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2324 | } |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2325 | |
| 2326 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2327 | name: "NoSharedCipher", |
| 2328 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2329 | MaxVersion: VersionTLS12, |
| 2330 | CipherSuites: []uint16{}, |
| 2331 | }, |
| 2332 | shouldFail: true, |
| 2333 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2334 | }) |
| 2335 | |
| 2336 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2337 | name: "NoSharedCipher-TLS13", |
| 2338 | config: Config{ |
| 2339 | MaxVersion: VersionTLS13, |
| 2340 | CipherSuites: []uint16{}, |
| 2341 | }, |
| 2342 | shouldFail: true, |
| 2343 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2344 | }) |
| 2345 | |
| 2346 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2347 | name: "UnsupportedCipherSuite", |
| 2348 | config: Config{ |
| 2349 | MaxVersion: VersionTLS12, |
| 2350 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2351 | Bugs: ProtocolBugs{ |
| 2352 | IgnorePeerCipherPreferences: true, |
| 2353 | }, |
| 2354 | }, |
| 2355 | flags: []string{"-cipher", "DEFAULT:!RC4"}, |
| 2356 | shouldFail: true, |
| 2357 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 2358 | }) |
| 2359 | |
| 2360 | testCases = append(testCases, testCase{ |
David Benjamin | e470e66 | 2016-07-18 15:47:32 +0200 | [diff] [blame] | 2361 | name: "ServerHelloBogusCipher", |
| 2362 | config: Config{ |
| 2363 | MaxVersion: VersionTLS12, |
| 2364 | Bugs: ProtocolBugs{ |
| 2365 | SendCipherSuite: bogusCipher, |
| 2366 | }, |
| 2367 | }, |
| 2368 | shouldFail: true, |
| 2369 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2370 | }) |
| 2371 | testCases = append(testCases, testCase{ |
| 2372 | name: "ServerHelloBogusCipher-TLS13", |
| 2373 | config: Config{ |
| 2374 | MaxVersion: VersionTLS13, |
| 2375 | Bugs: ProtocolBugs{ |
| 2376 | SendCipherSuite: bogusCipher, |
| 2377 | }, |
| 2378 | }, |
| 2379 | shouldFail: true, |
| 2380 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2381 | }) |
| 2382 | |
| 2383 | testCases = append(testCases, testCase{ |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2384 | name: "WeakDH", |
| 2385 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2386 | MaxVersion: VersionTLS12, |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2387 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2388 | Bugs: ProtocolBugs{ |
| 2389 | // This is a 1023-bit prime number, generated |
| 2390 | // with: |
| 2391 | // openssl gendh 1023 | openssl asn1parse -i |
| 2392 | DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"), |
| 2393 | }, |
| 2394 | }, |
| 2395 | shouldFail: true, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2396 | expectedError: ":BAD_DH_P_LENGTH:", |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2397 | }) |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2398 | |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2399 | testCases = append(testCases, testCase{ |
| 2400 | name: "SillyDH", |
| 2401 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2402 | MaxVersion: VersionTLS12, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2403 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2404 | Bugs: ProtocolBugs{ |
| 2405 | // This is a 4097-bit prime number, generated |
| 2406 | // with: |
| 2407 | // openssl gendh 4097 | openssl asn1parse -i |
| 2408 | DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"), |
| 2409 | }, |
| 2410 | }, |
| 2411 | shouldFail: true, |
| 2412 | expectedError: ":DH_P_TOO_LONG:", |
| 2413 | }) |
| 2414 | |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2415 | // This test ensures that Diffie-Hellman public values are padded with |
| 2416 | // zeros so that they're the same length as the prime. This is to avoid |
| 2417 | // hitting a bug in yaSSL. |
| 2418 | testCases = append(testCases, testCase{ |
| 2419 | testType: serverTest, |
| 2420 | name: "DHPublicValuePadded", |
| 2421 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2422 | MaxVersion: VersionTLS12, |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2423 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2424 | Bugs: ProtocolBugs{ |
| 2425 | RequireDHPublicValueLen: (1025 + 7) / 8, |
| 2426 | }, |
| 2427 | }, |
| 2428 | flags: []string{"-use-sparse-dh-prime"}, |
| 2429 | }) |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2430 | |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2431 | // The server must be tolerant to bogus ciphers. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2432 | testCases = append(testCases, testCase{ |
| 2433 | testType: serverTest, |
| 2434 | name: "UnknownCipher", |
| 2435 | config: Config{ |
| 2436 | CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2437 | }, |
| 2438 | }) |
| 2439 | |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2440 | // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS |
| 2441 | // 1.1 specific cipher suite settings. A server is setup with the given |
| 2442 | // cipher lists and then a connection is made for each member of |
| 2443 | // expectations. The cipher suite that the server selects must match |
| 2444 | // the specified one. |
| 2445 | var versionSpecificCiphersTest = []struct { |
| 2446 | ciphersDefault, ciphersTLS10, ciphersTLS11 string |
| 2447 | // expectations is a map from TLS version to cipher suite id. |
| 2448 | expectations map[uint16]uint16 |
| 2449 | }{ |
| 2450 | { |
| 2451 | // Test that the null case (where no version-specific ciphers are set) |
| 2452 | // works as expected. |
| 2453 | "RC4-SHA:AES128-SHA", // default ciphers |
| 2454 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2455 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2456 | map[uint16]uint16{ |
| 2457 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2458 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2459 | VersionTLS11: TLS_RSA_WITH_RC4_128_SHA, |
| 2460 | VersionTLS12: TLS_RSA_WITH_RC4_128_SHA, |
| 2461 | }, |
| 2462 | }, |
| 2463 | { |
| 2464 | // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different |
| 2465 | // cipher. |
| 2466 | "RC4-SHA:AES128-SHA", // default |
| 2467 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2468 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2469 | map[uint16]uint16{ |
| 2470 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2471 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2472 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2473 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2474 | }, |
| 2475 | }, |
| 2476 | { |
| 2477 | // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different |
| 2478 | // cipher. |
| 2479 | "RC4-SHA:AES128-SHA", // default |
| 2480 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2481 | "AES128-SHA", // these ciphers for TLS ≥ 1.1 |
| 2482 | map[uint16]uint16{ |
| 2483 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2484 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2485 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2486 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2487 | }, |
| 2488 | }, |
| 2489 | { |
| 2490 | // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should |
| 2491 | // mask ciphers_tls10 for TLS 1.1 and 1.2. |
| 2492 | "RC4-SHA:AES128-SHA", // default |
| 2493 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2494 | "AES256-SHA", // these ciphers for TLS ≥ 1.1 |
| 2495 | map[uint16]uint16{ |
| 2496 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2497 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2498 | VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2499 | VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2500 | }, |
| 2501 | }, |
| 2502 | } |
| 2503 | |
| 2504 | for i, test := range versionSpecificCiphersTest { |
| 2505 | for version, expectedCipherSuite := range test.expectations { |
| 2506 | flags := []string{"-cipher", test.ciphersDefault} |
| 2507 | if len(test.ciphersTLS10) > 0 { |
| 2508 | flags = append(flags, "-cipher-tls10", test.ciphersTLS10) |
| 2509 | } |
| 2510 | if len(test.ciphersTLS11) > 0 { |
| 2511 | flags = append(flags, "-cipher-tls11", test.ciphersTLS11) |
| 2512 | } |
| 2513 | |
| 2514 | testCases = append(testCases, testCase{ |
| 2515 | testType: serverTest, |
| 2516 | name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version), |
| 2517 | config: Config{ |
| 2518 | MaxVersion: version, |
| 2519 | MinVersion: version, |
| 2520 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA}, |
| 2521 | }, |
| 2522 | flags: flags, |
| 2523 | expectedCipher: expectedCipherSuite, |
| 2524 | }) |
| 2525 | } |
| 2526 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | func addBadECDSASignatureTests() { |
| 2530 | for badR := BadValue(1); badR < NumBadValues; badR++ { |
| 2531 | for badS := BadValue(1); badS < NumBadValues; badS++ { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2532 | testCases = append(testCases, testCase{ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2533 | name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS), |
| 2534 | config: Config{ |
| 2535 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2536 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2537 | Bugs: ProtocolBugs{ |
| 2538 | BadECDSAR: badR, |
| 2539 | BadECDSAS: badS, |
| 2540 | }, |
| 2541 | }, |
| 2542 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2543 | expectedError: ":BAD_SIGNATURE:", |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2544 | }) |
| 2545 | } |
| 2546 | } |
| 2547 | } |
| 2548 | |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2549 | func addCBCPaddingTests() { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2550 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2551 | name: "MaxCBCPadding", |
| 2552 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2553 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2554 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2555 | Bugs: ProtocolBugs{ |
| 2556 | MaxPadding: true, |
| 2557 | }, |
| 2558 | }, |
| 2559 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2560 | }) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2561 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2562 | name: "BadCBCPadding", |
| 2563 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2564 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2565 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2566 | Bugs: ProtocolBugs{ |
| 2567 | PaddingFirstByteBad: true, |
| 2568 | }, |
| 2569 | }, |
| 2570 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2571 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2572 | }) |
| 2573 | // OpenSSL previously had an issue where the first byte of padding in |
| 2574 | // 255 bytes of padding wasn't checked. |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2575 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2576 | name: "BadCBCPadding255", |
| 2577 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2578 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2579 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2580 | Bugs: ProtocolBugs{ |
| 2581 | MaxPadding: true, |
| 2582 | PaddingFirstByteBadIf255: true, |
| 2583 | }, |
| 2584 | }, |
| 2585 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2586 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2587 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2588 | }) |
| 2589 | } |
| 2590 | |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2591 | func addCBCSplittingTests() { |
| 2592 | testCases = append(testCases, testCase{ |
| 2593 | name: "CBCRecordSplitting", |
| 2594 | config: Config{ |
| 2595 | MaxVersion: VersionTLS10, |
| 2596 | MinVersion: VersionTLS10, |
| 2597 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2598 | }, |
David Benjamin | ac8302a | 2015-09-01 17:18:15 -0400 | [diff] [blame] | 2599 | messageLen: -1, // read until EOF |
| 2600 | resumeSession: true, |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2601 | flags: []string{ |
| 2602 | "-async", |
| 2603 | "-write-different-record-sizes", |
| 2604 | "-cbc-record-splitting", |
| 2605 | }, |
David Benjamin | a8e3e0e | 2014-08-06 22:11:10 -0400 | [diff] [blame] | 2606 | }) |
| 2607 | testCases = append(testCases, testCase{ |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2608 | name: "CBCRecordSplittingPartialWrite", |
| 2609 | config: Config{ |
| 2610 | MaxVersion: VersionTLS10, |
| 2611 | MinVersion: VersionTLS10, |
| 2612 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2613 | }, |
| 2614 | messageLen: -1, // read until EOF |
| 2615 | flags: []string{ |
| 2616 | "-async", |
| 2617 | "-write-different-record-sizes", |
| 2618 | "-cbc-record-splitting", |
| 2619 | "-partial-write", |
| 2620 | }, |
| 2621 | }) |
| 2622 | } |
| 2623 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2624 | func addClientAuthTests() { |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 2625 | // Add a dummy cert pool to stress certificate authority parsing. |
| 2626 | // TODO(davidben): Add tests that those values parse out correctly. |
| 2627 | certPool := x509.NewCertPool() |
| 2628 | cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0]) |
| 2629 | if err != nil { |
| 2630 | panic(err) |
| 2631 | } |
| 2632 | certPool.AddCert(cert) |
| 2633 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2634 | for _, ver := range tlsVersions { |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2635 | testCases = append(testCases, testCase{ |
| 2636 | testType: clientTest, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2637 | name: ver.name + "-Client-ClientAuth-RSA", |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2638 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2639 | MinVersion: ver.version, |
| 2640 | MaxVersion: ver.version, |
| 2641 | ClientAuth: RequireAnyClientCert, |
| 2642 | ClientCAs: certPool, |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2643 | }, |
| 2644 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2645 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2646 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2647 | }, |
| 2648 | }) |
| 2649 | testCases = append(testCases, testCase{ |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2650 | testType: serverTest, |
| 2651 | name: ver.name + "-Server-ClientAuth-RSA", |
| 2652 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2653 | MinVersion: ver.version, |
| 2654 | MaxVersion: ver.version, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2655 | Certificates: []Certificate{rsaCertificate}, |
| 2656 | }, |
| 2657 | flags: []string{"-require-any-client-certificate"}, |
| 2658 | }) |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2659 | if ver.version != VersionSSL30 { |
| 2660 | testCases = append(testCases, testCase{ |
| 2661 | testType: serverTest, |
| 2662 | name: ver.name + "-Server-ClientAuth-ECDSA", |
| 2663 | config: Config{ |
| 2664 | MinVersion: ver.version, |
| 2665 | MaxVersion: ver.version, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2666 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2667 | }, |
| 2668 | flags: []string{"-require-any-client-certificate"}, |
| 2669 | }) |
| 2670 | testCases = append(testCases, testCase{ |
| 2671 | testType: clientTest, |
| 2672 | name: ver.name + "-Client-ClientAuth-ECDSA", |
| 2673 | config: Config{ |
| 2674 | MinVersion: ver.version, |
| 2675 | MaxVersion: ver.version, |
| 2676 | ClientAuth: RequireAnyClientCert, |
| 2677 | ClientCAs: certPool, |
| 2678 | }, |
| 2679 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2680 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 2681 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2682 | }, |
| 2683 | }) |
| 2684 | } |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2685 | } |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2686 | |
| 2687 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2688 | name: "NoClientCertificate", |
| 2689 | config: Config{ |
| 2690 | MaxVersion: VersionTLS12, |
| 2691 | ClientAuth: RequireAnyClientCert, |
| 2692 | }, |
| 2693 | shouldFail: true, |
| 2694 | expectedLocalError: "client didn't provide a certificate", |
| 2695 | }) |
| 2696 | |
| 2697 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2698 | name: "NoClientCertificate-TLS13", |
| 2699 | config: Config{ |
| 2700 | MaxVersion: VersionTLS13, |
| 2701 | ClientAuth: RequireAnyClientCert, |
| 2702 | }, |
| 2703 | shouldFail: true, |
| 2704 | expectedLocalError: "client didn't provide a certificate", |
| 2705 | }) |
| 2706 | |
| 2707 | testCases = append(testCases, testCase{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2708 | testType: serverTest, |
| 2709 | name: "RequireAnyClientCertificate", |
| 2710 | config: Config{ |
| 2711 | MaxVersion: VersionTLS12, |
| 2712 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2713 | flags: []string{"-require-any-client-certificate"}, |
| 2714 | shouldFail: true, |
| 2715 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2716 | }) |
| 2717 | |
| 2718 | testCases = append(testCases, testCase{ |
| 2719 | testType: serverTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2720 | name: "RequireAnyClientCertificate-TLS13", |
| 2721 | config: Config{ |
| 2722 | MaxVersion: VersionTLS13, |
| 2723 | }, |
| 2724 | flags: []string{"-require-any-client-certificate"}, |
| 2725 | shouldFail: true, |
| 2726 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2727 | }) |
| 2728 | |
| 2729 | testCases = append(testCases, testCase{ |
| 2730 | testType: serverTest, |
David Benjamin | df28c3a | 2016-03-10 16:11:51 -0500 | [diff] [blame] | 2731 | name: "RequireAnyClientCertificate-SSL3", |
| 2732 | config: Config{ |
| 2733 | MaxVersion: VersionSSL30, |
| 2734 | }, |
| 2735 | flags: []string{"-require-any-client-certificate"}, |
| 2736 | shouldFail: true, |
| 2737 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2738 | }) |
| 2739 | |
| 2740 | testCases = append(testCases, testCase{ |
| 2741 | testType: serverTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2742 | name: "SkipClientCertificate", |
| 2743 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2744 | MaxVersion: VersionTLS12, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2745 | Bugs: ProtocolBugs{ |
| 2746 | SkipClientCertificate: true, |
| 2747 | }, |
| 2748 | }, |
| 2749 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2750 | flags: []string{"-verify-peer"}, |
| 2751 | shouldFail: true, |
David Benjamin | df28c3a | 2016-03-10 16:11:51 -0500 | [diff] [blame] | 2752 | expectedError: ":UNEXPECTED_MESSAGE:", |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2753 | }) |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2754 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2755 | testCases = append(testCases, testCase{ |
| 2756 | testType: serverTest, |
| 2757 | name: "SkipClientCertificate-TLS13", |
| 2758 | config: Config{ |
| 2759 | MaxVersion: VersionTLS13, |
| 2760 | Bugs: ProtocolBugs{ |
| 2761 | SkipClientCertificate: true, |
| 2762 | }, |
| 2763 | }, |
| 2764 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2765 | flags: []string{"-verify-peer"}, |
| 2766 | shouldFail: true, |
| 2767 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2768 | }) |
| 2769 | |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2770 | // Client auth is only legal in certificate-based ciphers. |
| 2771 | testCases = append(testCases, testCase{ |
| 2772 | testType: clientTest, |
| 2773 | name: "ClientAuth-PSK", |
| 2774 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2775 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2776 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 2777 | PreSharedKey: []byte("secret"), |
| 2778 | ClientAuth: RequireAnyClientCert, |
| 2779 | }, |
| 2780 | flags: []string{ |
| 2781 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2782 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2783 | "-psk", "secret", |
| 2784 | }, |
| 2785 | shouldFail: true, |
| 2786 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2787 | }) |
| 2788 | testCases = append(testCases, testCase{ |
| 2789 | testType: clientTest, |
| 2790 | name: "ClientAuth-ECDHE_PSK", |
| 2791 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2792 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2793 | CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 2794 | PreSharedKey: []byte("secret"), |
| 2795 | ClientAuth: RequireAnyClientCert, |
| 2796 | }, |
| 2797 | flags: []string{ |
| 2798 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2799 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2800 | "-psk", "secret", |
| 2801 | }, |
| 2802 | shouldFail: true, |
| 2803 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2804 | }) |
David Benjamin | 2f8935d | 2016-07-13 19:47:39 -0400 | [diff] [blame] | 2805 | |
| 2806 | // Regression test for a bug where the client CA list, if explicitly |
| 2807 | // set to NULL, was mis-encoded. |
| 2808 | testCases = append(testCases, testCase{ |
| 2809 | testType: serverTest, |
| 2810 | name: "Null-Client-CA-List", |
| 2811 | config: Config{ |
| 2812 | MaxVersion: VersionTLS12, |
| 2813 | Certificates: []Certificate{rsaCertificate}, |
| 2814 | }, |
| 2815 | flags: []string{ |
| 2816 | "-require-any-client-certificate", |
| 2817 | "-use-null-client-ca-list", |
| 2818 | }, |
| 2819 | }) |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2820 | } |
| 2821 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2822 | func addExtendedMasterSecretTests() { |
| 2823 | const expectEMSFlag = "-expect-extended-master-secret" |
| 2824 | |
| 2825 | for _, with := range []bool{false, true} { |
| 2826 | prefix := "No" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2827 | if with { |
| 2828 | prefix = "" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | for _, isClient := range []bool{false, true} { |
| 2832 | suffix := "-Server" |
| 2833 | testType := serverTest |
| 2834 | if isClient { |
| 2835 | suffix = "-Client" |
| 2836 | testType = clientTest |
| 2837 | } |
| 2838 | |
| 2839 | for _, ver := range tlsVersions { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2840 | // In TLS 1.3, the extension is irrelevant and |
| 2841 | // always reports as enabled. |
| 2842 | var flags []string |
| 2843 | if with || ver.version >= VersionTLS13 { |
| 2844 | flags = []string{expectEMSFlag} |
| 2845 | } |
| 2846 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2847 | test := testCase{ |
| 2848 | testType: testType, |
| 2849 | name: prefix + "ExtendedMasterSecret-" + ver.name + suffix, |
| 2850 | config: Config{ |
| 2851 | MinVersion: ver.version, |
| 2852 | MaxVersion: ver.version, |
| 2853 | Bugs: ProtocolBugs{ |
| 2854 | NoExtendedMasterSecret: !with, |
| 2855 | RequireExtendedMasterSecret: with, |
| 2856 | }, |
| 2857 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2858 | flags: flags, |
| 2859 | shouldFail: ver.version == VersionSSL30 && with, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2860 | } |
| 2861 | if test.shouldFail { |
| 2862 | test.expectedLocalError = "extended master secret required but not supported by peer" |
| 2863 | } |
| 2864 | testCases = append(testCases, test) |
| 2865 | } |
| 2866 | } |
| 2867 | } |
| 2868 | |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2869 | for _, isClient := range []bool{false, true} { |
| 2870 | for _, supportedInFirstConnection := range []bool{false, true} { |
| 2871 | for _, supportedInResumeConnection := range []bool{false, true} { |
| 2872 | boolToWord := func(b bool) string { |
| 2873 | if b { |
| 2874 | return "Yes" |
| 2875 | } |
| 2876 | return "No" |
| 2877 | } |
| 2878 | suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-" |
| 2879 | if isClient { |
| 2880 | suffix += "Client" |
| 2881 | } else { |
| 2882 | suffix += "Server" |
| 2883 | } |
| 2884 | |
| 2885 | supportedConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2886 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2887 | Bugs: ProtocolBugs{ |
| 2888 | RequireExtendedMasterSecret: true, |
| 2889 | }, |
| 2890 | } |
| 2891 | |
| 2892 | noSupportConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2893 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2894 | Bugs: ProtocolBugs{ |
| 2895 | NoExtendedMasterSecret: true, |
| 2896 | }, |
| 2897 | } |
| 2898 | |
| 2899 | test := testCase{ |
| 2900 | name: "ExtendedMasterSecret-" + suffix, |
| 2901 | resumeSession: true, |
| 2902 | } |
| 2903 | |
| 2904 | if !isClient { |
| 2905 | test.testType = serverTest |
| 2906 | } |
| 2907 | |
| 2908 | if supportedInFirstConnection { |
| 2909 | test.config = supportedConfig |
| 2910 | } else { |
| 2911 | test.config = noSupportConfig |
| 2912 | } |
| 2913 | |
| 2914 | if supportedInResumeConnection { |
| 2915 | test.resumeConfig = &supportedConfig |
| 2916 | } else { |
| 2917 | test.resumeConfig = &noSupportConfig |
| 2918 | } |
| 2919 | |
| 2920 | switch suffix { |
| 2921 | case "YesToYes-Client", "YesToYes-Server": |
| 2922 | // When a session is resumed, it should |
| 2923 | // still be aware that its master |
| 2924 | // secret was generated via EMS and |
| 2925 | // thus it's safe to use tls-unique. |
| 2926 | test.flags = []string{expectEMSFlag} |
| 2927 | case "NoToYes-Server": |
| 2928 | // If an original connection did not |
| 2929 | // contain EMS, but a resumption |
| 2930 | // handshake does, then a server should |
| 2931 | // not resume the session. |
| 2932 | test.expectResumeRejected = true |
| 2933 | case "YesToNo-Server": |
| 2934 | // Resuming an EMS session without the |
| 2935 | // EMS extension should cause the |
| 2936 | // server to abort the connection. |
| 2937 | test.shouldFail = true |
| 2938 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 2939 | case "NoToYes-Client": |
| 2940 | // A client should abort a connection |
| 2941 | // where the server resumed a non-EMS |
| 2942 | // session but echoed the EMS |
| 2943 | // extension. |
| 2944 | test.shouldFail = true |
| 2945 | test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:" |
| 2946 | case "YesToNo-Client": |
| 2947 | // A client should abort a connection |
| 2948 | // where the server didn't echo EMS |
| 2949 | // when the session used it. |
| 2950 | test.shouldFail = true |
| 2951 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 2952 | } |
| 2953 | |
| 2954 | testCases = append(testCases, test) |
| 2955 | } |
| 2956 | } |
| 2957 | } |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2958 | } |
| 2959 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 2960 | type stateMachineTestConfig struct { |
| 2961 | protocol protocol |
| 2962 | async bool |
| 2963 | splitHandshake, packHandshakeFlight bool |
| 2964 | } |
| 2965 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 2966 | // Adds tests that try to cover the range of the handshake state machine, under |
| 2967 | // various conditions. Some of these are redundant with other tests, but they |
| 2968 | // only cover the synchronous case. |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 2969 | func addAllStateMachineCoverageTests() { |
| 2970 | for _, async := range []bool{false, true} { |
| 2971 | for _, protocol := range []protocol{tls, dtls} { |
| 2972 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 2973 | protocol: protocol, |
| 2974 | async: async, |
| 2975 | }) |
| 2976 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 2977 | protocol: protocol, |
| 2978 | async: async, |
| 2979 | splitHandshake: true, |
| 2980 | }) |
| 2981 | if protocol == tls { |
| 2982 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 2983 | protocol: protocol, |
| 2984 | async: async, |
| 2985 | packHandshakeFlight: true, |
| 2986 | }) |
| 2987 | } |
| 2988 | } |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | func addStateMachineCoverageTests(config stateMachineTestConfig) { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2993 | var tests []testCase |
| 2994 | |
| 2995 | // Basic handshake, with resumption. Client and server, |
| 2996 | // session ID and session ticket. |
| 2997 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2998 | name: "Basic-Client", |
| 2999 | config: Config{ |
| 3000 | MaxVersion: VersionTLS12, |
| 3001 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3002 | resumeSession: true, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3003 | // Ensure session tickets are used, not session IDs. |
| 3004 | noSessionCache: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3005 | }) |
| 3006 | tests = append(tests, testCase{ |
| 3007 | name: "Basic-Client-RenewTicket", |
| 3008 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3009 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3010 | Bugs: ProtocolBugs{ |
| 3011 | RenewTicketOnResume: true, |
| 3012 | }, |
| 3013 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 3014 | flags: []string{"-expect-ticket-renewal"}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3015 | resumeSession: true, |
| 3016 | }) |
| 3017 | tests = append(tests, testCase{ |
| 3018 | name: "Basic-Client-NoTicket", |
| 3019 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3020 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3021 | SessionTicketsDisabled: true, |
| 3022 | }, |
| 3023 | resumeSession: true, |
| 3024 | }) |
| 3025 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3026 | name: "Basic-Client-Implicit", |
| 3027 | config: Config{ |
| 3028 | MaxVersion: VersionTLS12, |
| 3029 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3030 | flags: []string{"-implicit-handshake"}, |
| 3031 | resumeSession: true, |
| 3032 | }) |
| 3033 | tests = append(tests, testCase{ |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3034 | testType: serverTest, |
| 3035 | name: "Basic-Server", |
| 3036 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3037 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 3038 | Bugs: ProtocolBugs{ |
| 3039 | RequireSessionTickets: true, |
| 3040 | }, |
| 3041 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3042 | resumeSession: true, |
| 3043 | }) |
| 3044 | tests = append(tests, testCase{ |
| 3045 | testType: serverTest, |
| 3046 | name: "Basic-Server-NoTickets", |
| 3047 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3048 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3049 | SessionTicketsDisabled: true, |
| 3050 | }, |
| 3051 | resumeSession: true, |
| 3052 | }) |
| 3053 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3054 | testType: serverTest, |
| 3055 | name: "Basic-Server-Implicit", |
| 3056 | config: Config{ |
| 3057 | MaxVersion: VersionTLS12, |
| 3058 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3059 | flags: []string{"-implicit-handshake"}, |
| 3060 | resumeSession: true, |
| 3061 | }) |
| 3062 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3063 | testType: serverTest, |
| 3064 | name: "Basic-Server-EarlyCallback", |
| 3065 | config: Config{ |
| 3066 | MaxVersion: VersionTLS12, |
| 3067 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3068 | flags: []string{"-use-early-callback"}, |
| 3069 | resumeSession: true, |
| 3070 | }) |
| 3071 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3072 | // TLS 1.3 basic handshake shapes. |
| 3073 | tests = append(tests, testCase{ |
| 3074 | name: "TLS13-1RTT-Client", |
| 3075 | config: Config{ |
| 3076 | MaxVersion: VersionTLS13, |
| 3077 | }, |
| 3078 | }) |
| 3079 | tests = append(tests, testCase{ |
| 3080 | testType: serverTest, |
| 3081 | name: "TLS13-1RTT-Server", |
| 3082 | config: Config{ |
| 3083 | MaxVersion: VersionTLS13, |
| 3084 | }, |
| 3085 | }) |
| 3086 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3087 | // TLS client auth. |
| 3088 | tests = append(tests, testCase{ |
| 3089 | testType: clientTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3090 | name: "ClientAuth-NoCertificate-Client", |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3091 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3092 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3093 | ClientAuth: RequestClientCert, |
| 3094 | }, |
| 3095 | }) |
| 3096 | tests = append(tests, testCase{ |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3097 | testType: serverTest, |
| 3098 | name: "ClientAuth-NoCertificate-Server", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3099 | config: Config{ |
| 3100 | MaxVersion: VersionTLS12, |
| 3101 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3102 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3103 | flags: []string{"-verify-peer"}, |
| 3104 | }) |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3105 | if config.protocol == tls { |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3106 | tests = append(tests, testCase{ |
| 3107 | testType: clientTest, |
| 3108 | name: "ClientAuth-NoCertificate-Client-SSL3", |
| 3109 | config: Config{ |
| 3110 | MaxVersion: VersionSSL30, |
| 3111 | ClientAuth: RequestClientCert, |
| 3112 | }, |
| 3113 | }) |
| 3114 | tests = append(tests, testCase{ |
| 3115 | testType: serverTest, |
| 3116 | name: "ClientAuth-NoCertificate-Server-SSL3", |
| 3117 | config: Config{ |
| 3118 | MaxVersion: VersionSSL30, |
| 3119 | }, |
| 3120 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3121 | flags: []string{"-verify-peer"}, |
| 3122 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3123 | tests = append(tests, testCase{ |
| 3124 | testType: clientTest, |
| 3125 | name: "ClientAuth-NoCertificate-Client-TLS13", |
| 3126 | config: Config{ |
| 3127 | MaxVersion: VersionTLS13, |
| 3128 | ClientAuth: RequestClientCert, |
| 3129 | }, |
| 3130 | }) |
| 3131 | tests = append(tests, testCase{ |
| 3132 | testType: serverTest, |
| 3133 | name: "ClientAuth-NoCertificate-Server-TLS13", |
| 3134 | config: Config{ |
| 3135 | MaxVersion: VersionTLS13, |
| 3136 | }, |
| 3137 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3138 | flags: []string{"-verify-peer"}, |
| 3139 | }) |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3140 | } |
| 3141 | tests = append(tests, testCase{ |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3142 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3143 | name: "ClientAuth-RSA-Client", |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3144 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3145 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3146 | ClientAuth: RequireAnyClientCert, |
| 3147 | }, |
| 3148 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3149 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3150 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3151 | }, |
| 3152 | }) |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3153 | tests = append(tests, testCase{ |
| 3154 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3155 | name: "ClientAuth-RSA-Client-TLS13", |
| 3156 | config: Config{ |
| 3157 | MaxVersion: VersionTLS13, |
| 3158 | ClientAuth: RequireAnyClientCert, |
| 3159 | }, |
| 3160 | flags: []string{ |
| 3161 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3162 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3163 | }, |
| 3164 | }) |
| 3165 | tests = append(tests, testCase{ |
| 3166 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3167 | name: "ClientAuth-ECDSA-Client", |
| 3168 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3169 | MaxVersion: VersionTLS12, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3170 | ClientAuth: RequireAnyClientCert, |
| 3171 | }, |
| 3172 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3173 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3174 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3175 | }, |
| 3176 | }) |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3177 | tests = append(tests, testCase{ |
| 3178 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3179 | name: "ClientAuth-ECDSA-Client-TLS13", |
| 3180 | config: Config{ |
| 3181 | MaxVersion: VersionTLS13, |
| 3182 | ClientAuth: RequireAnyClientCert, |
| 3183 | }, |
| 3184 | flags: []string{ |
| 3185 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3186 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 3187 | }, |
| 3188 | }) |
| 3189 | tests = append(tests, testCase{ |
| 3190 | testType: clientTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3191 | name: "ClientAuth-NoCertificate-OldCallback", |
| 3192 | config: Config{ |
| 3193 | MaxVersion: VersionTLS12, |
| 3194 | ClientAuth: RequestClientCert, |
| 3195 | }, |
| 3196 | flags: []string{"-use-old-client-cert-callback"}, |
| 3197 | }) |
| 3198 | tests = append(tests, testCase{ |
| 3199 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3200 | name: "ClientAuth-NoCertificate-OldCallback-TLS13", |
| 3201 | config: Config{ |
| 3202 | MaxVersion: VersionTLS13, |
| 3203 | ClientAuth: RequestClientCert, |
| 3204 | }, |
| 3205 | flags: []string{"-use-old-client-cert-callback"}, |
| 3206 | }) |
| 3207 | tests = append(tests, testCase{ |
| 3208 | testType: clientTest, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3209 | name: "ClientAuth-OldCallback", |
| 3210 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3211 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3212 | ClientAuth: RequireAnyClientCert, |
| 3213 | }, |
| 3214 | flags: []string{ |
| 3215 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3216 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3217 | "-use-old-client-cert-callback", |
| 3218 | }, |
| 3219 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3220 | tests = append(tests, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3221 | testType: clientTest, |
| 3222 | name: "ClientAuth-OldCallback-TLS13", |
| 3223 | config: Config{ |
| 3224 | MaxVersion: VersionTLS13, |
| 3225 | ClientAuth: RequireAnyClientCert, |
| 3226 | }, |
| 3227 | flags: []string{ |
| 3228 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3229 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3230 | "-use-old-client-cert-callback", |
| 3231 | }, |
| 3232 | }) |
| 3233 | tests = append(tests, testCase{ |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3234 | testType: serverTest, |
| 3235 | name: "ClientAuth-Server", |
| 3236 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3237 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3238 | Certificates: []Certificate{rsaCertificate}, |
| 3239 | }, |
| 3240 | flags: []string{"-require-any-client-certificate"}, |
| 3241 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3242 | tests = append(tests, testCase{ |
| 3243 | testType: serverTest, |
| 3244 | name: "ClientAuth-Server-TLS13", |
| 3245 | config: Config{ |
| 3246 | MaxVersion: VersionTLS13, |
| 3247 | Certificates: []Certificate{rsaCertificate}, |
| 3248 | }, |
| 3249 | flags: []string{"-require-any-client-certificate"}, |
| 3250 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3251 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3252 | // Test each key exchange on the server side for async keys. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3253 | tests = append(tests, testCase{ |
| 3254 | testType: serverTest, |
| 3255 | name: "Basic-Server-RSA", |
| 3256 | config: Config{ |
| 3257 | MaxVersion: VersionTLS12, |
| 3258 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 3259 | }, |
| 3260 | flags: []string{ |
| 3261 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3262 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3263 | }, |
| 3264 | }) |
| 3265 | tests = append(tests, testCase{ |
| 3266 | testType: serverTest, |
| 3267 | name: "Basic-Server-ECDHE-RSA", |
| 3268 | config: Config{ |
| 3269 | MaxVersion: VersionTLS12, |
| 3270 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3271 | }, |
| 3272 | flags: []string{ |
| 3273 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3274 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3275 | }, |
| 3276 | }) |
| 3277 | tests = append(tests, testCase{ |
| 3278 | testType: serverTest, |
| 3279 | name: "Basic-Server-ECDHE-ECDSA", |
| 3280 | config: Config{ |
| 3281 | MaxVersion: VersionTLS12, |
| 3282 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 3283 | }, |
| 3284 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3285 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3286 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3287 | }, |
| 3288 | }) |
| 3289 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3290 | // No session ticket support; server doesn't send NewSessionTicket. |
| 3291 | tests = append(tests, testCase{ |
| 3292 | name: "SessionTicketsDisabled-Client", |
| 3293 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3294 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3295 | SessionTicketsDisabled: true, |
| 3296 | }, |
| 3297 | }) |
| 3298 | tests = append(tests, testCase{ |
| 3299 | testType: serverTest, |
| 3300 | name: "SessionTicketsDisabled-Server", |
| 3301 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3302 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3303 | SessionTicketsDisabled: true, |
| 3304 | }, |
| 3305 | }) |
| 3306 | |
| 3307 | // Skip ServerKeyExchange in PSK key exchange if there's no |
| 3308 | // identity hint. |
| 3309 | tests = append(tests, testCase{ |
| 3310 | name: "EmptyPSKHint-Client", |
| 3311 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3312 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3313 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3314 | PreSharedKey: []byte("secret"), |
| 3315 | }, |
| 3316 | flags: []string{"-psk", "secret"}, |
| 3317 | }) |
| 3318 | tests = append(tests, testCase{ |
| 3319 | testType: serverTest, |
| 3320 | name: "EmptyPSKHint-Server", |
| 3321 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3322 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3323 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3324 | PreSharedKey: []byte("secret"), |
| 3325 | }, |
| 3326 | flags: []string{"-psk", "secret"}, |
| 3327 | }) |
| 3328 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3329 | // OCSP stapling tests. |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3330 | tests = append(tests, testCase{ |
| 3331 | testType: clientTest, |
| 3332 | name: "OCSPStapling-Client", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3333 | config: Config{ |
| 3334 | MaxVersion: VersionTLS12, |
| 3335 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3336 | flags: []string{ |
| 3337 | "-enable-ocsp-stapling", |
| 3338 | "-expect-ocsp-response", |
| 3339 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3340 | "-verify-peer", |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3341 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3342 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3343 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3344 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3345 | testType: serverTest, |
| 3346 | name: "OCSPStapling-Server", |
| 3347 | config: Config{ |
| 3348 | MaxVersion: VersionTLS12, |
| 3349 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3350 | expectedOCSPResponse: testOCSPResponse, |
| 3351 | flags: []string{ |
| 3352 | "-ocsp-response", |
| 3353 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3354 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3355 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3356 | }) |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3357 | tests = append(tests, testCase{ |
| 3358 | testType: clientTest, |
| 3359 | name: "OCSPStapling-Client-TLS13", |
| 3360 | config: Config{ |
| 3361 | MaxVersion: VersionTLS13, |
| 3362 | }, |
| 3363 | flags: []string{ |
| 3364 | "-enable-ocsp-stapling", |
| 3365 | "-expect-ocsp-response", |
| 3366 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3367 | "-verify-peer", |
| 3368 | }, |
| 3369 | // TODO(davidben): Enable this when resumption is implemented |
| 3370 | // in TLS 1.3. |
| 3371 | resumeSession: false, |
| 3372 | }) |
| 3373 | tests = append(tests, testCase{ |
| 3374 | testType: serverTest, |
| 3375 | name: "OCSPStapling-Server-TLS13", |
| 3376 | config: Config{ |
| 3377 | MaxVersion: VersionTLS13, |
| 3378 | }, |
| 3379 | expectedOCSPResponse: testOCSPResponse, |
| 3380 | flags: []string{ |
| 3381 | "-ocsp-response", |
| 3382 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3383 | }, |
| 3384 | // TODO(davidben): Enable this when resumption is implemented |
| 3385 | // in TLS 1.3. |
| 3386 | resumeSession: false, |
| 3387 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3388 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3389 | // Certificate verification tests. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3390 | for _, vers := range tlsVersions { |
| 3391 | if config.protocol == dtls && !vers.hasDTLS { |
| 3392 | continue |
| 3393 | } |
| 3394 | tests = append(tests, testCase{ |
| 3395 | testType: clientTest, |
| 3396 | name: "CertificateVerificationSucceed-" + vers.name, |
| 3397 | config: Config{ |
| 3398 | MaxVersion: vers.version, |
| 3399 | }, |
| 3400 | flags: []string{ |
| 3401 | "-verify-peer", |
| 3402 | }, |
Adam Langley | 9498e74 | 2016-07-18 10:17:16 -0700 | [diff] [blame] | 3403 | resumeSession: vers.version != VersionTLS13, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3404 | }) |
| 3405 | tests = append(tests, testCase{ |
| 3406 | testType: clientTest, |
| 3407 | name: "CertificateVerificationFail-" + vers.name, |
| 3408 | config: Config{ |
| 3409 | MaxVersion: vers.version, |
| 3410 | }, |
| 3411 | flags: []string{ |
| 3412 | "-verify-fail", |
| 3413 | "-verify-peer", |
| 3414 | }, |
| 3415 | shouldFail: true, |
| 3416 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 3417 | }) |
| 3418 | tests = append(tests, testCase{ |
| 3419 | testType: clientTest, |
| 3420 | name: "CertificateVerificationSoftFail-" + vers.name, |
| 3421 | config: Config{ |
| 3422 | MaxVersion: vers.version, |
| 3423 | }, |
| 3424 | flags: []string{ |
| 3425 | "-verify-fail", |
| 3426 | "-expect-verify-result", |
| 3427 | }, |
Adam Langley | 9498e74 | 2016-07-18 10:17:16 -0700 | [diff] [blame] | 3428 | resumeSession: vers.version != VersionTLS13, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3429 | }) |
| 3430 | } |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3431 | |
David Benjamin | 1d4f4c0 | 2016-07-26 18:03:08 -0400 | [diff] [blame] | 3432 | tests = append(tests, testCase{ |
| 3433 | name: "ShimSendAlert", |
| 3434 | flags: []string{"-send-alert"}, |
| 3435 | shimWritesFirst: true, |
| 3436 | shouldFail: true, |
| 3437 | expectedLocalError: "remote error: decompression failure", |
| 3438 | }) |
| 3439 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3440 | if config.protocol == tls { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3441 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3442 | name: "Renegotiate-Client", |
| 3443 | config: Config{ |
| 3444 | MaxVersion: VersionTLS12, |
| 3445 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 3446 | renegotiate: 1, |
| 3447 | flags: []string{ |
| 3448 | "-renegotiate-freely", |
| 3449 | "-expect-total-renegotiations", "1", |
| 3450 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3451 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3452 | |
David Benjamin | 4792110 | 2016-07-28 11:29:18 -0400 | [diff] [blame] | 3453 | tests = append(tests, testCase{ |
| 3454 | name: "SendHalfHelloRequest", |
| 3455 | config: Config{ |
| 3456 | MaxVersion: VersionTLS12, |
| 3457 | Bugs: ProtocolBugs{ |
| 3458 | PackHelloRequestWithFinished: config.packHandshakeFlight, |
| 3459 | }, |
| 3460 | }, |
| 3461 | sendHalfHelloRequest: true, |
| 3462 | flags: []string{"-renegotiate-ignore"}, |
| 3463 | shouldFail: true, |
| 3464 | expectedError: ":UNEXPECTED_RECORD:", |
| 3465 | }) |
| 3466 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3467 | // NPN on client and server; results in post-handshake message. |
| 3468 | tests = append(tests, testCase{ |
| 3469 | name: "NPN-Client", |
| 3470 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3471 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3472 | NextProtos: []string{"foo"}, |
| 3473 | }, |
| 3474 | flags: []string{"-select-next-proto", "foo"}, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3475 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3476 | expectedNextProto: "foo", |
| 3477 | expectedNextProtoType: npn, |
| 3478 | }) |
| 3479 | tests = append(tests, testCase{ |
| 3480 | testType: serverTest, |
| 3481 | name: "NPN-Server", |
| 3482 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3483 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3484 | NextProtos: []string{"bar"}, |
| 3485 | }, |
| 3486 | flags: []string{ |
| 3487 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3488 | "-expect-next-proto", "bar", |
| 3489 | }, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3490 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3491 | expectedNextProto: "bar", |
| 3492 | expectedNextProtoType: npn, |
| 3493 | }) |
| 3494 | |
| 3495 | // TODO(davidben): Add tests for when False Start doesn't trigger. |
| 3496 | |
| 3497 | // Client does False Start and negotiates NPN. |
| 3498 | tests = append(tests, testCase{ |
| 3499 | name: "FalseStart", |
| 3500 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3501 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3502 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3503 | NextProtos: []string{"foo"}, |
| 3504 | Bugs: ProtocolBugs{ |
| 3505 | ExpectFalseStart: true, |
| 3506 | }, |
| 3507 | }, |
| 3508 | flags: []string{ |
| 3509 | "-false-start", |
| 3510 | "-select-next-proto", "foo", |
| 3511 | }, |
| 3512 | shimWritesFirst: true, |
| 3513 | resumeSession: true, |
| 3514 | }) |
| 3515 | |
| 3516 | // Client does False Start and negotiates ALPN. |
| 3517 | tests = append(tests, testCase{ |
| 3518 | name: "FalseStart-ALPN", |
| 3519 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3520 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3521 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3522 | NextProtos: []string{"foo"}, |
| 3523 | Bugs: ProtocolBugs{ |
| 3524 | ExpectFalseStart: true, |
| 3525 | }, |
| 3526 | }, |
| 3527 | flags: []string{ |
| 3528 | "-false-start", |
| 3529 | "-advertise-alpn", "\x03foo", |
| 3530 | }, |
| 3531 | shimWritesFirst: true, |
| 3532 | resumeSession: true, |
| 3533 | }) |
| 3534 | |
| 3535 | // Client does False Start but doesn't explicitly call |
| 3536 | // SSL_connect. |
| 3537 | tests = append(tests, testCase{ |
| 3538 | name: "FalseStart-Implicit", |
| 3539 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3540 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3541 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3542 | NextProtos: []string{"foo"}, |
| 3543 | }, |
| 3544 | flags: []string{ |
| 3545 | "-implicit-handshake", |
| 3546 | "-false-start", |
| 3547 | "-advertise-alpn", "\x03foo", |
| 3548 | }, |
| 3549 | }) |
| 3550 | |
| 3551 | // False Start without session tickets. |
| 3552 | tests = append(tests, testCase{ |
| 3553 | name: "FalseStart-SessionTicketsDisabled", |
| 3554 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3555 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3556 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3557 | NextProtos: []string{"foo"}, |
| 3558 | SessionTicketsDisabled: true, |
| 3559 | Bugs: ProtocolBugs{ |
| 3560 | ExpectFalseStart: true, |
| 3561 | }, |
| 3562 | }, |
| 3563 | flags: []string{ |
| 3564 | "-false-start", |
| 3565 | "-select-next-proto", "foo", |
| 3566 | }, |
| 3567 | shimWritesFirst: true, |
| 3568 | }) |
| 3569 | |
Adam Langley | df759b5 | 2016-07-11 15:24:37 -0700 | [diff] [blame] | 3570 | tests = append(tests, testCase{ |
| 3571 | name: "FalseStart-CECPQ1", |
| 3572 | config: Config{ |
| 3573 | MaxVersion: VersionTLS12, |
| 3574 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 3575 | NextProtos: []string{"foo"}, |
| 3576 | Bugs: ProtocolBugs{ |
| 3577 | ExpectFalseStart: true, |
| 3578 | }, |
| 3579 | }, |
| 3580 | flags: []string{ |
| 3581 | "-false-start", |
| 3582 | "-cipher", "DEFAULT:kCECPQ1", |
| 3583 | "-select-next-proto", "foo", |
| 3584 | }, |
| 3585 | shimWritesFirst: true, |
| 3586 | resumeSession: true, |
| 3587 | }) |
| 3588 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3589 | // Server parses a V2ClientHello. |
| 3590 | tests = append(tests, testCase{ |
| 3591 | testType: serverTest, |
| 3592 | name: "SendV2ClientHello", |
| 3593 | config: Config{ |
| 3594 | // Choose a cipher suite that does not involve |
| 3595 | // elliptic curves, so no extensions are |
| 3596 | // involved. |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3597 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3598 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 3599 | Bugs: ProtocolBugs{ |
| 3600 | SendV2ClientHello: true, |
| 3601 | }, |
| 3602 | }, |
| 3603 | }) |
| 3604 | |
| 3605 | // Client sends a Channel ID. |
| 3606 | tests = append(tests, testCase{ |
| 3607 | name: "ChannelID-Client", |
| 3608 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3609 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3610 | RequestChannelID: true, |
| 3611 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3612 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3613 | resumeSession: true, |
| 3614 | expectChannelID: true, |
| 3615 | }) |
| 3616 | |
| 3617 | // Server accepts a Channel ID. |
| 3618 | tests = append(tests, testCase{ |
| 3619 | testType: serverTest, |
| 3620 | name: "ChannelID-Server", |
| 3621 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3622 | MaxVersion: VersionTLS12, |
| 3623 | ChannelID: channelIDKey, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3624 | }, |
| 3625 | flags: []string{ |
| 3626 | "-expect-channel-id", |
| 3627 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3628 | }, |
| 3629 | resumeSession: true, |
| 3630 | expectChannelID: true, |
| 3631 | }) |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3632 | |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3633 | // Channel ID and NPN at the same time, to ensure their relative |
| 3634 | // ordering is correct. |
| 3635 | tests = append(tests, testCase{ |
| 3636 | name: "ChannelID-NPN-Client", |
| 3637 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3638 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3639 | RequestChannelID: true, |
| 3640 | NextProtos: []string{"foo"}, |
| 3641 | }, |
| 3642 | flags: []string{ |
| 3643 | "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile), |
| 3644 | "-select-next-proto", "foo", |
| 3645 | }, |
| 3646 | resumeSession: true, |
| 3647 | expectChannelID: true, |
| 3648 | expectedNextProto: "foo", |
| 3649 | expectedNextProtoType: npn, |
| 3650 | }) |
| 3651 | tests = append(tests, testCase{ |
| 3652 | testType: serverTest, |
| 3653 | name: "ChannelID-NPN-Server", |
| 3654 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3655 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3656 | ChannelID: channelIDKey, |
| 3657 | NextProtos: []string{"bar"}, |
| 3658 | }, |
| 3659 | flags: []string{ |
| 3660 | "-expect-channel-id", |
| 3661 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3662 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3663 | "-expect-next-proto", "bar", |
| 3664 | }, |
| 3665 | resumeSession: true, |
| 3666 | expectChannelID: true, |
| 3667 | expectedNextProto: "bar", |
| 3668 | expectedNextProtoType: npn, |
| 3669 | }) |
| 3670 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3671 | // Bidirectional shutdown with the runner initiating. |
| 3672 | tests = append(tests, testCase{ |
| 3673 | name: "Shutdown-Runner", |
| 3674 | config: Config{ |
| 3675 | Bugs: ProtocolBugs{ |
| 3676 | ExpectCloseNotify: true, |
| 3677 | }, |
| 3678 | }, |
| 3679 | flags: []string{"-check-close-notify"}, |
| 3680 | }) |
| 3681 | |
| 3682 | // Bidirectional shutdown with the shim initiating. The runner, |
| 3683 | // in the meantime, sends garbage before the close_notify which |
| 3684 | // the shim must ignore. |
| 3685 | tests = append(tests, testCase{ |
| 3686 | name: "Shutdown-Shim", |
| 3687 | config: Config{ |
| 3688 | Bugs: ProtocolBugs{ |
| 3689 | ExpectCloseNotify: true, |
| 3690 | }, |
| 3691 | }, |
| 3692 | shimShutsDown: true, |
| 3693 | sendEmptyRecords: 1, |
| 3694 | sendWarningAlerts: 1, |
| 3695 | flags: []string{"-check-close-notify"}, |
| 3696 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3697 | } else { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3698 | // TODO(davidben): DTLS 1.3 will want a similar thing for |
| 3699 | // HelloRetryRequest. |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3700 | tests = append(tests, testCase{ |
| 3701 | name: "SkipHelloVerifyRequest", |
| 3702 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3703 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3704 | Bugs: ProtocolBugs{ |
| 3705 | SkipHelloVerifyRequest: true, |
| 3706 | }, |
| 3707 | }, |
| 3708 | }) |
| 3709 | } |
| 3710 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3711 | for _, test := range tests { |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3712 | test.protocol = config.protocol |
| 3713 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3714 | test.name += "-DTLS" |
| 3715 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3716 | if config.async { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3717 | test.name += "-Async" |
| 3718 | test.flags = append(test.flags, "-async") |
| 3719 | } else { |
| 3720 | test.name += "-Sync" |
| 3721 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3722 | if config.splitHandshake { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3723 | test.name += "-SplitHandshakeRecords" |
| 3724 | test.config.Bugs.MaxHandshakeRecordLength = 1 |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3725 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3726 | test.config.Bugs.MaxPacketLength = 256 |
| 3727 | test.flags = append(test.flags, "-mtu", "256") |
| 3728 | } |
| 3729 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3730 | if config.packHandshakeFlight { |
| 3731 | test.name += "-PackHandshakeFlight" |
| 3732 | test.config.Bugs.PackHandshakeFlight = true |
| 3733 | } |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3734 | testCases = append(testCases, test) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 3735 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 3736 | } |
| 3737 | |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3738 | func addDDoSCallbackTests() { |
| 3739 | // DDoS callback. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3740 | // TODO(davidben): Implement DDoS resumption tests for TLS 1.3. |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3741 | for _, resume := range []bool{false, true} { |
| 3742 | suffix := "Resume" |
| 3743 | if resume { |
| 3744 | suffix = "No" + suffix |
| 3745 | } |
| 3746 | |
| 3747 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3748 | testType: serverTest, |
| 3749 | name: "Server-DDoS-OK-" + suffix, |
| 3750 | config: Config{ |
| 3751 | MaxVersion: VersionTLS12, |
| 3752 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3753 | flags: []string{"-install-ddos-callback"}, |
| 3754 | resumeSession: resume, |
| 3755 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3756 | if !resume { |
| 3757 | testCases = append(testCases, testCase{ |
| 3758 | testType: serverTest, |
| 3759 | name: "Server-DDoS-OK-" + suffix + "-TLS13", |
| 3760 | config: Config{ |
| 3761 | MaxVersion: VersionTLS13, |
| 3762 | }, |
| 3763 | flags: []string{"-install-ddos-callback"}, |
| 3764 | resumeSession: resume, |
| 3765 | }) |
| 3766 | } |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3767 | |
| 3768 | failFlag := "-fail-ddos-callback" |
| 3769 | if resume { |
| 3770 | failFlag = "-fail-second-ddos-callback" |
| 3771 | } |
| 3772 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3773 | testType: serverTest, |
| 3774 | name: "Server-DDoS-Reject-" + suffix, |
| 3775 | config: Config{ |
| 3776 | MaxVersion: VersionTLS12, |
| 3777 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3778 | flags: []string{"-install-ddos-callback", failFlag}, |
| 3779 | resumeSession: resume, |
| 3780 | shouldFail: true, |
| 3781 | expectedError: ":CONNECTION_REJECTED:", |
| 3782 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3783 | if !resume { |
| 3784 | testCases = append(testCases, testCase{ |
| 3785 | testType: serverTest, |
| 3786 | name: "Server-DDoS-Reject-" + suffix + "-TLS13", |
| 3787 | config: Config{ |
| 3788 | MaxVersion: VersionTLS13, |
| 3789 | }, |
| 3790 | flags: []string{"-install-ddos-callback", failFlag}, |
| 3791 | resumeSession: resume, |
| 3792 | shouldFail: true, |
| 3793 | expectedError: ":CONNECTION_REJECTED:", |
| 3794 | }) |
| 3795 | } |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3796 | } |
| 3797 | } |
| 3798 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3799 | func addVersionNegotiationTests() { |
| 3800 | for i, shimVers := range tlsVersions { |
| 3801 | // Assemble flags to disable all newer versions on the shim. |
| 3802 | var flags []string |
| 3803 | for _, vers := range tlsVersions[i+1:] { |
| 3804 | flags = append(flags, vers.flag) |
| 3805 | } |
| 3806 | |
| 3807 | for _, runnerVers := range tlsVersions { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3808 | protocols := []protocol{tls} |
| 3809 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 3810 | protocols = append(protocols, dtls) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3811 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3812 | for _, protocol := range protocols { |
| 3813 | expectedVersion := shimVers.version |
| 3814 | if runnerVers.version < shimVers.version { |
| 3815 | expectedVersion = runnerVers.version |
| 3816 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3817 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3818 | suffix := shimVers.name + "-" + runnerVers.name |
| 3819 | if protocol == dtls { |
| 3820 | suffix += "-DTLS" |
| 3821 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3822 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3823 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 3824 | |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3825 | clientVers := shimVers.version |
| 3826 | if clientVers > VersionTLS10 { |
| 3827 | clientVers = VersionTLS10 |
| 3828 | } |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3829 | serverVers := expectedVersion |
| 3830 | if expectedVersion >= VersionTLS13 { |
| 3831 | serverVers = VersionTLS10 |
| 3832 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3833 | testCases = append(testCases, testCase{ |
| 3834 | protocol: protocol, |
| 3835 | testType: clientTest, |
| 3836 | name: "VersionNegotiation-Client-" + suffix, |
| 3837 | config: Config{ |
| 3838 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3839 | Bugs: ProtocolBugs{ |
| 3840 | ExpectInitialRecordVersion: clientVers, |
| 3841 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3842 | }, |
| 3843 | flags: flags, |
| 3844 | expectedVersion: expectedVersion, |
| 3845 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3846 | testCases = append(testCases, testCase{ |
| 3847 | protocol: protocol, |
| 3848 | testType: clientTest, |
| 3849 | name: "VersionNegotiation-Client2-" + suffix, |
| 3850 | config: Config{ |
| 3851 | MaxVersion: runnerVers.version, |
| 3852 | Bugs: ProtocolBugs{ |
| 3853 | ExpectInitialRecordVersion: clientVers, |
| 3854 | }, |
| 3855 | }, |
| 3856 | flags: []string{"-max-version", shimVersFlag}, |
| 3857 | expectedVersion: expectedVersion, |
| 3858 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3859 | |
| 3860 | testCases = append(testCases, testCase{ |
| 3861 | protocol: protocol, |
| 3862 | testType: serverTest, |
| 3863 | name: "VersionNegotiation-Server-" + suffix, |
| 3864 | config: Config{ |
| 3865 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3866 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3867 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3868 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3869 | }, |
| 3870 | flags: flags, |
| 3871 | expectedVersion: expectedVersion, |
| 3872 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3873 | testCases = append(testCases, testCase{ |
| 3874 | protocol: protocol, |
| 3875 | testType: serverTest, |
| 3876 | name: "VersionNegotiation-Server2-" + suffix, |
| 3877 | config: Config{ |
| 3878 | MaxVersion: runnerVers.version, |
| 3879 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3880 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3881 | }, |
| 3882 | }, |
| 3883 | flags: []string{"-max-version", shimVersFlag}, |
| 3884 | expectedVersion: expectedVersion, |
| 3885 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3886 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3887 | } |
| 3888 | } |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 3889 | |
| 3890 | // Test for version tolerance. |
| 3891 | testCases = append(testCases, testCase{ |
| 3892 | testType: serverTest, |
| 3893 | name: "MinorVersionTolerance", |
| 3894 | config: Config{ |
| 3895 | Bugs: ProtocolBugs{ |
| 3896 | SendClientVersion: 0x03ff, |
| 3897 | }, |
| 3898 | }, |
| 3899 | expectedVersion: VersionTLS13, |
| 3900 | }) |
| 3901 | testCases = append(testCases, testCase{ |
| 3902 | testType: serverTest, |
| 3903 | name: "MajorVersionTolerance", |
| 3904 | config: Config{ |
| 3905 | Bugs: ProtocolBugs{ |
| 3906 | SendClientVersion: 0x0400, |
| 3907 | }, |
| 3908 | }, |
| 3909 | expectedVersion: VersionTLS13, |
| 3910 | }) |
| 3911 | testCases = append(testCases, testCase{ |
| 3912 | protocol: dtls, |
| 3913 | testType: serverTest, |
| 3914 | name: "MinorVersionTolerance-DTLS", |
| 3915 | config: Config{ |
| 3916 | Bugs: ProtocolBugs{ |
| 3917 | SendClientVersion: 0x03ff, |
| 3918 | }, |
| 3919 | }, |
| 3920 | expectedVersion: VersionTLS12, |
| 3921 | }) |
| 3922 | testCases = append(testCases, testCase{ |
| 3923 | protocol: dtls, |
| 3924 | testType: serverTest, |
| 3925 | name: "MajorVersionTolerance-DTLS", |
| 3926 | config: Config{ |
| 3927 | Bugs: ProtocolBugs{ |
| 3928 | SendClientVersion: 0x0400, |
| 3929 | }, |
| 3930 | }, |
| 3931 | expectedVersion: VersionTLS12, |
| 3932 | }) |
| 3933 | |
| 3934 | // Test that versions below 3.0 are rejected. |
| 3935 | testCases = append(testCases, testCase{ |
| 3936 | testType: serverTest, |
| 3937 | name: "VersionTooLow", |
| 3938 | config: Config{ |
| 3939 | Bugs: ProtocolBugs{ |
| 3940 | SendClientVersion: 0x0200, |
| 3941 | }, |
| 3942 | }, |
| 3943 | shouldFail: true, |
| 3944 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 3945 | }) |
| 3946 | testCases = append(testCases, testCase{ |
| 3947 | protocol: dtls, |
| 3948 | testType: serverTest, |
| 3949 | name: "VersionTooLow-DTLS", |
| 3950 | config: Config{ |
| 3951 | Bugs: ProtocolBugs{ |
| 3952 | // 0x0201 is the lowest version expressable in |
| 3953 | // DTLS. |
| 3954 | SendClientVersion: 0x0201, |
| 3955 | }, |
| 3956 | }, |
| 3957 | shouldFail: true, |
| 3958 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 3959 | }) |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 3960 | |
| 3961 | // Test TLS 1.3's downgrade signal. |
| 3962 | testCases = append(testCases, testCase{ |
| 3963 | name: "Downgrade-TLS12-Client", |
| 3964 | config: Config{ |
| 3965 | Bugs: ProtocolBugs{ |
| 3966 | NegotiateVersion: VersionTLS12, |
| 3967 | }, |
| 3968 | }, |
| 3969 | shouldFail: true, |
| 3970 | expectedError: ":DOWNGRADE_DETECTED:", |
| 3971 | }) |
| 3972 | testCases = append(testCases, testCase{ |
| 3973 | testType: serverTest, |
| 3974 | name: "Downgrade-TLS12-Server", |
| 3975 | config: Config{ |
| 3976 | Bugs: ProtocolBugs{ |
| 3977 | SendClientVersion: VersionTLS12, |
| 3978 | }, |
| 3979 | }, |
| 3980 | shouldFail: true, |
| 3981 | expectedLocalError: "tls: downgrade from TLS 1.3 detected", |
| 3982 | }) |
David Benjamin | 5e7e7cc | 2016-07-21 12:55:28 +0200 | [diff] [blame] | 3983 | |
| 3984 | // Test that FALLBACK_SCSV is sent and that the downgrade signal works |
| 3985 | // behave correctly when both real maximum and fallback versions are |
| 3986 | // set. |
| 3987 | testCases = append(testCases, testCase{ |
| 3988 | name: "Downgrade-TLS12-Client-Fallback", |
| 3989 | config: Config{ |
| 3990 | Bugs: ProtocolBugs{ |
| 3991 | FailIfNotFallbackSCSV: true, |
| 3992 | }, |
| 3993 | }, |
| 3994 | flags: []string{ |
| 3995 | "-max-version", strconv.Itoa(VersionTLS13), |
| 3996 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 3997 | }, |
| 3998 | shouldFail: true, |
| 3999 | expectedError: ":DOWNGRADE_DETECTED:", |
| 4000 | }) |
| 4001 | testCases = append(testCases, testCase{ |
| 4002 | name: "Downgrade-TLS12-Client-FallbackEqualsMax", |
| 4003 | flags: []string{ |
| 4004 | "-max-version", strconv.Itoa(VersionTLS12), |
| 4005 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 4006 | }, |
| 4007 | }) |
| 4008 | |
| 4009 | // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather |
| 4010 | // just have such connections fail than risk getting confused because we |
| 4011 | // didn't sent the 1.3 ClientHello.) |
| 4012 | testCases = append(testCases, testCase{ |
| 4013 | name: "Downgrade-TLS12-Fallback-CheckVersion", |
| 4014 | config: Config{ |
| 4015 | Bugs: ProtocolBugs{ |
| 4016 | NegotiateVersion: VersionTLS13, |
| 4017 | FailIfNotFallbackSCSV: true, |
| 4018 | }, |
| 4019 | }, |
| 4020 | flags: []string{ |
| 4021 | "-max-version", strconv.Itoa(VersionTLS13), |
| 4022 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 4023 | }, |
| 4024 | shouldFail: true, |
| 4025 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 4026 | }) |
| 4027 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 4028 | } |
| 4029 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4030 | func addMinimumVersionTests() { |
| 4031 | for i, shimVers := range tlsVersions { |
| 4032 | // Assemble flags to disable all older versions on the shim. |
| 4033 | var flags []string |
| 4034 | for _, vers := range tlsVersions[:i] { |
| 4035 | flags = append(flags, vers.flag) |
| 4036 | } |
| 4037 | |
| 4038 | for _, runnerVers := range tlsVersions { |
| 4039 | protocols := []protocol{tls} |
| 4040 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 4041 | protocols = append(protocols, dtls) |
| 4042 | } |
| 4043 | for _, protocol := range protocols { |
| 4044 | suffix := shimVers.name + "-" + runnerVers.name |
| 4045 | if protocol == dtls { |
| 4046 | suffix += "-DTLS" |
| 4047 | } |
| 4048 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 4049 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4050 | var expectedVersion uint16 |
| 4051 | var shouldFail bool |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4052 | var expectedClientError, expectedServerError string |
| 4053 | var expectedClientLocalError, expectedServerLocalError string |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4054 | if runnerVers.version >= shimVers.version { |
| 4055 | expectedVersion = runnerVers.version |
| 4056 | } else { |
| 4057 | shouldFail = true |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4058 | expectedServerError = ":UNSUPPORTED_PROTOCOL:" |
| 4059 | expectedServerLocalError = "remote error: protocol version not supported" |
| 4060 | if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 { |
| 4061 | // If the client's minimum version is TLS 1.3 and the runner's |
| 4062 | // maximum is below TLS 1.2, the runner will fail to select a |
| 4063 | // cipher before the shim rejects the selected version. |
| 4064 | expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:" |
| 4065 | expectedClientLocalError = "tls: no cipher suite supported by both client and server" |
| 4066 | } else { |
| 4067 | expectedClientError = expectedServerError |
| 4068 | expectedClientLocalError = expectedServerLocalError |
| 4069 | } |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | testCases = append(testCases, testCase{ |
| 4073 | protocol: protocol, |
| 4074 | testType: clientTest, |
| 4075 | name: "MinimumVersion-Client-" + suffix, |
| 4076 | config: Config{ |
| 4077 | MaxVersion: runnerVers.version, |
| 4078 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4079 | flags: flags, |
| 4080 | expectedVersion: expectedVersion, |
| 4081 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4082 | expectedError: expectedClientError, |
| 4083 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4084 | }) |
| 4085 | testCases = append(testCases, testCase{ |
| 4086 | protocol: protocol, |
| 4087 | testType: clientTest, |
| 4088 | name: "MinimumVersion-Client2-" + suffix, |
| 4089 | config: Config{ |
| 4090 | MaxVersion: runnerVers.version, |
| 4091 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4092 | flags: []string{"-min-version", shimVersFlag}, |
| 4093 | expectedVersion: expectedVersion, |
| 4094 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4095 | expectedError: expectedClientError, |
| 4096 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4097 | }) |
| 4098 | |
| 4099 | testCases = append(testCases, testCase{ |
| 4100 | protocol: protocol, |
| 4101 | testType: serverTest, |
| 4102 | name: "MinimumVersion-Server-" + suffix, |
| 4103 | config: Config{ |
| 4104 | MaxVersion: runnerVers.version, |
| 4105 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4106 | flags: flags, |
| 4107 | expectedVersion: expectedVersion, |
| 4108 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4109 | expectedError: expectedServerError, |
| 4110 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4111 | }) |
| 4112 | testCases = append(testCases, testCase{ |
| 4113 | protocol: protocol, |
| 4114 | testType: serverTest, |
| 4115 | name: "MinimumVersion-Server2-" + suffix, |
| 4116 | config: Config{ |
| 4117 | MaxVersion: runnerVers.version, |
| 4118 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4119 | flags: []string{"-min-version", shimVersFlag}, |
| 4120 | expectedVersion: expectedVersion, |
| 4121 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4122 | expectedError: expectedServerError, |
| 4123 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4124 | }) |
| 4125 | } |
| 4126 | } |
| 4127 | } |
| 4128 | } |
| 4129 | |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4130 | func addExtensionTests() { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4131 | // TODO(davidben): Extensions, where applicable, all move their server |
| 4132 | // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these |
| 4133 | // tests for both. Also test interaction with 0-RTT when implemented. |
| 4134 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4135 | // Repeat extensions tests all versions except SSL 3.0. |
| 4136 | for _, ver := range tlsVersions { |
| 4137 | if ver.version == VersionSSL30 { |
| 4138 | continue |
| 4139 | } |
| 4140 | |
| 4141 | // TODO(davidben): Implement resumption in TLS 1.3. |
| 4142 | resumeSession := ver.version < VersionTLS13 |
| 4143 | |
| 4144 | // Test that duplicate extensions are rejected. |
| 4145 | testCases = append(testCases, testCase{ |
| 4146 | testType: clientTest, |
| 4147 | name: "DuplicateExtensionClient-" + ver.name, |
| 4148 | config: Config{ |
| 4149 | MaxVersion: ver.version, |
| 4150 | Bugs: ProtocolBugs{ |
| 4151 | DuplicateExtension: true, |
| 4152 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4153 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4154 | shouldFail: true, |
| 4155 | expectedLocalError: "remote error: error decoding message", |
| 4156 | }) |
| 4157 | testCases = append(testCases, testCase{ |
| 4158 | testType: serverTest, |
| 4159 | name: "DuplicateExtensionServer-" + ver.name, |
| 4160 | config: Config{ |
| 4161 | MaxVersion: ver.version, |
| 4162 | Bugs: ProtocolBugs{ |
| 4163 | DuplicateExtension: true, |
| 4164 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4165 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4166 | shouldFail: true, |
| 4167 | expectedLocalError: "remote error: error decoding message", |
| 4168 | }) |
| 4169 | |
| 4170 | // Test SNI. |
| 4171 | testCases = append(testCases, testCase{ |
| 4172 | testType: clientTest, |
| 4173 | name: "ServerNameExtensionClient-" + ver.name, |
| 4174 | config: Config{ |
| 4175 | MaxVersion: ver.version, |
| 4176 | Bugs: ProtocolBugs{ |
| 4177 | ExpectServerName: "example.com", |
| 4178 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4179 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4180 | flags: []string{"-host-name", "example.com"}, |
| 4181 | }) |
| 4182 | testCases = append(testCases, testCase{ |
| 4183 | testType: clientTest, |
| 4184 | name: "ServerNameExtensionClientMismatch-" + ver.name, |
| 4185 | config: Config{ |
| 4186 | MaxVersion: ver.version, |
| 4187 | Bugs: ProtocolBugs{ |
| 4188 | ExpectServerName: "mismatch.com", |
| 4189 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4190 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4191 | flags: []string{"-host-name", "example.com"}, |
| 4192 | shouldFail: true, |
| 4193 | expectedLocalError: "tls: unexpected server name", |
| 4194 | }) |
| 4195 | testCases = append(testCases, testCase{ |
| 4196 | testType: clientTest, |
| 4197 | name: "ServerNameExtensionClientMissing-" + ver.name, |
| 4198 | config: Config{ |
| 4199 | MaxVersion: ver.version, |
| 4200 | Bugs: ProtocolBugs{ |
| 4201 | ExpectServerName: "missing.com", |
| 4202 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4203 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4204 | shouldFail: true, |
| 4205 | expectedLocalError: "tls: unexpected server name", |
| 4206 | }) |
| 4207 | testCases = append(testCases, testCase{ |
| 4208 | testType: serverTest, |
| 4209 | name: "ServerNameExtensionServer-" + ver.name, |
| 4210 | config: Config{ |
| 4211 | MaxVersion: ver.version, |
| 4212 | ServerName: "example.com", |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 4213 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4214 | flags: []string{"-expect-server-name", "example.com"}, |
| 4215 | resumeSession: resumeSession, |
| 4216 | }) |
| 4217 | |
| 4218 | // Test ALPN. |
| 4219 | testCases = append(testCases, testCase{ |
| 4220 | testType: clientTest, |
| 4221 | name: "ALPNClient-" + ver.name, |
| 4222 | config: Config{ |
| 4223 | MaxVersion: ver.version, |
| 4224 | NextProtos: []string{"foo"}, |
| 4225 | }, |
| 4226 | flags: []string{ |
| 4227 | "-advertise-alpn", "\x03foo\x03bar\x03baz", |
| 4228 | "-expect-alpn", "foo", |
| 4229 | }, |
| 4230 | expectedNextProto: "foo", |
| 4231 | expectedNextProtoType: alpn, |
| 4232 | resumeSession: resumeSession, |
| 4233 | }) |
| 4234 | testCases = append(testCases, testCase{ |
| 4235 | testType: serverTest, |
| 4236 | name: "ALPNServer-" + ver.name, |
| 4237 | config: Config{ |
| 4238 | MaxVersion: ver.version, |
| 4239 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4240 | }, |
| 4241 | flags: []string{ |
| 4242 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4243 | "-select-alpn", "foo", |
| 4244 | }, |
| 4245 | expectedNextProto: "foo", |
| 4246 | expectedNextProtoType: alpn, |
| 4247 | resumeSession: resumeSession, |
| 4248 | }) |
| 4249 | testCases = append(testCases, testCase{ |
| 4250 | testType: serverTest, |
| 4251 | name: "ALPNServer-Decline-" + ver.name, |
| 4252 | config: Config{ |
| 4253 | MaxVersion: ver.version, |
| 4254 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4255 | }, |
| 4256 | flags: []string{"-decline-alpn"}, |
| 4257 | expectNoNextProto: true, |
| 4258 | resumeSession: resumeSession, |
| 4259 | }) |
| 4260 | |
| 4261 | var emptyString string |
| 4262 | testCases = append(testCases, testCase{ |
| 4263 | testType: clientTest, |
| 4264 | name: "ALPNClient-EmptyProtocolName-" + ver.name, |
| 4265 | config: Config{ |
| 4266 | MaxVersion: ver.version, |
| 4267 | NextProtos: []string{""}, |
| 4268 | Bugs: ProtocolBugs{ |
| 4269 | // A server returning an empty ALPN protocol |
| 4270 | // should be rejected. |
| 4271 | ALPNProtocol: &emptyString, |
| 4272 | }, |
| 4273 | }, |
| 4274 | flags: []string{ |
| 4275 | "-advertise-alpn", "\x03foo", |
| 4276 | }, |
| 4277 | shouldFail: true, |
| 4278 | expectedError: ":PARSE_TLSEXT:", |
| 4279 | }) |
| 4280 | testCases = append(testCases, testCase{ |
| 4281 | testType: serverTest, |
| 4282 | name: "ALPNServer-EmptyProtocolName-" + ver.name, |
| 4283 | config: Config{ |
| 4284 | MaxVersion: ver.version, |
| 4285 | // A ClientHello containing an empty ALPN protocol |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4286 | // should be rejected. |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4287 | NextProtos: []string{"foo", "", "baz"}, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4288 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4289 | flags: []string{ |
| 4290 | "-select-alpn", "foo", |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 4291 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4292 | shouldFail: true, |
| 4293 | expectedError: ":PARSE_TLSEXT:", |
| 4294 | }) |
| 4295 | |
| 4296 | // Test NPN and the interaction with ALPN. |
| 4297 | if ver.version < VersionTLS13 { |
| 4298 | // Test that the server prefers ALPN over NPN. |
| 4299 | testCases = append(testCases, testCase{ |
| 4300 | testType: serverTest, |
| 4301 | name: "ALPNServer-Preferred-" + ver.name, |
| 4302 | config: Config{ |
| 4303 | MaxVersion: ver.version, |
| 4304 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4305 | }, |
| 4306 | flags: []string{ |
| 4307 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4308 | "-select-alpn", "foo", |
| 4309 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4310 | }, |
| 4311 | expectedNextProto: "foo", |
| 4312 | expectedNextProtoType: alpn, |
| 4313 | resumeSession: resumeSession, |
| 4314 | }) |
| 4315 | testCases = append(testCases, testCase{ |
| 4316 | testType: serverTest, |
| 4317 | name: "ALPNServer-Preferred-Swapped-" + ver.name, |
| 4318 | config: Config{ |
| 4319 | MaxVersion: ver.version, |
| 4320 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4321 | Bugs: ProtocolBugs{ |
| 4322 | SwapNPNAndALPN: true, |
| 4323 | }, |
| 4324 | }, |
| 4325 | flags: []string{ |
| 4326 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4327 | "-select-alpn", "foo", |
| 4328 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4329 | }, |
| 4330 | expectedNextProto: "foo", |
| 4331 | expectedNextProtoType: alpn, |
| 4332 | resumeSession: resumeSession, |
| 4333 | }) |
| 4334 | |
| 4335 | // Test that negotiating both NPN and ALPN is forbidden. |
| 4336 | testCases = append(testCases, testCase{ |
| 4337 | name: "NegotiateALPNAndNPN-" + ver.name, |
| 4338 | config: Config{ |
| 4339 | MaxVersion: ver.version, |
| 4340 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4341 | Bugs: ProtocolBugs{ |
| 4342 | NegotiateALPNAndNPN: true, |
| 4343 | }, |
| 4344 | }, |
| 4345 | flags: []string{ |
| 4346 | "-advertise-alpn", "\x03foo", |
| 4347 | "-select-next-proto", "foo", |
| 4348 | }, |
| 4349 | shouldFail: true, |
| 4350 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4351 | }) |
| 4352 | testCases = append(testCases, testCase{ |
| 4353 | name: "NegotiateALPNAndNPN-Swapped-" + ver.name, |
| 4354 | config: Config{ |
| 4355 | MaxVersion: ver.version, |
| 4356 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4357 | Bugs: ProtocolBugs{ |
| 4358 | NegotiateALPNAndNPN: true, |
| 4359 | SwapNPNAndALPN: true, |
| 4360 | }, |
| 4361 | }, |
| 4362 | flags: []string{ |
| 4363 | "-advertise-alpn", "\x03foo", |
| 4364 | "-select-next-proto", "foo", |
| 4365 | }, |
| 4366 | shouldFail: true, |
| 4367 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4368 | }) |
| 4369 | |
| 4370 | // Test that NPN can be disabled with SSL_OP_DISABLE_NPN. |
| 4371 | testCases = append(testCases, testCase{ |
| 4372 | name: "DisableNPN-" + ver.name, |
| 4373 | config: Config{ |
| 4374 | MaxVersion: ver.version, |
| 4375 | NextProtos: []string{"foo"}, |
| 4376 | }, |
| 4377 | flags: []string{ |
| 4378 | "-select-next-proto", "foo", |
| 4379 | "-disable-npn", |
| 4380 | }, |
| 4381 | expectNoNextProto: true, |
| 4382 | }) |
| 4383 | } |
| 4384 | |
| 4385 | // Test ticket behavior. |
| 4386 | // |
| 4387 | // TODO(davidben): Add TLS 1.3 versions of these. |
| 4388 | if ver.version < VersionTLS13 { |
| 4389 | // Resume with a corrupt ticket. |
| 4390 | testCases = append(testCases, testCase{ |
| 4391 | testType: serverTest, |
| 4392 | name: "CorruptTicket-" + ver.name, |
| 4393 | config: Config{ |
| 4394 | MaxVersion: ver.version, |
| 4395 | Bugs: ProtocolBugs{ |
| 4396 | CorruptTicket: true, |
| 4397 | }, |
| 4398 | }, |
| 4399 | resumeSession: true, |
| 4400 | expectResumeRejected: true, |
| 4401 | }) |
| 4402 | // Test the ticket callback, with and without renewal. |
| 4403 | testCases = append(testCases, testCase{ |
| 4404 | testType: serverTest, |
| 4405 | name: "TicketCallback-" + ver.name, |
| 4406 | config: Config{ |
| 4407 | MaxVersion: ver.version, |
| 4408 | }, |
| 4409 | resumeSession: true, |
| 4410 | flags: []string{"-use-ticket-callback"}, |
| 4411 | }) |
| 4412 | testCases = append(testCases, testCase{ |
| 4413 | testType: serverTest, |
| 4414 | name: "TicketCallback-Renew-" + ver.name, |
| 4415 | config: Config{ |
| 4416 | MaxVersion: ver.version, |
| 4417 | Bugs: ProtocolBugs{ |
| 4418 | ExpectNewTicket: true, |
| 4419 | }, |
| 4420 | }, |
| 4421 | flags: []string{"-use-ticket-callback", "-renew-ticket"}, |
| 4422 | resumeSession: true, |
| 4423 | }) |
| 4424 | |
| 4425 | // Resume with an oversized session id. |
| 4426 | testCases = append(testCases, testCase{ |
| 4427 | testType: serverTest, |
| 4428 | name: "OversizedSessionId-" + ver.name, |
| 4429 | config: Config{ |
| 4430 | MaxVersion: ver.version, |
| 4431 | Bugs: ProtocolBugs{ |
| 4432 | OversizedSessionId: true, |
| 4433 | }, |
| 4434 | }, |
| 4435 | resumeSession: true, |
| 4436 | shouldFail: true, |
| 4437 | expectedError: ":DECODE_ERROR:", |
| 4438 | }) |
| 4439 | } |
| 4440 | |
| 4441 | // Basic DTLS-SRTP tests. Include fake profiles to ensure they |
| 4442 | // are ignored. |
| 4443 | if ver.hasDTLS { |
| 4444 | testCases = append(testCases, testCase{ |
| 4445 | protocol: dtls, |
| 4446 | name: "SRTP-Client-" + ver.name, |
| 4447 | config: Config{ |
| 4448 | MaxVersion: ver.version, |
| 4449 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4450 | }, |
| 4451 | flags: []string{ |
| 4452 | "-srtp-profiles", |
| 4453 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4454 | }, |
| 4455 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4456 | }) |
| 4457 | testCases = append(testCases, testCase{ |
| 4458 | protocol: dtls, |
| 4459 | testType: serverTest, |
| 4460 | name: "SRTP-Server-" + ver.name, |
| 4461 | config: Config{ |
| 4462 | MaxVersion: ver.version, |
| 4463 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4464 | }, |
| 4465 | flags: []string{ |
| 4466 | "-srtp-profiles", |
| 4467 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4468 | }, |
| 4469 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4470 | }) |
| 4471 | // Test that the MKI is ignored. |
| 4472 | testCases = append(testCases, testCase{ |
| 4473 | protocol: dtls, |
| 4474 | testType: serverTest, |
| 4475 | name: "SRTP-Server-IgnoreMKI-" + ver.name, |
| 4476 | config: Config{ |
| 4477 | MaxVersion: ver.version, |
| 4478 | SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80}, |
| 4479 | Bugs: ProtocolBugs{ |
| 4480 | SRTPMasterKeyIdentifer: "bogus", |
| 4481 | }, |
| 4482 | }, |
| 4483 | flags: []string{ |
| 4484 | "-srtp-profiles", |
| 4485 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4486 | }, |
| 4487 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4488 | }) |
| 4489 | // Test that SRTP isn't negotiated on the server if there were |
| 4490 | // no matching profiles. |
| 4491 | testCases = append(testCases, testCase{ |
| 4492 | protocol: dtls, |
| 4493 | testType: serverTest, |
| 4494 | name: "SRTP-Server-NoMatch-" + ver.name, |
| 4495 | config: Config{ |
| 4496 | MaxVersion: ver.version, |
| 4497 | SRTPProtectionProfiles: []uint16{100, 101, 102}, |
| 4498 | }, |
| 4499 | flags: []string{ |
| 4500 | "-srtp-profiles", |
| 4501 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4502 | }, |
| 4503 | expectedSRTPProtectionProfile: 0, |
| 4504 | }) |
| 4505 | // Test that the server returning an invalid SRTP profile is |
| 4506 | // flagged as an error by the client. |
| 4507 | testCases = append(testCases, testCase{ |
| 4508 | protocol: dtls, |
| 4509 | name: "SRTP-Client-NoMatch-" + ver.name, |
| 4510 | config: Config{ |
| 4511 | MaxVersion: ver.version, |
| 4512 | Bugs: ProtocolBugs{ |
| 4513 | SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32, |
| 4514 | }, |
| 4515 | }, |
| 4516 | flags: []string{ |
| 4517 | "-srtp-profiles", |
| 4518 | "SRTP_AES128_CM_SHA1_80", |
| 4519 | }, |
| 4520 | shouldFail: true, |
| 4521 | expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:", |
| 4522 | }) |
| 4523 | } |
| 4524 | |
| 4525 | // Test SCT list. |
| 4526 | testCases = append(testCases, testCase{ |
| 4527 | name: "SignedCertificateTimestampList-Client-" + ver.name, |
| 4528 | testType: clientTest, |
| 4529 | config: Config{ |
| 4530 | MaxVersion: ver.version, |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 4531 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4532 | flags: []string{ |
| 4533 | "-enable-signed-cert-timestamps", |
| 4534 | "-expect-signed-cert-timestamps", |
| 4535 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 4536 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4537 | resumeSession: resumeSession, |
| 4538 | }) |
| 4539 | testCases = append(testCases, testCase{ |
| 4540 | name: "SendSCTListOnResume-" + ver.name, |
| 4541 | config: Config{ |
| 4542 | MaxVersion: ver.version, |
| 4543 | Bugs: ProtocolBugs{ |
| 4544 | SendSCTListOnResume: []byte("bogus"), |
| 4545 | }, |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 4546 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4547 | flags: []string{ |
| 4548 | "-enable-signed-cert-timestamps", |
| 4549 | "-expect-signed-cert-timestamps", |
| 4550 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 4551 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4552 | resumeSession: resumeSession, |
| 4553 | }) |
| 4554 | testCases = append(testCases, testCase{ |
| 4555 | name: "SignedCertificateTimestampList-Server-" + ver.name, |
| 4556 | testType: serverTest, |
| 4557 | config: Config{ |
| 4558 | MaxVersion: ver.version, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4559 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4560 | flags: []string{ |
| 4561 | "-signed-cert-timestamps", |
| 4562 | base64.StdEncoding.EncodeToString(testSCTList), |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4563 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4564 | expectedSCTList: testSCTList, |
| 4565 | resumeSession: resumeSession, |
| 4566 | }) |
| 4567 | } |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4568 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 4569 | testCases = append(testCases, testCase{ |
Adam Langley | 33ad2b5 | 2015-07-20 17:43:53 -0700 | [diff] [blame] | 4570 | testType: clientTest, |
| 4571 | name: "ClientHelloPadding", |
| 4572 | config: Config{ |
| 4573 | Bugs: ProtocolBugs{ |
| 4574 | RequireClientHelloSize: 512, |
| 4575 | }, |
| 4576 | }, |
| 4577 | // This hostname just needs to be long enough to push the |
| 4578 | // ClientHello into F5's danger zone between 256 and 511 bytes |
| 4579 | // long. |
| 4580 | flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"}, |
| 4581 | }) |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 4582 | |
| 4583 | // Extensions should not function in SSL 3.0. |
| 4584 | testCases = append(testCases, testCase{ |
| 4585 | testType: serverTest, |
| 4586 | name: "SSLv3Extensions-NoALPN", |
| 4587 | config: Config{ |
| 4588 | MaxVersion: VersionSSL30, |
| 4589 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4590 | }, |
| 4591 | flags: []string{ |
| 4592 | "-select-alpn", "foo", |
| 4593 | }, |
| 4594 | expectNoNextProto: true, |
| 4595 | }) |
| 4596 | |
| 4597 | // Test session tickets separately as they follow a different codepath. |
| 4598 | testCases = append(testCases, testCase{ |
| 4599 | testType: serverTest, |
| 4600 | name: "SSLv3Extensions-NoTickets", |
| 4601 | config: Config{ |
| 4602 | MaxVersion: VersionSSL30, |
| 4603 | Bugs: ProtocolBugs{ |
| 4604 | // Historically, session tickets in SSL 3.0 |
| 4605 | // failed in different ways depending on whether |
| 4606 | // the client supported renegotiation_info. |
| 4607 | NoRenegotiationInfo: true, |
| 4608 | }, |
| 4609 | }, |
| 4610 | resumeSession: true, |
| 4611 | }) |
| 4612 | testCases = append(testCases, testCase{ |
| 4613 | testType: serverTest, |
| 4614 | name: "SSLv3Extensions-NoTickets2", |
| 4615 | config: Config{ |
| 4616 | MaxVersion: VersionSSL30, |
| 4617 | }, |
| 4618 | resumeSession: true, |
| 4619 | }) |
| 4620 | |
| 4621 | // But SSL 3.0 does send and process renegotiation_info. |
| 4622 | testCases = append(testCases, testCase{ |
| 4623 | testType: serverTest, |
| 4624 | name: "SSLv3Extensions-RenegotiationInfo", |
| 4625 | config: Config{ |
| 4626 | MaxVersion: VersionSSL30, |
| 4627 | Bugs: ProtocolBugs{ |
| 4628 | RequireRenegotiationInfo: true, |
| 4629 | }, |
| 4630 | }, |
| 4631 | }) |
| 4632 | testCases = append(testCases, testCase{ |
| 4633 | testType: serverTest, |
| 4634 | name: "SSLv3Extensions-RenegotiationInfo-SCSV", |
| 4635 | config: Config{ |
| 4636 | MaxVersion: VersionSSL30, |
| 4637 | Bugs: ProtocolBugs{ |
| 4638 | NoRenegotiationInfo: true, |
| 4639 | SendRenegotiationSCSV: true, |
| 4640 | RequireRenegotiationInfo: true, |
| 4641 | }, |
| 4642 | }, |
| 4643 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 4644 | |
| 4645 | // Test that illegal extensions in TLS 1.3 are rejected by the client if |
| 4646 | // in ServerHello. |
| 4647 | testCases = append(testCases, testCase{ |
| 4648 | name: "NPN-Forbidden-TLS13", |
| 4649 | config: Config{ |
| 4650 | MaxVersion: VersionTLS13, |
| 4651 | NextProtos: []string{"foo"}, |
| 4652 | Bugs: ProtocolBugs{ |
| 4653 | NegotiateNPNAtAllVersions: true, |
| 4654 | }, |
| 4655 | }, |
| 4656 | flags: []string{"-select-next-proto", "foo"}, |
| 4657 | shouldFail: true, |
| 4658 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4659 | }) |
| 4660 | testCases = append(testCases, testCase{ |
| 4661 | name: "EMS-Forbidden-TLS13", |
| 4662 | config: Config{ |
| 4663 | MaxVersion: VersionTLS13, |
| 4664 | Bugs: ProtocolBugs{ |
| 4665 | NegotiateEMSAtAllVersions: true, |
| 4666 | }, |
| 4667 | }, |
| 4668 | shouldFail: true, |
| 4669 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4670 | }) |
| 4671 | testCases = append(testCases, testCase{ |
| 4672 | name: "RenegotiationInfo-Forbidden-TLS13", |
| 4673 | config: Config{ |
| 4674 | MaxVersion: VersionTLS13, |
| 4675 | Bugs: ProtocolBugs{ |
| 4676 | NegotiateRenegotiationInfoAtAllVersions: true, |
| 4677 | }, |
| 4678 | }, |
| 4679 | shouldFail: true, |
| 4680 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4681 | }) |
| 4682 | testCases = append(testCases, testCase{ |
| 4683 | name: "ChannelID-Forbidden-TLS13", |
| 4684 | config: Config{ |
| 4685 | MaxVersion: VersionTLS13, |
| 4686 | RequestChannelID: true, |
| 4687 | Bugs: ProtocolBugs{ |
| 4688 | NegotiateChannelIDAtAllVersions: true, |
| 4689 | }, |
| 4690 | }, |
| 4691 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
| 4692 | shouldFail: true, |
| 4693 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4694 | }) |
| 4695 | testCases = append(testCases, testCase{ |
| 4696 | name: "Ticket-Forbidden-TLS13", |
| 4697 | config: Config{ |
| 4698 | MaxVersion: VersionTLS12, |
| 4699 | }, |
| 4700 | resumeConfig: &Config{ |
| 4701 | MaxVersion: VersionTLS13, |
| 4702 | Bugs: ProtocolBugs{ |
| 4703 | AdvertiseTicketExtension: true, |
| 4704 | }, |
| 4705 | }, |
| 4706 | resumeSession: true, |
| 4707 | shouldFail: true, |
| 4708 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4709 | }) |
| 4710 | |
| 4711 | // Test that illegal extensions in TLS 1.3 are declined by the server if |
| 4712 | // offered in ClientHello. The runner's server will fail if this occurs, |
| 4713 | // so we exercise the offering path. (EMS and Renegotiation Info are |
| 4714 | // implicit in every test.) |
| 4715 | testCases = append(testCases, testCase{ |
| 4716 | testType: serverTest, |
| 4717 | name: "ChannelID-Declined-TLS13", |
| 4718 | config: Config{ |
| 4719 | MaxVersion: VersionTLS13, |
| 4720 | ChannelID: channelIDKey, |
| 4721 | }, |
| 4722 | flags: []string{"-enable-channel-id"}, |
| 4723 | }) |
| 4724 | testCases = append(testCases, testCase{ |
| 4725 | testType: serverTest, |
| 4726 | name: "NPN-Server", |
| 4727 | config: Config{ |
| 4728 | MaxVersion: VersionTLS13, |
| 4729 | NextProtos: []string{"bar"}, |
| 4730 | }, |
| 4731 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 4732 | }) |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4733 | } |
| 4734 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4735 | func addResumptionVersionTests() { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4736 | for _, sessionVers := range tlsVersions { |
David Benjamin | 6e6abe1 | 2016-07-13 20:57:22 -0400 | [diff] [blame] | 4737 | // TODO(davidben,svaldez): Implement resumption in TLS 1.3. |
| 4738 | if sessionVers.version >= VersionTLS13 { |
| 4739 | continue |
| 4740 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4741 | for _, resumeVers := range tlsVersions { |
David Benjamin | 6e6abe1 | 2016-07-13 20:57:22 -0400 | [diff] [blame] | 4742 | if resumeVers.version >= VersionTLS13 { |
| 4743 | continue |
| 4744 | } |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4745 | cipher := TLS_RSA_WITH_AES_128_CBC_SHA |
| 4746 | if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 { |
| 4747 | // TLS 1.3 only shares ciphers with TLS 1.2, so |
| 4748 | // we skip certain combinations and use a |
| 4749 | // different cipher to test with. |
| 4750 | cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
| 4751 | if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 { |
| 4752 | continue |
| 4753 | } |
| 4754 | } |
| 4755 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4756 | protocols := []protocol{tls} |
| 4757 | if sessionVers.hasDTLS && resumeVers.hasDTLS { |
| 4758 | protocols = append(protocols, dtls) |
David Benjamin | bdf5e72 | 2014-11-11 00:52:15 -0500 | [diff] [blame] | 4759 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4760 | for _, protocol := range protocols { |
| 4761 | suffix := "-" + sessionVers.name + "-" + resumeVers.name |
| 4762 | if protocol == dtls { |
| 4763 | suffix += "-DTLS" |
| 4764 | } |
| 4765 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4766 | if sessionVers.version == resumeVers.version { |
| 4767 | testCases = append(testCases, testCase{ |
| 4768 | protocol: protocol, |
| 4769 | name: "Resume-Client" + suffix, |
| 4770 | resumeSession: true, |
| 4771 | config: Config{ |
| 4772 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4773 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4774 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4775 | expectedVersion: sessionVers.version, |
| 4776 | expectedResumeVersion: resumeVers.version, |
| 4777 | }) |
| 4778 | } else { |
| 4779 | testCases = append(testCases, testCase{ |
| 4780 | protocol: protocol, |
| 4781 | name: "Resume-Client-Mismatch" + suffix, |
| 4782 | resumeSession: true, |
| 4783 | config: Config{ |
| 4784 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4785 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4786 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4787 | expectedVersion: sessionVers.version, |
| 4788 | resumeConfig: &Config{ |
| 4789 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4790 | CipherSuites: []uint16{cipher}, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4791 | Bugs: ProtocolBugs{ |
| 4792 | AllowSessionVersionMismatch: true, |
| 4793 | }, |
| 4794 | }, |
| 4795 | expectedResumeVersion: resumeVers.version, |
| 4796 | shouldFail: true, |
| 4797 | expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:", |
| 4798 | }) |
| 4799 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4800 | |
| 4801 | testCases = append(testCases, testCase{ |
| 4802 | protocol: protocol, |
| 4803 | name: "Resume-Client-NoResume" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4804 | resumeSession: true, |
| 4805 | config: Config{ |
| 4806 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4807 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4808 | }, |
| 4809 | expectedVersion: sessionVers.version, |
| 4810 | resumeConfig: &Config{ |
| 4811 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4812 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4813 | }, |
| 4814 | newSessionsOnResume: true, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 4815 | expectResumeRejected: true, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4816 | expectedResumeVersion: resumeVers.version, |
| 4817 | }) |
| 4818 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4819 | testCases = append(testCases, testCase{ |
| 4820 | protocol: protocol, |
| 4821 | testType: serverTest, |
| 4822 | name: "Resume-Server" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4823 | resumeSession: true, |
| 4824 | config: Config{ |
| 4825 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4826 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4827 | }, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 4828 | expectedVersion: sessionVers.version, |
| 4829 | expectResumeRejected: sessionVers.version != resumeVers.version, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4830 | resumeConfig: &Config{ |
| 4831 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4832 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4833 | }, |
| 4834 | expectedResumeVersion: resumeVers.version, |
| 4835 | }) |
| 4836 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4837 | } |
| 4838 | } |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4839 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4840 | // TODO(davidben): This test should have a TLS 1.3 variant later. |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4841 | testCases = append(testCases, testCase{ |
| 4842 | name: "Resume-Client-CipherMismatch", |
| 4843 | resumeSession: true, |
| 4844 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4845 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4846 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 4847 | }, |
| 4848 | resumeConfig: &Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4849 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4850 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 4851 | Bugs: ProtocolBugs{ |
| 4852 | SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 4853 | }, |
| 4854 | }, |
| 4855 | shouldFail: true, |
| 4856 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 4857 | }) |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4858 | } |
| 4859 | |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 4860 | func addRenegotiationTests() { |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 4861 | // Servers cannot renegotiate. |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 4862 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4863 | testType: serverTest, |
| 4864 | name: "Renegotiate-Server-Forbidden", |
| 4865 | config: Config{ |
| 4866 | MaxVersion: VersionTLS12, |
| 4867 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4868 | renegotiate: 1, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 4869 | shouldFail: true, |
| 4870 | expectedError: ":NO_RENEGOTIATION:", |
| 4871 | expectedLocalError: "remote error: no renegotiation", |
| 4872 | }) |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 4873 | // The server shouldn't echo the renegotiation extension unless |
| 4874 | // requested by the client. |
| 4875 | testCases = append(testCases, testCase{ |
| 4876 | testType: serverTest, |
| 4877 | name: "Renegotiate-Server-NoExt", |
| 4878 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4879 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 4880 | Bugs: ProtocolBugs{ |
| 4881 | NoRenegotiationInfo: true, |
| 4882 | RequireRenegotiationInfo: true, |
| 4883 | }, |
| 4884 | }, |
| 4885 | shouldFail: true, |
| 4886 | expectedLocalError: "renegotiation extension missing", |
| 4887 | }) |
| 4888 | // The renegotiation SCSV should be sufficient for the server to echo |
| 4889 | // the extension. |
| 4890 | testCases = append(testCases, testCase{ |
| 4891 | testType: serverTest, |
| 4892 | name: "Renegotiate-Server-NoExt-SCSV", |
| 4893 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4894 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 4895 | Bugs: ProtocolBugs{ |
| 4896 | NoRenegotiationInfo: true, |
| 4897 | SendRenegotiationSCSV: true, |
| 4898 | RequireRenegotiationInfo: true, |
| 4899 | }, |
| 4900 | }, |
| 4901 | }) |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4902 | testCases = append(testCases, testCase{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 4903 | name: "Renegotiate-Client", |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4904 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4905 | MaxVersion: VersionTLS12, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4906 | Bugs: ProtocolBugs{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 4907 | FailIfResumeOnRenego: true, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4908 | }, |
| 4909 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4910 | renegotiate: 1, |
| 4911 | flags: []string{ |
| 4912 | "-renegotiate-freely", |
| 4913 | "-expect-total-renegotiations", "1", |
| 4914 | }, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4915 | }) |
| 4916 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4917 | name: "Renegotiate-Client-EmptyExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4918 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4919 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4920 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4921 | Bugs: ProtocolBugs{ |
| 4922 | EmptyRenegotiationInfo: true, |
| 4923 | }, |
| 4924 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4925 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4926 | shouldFail: true, |
| 4927 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4928 | }) |
| 4929 | testCases = append(testCases, testCase{ |
| 4930 | name: "Renegotiate-Client-BadExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4931 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4932 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4933 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4934 | Bugs: ProtocolBugs{ |
| 4935 | BadRenegotiationInfo: true, |
| 4936 | }, |
| 4937 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4938 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4939 | shouldFail: true, |
| 4940 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4941 | }) |
| 4942 | testCases = append(testCases, testCase{ |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 4943 | name: "Renegotiate-Client-Downgrade", |
| 4944 | renegotiate: 1, |
| 4945 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4946 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 4947 | Bugs: ProtocolBugs{ |
| 4948 | NoRenegotiationInfoAfterInitial: true, |
| 4949 | }, |
| 4950 | }, |
| 4951 | flags: []string{"-renegotiate-freely"}, |
| 4952 | shouldFail: true, |
| 4953 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4954 | }) |
| 4955 | testCases = append(testCases, testCase{ |
| 4956 | name: "Renegotiate-Client-Upgrade", |
| 4957 | renegotiate: 1, |
| 4958 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4959 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 4960 | Bugs: ProtocolBugs{ |
| 4961 | NoRenegotiationInfoInInitial: true, |
| 4962 | }, |
| 4963 | }, |
| 4964 | flags: []string{"-renegotiate-freely"}, |
| 4965 | shouldFail: true, |
| 4966 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4967 | }) |
| 4968 | testCases = append(testCases, testCase{ |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4969 | name: "Renegotiate-Client-NoExt-Allowed", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4970 | renegotiate: 1, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4971 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4972 | MaxVersion: VersionTLS12, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4973 | Bugs: ProtocolBugs{ |
| 4974 | NoRenegotiationInfo: true, |
| 4975 | }, |
| 4976 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4977 | flags: []string{ |
| 4978 | "-renegotiate-freely", |
| 4979 | "-expect-total-renegotiations", "1", |
| 4980 | }, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4981 | }) |
| 4982 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4983 | name: "Renegotiate-Client-SwitchCiphers", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4984 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4985 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4986 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4987 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 4988 | }, |
| 4989 | renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4990 | flags: []string{ |
| 4991 | "-renegotiate-freely", |
| 4992 | "-expect-total-renegotiations", "1", |
| 4993 | }, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4994 | }) |
| 4995 | testCases = append(testCases, testCase{ |
| 4996 | name: "Renegotiate-Client-SwitchCiphers2", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4997 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4998 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4999 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 5000 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5001 | }, |
| 5002 | renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5003 | flags: []string{ |
| 5004 | "-renegotiate-freely", |
| 5005 | "-expect-total-renegotiations", "1", |
| 5006 | }, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 5007 | }) |
| 5008 | testCases = append(testCases, testCase{ |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5009 | name: "Renegotiate-SameClientVersion", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5010 | renegotiate: 1, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5011 | config: Config{ |
| 5012 | MaxVersion: VersionTLS10, |
| 5013 | Bugs: ProtocolBugs{ |
| 5014 | RequireSameRenegoClientVersion: true, |
| 5015 | }, |
| 5016 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5017 | flags: []string{ |
| 5018 | "-renegotiate-freely", |
| 5019 | "-expect-total-renegotiations", "1", |
| 5020 | }, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 5021 | }) |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5022 | testCases = append(testCases, testCase{ |
| 5023 | name: "Renegotiate-FalseStart", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5024 | renegotiate: 1, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5025 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5026 | MaxVersion: VersionTLS12, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5027 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5028 | NextProtos: []string{"foo"}, |
| 5029 | }, |
| 5030 | flags: []string{ |
| 5031 | "-false-start", |
| 5032 | "-select-next-proto", "foo", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5033 | "-renegotiate-freely", |
David Benjamin | 324dce4 | 2015-10-12 19:49:00 -0400 | [diff] [blame] | 5034 | "-expect-total-renegotiations", "1", |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 5035 | }, |
| 5036 | shimWritesFirst: true, |
| 5037 | }) |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5038 | |
| 5039 | // Client-side renegotiation controls. |
| 5040 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5041 | name: "Renegotiate-Client-Forbidden-1", |
| 5042 | config: Config{ |
| 5043 | MaxVersion: VersionTLS12, |
| 5044 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5045 | renegotiate: 1, |
| 5046 | shouldFail: true, |
| 5047 | expectedError: ":NO_RENEGOTIATION:", |
| 5048 | expectedLocalError: "remote error: no renegotiation", |
| 5049 | }) |
| 5050 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5051 | name: "Renegotiate-Client-Once-1", |
| 5052 | config: Config{ |
| 5053 | MaxVersion: VersionTLS12, |
| 5054 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5055 | renegotiate: 1, |
| 5056 | flags: []string{ |
| 5057 | "-renegotiate-once", |
| 5058 | "-expect-total-renegotiations", "1", |
| 5059 | }, |
| 5060 | }) |
| 5061 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5062 | name: "Renegotiate-Client-Freely-1", |
| 5063 | config: Config{ |
| 5064 | MaxVersion: VersionTLS12, |
| 5065 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5066 | renegotiate: 1, |
| 5067 | flags: []string{ |
| 5068 | "-renegotiate-freely", |
| 5069 | "-expect-total-renegotiations", "1", |
| 5070 | }, |
| 5071 | }) |
| 5072 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5073 | name: "Renegotiate-Client-Once-2", |
| 5074 | config: Config{ |
| 5075 | MaxVersion: VersionTLS12, |
| 5076 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5077 | renegotiate: 2, |
| 5078 | flags: []string{"-renegotiate-once"}, |
| 5079 | shouldFail: true, |
| 5080 | expectedError: ":NO_RENEGOTIATION:", |
| 5081 | expectedLocalError: "remote error: no renegotiation", |
| 5082 | }) |
| 5083 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5084 | name: "Renegotiate-Client-Freely-2", |
| 5085 | config: Config{ |
| 5086 | MaxVersion: VersionTLS12, |
| 5087 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 5088 | renegotiate: 2, |
| 5089 | flags: []string{ |
| 5090 | "-renegotiate-freely", |
| 5091 | "-expect-total-renegotiations", "2", |
| 5092 | }, |
| 5093 | }) |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5094 | testCases = append(testCases, testCase{ |
| 5095 | name: "Renegotiate-Client-NoIgnore", |
| 5096 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5097 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5098 | Bugs: ProtocolBugs{ |
| 5099 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5100 | }, |
| 5101 | }, |
| 5102 | shouldFail: true, |
| 5103 | expectedError: ":NO_RENEGOTIATION:", |
| 5104 | }) |
| 5105 | testCases = append(testCases, testCase{ |
| 5106 | name: "Renegotiate-Client-Ignore", |
| 5107 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5108 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 5109 | Bugs: ProtocolBugs{ |
| 5110 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5111 | }, |
| 5112 | }, |
| 5113 | flags: []string{ |
| 5114 | "-renegotiate-ignore", |
| 5115 | "-expect-total-renegotiations", "0", |
| 5116 | }, |
| 5117 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5118 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5119 | // Stray HelloRequests during the handshake are ignored in TLS 1.2. |
David Benjamin | 71dd666 | 2016-07-08 14:10:48 -0700 | [diff] [blame] | 5120 | testCases = append(testCases, testCase{ |
| 5121 | name: "StrayHelloRequest", |
| 5122 | config: Config{ |
| 5123 | MaxVersion: VersionTLS12, |
| 5124 | Bugs: ProtocolBugs{ |
| 5125 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5126 | }, |
| 5127 | }, |
| 5128 | }) |
| 5129 | testCases = append(testCases, testCase{ |
| 5130 | name: "StrayHelloRequest-Packed", |
| 5131 | config: Config{ |
| 5132 | MaxVersion: VersionTLS12, |
| 5133 | Bugs: ProtocolBugs{ |
| 5134 | PackHandshakeFlight: true, |
| 5135 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5136 | }, |
| 5137 | }, |
| 5138 | }) |
| 5139 | |
David Benjamin | 12d2c48 | 2016-07-24 10:56:51 -0400 | [diff] [blame] | 5140 | // Test renegotiation works if HelloRequest and server Finished come in |
| 5141 | // the same record. |
| 5142 | testCases = append(testCases, testCase{ |
| 5143 | name: "Renegotiate-Client-Packed", |
| 5144 | config: Config{ |
| 5145 | MaxVersion: VersionTLS12, |
| 5146 | Bugs: ProtocolBugs{ |
| 5147 | PackHandshakeFlight: true, |
| 5148 | PackHelloRequestWithFinished: true, |
| 5149 | }, |
| 5150 | }, |
| 5151 | renegotiate: 1, |
| 5152 | flags: []string{ |
| 5153 | "-renegotiate-freely", |
| 5154 | "-expect-total-renegotiations", "1", |
| 5155 | }, |
| 5156 | }) |
| 5157 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5158 | // Renegotiation is forbidden in TLS 1.3. |
| 5159 | testCases = append(testCases, testCase{ |
| 5160 | name: "Renegotiate-Client-TLS13", |
| 5161 | config: Config{ |
| 5162 | MaxVersion: VersionTLS13, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5163 | Bugs: ProtocolBugs{ |
| 5164 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5165 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5166 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5167 | flags: []string{ |
| 5168 | "-renegotiate-freely", |
| 5169 | }, |
Steven Valdez | 8e1c7be | 2016-07-26 12:39:22 -0400 | [diff] [blame] | 5170 | shouldFail: true, |
| 5171 | expectedError: ":UNEXPECTED_MESSAGE:", |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5172 | }) |
| 5173 | |
| 5174 | // Stray HelloRequests during the handshake are forbidden in TLS 1.3. |
| 5175 | testCases = append(testCases, testCase{ |
| 5176 | name: "StrayHelloRequest-TLS13", |
| 5177 | config: Config{ |
| 5178 | MaxVersion: VersionTLS13, |
| 5179 | Bugs: ProtocolBugs{ |
| 5180 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5181 | }, |
| 5182 | }, |
| 5183 | shouldFail: true, |
| 5184 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 5185 | }) |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 5186 | } |
| 5187 | |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5188 | func addDTLSReplayTests() { |
| 5189 | // Test that sequence number replays are detected. |
| 5190 | testCases = append(testCases, testCase{ |
| 5191 | protocol: dtls, |
| 5192 | name: "DTLS-Replay", |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5193 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5194 | replayWrites: true, |
| 5195 | }) |
| 5196 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5197 | // Test the incoming sequence number skipping by values larger |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5198 | // than the retransmit window. |
| 5199 | testCases = append(testCases, testCase{ |
| 5200 | protocol: dtls, |
| 5201 | name: "DTLS-Replay-LargeGaps", |
| 5202 | config: Config{ |
| 5203 | Bugs: ProtocolBugs{ |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5204 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5205 | return in * 127 |
| 5206 | }, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5207 | }, |
| 5208 | }, |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5209 | messageCount: 200, |
| 5210 | replayWrites: true, |
| 5211 | }) |
| 5212 | |
| 5213 | // Test the incoming sequence number changing non-monotonically. |
| 5214 | testCases = append(testCases, testCase{ |
| 5215 | protocol: dtls, |
| 5216 | name: "DTLS-Replay-NonMonotonic", |
| 5217 | config: Config{ |
| 5218 | Bugs: ProtocolBugs{ |
| 5219 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5220 | return in ^ 31 |
| 5221 | }, |
| 5222 | }, |
| 5223 | }, |
| 5224 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5225 | replayWrites: true, |
| 5226 | }) |
| 5227 | } |
| 5228 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5229 | var testSignatureAlgorithms = []struct { |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5230 | name string |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5231 | id signatureAlgorithm |
| 5232 | cert testCert |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5233 | }{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5234 | {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA}, |
| 5235 | {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA}, |
| 5236 | {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA}, |
| 5237 | {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5238 | {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5239 | {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256}, |
| 5240 | {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384}, |
| 5241 | {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521}, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5242 | {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA}, |
| 5243 | {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA}, |
| 5244 | {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5245 | // Tests for key types prior to TLS 1.2. |
| 5246 | {"RSA", 0, testCertRSA}, |
| 5247 | {"ECDSA", 0, testCertECDSAP256}, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5248 | } |
| 5249 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5250 | const fakeSigAlg1 signatureAlgorithm = 0x2a01 |
| 5251 | const fakeSigAlg2 signatureAlgorithm = 0xff01 |
| 5252 | |
| 5253 | func addSignatureAlgorithmTests() { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5254 | // Not all ciphers involve a signature. Advertise a list which gives all |
| 5255 | // versions a signing cipher. |
| 5256 | signingCiphers := []uint16{ |
| 5257 | TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 5258 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 5259 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 5260 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 5261 | TLS_DHE_RSA_WITH_AES_128_CBC_SHA, |
| 5262 | } |
| 5263 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5264 | var allAlgorithms []signatureAlgorithm |
| 5265 | for _, alg := range testSignatureAlgorithms { |
| 5266 | if alg.id != 0 { |
| 5267 | allAlgorithms = append(allAlgorithms, alg.id) |
| 5268 | } |
| 5269 | } |
| 5270 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5271 | // Make sure each signature algorithm works. Include some fake values in |
| 5272 | // the list and ensure they're ignored. |
| 5273 | for _, alg := range testSignatureAlgorithms { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5274 | for _, ver := range tlsVersions { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5275 | if (ver.version < VersionTLS12) != (alg.id == 0) { |
| 5276 | continue |
| 5277 | } |
| 5278 | |
| 5279 | // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing |
| 5280 | // or remove it in C. |
| 5281 | if ver.version == VersionSSL30 && alg.cert != testCertRSA { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5282 | continue |
| 5283 | } |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5284 | |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5285 | var shouldFail bool |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5286 | // ecdsa_sha1 does not exist in TLS 1.3. |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5287 | if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 { |
| 5288 | shouldFail = true |
| 5289 | } |
| 5290 | // RSA-PSS does not exist in TLS 1.2. |
| 5291 | if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") { |
| 5292 | shouldFail = true |
| 5293 | } |
| 5294 | |
| 5295 | var signError, verifyError string |
| 5296 | if shouldFail { |
| 5297 | signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:" |
| 5298 | verifyError = ":WRONG_SIGNATURE_TYPE:" |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5299 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5300 | |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5301 | suffix := "-" + alg.name + "-" + ver.name |
David Benjamin | 6e80765 | 2015-11-02 12:02:20 -0500 | [diff] [blame] | 5302 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5303 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5304 | name: "ClientAuth-Sign" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5305 | config: Config{ |
| 5306 | MaxVersion: ver.version, |
| 5307 | ClientAuth: RequireAnyClientCert, |
| 5308 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5309 | fakeSigAlg1, |
| 5310 | alg.id, |
| 5311 | fakeSigAlg2, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5312 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5313 | }, |
| 5314 | flags: []string{ |
| 5315 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5316 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5317 | "-enable-all-curves", |
| 5318 | }, |
| 5319 | shouldFail: shouldFail, |
| 5320 | expectedError: signError, |
| 5321 | expectedPeerSignatureAlgorithm: alg.id, |
| 5322 | }) |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5323 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5324 | testCases = append(testCases, testCase{ |
| 5325 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5326 | name: "ClientAuth-Verify" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5327 | config: Config{ |
| 5328 | MaxVersion: ver.version, |
| 5329 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5330 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5331 | alg.id, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5332 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5333 | Bugs: ProtocolBugs{ |
| 5334 | SkipECDSACurveCheck: shouldFail, |
| 5335 | IgnoreSignatureVersionChecks: shouldFail, |
| 5336 | // The client won't advertise 1.3-only algorithms after |
| 5337 | // version negotiation. |
| 5338 | IgnorePeerSignatureAlgorithmPreferences: shouldFail, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5339 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5340 | }, |
| 5341 | flags: []string{ |
| 5342 | "-require-any-client-certificate", |
| 5343 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5344 | "-enable-all-curves", |
| 5345 | }, |
| 5346 | shouldFail: shouldFail, |
| 5347 | expectedError: verifyError, |
| 5348 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5349 | |
| 5350 | testCases = append(testCases, testCase{ |
| 5351 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5352 | name: "ServerAuth-Sign" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5353 | config: Config{ |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5354 | MaxVersion: ver.version, |
| 5355 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5356 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5357 | fakeSigAlg1, |
| 5358 | alg.id, |
| 5359 | fakeSigAlg2, |
| 5360 | }, |
| 5361 | }, |
| 5362 | flags: []string{ |
| 5363 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5364 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5365 | "-enable-all-curves", |
| 5366 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5367 | shouldFail: shouldFail, |
| 5368 | expectedError: signError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5369 | expectedPeerSignatureAlgorithm: alg.id, |
| 5370 | }) |
| 5371 | |
| 5372 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5373 | name: "ServerAuth-Verify" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5374 | config: Config{ |
| 5375 | MaxVersion: ver.version, |
| 5376 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5377 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5378 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5379 | alg.id, |
| 5380 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5381 | Bugs: ProtocolBugs{ |
| 5382 | SkipECDSACurveCheck: shouldFail, |
| 5383 | IgnoreSignatureVersionChecks: shouldFail, |
| 5384 | }, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5385 | }, |
| 5386 | flags: []string{ |
| 5387 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5388 | "-enable-all-curves", |
| 5389 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5390 | shouldFail: shouldFail, |
| 5391 | expectedError: verifyError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5392 | }) |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5393 | |
| 5394 | if !shouldFail { |
| 5395 | testCases = append(testCases, testCase{ |
| 5396 | testType: serverTest, |
| 5397 | name: "ClientAuth-InvalidSignature" + suffix, |
| 5398 | config: Config{ |
| 5399 | MaxVersion: ver.version, |
| 5400 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5401 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5402 | alg.id, |
| 5403 | }, |
| 5404 | Bugs: ProtocolBugs{ |
| 5405 | InvalidSignature: true, |
| 5406 | }, |
| 5407 | }, |
| 5408 | flags: []string{ |
| 5409 | "-require-any-client-certificate", |
| 5410 | "-enable-all-curves", |
| 5411 | }, |
| 5412 | shouldFail: true, |
| 5413 | expectedError: ":BAD_SIGNATURE:", |
| 5414 | }) |
| 5415 | |
| 5416 | testCases = append(testCases, testCase{ |
| 5417 | name: "ServerAuth-InvalidSignature" + suffix, |
| 5418 | config: Config{ |
| 5419 | MaxVersion: ver.version, |
| 5420 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5421 | CipherSuites: signingCiphers, |
| 5422 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5423 | alg.id, |
| 5424 | }, |
| 5425 | Bugs: ProtocolBugs{ |
| 5426 | InvalidSignature: true, |
| 5427 | }, |
| 5428 | }, |
| 5429 | flags: []string{"-enable-all-curves"}, |
| 5430 | shouldFail: true, |
| 5431 | expectedError: ":BAD_SIGNATURE:", |
| 5432 | }) |
| 5433 | } |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5434 | |
| 5435 | if ver.version >= VersionTLS12 && !shouldFail { |
| 5436 | testCases = append(testCases, testCase{ |
| 5437 | name: "ClientAuth-Sign-Negotiate" + suffix, |
| 5438 | config: Config{ |
| 5439 | MaxVersion: ver.version, |
| 5440 | ClientAuth: RequireAnyClientCert, |
| 5441 | VerifySignatureAlgorithms: allAlgorithms, |
| 5442 | }, |
| 5443 | flags: []string{ |
| 5444 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5445 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5446 | "-enable-all-curves", |
| 5447 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 5448 | }, |
| 5449 | expectedPeerSignatureAlgorithm: alg.id, |
| 5450 | }) |
| 5451 | |
| 5452 | testCases = append(testCases, testCase{ |
| 5453 | testType: serverTest, |
| 5454 | name: "ServerAuth-Sign-Negotiate" + suffix, |
| 5455 | config: Config{ |
| 5456 | MaxVersion: ver.version, |
| 5457 | CipherSuites: signingCiphers, |
| 5458 | VerifySignatureAlgorithms: allAlgorithms, |
| 5459 | }, |
| 5460 | flags: []string{ |
| 5461 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5462 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5463 | "-enable-all-curves", |
| 5464 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 5465 | }, |
| 5466 | expectedPeerSignatureAlgorithm: alg.id, |
| 5467 | }) |
| 5468 | } |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5469 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5470 | } |
| 5471 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5472 | // Test that algorithm selection takes the key type into account. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5473 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5474 | name: "ClientAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5475 | config: Config{ |
| 5476 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5477 | MaxVersion: VersionTLS12, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5478 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5479 | signatureECDSAWithP521AndSHA512, |
| 5480 | signatureRSAPKCS1WithSHA384, |
| 5481 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5482 | }, |
| 5483 | }, |
| 5484 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5485 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5486 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5487 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5488 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5489 | }) |
| 5490 | |
| 5491 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5492 | name: "ClientAuth-SignatureType-TLS13", |
| 5493 | config: Config{ |
| 5494 | ClientAuth: RequireAnyClientCert, |
| 5495 | MaxVersion: VersionTLS13, |
| 5496 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5497 | signatureECDSAWithP521AndSHA512, |
| 5498 | signatureRSAPKCS1WithSHA384, |
| 5499 | signatureRSAPSSWithSHA384, |
| 5500 | signatureECDSAWithSHA1, |
| 5501 | }, |
| 5502 | }, |
| 5503 | flags: []string{ |
| 5504 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5505 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5506 | }, |
| 5507 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 5508 | }) |
| 5509 | |
| 5510 | testCases = append(testCases, testCase{ |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5511 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5512 | name: "ServerAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5513 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5514 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5515 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5516 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5517 | signatureECDSAWithP521AndSHA512, |
| 5518 | signatureRSAPKCS1WithSHA384, |
| 5519 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5520 | }, |
| 5521 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5522 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5523 | }) |
| 5524 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5525 | testCases = append(testCases, testCase{ |
| 5526 | testType: serverTest, |
| 5527 | name: "ServerAuth-SignatureType-TLS13", |
| 5528 | config: Config{ |
| 5529 | MaxVersion: VersionTLS13, |
| 5530 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5531 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5532 | signatureECDSAWithP521AndSHA512, |
| 5533 | signatureRSAPKCS1WithSHA384, |
| 5534 | signatureRSAPSSWithSHA384, |
| 5535 | signatureECDSAWithSHA1, |
| 5536 | }, |
| 5537 | }, |
| 5538 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 5539 | }) |
| 5540 | |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5541 | // Test that signature verification takes the key type into account. |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5542 | testCases = append(testCases, testCase{ |
| 5543 | testType: serverTest, |
| 5544 | name: "Verify-ClientAuth-SignatureType", |
| 5545 | config: Config{ |
| 5546 | MaxVersion: VersionTLS12, |
| 5547 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5548 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5549 | signatureRSAPKCS1WithSHA256, |
| 5550 | }, |
| 5551 | Bugs: ProtocolBugs{ |
| 5552 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5553 | }, |
| 5554 | }, |
| 5555 | flags: []string{ |
| 5556 | "-require-any-client-certificate", |
| 5557 | }, |
| 5558 | shouldFail: true, |
| 5559 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5560 | }) |
| 5561 | |
| 5562 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5563 | testType: serverTest, |
| 5564 | name: "Verify-ClientAuth-SignatureType-TLS13", |
| 5565 | config: Config{ |
| 5566 | MaxVersion: VersionTLS13, |
| 5567 | Certificates: []Certificate{rsaCertificate}, |
| 5568 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5569 | signatureRSAPSSWithSHA256, |
| 5570 | }, |
| 5571 | Bugs: ProtocolBugs{ |
| 5572 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5573 | }, |
| 5574 | }, |
| 5575 | flags: []string{ |
| 5576 | "-require-any-client-certificate", |
| 5577 | }, |
| 5578 | shouldFail: true, |
| 5579 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5580 | }) |
| 5581 | |
| 5582 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5583 | name: "Verify-ServerAuth-SignatureType", |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5584 | config: Config{ |
| 5585 | MaxVersion: VersionTLS12, |
| 5586 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5587 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5588 | signatureRSAPKCS1WithSHA256, |
| 5589 | }, |
| 5590 | Bugs: ProtocolBugs{ |
| 5591 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5592 | }, |
| 5593 | }, |
| 5594 | shouldFail: true, |
| 5595 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5596 | }) |
| 5597 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5598 | testCases = append(testCases, testCase{ |
| 5599 | name: "Verify-ServerAuth-SignatureType-TLS13", |
| 5600 | config: Config{ |
| 5601 | MaxVersion: VersionTLS13, |
| 5602 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5603 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5604 | signatureRSAPSSWithSHA256, |
| 5605 | }, |
| 5606 | Bugs: ProtocolBugs{ |
| 5607 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5608 | }, |
| 5609 | }, |
| 5610 | shouldFail: true, |
| 5611 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5612 | }) |
| 5613 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5614 | // Test that, if the list is missing, the peer falls back to SHA-1 in |
| 5615 | // TLS 1.2, but not TLS 1.3. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5616 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5617 | name: "ClientAuth-SHA1-Fallback", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5618 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5619 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5620 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5621 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5622 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5623 | }, |
| 5624 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5625 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5626 | }, |
| 5627 | }, |
| 5628 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5629 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5630 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5631 | }, |
| 5632 | }) |
| 5633 | |
| 5634 | testCases = append(testCases, testCase{ |
| 5635 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5636 | name: "ServerAuth-SHA1-Fallback", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5637 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5638 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5639 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5640 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5641 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5642 | }, |
| 5643 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5644 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5645 | }, |
| 5646 | }, |
| 5647 | }) |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5648 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5649 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5650 | name: "ClientAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5651 | config: Config{ |
| 5652 | MaxVersion: VersionTLS13, |
| 5653 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5654 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5655 | signatureRSAPKCS1WithSHA1, |
| 5656 | }, |
| 5657 | Bugs: ProtocolBugs{ |
| 5658 | NoSignatureAlgorithms: true, |
| 5659 | }, |
| 5660 | }, |
| 5661 | flags: []string{ |
| 5662 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5663 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5664 | }, |
| 5665 | shouldFail: true, |
| 5666 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5667 | }) |
| 5668 | |
| 5669 | testCases = append(testCases, testCase{ |
| 5670 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5671 | name: "ServerAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5672 | config: Config{ |
| 5673 | MaxVersion: VersionTLS13, |
| 5674 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5675 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5676 | signatureRSAPKCS1WithSHA1, |
| 5677 | }, |
| 5678 | Bugs: ProtocolBugs{ |
| 5679 | NoSignatureAlgorithms: true, |
| 5680 | }, |
| 5681 | }, |
| 5682 | shouldFail: true, |
| 5683 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5684 | }) |
| 5685 | |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 5686 | // Test that hash preferences are enforced. BoringSSL does not implement |
| 5687 | // MD5 signatures. |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5688 | testCases = append(testCases, testCase{ |
| 5689 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5690 | name: "ClientAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5691 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5692 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5693 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5694 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5695 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5696 | }, |
| 5697 | Bugs: ProtocolBugs{ |
| 5698 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5699 | }, |
| 5700 | }, |
| 5701 | flags: []string{"-require-any-client-certificate"}, |
| 5702 | shouldFail: true, |
| 5703 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5704 | }) |
| 5705 | |
| 5706 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5707 | name: "ServerAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5708 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5709 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5710 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5711 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5712 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5713 | }, |
| 5714 | Bugs: ProtocolBugs{ |
| 5715 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5716 | }, |
| 5717 | }, |
| 5718 | shouldFail: true, |
| 5719 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5720 | }) |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 5721 | testCases = append(testCases, testCase{ |
| 5722 | testType: serverTest, |
| 5723 | name: "ClientAuth-Enforced-TLS13", |
| 5724 | config: Config{ |
| 5725 | MaxVersion: VersionTLS13, |
| 5726 | Certificates: []Certificate{rsaCertificate}, |
| 5727 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5728 | signatureRSAPKCS1WithMD5, |
| 5729 | }, |
| 5730 | Bugs: ProtocolBugs{ |
| 5731 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5732 | IgnoreSignatureVersionChecks: true, |
| 5733 | }, |
| 5734 | }, |
| 5735 | flags: []string{"-require-any-client-certificate"}, |
| 5736 | shouldFail: true, |
| 5737 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5738 | }) |
| 5739 | |
| 5740 | testCases = append(testCases, testCase{ |
| 5741 | name: "ServerAuth-Enforced-TLS13", |
| 5742 | config: Config{ |
| 5743 | MaxVersion: VersionTLS13, |
| 5744 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5745 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5746 | signatureRSAPKCS1WithMD5, |
| 5747 | }, |
| 5748 | Bugs: ProtocolBugs{ |
| 5749 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5750 | IgnoreSignatureVersionChecks: true, |
| 5751 | }, |
| 5752 | }, |
| 5753 | shouldFail: true, |
| 5754 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5755 | }) |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5756 | |
| 5757 | // Test that the agreed upon digest respects the client preferences and |
| 5758 | // the server digests. |
| 5759 | testCases = append(testCases, testCase{ |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5760 | name: "NoCommonAlgorithms-Digests", |
| 5761 | config: Config{ |
| 5762 | MaxVersion: VersionTLS12, |
| 5763 | ClientAuth: RequireAnyClientCert, |
| 5764 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5765 | signatureRSAPKCS1WithSHA512, |
| 5766 | signatureRSAPKCS1WithSHA1, |
| 5767 | }, |
| 5768 | }, |
| 5769 | flags: []string{ |
| 5770 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5771 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5772 | "-digest-prefs", "SHA256", |
| 5773 | }, |
| 5774 | shouldFail: true, |
| 5775 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5776 | }) |
| 5777 | testCases = append(testCases, testCase{ |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 5778 | name: "NoCommonAlgorithms", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5779 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5780 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5781 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5782 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5783 | signatureRSAPKCS1WithSHA512, |
| 5784 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5785 | }, |
| 5786 | }, |
| 5787 | flags: []string{ |
| 5788 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5789 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5790 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5791 | }, |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5792 | shouldFail: true, |
| 5793 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5794 | }) |
| 5795 | testCases = append(testCases, testCase{ |
| 5796 | name: "NoCommonAlgorithms-TLS13", |
| 5797 | config: Config{ |
| 5798 | MaxVersion: VersionTLS13, |
| 5799 | ClientAuth: RequireAnyClientCert, |
| 5800 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5801 | signatureRSAPSSWithSHA512, |
| 5802 | signatureRSAPSSWithSHA384, |
| 5803 | }, |
| 5804 | }, |
| 5805 | flags: []string{ |
| 5806 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5807 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5808 | "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)), |
| 5809 | }, |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 5810 | shouldFail: true, |
| 5811 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5812 | }) |
| 5813 | testCases = append(testCases, testCase{ |
| 5814 | name: "Agree-Digest-SHA256", |
| 5815 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5816 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5817 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5818 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5819 | signatureRSAPKCS1WithSHA1, |
| 5820 | signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5821 | }, |
| 5822 | }, |
| 5823 | flags: []string{ |
| 5824 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5825 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5826 | "-digest-prefs", "SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5827 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5828 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5829 | }) |
| 5830 | testCases = append(testCases, testCase{ |
| 5831 | name: "Agree-Digest-SHA1", |
| 5832 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5833 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5834 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5835 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5836 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5837 | }, |
| 5838 | }, |
| 5839 | flags: []string{ |
| 5840 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5841 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5842 | "-digest-prefs", "SHA512,SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5843 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5844 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5845 | }) |
| 5846 | testCases = append(testCases, testCase{ |
| 5847 | name: "Agree-Digest-Default", |
| 5848 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5849 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5850 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5851 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5852 | signatureRSAPKCS1WithSHA256, |
| 5853 | signatureECDSAWithP256AndSHA256, |
| 5854 | signatureRSAPKCS1WithSHA1, |
| 5855 | signatureECDSAWithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5856 | }, |
| 5857 | }, |
| 5858 | flags: []string{ |
| 5859 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5860 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5861 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5862 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5863 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5864 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5865 | // Test that the signing preference list may include extra algorithms |
| 5866 | // without negotiation problems. |
| 5867 | testCases = append(testCases, testCase{ |
| 5868 | testType: serverTest, |
| 5869 | name: "FilterExtraAlgorithms", |
| 5870 | config: Config{ |
| 5871 | MaxVersion: VersionTLS12, |
| 5872 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5873 | signatureRSAPKCS1WithSHA256, |
| 5874 | }, |
| 5875 | }, |
| 5876 | flags: []string{ |
| 5877 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5878 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5879 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)), |
| 5880 | "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)), |
| 5881 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
| 5882 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)), |
| 5883 | }, |
| 5884 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
| 5885 | }) |
| 5886 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5887 | // In TLS 1.2 and below, ECDSA uses the curve list rather than the |
| 5888 | // signature algorithms. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5889 | testCases = append(testCases, testCase{ |
| 5890 | name: "CheckLeafCurve", |
| 5891 | config: Config{ |
| 5892 | MaxVersion: VersionTLS12, |
| 5893 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5894 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5895 | }, |
| 5896 | flags: []string{"-p384-only"}, |
| 5897 | shouldFail: true, |
| 5898 | expectedError: ":BAD_ECC_CERT:", |
| 5899 | }) |
David Benjamin | 75ea5bb | 2016-07-08 17:43:29 -0700 | [diff] [blame] | 5900 | |
| 5901 | // In TLS 1.3, ECDSA does not use the ECDHE curve list. |
| 5902 | testCases = append(testCases, testCase{ |
| 5903 | name: "CheckLeafCurve-TLS13", |
| 5904 | config: Config{ |
| 5905 | MaxVersion: VersionTLS13, |
| 5906 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 5907 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 5908 | }, |
| 5909 | flags: []string{"-p384-only"}, |
| 5910 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5911 | |
| 5912 | // In TLS 1.2, the ECDSA curve is not in the signature algorithm. |
| 5913 | testCases = append(testCases, testCase{ |
| 5914 | name: "ECDSACurveMismatch-Verify-TLS12", |
| 5915 | config: Config{ |
| 5916 | MaxVersion: VersionTLS12, |
| 5917 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 5918 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5919 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5920 | signatureECDSAWithP384AndSHA384, |
| 5921 | }, |
| 5922 | }, |
| 5923 | }) |
| 5924 | |
| 5925 | // In TLS 1.3, the ECDSA curve comes from the signature algorithm. |
| 5926 | testCases = append(testCases, testCase{ |
| 5927 | name: "ECDSACurveMismatch-Verify-TLS13", |
| 5928 | config: Config{ |
| 5929 | MaxVersion: VersionTLS13, |
| 5930 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 5931 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5932 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5933 | signatureECDSAWithP384AndSHA384, |
| 5934 | }, |
| 5935 | Bugs: ProtocolBugs{ |
| 5936 | SkipECDSACurveCheck: true, |
| 5937 | }, |
| 5938 | }, |
| 5939 | shouldFail: true, |
| 5940 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5941 | }) |
| 5942 | |
| 5943 | // Signature algorithm selection in TLS 1.3 should take the curve into |
| 5944 | // account. |
| 5945 | testCases = append(testCases, testCase{ |
| 5946 | testType: serverTest, |
| 5947 | name: "ECDSACurveMismatch-Sign-TLS13", |
| 5948 | config: Config{ |
| 5949 | MaxVersion: VersionTLS13, |
| 5950 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5951 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5952 | signatureECDSAWithP384AndSHA384, |
| 5953 | signatureECDSAWithP256AndSHA256, |
| 5954 | }, |
| 5955 | }, |
| 5956 | flags: []string{ |
| 5957 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 5958 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 5959 | }, |
| 5960 | expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5961 | }) |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 5962 | |
| 5963 | // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the |
| 5964 | // server does not attempt to sign in that case. |
| 5965 | testCases = append(testCases, testCase{ |
| 5966 | testType: serverTest, |
| 5967 | name: "RSA-PSS-Large", |
| 5968 | config: Config{ |
| 5969 | MaxVersion: VersionTLS13, |
| 5970 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5971 | signatureRSAPSSWithSHA512, |
| 5972 | }, |
| 5973 | }, |
| 5974 | flags: []string{ |
| 5975 | "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile), |
| 5976 | "-key-file", path.Join(*resourceDir, rsa1024KeyFile), |
| 5977 | }, |
| 5978 | shouldFail: true, |
| 5979 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5980 | }) |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5981 | } |
| 5982 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5983 | // timeouts is the retransmit schedule for BoringSSL. It doubles and |
| 5984 | // caps at 60 seconds. On the 13th timeout, it gives up. |
| 5985 | var timeouts = []time.Duration{ |
| 5986 | 1 * time.Second, |
| 5987 | 2 * time.Second, |
| 5988 | 4 * time.Second, |
| 5989 | 8 * time.Second, |
| 5990 | 16 * time.Second, |
| 5991 | 32 * time.Second, |
| 5992 | 60 * time.Second, |
| 5993 | 60 * time.Second, |
| 5994 | 60 * time.Second, |
| 5995 | 60 * time.Second, |
| 5996 | 60 * time.Second, |
| 5997 | 60 * time.Second, |
| 5998 | 60 * time.Second, |
| 5999 | } |
| 6000 | |
Taylor Brandstetter | 376a0fe | 2016-05-10 19:30:28 -0700 | [diff] [blame] | 6001 | // shortTimeouts is an alternate set of timeouts which would occur if the |
| 6002 | // initial timeout duration was set to 250ms. |
| 6003 | var shortTimeouts = []time.Duration{ |
| 6004 | 250 * time.Millisecond, |
| 6005 | 500 * time.Millisecond, |
| 6006 | 1 * time.Second, |
| 6007 | 2 * time.Second, |
| 6008 | 4 * time.Second, |
| 6009 | 8 * time.Second, |
| 6010 | 16 * time.Second, |
| 6011 | 32 * time.Second, |
| 6012 | 60 * time.Second, |
| 6013 | 60 * time.Second, |
| 6014 | 60 * time.Second, |
| 6015 | 60 * time.Second, |
| 6016 | 60 * time.Second, |
| 6017 | } |
| 6018 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6019 | func addDTLSRetransmitTests() { |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6020 | // These tests work by coordinating some behavior on both the shim and |
| 6021 | // the runner. |
| 6022 | // |
| 6023 | // TimeoutSchedule configures the runner to send a series of timeout |
| 6024 | // opcodes to the shim (see packetAdaptor) immediately before reading |
| 6025 | // each peer handshake flight N. The timeout opcode both simulates a |
| 6026 | // timeout in the shim and acts as a synchronization point to help the |
| 6027 | // runner bracket each handshake flight. |
| 6028 | // |
| 6029 | // We assume the shim does not read from the channel eagerly. It must |
| 6030 | // first wait until it has sent flight N and is ready to receive |
| 6031 | // handshake flight N+1. At this point, it will process the timeout |
| 6032 | // opcode. It must then immediately respond with a timeout ACK and act |
| 6033 | // as if the shim was idle for the specified amount of time. |
| 6034 | // |
| 6035 | // The runner then drops all packets received before the ACK and |
| 6036 | // continues waiting for flight N. This ordering results in one attempt |
| 6037 | // at sending flight N to be dropped. For the test to complete, the |
| 6038 | // shim must send flight N again, testing that the shim implements DTLS |
| 6039 | // retransmit on a timeout. |
| 6040 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6041 | // TODO(davidben): Add DTLS 1.3 versions of these tests. There will |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6042 | // likely be more epochs to cross and the final message's retransmit may |
| 6043 | // be more complex. |
| 6044 | |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6045 | for _, async := range []bool{true, false} { |
| 6046 | var tests []testCase |
| 6047 | |
| 6048 | // Test that this is indeed the timeout schedule. Stress all |
| 6049 | // four patterns of handshake. |
| 6050 | for i := 1; i < len(timeouts); i++ { |
| 6051 | number := strconv.Itoa(i) |
| 6052 | tests = append(tests, testCase{ |
| 6053 | protocol: dtls, |
| 6054 | name: "DTLS-Retransmit-Client-" + number, |
| 6055 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6056 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6057 | Bugs: ProtocolBugs{ |
| 6058 | TimeoutSchedule: timeouts[:i], |
| 6059 | }, |
| 6060 | }, |
| 6061 | resumeSession: true, |
| 6062 | }) |
| 6063 | tests = append(tests, testCase{ |
| 6064 | protocol: dtls, |
| 6065 | testType: serverTest, |
| 6066 | name: "DTLS-Retransmit-Server-" + number, |
| 6067 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6068 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6069 | Bugs: ProtocolBugs{ |
| 6070 | TimeoutSchedule: timeouts[:i], |
| 6071 | }, |
| 6072 | }, |
| 6073 | resumeSession: true, |
| 6074 | }) |
| 6075 | } |
| 6076 | |
| 6077 | // Test that exceeding the timeout schedule hits a read |
| 6078 | // timeout. |
| 6079 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6080 | protocol: dtls, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6081 | name: "DTLS-Retransmit-Timeout", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6082 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6083 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6084 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6085 | TimeoutSchedule: timeouts, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6086 | }, |
| 6087 | }, |
| 6088 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6089 | shouldFail: true, |
| 6090 | expectedError: ":READ_TIMEOUT_EXPIRED:", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6091 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6092 | |
| 6093 | if async { |
| 6094 | // Test that timeout handling has a fudge factor, due to API |
| 6095 | // problems. |
| 6096 | tests = append(tests, testCase{ |
| 6097 | protocol: dtls, |
| 6098 | name: "DTLS-Retransmit-Fudge", |
| 6099 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6100 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6101 | Bugs: ProtocolBugs{ |
| 6102 | TimeoutSchedule: []time.Duration{ |
| 6103 | timeouts[0] - 10*time.Millisecond, |
| 6104 | }, |
| 6105 | }, |
| 6106 | }, |
| 6107 | resumeSession: true, |
| 6108 | }) |
| 6109 | } |
| 6110 | |
| 6111 | // Test that the final Finished retransmitting isn't |
| 6112 | // duplicated if the peer badly fragments everything. |
| 6113 | tests = append(tests, testCase{ |
| 6114 | testType: serverTest, |
| 6115 | protocol: dtls, |
| 6116 | name: "DTLS-Retransmit-Fragmented", |
| 6117 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6118 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6119 | Bugs: ProtocolBugs{ |
| 6120 | TimeoutSchedule: []time.Duration{timeouts[0]}, |
| 6121 | MaxHandshakeRecordLength: 2, |
| 6122 | }, |
| 6123 | }, |
| 6124 | }) |
| 6125 | |
| 6126 | // Test the timeout schedule when a shorter initial timeout duration is set. |
| 6127 | tests = append(tests, testCase{ |
| 6128 | protocol: dtls, |
| 6129 | name: "DTLS-Retransmit-Short-Client", |
| 6130 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6131 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6132 | Bugs: ProtocolBugs{ |
| 6133 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
| 6134 | }, |
| 6135 | }, |
| 6136 | resumeSession: true, |
| 6137 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
| 6138 | }) |
| 6139 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6140 | protocol: dtls, |
| 6141 | testType: serverTest, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6142 | name: "DTLS-Retransmit-Short-Server", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6143 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6144 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6145 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6146 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6147 | }, |
| 6148 | }, |
| 6149 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6150 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6151 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6152 | |
| 6153 | for _, test := range tests { |
| 6154 | if async { |
| 6155 | test.name += "-Async" |
| 6156 | test.flags = append(test.flags, "-async") |
| 6157 | } |
| 6158 | |
| 6159 | testCases = append(testCases, test) |
| 6160 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6161 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6162 | } |
| 6163 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 6164 | func addExportKeyingMaterialTests() { |
| 6165 | for _, vers := range tlsVersions { |
| 6166 | if vers.version == VersionSSL30 { |
| 6167 | continue |
| 6168 | } |
| 6169 | testCases = append(testCases, testCase{ |
| 6170 | name: "ExportKeyingMaterial-" + vers.name, |
| 6171 | config: Config{ |
| 6172 | MaxVersion: vers.version, |
| 6173 | }, |
| 6174 | exportKeyingMaterial: 1024, |
| 6175 | exportLabel: "label", |
| 6176 | exportContext: "context", |
| 6177 | useExportContext: true, |
| 6178 | }) |
| 6179 | testCases = append(testCases, testCase{ |
| 6180 | name: "ExportKeyingMaterial-NoContext-" + vers.name, |
| 6181 | config: Config{ |
| 6182 | MaxVersion: vers.version, |
| 6183 | }, |
| 6184 | exportKeyingMaterial: 1024, |
| 6185 | }) |
| 6186 | testCases = append(testCases, testCase{ |
| 6187 | name: "ExportKeyingMaterial-EmptyContext-" + vers.name, |
| 6188 | config: Config{ |
| 6189 | MaxVersion: vers.version, |
| 6190 | }, |
| 6191 | exportKeyingMaterial: 1024, |
| 6192 | useExportContext: true, |
| 6193 | }) |
| 6194 | testCases = append(testCases, testCase{ |
| 6195 | name: "ExportKeyingMaterial-Small-" + vers.name, |
| 6196 | config: Config{ |
| 6197 | MaxVersion: vers.version, |
| 6198 | }, |
| 6199 | exportKeyingMaterial: 1, |
| 6200 | exportLabel: "label", |
| 6201 | exportContext: "context", |
| 6202 | useExportContext: true, |
| 6203 | }) |
| 6204 | } |
| 6205 | testCases = append(testCases, testCase{ |
| 6206 | name: "ExportKeyingMaterial-SSL3", |
| 6207 | config: Config{ |
| 6208 | MaxVersion: VersionSSL30, |
| 6209 | }, |
| 6210 | exportKeyingMaterial: 1024, |
| 6211 | exportLabel: "label", |
| 6212 | exportContext: "context", |
| 6213 | useExportContext: true, |
| 6214 | shouldFail: true, |
| 6215 | expectedError: "failed to export keying material", |
| 6216 | }) |
| 6217 | } |
| 6218 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6219 | func addTLSUniqueTests() { |
| 6220 | for _, isClient := range []bool{false, true} { |
| 6221 | for _, isResumption := range []bool{false, true} { |
| 6222 | for _, hasEMS := range []bool{false, true} { |
| 6223 | var suffix string |
| 6224 | if isResumption { |
| 6225 | suffix = "Resume-" |
| 6226 | } else { |
| 6227 | suffix = "Full-" |
| 6228 | } |
| 6229 | |
| 6230 | if hasEMS { |
| 6231 | suffix += "EMS-" |
| 6232 | } else { |
| 6233 | suffix += "NoEMS-" |
| 6234 | } |
| 6235 | |
| 6236 | if isClient { |
| 6237 | suffix += "Client" |
| 6238 | } else { |
| 6239 | suffix += "Server" |
| 6240 | } |
| 6241 | |
| 6242 | test := testCase{ |
| 6243 | name: "TLSUnique-" + suffix, |
| 6244 | testTLSUnique: true, |
| 6245 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6246 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6247 | Bugs: ProtocolBugs{ |
| 6248 | NoExtendedMasterSecret: !hasEMS, |
| 6249 | }, |
| 6250 | }, |
| 6251 | } |
| 6252 | |
| 6253 | if isResumption { |
| 6254 | test.resumeSession = true |
| 6255 | test.resumeConfig = &Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6256 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6257 | Bugs: ProtocolBugs{ |
| 6258 | NoExtendedMasterSecret: !hasEMS, |
| 6259 | }, |
| 6260 | } |
| 6261 | } |
| 6262 | |
| 6263 | if isResumption && !hasEMS { |
| 6264 | test.shouldFail = true |
| 6265 | test.expectedError = "failed to get tls-unique" |
| 6266 | } |
| 6267 | |
| 6268 | testCases = append(testCases, test) |
| 6269 | } |
| 6270 | } |
| 6271 | } |
| 6272 | } |
| 6273 | |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6274 | func addCustomExtensionTests() { |
| 6275 | expectedContents := "custom extension" |
| 6276 | emptyString := "" |
| 6277 | |
| 6278 | for _, isClient := range []bool{false, true} { |
| 6279 | suffix := "Server" |
| 6280 | flag := "-enable-server-custom-extension" |
| 6281 | testType := serverTest |
| 6282 | if isClient { |
| 6283 | suffix = "Client" |
| 6284 | flag = "-enable-client-custom-extension" |
| 6285 | testType = clientTest |
| 6286 | } |
| 6287 | |
| 6288 | testCases = append(testCases, testCase{ |
| 6289 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6290 | name: "CustomExtensions-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6291 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6292 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6293 | Bugs: ProtocolBugs{ |
| 6294 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6295 | ExpectedCustomExtension: &expectedContents, |
| 6296 | }, |
| 6297 | }, |
| 6298 | flags: []string{flag}, |
| 6299 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6300 | testCases = append(testCases, testCase{ |
| 6301 | testType: testType, |
| 6302 | name: "CustomExtensions-" + suffix + "-TLS13", |
| 6303 | config: Config{ |
| 6304 | MaxVersion: VersionTLS13, |
| 6305 | Bugs: ProtocolBugs{ |
| 6306 | CustomExtension: expectedContents, |
| 6307 | ExpectedCustomExtension: &expectedContents, |
| 6308 | }, |
| 6309 | }, |
| 6310 | flags: []string{flag}, |
| 6311 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6312 | |
| 6313 | // If the parse callback fails, the handshake should also fail. |
| 6314 | testCases = append(testCases, testCase{ |
| 6315 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6316 | name: "CustomExtensions-ParseError-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6317 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6318 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6319 | Bugs: ProtocolBugs{ |
| 6320 | CustomExtension: expectedContents + "foo", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6321 | ExpectedCustomExtension: &expectedContents, |
| 6322 | }, |
| 6323 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6324 | flags: []string{flag}, |
| 6325 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6326 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6327 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6328 | testCases = append(testCases, testCase{ |
| 6329 | testType: testType, |
| 6330 | name: "CustomExtensions-ParseError-" + suffix + "-TLS13", |
| 6331 | config: Config{ |
| 6332 | MaxVersion: VersionTLS13, |
| 6333 | Bugs: ProtocolBugs{ |
| 6334 | CustomExtension: expectedContents + "foo", |
| 6335 | ExpectedCustomExtension: &expectedContents, |
| 6336 | }, |
| 6337 | }, |
| 6338 | flags: []string{flag}, |
| 6339 | shouldFail: true, |
| 6340 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6341 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6342 | |
| 6343 | // If the add callback fails, the handshake should also fail. |
| 6344 | testCases = append(testCases, testCase{ |
| 6345 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6346 | name: "CustomExtensions-FailAdd-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6347 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6348 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6349 | Bugs: ProtocolBugs{ |
| 6350 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6351 | ExpectedCustomExtension: &expectedContents, |
| 6352 | }, |
| 6353 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6354 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 6355 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6356 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6357 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6358 | testCases = append(testCases, testCase{ |
| 6359 | testType: testType, |
| 6360 | name: "CustomExtensions-FailAdd-" + suffix + "-TLS13", |
| 6361 | config: Config{ |
| 6362 | MaxVersion: VersionTLS13, |
| 6363 | Bugs: ProtocolBugs{ |
| 6364 | CustomExtension: expectedContents, |
| 6365 | ExpectedCustomExtension: &expectedContents, |
| 6366 | }, |
| 6367 | }, |
| 6368 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 6369 | shouldFail: true, |
| 6370 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6371 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6372 | |
| 6373 | // If the add callback returns zero, no extension should be |
| 6374 | // added. |
| 6375 | skipCustomExtension := expectedContents |
| 6376 | if isClient { |
| 6377 | // For the case where the client skips sending the |
| 6378 | // custom extension, the server must not “echo” it. |
| 6379 | skipCustomExtension = "" |
| 6380 | } |
| 6381 | testCases = append(testCases, testCase{ |
| 6382 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6383 | name: "CustomExtensions-Skip-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6384 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6385 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6386 | Bugs: ProtocolBugs{ |
| 6387 | CustomExtension: skipCustomExtension, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6388 | ExpectedCustomExtension: &emptyString, |
| 6389 | }, |
| 6390 | }, |
| 6391 | flags: []string{flag, "-custom-extension-skip"}, |
| 6392 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6393 | testCases = append(testCases, testCase{ |
| 6394 | testType: testType, |
| 6395 | name: "CustomExtensions-Skip-" + suffix + "-TLS13", |
| 6396 | config: Config{ |
| 6397 | MaxVersion: VersionTLS13, |
| 6398 | Bugs: ProtocolBugs{ |
| 6399 | CustomExtension: skipCustomExtension, |
| 6400 | ExpectedCustomExtension: &emptyString, |
| 6401 | }, |
| 6402 | }, |
| 6403 | flags: []string{flag, "-custom-extension-skip"}, |
| 6404 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6405 | } |
| 6406 | |
| 6407 | // The custom extension add callback should not be called if the client |
| 6408 | // doesn't send the extension. |
| 6409 | testCases = append(testCases, testCase{ |
| 6410 | testType: serverTest, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6411 | name: "CustomExtensions-NotCalled-Server", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6412 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6413 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6414 | Bugs: ProtocolBugs{ |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6415 | ExpectedCustomExtension: &emptyString, |
| 6416 | }, |
| 6417 | }, |
| 6418 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 6419 | }) |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6420 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6421 | testCases = append(testCases, testCase{ |
| 6422 | testType: serverTest, |
| 6423 | name: "CustomExtensions-NotCalled-Server-TLS13", |
| 6424 | config: Config{ |
| 6425 | MaxVersion: VersionTLS13, |
| 6426 | Bugs: ProtocolBugs{ |
| 6427 | ExpectedCustomExtension: &emptyString, |
| 6428 | }, |
| 6429 | }, |
| 6430 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 6431 | }) |
| 6432 | |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6433 | // Test an unknown extension from the server. |
| 6434 | testCases = append(testCases, testCase{ |
| 6435 | testType: clientTest, |
| 6436 | name: "UnknownExtension-Client", |
| 6437 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6438 | MaxVersion: VersionTLS12, |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6439 | Bugs: ProtocolBugs{ |
| 6440 | CustomExtension: expectedContents, |
| 6441 | }, |
| 6442 | }, |
David Benjamin | 0c40a96 | 2016-08-01 12:05:50 -0400 | [diff] [blame^] | 6443 | shouldFail: true, |
| 6444 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6445 | expectedLocalError: "remote error: unsupported extension", |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6446 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6447 | testCases = append(testCases, testCase{ |
| 6448 | testType: clientTest, |
| 6449 | name: "UnknownExtension-Client-TLS13", |
| 6450 | config: Config{ |
| 6451 | MaxVersion: VersionTLS13, |
| 6452 | Bugs: ProtocolBugs{ |
| 6453 | CustomExtension: expectedContents, |
| 6454 | }, |
| 6455 | }, |
David Benjamin | 0c40a96 | 2016-08-01 12:05:50 -0400 | [diff] [blame^] | 6456 | shouldFail: true, |
| 6457 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6458 | expectedLocalError: "remote error: unsupported extension", |
| 6459 | }) |
| 6460 | |
| 6461 | // Test a known but unoffered extension from the server. |
| 6462 | testCases = append(testCases, testCase{ |
| 6463 | testType: clientTest, |
| 6464 | name: "UnofferedExtension-Client", |
| 6465 | config: Config{ |
| 6466 | MaxVersion: VersionTLS12, |
| 6467 | Bugs: ProtocolBugs{ |
| 6468 | SendALPN: "alpn", |
| 6469 | }, |
| 6470 | }, |
| 6471 | shouldFail: true, |
| 6472 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6473 | expectedLocalError: "remote error: unsupported extension", |
| 6474 | }) |
| 6475 | testCases = append(testCases, testCase{ |
| 6476 | testType: clientTest, |
| 6477 | name: "UnofferedExtension-Client-TLS13", |
| 6478 | config: Config{ |
| 6479 | MaxVersion: VersionTLS13, |
| 6480 | Bugs: ProtocolBugs{ |
| 6481 | SendALPN: "alpn", |
| 6482 | }, |
| 6483 | }, |
| 6484 | shouldFail: true, |
| 6485 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6486 | expectedLocalError: "remote error: unsupported extension", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6487 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6488 | } |
| 6489 | |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 6490 | func addRSAClientKeyExchangeTests() { |
| 6491 | for bad := RSABadValue(1); bad < NumRSABadValues; bad++ { |
| 6492 | testCases = append(testCases, testCase{ |
| 6493 | testType: serverTest, |
| 6494 | name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad), |
| 6495 | config: Config{ |
| 6496 | // Ensure the ClientHello version and final |
| 6497 | // version are different, to detect if the |
| 6498 | // server uses the wrong one. |
| 6499 | MaxVersion: VersionTLS11, |
| 6500 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 6501 | Bugs: ProtocolBugs{ |
| 6502 | BadRSAClientKeyExchange: bad, |
| 6503 | }, |
| 6504 | }, |
| 6505 | shouldFail: true, |
| 6506 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6507 | }) |
| 6508 | } |
| 6509 | } |
| 6510 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6511 | var testCurves = []struct { |
| 6512 | name string |
| 6513 | id CurveID |
| 6514 | }{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6515 | {"P-256", CurveP256}, |
| 6516 | {"P-384", CurveP384}, |
| 6517 | {"P-521", CurveP521}, |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 6518 | {"X25519", CurveX25519}, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6519 | } |
| 6520 | |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6521 | const bogusCurve = 0x1234 |
| 6522 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6523 | func addCurveTests() { |
| 6524 | for _, curve := range testCurves { |
| 6525 | testCases = append(testCases, testCase{ |
| 6526 | name: "CurveTest-Client-" + curve.name, |
| 6527 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6528 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6529 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6530 | CurvePreferences: []CurveID{curve.id}, |
| 6531 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6532 | flags: []string{"-enable-all-curves"}, |
| 6533 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6534 | }) |
| 6535 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6536 | name: "CurveTest-Client-" + curve.name + "-TLS13", |
| 6537 | config: Config{ |
| 6538 | MaxVersion: VersionTLS13, |
| 6539 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6540 | CurvePreferences: []CurveID{curve.id}, |
| 6541 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6542 | flags: []string{"-enable-all-curves"}, |
| 6543 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6544 | }) |
| 6545 | testCases = append(testCases, testCase{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6546 | testType: serverTest, |
| 6547 | name: "CurveTest-Server-" + curve.name, |
| 6548 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6549 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6550 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6551 | CurvePreferences: []CurveID{curve.id}, |
| 6552 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6553 | flags: []string{"-enable-all-curves"}, |
| 6554 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6555 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6556 | testCases = append(testCases, testCase{ |
| 6557 | testType: serverTest, |
| 6558 | name: "CurveTest-Server-" + curve.name + "-TLS13", |
| 6559 | config: Config{ |
| 6560 | MaxVersion: VersionTLS13, |
| 6561 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6562 | CurvePreferences: []CurveID{curve.id}, |
| 6563 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6564 | flags: []string{"-enable-all-curves"}, |
| 6565 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6566 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6567 | } |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 6568 | |
| 6569 | // The server must be tolerant to bogus curves. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 6570 | testCases = append(testCases, testCase{ |
| 6571 | testType: serverTest, |
| 6572 | name: "UnknownCurve", |
| 6573 | config: Config{ |
| 6574 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6575 | CurvePreferences: []CurveID{bogusCurve, CurveP256}, |
| 6576 | }, |
| 6577 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6578 | |
| 6579 | // The server must not consider ECDHE ciphers when there are no |
| 6580 | // supported curves. |
| 6581 | testCases = append(testCases, testCase{ |
| 6582 | testType: serverTest, |
| 6583 | name: "NoSupportedCurves", |
| 6584 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6585 | MaxVersion: VersionTLS12, |
| 6586 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6587 | Bugs: ProtocolBugs{ |
| 6588 | NoSupportedCurves: true, |
| 6589 | }, |
| 6590 | }, |
| 6591 | shouldFail: true, |
| 6592 | expectedError: ":NO_SHARED_CIPHER:", |
| 6593 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6594 | testCases = append(testCases, testCase{ |
| 6595 | testType: serverTest, |
| 6596 | name: "NoSupportedCurves-TLS13", |
| 6597 | config: Config{ |
| 6598 | MaxVersion: VersionTLS13, |
| 6599 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6600 | Bugs: ProtocolBugs{ |
| 6601 | NoSupportedCurves: true, |
| 6602 | }, |
| 6603 | }, |
| 6604 | shouldFail: true, |
| 6605 | expectedError: ":NO_SHARED_CIPHER:", |
| 6606 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6607 | |
| 6608 | // The server must fall back to another cipher when there are no |
| 6609 | // supported curves. |
| 6610 | testCases = append(testCases, testCase{ |
| 6611 | testType: serverTest, |
| 6612 | name: "NoCommonCurves", |
| 6613 | config: Config{ |
| 6614 | MaxVersion: VersionTLS12, |
| 6615 | CipherSuites: []uint16{ |
| 6616 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6617 | TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6618 | }, |
| 6619 | CurvePreferences: []CurveID{CurveP224}, |
| 6620 | }, |
| 6621 | expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6622 | }) |
| 6623 | |
| 6624 | // The client must reject bogus curves and disabled curves. |
| 6625 | testCases = append(testCases, testCase{ |
| 6626 | name: "BadECDHECurve", |
| 6627 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6628 | MaxVersion: VersionTLS12, |
| 6629 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6630 | Bugs: ProtocolBugs{ |
| 6631 | SendCurve: bogusCurve, |
| 6632 | }, |
| 6633 | }, |
| 6634 | shouldFail: true, |
| 6635 | expectedError: ":WRONG_CURVE:", |
| 6636 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6637 | testCases = append(testCases, testCase{ |
| 6638 | name: "BadECDHECurve-TLS13", |
| 6639 | config: Config{ |
| 6640 | MaxVersion: VersionTLS13, |
| 6641 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6642 | Bugs: ProtocolBugs{ |
| 6643 | SendCurve: bogusCurve, |
| 6644 | }, |
| 6645 | }, |
| 6646 | shouldFail: true, |
| 6647 | expectedError: ":WRONG_CURVE:", |
| 6648 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6649 | |
| 6650 | testCases = append(testCases, testCase{ |
| 6651 | name: "UnsupportedCurve", |
| 6652 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6653 | MaxVersion: VersionTLS12, |
| 6654 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6655 | CurvePreferences: []CurveID{CurveP256}, |
| 6656 | Bugs: ProtocolBugs{ |
| 6657 | IgnorePeerCurvePreferences: true, |
| 6658 | }, |
| 6659 | }, |
| 6660 | flags: []string{"-p384-only"}, |
| 6661 | shouldFail: true, |
| 6662 | expectedError: ":WRONG_CURVE:", |
| 6663 | }) |
| 6664 | |
David Benjamin | 4f92157 | 2016-07-17 14:20:10 +0200 | [diff] [blame] | 6665 | testCases = append(testCases, testCase{ |
| 6666 | // TODO(davidben): Add a TLS 1.3 version where |
| 6667 | // HelloRetryRequest requests an unsupported curve. |
| 6668 | name: "UnsupportedCurve-ServerHello-TLS13", |
| 6669 | config: Config{ |
| 6670 | MaxVersion: VersionTLS12, |
| 6671 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6672 | CurvePreferences: []CurveID{CurveP384}, |
| 6673 | Bugs: ProtocolBugs{ |
| 6674 | SendCurve: CurveP256, |
| 6675 | }, |
| 6676 | }, |
| 6677 | flags: []string{"-p384-only"}, |
| 6678 | shouldFail: true, |
| 6679 | expectedError: ":WRONG_CURVE:", |
| 6680 | }) |
| 6681 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6682 | // Test invalid curve points. |
| 6683 | testCases = append(testCases, testCase{ |
| 6684 | name: "InvalidECDHPoint-Client", |
| 6685 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6686 | MaxVersion: VersionTLS12, |
| 6687 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6688 | CurvePreferences: []CurveID{CurveP256}, |
| 6689 | Bugs: ProtocolBugs{ |
| 6690 | InvalidECDHPoint: true, |
| 6691 | }, |
| 6692 | }, |
| 6693 | shouldFail: true, |
| 6694 | expectedError: ":INVALID_ENCODING:", |
| 6695 | }) |
| 6696 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6697 | name: "InvalidECDHPoint-Client-TLS13", |
| 6698 | config: Config{ |
| 6699 | MaxVersion: VersionTLS13, |
| 6700 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6701 | CurvePreferences: []CurveID{CurveP256}, |
| 6702 | Bugs: ProtocolBugs{ |
| 6703 | InvalidECDHPoint: true, |
| 6704 | }, |
| 6705 | }, |
| 6706 | shouldFail: true, |
| 6707 | expectedError: ":INVALID_ENCODING:", |
| 6708 | }) |
| 6709 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6710 | testType: serverTest, |
| 6711 | name: "InvalidECDHPoint-Server", |
| 6712 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6713 | MaxVersion: VersionTLS12, |
| 6714 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6715 | CurvePreferences: []CurveID{CurveP256}, |
| 6716 | Bugs: ProtocolBugs{ |
| 6717 | InvalidECDHPoint: true, |
| 6718 | }, |
| 6719 | }, |
| 6720 | shouldFail: true, |
| 6721 | expectedError: ":INVALID_ENCODING:", |
| 6722 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6723 | testCases = append(testCases, testCase{ |
| 6724 | testType: serverTest, |
| 6725 | name: "InvalidECDHPoint-Server-TLS13", |
| 6726 | config: Config{ |
| 6727 | MaxVersion: VersionTLS13, |
| 6728 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6729 | CurvePreferences: []CurveID{CurveP256}, |
| 6730 | Bugs: ProtocolBugs{ |
| 6731 | InvalidECDHPoint: true, |
| 6732 | }, |
| 6733 | }, |
| 6734 | shouldFail: true, |
| 6735 | expectedError: ":INVALID_ENCODING:", |
| 6736 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6737 | } |
| 6738 | |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6739 | func addCECPQ1Tests() { |
| 6740 | testCases = append(testCases, testCase{ |
| 6741 | testType: clientTest, |
| 6742 | name: "CECPQ1-Client-BadX25519Part", |
| 6743 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6744 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6745 | MinVersion: VersionTLS12, |
| 6746 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6747 | Bugs: ProtocolBugs{ |
| 6748 | CECPQ1BadX25519Part: true, |
| 6749 | }, |
| 6750 | }, |
| 6751 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6752 | shouldFail: true, |
| 6753 | expectedLocalError: "local error: bad record MAC", |
| 6754 | }) |
| 6755 | testCases = append(testCases, testCase{ |
| 6756 | testType: clientTest, |
| 6757 | name: "CECPQ1-Client-BadNewhopePart", |
| 6758 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6759 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6760 | MinVersion: VersionTLS12, |
| 6761 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6762 | Bugs: ProtocolBugs{ |
| 6763 | CECPQ1BadNewhopePart: true, |
| 6764 | }, |
| 6765 | }, |
| 6766 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6767 | shouldFail: true, |
| 6768 | expectedLocalError: "local error: bad record MAC", |
| 6769 | }) |
| 6770 | testCases = append(testCases, testCase{ |
| 6771 | testType: serverTest, |
| 6772 | name: "CECPQ1-Server-BadX25519Part", |
| 6773 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6774 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6775 | MinVersion: VersionTLS12, |
| 6776 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6777 | Bugs: ProtocolBugs{ |
| 6778 | CECPQ1BadX25519Part: true, |
| 6779 | }, |
| 6780 | }, |
| 6781 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6782 | shouldFail: true, |
| 6783 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6784 | }) |
| 6785 | testCases = append(testCases, testCase{ |
| 6786 | testType: serverTest, |
| 6787 | name: "CECPQ1-Server-BadNewhopePart", |
| 6788 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6789 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6790 | MinVersion: VersionTLS12, |
| 6791 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6792 | Bugs: ProtocolBugs{ |
| 6793 | CECPQ1BadNewhopePart: true, |
| 6794 | }, |
| 6795 | }, |
| 6796 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6797 | shouldFail: true, |
| 6798 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6799 | }) |
| 6800 | } |
| 6801 | |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6802 | func addKeyExchangeInfoTests() { |
| 6803 | testCases = append(testCases, testCase{ |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6804 | name: "KeyExchangeInfo-DHE-Client", |
| 6805 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6806 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6807 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6808 | Bugs: ProtocolBugs{ |
| 6809 | // This is a 1234-bit prime number, generated |
| 6810 | // with: |
| 6811 | // openssl gendh 1234 | openssl asn1parse -i |
| 6812 | DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"), |
| 6813 | }, |
| 6814 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 6815 | flags: []string{"-expect-dhe-group-size", "1234"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6816 | }) |
| 6817 | testCases = append(testCases, testCase{ |
| 6818 | testType: serverTest, |
| 6819 | name: "KeyExchangeInfo-DHE-Server", |
| 6820 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6821 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6822 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6823 | }, |
| 6824 | // bssl_shim as a server configures a 2048-bit DHE group. |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 6825 | flags: []string{"-expect-dhe-group-size", "2048"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6826 | }) |
| 6827 | |
| 6828 | testCases = append(testCases, testCase{ |
| 6829 | name: "KeyExchangeInfo-ECDHE-Client", |
| 6830 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6831 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6832 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6833 | CurvePreferences: []CurveID{CurveX25519}, |
| 6834 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 6835 | flags: []string{"-expect-curve-id", "29", "-enable-all-curves"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6836 | }) |
| 6837 | testCases = append(testCases, testCase{ |
| 6838 | testType: serverTest, |
| 6839 | name: "KeyExchangeInfo-ECDHE-Server", |
| 6840 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6841 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6842 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6843 | CurvePreferences: []CurveID{CurveX25519}, |
| 6844 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 6845 | flags: []string{"-expect-curve-id", "29", "-enable-all-curves"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6846 | }) |
| 6847 | } |
| 6848 | |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 6849 | func addTLS13RecordTests() { |
| 6850 | testCases = append(testCases, testCase{ |
| 6851 | name: "TLS13-RecordPadding", |
| 6852 | config: Config{ |
| 6853 | MaxVersion: VersionTLS13, |
| 6854 | MinVersion: VersionTLS13, |
| 6855 | Bugs: ProtocolBugs{ |
| 6856 | RecordPadding: 10, |
| 6857 | }, |
| 6858 | }, |
| 6859 | }) |
| 6860 | |
| 6861 | testCases = append(testCases, testCase{ |
| 6862 | name: "TLS13-EmptyRecords", |
| 6863 | config: Config{ |
| 6864 | MaxVersion: VersionTLS13, |
| 6865 | MinVersion: VersionTLS13, |
| 6866 | Bugs: ProtocolBugs{ |
| 6867 | OmitRecordContents: true, |
| 6868 | }, |
| 6869 | }, |
| 6870 | shouldFail: true, |
| 6871 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6872 | }) |
| 6873 | |
| 6874 | testCases = append(testCases, testCase{ |
| 6875 | name: "TLS13-OnlyPadding", |
| 6876 | config: Config{ |
| 6877 | MaxVersion: VersionTLS13, |
| 6878 | MinVersion: VersionTLS13, |
| 6879 | Bugs: ProtocolBugs{ |
| 6880 | OmitRecordContents: true, |
| 6881 | RecordPadding: 10, |
| 6882 | }, |
| 6883 | }, |
| 6884 | shouldFail: true, |
| 6885 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6886 | }) |
| 6887 | |
| 6888 | testCases = append(testCases, testCase{ |
| 6889 | name: "TLS13-WrongOuterRecord", |
| 6890 | config: Config{ |
| 6891 | MaxVersion: VersionTLS13, |
| 6892 | MinVersion: VersionTLS13, |
| 6893 | Bugs: ProtocolBugs{ |
| 6894 | OuterRecordType: recordTypeHandshake, |
| 6895 | }, |
| 6896 | }, |
| 6897 | shouldFail: true, |
| 6898 | expectedError: ":INVALID_OUTER_RECORD_TYPE:", |
| 6899 | }) |
| 6900 | } |
| 6901 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 6902 | func addChangeCipherSpecTests() { |
| 6903 | // Test missing ChangeCipherSpecs. |
| 6904 | testCases = append(testCases, testCase{ |
| 6905 | name: "SkipChangeCipherSpec-Client", |
| 6906 | config: Config{ |
| 6907 | MaxVersion: VersionTLS12, |
| 6908 | Bugs: ProtocolBugs{ |
| 6909 | SkipChangeCipherSpec: true, |
| 6910 | }, |
| 6911 | }, |
| 6912 | shouldFail: true, |
| 6913 | expectedError: ":UNEXPECTED_RECORD:", |
| 6914 | }) |
| 6915 | testCases = append(testCases, testCase{ |
| 6916 | testType: serverTest, |
| 6917 | name: "SkipChangeCipherSpec-Server", |
| 6918 | config: Config{ |
| 6919 | MaxVersion: VersionTLS12, |
| 6920 | Bugs: ProtocolBugs{ |
| 6921 | SkipChangeCipherSpec: true, |
| 6922 | }, |
| 6923 | }, |
| 6924 | shouldFail: true, |
| 6925 | expectedError: ":UNEXPECTED_RECORD:", |
| 6926 | }) |
| 6927 | testCases = append(testCases, testCase{ |
| 6928 | testType: serverTest, |
| 6929 | name: "SkipChangeCipherSpec-Server-NPN", |
| 6930 | config: Config{ |
| 6931 | MaxVersion: VersionTLS12, |
| 6932 | NextProtos: []string{"bar"}, |
| 6933 | Bugs: ProtocolBugs{ |
| 6934 | SkipChangeCipherSpec: true, |
| 6935 | }, |
| 6936 | }, |
| 6937 | flags: []string{ |
| 6938 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 6939 | }, |
| 6940 | shouldFail: true, |
| 6941 | expectedError: ":UNEXPECTED_RECORD:", |
| 6942 | }) |
| 6943 | |
| 6944 | // Test synchronization between the handshake and ChangeCipherSpec. |
| 6945 | // Partial post-CCS handshake messages before ChangeCipherSpec should be |
| 6946 | // rejected. Test both with and without handshake packing to handle both |
| 6947 | // when the partial post-CCS message is in its own record and when it is |
| 6948 | // attached to the pre-CCS message. |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 6949 | for _, packed := range []bool{false, true} { |
| 6950 | var suffix string |
| 6951 | if packed { |
| 6952 | suffix = "-Packed" |
| 6953 | } |
| 6954 | |
| 6955 | testCases = append(testCases, testCase{ |
| 6956 | name: "FragmentAcrossChangeCipherSpec-Client" + suffix, |
| 6957 | config: Config{ |
| 6958 | MaxVersion: VersionTLS12, |
| 6959 | Bugs: ProtocolBugs{ |
| 6960 | FragmentAcrossChangeCipherSpec: true, |
| 6961 | PackHandshakeFlight: packed, |
| 6962 | }, |
| 6963 | }, |
| 6964 | shouldFail: true, |
| 6965 | expectedError: ":UNEXPECTED_RECORD:", |
| 6966 | }) |
| 6967 | testCases = append(testCases, testCase{ |
| 6968 | name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix, |
| 6969 | config: Config{ |
| 6970 | MaxVersion: VersionTLS12, |
| 6971 | }, |
| 6972 | resumeSession: true, |
| 6973 | resumeConfig: &Config{ |
| 6974 | MaxVersion: VersionTLS12, |
| 6975 | Bugs: ProtocolBugs{ |
| 6976 | FragmentAcrossChangeCipherSpec: true, |
| 6977 | PackHandshakeFlight: packed, |
| 6978 | }, |
| 6979 | }, |
| 6980 | shouldFail: true, |
| 6981 | expectedError: ":UNEXPECTED_RECORD:", |
| 6982 | }) |
| 6983 | testCases = append(testCases, testCase{ |
| 6984 | testType: serverTest, |
| 6985 | name: "FragmentAcrossChangeCipherSpec-Server" + suffix, |
| 6986 | config: Config{ |
| 6987 | MaxVersion: VersionTLS12, |
| 6988 | Bugs: ProtocolBugs{ |
| 6989 | FragmentAcrossChangeCipherSpec: true, |
| 6990 | PackHandshakeFlight: packed, |
| 6991 | }, |
| 6992 | }, |
| 6993 | shouldFail: true, |
| 6994 | expectedError: ":UNEXPECTED_RECORD:", |
| 6995 | }) |
| 6996 | testCases = append(testCases, testCase{ |
| 6997 | testType: serverTest, |
| 6998 | name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix, |
| 6999 | config: Config{ |
| 7000 | MaxVersion: VersionTLS12, |
| 7001 | }, |
| 7002 | resumeSession: true, |
| 7003 | resumeConfig: &Config{ |
| 7004 | MaxVersion: VersionTLS12, |
| 7005 | Bugs: ProtocolBugs{ |
| 7006 | FragmentAcrossChangeCipherSpec: true, |
| 7007 | PackHandshakeFlight: packed, |
| 7008 | }, |
| 7009 | }, |
| 7010 | shouldFail: true, |
| 7011 | expectedError: ":UNEXPECTED_RECORD:", |
| 7012 | }) |
| 7013 | testCases = append(testCases, testCase{ |
| 7014 | testType: serverTest, |
| 7015 | name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix, |
| 7016 | config: Config{ |
| 7017 | MaxVersion: VersionTLS12, |
| 7018 | NextProtos: []string{"bar"}, |
| 7019 | Bugs: ProtocolBugs{ |
| 7020 | FragmentAcrossChangeCipherSpec: true, |
| 7021 | PackHandshakeFlight: packed, |
| 7022 | }, |
| 7023 | }, |
| 7024 | flags: []string{ |
| 7025 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 7026 | }, |
| 7027 | shouldFail: true, |
| 7028 | expectedError: ":UNEXPECTED_RECORD:", |
| 7029 | }) |
| 7030 | } |
| 7031 | |
David Benjamin | 6167281 | 2016-07-14 23:10:43 -0400 | [diff] [blame] | 7032 | // Test that, in DTLS, ChangeCipherSpec is not allowed when there are |
| 7033 | // messages in the handshake queue. Do this by testing the server |
| 7034 | // reading the client Finished, reversing the flight so Finished comes |
| 7035 | // first. |
| 7036 | testCases = append(testCases, testCase{ |
| 7037 | protocol: dtls, |
| 7038 | testType: serverTest, |
| 7039 | name: "SendUnencryptedFinished-DTLS", |
| 7040 | config: Config{ |
| 7041 | MaxVersion: VersionTLS12, |
| 7042 | Bugs: ProtocolBugs{ |
| 7043 | SendUnencryptedFinished: true, |
| 7044 | ReverseHandshakeFragments: true, |
| 7045 | }, |
| 7046 | }, |
| 7047 | shouldFail: true, |
| 7048 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7049 | }) |
| 7050 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7051 | // Test synchronization between encryption changes and the handshake in |
| 7052 | // TLS 1.3, where ChangeCipherSpec is implicit. |
| 7053 | testCases = append(testCases, testCase{ |
| 7054 | name: "PartialEncryptedExtensionsWithServerHello", |
| 7055 | config: Config{ |
| 7056 | MaxVersion: VersionTLS13, |
| 7057 | Bugs: ProtocolBugs{ |
| 7058 | PartialEncryptedExtensionsWithServerHello: true, |
| 7059 | }, |
| 7060 | }, |
| 7061 | shouldFail: true, |
| 7062 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7063 | }) |
| 7064 | testCases = append(testCases, testCase{ |
| 7065 | testType: serverTest, |
| 7066 | name: "PartialClientFinishedWithClientHello", |
| 7067 | config: Config{ |
| 7068 | MaxVersion: VersionTLS13, |
| 7069 | Bugs: ProtocolBugs{ |
| 7070 | PartialClientFinishedWithClientHello: true, |
| 7071 | }, |
| 7072 | }, |
| 7073 | shouldFail: true, |
| 7074 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 7075 | }) |
| 7076 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7077 | // Test that early ChangeCipherSpecs are handled correctly. |
| 7078 | testCases = append(testCases, testCase{ |
| 7079 | testType: serverTest, |
| 7080 | name: "EarlyChangeCipherSpec-server-1", |
| 7081 | config: Config{ |
| 7082 | MaxVersion: VersionTLS12, |
| 7083 | Bugs: ProtocolBugs{ |
| 7084 | EarlyChangeCipherSpec: 1, |
| 7085 | }, |
| 7086 | }, |
| 7087 | shouldFail: true, |
| 7088 | expectedError: ":UNEXPECTED_RECORD:", |
| 7089 | }) |
| 7090 | testCases = append(testCases, testCase{ |
| 7091 | testType: serverTest, |
| 7092 | name: "EarlyChangeCipherSpec-server-2", |
| 7093 | config: Config{ |
| 7094 | MaxVersion: VersionTLS12, |
| 7095 | Bugs: ProtocolBugs{ |
| 7096 | EarlyChangeCipherSpec: 2, |
| 7097 | }, |
| 7098 | }, |
| 7099 | shouldFail: true, |
| 7100 | expectedError: ":UNEXPECTED_RECORD:", |
| 7101 | }) |
| 7102 | testCases = append(testCases, testCase{ |
| 7103 | protocol: dtls, |
| 7104 | name: "StrayChangeCipherSpec", |
| 7105 | config: Config{ |
| 7106 | // TODO(davidben): Once DTLS 1.3 exists, test |
| 7107 | // that stray ChangeCipherSpec messages are |
| 7108 | // rejected. |
| 7109 | MaxVersion: VersionTLS12, |
| 7110 | Bugs: ProtocolBugs{ |
| 7111 | StrayChangeCipherSpec: true, |
| 7112 | }, |
| 7113 | }, |
| 7114 | }) |
| 7115 | |
| 7116 | // Test that the contents of ChangeCipherSpec are checked. |
| 7117 | testCases = append(testCases, testCase{ |
| 7118 | name: "BadChangeCipherSpec-1", |
| 7119 | config: Config{ |
| 7120 | MaxVersion: VersionTLS12, |
| 7121 | Bugs: ProtocolBugs{ |
| 7122 | BadChangeCipherSpec: []byte{2}, |
| 7123 | }, |
| 7124 | }, |
| 7125 | shouldFail: true, |
| 7126 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7127 | }) |
| 7128 | testCases = append(testCases, testCase{ |
| 7129 | name: "BadChangeCipherSpec-2", |
| 7130 | config: Config{ |
| 7131 | MaxVersion: VersionTLS12, |
| 7132 | Bugs: ProtocolBugs{ |
| 7133 | BadChangeCipherSpec: []byte{1, 1}, |
| 7134 | }, |
| 7135 | }, |
| 7136 | shouldFail: true, |
| 7137 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7138 | }) |
| 7139 | testCases = append(testCases, testCase{ |
| 7140 | protocol: dtls, |
| 7141 | name: "BadChangeCipherSpec-DTLS-1", |
| 7142 | config: Config{ |
| 7143 | MaxVersion: VersionTLS12, |
| 7144 | Bugs: ProtocolBugs{ |
| 7145 | BadChangeCipherSpec: []byte{2}, |
| 7146 | }, |
| 7147 | }, |
| 7148 | shouldFail: true, |
| 7149 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7150 | }) |
| 7151 | testCases = append(testCases, testCase{ |
| 7152 | protocol: dtls, |
| 7153 | name: "BadChangeCipherSpec-DTLS-2", |
| 7154 | config: Config{ |
| 7155 | MaxVersion: VersionTLS12, |
| 7156 | Bugs: ProtocolBugs{ |
| 7157 | BadChangeCipherSpec: []byte{1, 1}, |
| 7158 | }, |
| 7159 | }, |
| 7160 | shouldFail: true, |
| 7161 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7162 | }) |
| 7163 | } |
| 7164 | |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7165 | func addWrongMessageTypeTests() { |
| 7166 | for _, protocol := range []protocol{tls, dtls} { |
| 7167 | var suffix string |
| 7168 | if protocol == dtls { |
| 7169 | suffix = "-DTLS" |
| 7170 | } |
| 7171 | |
| 7172 | testCases = append(testCases, testCase{ |
| 7173 | protocol: protocol, |
| 7174 | testType: serverTest, |
| 7175 | name: "WrongMessageType-ClientHello" + suffix, |
| 7176 | config: Config{ |
| 7177 | MaxVersion: VersionTLS12, |
| 7178 | Bugs: ProtocolBugs{ |
| 7179 | SendWrongMessageType: typeClientHello, |
| 7180 | }, |
| 7181 | }, |
| 7182 | shouldFail: true, |
| 7183 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7184 | expectedLocalError: "remote error: unexpected message", |
| 7185 | }) |
| 7186 | |
| 7187 | if protocol == dtls { |
| 7188 | testCases = append(testCases, testCase{ |
| 7189 | protocol: protocol, |
| 7190 | name: "WrongMessageType-HelloVerifyRequest" + suffix, |
| 7191 | config: Config{ |
| 7192 | MaxVersion: VersionTLS12, |
| 7193 | Bugs: ProtocolBugs{ |
| 7194 | SendWrongMessageType: typeHelloVerifyRequest, |
| 7195 | }, |
| 7196 | }, |
| 7197 | shouldFail: true, |
| 7198 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7199 | expectedLocalError: "remote error: unexpected message", |
| 7200 | }) |
| 7201 | } |
| 7202 | |
| 7203 | testCases = append(testCases, testCase{ |
| 7204 | protocol: protocol, |
| 7205 | name: "WrongMessageType-ServerHello" + suffix, |
| 7206 | config: Config{ |
| 7207 | MaxVersion: VersionTLS12, |
| 7208 | Bugs: ProtocolBugs{ |
| 7209 | SendWrongMessageType: typeServerHello, |
| 7210 | }, |
| 7211 | }, |
| 7212 | shouldFail: true, |
| 7213 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7214 | expectedLocalError: "remote error: unexpected message", |
| 7215 | }) |
| 7216 | |
| 7217 | testCases = append(testCases, testCase{ |
| 7218 | protocol: protocol, |
| 7219 | name: "WrongMessageType-ServerCertificate" + suffix, |
| 7220 | config: Config{ |
| 7221 | MaxVersion: VersionTLS12, |
| 7222 | Bugs: ProtocolBugs{ |
| 7223 | SendWrongMessageType: typeCertificate, |
| 7224 | }, |
| 7225 | }, |
| 7226 | shouldFail: true, |
| 7227 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7228 | expectedLocalError: "remote error: unexpected message", |
| 7229 | }) |
| 7230 | |
| 7231 | testCases = append(testCases, testCase{ |
| 7232 | protocol: protocol, |
| 7233 | name: "WrongMessageType-CertificateStatus" + suffix, |
| 7234 | config: Config{ |
| 7235 | MaxVersion: VersionTLS12, |
| 7236 | Bugs: ProtocolBugs{ |
| 7237 | SendWrongMessageType: typeCertificateStatus, |
| 7238 | }, |
| 7239 | }, |
| 7240 | flags: []string{"-enable-ocsp-stapling"}, |
| 7241 | shouldFail: true, |
| 7242 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7243 | expectedLocalError: "remote error: unexpected message", |
| 7244 | }) |
| 7245 | |
| 7246 | testCases = append(testCases, testCase{ |
| 7247 | protocol: protocol, |
| 7248 | name: "WrongMessageType-ServerKeyExchange" + suffix, |
| 7249 | config: Config{ |
| 7250 | MaxVersion: VersionTLS12, |
| 7251 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7252 | Bugs: ProtocolBugs{ |
| 7253 | SendWrongMessageType: typeServerKeyExchange, |
| 7254 | }, |
| 7255 | }, |
| 7256 | shouldFail: true, |
| 7257 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7258 | expectedLocalError: "remote error: unexpected message", |
| 7259 | }) |
| 7260 | |
| 7261 | testCases = append(testCases, testCase{ |
| 7262 | protocol: protocol, |
| 7263 | name: "WrongMessageType-CertificateRequest" + suffix, |
| 7264 | config: Config{ |
| 7265 | MaxVersion: VersionTLS12, |
| 7266 | ClientAuth: RequireAnyClientCert, |
| 7267 | Bugs: ProtocolBugs{ |
| 7268 | SendWrongMessageType: typeCertificateRequest, |
| 7269 | }, |
| 7270 | }, |
| 7271 | shouldFail: true, |
| 7272 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7273 | expectedLocalError: "remote error: unexpected message", |
| 7274 | }) |
| 7275 | |
| 7276 | testCases = append(testCases, testCase{ |
| 7277 | protocol: protocol, |
| 7278 | name: "WrongMessageType-ServerHelloDone" + suffix, |
| 7279 | config: Config{ |
| 7280 | MaxVersion: VersionTLS12, |
| 7281 | Bugs: ProtocolBugs{ |
| 7282 | SendWrongMessageType: typeServerHelloDone, |
| 7283 | }, |
| 7284 | }, |
| 7285 | shouldFail: true, |
| 7286 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7287 | expectedLocalError: "remote error: unexpected message", |
| 7288 | }) |
| 7289 | |
| 7290 | testCases = append(testCases, testCase{ |
| 7291 | testType: serverTest, |
| 7292 | protocol: protocol, |
| 7293 | name: "WrongMessageType-ClientCertificate" + suffix, |
| 7294 | config: Config{ |
| 7295 | Certificates: []Certificate{rsaCertificate}, |
| 7296 | MaxVersion: VersionTLS12, |
| 7297 | Bugs: ProtocolBugs{ |
| 7298 | SendWrongMessageType: typeCertificate, |
| 7299 | }, |
| 7300 | }, |
| 7301 | flags: []string{"-require-any-client-certificate"}, |
| 7302 | shouldFail: true, |
| 7303 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7304 | expectedLocalError: "remote error: unexpected message", |
| 7305 | }) |
| 7306 | |
| 7307 | testCases = append(testCases, testCase{ |
| 7308 | testType: serverTest, |
| 7309 | protocol: protocol, |
| 7310 | name: "WrongMessageType-CertificateVerify" + suffix, |
| 7311 | config: Config{ |
| 7312 | Certificates: []Certificate{rsaCertificate}, |
| 7313 | MaxVersion: VersionTLS12, |
| 7314 | Bugs: ProtocolBugs{ |
| 7315 | SendWrongMessageType: typeCertificateVerify, |
| 7316 | }, |
| 7317 | }, |
| 7318 | flags: []string{"-require-any-client-certificate"}, |
| 7319 | shouldFail: true, |
| 7320 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7321 | expectedLocalError: "remote error: unexpected message", |
| 7322 | }) |
| 7323 | |
| 7324 | testCases = append(testCases, testCase{ |
| 7325 | testType: serverTest, |
| 7326 | protocol: protocol, |
| 7327 | name: "WrongMessageType-ClientKeyExchange" + suffix, |
| 7328 | config: Config{ |
| 7329 | MaxVersion: VersionTLS12, |
| 7330 | Bugs: ProtocolBugs{ |
| 7331 | SendWrongMessageType: typeClientKeyExchange, |
| 7332 | }, |
| 7333 | }, |
| 7334 | shouldFail: true, |
| 7335 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7336 | expectedLocalError: "remote error: unexpected message", |
| 7337 | }) |
| 7338 | |
| 7339 | if protocol != dtls { |
| 7340 | testCases = append(testCases, testCase{ |
| 7341 | testType: serverTest, |
| 7342 | protocol: protocol, |
| 7343 | name: "WrongMessageType-NextProtocol" + suffix, |
| 7344 | config: Config{ |
| 7345 | MaxVersion: VersionTLS12, |
| 7346 | NextProtos: []string{"bar"}, |
| 7347 | Bugs: ProtocolBugs{ |
| 7348 | SendWrongMessageType: typeNextProtocol, |
| 7349 | }, |
| 7350 | }, |
| 7351 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 7352 | shouldFail: true, |
| 7353 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7354 | expectedLocalError: "remote error: unexpected message", |
| 7355 | }) |
| 7356 | |
| 7357 | testCases = append(testCases, testCase{ |
| 7358 | testType: serverTest, |
| 7359 | protocol: protocol, |
| 7360 | name: "WrongMessageType-ChannelID" + suffix, |
| 7361 | config: Config{ |
| 7362 | MaxVersion: VersionTLS12, |
| 7363 | ChannelID: channelIDKey, |
| 7364 | Bugs: ProtocolBugs{ |
| 7365 | SendWrongMessageType: typeChannelID, |
| 7366 | }, |
| 7367 | }, |
| 7368 | flags: []string{ |
| 7369 | "-expect-channel-id", |
| 7370 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 7371 | }, |
| 7372 | shouldFail: true, |
| 7373 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7374 | expectedLocalError: "remote error: unexpected message", |
| 7375 | }) |
| 7376 | } |
| 7377 | |
| 7378 | testCases = append(testCases, testCase{ |
| 7379 | testType: serverTest, |
| 7380 | protocol: protocol, |
| 7381 | name: "WrongMessageType-ClientFinished" + suffix, |
| 7382 | config: Config{ |
| 7383 | MaxVersion: VersionTLS12, |
| 7384 | Bugs: ProtocolBugs{ |
| 7385 | SendWrongMessageType: typeFinished, |
| 7386 | }, |
| 7387 | }, |
| 7388 | shouldFail: true, |
| 7389 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7390 | expectedLocalError: "remote error: unexpected message", |
| 7391 | }) |
| 7392 | |
| 7393 | testCases = append(testCases, testCase{ |
| 7394 | protocol: protocol, |
| 7395 | name: "WrongMessageType-NewSessionTicket" + suffix, |
| 7396 | config: Config{ |
| 7397 | MaxVersion: VersionTLS12, |
| 7398 | Bugs: ProtocolBugs{ |
| 7399 | SendWrongMessageType: typeNewSessionTicket, |
| 7400 | }, |
| 7401 | }, |
| 7402 | shouldFail: true, |
| 7403 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7404 | expectedLocalError: "remote error: unexpected message", |
| 7405 | }) |
| 7406 | |
| 7407 | testCases = append(testCases, testCase{ |
| 7408 | protocol: protocol, |
| 7409 | name: "WrongMessageType-ServerFinished" + suffix, |
| 7410 | config: Config{ |
| 7411 | MaxVersion: VersionTLS12, |
| 7412 | Bugs: ProtocolBugs{ |
| 7413 | SendWrongMessageType: typeFinished, |
| 7414 | }, |
| 7415 | }, |
| 7416 | shouldFail: true, |
| 7417 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7418 | expectedLocalError: "remote error: unexpected message", |
| 7419 | }) |
| 7420 | |
| 7421 | } |
| 7422 | } |
| 7423 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7424 | func addTLS13WrongMessageTypeTests() { |
| 7425 | testCases = append(testCases, testCase{ |
| 7426 | testType: serverTest, |
| 7427 | name: "WrongMessageType-TLS13-ClientHello", |
| 7428 | config: Config{ |
| 7429 | MaxVersion: VersionTLS13, |
| 7430 | Bugs: ProtocolBugs{ |
| 7431 | SendWrongMessageType: typeClientHello, |
| 7432 | }, |
| 7433 | }, |
| 7434 | shouldFail: true, |
| 7435 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7436 | expectedLocalError: "remote error: unexpected message", |
| 7437 | }) |
| 7438 | |
| 7439 | testCases = append(testCases, testCase{ |
| 7440 | name: "WrongMessageType-TLS13-ServerHello", |
| 7441 | config: Config{ |
| 7442 | MaxVersion: VersionTLS13, |
| 7443 | Bugs: ProtocolBugs{ |
| 7444 | SendWrongMessageType: typeServerHello, |
| 7445 | }, |
| 7446 | }, |
| 7447 | shouldFail: true, |
| 7448 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7449 | // The alert comes in with the wrong encryption. |
| 7450 | expectedLocalError: "local error: bad record MAC", |
| 7451 | }) |
| 7452 | |
| 7453 | testCases = append(testCases, testCase{ |
| 7454 | name: "WrongMessageType-TLS13-EncryptedExtensions", |
| 7455 | config: Config{ |
| 7456 | MaxVersion: VersionTLS13, |
| 7457 | Bugs: ProtocolBugs{ |
| 7458 | SendWrongMessageType: typeEncryptedExtensions, |
| 7459 | }, |
| 7460 | }, |
| 7461 | shouldFail: true, |
| 7462 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7463 | expectedLocalError: "remote error: unexpected message", |
| 7464 | }) |
| 7465 | |
| 7466 | testCases = append(testCases, testCase{ |
| 7467 | name: "WrongMessageType-TLS13-CertificateRequest", |
| 7468 | config: Config{ |
| 7469 | MaxVersion: VersionTLS13, |
| 7470 | ClientAuth: RequireAnyClientCert, |
| 7471 | Bugs: ProtocolBugs{ |
| 7472 | SendWrongMessageType: typeCertificateRequest, |
| 7473 | }, |
| 7474 | }, |
| 7475 | shouldFail: true, |
| 7476 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7477 | expectedLocalError: "remote error: unexpected message", |
| 7478 | }) |
| 7479 | |
| 7480 | testCases = append(testCases, testCase{ |
| 7481 | name: "WrongMessageType-TLS13-ServerCertificate", |
| 7482 | config: Config{ |
| 7483 | MaxVersion: VersionTLS13, |
| 7484 | Bugs: ProtocolBugs{ |
| 7485 | SendWrongMessageType: typeCertificate, |
| 7486 | }, |
| 7487 | }, |
| 7488 | shouldFail: true, |
| 7489 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7490 | expectedLocalError: "remote error: unexpected message", |
| 7491 | }) |
| 7492 | |
| 7493 | testCases = append(testCases, testCase{ |
| 7494 | name: "WrongMessageType-TLS13-ServerCertificateVerify", |
| 7495 | config: Config{ |
| 7496 | MaxVersion: VersionTLS13, |
| 7497 | Bugs: ProtocolBugs{ |
| 7498 | SendWrongMessageType: typeCertificateVerify, |
| 7499 | }, |
| 7500 | }, |
| 7501 | shouldFail: true, |
| 7502 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7503 | expectedLocalError: "remote error: unexpected message", |
| 7504 | }) |
| 7505 | |
| 7506 | testCases = append(testCases, testCase{ |
| 7507 | name: "WrongMessageType-TLS13-ServerFinished", |
| 7508 | config: Config{ |
| 7509 | MaxVersion: VersionTLS13, |
| 7510 | Bugs: ProtocolBugs{ |
| 7511 | SendWrongMessageType: typeFinished, |
| 7512 | }, |
| 7513 | }, |
| 7514 | shouldFail: true, |
| 7515 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7516 | expectedLocalError: "remote error: unexpected message", |
| 7517 | }) |
| 7518 | |
| 7519 | testCases = append(testCases, testCase{ |
| 7520 | testType: serverTest, |
| 7521 | name: "WrongMessageType-TLS13-ClientCertificate", |
| 7522 | config: Config{ |
| 7523 | Certificates: []Certificate{rsaCertificate}, |
| 7524 | MaxVersion: VersionTLS13, |
| 7525 | Bugs: ProtocolBugs{ |
| 7526 | SendWrongMessageType: typeCertificate, |
| 7527 | }, |
| 7528 | }, |
| 7529 | flags: []string{"-require-any-client-certificate"}, |
| 7530 | shouldFail: true, |
| 7531 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7532 | expectedLocalError: "remote error: unexpected message", |
| 7533 | }) |
| 7534 | |
| 7535 | testCases = append(testCases, testCase{ |
| 7536 | testType: serverTest, |
| 7537 | name: "WrongMessageType-TLS13-ClientCertificateVerify", |
| 7538 | config: Config{ |
| 7539 | Certificates: []Certificate{rsaCertificate}, |
| 7540 | MaxVersion: VersionTLS13, |
| 7541 | Bugs: ProtocolBugs{ |
| 7542 | SendWrongMessageType: typeCertificateVerify, |
| 7543 | }, |
| 7544 | }, |
| 7545 | flags: []string{"-require-any-client-certificate"}, |
| 7546 | shouldFail: true, |
| 7547 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7548 | expectedLocalError: "remote error: unexpected message", |
| 7549 | }) |
| 7550 | |
| 7551 | testCases = append(testCases, testCase{ |
| 7552 | testType: serverTest, |
| 7553 | name: "WrongMessageType-TLS13-ClientFinished", |
| 7554 | config: Config{ |
| 7555 | MaxVersion: VersionTLS13, |
| 7556 | Bugs: ProtocolBugs{ |
| 7557 | SendWrongMessageType: typeFinished, |
| 7558 | }, |
| 7559 | }, |
| 7560 | shouldFail: true, |
| 7561 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7562 | expectedLocalError: "remote error: unexpected message", |
| 7563 | }) |
| 7564 | } |
| 7565 | |
| 7566 | func addTLS13HandshakeTests() { |
| 7567 | testCases = append(testCases, testCase{ |
| 7568 | testType: clientTest, |
| 7569 | name: "MissingKeyShare-Client", |
| 7570 | config: Config{ |
| 7571 | MaxVersion: VersionTLS13, |
| 7572 | Bugs: ProtocolBugs{ |
| 7573 | MissingKeyShare: true, |
| 7574 | }, |
| 7575 | }, |
| 7576 | shouldFail: true, |
| 7577 | expectedError: ":MISSING_KEY_SHARE:", |
| 7578 | }) |
| 7579 | |
| 7580 | testCases = append(testCases, testCase{ |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7581 | testType: serverTest, |
| 7582 | name: "MissingKeyShare-Server", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7583 | config: Config{ |
| 7584 | MaxVersion: VersionTLS13, |
| 7585 | Bugs: ProtocolBugs{ |
| 7586 | MissingKeyShare: true, |
| 7587 | }, |
| 7588 | }, |
| 7589 | shouldFail: true, |
| 7590 | expectedError: ":MISSING_KEY_SHARE:", |
| 7591 | }) |
| 7592 | |
| 7593 | testCases = append(testCases, testCase{ |
| 7594 | testType: clientTest, |
| 7595 | name: "ClientHelloMissingKeyShare", |
| 7596 | config: Config{ |
| 7597 | MaxVersion: VersionTLS13, |
| 7598 | Bugs: ProtocolBugs{ |
| 7599 | MissingKeyShare: true, |
| 7600 | }, |
| 7601 | }, |
| 7602 | shouldFail: true, |
| 7603 | expectedError: ":MISSING_KEY_SHARE:", |
| 7604 | }) |
| 7605 | |
| 7606 | testCases = append(testCases, testCase{ |
| 7607 | testType: clientTest, |
| 7608 | name: "MissingKeyShare", |
| 7609 | config: Config{ |
| 7610 | MaxVersion: VersionTLS13, |
| 7611 | Bugs: ProtocolBugs{ |
| 7612 | MissingKeyShare: true, |
| 7613 | }, |
| 7614 | }, |
| 7615 | shouldFail: true, |
| 7616 | expectedError: ":MISSING_KEY_SHARE:", |
| 7617 | }) |
| 7618 | |
| 7619 | testCases = append(testCases, testCase{ |
| 7620 | testType: serverTest, |
| 7621 | name: "DuplicateKeyShares", |
| 7622 | config: Config{ |
| 7623 | MaxVersion: VersionTLS13, |
| 7624 | Bugs: ProtocolBugs{ |
| 7625 | DuplicateKeyShares: true, |
| 7626 | }, |
| 7627 | }, |
| 7628 | }) |
| 7629 | |
| 7630 | testCases = append(testCases, testCase{ |
| 7631 | testType: clientTest, |
| 7632 | name: "EmptyEncryptedExtensions", |
| 7633 | config: Config{ |
| 7634 | MaxVersion: VersionTLS13, |
| 7635 | Bugs: ProtocolBugs{ |
| 7636 | EmptyEncryptedExtensions: true, |
| 7637 | }, |
| 7638 | }, |
| 7639 | shouldFail: true, |
| 7640 | expectedLocalError: "remote error: error decoding message", |
| 7641 | }) |
| 7642 | |
| 7643 | testCases = append(testCases, testCase{ |
| 7644 | testType: clientTest, |
| 7645 | name: "EncryptedExtensionsWithKeyShare", |
| 7646 | config: Config{ |
| 7647 | MaxVersion: VersionTLS13, |
| 7648 | Bugs: ProtocolBugs{ |
| 7649 | EncryptedExtensionsWithKeyShare: true, |
| 7650 | }, |
| 7651 | }, |
| 7652 | shouldFail: true, |
| 7653 | expectedLocalError: "remote error: unsupported extension", |
| 7654 | }) |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7655 | |
| 7656 | testCases = append(testCases, testCase{ |
| 7657 | testType: serverTest, |
| 7658 | name: "SendHelloRetryRequest", |
| 7659 | config: Config{ |
| 7660 | MaxVersion: VersionTLS13, |
| 7661 | // Require a HelloRetryRequest for every curve. |
| 7662 | DefaultCurves: []CurveID{}, |
| 7663 | }, |
| 7664 | expectedCurveID: CurveX25519, |
| 7665 | }) |
| 7666 | |
| 7667 | testCases = append(testCases, testCase{ |
| 7668 | testType: serverTest, |
| 7669 | name: "SendHelloRetryRequest-2", |
| 7670 | config: Config{ |
| 7671 | MaxVersion: VersionTLS13, |
| 7672 | DefaultCurves: []CurveID{CurveP384}, |
| 7673 | }, |
| 7674 | // Although the ClientHello did not predict our preferred curve, |
| 7675 | // we always select it whether it is predicted or not. |
| 7676 | expectedCurveID: CurveX25519, |
| 7677 | }) |
| 7678 | |
| 7679 | testCases = append(testCases, testCase{ |
| 7680 | name: "UnknownCurve-HelloRetryRequest", |
| 7681 | config: Config{ |
| 7682 | MaxVersion: VersionTLS13, |
| 7683 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7684 | CurvePreferences: []CurveID{CurveP384}, |
| 7685 | Bugs: ProtocolBugs{ |
| 7686 | SendHelloRetryRequestCurve: bogusCurve, |
| 7687 | }, |
| 7688 | }, |
| 7689 | shouldFail: true, |
| 7690 | expectedError: ":WRONG_CURVE:", |
| 7691 | }) |
| 7692 | |
| 7693 | testCases = append(testCases, testCase{ |
| 7694 | name: "DisabledCurve-HelloRetryRequest", |
| 7695 | config: Config{ |
| 7696 | MaxVersion: VersionTLS13, |
| 7697 | CurvePreferences: []CurveID{CurveP256}, |
| 7698 | Bugs: ProtocolBugs{ |
| 7699 | IgnorePeerCurvePreferences: true, |
| 7700 | }, |
| 7701 | }, |
| 7702 | flags: []string{"-p384-only"}, |
| 7703 | shouldFail: true, |
| 7704 | expectedError: ":WRONG_CURVE:", |
| 7705 | }) |
| 7706 | |
| 7707 | testCases = append(testCases, testCase{ |
| 7708 | name: "UnnecessaryHelloRetryRequest", |
| 7709 | config: Config{ |
| 7710 | MaxVersion: VersionTLS13, |
| 7711 | Bugs: ProtocolBugs{ |
| 7712 | UnnecessaryHelloRetryRequest: true, |
| 7713 | }, |
| 7714 | }, |
| 7715 | shouldFail: true, |
| 7716 | expectedError: ":WRONG_CURVE:", |
| 7717 | }) |
| 7718 | |
| 7719 | testCases = append(testCases, testCase{ |
| 7720 | name: "SecondHelloRetryRequest", |
| 7721 | config: Config{ |
| 7722 | MaxVersion: VersionTLS13, |
| 7723 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7724 | CurvePreferences: []CurveID{CurveP384}, |
| 7725 | Bugs: ProtocolBugs{ |
| 7726 | SecondHelloRetryRequest: true, |
| 7727 | }, |
| 7728 | }, |
| 7729 | shouldFail: true, |
| 7730 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7731 | }) |
| 7732 | |
| 7733 | testCases = append(testCases, testCase{ |
| 7734 | testType: serverTest, |
| 7735 | name: "SecondClientHelloMissingKeyShare", |
| 7736 | config: Config{ |
| 7737 | MaxVersion: VersionTLS13, |
| 7738 | DefaultCurves: []CurveID{}, |
| 7739 | Bugs: ProtocolBugs{ |
| 7740 | SecondClientHelloMissingKeyShare: true, |
| 7741 | }, |
| 7742 | }, |
| 7743 | shouldFail: true, |
| 7744 | expectedError: ":MISSING_KEY_SHARE:", |
| 7745 | }) |
| 7746 | |
| 7747 | testCases = append(testCases, testCase{ |
| 7748 | testType: serverTest, |
| 7749 | name: "SecondClientHelloWrongCurve", |
| 7750 | config: Config{ |
| 7751 | MaxVersion: VersionTLS13, |
| 7752 | DefaultCurves: []CurveID{}, |
| 7753 | Bugs: ProtocolBugs{ |
| 7754 | MisinterpretHelloRetryRequestCurve: CurveP521, |
| 7755 | }, |
| 7756 | }, |
| 7757 | shouldFail: true, |
| 7758 | expectedError: ":WRONG_CURVE:", |
| 7759 | }) |
| 7760 | |
| 7761 | testCases = append(testCases, testCase{ |
| 7762 | name: "HelloRetryRequestVersionMismatch", |
| 7763 | config: Config{ |
| 7764 | MaxVersion: VersionTLS13, |
| 7765 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7766 | CurvePreferences: []CurveID{CurveP384}, |
| 7767 | Bugs: ProtocolBugs{ |
| 7768 | SendServerHelloVersion: 0x0305, |
| 7769 | }, |
| 7770 | }, |
| 7771 | shouldFail: true, |
| 7772 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 7773 | }) |
| 7774 | |
| 7775 | testCases = append(testCases, testCase{ |
| 7776 | name: "HelloRetryRequestCurveMismatch", |
| 7777 | config: Config{ |
| 7778 | MaxVersion: VersionTLS13, |
| 7779 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7780 | CurvePreferences: []CurveID{CurveP384}, |
| 7781 | Bugs: ProtocolBugs{ |
| 7782 | // Send P-384 (correct) in the HelloRetryRequest. |
| 7783 | SendHelloRetryRequestCurve: CurveP384, |
| 7784 | // But send P-256 in the ServerHello. |
| 7785 | SendCurve: CurveP256, |
| 7786 | }, |
| 7787 | }, |
| 7788 | shouldFail: true, |
| 7789 | expectedError: ":WRONG_CURVE:", |
| 7790 | }) |
| 7791 | |
| 7792 | // Test the server selecting a curve that requires a HelloRetryRequest |
| 7793 | // without sending it. |
| 7794 | testCases = append(testCases, testCase{ |
| 7795 | name: "SkipHelloRetryRequest", |
| 7796 | config: Config{ |
| 7797 | MaxVersion: VersionTLS13, |
| 7798 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7799 | CurvePreferences: []CurveID{CurveP384}, |
| 7800 | Bugs: ProtocolBugs{ |
| 7801 | SkipHelloRetryRequest: true, |
| 7802 | }, |
| 7803 | }, |
| 7804 | shouldFail: true, |
| 7805 | expectedError: ":WRONG_CURVE:", |
| 7806 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7807 | } |
| 7808 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7809 | 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] | 7810 | defer wg.Done() |
| 7811 | |
| 7812 | for test := range c { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 7813 | var err error |
| 7814 | |
| 7815 | if *mallocTest < 0 { |
| 7816 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7817 | err = runTest(test, shimPath, -1) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 7818 | } else { |
| 7819 | for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ { |
| 7820 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7821 | if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 7822 | if err != nil { |
| 7823 | fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err) |
| 7824 | } |
| 7825 | break |
| 7826 | } |
| 7827 | } |
| 7828 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7829 | statusChan <- statusMsg{test: test, err: err} |
| 7830 | } |
| 7831 | } |
| 7832 | |
| 7833 | type statusMsg struct { |
| 7834 | test *testCase |
| 7835 | started bool |
| 7836 | err error |
| 7837 | } |
| 7838 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7839 | func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 7840 | var started, done, failed, unimplemented, lineLen int |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7841 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7842 | testOutput := newTestOutput() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7843 | for msg := range statusChan { |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7844 | if !*pipe { |
| 7845 | // Erase the previous status line. |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 7846 | var erase string |
| 7847 | for i := 0; i < lineLen; i++ { |
| 7848 | erase += "\b \b" |
| 7849 | } |
| 7850 | fmt.Print(erase) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7851 | } |
| 7852 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7853 | if msg.started { |
| 7854 | started++ |
| 7855 | } else { |
| 7856 | done++ |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7857 | |
| 7858 | if msg.err != nil { |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 7859 | if msg.err == errUnimplemented { |
| 7860 | if *pipe { |
| 7861 | // Print each test instead of a status line. |
| 7862 | fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name) |
| 7863 | } |
| 7864 | unimplemented++ |
| 7865 | testOutput.addResult(msg.test.name, "UNIMPLEMENTED") |
| 7866 | } else { |
| 7867 | fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err) |
| 7868 | failed++ |
| 7869 | testOutput.addResult(msg.test.name, "FAIL") |
| 7870 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7871 | } else { |
| 7872 | if *pipe { |
| 7873 | // Print each test instead of a status line. |
| 7874 | fmt.Printf("PASSED (%s)\n", msg.test.name) |
| 7875 | } |
| 7876 | testOutput.addResult(msg.test.name, "PASS") |
| 7877 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7878 | } |
| 7879 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7880 | if !*pipe { |
| 7881 | // Print a new status line. |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 7882 | 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] | 7883 | lineLen = len(line) |
| 7884 | os.Stdout.WriteString(line) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7885 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7886 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7887 | |
| 7888 | doneChan <- testOutput |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7889 | } |
| 7890 | |
| 7891 | func main() { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7892 | flag.Parse() |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7893 | *resourceDir = path.Clean(*resourceDir) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 7894 | initCertificates() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7895 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7896 | addBasicTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7897 | addCipherSuiteTests() |
| 7898 | addBadECDSASignatureTests() |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7899 | addCBCPaddingTests() |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 7900 | addCBCSplittingTests() |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 7901 | addClientAuthTests() |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 7902 | addDDoSCallbackTests() |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 7903 | addVersionNegotiationTests() |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 7904 | addMinimumVersionTests() |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 7905 | addExtensionTests() |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 7906 | addResumptionVersionTests() |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 7907 | addExtendedMasterSecretTests() |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 7908 | addRenegotiationTests() |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 7909 | addDTLSReplayTests() |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 7910 | addSignatureAlgorithmTests() |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 7911 | addDTLSRetransmitTests() |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 7912 | addExportKeyingMaterialTests() |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 7913 | addTLSUniqueTests() |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7914 | addCustomExtensionTests() |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 7915 | addRSAClientKeyExchangeTests() |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7916 | addCurveTests() |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7917 | addCECPQ1Tests() |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7918 | addKeyExchangeInfoTests() |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 7919 | addTLS13RecordTests() |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 7920 | addAllStateMachineCoverageTests() |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7921 | addChangeCipherSpecTests() |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7922 | addWrongMessageTypeTests() |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7923 | addTLS13WrongMessageTypeTests() |
| 7924 | addTLS13HandshakeTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7925 | |
| 7926 | var wg sync.WaitGroup |
| 7927 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7928 | statusChan := make(chan statusMsg, *numWorkers) |
| 7929 | testChan := make(chan *testCase, *numWorkers) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7930 | doneChan := make(chan *testOutput) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7931 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 7932 | go statusPrinter(doneChan, statusChan, len(testCases)) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7933 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7934 | for i := 0; i < *numWorkers; i++ { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7935 | wg.Add(1) |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7936 | go worker(statusChan, testChan, *shimPath, &wg) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7937 | } |
| 7938 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 7939 | var foundTest bool |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 7940 | for i := range testCases { |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 7941 | matched := true |
| 7942 | if len(*testToRun) != 0 { |
| 7943 | var err error |
| 7944 | matched, err = filepath.Match(*testToRun, testCases[i].name) |
| 7945 | if err != nil { |
| 7946 | fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err) |
| 7947 | os.Exit(1) |
| 7948 | } |
| 7949 | } |
| 7950 | |
| 7951 | if matched { |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 7952 | foundTest = true |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 7953 | testChan <- &testCases[i] |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7954 | } |
| 7955 | } |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 7956 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 7957 | if !foundTest { |
David Benjamin | 17e1292 | 2016-07-28 18:04:43 -0400 | [diff] [blame] | 7958 | fmt.Fprintf(os.Stderr, "No tests matched %q\n", *testToRun) |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 7959 | os.Exit(1) |
| 7960 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7961 | |
| 7962 | close(testChan) |
| 7963 | wg.Wait() |
| 7964 | close(statusChan) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7965 | testOutput := <-doneChan |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7966 | |
| 7967 | fmt.Printf("\n") |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7968 | |
| 7969 | if *jsonOutput != "" { |
| 7970 | if err := testOutput.writeTo(*jsonOutput); err != nil { |
| 7971 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 7972 | } |
| 7973 | } |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 7974 | |
EKR | 842ae6c | 2016-07-27 09:22:05 +0200 | [diff] [blame] | 7975 | if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 { |
| 7976 | os.Exit(1) |
| 7977 | } |
| 7978 | |
| 7979 | if !testOutput.noneFailed { |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 7980 | os.Exit(1) |
| 7981 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7982 | } |