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 |
| 13 | // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 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" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 24 | "flag" |
| 25 | "fmt" |
| 26 | "io" |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 27 | "io/ioutil" |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 28 | "math/big" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 29 | "net" |
| 30 | "os" |
| 31 | "os/exec" |
David Benjamin | 884fdf1 | 2014-08-02 15:28:23 -0400 | [diff] [blame] | 32 | "path" |
David Benjamin | 2bc8e6f | 2014-08-02 15:22:37 -0400 | [diff] [blame] | 33 | "runtime" |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 34 | "strconv" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 35 | "strings" |
| 36 | "sync" |
| 37 | "syscall" |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 38 | "time" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 39 | ) |
| 40 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 41 | var ( |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 42 | useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind") |
| 43 | useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb") |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 44 | useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb") |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 45 | flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection") |
| 46 | mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.") |
| 47 | 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.") |
| 48 | jsonOutput = flag.String("json-output", "", "The file to output JSON results to.") |
| 49 | pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.") |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 50 | testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests") |
| 51 | numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.") |
| 52 | shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.") |
| 53 | resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.") |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 54 | fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.") |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 55 | transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.") |
David Benjamin | 01784b4 | 2016-06-07 18:00:52 -0400 | [diff] [blame] | 56 | idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.") |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 57 | deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 58 | ) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 59 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 60 | type testCert int |
| 61 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 62 | const ( |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 63 | testCertRSA testCert = iota |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 64 | testCertRSA1024 |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 65 | testCertECDSAP256 |
| 66 | testCertECDSAP384 |
| 67 | testCertECDSAP521 |
| 68 | ) |
| 69 | |
| 70 | const ( |
| 71 | rsaCertificateFile = "cert.pem" |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 72 | rsa1024CertificateFile = "rsa_1024_cert.pem" |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 73 | ecdsaP256CertificateFile = "ecdsa_p256_cert.pem" |
| 74 | ecdsaP384CertificateFile = "ecdsa_p384_cert.pem" |
| 75 | ecdsaP521CertificateFile = "ecdsa_p521_cert.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 76 | ) |
| 77 | |
| 78 | const ( |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 79 | rsaKeyFile = "key.pem" |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 80 | rsa1024KeyFile = "rsa_1024_key.pem" |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 81 | ecdsaP256KeyFile = "ecdsa_p256_key.pem" |
| 82 | ecdsaP384KeyFile = "ecdsa_p384_key.pem" |
| 83 | ecdsaP521KeyFile = "ecdsa_p521_key.pem" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 84 | channelIDKeyFile = "channel_id_key.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 85 | ) |
| 86 | |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 87 | var ( |
| 88 | rsaCertificate Certificate |
| 89 | rsa1024Certificate Certificate |
| 90 | ecdsaP256Certificate Certificate |
| 91 | ecdsaP384Certificate Certificate |
| 92 | ecdsaP521Certificate Certificate |
| 93 | ) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 94 | |
| 95 | var testCerts = []struct { |
| 96 | id testCert |
| 97 | certFile, keyFile string |
| 98 | cert *Certificate |
| 99 | }{ |
| 100 | { |
| 101 | id: testCertRSA, |
| 102 | certFile: rsaCertificateFile, |
| 103 | keyFile: rsaKeyFile, |
| 104 | cert: &rsaCertificate, |
| 105 | }, |
| 106 | { |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 107 | id: testCertRSA1024, |
| 108 | certFile: rsa1024CertificateFile, |
| 109 | keyFile: rsa1024KeyFile, |
| 110 | cert: &rsa1024Certificate, |
| 111 | }, |
| 112 | { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 113 | id: testCertECDSAP256, |
| 114 | certFile: ecdsaP256CertificateFile, |
| 115 | keyFile: ecdsaP256KeyFile, |
| 116 | cert: &ecdsaP256Certificate, |
| 117 | }, |
| 118 | { |
| 119 | id: testCertECDSAP384, |
| 120 | certFile: ecdsaP384CertificateFile, |
| 121 | keyFile: ecdsaP384KeyFile, |
| 122 | cert: &ecdsaP384Certificate, |
| 123 | }, |
| 124 | { |
| 125 | id: testCertECDSAP521, |
| 126 | certFile: ecdsaP521CertificateFile, |
| 127 | keyFile: ecdsaP521KeyFile, |
| 128 | cert: &ecdsaP521Certificate, |
| 129 | }, |
| 130 | } |
| 131 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 132 | var channelIDKey *ecdsa.PrivateKey |
| 133 | var channelIDBytes []byte |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 134 | |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 135 | var testOCSPResponse = []byte{1, 2, 3, 4} |
| 136 | var testSCTList = []byte{5, 6, 7, 8} |
| 137 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 138 | func initCertificates() { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 139 | for i := range testCerts { |
| 140 | cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile)) |
| 141 | if err != nil { |
| 142 | panic(err) |
| 143 | } |
| 144 | cert.OCSPStaple = testOCSPResponse |
| 145 | cert.SignedCertificateTimestampList = testSCTList |
| 146 | *testCerts[i].cert = cert |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 147 | } |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 148 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 149 | channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile)) |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 150 | if err != nil { |
| 151 | panic(err) |
| 152 | } |
| 153 | channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock) |
| 154 | if channelIDDERBlock.Type != "EC PRIVATE KEY" { |
| 155 | panic("bad key type") |
| 156 | } |
| 157 | channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes) |
| 158 | if err != nil { |
| 159 | panic(err) |
| 160 | } |
| 161 | if channelIDKey.Curve != elliptic.P256() { |
| 162 | panic("bad curve") |
| 163 | } |
| 164 | |
| 165 | channelIDBytes = make([]byte, 64) |
| 166 | writeIntPadded(channelIDBytes[:32], channelIDKey.X) |
| 167 | writeIntPadded(channelIDBytes[32:], channelIDKey.Y) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 168 | } |
| 169 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 170 | func getRunnerCertificate(t testCert) Certificate { |
| 171 | for _, cert := range testCerts { |
| 172 | if cert.id == t { |
| 173 | return *cert.cert |
| 174 | } |
| 175 | } |
| 176 | panic("Unknown test certificate") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 177 | } |
| 178 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 179 | func getShimCertificate(t testCert) string { |
| 180 | for _, cert := range testCerts { |
| 181 | if cert.id == t { |
| 182 | return cert.certFile |
| 183 | } |
| 184 | } |
| 185 | panic("Unknown test certificate") |
| 186 | } |
| 187 | |
| 188 | func getShimKey(t testCert) string { |
| 189 | for _, cert := range testCerts { |
| 190 | if cert.id == t { |
| 191 | return cert.keyFile |
| 192 | } |
| 193 | } |
| 194 | panic("Unknown test certificate") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 195 | } |
| 196 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 197 | type testType int |
| 198 | |
| 199 | const ( |
| 200 | clientTest testType = iota |
| 201 | serverTest |
| 202 | ) |
| 203 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 204 | type protocol int |
| 205 | |
| 206 | const ( |
| 207 | tls protocol = iota |
| 208 | dtls |
| 209 | ) |
| 210 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 211 | const ( |
| 212 | alpn = 1 |
| 213 | npn = 2 |
| 214 | ) |
| 215 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 216 | type testCase struct { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 217 | testType testType |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 218 | protocol protocol |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 219 | name string |
| 220 | config Config |
| 221 | shouldFail bool |
| 222 | expectedError string |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 223 | // expectedLocalError, if not empty, contains a substring that must be |
| 224 | // found in the local error. |
| 225 | expectedLocalError string |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 226 | // expectedVersion, if non-zero, specifies the TLS version that must be |
| 227 | // negotiated. |
| 228 | expectedVersion uint16 |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 229 | // expectedResumeVersion, if non-zero, specifies the TLS version that |
| 230 | // must be negotiated on resumption. If zero, expectedVersion is used. |
| 231 | expectedResumeVersion uint16 |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 232 | // expectedCipher, if non-zero, specifies the TLS cipher suite that |
| 233 | // should be negotiated. |
| 234 | expectedCipher uint16 |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 235 | // expectChannelID controls whether the connection should have |
| 236 | // negotiated a Channel ID with channelIDKey. |
| 237 | expectChannelID bool |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 238 | // expectedNextProto controls whether the connection should |
| 239 | // negotiate a next protocol via NPN or ALPN. |
| 240 | expectedNextProto string |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 241 | // expectNoNextProto, if true, means that no next protocol should be |
| 242 | // negotiated. |
| 243 | expectNoNextProto bool |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 244 | // expectedNextProtoType, if non-zero, is the expected next |
| 245 | // protocol negotiation mechanism. |
| 246 | expectedNextProtoType int |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 247 | // expectedSRTPProtectionProfile is the DTLS-SRTP profile that |
| 248 | // should be negotiated. If zero, none should be negotiated. |
| 249 | expectedSRTPProtectionProfile uint16 |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 250 | // expectedOCSPResponse, if not nil, is the expected OCSP response to be received. |
| 251 | expectedOCSPResponse []uint8 |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 252 | // expectedSCTList, if not nil, is the expected SCT list to be received. |
| 253 | expectedSCTList []uint8 |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 254 | // expectedPeerSignatureAlgorithm, if not zero, is the signature |
| 255 | // algorithm that the peer should have used in the handshake. |
| 256 | expectedPeerSignatureAlgorithm signatureAlgorithm |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 257 | // messageLen is the length, in bytes, of the test message that will be |
| 258 | // sent. |
| 259 | messageLen int |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 260 | // messageCount is the number of test messages that will be sent. |
| 261 | messageCount int |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 262 | // digestPrefs is the list of digest preferences from the client. |
| 263 | digestPrefs string |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 264 | // certFile is the path to the certificate to use for the server. |
| 265 | certFile string |
| 266 | // keyFile is the path to the private key to use for the server. |
| 267 | keyFile string |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 268 | // resumeSession controls whether a second connection should be tested |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 269 | // which attempts to resume the first session. |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 270 | resumeSession bool |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 271 | // expectResumeRejected, if true, specifies that the attempted |
| 272 | // resumption must be rejected by the client. This is only valid for a |
| 273 | // serverTest. |
| 274 | expectResumeRejected bool |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 275 | // resumeConfig, if not nil, points to a Config to be used on |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 276 | // resumption. Unless newSessionsOnResume is set, |
| 277 | // SessionTicketKey, ServerSessionCache, and |
| 278 | // ClientSessionCache are copied from the initial connection's |
| 279 | // config. If nil, the initial connection's config is used. |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 280 | resumeConfig *Config |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 281 | // newSessionsOnResume, if true, will cause resumeConfig to |
| 282 | // use a different session resumption context. |
| 283 | newSessionsOnResume bool |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 284 | // noSessionCache, if true, will cause the server to run without a |
| 285 | // session cache. |
| 286 | noSessionCache bool |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 287 | // sendPrefix sends a prefix on the socket before actually performing a |
| 288 | // handshake. |
| 289 | sendPrefix string |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 290 | // shimWritesFirst controls whether the shim sends an initial "hello" |
| 291 | // message before doing a roundtrip with the runner. |
| 292 | shimWritesFirst bool |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 293 | // shimShutsDown, if true, runs a test where the shim shuts down the |
| 294 | // connection immediately after the handshake rather than echoing |
| 295 | // messages from the runner. |
| 296 | shimShutsDown bool |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 297 | // renegotiate indicates the number of times the connection should be |
| 298 | // renegotiated during the exchange. |
| 299 | renegotiate int |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 300 | // renegotiateCiphers is a list of ciphersuite ids that will be |
| 301 | // switched in just before renegotiation. |
| 302 | renegotiateCiphers []uint16 |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 303 | // replayWrites, if true, configures the underlying transport |
| 304 | // to replay every write it makes in DTLS tests. |
| 305 | replayWrites bool |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 306 | // damageFirstWrite, if true, configures the underlying transport to |
| 307 | // damage the final byte of the first application data write. |
| 308 | damageFirstWrite bool |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 309 | // exportKeyingMaterial, if non-zero, configures the test to exchange |
| 310 | // keying material and verify they match. |
| 311 | exportKeyingMaterial int |
| 312 | exportLabel string |
| 313 | exportContext string |
| 314 | useExportContext bool |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 315 | // flags, if not empty, contains a list of command-line flags that will |
| 316 | // be passed to the shim program. |
| 317 | flags []string |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 318 | // testTLSUnique, if true, causes the shim to send the tls-unique value |
| 319 | // which will be compared against the expected value. |
| 320 | testTLSUnique bool |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 321 | // sendEmptyRecords is the number of consecutive empty records to send |
| 322 | // before and after the test message. |
| 323 | sendEmptyRecords int |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 324 | // sendWarningAlerts is the number of consecutive warning alerts to send |
| 325 | // before and after the test message. |
| 326 | sendWarningAlerts int |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 327 | // expectMessageDropped, if true, means the test message is expected to |
| 328 | // be dropped by the client rather than echoed back. |
| 329 | expectMessageDropped bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 332 | var testCases []testCase |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 333 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 334 | func writeTranscript(test *testCase, isResume bool, data []byte) { |
| 335 | if len(data) == 0 { |
| 336 | return |
| 337 | } |
| 338 | |
| 339 | protocol := "tls" |
| 340 | if test.protocol == dtls { |
| 341 | protocol = "dtls" |
| 342 | } |
| 343 | |
| 344 | side := "client" |
| 345 | if test.testType == serverTest { |
| 346 | side = "server" |
| 347 | } |
| 348 | |
| 349 | dir := path.Join(*transcriptDir, protocol, side) |
| 350 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 351 | fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err) |
| 352 | return |
| 353 | } |
| 354 | |
| 355 | name := test.name |
| 356 | if isResume { |
| 357 | name += "-Resume" |
| 358 | } else { |
| 359 | name += "-Normal" |
| 360 | } |
| 361 | |
| 362 | if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil { |
| 363 | fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err) |
| 364 | } |
| 365 | } |
| 366 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 367 | // A timeoutConn implements an idle timeout on each Read and Write operation. |
| 368 | type timeoutConn struct { |
| 369 | net.Conn |
| 370 | timeout time.Duration |
| 371 | } |
| 372 | |
| 373 | func (t *timeoutConn) Read(b []byte) (int, error) { |
| 374 | if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil { |
| 375 | return 0, err |
| 376 | } |
| 377 | return t.Conn.Read(b) |
| 378 | } |
| 379 | |
| 380 | func (t *timeoutConn) Write(b []byte) (int, error) { |
| 381 | if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil { |
| 382 | return 0, err |
| 383 | } |
| 384 | return t.Conn.Write(b) |
| 385 | } |
| 386 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 387 | func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error { |
David Benjamin | 01784b4 | 2016-06-07 18:00:52 -0400 | [diff] [blame] | 388 | conn = &timeoutConn{conn, *idleTimeout} |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 389 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 390 | if test.protocol == dtls { |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 391 | config.Bugs.PacketAdaptor = newPacketAdaptor(conn) |
| 392 | conn = config.Bugs.PacketAdaptor |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 393 | } |
| 394 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 395 | if *flagDebug || len(*transcriptDir) != 0 { |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 396 | local, peer := "client", "server" |
| 397 | if test.testType == clientTest { |
| 398 | local, peer = peer, local |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 399 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 400 | connDebug := &recordingConn{ |
| 401 | Conn: conn, |
| 402 | isDatagram: test.protocol == dtls, |
| 403 | local: local, |
| 404 | peer: peer, |
| 405 | } |
| 406 | conn = connDebug |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 407 | if *flagDebug { |
| 408 | defer connDebug.WriteTo(os.Stdout) |
| 409 | } |
| 410 | if len(*transcriptDir) != 0 { |
| 411 | defer func() { |
| 412 | writeTranscript(test, isResume, connDebug.Transcript()) |
| 413 | }() |
| 414 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 415 | |
| 416 | if config.Bugs.PacketAdaptor != nil { |
| 417 | config.Bugs.PacketAdaptor.debug = connDebug |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | if test.replayWrites { |
| 422 | conn = newReplayAdaptor(conn) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 423 | } |
| 424 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 425 | var connDamage *damageAdaptor |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 426 | if test.damageFirstWrite { |
| 427 | connDamage = newDamageAdaptor(conn) |
| 428 | conn = connDamage |
| 429 | } |
| 430 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 431 | if test.sendPrefix != "" { |
| 432 | if _, err := conn.Write([]byte(test.sendPrefix)); err != nil { |
| 433 | return err |
| 434 | } |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 435 | } |
| 436 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 437 | var tlsConn *Conn |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 438 | if test.testType == clientTest { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 439 | if test.protocol == dtls { |
| 440 | tlsConn = DTLSServer(conn, config) |
| 441 | } else { |
| 442 | tlsConn = Server(conn, config) |
| 443 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 444 | } else { |
| 445 | config.InsecureSkipVerify = true |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 446 | if test.protocol == dtls { |
| 447 | tlsConn = DTLSClient(conn, config) |
| 448 | } else { |
| 449 | tlsConn = Client(conn, config) |
| 450 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 451 | } |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 452 | defer tlsConn.Close() |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 453 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 454 | if err := tlsConn.Handshake(); err != nil { |
| 455 | return err |
| 456 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 457 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 458 | // TODO(davidben): move all per-connection expectations into a dedicated |
| 459 | // expectations struct that can be specified separately for the two |
| 460 | // legs. |
| 461 | expectedVersion := test.expectedVersion |
| 462 | if isResume && test.expectedResumeVersion != 0 { |
| 463 | expectedVersion = test.expectedResumeVersion |
| 464 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 465 | connState := tlsConn.ConnectionState() |
| 466 | if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 467 | return fmt.Errorf("got version %x, expected %x", vers, expectedVersion) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 468 | } |
| 469 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 470 | if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher { |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 471 | return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher) |
| 472 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 473 | if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected { |
| 474 | return fmt.Errorf("didResume is %t, but we expected the opposite", didResume) |
| 475 | } |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 476 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 477 | if test.expectChannelID { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 478 | channelID := connState.ChannelID |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 479 | if channelID == nil { |
| 480 | return fmt.Errorf("no channel ID negotiated") |
| 481 | } |
| 482 | if channelID.Curve != channelIDKey.Curve || |
| 483 | channelIDKey.X.Cmp(channelIDKey.X) != 0 || |
| 484 | channelIDKey.Y.Cmp(channelIDKey.Y) != 0 { |
| 485 | return fmt.Errorf("incorrect channel ID") |
| 486 | } |
| 487 | } |
| 488 | |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 489 | if expected := test.expectedNextProto; expected != "" { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 490 | if actual := connState.NegotiatedProtocol; actual != expected { |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 491 | return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected) |
| 492 | } |
| 493 | } |
| 494 | |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 495 | if test.expectNoNextProto { |
| 496 | if actual := connState.NegotiatedProtocol; actual != "" { |
| 497 | return fmt.Errorf("got unexpected next proto %s", actual) |
| 498 | } |
| 499 | } |
| 500 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 501 | if test.expectedNextProtoType != 0 { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 502 | if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN { |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 503 | return fmt.Errorf("next proto type mismatch") |
| 504 | } |
| 505 | } |
| 506 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 507 | if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile { |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 508 | return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile) |
| 509 | } |
| 510 | |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 511 | if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) { |
| 512 | return fmt.Errorf("OCSP Response mismatch") |
| 513 | } |
| 514 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 515 | if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) { |
| 516 | return fmt.Errorf("SCT list mismatch") |
| 517 | } |
| 518 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 519 | if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm { |
| 520 | 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] | 521 | } |
| 522 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 523 | if test.exportKeyingMaterial > 0 { |
| 524 | actual := make([]byte, test.exportKeyingMaterial) |
| 525 | if _, err := io.ReadFull(tlsConn, actual); err != nil { |
| 526 | return err |
| 527 | } |
| 528 | expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext) |
| 529 | if err != nil { |
| 530 | return err |
| 531 | } |
| 532 | if !bytes.Equal(actual, expected) { |
| 533 | return fmt.Errorf("keying material mismatch") |
| 534 | } |
| 535 | } |
| 536 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 537 | if test.testTLSUnique { |
| 538 | var peersValue [12]byte |
| 539 | if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil { |
| 540 | return err |
| 541 | } |
| 542 | expected := tlsConn.ConnectionState().TLSUnique |
| 543 | if !bytes.Equal(peersValue[:], expected) { |
| 544 | return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected) |
| 545 | } |
| 546 | } |
| 547 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 548 | if test.shimWritesFirst { |
| 549 | var buf [5]byte |
| 550 | _, err := io.ReadFull(tlsConn, buf[:]) |
| 551 | if err != nil { |
| 552 | return err |
| 553 | } |
| 554 | if string(buf[:]) != "hello" { |
| 555 | return fmt.Errorf("bad initial message") |
| 556 | } |
| 557 | } |
| 558 | |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 559 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 560 | tlsConn.Write(nil) |
| 561 | } |
| 562 | |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 563 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 564 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 565 | } |
| 566 | |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 567 | if test.renegotiate > 0 { |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 568 | if test.renegotiateCiphers != nil { |
| 569 | config.CipherSuites = test.renegotiateCiphers |
| 570 | } |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 571 | for i := 0; i < test.renegotiate; i++ { |
| 572 | if err := tlsConn.Renegotiate(); err != nil { |
| 573 | return err |
| 574 | } |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 575 | } |
| 576 | } else if test.renegotiateCiphers != nil { |
| 577 | panic("renegotiateCiphers without renegotiate") |
| 578 | } |
| 579 | |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 580 | if test.damageFirstWrite { |
| 581 | connDamage.setDamage(true) |
| 582 | tlsConn.Write([]byte("DAMAGED WRITE")) |
| 583 | connDamage.setDamage(false) |
| 584 | } |
| 585 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 586 | messageLen := test.messageLen |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 587 | if messageLen < 0 { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 588 | if test.protocol == dtls { |
| 589 | return fmt.Errorf("messageLen < 0 not supported for DTLS tests") |
| 590 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 591 | // Read until EOF. |
| 592 | _, err := io.Copy(ioutil.Discard, tlsConn) |
| 593 | return err |
| 594 | } |
David Benjamin | 4417d05 | 2015-04-05 04:17:25 -0400 | [diff] [blame] | 595 | if messageLen == 0 { |
| 596 | messageLen = 32 |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 597 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 598 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 599 | messageCount := test.messageCount |
| 600 | if messageCount == 0 { |
| 601 | messageCount = 1 |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 602 | } |
| 603 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 604 | for j := 0; j < messageCount; j++ { |
| 605 | testMessage := make([]byte, messageLen) |
| 606 | for i := range testMessage { |
| 607 | testMessage[i] = 0x42 ^ byte(j) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 608 | } |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 609 | tlsConn.Write(testMessage) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 610 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 611 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 612 | tlsConn.Write(nil) |
| 613 | } |
| 614 | |
| 615 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 616 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 617 | } |
| 618 | |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 619 | if test.shimShutsDown || test.expectMessageDropped { |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 620 | // The shim will not respond. |
| 621 | continue |
| 622 | } |
| 623 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 624 | buf := make([]byte, len(testMessage)) |
| 625 | if test.protocol == dtls { |
| 626 | bufTmp := make([]byte, len(buf)+1) |
| 627 | n, err := tlsConn.Read(bufTmp) |
| 628 | if err != nil { |
| 629 | return err |
| 630 | } |
| 631 | if n != len(buf) { |
| 632 | return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf)) |
| 633 | } |
| 634 | copy(buf, bufTmp) |
| 635 | } else { |
| 636 | _, err := io.ReadFull(tlsConn, buf) |
| 637 | if err != nil { |
| 638 | return err |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | for i, v := range buf { |
| 643 | if v != testMessage[i]^0xff { |
| 644 | return fmt.Errorf("bad reply contents at byte %d", i) |
| 645 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | |
| 649 | return nil |
| 650 | } |
| 651 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 652 | func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd { |
| 653 | valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"} |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 654 | if dbAttach { |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 655 | 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] | 656 | } |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 657 | valgrindArgs = append(valgrindArgs, path) |
| 658 | valgrindArgs = append(valgrindArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 659 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 660 | return exec.Command("valgrind", valgrindArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 661 | } |
| 662 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 663 | func gdbOf(path string, args ...string) *exec.Cmd { |
| 664 | xtermArgs := []string{"-e", "gdb", "--args"} |
| 665 | xtermArgs = append(xtermArgs, path) |
| 666 | xtermArgs = append(xtermArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 667 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 668 | return exec.Command("xterm", xtermArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 669 | } |
| 670 | |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 671 | func lldbOf(path string, args ...string) *exec.Cmd { |
| 672 | xtermArgs := []string{"-e", "lldb", "--"} |
| 673 | xtermArgs = append(xtermArgs, path) |
| 674 | xtermArgs = append(xtermArgs, args...) |
| 675 | |
| 676 | return exec.Command("xterm", xtermArgs...) |
| 677 | } |
| 678 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 679 | type moreMallocsError struct{} |
| 680 | |
| 681 | func (moreMallocsError) Error() string { |
| 682 | return "child process did not exhaust all allocation calls" |
| 683 | } |
| 684 | |
| 685 | var errMoreMallocs = moreMallocsError{} |
| 686 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 687 | // accept accepts a connection from listener, unless waitChan signals a process |
| 688 | // exit first. |
| 689 | func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) { |
| 690 | type connOrError struct { |
| 691 | conn net.Conn |
| 692 | err error |
| 693 | } |
| 694 | connChan := make(chan connOrError, 1) |
| 695 | go func() { |
| 696 | conn, err := listener.Accept() |
| 697 | connChan <- connOrError{conn, err} |
| 698 | close(connChan) |
| 699 | }() |
| 700 | select { |
| 701 | case result := <-connChan: |
| 702 | return result.conn, result.err |
| 703 | case childErr := <-waitChan: |
| 704 | waitChan <- childErr |
| 705 | return nil, fmt.Errorf("child exited early: %s", childErr) |
| 706 | } |
| 707 | } |
| 708 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 709 | func runTest(test *testCase, shimPath string, mallocNumToFail int64) error { |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 710 | if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) { |
| 711 | panic("Error expected without shouldFail in " + test.name) |
| 712 | } |
| 713 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 714 | if test.expectResumeRejected && !test.resumeSession { |
| 715 | panic("expectResumeRejected without resumeSession in " + test.name) |
| 716 | } |
| 717 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 718 | listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}}) |
| 719 | if err != nil { |
| 720 | panic(err) |
| 721 | } |
| 722 | defer func() { |
| 723 | if listener != nil { |
| 724 | listener.Close() |
| 725 | } |
| 726 | }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 727 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 728 | flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)} |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 729 | if test.testType == serverTest { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 730 | flags = append(flags, "-server") |
| 731 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 732 | flags = append(flags, "-key-file") |
| 733 | if test.keyFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 734 | flags = append(flags, path.Join(*resourceDir, rsaKeyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 735 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 736 | flags = append(flags, path.Join(*resourceDir, test.keyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | flags = append(flags, "-cert-file") |
| 740 | if test.certFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 741 | flags = append(flags, path.Join(*resourceDir, rsaCertificateFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 742 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 743 | flags = append(flags, path.Join(*resourceDir, test.certFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 744 | } |
| 745 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 746 | |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 747 | if test.digestPrefs != "" { |
| 748 | flags = append(flags, "-digest-prefs") |
| 749 | flags = append(flags, test.digestPrefs) |
| 750 | } |
| 751 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 752 | if test.protocol == dtls { |
| 753 | flags = append(flags, "-dtls") |
| 754 | } |
| 755 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 756 | if test.resumeSession { |
| 757 | flags = append(flags, "-resume") |
| 758 | } |
| 759 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 760 | if test.shimWritesFirst { |
| 761 | flags = append(flags, "-shim-writes-first") |
| 762 | } |
| 763 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 764 | if test.shimShutsDown { |
| 765 | flags = append(flags, "-shim-shuts-down") |
| 766 | } |
| 767 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 768 | if test.exportKeyingMaterial > 0 { |
| 769 | flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial)) |
| 770 | flags = append(flags, "-export-label", test.exportLabel) |
| 771 | flags = append(flags, "-export-context", test.exportContext) |
| 772 | if test.useExportContext { |
| 773 | flags = append(flags, "-use-export-context") |
| 774 | } |
| 775 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 776 | if test.expectResumeRejected { |
| 777 | flags = append(flags, "-expect-session-miss") |
| 778 | } |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 779 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 780 | if test.testTLSUnique { |
| 781 | flags = append(flags, "-tls-unique") |
| 782 | } |
| 783 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 784 | flags = append(flags, test.flags...) |
| 785 | |
| 786 | var shim *exec.Cmd |
| 787 | if *useValgrind { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 788 | shim = valgrindOf(false, shimPath, flags...) |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 789 | } else if *useGDB { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 790 | shim = gdbOf(shimPath, flags...) |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 791 | } else if *useLLDB { |
| 792 | shim = lldbOf(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 793 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 794 | shim = exec.Command(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 795 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 796 | shim.Stdin = os.Stdin |
| 797 | var stdoutBuf, stderrBuf bytes.Buffer |
| 798 | shim.Stdout = &stdoutBuf |
| 799 | shim.Stderr = &stderrBuf |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 800 | if mallocNumToFail >= 0 { |
David Benjamin | 9e128b0 | 2015-02-09 13:13:09 -0500 | [diff] [blame] | 801 | shim.Env = os.Environ() |
| 802 | 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] | 803 | if *mallocTestDebug { |
David Benjamin | 184494d | 2015-06-12 18:23:47 -0400 | [diff] [blame] | 804 | shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 805 | } |
| 806 | shim.Env = append(shim.Env, "_MALLOC_CHECK=1") |
| 807 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 808 | |
| 809 | if err := shim.Start(); err != nil { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 810 | panic(err) |
| 811 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 812 | waitChan := make(chan error, 1) |
| 813 | go func() { waitChan <- shim.Wait() }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 814 | |
| 815 | config := test.config |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 816 | if !test.noSessionCache { |
| 817 | config.ClientSessionCache = NewLRUClientSessionCache(1) |
| 818 | config.ServerSessionCache = NewLRUServerSessionCache(1) |
| 819 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 820 | if test.testType == clientTest { |
| 821 | if len(config.Certificates) == 0 { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 822 | config.Certificates = []Certificate{rsaCertificate} |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 823 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 824 | } else { |
| 825 | // Supply a ServerName to ensure a constant session cache key, |
| 826 | // rather than falling back to net.Conn.RemoteAddr. |
| 827 | if len(config.ServerName) == 0 { |
| 828 | config.ServerName = "test" |
| 829 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 830 | } |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 831 | if *fuzzer { |
| 832 | config.Bugs.NullAllCiphers = true |
| 833 | } |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 834 | if *deterministic { |
| 835 | config.Rand = &deterministicRand{} |
| 836 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 837 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 838 | conn, err := acceptOrWait(listener, waitChan) |
| 839 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 840 | err = doExchange(test, &config, conn, false /* not a resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 841 | conn.Close() |
| 842 | } |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 843 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 844 | if err == nil && test.resumeSession { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 845 | var resumeConfig Config |
| 846 | if test.resumeConfig != nil { |
| 847 | resumeConfig = *test.resumeConfig |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 848 | if len(resumeConfig.ServerName) == 0 { |
| 849 | resumeConfig.ServerName = config.ServerName |
| 850 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 851 | if len(resumeConfig.Certificates) == 0 { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 852 | resumeConfig.Certificates = []Certificate{rsaCertificate} |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 853 | } |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 854 | if test.newSessionsOnResume { |
| 855 | if !test.noSessionCache { |
| 856 | resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1) |
| 857 | resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1) |
| 858 | } |
| 859 | } else { |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 860 | resumeConfig.SessionTicketKey = config.SessionTicketKey |
| 861 | resumeConfig.ClientSessionCache = config.ClientSessionCache |
| 862 | resumeConfig.ServerSessionCache = config.ServerSessionCache |
| 863 | } |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 864 | if *fuzzer { |
| 865 | resumeConfig.Bugs.NullAllCiphers = true |
| 866 | } |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 867 | resumeConfig.Rand = config.Rand |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 868 | } else { |
| 869 | resumeConfig = config |
| 870 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 871 | var connResume net.Conn |
| 872 | connResume, err = acceptOrWait(listener, waitChan) |
| 873 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 874 | err = doExchange(test, &resumeConfig, connResume, true /* resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 875 | connResume.Close() |
| 876 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 877 | } |
| 878 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 879 | // Close the listener now. This is to avoid hangs should the shim try to |
| 880 | // open more connections than expected. |
| 881 | listener.Close() |
| 882 | listener = nil |
| 883 | |
| 884 | childErr := <-waitChan |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 885 | if exitError, ok := childErr.(*exec.ExitError); ok { |
| 886 | if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 { |
| 887 | return errMoreMallocs |
| 888 | } |
| 889 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 890 | |
David Benjamin | 9bea349 | 2016-03-02 10:59:16 -0500 | [diff] [blame] | 891 | // Account for Windows line endings. |
| 892 | stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1) |
| 893 | stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1) |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 894 | |
| 895 | // Separate the errors from the shim and those from tools like |
| 896 | // AddressSanitizer. |
| 897 | var extraStderr string |
| 898 | if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 { |
| 899 | stderr = stderrParts[0] |
| 900 | extraStderr = stderrParts[1] |
| 901 | } |
| 902 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 903 | failed := err != nil || childErr != nil |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 904 | correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError) |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 905 | localError := "none" |
| 906 | if err != nil { |
| 907 | localError = err.Error() |
| 908 | } |
| 909 | if len(test.expectedLocalError) != 0 { |
| 910 | correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError) |
| 911 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 912 | |
| 913 | if failed != test.shouldFail || failed && !correctFailure { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 914 | childError := "none" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 915 | if childErr != nil { |
| 916 | childError = childErr.Error() |
| 917 | } |
| 918 | |
| 919 | var msg string |
| 920 | switch { |
| 921 | case failed && !test.shouldFail: |
| 922 | msg = "unexpected failure" |
| 923 | case !failed && test.shouldFail: |
| 924 | msg = "unexpected success" |
| 925 | case failed && !correctFailure: |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 926 | msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 927 | default: |
| 928 | panic("internal error") |
| 929 | } |
| 930 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 931 | 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] | 932 | } |
| 933 | |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 934 | if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) { |
| 935 | return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | return nil |
| 939 | } |
| 940 | |
| 941 | var tlsVersions = []struct { |
| 942 | name string |
| 943 | version uint16 |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 944 | flag string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 945 | hasDTLS bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 946 | }{ |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 947 | {"SSL3", VersionSSL30, "-no-ssl3", false}, |
| 948 | {"TLS1", VersionTLS10, "-no-tls1", true}, |
| 949 | {"TLS11", VersionTLS11, "-no-tls11", false}, |
| 950 | {"TLS12", VersionTLS12, "-no-tls12", true}, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 951 | // TODO(nharper): Once we have a real implementation of TLS 1.3, update the name here. |
| 952 | {"FakeTLS13", VersionTLS13, "-no-tls13", false}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | var testCipherSuites = []struct { |
| 956 | name string |
| 957 | id uint16 |
| 958 | }{ |
| 959 | {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 960 | {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 961 | {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 962 | {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 963 | {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 964 | {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 965 | {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 966 | {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 967 | {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 968 | {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 969 | {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384}, |
| 970 | {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 971 | {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 972 | {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 973 | {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 974 | {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}, |
| 975 | {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 976 | {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 977 | {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 978 | {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 979 | {"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] | 980 | {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 981 | {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 982 | {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 983 | {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 984 | {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 985 | {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 986 | {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 987 | {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 988 | {"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] | 989 | {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA}, |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 990 | {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 991 | {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 992 | {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 993 | {"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] | 994 | {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 995 | {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA}, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 996 | {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 997 | {"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] | 998 | {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256}, |
Steven Valdez | 3084e7b | 2016-06-02 12:07:20 -0400 | [diff] [blame] | 999 | {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256}, |
| 1000 | {"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] | 1001 | {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1002 | {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1003 | {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA}, |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1004 | {"NULL-SHA", TLS_RSA_WITH_NULL_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1007 | func hasComponent(suiteName, component string) bool { |
| 1008 | return strings.Contains("-"+suiteName+"-", "-"+component+"-") |
| 1009 | } |
| 1010 | |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1011 | func isTLS12Only(suiteName string) bool { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1012 | return hasComponent(suiteName, "GCM") || |
| 1013 | hasComponent(suiteName, "SHA256") || |
David Benjamin | e9a80ff | 2015-04-07 00:46:46 -0400 | [diff] [blame] | 1014 | hasComponent(suiteName, "SHA384") || |
| 1015 | hasComponent(suiteName, "POLY1305") |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1016 | } |
| 1017 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1018 | func isTLS13Suite(suiteName string) bool { |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 1019 | // Only AEADs. |
| 1020 | if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") { |
| 1021 | return false |
| 1022 | } |
| 1023 | // No old CHACHA20_POLY1305. |
| 1024 | if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") { |
| 1025 | return false |
| 1026 | } |
| 1027 | // Must have ECDHE. |
| 1028 | // TODO(davidben,svaldez): Add pure PSK support. |
| 1029 | if !hasComponent(suiteName, "ECDHE") { |
| 1030 | return false |
| 1031 | } |
| 1032 | // TODO(davidben,svaldez): Add PSK support. |
| 1033 | if hasComponent(suiteName, "PSK") { |
| 1034 | return false |
| 1035 | } |
| 1036 | return true |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1039 | func isDTLSCipher(suiteName string) bool { |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1040 | return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL") |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1041 | } |
| 1042 | |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 1043 | func bigFromHex(hex string) *big.Int { |
| 1044 | ret, ok := new(big.Int).SetString(hex, 16) |
| 1045 | if !ok { |
| 1046 | panic("failed to parse hex number 0x" + hex) |
| 1047 | } |
| 1048 | return ret |
| 1049 | } |
| 1050 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1051 | func addBasicTests() { |
| 1052 | basicTests := []testCase{ |
| 1053 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1054 | name: "NoFallbackSCSV", |
| 1055 | config: Config{ |
| 1056 | Bugs: ProtocolBugs{ |
| 1057 | FailIfNotFallbackSCSV: true, |
| 1058 | }, |
| 1059 | }, |
| 1060 | shouldFail: true, |
| 1061 | expectedLocalError: "no fallback SCSV found", |
| 1062 | }, |
| 1063 | { |
| 1064 | name: "SendFallbackSCSV", |
| 1065 | config: Config{ |
| 1066 | Bugs: ProtocolBugs{ |
| 1067 | FailIfNotFallbackSCSV: true, |
| 1068 | }, |
| 1069 | }, |
| 1070 | flags: []string{"-fallback-scsv"}, |
| 1071 | }, |
| 1072 | { |
| 1073 | name: "ClientCertificateTypes", |
| 1074 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1075 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1076 | ClientAuth: RequestClientCert, |
| 1077 | ClientCertificateTypes: []byte{ |
| 1078 | CertTypeDSSSign, |
| 1079 | CertTypeRSASign, |
| 1080 | CertTypeECDSASign, |
| 1081 | }, |
| 1082 | }, |
| 1083 | flags: []string{ |
| 1084 | "-expect-certificate-types", |
| 1085 | base64.StdEncoding.EncodeToString([]byte{ |
| 1086 | CertTypeDSSSign, |
| 1087 | CertTypeRSASign, |
| 1088 | CertTypeECDSASign, |
| 1089 | }), |
| 1090 | }, |
| 1091 | }, |
| 1092 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1093 | name: "UnauthenticatedECDH", |
| 1094 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1095 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1096 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1097 | Bugs: ProtocolBugs{ |
| 1098 | UnauthenticatedECDH: true, |
| 1099 | }, |
| 1100 | }, |
| 1101 | shouldFail: true, |
| 1102 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1103 | }, |
| 1104 | { |
| 1105 | name: "SkipCertificateStatus", |
| 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 | SkipCertificateStatus: true, |
| 1111 | }, |
| 1112 | }, |
| 1113 | flags: []string{ |
| 1114 | "-enable-ocsp-stapling", |
| 1115 | }, |
| 1116 | }, |
| 1117 | { |
| 1118 | name: "SkipServerKeyExchange", |
| 1119 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1120 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1121 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1122 | Bugs: ProtocolBugs{ |
| 1123 | SkipServerKeyExchange: true, |
| 1124 | }, |
| 1125 | }, |
| 1126 | shouldFail: true, |
| 1127 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1128 | }, |
| 1129 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1130 | testType: serverTest, |
| 1131 | name: "Alert", |
| 1132 | config: Config{ |
| 1133 | Bugs: ProtocolBugs{ |
| 1134 | SendSpuriousAlert: alertRecordOverflow, |
| 1135 | }, |
| 1136 | }, |
| 1137 | shouldFail: true, |
| 1138 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1139 | }, |
| 1140 | { |
| 1141 | protocol: dtls, |
| 1142 | testType: serverTest, |
| 1143 | name: "Alert-DTLS", |
| 1144 | config: Config{ |
| 1145 | Bugs: ProtocolBugs{ |
| 1146 | SendSpuriousAlert: alertRecordOverflow, |
| 1147 | }, |
| 1148 | }, |
| 1149 | shouldFail: true, |
| 1150 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1151 | }, |
| 1152 | { |
| 1153 | testType: serverTest, |
| 1154 | name: "FragmentAlert", |
| 1155 | config: Config{ |
| 1156 | Bugs: ProtocolBugs{ |
| 1157 | FragmentAlert: true, |
| 1158 | SendSpuriousAlert: alertRecordOverflow, |
| 1159 | }, |
| 1160 | }, |
| 1161 | shouldFail: true, |
| 1162 | expectedError: ":BAD_ALERT:", |
| 1163 | }, |
| 1164 | { |
| 1165 | protocol: dtls, |
| 1166 | testType: serverTest, |
| 1167 | name: "FragmentAlert-DTLS", |
| 1168 | config: Config{ |
| 1169 | Bugs: ProtocolBugs{ |
| 1170 | FragmentAlert: true, |
| 1171 | SendSpuriousAlert: alertRecordOverflow, |
| 1172 | }, |
| 1173 | }, |
| 1174 | shouldFail: true, |
| 1175 | expectedError: ":BAD_ALERT:", |
| 1176 | }, |
| 1177 | { |
| 1178 | testType: serverTest, |
David Benjamin | 0d3a8c6 | 2016-03-11 22:25:18 -0500 | [diff] [blame] | 1179 | name: "DoubleAlert", |
| 1180 | config: Config{ |
| 1181 | Bugs: ProtocolBugs{ |
| 1182 | DoubleAlert: true, |
| 1183 | SendSpuriousAlert: alertRecordOverflow, |
| 1184 | }, |
| 1185 | }, |
| 1186 | shouldFail: true, |
| 1187 | expectedError: ":BAD_ALERT:", |
| 1188 | }, |
| 1189 | { |
| 1190 | protocol: dtls, |
| 1191 | testType: serverTest, |
| 1192 | name: "DoubleAlert-DTLS", |
| 1193 | config: Config{ |
| 1194 | Bugs: ProtocolBugs{ |
| 1195 | DoubleAlert: true, |
| 1196 | SendSpuriousAlert: alertRecordOverflow, |
| 1197 | }, |
| 1198 | }, |
| 1199 | shouldFail: true, |
| 1200 | expectedError: ":BAD_ALERT:", |
| 1201 | }, |
| 1202 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1203 | name: "SkipNewSessionTicket", |
| 1204 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1205 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1206 | Bugs: ProtocolBugs{ |
| 1207 | SkipNewSessionTicket: true, |
| 1208 | }, |
| 1209 | }, |
| 1210 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1211 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1212 | }, |
| 1213 | { |
| 1214 | testType: serverTest, |
| 1215 | name: "FallbackSCSV", |
| 1216 | config: Config{ |
| 1217 | MaxVersion: VersionTLS11, |
| 1218 | Bugs: ProtocolBugs{ |
| 1219 | SendFallbackSCSV: true, |
| 1220 | }, |
| 1221 | }, |
| 1222 | shouldFail: true, |
| 1223 | expectedError: ":INAPPROPRIATE_FALLBACK:", |
| 1224 | }, |
| 1225 | { |
| 1226 | testType: serverTest, |
| 1227 | name: "FallbackSCSV-VersionMatch", |
| 1228 | config: Config{ |
| 1229 | Bugs: ProtocolBugs{ |
| 1230 | SendFallbackSCSV: true, |
| 1231 | }, |
| 1232 | }, |
| 1233 | }, |
| 1234 | { |
| 1235 | testType: serverTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1236 | name: "FallbackSCSV-VersionMatch-TLS12", |
| 1237 | config: Config{ |
| 1238 | MaxVersion: VersionTLS12, |
| 1239 | Bugs: ProtocolBugs{ |
| 1240 | SendFallbackSCSV: true, |
| 1241 | }, |
| 1242 | }, |
| 1243 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 1244 | }, |
| 1245 | { |
| 1246 | testType: serverTest, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1247 | name: "FragmentedClientVersion", |
| 1248 | config: Config{ |
| 1249 | Bugs: ProtocolBugs{ |
| 1250 | MaxHandshakeRecordLength: 1, |
| 1251 | FragmentClientVersion: true, |
| 1252 | }, |
| 1253 | }, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1254 | expectedVersion: VersionTLS13, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1255 | }, |
| 1256 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1257 | testType: serverTest, |
| 1258 | name: "HttpGET", |
| 1259 | sendPrefix: "GET / HTTP/1.0\n", |
| 1260 | shouldFail: true, |
| 1261 | expectedError: ":HTTP_REQUEST:", |
| 1262 | }, |
| 1263 | { |
| 1264 | testType: serverTest, |
| 1265 | name: "HttpPOST", |
| 1266 | sendPrefix: "POST / HTTP/1.0\n", |
| 1267 | shouldFail: true, |
| 1268 | expectedError: ":HTTP_REQUEST:", |
| 1269 | }, |
| 1270 | { |
| 1271 | testType: serverTest, |
| 1272 | name: "HttpHEAD", |
| 1273 | sendPrefix: "HEAD / HTTP/1.0\n", |
| 1274 | shouldFail: true, |
| 1275 | expectedError: ":HTTP_REQUEST:", |
| 1276 | }, |
| 1277 | { |
| 1278 | testType: serverTest, |
| 1279 | name: "HttpPUT", |
| 1280 | sendPrefix: "PUT / HTTP/1.0\n", |
| 1281 | shouldFail: true, |
| 1282 | expectedError: ":HTTP_REQUEST:", |
| 1283 | }, |
| 1284 | { |
| 1285 | testType: serverTest, |
| 1286 | name: "HttpCONNECT", |
| 1287 | sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n", |
| 1288 | shouldFail: true, |
| 1289 | expectedError: ":HTTPS_PROXY_REQUEST:", |
| 1290 | }, |
| 1291 | { |
| 1292 | testType: serverTest, |
| 1293 | name: "Garbage", |
| 1294 | sendPrefix: "blah", |
| 1295 | shouldFail: true, |
David Benjamin | 97760d5 | 2015-07-24 23:02:49 -0400 | [diff] [blame] | 1296 | expectedError: ":WRONG_VERSION_NUMBER:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1297 | }, |
| 1298 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1299 | name: "RSAEphemeralKey", |
| 1300 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1301 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1302 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 1303 | Bugs: ProtocolBugs{ |
| 1304 | RSAEphemeralKey: true, |
| 1305 | }, |
| 1306 | }, |
| 1307 | shouldFail: true, |
| 1308 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1309 | }, |
| 1310 | { |
| 1311 | name: "DisableEverything", |
Steven Valdez | 4f94b1c | 2016-05-24 12:31:07 -0400 | [diff] [blame] | 1312 | flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1313 | shouldFail: true, |
| 1314 | expectedError: ":WRONG_SSL_VERSION:", |
| 1315 | }, |
| 1316 | { |
| 1317 | protocol: dtls, |
| 1318 | name: "DisableEverything-DTLS", |
| 1319 | flags: []string{"-no-tls12", "-no-tls1"}, |
| 1320 | shouldFail: true, |
| 1321 | expectedError: ":WRONG_SSL_VERSION:", |
| 1322 | }, |
| 1323 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1324 | protocol: dtls, |
| 1325 | testType: serverTest, |
| 1326 | name: "MTU", |
| 1327 | config: Config{ |
| 1328 | Bugs: ProtocolBugs{ |
| 1329 | MaxPacketLength: 256, |
| 1330 | }, |
| 1331 | }, |
| 1332 | flags: []string{"-mtu", "256"}, |
| 1333 | }, |
| 1334 | { |
| 1335 | protocol: dtls, |
| 1336 | testType: serverTest, |
| 1337 | name: "MTUExceeded", |
| 1338 | config: Config{ |
| 1339 | Bugs: ProtocolBugs{ |
| 1340 | MaxPacketLength: 255, |
| 1341 | }, |
| 1342 | }, |
| 1343 | flags: []string{"-mtu", "256"}, |
| 1344 | shouldFail: true, |
| 1345 | expectedLocalError: "dtls: exceeded maximum packet length", |
| 1346 | }, |
| 1347 | { |
| 1348 | name: "CertMismatchRSA", |
| 1349 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1350 | // TODO(davidben): Add a TLS 1.3 version of this test. |
| 1351 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1352 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1353 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1354 | Bugs: ProtocolBugs{ |
| 1355 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1356 | }, |
| 1357 | }, |
| 1358 | shouldFail: true, |
| 1359 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1360 | }, |
| 1361 | { |
| 1362 | name: "CertMismatchECDSA", |
| 1363 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1364 | // TODO(davidben): Add a TLS 1.3 version of this test. |
| 1365 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1366 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1367 | Certificates: []Certificate{rsaCertificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1368 | Bugs: ProtocolBugs{ |
| 1369 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1370 | }, |
| 1371 | }, |
| 1372 | shouldFail: true, |
| 1373 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1374 | }, |
| 1375 | { |
| 1376 | name: "EmptyCertificateList", |
| 1377 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1378 | // TODO(davidben): Add a TLS 1.3 version of this test. |
| 1379 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1380 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1381 | Bugs: ProtocolBugs{ |
| 1382 | EmptyCertificateList: true, |
| 1383 | }, |
| 1384 | }, |
| 1385 | shouldFail: true, |
| 1386 | expectedError: ":DECODE_ERROR:", |
| 1387 | }, |
| 1388 | { |
| 1389 | name: "TLSFatalBadPackets", |
| 1390 | damageFirstWrite: true, |
| 1391 | shouldFail: true, |
| 1392 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 1393 | }, |
| 1394 | { |
| 1395 | protocol: dtls, |
| 1396 | name: "DTLSIgnoreBadPackets", |
| 1397 | damageFirstWrite: true, |
| 1398 | }, |
| 1399 | { |
| 1400 | protocol: dtls, |
| 1401 | name: "DTLSIgnoreBadPackets-Async", |
| 1402 | damageFirstWrite: true, |
| 1403 | flags: []string{"-async"}, |
| 1404 | }, |
| 1405 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1406 | name: "AppDataBeforeHandshake", |
| 1407 | config: Config{ |
| 1408 | Bugs: ProtocolBugs{ |
| 1409 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1410 | }, |
| 1411 | }, |
| 1412 | shouldFail: true, |
| 1413 | expectedError: ":UNEXPECTED_RECORD:", |
| 1414 | }, |
| 1415 | { |
| 1416 | name: "AppDataBeforeHandshake-Empty", |
| 1417 | config: Config{ |
| 1418 | Bugs: ProtocolBugs{ |
| 1419 | AppDataBeforeHandshake: []byte{}, |
| 1420 | }, |
| 1421 | }, |
| 1422 | shouldFail: true, |
| 1423 | expectedError: ":UNEXPECTED_RECORD:", |
| 1424 | }, |
| 1425 | { |
| 1426 | protocol: dtls, |
| 1427 | name: "AppDataBeforeHandshake-DTLS", |
| 1428 | config: Config{ |
| 1429 | Bugs: ProtocolBugs{ |
| 1430 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1431 | }, |
| 1432 | }, |
| 1433 | shouldFail: true, |
| 1434 | expectedError: ":UNEXPECTED_RECORD:", |
| 1435 | }, |
| 1436 | { |
| 1437 | protocol: dtls, |
| 1438 | name: "AppDataBeforeHandshake-DTLS-Empty", |
| 1439 | config: Config{ |
| 1440 | Bugs: ProtocolBugs{ |
| 1441 | AppDataBeforeHandshake: []byte{}, |
| 1442 | }, |
| 1443 | }, |
| 1444 | shouldFail: true, |
| 1445 | expectedError: ":UNEXPECTED_RECORD:", |
| 1446 | }, |
| 1447 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1448 | name: "AppDataAfterChangeCipherSpec", |
| 1449 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1450 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1451 | Bugs: ProtocolBugs{ |
| 1452 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1453 | }, |
| 1454 | }, |
| 1455 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1456 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1457 | }, |
| 1458 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1459 | name: "AppDataAfterChangeCipherSpec-Empty", |
| 1460 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1461 | MaxVersion: VersionTLS12, |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1462 | Bugs: ProtocolBugs{ |
| 1463 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1464 | }, |
| 1465 | }, |
| 1466 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1467 | expectedError: ":UNEXPECTED_RECORD:", |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1468 | }, |
| 1469 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1470 | protocol: dtls, |
| 1471 | name: "AppDataAfterChangeCipherSpec-DTLS", |
| 1472 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1473 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1474 | Bugs: ProtocolBugs{ |
| 1475 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1476 | }, |
| 1477 | }, |
| 1478 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1479 | // application data. |
| 1480 | }, |
| 1481 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1482 | protocol: dtls, |
| 1483 | name: "AppDataAfterChangeCipherSpec-DTLS-Empty", |
| 1484 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1485 | MaxVersion: VersionTLS12, |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1486 | Bugs: ProtocolBugs{ |
| 1487 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1488 | }, |
| 1489 | }, |
| 1490 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1491 | // application data. |
| 1492 | }, |
| 1493 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1494 | name: "AlertAfterChangeCipherSpec", |
| 1495 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1496 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1497 | Bugs: ProtocolBugs{ |
| 1498 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1499 | }, |
| 1500 | }, |
| 1501 | shouldFail: true, |
| 1502 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1503 | }, |
| 1504 | { |
| 1505 | protocol: dtls, |
| 1506 | name: "AlertAfterChangeCipherSpec-DTLS", |
| 1507 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1508 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1509 | Bugs: ProtocolBugs{ |
| 1510 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1511 | }, |
| 1512 | }, |
| 1513 | shouldFail: true, |
| 1514 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1515 | }, |
| 1516 | { |
| 1517 | protocol: dtls, |
| 1518 | name: "ReorderHandshakeFragments-Small-DTLS", |
| 1519 | config: Config{ |
| 1520 | Bugs: ProtocolBugs{ |
| 1521 | ReorderHandshakeFragments: true, |
| 1522 | // Small enough that every handshake message is |
| 1523 | // fragmented. |
| 1524 | MaxHandshakeRecordLength: 2, |
| 1525 | }, |
| 1526 | }, |
| 1527 | }, |
| 1528 | { |
| 1529 | protocol: dtls, |
| 1530 | name: "ReorderHandshakeFragments-Large-DTLS", |
| 1531 | config: Config{ |
| 1532 | Bugs: ProtocolBugs{ |
| 1533 | ReorderHandshakeFragments: true, |
| 1534 | // Large enough that no handshake message is |
| 1535 | // fragmented. |
| 1536 | MaxHandshakeRecordLength: 2048, |
| 1537 | }, |
| 1538 | }, |
| 1539 | }, |
| 1540 | { |
| 1541 | protocol: dtls, |
| 1542 | name: "MixCompleteMessageWithFragments-DTLS", |
| 1543 | config: Config{ |
| 1544 | Bugs: ProtocolBugs{ |
| 1545 | ReorderHandshakeFragments: true, |
| 1546 | MixCompleteMessageWithFragments: true, |
| 1547 | MaxHandshakeRecordLength: 2, |
| 1548 | }, |
| 1549 | }, |
| 1550 | }, |
| 1551 | { |
| 1552 | name: "SendInvalidRecordType", |
| 1553 | config: Config{ |
| 1554 | Bugs: ProtocolBugs{ |
| 1555 | SendInvalidRecordType: true, |
| 1556 | }, |
| 1557 | }, |
| 1558 | shouldFail: true, |
| 1559 | expectedError: ":UNEXPECTED_RECORD:", |
| 1560 | }, |
| 1561 | { |
| 1562 | protocol: dtls, |
| 1563 | name: "SendInvalidRecordType-DTLS", |
| 1564 | config: Config{ |
| 1565 | Bugs: ProtocolBugs{ |
| 1566 | SendInvalidRecordType: true, |
| 1567 | }, |
| 1568 | }, |
| 1569 | shouldFail: true, |
| 1570 | expectedError: ":UNEXPECTED_RECORD:", |
| 1571 | }, |
| 1572 | { |
| 1573 | name: "FalseStart-SkipServerSecondLeg", |
| 1574 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1575 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1576 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1577 | NextProtos: []string{"foo"}, |
| 1578 | Bugs: ProtocolBugs{ |
| 1579 | SkipNewSessionTicket: true, |
| 1580 | SkipChangeCipherSpec: true, |
| 1581 | SkipFinished: true, |
| 1582 | ExpectFalseStart: true, |
| 1583 | }, |
| 1584 | }, |
| 1585 | flags: []string{ |
| 1586 | "-false-start", |
| 1587 | "-handshake-never-done", |
| 1588 | "-advertise-alpn", "\x03foo", |
| 1589 | }, |
| 1590 | shimWritesFirst: true, |
| 1591 | shouldFail: true, |
| 1592 | expectedError: ":UNEXPECTED_RECORD:", |
| 1593 | }, |
| 1594 | { |
| 1595 | name: "FalseStart-SkipServerSecondLeg-Implicit", |
| 1596 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1597 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1598 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1599 | NextProtos: []string{"foo"}, |
| 1600 | Bugs: ProtocolBugs{ |
| 1601 | SkipNewSessionTicket: true, |
| 1602 | SkipChangeCipherSpec: true, |
| 1603 | SkipFinished: true, |
| 1604 | }, |
| 1605 | }, |
| 1606 | flags: []string{ |
| 1607 | "-implicit-handshake", |
| 1608 | "-false-start", |
| 1609 | "-handshake-never-done", |
| 1610 | "-advertise-alpn", "\x03foo", |
| 1611 | }, |
| 1612 | shouldFail: true, |
| 1613 | expectedError: ":UNEXPECTED_RECORD:", |
| 1614 | }, |
| 1615 | { |
| 1616 | testType: serverTest, |
| 1617 | name: "FailEarlyCallback", |
| 1618 | flags: []string{"-fail-early-callback"}, |
| 1619 | shouldFail: true, |
| 1620 | expectedError: ":CONNECTION_REJECTED:", |
| 1621 | expectedLocalError: "remote error: access denied", |
| 1622 | }, |
| 1623 | { |
| 1624 | name: "WrongMessageType", |
| 1625 | config: Config{ |
David Benjamin | 1edae6b | 2016-07-13 16:58:23 -0400 | [diff] [blame] | 1626 | MaxVersion: VersionTLS12, |
| 1627 | Bugs: ProtocolBugs{ |
| 1628 | WrongCertificateMessageType: true, |
| 1629 | }, |
| 1630 | }, |
| 1631 | shouldFail: true, |
| 1632 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1633 | expectedLocalError: "remote error: unexpected message", |
| 1634 | }, |
| 1635 | { |
| 1636 | name: "WrongMessageType-TLS13", |
| 1637 | config: Config{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1638 | Bugs: ProtocolBugs{ |
| 1639 | WrongCertificateMessageType: true, |
| 1640 | }, |
| 1641 | }, |
| 1642 | shouldFail: true, |
| 1643 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1644 | expectedLocalError: "remote error: unexpected message", |
| 1645 | }, |
| 1646 | { |
| 1647 | protocol: dtls, |
| 1648 | name: "WrongMessageType-DTLS", |
| 1649 | config: Config{ |
| 1650 | Bugs: ProtocolBugs{ |
| 1651 | WrongCertificateMessageType: true, |
| 1652 | }, |
| 1653 | }, |
| 1654 | shouldFail: true, |
| 1655 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1656 | expectedLocalError: "remote error: unexpected message", |
| 1657 | }, |
| 1658 | { |
| 1659 | protocol: dtls, |
| 1660 | name: "FragmentMessageTypeMismatch-DTLS", |
| 1661 | config: Config{ |
| 1662 | Bugs: ProtocolBugs{ |
| 1663 | MaxHandshakeRecordLength: 2, |
| 1664 | FragmentMessageTypeMismatch: true, |
| 1665 | }, |
| 1666 | }, |
| 1667 | shouldFail: true, |
| 1668 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1669 | }, |
| 1670 | { |
| 1671 | protocol: dtls, |
| 1672 | name: "FragmentMessageLengthMismatch-DTLS", |
| 1673 | config: Config{ |
| 1674 | Bugs: ProtocolBugs{ |
| 1675 | MaxHandshakeRecordLength: 2, |
| 1676 | FragmentMessageLengthMismatch: true, |
| 1677 | }, |
| 1678 | }, |
| 1679 | shouldFail: true, |
| 1680 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1681 | }, |
| 1682 | { |
| 1683 | protocol: dtls, |
| 1684 | name: "SplitFragments-Header-DTLS", |
| 1685 | config: Config{ |
| 1686 | Bugs: ProtocolBugs{ |
| 1687 | SplitFragments: 2, |
| 1688 | }, |
| 1689 | }, |
| 1690 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1691 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1692 | }, |
| 1693 | { |
| 1694 | protocol: dtls, |
| 1695 | name: "SplitFragments-Boundary-DTLS", |
| 1696 | config: Config{ |
| 1697 | Bugs: ProtocolBugs{ |
| 1698 | SplitFragments: dtlsRecordHeaderLen, |
| 1699 | }, |
| 1700 | }, |
| 1701 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1702 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1703 | }, |
| 1704 | { |
| 1705 | protocol: dtls, |
| 1706 | name: "SplitFragments-Body-DTLS", |
| 1707 | config: Config{ |
| 1708 | Bugs: ProtocolBugs{ |
| 1709 | SplitFragments: dtlsRecordHeaderLen + 1, |
| 1710 | }, |
| 1711 | }, |
| 1712 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1713 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1714 | }, |
| 1715 | { |
| 1716 | protocol: dtls, |
| 1717 | name: "SendEmptyFragments-DTLS", |
| 1718 | config: Config{ |
| 1719 | Bugs: ProtocolBugs{ |
| 1720 | SendEmptyFragments: true, |
| 1721 | }, |
| 1722 | }, |
| 1723 | }, |
| 1724 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1725 | name: "BadFinished-Client", |
| 1726 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1727 | // TODO(davidben): Add a TLS 1.3 version of this. |
| 1728 | MaxVersion: VersionTLS12, |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1729 | Bugs: ProtocolBugs{ |
| 1730 | BadFinished: true, |
| 1731 | }, |
| 1732 | }, |
| 1733 | shouldFail: true, |
| 1734 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1735 | }, |
| 1736 | { |
| 1737 | testType: serverTest, |
| 1738 | name: "BadFinished-Server", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1739 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1740 | // TODO(davidben): Add a TLS 1.3 version of this. |
| 1741 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1742 | Bugs: ProtocolBugs{ |
| 1743 | BadFinished: true, |
| 1744 | }, |
| 1745 | }, |
| 1746 | shouldFail: true, |
| 1747 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1748 | }, |
| 1749 | { |
| 1750 | name: "FalseStart-BadFinished", |
| 1751 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1752 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1753 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1754 | NextProtos: []string{"foo"}, |
| 1755 | Bugs: ProtocolBugs{ |
| 1756 | BadFinished: true, |
| 1757 | ExpectFalseStart: true, |
| 1758 | }, |
| 1759 | }, |
| 1760 | flags: []string{ |
| 1761 | "-false-start", |
| 1762 | "-handshake-never-done", |
| 1763 | "-advertise-alpn", "\x03foo", |
| 1764 | }, |
| 1765 | shimWritesFirst: true, |
| 1766 | shouldFail: true, |
| 1767 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1768 | }, |
| 1769 | { |
| 1770 | name: "NoFalseStart-NoALPN", |
| 1771 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1772 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1773 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1774 | Bugs: ProtocolBugs{ |
| 1775 | ExpectFalseStart: true, |
| 1776 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1777 | }, |
| 1778 | }, |
| 1779 | flags: []string{ |
| 1780 | "-false-start", |
| 1781 | }, |
| 1782 | shimWritesFirst: true, |
| 1783 | shouldFail: true, |
| 1784 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1785 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1786 | }, |
| 1787 | { |
| 1788 | name: "NoFalseStart-NoAEAD", |
| 1789 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1790 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1791 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1792 | NextProtos: []string{"foo"}, |
| 1793 | Bugs: ProtocolBugs{ |
| 1794 | ExpectFalseStart: true, |
| 1795 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1796 | }, |
| 1797 | }, |
| 1798 | flags: []string{ |
| 1799 | "-false-start", |
| 1800 | "-advertise-alpn", "\x03foo", |
| 1801 | }, |
| 1802 | shimWritesFirst: true, |
| 1803 | shouldFail: true, |
| 1804 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1805 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1806 | }, |
| 1807 | { |
| 1808 | name: "NoFalseStart-RSA", |
| 1809 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1810 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1811 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1812 | NextProtos: []string{"foo"}, |
| 1813 | Bugs: ProtocolBugs{ |
| 1814 | ExpectFalseStart: true, |
| 1815 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1816 | }, |
| 1817 | }, |
| 1818 | flags: []string{ |
| 1819 | "-false-start", |
| 1820 | "-advertise-alpn", "\x03foo", |
| 1821 | }, |
| 1822 | shimWritesFirst: true, |
| 1823 | shouldFail: true, |
| 1824 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1825 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1826 | }, |
| 1827 | { |
| 1828 | name: "NoFalseStart-DHE_RSA", |
| 1829 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1830 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1831 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1832 | NextProtos: []string{"foo"}, |
| 1833 | Bugs: ProtocolBugs{ |
| 1834 | ExpectFalseStart: true, |
| 1835 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1836 | }, |
| 1837 | }, |
| 1838 | flags: []string{ |
| 1839 | "-false-start", |
| 1840 | "-advertise-alpn", "\x03foo", |
| 1841 | }, |
| 1842 | shimWritesFirst: true, |
| 1843 | shouldFail: true, |
| 1844 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1845 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1846 | }, |
| 1847 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1848 | protocol: dtls, |
| 1849 | name: "SendSplitAlert-Sync", |
| 1850 | config: Config{ |
| 1851 | Bugs: ProtocolBugs{ |
| 1852 | SendSplitAlert: true, |
| 1853 | }, |
| 1854 | }, |
| 1855 | }, |
| 1856 | { |
| 1857 | protocol: dtls, |
| 1858 | name: "SendSplitAlert-Async", |
| 1859 | config: Config{ |
| 1860 | Bugs: ProtocolBugs{ |
| 1861 | SendSplitAlert: true, |
| 1862 | }, |
| 1863 | }, |
| 1864 | flags: []string{"-async"}, |
| 1865 | }, |
| 1866 | { |
| 1867 | protocol: dtls, |
| 1868 | name: "PackDTLSHandshake", |
| 1869 | config: Config{ |
| 1870 | Bugs: ProtocolBugs{ |
| 1871 | MaxHandshakeRecordLength: 2, |
| 1872 | PackHandshakeFragments: 20, |
| 1873 | PackHandshakeRecords: 200, |
| 1874 | }, |
| 1875 | }, |
| 1876 | }, |
| 1877 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1878 | name: "SendEmptyRecords-Pass", |
| 1879 | sendEmptyRecords: 32, |
| 1880 | }, |
| 1881 | { |
| 1882 | name: "SendEmptyRecords", |
| 1883 | sendEmptyRecords: 33, |
| 1884 | shouldFail: true, |
| 1885 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1886 | }, |
| 1887 | { |
| 1888 | name: "SendEmptyRecords-Async", |
| 1889 | sendEmptyRecords: 33, |
| 1890 | flags: []string{"-async"}, |
| 1891 | shouldFail: true, |
| 1892 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1893 | }, |
| 1894 | { |
| 1895 | name: "SendWarningAlerts-Pass", |
| 1896 | sendWarningAlerts: 4, |
| 1897 | }, |
| 1898 | { |
| 1899 | protocol: dtls, |
| 1900 | name: "SendWarningAlerts-DTLS-Pass", |
| 1901 | sendWarningAlerts: 4, |
| 1902 | }, |
| 1903 | { |
| 1904 | name: "SendWarningAlerts", |
| 1905 | sendWarningAlerts: 5, |
| 1906 | shouldFail: true, |
| 1907 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 1908 | }, |
| 1909 | { |
| 1910 | name: "SendWarningAlerts-Async", |
| 1911 | sendWarningAlerts: 5, |
| 1912 | flags: []string{"-async"}, |
| 1913 | shouldFail: true, |
| 1914 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 1915 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 1916 | { |
| 1917 | name: "EmptySessionID", |
| 1918 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1919 | MaxVersion: VersionTLS12, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 1920 | SessionTicketsDisabled: true, |
| 1921 | }, |
| 1922 | noSessionCache: true, |
| 1923 | flags: []string{"-expect-no-session"}, |
| 1924 | }, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 1925 | { |
| 1926 | name: "Unclean-Shutdown", |
| 1927 | config: Config{ |
| 1928 | Bugs: ProtocolBugs{ |
| 1929 | NoCloseNotify: true, |
| 1930 | ExpectCloseNotify: true, |
| 1931 | }, |
| 1932 | }, |
| 1933 | shimShutsDown: true, |
| 1934 | flags: []string{"-check-close-notify"}, |
| 1935 | shouldFail: true, |
| 1936 | expectedError: "Unexpected SSL_shutdown result: -1 != 1", |
| 1937 | }, |
| 1938 | { |
| 1939 | name: "Unclean-Shutdown-Ignored", |
| 1940 | config: Config{ |
| 1941 | Bugs: ProtocolBugs{ |
| 1942 | NoCloseNotify: true, |
| 1943 | }, |
| 1944 | }, |
| 1945 | shimShutsDown: true, |
| 1946 | }, |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 1947 | { |
David Benjamin | fa214e4 | 2016-05-10 17:03:10 -0400 | [diff] [blame] | 1948 | name: "Unclean-Shutdown-Alert", |
| 1949 | config: Config{ |
| 1950 | Bugs: ProtocolBugs{ |
| 1951 | SendAlertOnShutdown: alertDecompressionFailure, |
| 1952 | ExpectCloseNotify: true, |
| 1953 | }, |
| 1954 | }, |
| 1955 | shimShutsDown: true, |
| 1956 | flags: []string{"-check-close-notify"}, |
| 1957 | shouldFail: true, |
| 1958 | expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:", |
| 1959 | }, |
| 1960 | { |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 1961 | name: "LargePlaintext", |
| 1962 | config: Config{ |
| 1963 | Bugs: ProtocolBugs{ |
| 1964 | SendLargeRecords: true, |
| 1965 | }, |
| 1966 | }, |
| 1967 | messageLen: maxPlaintext + 1, |
| 1968 | shouldFail: true, |
| 1969 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 1970 | }, |
| 1971 | { |
| 1972 | protocol: dtls, |
| 1973 | name: "LargePlaintext-DTLS", |
| 1974 | config: Config{ |
| 1975 | Bugs: ProtocolBugs{ |
| 1976 | SendLargeRecords: true, |
| 1977 | }, |
| 1978 | }, |
| 1979 | messageLen: maxPlaintext + 1, |
| 1980 | shouldFail: true, |
| 1981 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 1982 | }, |
| 1983 | { |
| 1984 | name: "LargeCiphertext", |
| 1985 | config: Config{ |
| 1986 | Bugs: ProtocolBugs{ |
| 1987 | SendLargeRecords: true, |
| 1988 | }, |
| 1989 | }, |
| 1990 | messageLen: maxPlaintext * 2, |
| 1991 | shouldFail: true, |
| 1992 | expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:", |
| 1993 | }, |
| 1994 | { |
| 1995 | protocol: dtls, |
| 1996 | name: "LargeCiphertext-DTLS", |
| 1997 | config: Config{ |
| 1998 | Bugs: ProtocolBugs{ |
| 1999 | SendLargeRecords: true, |
| 2000 | }, |
| 2001 | }, |
| 2002 | messageLen: maxPlaintext * 2, |
| 2003 | // Unlike the other four cases, DTLS drops records which |
| 2004 | // are invalid before authentication, so the connection |
| 2005 | // does not fail. |
| 2006 | expectMessageDropped: true, |
| 2007 | }, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2008 | { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2009 | // In TLS 1.2 and below, empty NewSessionTicket messages |
| 2010 | // mean the server changed its mind on sending a ticket. |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2011 | name: "SendEmptySessionTicket", |
| 2012 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2013 | MaxVersion: VersionTLS12, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2014 | Bugs: ProtocolBugs{ |
| 2015 | SendEmptySessionTicket: true, |
| 2016 | FailIfSessionOffered: true, |
| 2017 | }, |
| 2018 | }, |
| 2019 | flags: []string{"-expect-no-session"}, |
| 2020 | resumeSession: true, |
| 2021 | expectResumeRejected: true, |
| 2022 | }, |
David Benjamin | 99fdfb9 | 2015-11-02 12:11:35 -0500 | [diff] [blame] | 2023 | { |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2024 | name: "BadHelloRequest-1", |
| 2025 | renegotiate: 1, |
| 2026 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2027 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2028 | Bugs: ProtocolBugs{ |
| 2029 | BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1}, |
| 2030 | }, |
| 2031 | }, |
| 2032 | flags: []string{ |
| 2033 | "-renegotiate-freely", |
| 2034 | "-expect-total-renegotiations", "1", |
| 2035 | }, |
| 2036 | shouldFail: true, |
| 2037 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2038 | }, |
| 2039 | { |
| 2040 | name: "BadHelloRequest-2", |
| 2041 | renegotiate: 1, |
| 2042 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2043 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2044 | Bugs: ProtocolBugs{ |
| 2045 | BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0}, |
| 2046 | }, |
| 2047 | }, |
| 2048 | flags: []string{ |
| 2049 | "-renegotiate-freely", |
| 2050 | "-expect-total-renegotiations", "1", |
| 2051 | }, |
| 2052 | shouldFail: true, |
| 2053 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2054 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2055 | { |
| 2056 | testType: serverTest, |
| 2057 | name: "SupportTicketsWithSessionID", |
| 2058 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2059 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2060 | SessionTicketsDisabled: true, |
| 2061 | }, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2062 | resumeConfig: &Config{ |
| 2063 | MaxVersion: VersionTLS12, |
| 2064 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2065 | resumeSession: true, |
| 2066 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2067 | } |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2068 | testCases = append(testCases, basicTests...) |
| 2069 | } |
| 2070 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2071 | func addCipherSuiteTests() { |
| 2072 | for _, suite := range testCipherSuites { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2073 | const psk = "12345" |
| 2074 | const pskIdentity = "luggage combo" |
| 2075 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2076 | var cert Certificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2077 | var certFile string |
| 2078 | var keyFile string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2079 | if hasComponent(suite.name, "ECDSA") { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2080 | cert = ecdsaP256Certificate |
| 2081 | certFile = ecdsaP256CertificateFile |
| 2082 | keyFile = ecdsaP256KeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2083 | } else { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2084 | cert = rsaCertificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2085 | certFile = rsaCertificateFile |
| 2086 | keyFile = rsaKeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2089 | var flags []string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2090 | if hasComponent(suite.name, "PSK") { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2091 | flags = append(flags, |
| 2092 | "-psk", psk, |
| 2093 | "-psk-identity", pskIdentity) |
| 2094 | } |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 2095 | if hasComponent(suite.name, "NULL") { |
| 2096 | // NULL ciphers must be explicitly enabled. |
| 2097 | flags = append(flags, "-cipher", "DEFAULT:NULL-SHA") |
| 2098 | } |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 2099 | if hasComponent(suite.name, "CECPQ1") { |
| 2100 | // CECPQ1 ciphers must be explicitly enabled. |
| 2101 | flags = append(flags, "-cipher", "DEFAULT:kCECPQ1") |
| 2102 | } |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2103 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2104 | for _, ver := range tlsVersions { |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2105 | for _, protocol := range []protocol{tls, dtls} { |
| 2106 | var prefix string |
| 2107 | if protocol == dtls { |
| 2108 | if !ver.hasDTLS { |
| 2109 | continue |
| 2110 | } |
| 2111 | prefix = "D" |
| 2112 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2113 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2114 | var shouldServerFail, shouldClientFail bool |
| 2115 | if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 { |
| 2116 | // BoringSSL clients accept ECDHE on SSLv3, but |
| 2117 | // a BoringSSL server will never select it |
| 2118 | // because the extension is missing. |
| 2119 | shouldServerFail = true |
| 2120 | } |
| 2121 | if isTLS12Only(suite.name) && ver.version < VersionTLS12 { |
| 2122 | shouldClientFail = true |
| 2123 | shouldServerFail = true |
| 2124 | } |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 2125 | if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2126 | shouldClientFail = true |
| 2127 | shouldServerFail = true |
| 2128 | } |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2129 | if !isDTLSCipher(suite.name) && protocol == dtls { |
| 2130 | shouldClientFail = true |
| 2131 | shouldServerFail = true |
| 2132 | } |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 2133 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2134 | var expectedServerError, expectedClientError string |
| 2135 | if shouldServerFail { |
| 2136 | expectedServerError = ":NO_SHARED_CIPHER:" |
| 2137 | } |
| 2138 | if shouldClientFail { |
| 2139 | expectedClientError = ":WRONG_CIPHER_RETURNED:" |
| 2140 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2141 | |
David Benjamin | 9deb117 | 2016-07-13 17:13:49 -0400 | [diff] [blame] | 2142 | // TODO(davidben,svaldez): Implement resumption for TLS 1.3. |
| 2143 | resumeSession := ver.version < VersionTLS13 |
| 2144 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2145 | testCases = append(testCases, testCase{ |
| 2146 | testType: serverTest, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2147 | protocol: protocol, |
| 2148 | |
| 2149 | name: prefix + ver.name + "-" + suite.name + "-server", |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2150 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2151 | MinVersion: ver.version, |
| 2152 | MaxVersion: ver.version, |
| 2153 | CipherSuites: []uint16{suite.id}, |
| 2154 | Certificates: []Certificate{cert}, |
| 2155 | PreSharedKey: []byte(psk), |
| 2156 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2157 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2158 | EnableAllCiphers: shouldServerFail, |
| 2159 | IgnorePeerCipherPreferences: shouldServerFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2160 | }, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2161 | }, |
| 2162 | certFile: certFile, |
| 2163 | keyFile: keyFile, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2164 | flags: flags, |
David Benjamin | 9deb117 | 2016-07-13 17:13:49 -0400 | [diff] [blame] | 2165 | resumeSession: resumeSession, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2166 | shouldFail: shouldServerFail, |
| 2167 | expectedError: expectedServerError, |
| 2168 | }) |
| 2169 | |
| 2170 | testCases = append(testCases, testCase{ |
| 2171 | testType: clientTest, |
| 2172 | protocol: protocol, |
| 2173 | name: prefix + ver.name + "-" + suite.name + "-client", |
| 2174 | config: Config{ |
| 2175 | MinVersion: ver.version, |
| 2176 | MaxVersion: ver.version, |
| 2177 | CipherSuites: []uint16{suite.id}, |
| 2178 | Certificates: []Certificate{cert}, |
| 2179 | PreSharedKey: []byte(psk), |
| 2180 | PreSharedKeyIdentity: pskIdentity, |
| 2181 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2182 | EnableAllCiphers: shouldClientFail, |
| 2183 | IgnorePeerCipherPreferences: shouldClientFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2184 | }, |
| 2185 | }, |
| 2186 | flags: flags, |
David Benjamin | 9deb117 | 2016-07-13 17:13:49 -0400 | [diff] [blame] | 2187 | resumeSession: resumeSession, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2188 | shouldFail: shouldClientFail, |
| 2189 | expectedError: expectedClientError, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2190 | }) |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2191 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2192 | if !shouldClientFail { |
| 2193 | // Ensure the maximum record size is accepted. |
| 2194 | testCases = append(testCases, testCase{ |
| 2195 | name: prefix + ver.name + "-" + suite.name + "-LargeRecord", |
| 2196 | config: Config{ |
| 2197 | MinVersion: ver.version, |
| 2198 | MaxVersion: ver.version, |
| 2199 | CipherSuites: []uint16{suite.id}, |
| 2200 | Certificates: []Certificate{cert}, |
| 2201 | PreSharedKey: []byte(psk), |
| 2202 | PreSharedKeyIdentity: pskIdentity, |
| 2203 | }, |
| 2204 | flags: flags, |
| 2205 | messageLen: maxPlaintext, |
| 2206 | }) |
| 2207 | } |
| 2208 | } |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2209 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2210 | } |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2211 | |
| 2212 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2213 | name: "NoSharedCipher", |
| 2214 | config: Config{ |
| 2215 | // TODO(davidben): Add a TLS 1.3 version of this test. |
| 2216 | MaxVersion: VersionTLS12, |
| 2217 | CipherSuites: []uint16{}, |
| 2218 | }, |
| 2219 | shouldFail: true, |
| 2220 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2221 | }) |
| 2222 | |
| 2223 | testCases = append(testCases, testCase{ |
| 2224 | name: "UnsupportedCipherSuite", |
| 2225 | config: Config{ |
| 2226 | MaxVersion: VersionTLS12, |
| 2227 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2228 | Bugs: ProtocolBugs{ |
| 2229 | IgnorePeerCipherPreferences: true, |
| 2230 | }, |
| 2231 | }, |
| 2232 | flags: []string{"-cipher", "DEFAULT:!RC4"}, |
| 2233 | shouldFail: true, |
| 2234 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 2235 | }) |
| 2236 | |
| 2237 | testCases = append(testCases, testCase{ |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2238 | name: "WeakDH", |
| 2239 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2240 | MaxVersion: VersionTLS12, |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2241 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2242 | Bugs: ProtocolBugs{ |
| 2243 | // This is a 1023-bit prime number, generated |
| 2244 | // with: |
| 2245 | // openssl gendh 1023 | openssl asn1parse -i |
| 2246 | DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"), |
| 2247 | }, |
| 2248 | }, |
| 2249 | shouldFail: true, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2250 | expectedError: ":BAD_DH_P_LENGTH:", |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2251 | }) |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2252 | |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2253 | testCases = append(testCases, testCase{ |
| 2254 | name: "SillyDH", |
| 2255 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2256 | MaxVersion: VersionTLS12, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2257 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2258 | Bugs: ProtocolBugs{ |
| 2259 | // This is a 4097-bit prime number, generated |
| 2260 | // with: |
| 2261 | // openssl gendh 4097 | openssl asn1parse -i |
| 2262 | DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"), |
| 2263 | }, |
| 2264 | }, |
| 2265 | shouldFail: true, |
| 2266 | expectedError: ":DH_P_TOO_LONG:", |
| 2267 | }) |
| 2268 | |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2269 | // This test ensures that Diffie-Hellman public values are padded with |
| 2270 | // zeros so that they're the same length as the prime. This is to avoid |
| 2271 | // hitting a bug in yaSSL. |
| 2272 | testCases = append(testCases, testCase{ |
| 2273 | testType: serverTest, |
| 2274 | name: "DHPublicValuePadded", |
| 2275 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2276 | MaxVersion: VersionTLS12, |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2277 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2278 | Bugs: ProtocolBugs{ |
| 2279 | RequireDHPublicValueLen: (1025 + 7) / 8, |
| 2280 | }, |
| 2281 | }, |
| 2282 | flags: []string{"-use-sparse-dh-prime"}, |
| 2283 | }) |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2284 | |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2285 | // The server must be tolerant to bogus ciphers. |
| 2286 | const bogusCipher = 0x1234 |
| 2287 | testCases = append(testCases, testCase{ |
| 2288 | testType: serverTest, |
| 2289 | name: "UnknownCipher", |
| 2290 | config: Config{ |
| 2291 | CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2292 | }, |
| 2293 | }) |
| 2294 | |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2295 | // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS |
| 2296 | // 1.1 specific cipher suite settings. A server is setup with the given |
| 2297 | // cipher lists and then a connection is made for each member of |
| 2298 | // expectations. The cipher suite that the server selects must match |
| 2299 | // the specified one. |
| 2300 | var versionSpecificCiphersTest = []struct { |
| 2301 | ciphersDefault, ciphersTLS10, ciphersTLS11 string |
| 2302 | // expectations is a map from TLS version to cipher suite id. |
| 2303 | expectations map[uint16]uint16 |
| 2304 | }{ |
| 2305 | { |
| 2306 | // Test that the null case (where no version-specific ciphers are set) |
| 2307 | // works as expected. |
| 2308 | "RC4-SHA:AES128-SHA", // default ciphers |
| 2309 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2310 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2311 | map[uint16]uint16{ |
| 2312 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2313 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2314 | VersionTLS11: TLS_RSA_WITH_RC4_128_SHA, |
| 2315 | VersionTLS12: TLS_RSA_WITH_RC4_128_SHA, |
| 2316 | }, |
| 2317 | }, |
| 2318 | { |
| 2319 | // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different |
| 2320 | // cipher. |
| 2321 | "RC4-SHA:AES128-SHA", // default |
| 2322 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2323 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2324 | map[uint16]uint16{ |
| 2325 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2326 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2327 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2328 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2329 | }, |
| 2330 | }, |
| 2331 | { |
| 2332 | // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different |
| 2333 | // cipher. |
| 2334 | "RC4-SHA:AES128-SHA", // default |
| 2335 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2336 | "AES128-SHA", // these ciphers for TLS ≥ 1.1 |
| 2337 | map[uint16]uint16{ |
| 2338 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2339 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2340 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2341 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2342 | }, |
| 2343 | }, |
| 2344 | { |
| 2345 | // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should |
| 2346 | // mask ciphers_tls10 for TLS 1.1 and 1.2. |
| 2347 | "RC4-SHA:AES128-SHA", // default |
| 2348 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2349 | "AES256-SHA", // these ciphers for TLS ≥ 1.1 |
| 2350 | map[uint16]uint16{ |
| 2351 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2352 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2353 | VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2354 | VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2355 | }, |
| 2356 | }, |
| 2357 | } |
| 2358 | |
| 2359 | for i, test := range versionSpecificCiphersTest { |
| 2360 | for version, expectedCipherSuite := range test.expectations { |
| 2361 | flags := []string{"-cipher", test.ciphersDefault} |
| 2362 | if len(test.ciphersTLS10) > 0 { |
| 2363 | flags = append(flags, "-cipher-tls10", test.ciphersTLS10) |
| 2364 | } |
| 2365 | if len(test.ciphersTLS11) > 0 { |
| 2366 | flags = append(flags, "-cipher-tls11", test.ciphersTLS11) |
| 2367 | } |
| 2368 | |
| 2369 | testCases = append(testCases, testCase{ |
| 2370 | testType: serverTest, |
| 2371 | name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version), |
| 2372 | config: Config{ |
| 2373 | MaxVersion: version, |
| 2374 | MinVersion: version, |
| 2375 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA}, |
| 2376 | }, |
| 2377 | flags: flags, |
| 2378 | expectedCipher: expectedCipherSuite, |
| 2379 | }) |
| 2380 | } |
| 2381 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | func addBadECDSASignatureTests() { |
| 2385 | for badR := BadValue(1); badR < NumBadValues; badR++ { |
| 2386 | for badS := BadValue(1); badS < NumBadValues; badS++ { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2387 | testCases = append(testCases, testCase{ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2388 | name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS), |
| 2389 | config: Config{ |
| 2390 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2391 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2392 | Bugs: ProtocolBugs{ |
| 2393 | BadECDSAR: badR, |
| 2394 | BadECDSAS: badS, |
| 2395 | }, |
| 2396 | }, |
| 2397 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2398 | expectedError: ":BAD_SIGNATURE:", |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2399 | }) |
| 2400 | } |
| 2401 | } |
| 2402 | } |
| 2403 | |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2404 | func addCBCPaddingTests() { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2405 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2406 | name: "MaxCBCPadding", |
| 2407 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2408 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2409 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2410 | Bugs: ProtocolBugs{ |
| 2411 | MaxPadding: true, |
| 2412 | }, |
| 2413 | }, |
| 2414 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2415 | }) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2416 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2417 | name: "BadCBCPadding", |
| 2418 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2419 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2420 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2421 | Bugs: ProtocolBugs{ |
| 2422 | PaddingFirstByteBad: true, |
| 2423 | }, |
| 2424 | }, |
| 2425 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2426 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2427 | }) |
| 2428 | // OpenSSL previously had an issue where the first byte of padding in |
| 2429 | // 255 bytes of padding wasn't checked. |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2430 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2431 | name: "BadCBCPadding255", |
| 2432 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2433 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2434 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2435 | Bugs: ProtocolBugs{ |
| 2436 | MaxPadding: true, |
| 2437 | PaddingFirstByteBadIf255: true, |
| 2438 | }, |
| 2439 | }, |
| 2440 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2441 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2442 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2443 | }) |
| 2444 | } |
| 2445 | |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2446 | func addCBCSplittingTests() { |
| 2447 | testCases = append(testCases, testCase{ |
| 2448 | name: "CBCRecordSplitting", |
| 2449 | config: Config{ |
| 2450 | MaxVersion: VersionTLS10, |
| 2451 | MinVersion: VersionTLS10, |
| 2452 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2453 | }, |
David Benjamin | ac8302a | 2015-09-01 17:18:15 -0400 | [diff] [blame] | 2454 | messageLen: -1, // read until EOF |
| 2455 | resumeSession: true, |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2456 | flags: []string{ |
| 2457 | "-async", |
| 2458 | "-write-different-record-sizes", |
| 2459 | "-cbc-record-splitting", |
| 2460 | }, |
David Benjamin | a8e3e0e | 2014-08-06 22:11:10 -0400 | [diff] [blame] | 2461 | }) |
| 2462 | testCases = append(testCases, testCase{ |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2463 | name: "CBCRecordSplittingPartialWrite", |
| 2464 | config: Config{ |
| 2465 | MaxVersion: VersionTLS10, |
| 2466 | MinVersion: VersionTLS10, |
| 2467 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2468 | }, |
| 2469 | messageLen: -1, // read until EOF |
| 2470 | flags: []string{ |
| 2471 | "-async", |
| 2472 | "-write-different-record-sizes", |
| 2473 | "-cbc-record-splitting", |
| 2474 | "-partial-write", |
| 2475 | }, |
| 2476 | }) |
| 2477 | } |
| 2478 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2479 | func addClientAuthTests() { |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 2480 | // Add a dummy cert pool to stress certificate authority parsing. |
| 2481 | // TODO(davidben): Add tests that those values parse out correctly. |
| 2482 | certPool := x509.NewCertPool() |
| 2483 | cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0]) |
| 2484 | if err != nil { |
| 2485 | panic(err) |
| 2486 | } |
| 2487 | certPool.AddCert(cert) |
| 2488 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2489 | for _, ver := range tlsVersions { |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2490 | testCases = append(testCases, testCase{ |
| 2491 | testType: clientTest, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2492 | name: ver.name + "-Client-ClientAuth-RSA", |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2493 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2494 | MinVersion: ver.version, |
| 2495 | MaxVersion: ver.version, |
| 2496 | ClientAuth: RequireAnyClientCert, |
| 2497 | ClientCAs: certPool, |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2498 | }, |
| 2499 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2500 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2501 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2502 | }, |
| 2503 | }) |
| 2504 | testCases = append(testCases, testCase{ |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2505 | testType: serverTest, |
| 2506 | name: ver.name + "-Server-ClientAuth-RSA", |
| 2507 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2508 | MinVersion: ver.version, |
| 2509 | MaxVersion: ver.version, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2510 | Certificates: []Certificate{rsaCertificate}, |
| 2511 | }, |
| 2512 | flags: []string{"-require-any-client-certificate"}, |
| 2513 | }) |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2514 | if ver.version != VersionSSL30 { |
| 2515 | testCases = append(testCases, testCase{ |
| 2516 | testType: serverTest, |
| 2517 | name: ver.name + "-Server-ClientAuth-ECDSA", |
| 2518 | config: Config{ |
| 2519 | MinVersion: ver.version, |
| 2520 | MaxVersion: ver.version, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2521 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2522 | }, |
| 2523 | flags: []string{"-require-any-client-certificate"}, |
| 2524 | }) |
| 2525 | testCases = append(testCases, testCase{ |
| 2526 | testType: clientTest, |
| 2527 | name: ver.name + "-Client-ClientAuth-ECDSA", |
| 2528 | config: Config{ |
| 2529 | MinVersion: ver.version, |
| 2530 | MaxVersion: ver.version, |
| 2531 | ClientAuth: RequireAnyClientCert, |
| 2532 | ClientCAs: certPool, |
| 2533 | }, |
| 2534 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2535 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 2536 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2537 | }, |
| 2538 | }) |
| 2539 | } |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2540 | } |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2541 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2542 | // TODO(davidben): These tests will need TLS 1.3 versions when the |
| 2543 | // handshake is separate. |
| 2544 | |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2545 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2546 | name: "NoClientCertificate", |
| 2547 | config: Config{ |
| 2548 | MaxVersion: VersionTLS12, |
| 2549 | ClientAuth: RequireAnyClientCert, |
| 2550 | }, |
| 2551 | shouldFail: true, |
| 2552 | expectedLocalError: "client didn't provide a certificate", |
| 2553 | }) |
| 2554 | |
| 2555 | testCases = append(testCases, testCase{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2556 | testType: serverTest, |
| 2557 | name: "RequireAnyClientCertificate", |
| 2558 | config: Config{ |
| 2559 | MaxVersion: VersionTLS12, |
| 2560 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2561 | flags: []string{"-require-any-client-certificate"}, |
| 2562 | shouldFail: true, |
| 2563 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2564 | }) |
| 2565 | |
| 2566 | testCases = append(testCases, testCase{ |
| 2567 | testType: serverTest, |
David Benjamin | df28c3a | 2016-03-10 16:11:51 -0500 | [diff] [blame] | 2568 | name: "RequireAnyClientCertificate-SSL3", |
| 2569 | config: Config{ |
| 2570 | MaxVersion: VersionSSL30, |
| 2571 | }, |
| 2572 | flags: []string{"-require-any-client-certificate"}, |
| 2573 | shouldFail: true, |
| 2574 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2575 | }) |
| 2576 | |
| 2577 | testCases = append(testCases, testCase{ |
| 2578 | testType: serverTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2579 | name: "SkipClientCertificate", |
| 2580 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2581 | MaxVersion: VersionTLS12, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2582 | Bugs: ProtocolBugs{ |
| 2583 | SkipClientCertificate: true, |
| 2584 | }, |
| 2585 | }, |
| 2586 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2587 | flags: []string{"-verify-peer"}, |
| 2588 | shouldFail: true, |
David Benjamin | df28c3a | 2016-03-10 16:11:51 -0500 | [diff] [blame] | 2589 | expectedError: ":UNEXPECTED_MESSAGE:", |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2590 | }) |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2591 | |
| 2592 | // Client auth is only legal in certificate-based ciphers. |
| 2593 | testCases = append(testCases, testCase{ |
| 2594 | testType: clientTest, |
| 2595 | name: "ClientAuth-PSK", |
| 2596 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2597 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2598 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 2599 | PreSharedKey: []byte("secret"), |
| 2600 | ClientAuth: RequireAnyClientCert, |
| 2601 | }, |
| 2602 | flags: []string{ |
| 2603 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2604 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2605 | "-psk", "secret", |
| 2606 | }, |
| 2607 | shouldFail: true, |
| 2608 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2609 | }) |
| 2610 | testCases = append(testCases, testCase{ |
| 2611 | testType: clientTest, |
| 2612 | name: "ClientAuth-ECDHE_PSK", |
| 2613 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2614 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2615 | CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 2616 | PreSharedKey: []byte("secret"), |
| 2617 | ClientAuth: RequireAnyClientCert, |
| 2618 | }, |
| 2619 | flags: []string{ |
| 2620 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2621 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2622 | "-psk", "secret", |
| 2623 | }, |
| 2624 | shouldFail: true, |
| 2625 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2626 | }) |
David Benjamin | 2f8935d | 2016-07-13 19:47:39 -0400 | [diff] [blame] | 2627 | |
| 2628 | // Regression test for a bug where the client CA list, if explicitly |
| 2629 | // set to NULL, was mis-encoded. |
| 2630 | testCases = append(testCases, testCase{ |
| 2631 | testType: serverTest, |
| 2632 | name: "Null-Client-CA-List", |
| 2633 | config: Config{ |
| 2634 | MaxVersion: VersionTLS12, |
| 2635 | Certificates: []Certificate{rsaCertificate}, |
| 2636 | }, |
| 2637 | flags: []string{ |
| 2638 | "-require-any-client-certificate", |
| 2639 | "-use-null-client-ca-list", |
| 2640 | }, |
| 2641 | }) |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2642 | } |
| 2643 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2644 | func addExtendedMasterSecretTests() { |
| 2645 | const expectEMSFlag = "-expect-extended-master-secret" |
| 2646 | |
| 2647 | for _, with := range []bool{false, true} { |
| 2648 | prefix := "No" |
| 2649 | var flags []string |
| 2650 | if with { |
| 2651 | prefix = "" |
| 2652 | flags = []string{expectEMSFlag} |
| 2653 | } |
| 2654 | |
| 2655 | for _, isClient := range []bool{false, true} { |
| 2656 | suffix := "-Server" |
| 2657 | testType := serverTest |
| 2658 | if isClient { |
| 2659 | suffix = "-Client" |
| 2660 | testType = clientTest |
| 2661 | } |
| 2662 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2663 | // TODO(davidben): Once the new TLS 1.3 handshake is in, |
| 2664 | // test that the extension is irrelevant, but the API |
| 2665 | // acts as if it is enabled. |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2666 | for _, ver := range tlsVersions { |
| 2667 | test := testCase{ |
| 2668 | testType: testType, |
| 2669 | name: prefix + "ExtendedMasterSecret-" + ver.name + suffix, |
| 2670 | config: Config{ |
| 2671 | MinVersion: ver.version, |
| 2672 | MaxVersion: ver.version, |
| 2673 | Bugs: ProtocolBugs{ |
| 2674 | NoExtendedMasterSecret: !with, |
| 2675 | RequireExtendedMasterSecret: with, |
| 2676 | }, |
| 2677 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2678 | flags: flags, |
| 2679 | shouldFail: ver.version == VersionSSL30 && with, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2680 | } |
| 2681 | if test.shouldFail { |
| 2682 | test.expectedLocalError = "extended master secret required but not supported by peer" |
| 2683 | } |
| 2684 | testCases = append(testCases, test) |
| 2685 | } |
| 2686 | } |
| 2687 | } |
| 2688 | |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2689 | for _, isClient := range []bool{false, true} { |
| 2690 | for _, supportedInFirstConnection := range []bool{false, true} { |
| 2691 | for _, supportedInResumeConnection := range []bool{false, true} { |
| 2692 | boolToWord := func(b bool) string { |
| 2693 | if b { |
| 2694 | return "Yes" |
| 2695 | } |
| 2696 | return "No" |
| 2697 | } |
| 2698 | suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-" |
| 2699 | if isClient { |
| 2700 | suffix += "Client" |
| 2701 | } else { |
| 2702 | suffix += "Server" |
| 2703 | } |
| 2704 | |
| 2705 | supportedConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2706 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2707 | Bugs: ProtocolBugs{ |
| 2708 | RequireExtendedMasterSecret: true, |
| 2709 | }, |
| 2710 | } |
| 2711 | |
| 2712 | noSupportConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2713 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2714 | Bugs: ProtocolBugs{ |
| 2715 | NoExtendedMasterSecret: true, |
| 2716 | }, |
| 2717 | } |
| 2718 | |
| 2719 | test := testCase{ |
| 2720 | name: "ExtendedMasterSecret-" + suffix, |
| 2721 | resumeSession: true, |
| 2722 | } |
| 2723 | |
| 2724 | if !isClient { |
| 2725 | test.testType = serverTest |
| 2726 | } |
| 2727 | |
| 2728 | if supportedInFirstConnection { |
| 2729 | test.config = supportedConfig |
| 2730 | } else { |
| 2731 | test.config = noSupportConfig |
| 2732 | } |
| 2733 | |
| 2734 | if supportedInResumeConnection { |
| 2735 | test.resumeConfig = &supportedConfig |
| 2736 | } else { |
| 2737 | test.resumeConfig = &noSupportConfig |
| 2738 | } |
| 2739 | |
| 2740 | switch suffix { |
| 2741 | case "YesToYes-Client", "YesToYes-Server": |
| 2742 | // When a session is resumed, it should |
| 2743 | // still be aware that its master |
| 2744 | // secret was generated via EMS and |
| 2745 | // thus it's safe to use tls-unique. |
| 2746 | test.flags = []string{expectEMSFlag} |
| 2747 | case "NoToYes-Server": |
| 2748 | // If an original connection did not |
| 2749 | // contain EMS, but a resumption |
| 2750 | // handshake does, then a server should |
| 2751 | // not resume the session. |
| 2752 | test.expectResumeRejected = true |
| 2753 | case "YesToNo-Server": |
| 2754 | // Resuming an EMS session without the |
| 2755 | // EMS extension should cause the |
| 2756 | // server to abort the connection. |
| 2757 | test.shouldFail = true |
| 2758 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 2759 | case "NoToYes-Client": |
| 2760 | // A client should abort a connection |
| 2761 | // where the server resumed a non-EMS |
| 2762 | // session but echoed the EMS |
| 2763 | // extension. |
| 2764 | test.shouldFail = true |
| 2765 | test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:" |
| 2766 | case "YesToNo-Client": |
| 2767 | // A client should abort a connection |
| 2768 | // where the server didn't echo EMS |
| 2769 | // when the session used it. |
| 2770 | test.shouldFail = true |
| 2771 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 2772 | } |
| 2773 | |
| 2774 | testCases = append(testCases, test) |
| 2775 | } |
| 2776 | } |
| 2777 | } |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2778 | } |
| 2779 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 2780 | type stateMachineTestConfig struct { |
| 2781 | protocol protocol |
| 2782 | async bool |
| 2783 | splitHandshake, packHandshakeFlight bool |
| 2784 | } |
| 2785 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 2786 | // Adds tests that try to cover the range of the handshake state machine, under |
| 2787 | // various conditions. Some of these are redundant with other tests, but they |
| 2788 | // only cover the synchronous case. |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 2789 | func addAllStateMachineCoverageTests() { |
| 2790 | for _, async := range []bool{false, true} { |
| 2791 | for _, protocol := range []protocol{tls, dtls} { |
| 2792 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 2793 | protocol: protocol, |
| 2794 | async: async, |
| 2795 | }) |
| 2796 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 2797 | protocol: protocol, |
| 2798 | async: async, |
| 2799 | splitHandshake: true, |
| 2800 | }) |
| 2801 | if protocol == tls { |
| 2802 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 2803 | protocol: protocol, |
| 2804 | async: async, |
| 2805 | packHandshakeFlight: true, |
| 2806 | }) |
| 2807 | } |
| 2808 | } |
| 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | func addStateMachineCoverageTests(config stateMachineTestConfig) { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2813 | var tests []testCase |
| 2814 | |
| 2815 | // Basic handshake, with resumption. Client and server, |
| 2816 | // session ID and session ticket. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2817 | // |
| 2818 | // TODO(davidben): Add TLS 1.3 tests for all of its different handshake |
| 2819 | // shapes. |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2820 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2821 | name: "Basic-Client", |
| 2822 | config: Config{ |
| 2823 | MaxVersion: VersionTLS12, |
| 2824 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2825 | resumeSession: true, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2826 | // Ensure session tickets are used, not session IDs. |
| 2827 | noSessionCache: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2828 | }) |
| 2829 | tests = append(tests, testCase{ |
| 2830 | name: "Basic-Client-RenewTicket", |
| 2831 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2832 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2833 | Bugs: ProtocolBugs{ |
| 2834 | RenewTicketOnResume: true, |
| 2835 | }, |
| 2836 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 2837 | flags: []string{"-expect-ticket-renewal"}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2838 | resumeSession: true, |
| 2839 | }) |
| 2840 | tests = append(tests, testCase{ |
| 2841 | name: "Basic-Client-NoTicket", |
| 2842 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2843 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2844 | SessionTicketsDisabled: true, |
| 2845 | }, |
| 2846 | resumeSession: true, |
| 2847 | }) |
| 2848 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2849 | name: "Basic-Client-Implicit", |
| 2850 | config: Config{ |
| 2851 | MaxVersion: VersionTLS12, |
| 2852 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2853 | flags: []string{"-implicit-handshake"}, |
| 2854 | resumeSession: true, |
| 2855 | }) |
| 2856 | tests = append(tests, testCase{ |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2857 | testType: serverTest, |
| 2858 | name: "Basic-Server", |
| 2859 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2860 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2861 | Bugs: ProtocolBugs{ |
| 2862 | RequireSessionTickets: true, |
| 2863 | }, |
| 2864 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2865 | resumeSession: true, |
| 2866 | }) |
| 2867 | tests = append(tests, testCase{ |
| 2868 | testType: serverTest, |
| 2869 | name: "Basic-Server-NoTickets", |
| 2870 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2871 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2872 | SessionTicketsDisabled: true, |
| 2873 | }, |
| 2874 | resumeSession: true, |
| 2875 | }) |
| 2876 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2877 | testType: serverTest, |
| 2878 | name: "Basic-Server-Implicit", |
| 2879 | config: Config{ |
| 2880 | MaxVersion: VersionTLS12, |
| 2881 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2882 | flags: []string{"-implicit-handshake"}, |
| 2883 | resumeSession: true, |
| 2884 | }) |
| 2885 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2886 | testType: serverTest, |
| 2887 | name: "Basic-Server-EarlyCallback", |
| 2888 | config: Config{ |
| 2889 | MaxVersion: VersionTLS12, |
| 2890 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2891 | flags: []string{"-use-early-callback"}, |
| 2892 | resumeSession: true, |
| 2893 | }) |
| 2894 | |
| 2895 | // TLS client auth. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2896 | // |
| 2897 | // TODO(davidben): Add TLS 1.3 client auth tests. |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2898 | tests = append(tests, testCase{ |
| 2899 | testType: clientTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2900 | name: "ClientAuth-NoCertificate-Client", |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 2901 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2902 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 2903 | ClientAuth: RequestClientCert, |
| 2904 | }, |
| 2905 | }) |
| 2906 | tests = append(tests, testCase{ |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2907 | testType: serverTest, |
| 2908 | name: "ClientAuth-NoCertificate-Server", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2909 | config: Config{ |
| 2910 | MaxVersion: VersionTLS12, |
| 2911 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2912 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2913 | flags: []string{"-verify-peer"}, |
| 2914 | }) |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 2915 | if config.protocol == tls { |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2916 | tests = append(tests, testCase{ |
| 2917 | testType: clientTest, |
| 2918 | name: "ClientAuth-NoCertificate-Client-SSL3", |
| 2919 | config: Config{ |
| 2920 | MaxVersion: VersionSSL30, |
| 2921 | ClientAuth: RequestClientCert, |
| 2922 | }, |
| 2923 | }) |
| 2924 | tests = append(tests, testCase{ |
| 2925 | testType: serverTest, |
| 2926 | name: "ClientAuth-NoCertificate-Server-SSL3", |
| 2927 | config: Config{ |
| 2928 | MaxVersion: VersionSSL30, |
| 2929 | }, |
| 2930 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2931 | flags: []string{"-verify-peer"}, |
| 2932 | }) |
| 2933 | } |
| 2934 | tests = append(tests, testCase{ |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 2935 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 2936 | name: "ClientAuth-RSA-Client", |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2937 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2938 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2939 | ClientAuth: RequireAnyClientCert, |
| 2940 | }, |
| 2941 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2942 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2943 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2944 | }, |
| 2945 | }) |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 2946 | tests = append(tests, testCase{ |
| 2947 | testType: clientTest, |
| 2948 | name: "ClientAuth-ECDSA-Client", |
| 2949 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2950 | MaxVersion: VersionTLS12, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 2951 | ClientAuth: RequireAnyClientCert, |
| 2952 | }, |
| 2953 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2954 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 2955 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 2956 | }, |
| 2957 | }) |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 2958 | tests = append(tests, testCase{ |
| 2959 | testType: clientTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2960 | name: "ClientAuth-NoCertificate-OldCallback", |
| 2961 | config: Config{ |
| 2962 | MaxVersion: VersionTLS12, |
| 2963 | ClientAuth: RequestClientCert, |
| 2964 | }, |
| 2965 | flags: []string{"-use-old-client-cert-callback"}, |
| 2966 | }) |
| 2967 | tests = append(tests, testCase{ |
| 2968 | testType: clientTest, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 2969 | name: "ClientAuth-OldCallback", |
| 2970 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2971 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 2972 | ClientAuth: RequireAnyClientCert, |
| 2973 | }, |
| 2974 | flags: []string{ |
| 2975 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2976 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2977 | "-use-old-client-cert-callback", |
| 2978 | }, |
| 2979 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2980 | tests = append(tests, testCase{ |
| 2981 | testType: serverTest, |
| 2982 | name: "ClientAuth-Server", |
| 2983 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2984 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2985 | Certificates: []Certificate{rsaCertificate}, |
| 2986 | }, |
| 2987 | flags: []string{"-require-any-client-certificate"}, |
| 2988 | }) |
| 2989 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2990 | // Test each key exchange on the server side for async keys. |
| 2991 | // |
| 2992 | // TODO(davidben): Add TLS 1.3 versions of these. |
| 2993 | tests = append(tests, testCase{ |
| 2994 | testType: serverTest, |
| 2995 | name: "Basic-Server-RSA", |
| 2996 | config: Config{ |
| 2997 | MaxVersion: VersionTLS12, |
| 2998 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 2999 | }, |
| 3000 | flags: []string{ |
| 3001 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3002 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3003 | }, |
| 3004 | }) |
| 3005 | tests = append(tests, testCase{ |
| 3006 | testType: serverTest, |
| 3007 | name: "Basic-Server-ECDHE-RSA", |
| 3008 | config: Config{ |
| 3009 | MaxVersion: VersionTLS12, |
| 3010 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3011 | }, |
| 3012 | flags: []string{ |
| 3013 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3014 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3015 | }, |
| 3016 | }) |
| 3017 | tests = append(tests, testCase{ |
| 3018 | testType: serverTest, |
| 3019 | name: "Basic-Server-ECDHE-ECDSA", |
| 3020 | config: Config{ |
| 3021 | MaxVersion: VersionTLS12, |
| 3022 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 3023 | }, |
| 3024 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3025 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3026 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3027 | }, |
| 3028 | }) |
| 3029 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3030 | // No session ticket support; server doesn't send NewSessionTicket. |
| 3031 | tests = append(tests, testCase{ |
| 3032 | name: "SessionTicketsDisabled-Client", |
| 3033 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3034 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3035 | SessionTicketsDisabled: true, |
| 3036 | }, |
| 3037 | }) |
| 3038 | tests = append(tests, testCase{ |
| 3039 | testType: serverTest, |
| 3040 | name: "SessionTicketsDisabled-Server", |
| 3041 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3042 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3043 | SessionTicketsDisabled: true, |
| 3044 | }, |
| 3045 | }) |
| 3046 | |
| 3047 | // Skip ServerKeyExchange in PSK key exchange if there's no |
| 3048 | // identity hint. |
| 3049 | tests = append(tests, testCase{ |
| 3050 | name: "EmptyPSKHint-Client", |
| 3051 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3052 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3053 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3054 | PreSharedKey: []byte("secret"), |
| 3055 | }, |
| 3056 | flags: []string{"-psk", "secret"}, |
| 3057 | }) |
| 3058 | tests = append(tests, testCase{ |
| 3059 | testType: serverTest, |
| 3060 | name: "EmptyPSKHint-Server", |
| 3061 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3062 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3063 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3064 | PreSharedKey: []byte("secret"), |
| 3065 | }, |
| 3066 | flags: []string{"-psk", "secret"}, |
| 3067 | }) |
| 3068 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3069 | // OCSP stapling tests. |
| 3070 | // |
| 3071 | // TODO(davidben): Test the TLS 1.3 version of OCSP stapling. |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3072 | tests = append(tests, testCase{ |
| 3073 | testType: clientTest, |
| 3074 | name: "OCSPStapling-Client", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3075 | config: Config{ |
| 3076 | MaxVersion: VersionTLS12, |
| 3077 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3078 | flags: []string{ |
| 3079 | "-enable-ocsp-stapling", |
| 3080 | "-expect-ocsp-response", |
| 3081 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3082 | "-verify-peer", |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3083 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3084 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3085 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3086 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3087 | testType: serverTest, |
| 3088 | name: "OCSPStapling-Server", |
| 3089 | config: Config{ |
| 3090 | MaxVersion: VersionTLS12, |
| 3091 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3092 | expectedOCSPResponse: testOCSPResponse, |
| 3093 | flags: []string{ |
| 3094 | "-ocsp-response", |
| 3095 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3096 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3097 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3098 | }) |
| 3099 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3100 | // Certificate verification tests. |
| 3101 | // |
| 3102 | // TODO(davidben): Test the TLS 1.3 version. |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3103 | tests = append(tests, testCase{ |
| 3104 | testType: clientTest, |
| 3105 | name: "CertificateVerificationSucceed", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3106 | config: Config{ |
| 3107 | MaxVersion: VersionTLS12, |
| 3108 | }, |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3109 | flags: []string{ |
| 3110 | "-verify-peer", |
| 3111 | }, |
| 3112 | }) |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3113 | tests = append(tests, testCase{ |
| 3114 | testType: clientTest, |
| 3115 | name: "CertificateVerificationFail", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3116 | config: Config{ |
| 3117 | MaxVersion: VersionTLS12, |
| 3118 | }, |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3119 | flags: []string{ |
| 3120 | "-verify-fail", |
| 3121 | "-verify-peer", |
| 3122 | }, |
| 3123 | shouldFail: true, |
| 3124 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 3125 | }) |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3126 | tests = append(tests, testCase{ |
| 3127 | testType: clientTest, |
| 3128 | name: "CertificateVerificationSoftFail", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3129 | config: Config{ |
| 3130 | MaxVersion: VersionTLS12, |
| 3131 | }, |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3132 | flags: []string{ |
| 3133 | "-verify-fail", |
| 3134 | "-expect-verify-result", |
| 3135 | }, |
| 3136 | }) |
| 3137 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3138 | if config.protocol == tls { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3139 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3140 | name: "Renegotiate-Client", |
| 3141 | config: Config{ |
| 3142 | MaxVersion: VersionTLS12, |
| 3143 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 3144 | renegotiate: 1, |
| 3145 | flags: []string{ |
| 3146 | "-renegotiate-freely", |
| 3147 | "-expect-total-renegotiations", "1", |
| 3148 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3149 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3150 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3151 | // NPN on client and server; results in post-handshake message. |
| 3152 | tests = append(tests, testCase{ |
| 3153 | name: "NPN-Client", |
| 3154 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3155 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3156 | NextProtos: []string{"foo"}, |
| 3157 | }, |
| 3158 | flags: []string{"-select-next-proto", "foo"}, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3159 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3160 | expectedNextProto: "foo", |
| 3161 | expectedNextProtoType: npn, |
| 3162 | }) |
| 3163 | tests = append(tests, testCase{ |
| 3164 | testType: serverTest, |
| 3165 | name: "NPN-Server", |
| 3166 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3167 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3168 | NextProtos: []string{"bar"}, |
| 3169 | }, |
| 3170 | flags: []string{ |
| 3171 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3172 | "-expect-next-proto", "bar", |
| 3173 | }, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3174 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3175 | expectedNextProto: "bar", |
| 3176 | expectedNextProtoType: npn, |
| 3177 | }) |
| 3178 | |
| 3179 | // TODO(davidben): Add tests for when False Start doesn't trigger. |
| 3180 | |
| 3181 | // Client does False Start and negotiates NPN. |
| 3182 | tests = append(tests, testCase{ |
| 3183 | name: "FalseStart", |
| 3184 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3185 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3186 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3187 | NextProtos: []string{"foo"}, |
| 3188 | Bugs: ProtocolBugs{ |
| 3189 | ExpectFalseStart: true, |
| 3190 | }, |
| 3191 | }, |
| 3192 | flags: []string{ |
| 3193 | "-false-start", |
| 3194 | "-select-next-proto", "foo", |
| 3195 | }, |
| 3196 | shimWritesFirst: true, |
| 3197 | resumeSession: true, |
| 3198 | }) |
| 3199 | |
| 3200 | // Client does False Start and negotiates ALPN. |
| 3201 | tests = append(tests, testCase{ |
| 3202 | name: "FalseStart-ALPN", |
| 3203 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3204 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3205 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3206 | NextProtos: []string{"foo"}, |
| 3207 | Bugs: ProtocolBugs{ |
| 3208 | ExpectFalseStart: true, |
| 3209 | }, |
| 3210 | }, |
| 3211 | flags: []string{ |
| 3212 | "-false-start", |
| 3213 | "-advertise-alpn", "\x03foo", |
| 3214 | }, |
| 3215 | shimWritesFirst: true, |
| 3216 | resumeSession: true, |
| 3217 | }) |
| 3218 | |
| 3219 | // Client does False Start but doesn't explicitly call |
| 3220 | // SSL_connect. |
| 3221 | tests = append(tests, testCase{ |
| 3222 | name: "FalseStart-Implicit", |
| 3223 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3224 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3225 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3226 | NextProtos: []string{"foo"}, |
| 3227 | }, |
| 3228 | flags: []string{ |
| 3229 | "-implicit-handshake", |
| 3230 | "-false-start", |
| 3231 | "-advertise-alpn", "\x03foo", |
| 3232 | }, |
| 3233 | }) |
| 3234 | |
| 3235 | // False Start without session tickets. |
| 3236 | tests = append(tests, testCase{ |
| 3237 | name: "FalseStart-SessionTicketsDisabled", |
| 3238 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3239 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3240 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3241 | NextProtos: []string{"foo"}, |
| 3242 | SessionTicketsDisabled: true, |
| 3243 | Bugs: ProtocolBugs{ |
| 3244 | ExpectFalseStart: true, |
| 3245 | }, |
| 3246 | }, |
| 3247 | flags: []string{ |
| 3248 | "-false-start", |
| 3249 | "-select-next-proto", "foo", |
| 3250 | }, |
| 3251 | shimWritesFirst: true, |
| 3252 | }) |
| 3253 | |
Adam Langley | df759b5 | 2016-07-11 15:24:37 -0700 | [diff] [blame] | 3254 | tests = append(tests, testCase{ |
| 3255 | name: "FalseStart-CECPQ1", |
| 3256 | config: Config{ |
| 3257 | MaxVersion: VersionTLS12, |
| 3258 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 3259 | NextProtos: []string{"foo"}, |
| 3260 | Bugs: ProtocolBugs{ |
| 3261 | ExpectFalseStart: true, |
| 3262 | }, |
| 3263 | }, |
| 3264 | flags: []string{ |
| 3265 | "-false-start", |
| 3266 | "-cipher", "DEFAULT:kCECPQ1", |
| 3267 | "-select-next-proto", "foo", |
| 3268 | }, |
| 3269 | shimWritesFirst: true, |
| 3270 | resumeSession: true, |
| 3271 | }) |
| 3272 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3273 | // Server parses a V2ClientHello. |
| 3274 | tests = append(tests, testCase{ |
| 3275 | testType: serverTest, |
| 3276 | name: "SendV2ClientHello", |
| 3277 | config: Config{ |
| 3278 | // Choose a cipher suite that does not involve |
| 3279 | // elliptic curves, so no extensions are |
| 3280 | // involved. |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3281 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3282 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 3283 | Bugs: ProtocolBugs{ |
| 3284 | SendV2ClientHello: true, |
| 3285 | }, |
| 3286 | }, |
| 3287 | }) |
| 3288 | |
| 3289 | // Client sends a Channel ID. |
| 3290 | tests = append(tests, testCase{ |
| 3291 | name: "ChannelID-Client", |
| 3292 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3293 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3294 | RequestChannelID: true, |
| 3295 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3296 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3297 | resumeSession: true, |
| 3298 | expectChannelID: true, |
| 3299 | }) |
| 3300 | |
| 3301 | // Server accepts a Channel ID. |
| 3302 | tests = append(tests, testCase{ |
| 3303 | testType: serverTest, |
| 3304 | name: "ChannelID-Server", |
| 3305 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3306 | MaxVersion: VersionTLS12, |
| 3307 | ChannelID: channelIDKey, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3308 | }, |
| 3309 | flags: []string{ |
| 3310 | "-expect-channel-id", |
| 3311 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3312 | }, |
| 3313 | resumeSession: true, |
| 3314 | expectChannelID: true, |
| 3315 | }) |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3316 | |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3317 | // Channel ID and NPN at the same time, to ensure their relative |
| 3318 | // ordering is correct. |
| 3319 | tests = append(tests, testCase{ |
| 3320 | name: "ChannelID-NPN-Client", |
| 3321 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3322 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3323 | RequestChannelID: true, |
| 3324 | NextProtos: []string{"foo"}, |
| 3325 | }, |
| 3326 | flags: []string{ |
| 3327 | "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile), |
| 3328 | "-select-next-proto", "foo", |
| 3329 | }, |
| 3330 | resumeSession: true, |
| 3331 | expectChannelID: true, |
| 3332 | expectedNextProto: "foo", |
| 3333 | expectedNextProtoType: npn, |
| 3334 | }) |
| 3335 | tests = append(tests, testCase{ |
| 3336 | testType: serverTest, |
| 3337 | name: "ChannelID-NPN-Server", |
| 3338 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3339 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3340 | ChannelID: channelIDKey, |
| 3341 | NextProtos: []string{"bar"}, |
| 3342 | }, |
| 3343 | flags: []string{ |
| 3344 | "-expect-channel-id", |
| 3345 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3346 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3347 | "-expect-next-proto", "bar", |
| 3348 | }, |
| 3349 | resumeSession: true, |
| 3350 | expectChannelID: true, |
| 3351 | expectedNextProto: "bar", |
| 3352 | expectedNextProtoType: npn, |
| 3353 | }) |
| 3354 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3355 | // Bidirectional shutdown with the runner initiating. |
| 3356 | tests = append(tests, testCase{ |
| 3357 | name: "Shutdown-Runner", |
| 3358 | config: Config{ |
| 3359 | Bugs: ProtocolBugs{ |
| 3360 | ExpectCloseNotify: true, |
| 3361 | }, |
| 3362 | }, |
| 3363 | flags: []string{"-check-close-notify"}, |
| 3364 | }) |
| 3365 | |
| 3366 | // Bidirectional shutdown with the shim initiating. The runner, |
| 3367 | // in the meantime, sends garbage before the close_notify which |
| 3368 | // the shim must ignore. |
| 3369 | tests = append(tests, testCase{ |
| 3370 | name: "Shutdown-Shim", |
| 3371 | config: Config{ |
| 3372 | Bugs: ProtocolBugs{ |
| 3373 | ExpectCloseNotify: true, |
| 3374 | }, |
| 3375 | }, |
| 3376 | shimShutsDown: true, |
| 3377 | sendEmptyRecords: 1, |
| 3378 | sendWarningAlerts: 1, |
| 3379 | flags: []string{"-check-close-notify"}, |
| 3380 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3381 | } else { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3382 | // TODO(davidben): DTLS 1.3 will want a similar thing for |
| 3383 | // HelloRetryRequest. |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3384 | tests = append(tests, testCase{ |
| 3385 | name: "SkipHelloVerifyRequest", |
| 3386 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3387 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3388 | Bugs: ProtocolBugs{ |
| 3389 | SkipHelloVerifyRequest: true, |
| 3390 | }, |
| 3391 | }, |
| 3392 | }) |
| 3393 | } |
| 3394 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3395 | for _, test := range tests { |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3396 | test.protocol = config.protocol |
| 3397 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3398 | test.name += "-DTLS" |
| 3399 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3400 | if config.async { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3401 | test.name += "-Async" |
| 3402 | test.flags = append(test.flags, "-async") |
| 3403 | } else { |
| 3404 | test.name += "-Sync" |
| 3405 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3406 | if config.splitHandshake { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3407 | test.name += "-SplitHandshakeRecords" |
| 3408 | test.config.Bugs.MaxHandshakeRecordLength = 1 |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3409 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3410 | test.config.Bugs.MaxPacketLength = 256 |
| 3411 | test.flags = append(test.flags, "-mtu", "256") |
| 3412 | } |
| 3413 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3414 | if config.packHandshakeFlight { |
| 3415 | test.name += "-PackHandshakeFlight" |
| 3416 | test.config.Bugs.PackHandshakeFlight = true |
| 3417 | } |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3418 | testCases = append(testCases, test) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 3419 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 3420 | } |
| 3421 | |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3422 | func addDDoSCallbackTests() { |
| 3423 | // DDoS callback. |
| 3424 | |
| 3425 | for _, resume := range []bool{false, true} { |
| 3426 | suffix := "Resume" |
| 3427 | if resume { |
| 3428 | suffix = "No" + suffix |
| 3429 | } |
| 3430 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3431 | // TODO(davidben): Test TLS 1.3's version of the DDoS callback. |
| 3432 | |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3433 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3434 | testType: serverTest, |
| 3435 | name: "Server-DDoS-OK-" + suffix, |
| 3436 | config: Config{ |
| 3437 | MaxVersion: VersionTLS12, |
| 3438 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3439 | flags: []string{"-install-ddos-callback"}, |
| 3440 | resumeSession: resume, |
| 3441 | }) |
| 3442 | |
| 3443 | failFlag := "-fail-ddos-callback" |
| 3444 | if resume { |
| 3445 | failFlag = "-fail-second-ddos-callback" |
| 3446 | } |
| 3447 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3448 | testType: serverTest, |
| 3449 | name: "Server-DDoS-Reject-" + suffix, |
| 3450 | config: Config{ |
| 3451 | MaxVersion: VersionTLS12, |
| 3452 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3453 | flags: []string{"-install-ddos-callback", failFlag}, |
| 3454 | resumeSession: resume, |
| 3455 | shouldFail: true, |
| 3456 | expectedError: ":CONNECTION_REJECTED:", |
| 3457 | }) |
| 3458 | } |
| 3459 | } |
| 3460 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3461 | func addVersionNegotiationTests() { |
| 3462 | for i, shimVers := range tlsVersions { |
| 3463 | // Assemble flags to disable all newer versions on the shim. |
| 3464 | var flags []string |
| 3465 | for _, vers := range tlsVersions[i+1:] { |
| 3466 | flags = append(flags, vers.flag) |
| 3467 | } |
| 3468 | |
| 3469 | for _, runnerVers := range tlsVersions { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3470 | protocols := []protocol{tls} |
| 3471 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 3472 | protocols = append(protocols, dtls) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3473 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3474 | for _, protocol := range protocols { |
| 3475 | expectedVersion := shimVers.version |
| 3476 | if runnerVers.version < shimVers.version { |
| 3477 | expectedVersion = runnerVers.version |
| 3478 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3479 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3480 | suffix := shimVers.name + "-" + runnerVers.name |
| 3481 | if protocol == dtls { |
| 3482 | suffix += "-DTLS" |
| 3483 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3484 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3485 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 3486 | |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3487 | clientVers := shimVers.version |
| 3488 | if clientVers > VersionTLS10 { |
| 3489 | clientVers = VersionTLS10 |
| 3490 | } |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3491 | serverVers := expectedVersion |
| 3492 | if expectedVersion >= VersionTLS13 { |
| 3493 | serverVers = VersionTLS10 |
| 3494 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3495 | testCases = append(testCases, testCase{ |
| 3496 | protocol: protocol, |
| 3497 | testType: clientTest, |
| 3498 | name: "VersionNegotiation-Client-" + suffix, |
| 3499 | config: Config{ |
| 3500 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3501 | Bugs: ProtocolBugs{ |
| 3502 | ExpectInitialRecordVersion: clientVers, |
| 3503 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3504 | }, |
| 3505 | flags: flags, |
| 3506 | expectedVersion: expectedVersion, |
| 3507 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3508 | testCases = append(testCases, testCase{ |
| 3509 | protocol: protocol, |
| 3510 | testType: clientTest, |
| 3511 | name: "VersionNegotiation-Client2-" + suffix, |
| 3512 | config: Config{ |
| 3513 | MaxVersion: runnerVers.version, |
| 3514 | Bugs: ProtocolBugs{ |
| 3515 | ExpectInitialRecordVersion: clientVers, |
| 3516 | }, |
| 3517 | }, |
| 3518 | flags: []string{"-max-version", shimVersFlag}, |
| 3519 | expectedVersion: expectedVersion, |
| 3520 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3521 | |
| 3522 | testCases = append(testCases, testCase{ |
| 3523 | protocol: protocol, |
| 3524 | testType: serverTest, |
| 3525 | name: "VersionNegotiation-Server-" + suffix, |
| 3526 | config: Config{ |
| 3527 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3528 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3529 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3530 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3531 | }, |
| 3532 | flags: flags, |
| 3533 | expectedVersion: expectedVersion, |
| 3534 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3535 | testCases = append(testCases, testCase{ |
| 3536 | protocol: protocol, |
| 3537 | testType: serverTest, |
| 3538 | name: "VersionNegotiation-Server2-" + suffix, |
| 3539 | config: Config{ |
| 3540 | MaxVersion: runnerVers.version, |
| 3541 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3542 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3543 | }, |
| 3544 | }, |
| 3545 | flags: []string{"-max-version", shimVersFlag}, |
| 3546 | expectedVersion: expectedVersion, |
| 3547 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3548 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3549 | } |
| 3550 | } |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 3551 | |
| 3552 | // Test for version tolerance. |
| 3553 | testCases = append(testCases, testCase{ |
| 3554 | testType: serverTest, |
| 3555 | name: "MinorVersionTolerance", |
| 3556 | config: Config{ |
| 3557 | Bugs: ProtocolBugs{ |
| 3558 | SendClientVersion: 0x03ff, |
| 3559 | }, |
| 3560 | }, |
| 3561 | expectedVersion: VersionTLS13, |
| 3562 | }) |
| 3563 | testCases = append(testCases, testCase{ |
| 3564 | testType: serverTest, |
| 3565 | name: "MajorVersionTolerance", |
| 3566 | config: Config{ |
| 3567 | Bugs: ProtocolBugs{ |
| 3568 | SendClientVersion: 0x0400, |
| 3569 | }, |
| 3570 | }, |
| 3571 | expectedVersion: VersionTLS13, |
| 3572 | }) |
| 3573 | testCases = append(testCases, testCase{ |
| 3574 | protocol: dtls, |
| 3575 | testType: serverTest, |
| 3576 | name: "MinorVersionTolerance-DTLS", |
| 3577 | config: Config{ |
| 3578 | Bugs: ProtocolBugs{ |
| 3579 | SendClientVersion: 0x03ff, |
| 3580 | }, |
| 3581 | }, |
| 3582 | expectedVersion: VersionTLS12, |
| 3583 | }) |
| 3584 | testCases = append(testCases, testCase{ |
| 3585 | protocol: dtls, |
| 3586 | testType: serverTest, |
| 3587 | name: "MajorVersionTolerance-DTLS", |
| 3588 | config: Config{ |
| 3589 | Bugs: ProtocolBugs{ |
| 3590 | SendClientVersion: 0x0400, |
| 3591 | }, |
| 3592 | }, |
| 3593 | expectedVersion: VersionTLS12, |
| 3594 | }) |
| 3595 | |
| 3596 | // Test that versions below 3.0 are rejected. |
| 3597 | testCases = append(testCases, testCase{ |
| 3598 | testType: serverTest, |
| 3599 | name: "VersionTooLow", |
| 3600 | config: Config{ |
| 3601 | Bugs: ProtocolBugs{ |
| 3602 | SendClientVersion: 0x0200, |
| 3603 | }, |
| 3604 | }, |
| 3605 | shouldFail: true, |
| 3606 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 3607 | }) |
| 3608 | testCases = append(testCases, testCase{ |
| 3609 | protocol: dtls, |
| 3610 | testType: serverTest, |
| 3611 | name: "VersionTooLow-DTLS", |
| 3612 | config: Config{ |
| 3613 | Bugs: ProtocolBugs{ |
| 3614 | // 0x0201 is the lowest version expressable in |
| 3615 | // DTLS. |
| 3616 | SendClientVersion: 0x0201, |
| 3617 | }, |
| 3618 | }, |
| 3619 | shouldFail: true, |
| 3620 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 3621 | }) |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 3622 | |
| 3623 | // Test TLS 1.3's downgrade signal. |
| 3624 | testCases = append(testCases, testCase{ |
| 3625 | name: "Downgrade-TLS12-Client", |
| 3626 | config: Config{ |
| 3627 | Bugs: ProtocolBugs{ |
| 3628 | NegotiateVersion: VersionTLS12, |
| 3629 | }, |
| 3630 | }, |
| 3631 | shouldFail: true, |
| 3632 | expectedError: ":DOWNGRADE_DETECTED:", |
| 3633 | }) |
| 3634 | testCases = append(testCases, testCase{ |
| 3635 | testType: serverTest, |
| 3636 | name: "Downgrade-TLS12-Server", |
| 3637 | config: Config{ |
| 3638 | Bugs: ProtocolBugs{ |
| 3639 | SendClientVersion: VersionTLS12, |
| 3640 | }, |
| 3641 | }, |
| 3642 | shouldFail: true, |
| 3643 | expectedLocalError: "tls: downgrade from TLS 1.3 detected", |
| 3644 | }) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3645 | } |
| 3646 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3647 | func addMinimumVersionTests() { |
| 3648 | for i, shimVers := range tlsVersions { |
| 3649 | // Assemble flags to disable all older versions on the shim. |
| 3650 | var flags []string |
| 3651 | for _, vers := range tlsVersions[:i] { |
| 3652 | flags = append(flags, vers.flag) |
| 3653 | } |
| 3654 | |
| 3655 | for _, runnerVers := range tlsVersions { |
| 3656 | protocols := []protocol{tls} |
| 3657 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 3658 | protocols = append(protocols, dtls) |
| 3659 | } |
| 3660 | for _, protocol := range protocols { |
| 3661 | suffix := shimVers.name + "-" + runnerVers.name |
| 3662 | if protocol == dtls { |
| 3663 | suffix += "-DTLS" |
| 3664 | } |
| 3665 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 3666 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3667 | var expectedVersion uint16 |
| 3668 | var shouldFail bool |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 3669 | var expectedClientError, expectedServerError string |
| 3670 | var expectedClientLocalError, expectedServerLocalError string |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3671 | if runnerVers.version >= shimVers.version { |
| 3672 | expectedVersion = runnerVers.version |
| 3673 | } else { |
| 3674 | shouldFail = true |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 3675 | expectedServerError = ":UNSUPPORTED_PROTOCOL:" |
| 3676 | expectedServerLocalError = "remote error: protocol version not supported" |
| 3677 | if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 { |
| 3678 | // If the client's minimum version is TLS 1.3 and the runner's |
| 3679 | // maximum is below TLS 1.2, the runner will fail to select a |
| 3680 | // cipher before the shim rejects the selected version. |
| 3681 | expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:" |
| 3682 | expectedClientLocalError = "tls: no cipher suite supported by both client and server" |
| 3683 | } else { |
| 3684 | expectedClientError = expectedServerError |
| 3685 | expectedClientLocalError = expectedServerLocalError |
| 3686 | } |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | testCases = append(testCases, testCase{ |
| 3690 | protocol: protocol, |
| 3691 | testType: clientTest, |
| 3692 | name: "MinimumVersion-Client-" + suffix, |
| 3693 | config: Config{ |
| 3694 | MaxVersion: runnerVers.version, |
| 3695 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3696 | flags: flags, |
| 3697 | expectedVersion: expectedVersion, |
| 3698 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 3699 | expectedError: expectedClientError, |
| 3700 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3701 | }) |
| 3702 | testCases = append(testCases, testCase{ |
| 3703 | protocol: protocol, |
| 3704 | testType: clientTest, |
| 3705 | name: "MinimumVersion-Client2-" + suffix, |
| 3706 | config: Config{ |
| 3707 | MaxVersion: runnerVers.version, |
| 3708 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3709 | flags: []string{"-min-version", shimVersFlag}, |
| 3710 | expectedVersion: expectedVersion, |
| 3711 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 3712 | expectedError: expectedClientError, |
| 3713 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3714 | }) |
| 3715 | |
| 3716 | testCases = append(testCases, testCase{ |
| 3717 | protocol: protocol, |
| 3718 | testType: serverTest, |
| 3719 | name: "MinimumVersion-Server-" + suffix, |
| 3720 | config: Config{ |
| 3721 | MaxVersion: runnerVers.version, |
| 3722 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3723 | flags: flags, |
| 3724 | expectedVersion: expectedVersion, |
| 3725 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 3726 | expectedError: expectedServerError, |
| 3727 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3728 | }) |
| 3729 | testCases = append(testCases, testCase{ |
| 3730 | protocol: protocol, |
| 3731 | testType: serverTest, |
| 3732 | name: "MinimumVersion-Server2-" + suffix, |
| 3733 | config: Config{ |
| 3734 | MaxVersion: runnerVers.version, |
| 3735 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3736 | flags: []string{"-min-version", shimVersFlag}, |
| 3737 | expectedVersion: expectedVersion, |
| 3738 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 3739 | expectedError: expectedServerError, |
| 3740 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3741 | }) |
| 3742 | } |
| 3743 | } |
| 3744 | } |
| 3745 | } |
| 3746 | |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3747 | func addExtensionTests() { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3748 | // TODO(davidben): Extensions, where applicable, all move their server |
| 3749 | // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these |
| 3750 | // tests for both. Also test interaction with 0-RTT when implemented. |
| 3751 | |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3752 | testCases = append(testCases, testCase{ |
| 3753 | testType: clientTest, |
| 3754 | name: "DuplicateExtensionClient", |
| 3755 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3756 | MaxVersion: VersionTLS12, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3757 | Bugs: ProtocolBugs{ |
| 3758 | DuplicateExtension: true, |
| 3759 | }, |
| 3760 | }, |
| 3761 | shouldFail: true, |
| 3762 | expectedLocalError: "remote error: error decoding message", |
| 3763 | }) |
| 3764 | testCases = append(testCases, testCase{ |
| 3765 | testType: serverTest, |
| 3766 | name: "DuplicateExtensionServer", |
| 3767 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3768 | MaxVersion: VersionTLS12, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3769 | Bugs: ProtocolBugs{ |
| 3770 | DuplicateExtension: true, |
| 3771 | }, |
| 3772 | }, |
| 3773 | shouldFail: true, |
| 3774 | expectedLocalError: "remote error: error decoding message", |
| 3775 | }) |
| 3776 | testCases = append(testCases, testCase{ |
| 3777 | testType: clientTest, |
| 3778 | name: "ServerNameExtensionClient", |
| 3779 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3780 | MaxVersion: VersionTLS12, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3781 | Bugs: ProtocolBugs{ |
| 3782 | ExpectServerName: "example.com", |
| 3783 | }, |
| 3784 | }, |
| 3785 | flags: []string{"-host-name", "example.com"}, |
| 3786 | }) |
| 3787 | testCases = append(testCases, testCase{ |
| 3788 | testType: clientTest, |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 3789 | name: "ServerNameExtensionClientMismatch", |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3790 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3791 | MaxVersion: VersionTLS12, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3792 | Bugs: ProtocolBugs{ |
| 3793 | ExpectServerName: "mismatch.com", |
| 3794 | }, |
| 3795 | }, |
| 3796 | flags: []string{"-host-name", "example.com"}, |
| 3797 | shouldFail: true, |
| 3798 | expectedLocalError: "tls: unexpected server name", |
| 3799 | }) |
| 3800 | testCases = append(testCases, testCase{ |
| 3801 | testType: clientTest, |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 3802 | name: "ServerNameExtensionClientMissing", |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3803 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3804 | MaxVersion: VersionTLS12, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3805 | Bugs: ProtocolBugs{ |
| 3806 | ExpectServerName: "missing.com", |
| 3807 | }, |
| 3808 | }, |
| 3809 | shouldFail: true, |
| 3810 | expectedLocalError: "tls: unexpected server name", |
| 3811 | }) |
| 3812 | testCases = append(testCases, testCase{ |
| 3813 | testType: serverTest, |
| 3814 | name: "ServerNameExtensionServer", |
| 3815 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3816 | MaxVersion: VersionTLS12, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 3817 | ServerName: "example.com", |
| 3818 | }, |
| 3819 | flags: []string{"-expect-server-name", "example.com"}, |
| 3820 | resumeSession: true, |
| 3821 | }) |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 3822 | testCases = append(testCases, testCase{ |
| 3823 | testType: clientTest, |
| 3824 | name: "ALPNClient", |
| 3825 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3826 | MaxVersion: VersionTLS12, |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 3827 | NextProtos: []string{"foo"}, |
| 3828 | }, |
| 3829 | flags: []string{ |
| 3830 | "-advertise-alpn", "\x03foo\x03bar\x03baz", |
| 3831 | "-expect-alpn", "foo", |
| 3832 | }, |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 3833 | expectedNextProto: "foo", |
| 3834 | expectedNextProtoType: alpn, |
| 3835 | resumeSession: true, |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 3836 | }) |
| 3837 | testCases = append(testCases, testCase{ |
| 3838 | testType: serverTest, |
| 3839 | name: "ALPNServer", |
| 3840 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3841 | MaxVersion: VersionTLS12, |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 3842 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3843 | }, |
| 3844 | flags: []string{ |
| 3845 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 3846 | "-select-alpn", "foo", |
| 3847 | }, |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 3848 | expectedNextProto: "foo", |
| 3849 | expectedNextProtoType: alpn, |
| 3850 | resumeSession: true, |
| 3851 | }) |
David Benjamin | 594e7d2 | 2016-03-17 17:49:56 -0400 | [diff] [blame] | 3852 | testCases = append(testCases, testCase{ |
| 3853 | testType: serverTest, |
| 3854 | name: "ALPNServer-Decline", |
| 3855 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3856 | MaxVersion: VersionTLS12, |
David Benjamin | 594e7d2 | 2016-03-17 17:49:56 -0400 | [diff] [blame] | 3857 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3858 | }, |
| 3859 | flags: []string{"-decline-alpn"}, |
| 3860 | expectNoNextProto: true, |
| 3861 | resumeSession: true, |
| 3862 | }) |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 3863 | // Test that the server prefers ALPN over NPN. |
| 3864 | testCases = append(testCases, testCase{ |
| 3865 | testType: serverTest, |
| 3866 | name: "ALPNServer-Preferred", |
| 3867 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3868 | MaxVersion: VersionTLS12, |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 3869 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3870 | }, |
| 3871 | flags: []string{ |
| 3872 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 3873 | "-select-alpn", "foo", |
| 3874 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3875 | }, |
| 3876 | expectedNextProto: "foo", |
| 3877 | expectedNextProtoType: alpn, |
| 3878 | resumeSession: true, |
| 3879 | }) |
| 3880 | testCases = append(testCases, testCase{ |
| 3881 | testType: serverTest, |
| 3882 | name: "ALPNServer-Preferred-Swapped", |
| 3883 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3884 | MaxVersion: VersionTLS12, |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 3885 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3886 | Bugs: ProtocolBugs{ |
| 3887 | SwapNPNAndALPN: true, |
| 3888 | }, |
| 3889 | }, |
| 3890 | flags: []string{ |
| 3891 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 3892 | "-select-alpn", "foo", |
| 3893 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3894 | }, |
| 3895 | expectedNextProto: "foo", |
| 3896 | expectedNextProtoType: alpn, |
| 3897 | resumeSession: true, |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 3898 | }) |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 3899 | var emptyString string |
| 3900 | testCases = append(testCases, testCase{ |
| 3901 | testType: clientTest, |
| 3902 | name: "ALPNClient-EmptyProtocolName", |
| 3903 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3904 | MaxVersion: VersionTLS12, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 3905 | NextProtos: []string{""}, |
| 3906 | Bugs: ProtocolBugs{ |
| 3907 | // A server returning an empty ALPN protocol |
| 3908 | // should be rejected. |
| 3909 | ALPNProtocol: &emptyString, |
| 3910 | }, |
| 3911 | }, |
| 3912 | flags: []string{ |
| 3913 | "-advertise-alpn", "\x03foo", |
| 3914 | }, |
Doug Hogan | ecdf7f9 | 2015-07-09 18:27:28 -0700 | [diff] [blame] | 3915 | shouldFail: true, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 3916 | expectedError: ":PARSE_TLSEXT:", |
| 3917 | }) |
| 3918 | testCases = append(testCases, testCase{ |
| 3919 | testType: serverTest, |
| 3920 | name: "ALPNServer-EmptyProtocolName", |
| 3921 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3922 | MaxVersion: VersionTLS12, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 3923 | // A ClientHello containing an empty ALPN protocol |
| 3924 | // should be rejected. |
| 3925 | NextProtos: []string{"foo", "", "baz"}, |
| 3926 | }, |
| 3927 | flags: []string{ |
| 3928 | "-select-alpn", "foo", |
| 3929 | }, |
Doug Hogan | ecdf7f9 | 2015-07-09 18:27:28 -0700 | [diff] [blame] | 3930 | shouldFail: true, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 3931 | expectedError: ":PARSE_TLSEXT:", |
| 3932 | }) |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 3933 | // Test that negotiating both NPN and ALPN is forbidden. |
| 3934 | testCases = append(testCases, testCase{ |
| 3935 | name: "NegotiateALPNAndNPN", |
| 3936 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3937 | MaxVersion: VersionTLS12, |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 3938 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3939 | Bugs: ProtocolBugs{ |
| 3940 | NegotiateALPNAndNPN: true, |
| 3941 | }, |
| 3942 | }, |
| 3943 | flags: []string{ |
| 3944 | "-advertise-alpn", "\x03foo", |
| 3945 | "-select-next-proto", "foo", |
| 3946 | }, |
| 3947 | shouldFail: true, |
| 3948 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 3949 | }) |
| 3950 | testCases = append(testCases, testCase{ |
| 3951 | name: "NegotiateALPNAndNPN-Swapped", |
| 3952 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3953 | MaxVersion: VersionTLS12, |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 3954 | NextProtos: []string{"foo", "bar", "baz"}, |
| 3955 | Bugs: ProtocolBugs{ |
| 3956 | NegotiateALPNAndNPN: true, |
| 3957 | SwapNPNAndALPN: true, |
| 3958 | }, |
| 3959 | }, |
| 3960 | flags: []string{ |
| 3961 | "-advertise-alpn", "\x03foo", |
| 3962 | "-select-next-proto", "foo", |
| 3963 | }, |
| 3964 | shouldFail: true, |
| 3965 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 3966 | }) |
David Benjamin | 091c4b9 | 2015-10-26 13:33:21 -0400 | [diff] [blame] | 3967 | // Test that NPN can be disabled with SSL_OP_DISABLE_NPN. |
| 3968 | testCases = append(testCases, testCase{ |
| 3969 | name: "DisableNPN", |
| 3970 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3971 | MaxVersion: VersionTLS12, |
David Benjamin | 091c4b9 | 2015-10-26 13:33:21 -0400 | [diff] [blame] | 3972 | NextProtos: []string{"foo"}, |
| 3973 | }, |
| 3974 | flags: []string{ |
| 3975 | "-select-next-proto", "foo", |
| 3976 | "-disable-npn", |
| 3977 | }, |
| 3978 | expectNoNextProto: true, |
| 3979 | }) |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 3980 | // Resume with a corrupt ticket. |
| 3981 | testCases = append(testCases, testCase{ |
| 3982 | testType: serverTest, |
| 3983 | name: "CorruptTicket", |
| 3984 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3985 | MaxVersion: VersionTLS12, |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 3986 | Bugs: ProtocolBugs{ |
| 3987 | CorruptTicket: true, |
| 3988 | }, |
| 3989 | }, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 3990 | resumeSession: true, |
| 3991 | expectResumeRejected: true, |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 3992 | }) |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 3993 | // Test the ticket callback, with and without renewal. |
| 3994 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3995 | testType: serverTest, |
| 3996 | name: "TicketCallback", |
| 3997 | config: Config{ |
| 3998 | MaxVersion: VersionTLS12, |
| 3999 | }, |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 4000 | resumeSession: true, |
| 4001 | flags: []string{"-use-ticket-callback"}, |
| 4002 | }) |
| 4003 | testCases = append(testCases, testCase{ |
| 4004 | testType: serverTest, |
| 4005 | name: "TicketCallback-Renew", |
| 4006 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4007 | MaxVersion: VersionTLS12, |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 4008 | Bugs: ProtocolBugs{ |
| 4009 | ExpectNewTicket: true, |
| 4010 | }, |
| 4011 | }, |
| 4012 | flags: []string{"-use-ticket-callback", "-renew-ticket"}, |
| 4013 | resumeSession: true, |
| 4014 | }) |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 4015 | // Resume with an oversized session id. |
| 4016 | testCases = append(testCases, testCase{ |
| 4017 | testType: serverTest, |
| 4018 | name: "OversizedSessionId", |
| 4019 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4020 | MaxVersion: VersionTLS12, |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 4021 | Bugs: ProtocolBugs{ |
| 4022 | OversizedSessionId: true, |
| 4023 | }, |
| 4024 | }, |
| 4025 | resumeSession: true, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 4026 | shouldFail: true, |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 4027 | expectedError: ":DECODE_ERROR:", |
| 4028 | }) |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4029 | // Basic DTLS-SRTP tests. Include fake profiles to ensure they |
| 4030 | // are ignored. |
| 4031 | testCases = append(testCases, testCase{ |
| 4032 | protocol: dtls, |
| 4033 | name: "SRTP-Client", |
| 4034 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4035 | MaxVersion: VersionTLS12, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4036 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4037 | }, |
| 4038 | flags: []string{ |
| 4039 | "-srtp-profiles", |
| 4040 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4041 | }, |
| 4042 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4043 | }) |
| 4044 | testCases = append(testCases, testCase{ |
| 4045 | protocol: dtls, |
| 4046 | testType: serverTest, |
| 4047 | name: "SRTP-Server", |
| 4048 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4049 | MaxVersion: VersionTLS12, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4050 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4051 | }, |
| 4052 | flags: []string{ |
| 4053 | "-srtp-profiles", |
| 4054 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4055 | }, |
| 4056 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4057 | }) |
| 4058 | // Test that the MKI is ignored. |
| 4059 | testCases = append(testCases, testCase{ |
| 4060 | protocol: dtls, |
| 4061 | testType: serverTest, |
| 4062 | name: "SRTP-Server-IgnoreMKI", |
| 4063 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4064 | MaxVersion: VersionTLS12, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4065 | SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80}, |
| 4066 | Bugs: ProtocolBugs{ |
| 4067 | SRTPMasterKeyIdentifer: "bogus", |
| 4068 | }, |
| 4069 | }, |
| 4070 | flags: []string{ |
| 4071 | "-srtp-profiles", |
| 4072 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4073 | }, |
| 4074 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4075 | }) |
| 4076 | // Test that SRTP isn't negotiated on the server if there were |
| 4077 | // no matching profiles. |
| 4078 | testCases = append(testCases, testCase{ |
| 4079 | protocol: dtls, |
| 4080 | testType: serverTest, |
| 4081 | name: "SRTP-Server-NoMatch", |
| 4082 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4083 | MaxVersion: VersionTLS12, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4084 | SRTPProtectionProfiles: []uint16{100, 101, 102}, |
| 4085 | }, |
| 4086 | flags: []string{ |
| 4087 | "-srtp-profiles", |
| 4088 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4089 | }, |
| 4090 | expectedSRTPProtectionProfile: 0, |
| 4091 | }) |
| 4092 | // Test that the server returning an invalid SRTP profile is |
| 4093 | // flagged as an error by the client. |
| 4094 | testCases = append(testCases, testCase{ |
| 4095 | protocol: dtls, |
| 4096 | name: "SRTP-Client-NoMatch", |
| 4097 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4098 | MaxVersion: VersionTLS12, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4099 | Bugs: ProtocolBugs{ |
| 4100 | SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32, |
| 4101 | }, |
| 4102 | }, |
| 4103 | flags: []string{ |
| 4104 | "-srtp-profiles", |
| 4105 | "SRTP_AES128_CM_SHA1_80", |
| 4106 | }, |
| 4107 | shouldFail: true, |
| 4108 | expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:", |
| 4109 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 4110 | // Test SCT list. |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 4111 | testCases = append(testCases, testCase{ |
David Benjamin | c057762 | 2015-09-12 18:28:38 -0400 | [diff] [blame] | 4112 | name: "SignedCertificateTimestampList-Client", |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 4113 | testType: clientTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4114 | config: Config{ |
| 4115 | MaxVersion: VersionTLS12, |
| 4116 | }, |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 4117 | flags: []string{ |
| 4118 | "-enable-signed-cert-timestamps", |
| 4119 | "-expect-signed-cert-timestamps", |
| 4120 | base64.StdEncoding.EncodeToString(testSCTList), |
| 4121 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 4122 | resumeSession: true, |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 4123 | }) |
Adam Langley | 33ad2b5 | 2015-07-20 17:43:53 -0700 | [diff] [blame] | 4124 | testCases = append(testCases, testCase{ |
David Benjamin | 80d1b35 | 2016-05-04 19:19:06 -0400 | [diff] [blame] | 4125 | name: "SendSCTListOnResume", |
| 4126 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4127 | MaxVersion: VersionTLS12, |
David Benjamin | 80d1b35 | 2016-05-04 19:19:06 -0400 | [diff] [blame] | 4128 | Bugs: ProtocolBugs{ |
| 4129 | SendSCTListOnResume: []byte("bogus"), |
| 4130 | }, |
| 4131 | }, |
| 4132 | flags: []string{ |
| 4133 | "-enable-signed-cert-timestamps", |
| 4134 | "-expect-signed-cert-timestamps", |
| 4135 | base64.StdEncoding.EncodeToString(testSCTList), |
| 4136 | }, |
| 4137 | resumeSession: true, |
| 4138 | }) |
| 4139 | testCases = append(testCases, testCase{ |
David Benjamin | c057762 | 2015-09-12 18:28:38 -0400 | [diff] [blame] | 4140 | name: "SignedCertificateTimestampList-Server", |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 4141 | testType: serverTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4142 | config: Config{ |
| 4143 | MaxVersion: VersionTLS12, |
| 4144 | }, |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 4145 | flags: []string{ |
| 4146 | "-signed-cert-timestamps", |
| 4147 | base64.StdEncoding.EncodeToString(testSCTList), |
| 4148 | }, |
| 4149 | expectedSCTList: testSCTList, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 4150 | resumeSession: true, |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 4151 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4152 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 4153 | testCases = append(testCases, testCase{ |
Adam Langley | 33ad2b5 | 2015-07-20 17:43:53 -0700 | [diff] [blame] | 4154 | testType: clientTest, |
| 4155 | name: "ClientHelloPadding", |
| 4156 | config: Config{ |
| 4157 | Bugs: ProtocolBugs{ |
| 4158 | RequireClientHelloSize: 512, |
| 4159 | }, |
| 4160 | }, |
| 4161 | // This hostname just needs to be long enough to push the |
| 4162 | // ClientHello into F5's danger zone between 256 and 511 bytes |
| 4163 | // long. |
| 4164 | flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"}, |
| 4165 | }) |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 4166 | |
| 4167 | // Extensions should not function in SSL 3.0. |
| 4168 | testCases = append(testCases, testCase{ |
| 4169 | testType: serverTest, |
| 4170 | name: "SSLv3Extensions-NoALPN", |
| 4171 | config: Config{ |
| 4172 | MaxVersion: VersionSSL30, |
| 4173 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4174 | }, |
| 4175 | flags: []string{ |
| 4176 | "-select-alpn", "foo", |
| 4177 | }, |
| 4178 | expectNoNextProto: true, |
| 4179 | }) |
| 4180 | |
| 4181 | // Test session tickets separately as they follow a different codepath. |
| 4182 | testCases = append(testCases, testCase{ |
| 4183 | testType: serverTest, |
| 4184 | name: "SSLv3Extensions-NoTickets", |
| 4185 | config: Config{ |
| 4186 | MaxVersion: VersionSSL30, |
| 4187 | Bugs: ProtocolBugs{ |
| 4188 | // Historically, session tickets in SSL 3.0 |
| 4189 | // failed in different ways depending on whether |
| 4190 | // the client supported renegotiation_info. |
| 4191 | NoRenegotiationInfo: true, |
| 4192 | }, |
| 4193 | }, |
| 4194 | resumeSession: true, |
| 4195 | }) |
| 4196 | testCases = append(testCases, testCase{ |
| 4197 | testType: serverTest, |
| 4198 | name: "SSLv3Extensions-NoTickets2", |
| 4199 | config: Config{ |
| 4200 | MaxVersion: VersionSSL30, |
| 4201 | }, |
| 4202 | resumeSession: true, |
| 4203 | }) |
| 4204 | |
| 4205 | // But SSL 3.0 does send and process renegotiation_info. |
| 4206 | testCases = append(testCases, testCase{ |
| 4207 | testType: serverTest, |
| 4208 | name: "SSLv3Extensions-RenegotiationInfo", |
| 4209 | config: Config{ |
| 4210 | MaxVersion: VersionSSL30, |
| 4211 | Bugs: ProtocolBugs{ |
| 4212 | RequireRenegotiationInfo: true, |
| 4213 | }, |
| 4214 | }, |
| 4215 | }) |
| 4216 | testCases = append(testCases, testCase{ |
| 4217 | testType: serverTest, |
| 4218 | name: "SSLv3Extensions-RenegotiationInfo-SCSV", |
| 4219 | config: Config{ |
| 4220 | MaxVersion: VersionSSL30, |
| 4221 | Bugs: ProtocolBugs{ |
| 4222 | NoRenegotiationInfo: true, |
| 4223 | SendRenegotiationSCSV: true, |
| 4224 | RequireRenegotiationInfo: true, |
| 4225 | }, |
| 4226 | }, |
| 4227 | }) |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4228 | } |
| 4229 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4230 | func addResumptionVersionTests() { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4231 | for _, sessionVers := range tlsVersions { |
David Benjamin | 6e6abe1 | 2016-07-13 20:57:22 -0400 | [diff] [blame] | 4232 | // TODO(davidben,svaldez): Implement resumption in TLS 1.3. |
| 4233 | if sessionVers.version >= VersionTLS13 { |
| 4234 | continue |
| 4235 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4236 | for _, resumeVers := range tlsVersions { |
David Benjamin | 6e6abe1 | 2016-07-13 20:57:22 -0400 | [diff] [blame] | 4237 | if resumeVers.version >= VersionTLS13 { |
| 4238 | continue |
| 4239 | } |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4240 | cipher := TLS_RSA_WITH_AES_128_CBC_SHA |
| 4241 | if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 { |
| 4242 | // TLS 1.3 only shares ciphers with TLS 1.2, so |
| 4243 | // we skip certain combinations and use a |
| 4244 | // different cipher to test with. |
| 4245 | cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
| 4246 | if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 { |
| 4247 | continue |
| 4248 | } |
| 4249 | } |
| 4250 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4251 | protocols := []protocol{tls} |
| 4252 | if sessionVers.hasDTLS && resumeVers.hasDTLS { |
| 4253 | protocols = append(protocols, dtls) |
David Benjamin | bdf5e72 | 2014-11-11 00:52:15 -0500 | [diff] [blame] | 4254 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4255 | for _, protocol := range protocols { |
| 4256 | suffix := "-" + sessionVers.name + "-" + resumeVers.name |
| 4257 | if protocol == dtls { |
| 4258 | suffix += "-DTLS" |
| 4259 | } |
| 4260 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4261 | if sessionVers.version == resumeVers.version { |
| 4262 | testCases = append(testCases, testCase{ |
| 4263 | protocol: protocol, |
| 4264 | name: "Resume-Client" + suffix, |
| 4265 | resumeSession: true, |
| 4266 | config: Config{ |
| 4267 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4268 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4269 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4270 | expectedVersion: sessionVers.version, |
| 4271 | expectedResumeVersion: resumeVers.version, |
| 4272 | }) |
| 4273 | } else { |
| 4274 | testCases = append(testCases, testCase{ |
| 4275 | protocol: protocol, |
| 4276 | name: "Resume-Client-Mismatch" + suffix, |
| 4277 | resumeSession: true, |
| 4278 | config: Config{ |
| 4279 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4280 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4281 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4282 | expectedVersion: sessionVers.version, |
| 4283 | resumeConfig: &Config{ |
| 4284 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4285 | CipherSuites: []uint16{cipher}, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4286 | Bugs: ProtocolBugs{ |
| 4287 | AllowSessionVersionMismatch: true, |
| 4288 | }, |
| 4289 | }, |
| 4290 | expectedResumeVersion: resumeVers.version, |
| 4291 | shouldFail: true, |
| 4292 | expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:", |
| 4293 | }) |
| 4294 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4295 | |
| 4296 | testCases = append(testCases, testCase{ |
| 4297 | protocol: protocol, |
| 4298 | name: "Resume-Client-NoResume" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4299 | resumeSession: true, |
| 4300 | config: Config{ |
| 4301 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4302 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4303 | }, |
| 4304 | expectedVersion: sessionVers.version, |
| 4305 | resumeConfig: &Config{ |
| 4306 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4307 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4308 | }, |
| 4309 | newSessionsOnResume: true, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 4310 | expectResumeRejected: true, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4311 | expectedResumeVersion: resumeVers.version, |
| 4312 | }) |
| 4313 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4314 | testCases = append(testCases, testCase{ |
| 4315 | protocol: protocol, |
| 4316 | testType: serverTest, |
| 4317 | name: "Resume-Server" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4318 | resumeSession: true, |
| 4319 | config: Config{ |
| 4320 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4321 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4322 | }, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 4323 | expectedVersion: sessionVers.version, |
| 4324 | expectResumeRejected: sessionVers.version != resumeVers.version, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4325 | resumeConfig: &Config{ |
| 4326 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4327 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4328 | }, |
| 4329 | expectedResumeVersion: resumeVers.version, |
| 4330 | }) |
| 4331 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4332 | } |
| 4333 | } |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4334 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4335 | // TODO(davidben): This test should have a TLS 1.3 variant later. |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4336 | testCases = append(testCases, testCase{ |
| 4337 | name: "Resume-Client-CipherMismatch", |
| 4338 | resumeSession: true, |
| 4339 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4340 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4341 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 4342 | }, |
| 4343 | resumeConfig: &Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4344 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4345 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 4346 | Bugs: ProtocolBugs{ |
| 4347 | SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 4348 | }, |
| 4349 | }, |
| 4350 | shouldFail: true, |
| 4351 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 4352 | }) |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4353 | } |
| 4354 | |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 4355 | func addRenegotiationTests() { |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 4356 | // Servers cannot renegotiate. |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 4357 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4358 | testType: serverTest, |
| 4359 | name: "Renegotiate-Server-Forbidden", |
| 4360 | config: Config{ |
| 4361 | MaxVersion: VersionTLS12, |
| 4362 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4363 | renegotiate: 1, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 4364 | shouldFail: true, |
| 4365 | expectedError: ":NO_RENEGOTIATION:", |
| 4366 | expectedLocalError: "remote error: no renegotiation", |
| 4367 | }) |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 4368 | // The server shouldn't echo the renegotiation extension unless |
| 4369 | // requested by the client. |
| 4370 | testCases = append(testCases, testCase{ |
| 4371 | testType: serverTest, |
| 4372 | name: "Renegotiate-Server-NoExt", |
| 4373 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4374 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 4375 | Bugs: ProtocolBugs{ |
| 4376 | NoRenegotiationInfo: true, |
| 4377 | RequireRenegotiationInfo: true, |
| 4378 | }, |
| 4379 | }, |
| 4380 | shouldFail: true, |
| 4381 | expectedLocalError: "renegotiation extension missing", |
| 4382 | }) |
| 4383 | // The renegotiation SCSV should be sufficient for the server to echo |
| 4384 | // the extension. |
| 4385 | testCases = append(testCases, testCase{ |
| 4386 | testType: serverTest, |
| 4387 | name: "Renegotiate-Server-NoExt-SCSV", |
| 4388 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4389 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 4390 | Bugs: ProtocolBugs{ |
| 4391 | NoRenegotiationInfo: true, |
| 4392 | SendRenegotiationSCSV: true, |
| 4393 | RequireRenegotiationInfo: true, |
| 4394 | }, |
| 4395 | }, |
| 4396 | }) |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4397 | testCases = append(testCases, testCase{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 4398 | name: "Renegotiate-Client", |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4399 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4400 | MaxVersion: VersionTLS12, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4401 | Bugs: ProtocolBugs{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 4402 | FailIfResumeOnRenego: true, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4403 | }, |
| 4404 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4405 | renegotiate: 1, |
| 4406 | flags: []string{ |
| 4407 | "-renegotiate-freely", |
| 4408 | "-expect-total-renegotiations", "1", |
| 4409 | }, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4410 | }) |
| 4411 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4412 | name: "Renegotiate-Client-EmptyExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4413 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4414 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4415 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4416 | Bugs: ProtocolBugs{ |
| 4417 | EmptyRenegotiationInfo: true, |
| 4418 | }, |
| 4419 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4420 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4421 | shouldFail: true, |
| 4422 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4423 | }) |
| 4424 | testCases = append(testCases, testCase{ |
| 4425 | name: "Renegotiate-Client-BadExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4426 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4427 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4428 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4429 | Bugs: ProtocolBugs{ |
| 4430 | BadRenegotiationInfo: true, |
| 4431 | }, |
| 4432 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4433 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4434 | shouldFail: true, |
| 4435 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4436 | }) |
| 4437 | testCases = append(testCases, testCase{ |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 4438 | name: "Renegotiate-Client-Downgrade", |
| 4439 | renegotiate: 1, |
| 4440 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4441 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 4442 | Bugs: ProtocolBugs{ |
| 4443 | NoRenegotiationInfoAfterInitial: true, |
| 4444 | }, |
| 4445 | }, |
| 4446 | flags: []string{"-renegotiate-freely"}, |
| 4447 | shouldFail: true, |
| 4448 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4449 | }) |
| 4450 | testCases = append(testCases, testCase{ |
| 4451 | name: "Renegotiate-Client-Upgrade", |
| 4452 | renegotiate: 1, |
| 4453 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4454 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 4455 | Bugs: ProtocolBugs{ |
| 4456 | NoRenegotiationInfoInInitial: true, |
| 4457 | }, |
| 4458 | }, |
| 4459 | flags: []string{"-renegotiate-freely"}, |
| 4460 | shouldFail: true, |
| 4461 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4462 | }) |
| 4463 | testCases = append(testCases, testCase{ |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4464 | name: "Renegotiate-Client-NoExt-Allowed", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4465 | renegotiate: 1, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4466 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4467 | MaxVersion: VersionTLS12, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4468 | Bugs: ProtocolBugs{ |
| 4469 | NoRenegotiationInfo: true, |
| 4470 | }, |
| 4471 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4472 | flags: []string{ |
| 4473 | "-renegotiate-freely", |
| 4474 | "-expect-total-renegotiations", "1", |
| 4475 | }, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4476 | }) |
| 4477 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4478 | name: "Renegotiate-Client-SwitchCiphers", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4479 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4480 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4481 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4482 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 4483 | }, |
| 4484 | renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4485 | flags: []string{ |
| 4486 | "-renegotiate-freely", |
| 4487 | "-expect-total-renegotiations", "1", |
| 4488 | }, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4489 | }) |
| 4490 | testCases = append(testCases, testCase{ |
| 4491 | name: "Renegotiate-Client-SwitchCiphers2", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4492 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4493 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4494 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4495 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4496 | }, |
| 4497 | renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4498 | flags: []string{ |
| 4499 | "-renegotiate-freely", |
| 4500 | "-expect-total-renegotiations", "1", |
| 4501 | }, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 4502 | }) |
| 4503 | testCases = append(testCases, testCase{ |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 4504 | name: "Renegotiate-SameClientVersion", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4505 | renegotiate: 1, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 4506 | config: Config{ |
| 4507 | MaxVersion: VersionTLS10, |
| 4508 | Bugs: ProtocolBugs{ |
| 4509 | RequireSameRenegoClientVersion: true, |
| 4510 | }, |
| 4511 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4512 | flags: []string{ |
| 4513 | "-renegotiate-freely", |
| 4514 | "-expect-total-renegotiations", "1", |
| 4515 | }, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 4516 | }) |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 4517 | testCases = append(testCases, testCase{ |
| 4518 | name: "Renegotiate-FalseStart", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4519 | renegotiate: 1, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 4520 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4521 | MaxVersion: VersionTLS12, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 4522 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4523 | NextProtos: []string{"foo"}, |
| 4524 | }, |
| 4525 | flags: []string{ |
| 4526 | "-false-start", |
| 4527 | "-select-next-proto", "foo", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4528 | "-renegotiate-freely", |
David Benjamin | 324dce4 | 2015-10-12 19:49:00 -0400 | [diff] [blame] | 4529 | "-expect-total-renegotiations", "1", |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 4530 | }, |
| 4531 | shimWritesFirst: true, |
| 4532 | }) |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4533 | |
| 4534 | // Client-side renegotiation controls. |
| 4535 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4536 | name: "Renegotiate-Client-Forbidden-1", |
| 4537 | config: Config{ |
| 4538 | MaxVersion: VersionTLS12, |
| 4539 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4540 | renegotiate: 1, |
| 4541 | shouldFail: true, |
| 4542 | expectedError: ":NO_RENEGOTIATION:", |
| 4543 | expectedLocalError: "remote error: no renegotiation", |
| 4544 | }) |
| 4545 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4546 | name: "Renegotiate-Client-Once-1", |
| 4547 | config: Config{ |
| 4548 | MaxVersion: VersionTLS12, |
| 4549 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4550 | renegotiate: 1, |
| 4551 | flags: []string{ |
| 4552 | "-renegotiate-once", |
| 4553 | "-expect-total-renegotiations", "1", |
| 4554 | }, |
| 4555 | }) |
| 4556 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4557 | name: "Renegotiate-Client-Freely-1", |
| 4558 | config: Config{ |
| 4559 | MaxVersion: VersionTLS12, |
| 4560 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4561 | renegotiate: 1, |
| 4562 | flags: []string{ |
| 4563 | "-renegotiate-freely", |
| 4564 | "-expect-total-renegotiations", "1", |
| 4565 | }, |
| 4566 | }) |
| 4567 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4568 | name: "Renegotiate-Client-Once-2", |
| 4569 | config: Config{ |
| 4570 | MaxVersion: VersionTLS12, |
| 4571 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4572 | renegotiate: 2, |
| 4573 | flags: []string{"-renegotiate-once"}, |
| 4574 | shouldFail: true, |
| 4575 | expectedError: ":NO_RENEGOTIATION:", |
| 4576 | expectedLocalError: "remote error: no renegotiation", |
| 4577 | }) |
| 4578 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4579 | name: "Renegotiate-Client-Freely-2", |
| 4580 | config: Config{ |
| 4581 | MaxVersion: VersionTLS12, |
| 4582 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4583 | renegotiate: 2, |
| 4584 | flags: []string{ |
| 4585 | "-renegotiate-freely", |
| 4586 | "-expect-total-renegotiations", "2", |
| 4587 | }, |
| 4588 | }) |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 4589 | testCases = append(testCases, testCase{ |
| 4590 | name: "Renegotiate-Client-NoIgnore", |
| 4591 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4592 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 4593 | Bugs: ProtocolBugs{ |
| 4594 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 4595 | }, |
| 4596 | }, |
| 4597 | shouldFail: true, |
| 4598 | expectedError: ":NO_RENEGOTIATION:", |
| 4599 | }) |
| 4600 | testCases = append(testCases, testCase{ |
| 4601 | name: "Renegotiate-Client-Ignore", |
| 4602 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4603 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 4604 | Bugs: ProtocolBugs{ |
| 4605 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 4606 | }, |
| 4607 | }, |
| 4608 | flags: []string{ |
| 4609 | "-renegotiate-ignore", |
| 4610 | "-expect-total-renegotiations", "0", |
| 4611 | }, |
| 4612 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4613 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 4614 | // Stray HelloRequests during the handshake are ignored in TLS 1.2. |
David Benjamin | 71dd666 | 2016-07-08 14:10:48 -0700 | [diff] [blame] | 4615 | testCases = append(testCases, testCase{ |
| 4616 | name: "StrayHelloRequest", |
| 4617 | config: Config{ |
| 4618 | MaxVersion: VersionTLS12, |
| 4619 | Bugs: ProtocolBugs{ |
| 4620 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 4621 | }, |
| 4622 | }, |
| 4623 | }) |
| 4624 | testCases = append(testCases, testCase{ |
| 4625 | name: "StrayHelloRequest-Packed", |
| 4626 | config: Config{ |
| 4627 | MaxVersion: VersionTLS12, |
| 4628 | Bugs: ProtocolBugs{ |
| 4629 | PackHandshakeFlight: true, |
| 4630 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 4631 | }, |
| 4632 | }, |
| 4633 | }) |
| 4634 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 4635 | // Renegotiation is forbidden in TLS 1.3. |
| 4636 | testCases = append(testCases, testCase{ |
| 4637 | name: "Renegotiate-Client-TLS13", |
| 4638 | config: Config{ |
| 4639 | MaxVersion: VersionTLS13, |
| 4640 | }, |
| 4641 | renegotiate: 1, |
| 4642 | flags: []string{ |
| 4643 | "-renegotiate-freely", |
| 4644 | }, |
| 4645 | shouldFail: true, |
| 4646 | expectedError: ":NO_RENEGOTIATION:", |
| 4647 | }) |
| 4648 | |
| 4649 | // Stray HelloRequests during the handshake are forbidden in TLS 1.3. |
| 4650 | testCases = append(testCases, testCase{ |
| 4651 | name: "StrayHelloRequest-TLS13", |
| 4652 | config: Config{ |
| 4653 | MaxVersion: VersionTLS13, |
| 4654 | Bugs: ProtocolBugs{ |
| 4655 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 4656 | }, |
| 4657 | }, |
| 4658 | shouldFail: true, |
| 4659 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 4660 | }) |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 4661 | } |
| 4662 | |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 4663 | func addDTLSReplayTests() { |
| 4664 | // Test that sequence number replays are detected. |
| 4665 | testCases = append(testCases, testCase{ |
| 4666 | protocol: dtls, |
| 4667 | name: "DTLS-Replay", |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 4668 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 4669 | replayWrites: true, |
| 4670 | }) |
| 4671 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 4672 | // Test the incoming sequence number skipping by values larger |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 4673 | // than the retransmit window. |
| 4674 | testCases = append(testCases, testCase{ |
| 4675 | protocol: dtls, |
| 4676 | name: "DTLS-Replay-LargeGaps", |
| 4677 | config: Config{ |
| 4678 | Bugs: ProtocolBugs{ |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 4679 | SequenceNumberMapping: func(in uint64) uint64 { |
| 4680 | return in * 127 |
| 4681 | }, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 4682 | }, |
| 4683 | }, |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 4684 | messageCount: 200, |
| 4685 | replayWrites: true, |
| 4686 | }) |
| 4687 | |
| 4688 | // Test the incoming sequence number changing non-monotonically. |
| 4689 | testCases = append(testCases, testCase{ |
| 4690 | protocol: dtls, |
| 4691 | name: "DTLS-Replay-NonMonotonic", |
| 4692 | config: Config{ |
| 4693 | Bugs: ProtocolBugs{ |
| 4694 | SequenceNumberMapping: func(in uint64) uint64 { |
| 4695 | return in ^ 31 |
| 4696 | }, |
| 4697 | }, |
| 4698 | }, |
| 4699 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 4700 | replayWrites: true, |
| 4701 | }) |
| 4702 | } |
| 4703 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4704 | var testSignatureAlgorithms = []struct { |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4705 | name string |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4706 | id signatureAlgorithm |
| 4707 | cert testCert |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4708 | }{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4709 | {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA}, |
| 4710 | {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA}, |
| 4711 | {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA}, |
| 4712 | {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 4713 | {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 4714 | {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256}, |
| 4715 | {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384}, |
| 4716 | {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521}, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 4717 | {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA}, |
| 4718 | {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA}, |
| 4719 | {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 4720 | // Tests for key types prior to TLS 1.2. |
| 4721 | {"RSA", 0, testCertRSA}, |
| 4722 | {"ECDSA", 0, testCertECDSAP256}, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4723 | } |
| 4724 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4725 | const fakeSigAlg1 signatureAlgorithm = 0x2a01 |
| 4726 | const fakeSigAlg2 signatureAlgorithm = 0xff01 |
| 4727 | |
| 4728 | func addSignatureAlgorithmTests() { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 4729 | // Not all ciphers involve a signature. Advertise a list which gives all |
| 4730 | // versions a signing cipher. |
| 4731 | signingCiphers := []uint16{ |
| 4732 | TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 4733 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 4734 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 4735 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 4736 | TLS_DHE_RSA_WITH_AES_128_CBC_SHA, |
| 4737 | } |
| 4738 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4739 | // Make sure each signature algorithm works. Include some fake values in |
| 4740 | // the list and ensure they're ignored. |
| 4741 | for _, alg := range testSignatureAlgorithms { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4742 | for _, ver := range tlsVersions { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 4743 | if (ver.version < VersionTLS12) != (alg.id == 0) { |
| 4744 | continue |
| 4745 | } |
| 4746 | |
| 4747 | // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing |
| 4748 | // or remove it in C. |
| 4749 | if ver.version == VersionSSL30 && alg.cert != testCertRSA { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4750 | continue |
| 4751 | } |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4752 | |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 4753 | var shouldFail bool |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4754 | // ecdsa_sha1 does not exist in TLS 1.3. |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 4755 | if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 { |
| 4756 | shouldFail = true |
| 4757 | } |
| 4758 | // RSA-PSS does not exist in TLS 1.2. |
| 4759 | if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") { |
| 4760 | shouldFail = true |
| 4761 | } |
| 4762 | |
| 4763 | var signError, verifyError string |
| 4764 | if shouldFail { |
| 4765 | signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:" |
| 4766 | verifyError = ":WRONG_SIGNATURE_TYPE:" |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4767 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4768 | |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4769 | suffix := "-" + alg.name + "-" + ver.name |
David Benjamin | 6e80765 | 2015-11-02 12:02:20 -0500 | [diff] [blame] | 4770 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4771 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 4772 | name: "ClientAuth-Sign" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4773 | config: Config{ |
| 4774 | MaxVersion: ver.version, |
| 4775 | ClientAuth: RequireAnyClientCert, |
| 4776 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 4777 | fakeSigAlg1, |
| 4778 | alg.id, |
| 4779 | fakeSigAlg2, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4780 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4781 | }, |
| 4782 | flags: []string{ |
| 4783 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 4784 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 4785 | "-enable-all-curves", |
| 4786 | }, |
| 4787 | shouldFail: shouldFail, |
| 4788 | expectedError: signError, |
| 4789 | expectedPeerSignatureAlgorithm: alg.id, |
| 4790 | }) |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 4791 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4792 | testCases = append(testCases, testCase{ |
| 4793 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 4794 | name: "ClientAuth-Verify" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4795 | config: Config{ |
| 4796 | MaxVersion: ver.version, |
| 4797 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 4798 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 4799 | alg.id, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 4800 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4801 | Bugs: ProtocolBugs{ |
| 4802 | SkipECDSACurveCheck: shouldFail, |
| 4803 | IgnoreSignatureVersionChecks: shouldFail, |
| 4804 | // The client won't advertise 1.3-only algorithms after |
| 4805 | // version negotiation. |
| 4806 | IgnorePeerSignatureAlgorithmPreferences: shouldFail, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 4807 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4808 | }, |
| 4809 | flags: []string{ |
| 4810 | "-require-any-client-certificate", |
| 4811 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 4812 | "-enable-all-curves", |
| 4813 | }, |
| 4814 | shouldFail: shouldFail, |
| 4815 | expectedError: verifyError, |
| 4816 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4817 | |
| 4818 | testCases = append(testCases, testCase{ |
| 4819 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 4820 | name: "ServerAuth-Sign" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4821 | config: Config{ |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 4822 | MaxVersion: ver.version, |
| 4823 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4824 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4825 | fakeSigAlg1, |
| 4826 | alg.id, |
| 4827 | fakeSigAlg2, |
| 4828 | }, |
| 4829 | }, |
| 4830 | flags: []string{ |
| 4831 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 4832 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 4833 | "-enable-all-curves", |
| 4834 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 4835 | shouldFail: shouldFail, |
| 4836 | expectedError: signError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4837 | expectedPeerSignatureAlgorithm: alg.id, |
| 4838 | }) |
| 4839 | |
| 4840 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 4841 | name: "ServerAuth-Verify" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4842 | config: Config{ |
| 4843 | MaxVersion: ver.version, |
| 4844 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 4845 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4846 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4847 | alg.id, |
| 4848 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 4849 | Bugs: ProtocolBugs{ |
| 4850 | SkipECDSACurveCheck: shouldFail, |
| 4851 | IgnoreSignatureVersionChecks: shouldFail, |
| 4852 | }, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4853 | }, |
| 4854 | flags: []string{ |
| 4855 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 4856 | "-enable-all-curves", |
| 4857 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 4858 | shouldFail: shouldFail, |
| 4859 | expectedError: verifyError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4860 | }) |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 4861 | |
| 4862 | if !shouldFail { |
| 4863 | testCases = append(testCases, testCase{ |
| 4864 | testType: serverTest, |
| 4865 | name: "ClientAuth-InvalidSignature" + suffix, |
| 4866 | config: Config{ |
| 4867 | MaxVersion: ver.version, |
| 4868 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 4869 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 4870 | alg.id, |
| 4871 | }, |
| 4872 | Bugs: ProtocolBugs{ |
| 4873 | InvalidSignature: true, |
| 4874 | }, |
| 4875 | }, |
| 4876 | flags: []string{ |
| 4877 | "-require-any-client-certificate", |
| 4878 | "-enable-all-curves", |
| 4879 | }, |
| 4880 | shouldFail: true, |
| 4881 | expectedError: ":BAD_SIGNATURE:", |
| 4882 | }) |
| 4883 | |
| 4884 | testCases = append(testCases, testCase{ |
| 4885 | name: "ServerAuth-InvalidSignature" + suffix, |
| 4886 | config: Config{ |
| 4887 | MaxVersion: ver.version, |
| 4888 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 4889 | CipherSuites: signingCiphers, |
| 4890 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 4891 | alg.id, |
| 4892 | }, |
| 4893 | Bugs: ProtocolBugs{ |
| 4894 | InvalidSignature: true, |
| 4895 | }, |
| 4896 | }, |
| 4897 | flags: []string{"-enable-all-curves"}, |
| 4898 | shouldFail: true, |
| 4899 | expectedError: ":BAD_SIGNATURE:", |
| 4900 | }) |
| 4901 | } |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 4902 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4903 | } |
| 4904 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4905 | // Test that algorithm selection takes the key type into account. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4906 | // |
| 4907 | // TODO(davidben): Test this in TLS 1.3. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4908 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 4909 | name: "ClientAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4910 | config: Config{ |
| 4911 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4912 | MaxVersion: VersionTLS12, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4913 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4914 | signatureECDSAWithP521AndSHA512, |
| 4915 | signatureRSAPKCS1WithSHA384, |
| 4916 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4917 | }, |
| 4918 | }, |
| 4919 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 4920 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4921 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4922 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4923 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4924 | }) |
| 4925 | |
| 4926 | testCases = append(testCases, testCase{ |
| 4927 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 4928 | name: "ServerAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4929 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4930 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4931 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4932 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4933 | signatureECDSAWithP521AndSHA512, |
| 4934 | signatureRSAPKCS1WithSHA384, |
| 4935 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4936 | }, |
| 4937 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4938 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4939 | }) |
| 4940 | |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 4941 | // Test that signature verification takes the key type into account. |
| 4942 | // |
| 4943 | // TODO(davidben): Test this in TLS 1.3. |
| 4944 | testCases = append(testCases, testCase{ |
| 4945 | testType: serverTest, |
| 4946 | name: "Verify-ClientAuth-SignatureType", |
| 4947 | config: Config{ |
| 4948 | MaxVersion: VersionTLS12, |
| 4949 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4950 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 4951 | signatureRSAPKCS1WithSHA256, |
| 4952 | }, |
| 4953 | Bugs: ProtocolBugs{ |
| 4954 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 4955 | }, |
| 4956 | }, |
| 4957 | flags: []string{ |
| 4958 | "-require-any-client-certificate", |
| 4959 | }, |
| 4960 | shouldFail: true, |
| 4961 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 4962 | }) |
| 4963 | |
| 4964 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 4965 | name: "Verify-ServerAuth-SignatureType", |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 4966 | config: Config{ |
| 4967 | MaxVersion: VersionTLS12, |
| 4968 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4969 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 4970 | signatureRSAPKCS1WithSHA256, |
| 4971 | }, |
| 4972 | Bugs: ProtocolBugs{ |
| 4973 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 4974 | }, |
| 4975 | }, |
| 4976 | shouldFail: true, |
| 4977 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 4978 | }) |
| 4979 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 4980 | // Test that, if the list is missing, the peer falls back to SHA-1 in |
| 4981 | // TLS 1.2, but not TLS 1.3. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4982 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 4983 | name: "ClientAuth-SHA1-Fallback", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4984 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4985 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4986 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 4987 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4988 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4989 | }, |
| 4990 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 4991 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4992 | }, |
| 4993 | }, |
| 4994 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 4995 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4996 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 4997 | }, |
| 4998 | }) |
| 4999 | |
| 5000 | testCases = append(testCases, testCase{ |
| 5001 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5002 | name: "ServerAuth-SHA1-Fallback", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5003 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5004 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5005 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5006 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5007 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5008 | }, |
| 5009 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5010 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5011 | }, |
| 5012 | }, |
| 5013 | }) |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5014 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5015 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5016 | name: "ClientAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5017 | config: Config{ |
| 5018 | MaxVersion: VersionTLS13, |
| 5019 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5020 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5021 | signatureRSAPKCS1WithSHA1, |
| 5022 | }, |
| 5023 | Bugs: ProtocolBugs{ |
| 5024 | NoSignatureAlgorithms: true, |
| 5025 | }, |
| 5026 | }, |
| 5027 | flags: []string{ |
| 5028 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5029 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5030 | }, |
| 5031 | shouldFail: true, |
| 5032 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5033 | }) |
| 5034 | |
| 5035 | testCases = append(testCases, testCase{ |
| 5036 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5037 | name: "ServerAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5038 | config: Config{ |
| 5039 | MaxVersion: VersionTLS13, |
| 5040 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5041 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5042 | signatureRSAPKCS1WithSHA1, |
| 5043 | }, |
| 5044 | Bugs: ProtocolBugs{ |
| 5045 | NoSignatureAlgorithms: true, |
| 5046 | }, |
| 5047 | }, |
| 5048 | shouldFail: true, |
| 5049 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5050 | }) |
| 5051 | |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5052 | // Test that hash preferences are enforced. BoringSSL defaults to |
| 5053 | // rejecting MD5 signatures. |
| 5054 | testCases = append(testCases, testCase{ |
| 5055 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5056 | name: "ClientAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5057 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5058 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5059 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5060 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5061 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5062 | // Advertise SHA-1 so the handshake will |
| 5063 | // proceed, but the shim's preferences will be |
| 5064 | // ignored in CertificateVerify generation, so |
| 5065 | // MD5 will be chosen. |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5066 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5067 | }, |
| 5068 | Bugs: ProtocolBugs{ |
| 5069 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5070 | }, |
| 5071 | }, |
| 5072 | flags: []string{"-require-any-client-certificate"}, |
| 5073 | shouldFail: true, |
| 5074 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5075 | }) |
| 5076 | |
| 5077 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5078 | name: "ServerAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5079 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5080 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5081 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5082 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5083 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5084 | }, |
| 5085 | Bugs: ProtocolBugs{ |
| 5086 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5087 | }, |
| 5088 | }, |
| 5089 | shouldFail: true, |
| 5090 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5091 | }) |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5092 | |
| 5093 | // Test that the agreed upon digest respects the client preferences and |
| 5094 | // the server digests. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5095 | // |
| 5096 | // TODO(davidben): Add TLS 1.3 versions of these. |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5097 | testCases = append(testCases, testCase{ |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 5098 | name: "NoCommonAlgorithms", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5099 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5100 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5101 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5102 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5103 | signatureRSAPKCS1WithSHA512, |
| 5104 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5105 | }, |
| 5106 | }, |
| 5107 | flags: []string{ |
| 5108 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5109 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5110 | }, |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 5111 | digestPrefs: "SHA256", |
| 5112 | shouldFail: true, |
| 5113 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5114 | }) |
| 5115 | testCases = append(testCases, testCase{ |
| 5116 | name: "Agree-Digest-SHA256", |
| 5117 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5118 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5119 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5120 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5121 | signatureRSAPKCS1WithSHA1, |
| 5122 | signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5123 | }, |
| 5124 | }, |
| 5125 | flags: []string{ |
| 5126 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5127 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5128 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5129 | digestPrefs: "SHA256,SHA1", |
| 5130 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5131 | }) |
| 5132 | testCases = append(testCases, testCase{ |
| 5133 | name: "Agree-Digest-SHA1", |
| 5134 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5135 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5136 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5137 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5138 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5139 | }, |
| 5140 | }, |
| 5141 | flags: []string{ |
| 5142 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5143 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5144 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5145 | digestPrefs: "SHA512,SHA256,SHA1", |
| 5146 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5147 | }) |
| 5148 | testCases = append(testCases, testCase{ |
| 5149 | name: "Agree-Digest-Default", |
| 5150 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5151 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5152 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5153 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5154 | signatureRSAPKCS1WithSHA256, |
| 5155 | signatureECDSAWithP256AndSHA256, |
| 5156 | signatureRSAPKCS1WithSHA1, |
| 5157 | signatureECDSAWithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5158 | }, |
| 5159 | }, |
| 5160 | flags: []string{ |
| 5161 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5162 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5163 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5164 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5165 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5166 | |
| 5167 | // In TLS 1.2 and below, ECDSA uses the curve list rather than the |
| 5168 | // signature algorithms. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5169 | testCases = append(testCases, testCase{ |
| 5170 | name: "CheckLeafCurve", |
| 5171 | config: Config{ |
| 5172 | MaxVersion: VersionTLS12, |
| 5173 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5174 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5175 | }, |
| 5176 | flags: []string{"-p384-only"}, |
| 5177 | shouldFail: true, |
| 5178 | expectedError: ":BAD_ECC_CERT:", |
| 5179 | }) |
David Benjamin | 75ea5bb | 2016-07-08 17:43:29 -0700 | [diff] [blame] | 5180 | |
| 5181 | // In TLS 1.3, ECDSA does not use the ECDHE curve list. |
| 5182 | testCases = append(testCases, testCase{ |
| 5183 | name: "CheckLeafCurve-TLS13", |
| 5184 | config: Config{ |
| 5185 | MaxVersion: VersionTLS13, |
| 5186 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 5187 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 5188 | }, |
| 5189 | flags: []string{"-p384-only"}, |
| 5190 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5191 | |
| 5192 | // In TLS 1.2, the ECDSA curve is not in the signature algorithm. |
| 5193 | testCases = append(testCases, testCase{ |
| 5194 | name: "ECDSACurveMismatch-Verify-TLS12", |
| 5195 | config: Config{ |
| 5196 | MaxVersion: VersionTLS12, |
| 5197 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 5198 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5199 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5200 | signatureECDSAWithP384AndSHA384, |
| 5201 | }, |
| 5202 | }, |
| 5203 | }) |
| 5204 | |
| 5205 | // In TLS 1.3, the ECDSA curve comes from the signature algorithm. |
| 5206 | testCases = append(testCases, testCase{ |
| 5207 | name: "ECDSACurveMismatch-Verify-TLS13", |
| 5208 | config: Config{ |
| 5209 | MaxVersion: VersionTLS13, |
| 5210 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 5211 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5212 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5213 | signatureECDSAWithP384AndSHA384, |
| 5214 | }, |
| 5215 | Bugs: ProtocolBugs{ |
| 5216 | SkipECDSACurveCheck: true, |
| 5217 | }, |
| 5218 | }, |
| 5219 | shouldFail: true, |
| 5220 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5221 | }) |
| 5222 | |
| 5223 | // Signature algorithm selection in TLS 1.3 should take the curve into |
| 5224 | // account. |
| 5225 | testCases = append(testCases, testCase{ |
| 5226 | testType: serverTest, |
| 5227 | name: "ECDSACurveMismatch-Sign-TLS13", |
| 5228 | config: Config{ |
| 5229 | MaxVersion: VersionTLS13, |
| 5230 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5231 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5232 | signatureECDSAWithP384AndSHA384, |
| 5233 | signatureECDSAWithP256AndSHA256, |
| 5234 | }, |
| 5235 | }, |
| 5236 | flags: []string{ |
| 5237 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 5238 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 5239 | }, |
| 5240 | expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5241 | }) |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 5242 | |
| 5243 | // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the |
| 5244 | // server does not attempt to sign in that case. |
| 5245 | testCases = append(testCases, testCase{ |
| 5246 | testType: serverTest, |
| 5247 | name: "RSA-PSS-Large", |
| 5248 | config: Config{ |
| 5249 | MaxVersion: VersionTLS13, |
| 5250 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5251 | signatureRSAPSSWithSHA512, |
| 5252 | }, |
| 5253 | }, |
| 5254 | flags: []string{ |
| 5255 | "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile), |
| 5256 | "-key-file", path.Join(*resourceDir, rsa1024KeyFile), |
| 5257 | }, |
| 5258 | shouldFail: true, |
| 5259 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5260 | }) |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5261 | } |
| 5262 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5263 | // timeouts is the retransmit schedule for BoringSSL. It doubles and |
| 5264 | // caps at 60 seconds. On the 13th timeout, it gives up. |
| 5265 | var timeouts = []time.Duration{ |
| 5266 | 1 * time.Second, |
| 5267 | 2 * time.Second, |
| 5268 | 4 * time.Second, |
| 5269 | 8 * time.Second, |
| 5270 | 16 * time.Second, |
| 5271 | 32 * time.Second, |
| 5272 | 60 * time.Second, |
| 5273 | 60 * time.Second, |
| 5274 | 60 * time.Second, |
| 5275 | 60 * time.Second, |
| 5276 | 60 * time.Second, |
| 5277 | 60 * time.Second, |
| 5278 | 60 * time.Second, |
| 5279 | } |
| 5280 | |
Taylor Brandstetter | 376a0fe | 2016-05-10 19:30:28 -0700 | [diff] [blame] | 5281 | // shortTimeouts is an alternate set of timeouts which would occur if the |
| 5282 | // initial timeout duration was set to 250ms. |
| 5283 | var shortTimeouts = []time.Duration{ |
| 5284 | 250 * time.Millisecond, |
| 5285 | 500 * time.Millisecond, |
| 5286 | 1 * time.Second, |
| 5287 | 2 * time.Second, |
| 5288 | 4 * time.Second, |
| 5289 | 8 * time.Second, |
| 5290 | 16 * time.Second, |
| 5291 | 32 * time.Second, |
| 5292 | 60 * time.Second, |
| 5293 | 60 * time.Second, |
| 5294 | 60 * time.Second, |
| 5295 | 60 * time.Second, |
| 5296 | 60 * time.Second, |
| 5297 | } |
| 5298 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5299 | func addDTLSRetransmitTests() { |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5300 | // These tests work by coordinating some behavior on both the shim and |
| 5301 | // the runner. |
| 5302 | // |
| 5303 | // TimeoutSchedule configures the runner to send a series of timeout |
| 5304 | // opcodes to the shim (see packetAdaptor) immediately before reading |
| 5305 | // each peer handshake flight N. The timeout opcode both simulates a |
| 5306 | // timeout in the shim and acts as a synchronization point to help the |
| 5307 | // runner bracket each handshake flight. |
| 5308 | // |
| 5309 | // We assume the shim does not read from the channel eagerly. It must |
| 5310 | // first wait until it has sent flight N and is ready to receive |
| 5311 | // handshake flight N+1. At this point, it will process the timeout |
| 5312 | // opcode. It must then immediately respond with a timeout ACK and act |
| 5313 | // as if the shim was idle for the specified amount of time. |
| 5314 | // |
| 5315 | // The runner then drops all packets received before the ACK and |
| 5316 | // continues waiting for flight N. This ordering results in one attempt |
| 5317 | // at sending flight N to be dropped. For the test to complete, the |
| 5318 | // shim must send flight N again, testing that the shim implements DTLS |
| 5319 | // retransmit on a timeout. |
| 5320 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5321 | // TODO(davidben): Add TLS 1.3 versions of these tests. There will |
| 5322 | // likely be more epochs to cross and the final message's retransmit may |
| 5323 | // be more complex. |
| 5324 | |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5325 | for _, async := range []bool{true, false} { |
| 5326 | var tests []testCase |
| 5327 | |
| 5328 | // Test that this is indeed the timeout schedule. Stress all |
| 5329 | // four patterns of handshake. |
| 5330 | for i := 1; i < len(timeouts); i++ { |
| 5331 | number := strconv.Itoa(i) |
| 5332 | tests = append(tests, testCase{ |
| 5333 | protocol: dtls, |
| 5334 | name: "DTLS-Retransmit-Client-" + number, |
| 5335 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5336 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5337 | Bugs: ProtocolBugs{ |
| 5338 | TimeoutSchedule: timeouts[:i], |
| 5339 | }, |
| 5340 | }, |
| 5341 | resumeSession: true, |
| 5342 | }) |
| 5343 | tests = append(tests, testCase{ |
| 5344 | protocol: dtls, |
| 5345 | testType: serverTest, |
| 5346 | name: "DTLS-Retransmit-Server-" + number, |
| 5347 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5348 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5349 | Bugs: ProtocolBugs{ |
| 5350 | TimeoutSchedule: timeouts[:i], |
| 5351 | }, |
| 5352 | }, |
| 5353 | resumeSession: true, |
| 5354 | }) |
| 5355 | } |
| 5356 | |
| 5357 | // Test that exceeding the timeout schedule hits a read |
| 5358 | // timeout. |
| 5359 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5360 | protocol: dtls, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5361 | name: "DTLS-Retransmit-Timeout", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5362 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5363 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5364 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5365 | TimeoutSchedule: timeouts, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5366 | }, |
| 5367 | }, |
| 5368 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5369 | shouldFail: true, |
| 5370 | expectedError: ":READ_TIMEOUT_EXPIRED:", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5371 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5372 | |
| 5373 | if async { |
| 5374 | // Test that timeout handling has a fudge factor, due to API |
| 5375 | // problems. |
| 5376 | tests = append(tests, testCase{ |
| 5377 | protocol: dtls, |
| 5378 | name: "DTLS-Retransmit-Fudge", |
| 5379 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5380 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5381 | Bugs: ProtocolBugs{ |
| 5382 | TimeoutSchedule: []time.Duration{ |
| 5383 | timeouts[0] - 10*time.Millisecond, |
| 5384 | }, |
| 5385 | }, |
| 5386 | }, |
| 5387 | resumeSession: true, |
| 5388 | }) |
| 5389 | } |
| 5390 | |
| 5391 | // Test that the final Finished retransmitting isn't |
| 5392 | // duplicated if the peer badly fragments everything. |
| 5393 | tests = append(tests, testCase{ |
| 5394 | testType: serverTest, |
| 5395 | protocol: dtls, |
| 5396 | name: "DTLS-Retransmit-Fragmented", |
| 5397 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5398 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5399 | Bugs: ProtocolBugs{ |
| 5400 | TimeoutSchedule: []time.Duration{timeouts[0]}, |
| 5401 | MaxHandshakeRecordLength: 2, |
| 5402 | }, |
| 5403 | }, |
| 5404 | }) |
| 5405 | |
| 5406 | // Test the timeout schedule when a shorter initial timeout duration is set. |
| 5407 | tests = append(tests, testCase{ |
| 5408 | protocol: dtls, |
| 5409 | name: "DTLS-Retransmit-Short-Client", |
| 5410 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5411 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5412 | Bugs: ProtocolBugs{ |
| 5413 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
| 5414 | }, |
| 5415 | }, |
| 5416 | resumeSession: true, |
| 5417 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
| 5418 | }) |
| 5419 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5420 | protocol: dtls, |
| 5421 | testType: serverTest, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5422 | name: "DTLS-Retransmit-Short-Server", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5423 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5424 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5425 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5426 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5427 | }, |
| 5428 | }, |
| 5429 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5430 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5431 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5432 | |
| 5433 | for _, test := range tests { |
| 5434 | if async { |
| 5435 | test.name += "-Async" |
| 5436 | test.flags = append(test.flags, "-async") |
| 5437 | } |
| 5438 | |
| 5439 | testCases = append(testCases, test) |
| 5440 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5441 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5442 | } |
| 5443 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 5444 | func addExportKeyingMaterialTests() { |
| 5445 | for _, vers := range tlsVersions { |
| 5446 | if vers.version == VersionSSL30 { |
| 5447 | continue |
| 5448 | } |
| 5449 | testCases = append(testCases, testCase{ |
| 5450 | name: "ExportKeyingMaterial-" + vers.name, |
| 5451 | config: Config{ |
| 5452 | MaxVersion: vers.version, |
| 5453 | }, |
| 5454 | exportKeyingMaterial: 1024, |
| 5455 | exportLabel: "label", |
| 5456 | exportContext: "context", |
| 5457 | useExportContext: true, |
| 5458 | }) |
| 5459 | testCases = append(testCases, testCase{ |
| 5460 | name: "ExportKeyingMaterial-NoContext-" + vers.name, |
| 5461 | config: Config{ |
| 5462 | MaxVersion: vers.version, |
| 5463 | }, |
| 5464 | exportKeyingMaterial: 1024, |
| 5465 | }) |
| 5466 | testCases = append(testCases, testCase{ |
| 5467 | name: "ExportKeyingMaterial-EmptyContext-" + vers.name, |
| 5468 | config: Config{ |
| 5469 | MaxVersion: vers.version, |
| 5470 | }, |
| 5471 | exportKeyingMaterial: 1024, |
| 5472 | useExportContext: true, |
| 5473 | }) |
| 5474 | testCases = append(testCases, testCase{ |
| 5475 | name: "ExportKeyingMaterial-Small-" + vers.name, |
| 5476 | config: Config{ |
| 5477 | MaxVersion: vers.version, |
| 5478 | }, |
| 5479 | exportKeyingMaterial: 1, |
| 5480 | exportLabel: "label", |
| 5481 | exportContext: "context", |
| 5482 | useExportContext: true, |
| 5483 | }) |
| 5484 | } |
| 5485 | testCases = append(testCases, testCase{ |
| 5486 | name: "ExportKeyingMaterial-SSL3", |
| 5487 | config: Config{ |
| 5488 | MaxVersion: VersionSSL30, |
| 5489 | }, |
| 5490 | exportKeyingMaterial: 1024, |
| 5491 | exportLabel: "label", |
| 5492 | exportContext: "context", |
| 5493 | useExportContext: true, |
| 5494 | shouldFail: true, |
| 5495 | expectedError: "failed to export keying material", |
| 5496 | }) |
| 5497 | } |
| 5498 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 5499 | func addTLSUniqueTests() { |
| 5500 | for _, isClient := range []bool{false, true} { |
| 5501 | for _, isResumption := range []bool{false, true} { |
| 5502 | for _, hasEMS := range []bool{false, true} { |
| 5503 | var suffix string |
| 5504 | if isResumption { |
| 5505 | suffix = "Resume-" |
| 5506 | } else { |
| 5507 | suffix = "Full-" |
| 5508 | } |
| 5509 | |
| 5510 | if hasEMS { |
| 5511 | suffix += "EMS-" |
| 5512 | } else { |
| 5513 | suffix += "NoEMS-" |
| 5514 | } |
| 5515 | |
| 5516 | if isClient { |
| 5517 | suffix += "Client" |
| 5518 | } else { |
| 5519 | suffix += "Server" |
| 5520 | } |
| 5521 | |
| 5522 | test := testCase{ |
| 5523 | name: "TLSUnique-" + suffix, |
| 5524 | testTLSUnique: true, |
| 5525 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5526 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 5527 | Bugs: ProtocolBugs{ |
| 5528 | NoExtendedMasterSecret: !hasEMS, |
| 5529 | }, |
| 5530 | }, |
| 5531 | } |
| 5532 | |
| 5533 | if isResumption { |
| 5534 | test.resumeSession = true |
| 5535 | test.resumeConfig = &Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5536 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 5537 | Bugs: ProtocolBugs{ |
| 5538 | NoExtendedMasterSecret: !hasEMS, |
| 5539 | }, |
| 5540 | } |
| 5541 | } |
| 5542 | |
| 5543 | if isResumption && !hasEMS { |
| 5544 | test.shouldFail = true |
| 5545 | test.expectedError = "failed to get tls-unique" |
| 5546 | } |
| 5547 | |
| 5548 | testCases = append(testCases, test) |
| 5549 | } |
| 5550 | } |
| 5551 | } |
| 5552 | } |
| 5553 | |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5554 | func addCustomExtensionTests() { |
| 5555 | expectedContents := "custom extension" |
| 5556 | emptyString := "" |
| 5557 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5558 | // TODO(davidben): Add TLS 1.3 versions of these tests. |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5559 | for _, isClient := range []bool{false, true} { |
| 5560 | suffix := "Server" |
| 5561 | flag := "-enable-server-custom-extension" |
| 5562 | testType := serverTest |
| 5563 | if isClient { |
| 5564 | suffix = "Client" |
| 5565 | flag = "-enable-client-custom-extension" |
| 5566 | testType = clientTest |
| 5567 | } |
| 5568 | |
| 5569 | testCases = append(testCases, testCase{ |
| 5570 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5571 | name: "CustomExtensions-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5572 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5573 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5574 | Bugs: ProtocolBugs{ |
| 5575 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5576 | ExpectedCustomExtension: &expectedContents, |
| 5577 | }, |
| 5578 | }, |
| 5579 | flags: []string{flag}, |
| 5580 | }) |
| 5581 | |
| 5582 | // If the parse callback fails, the handshake should also fail. |
| 5583 | testCases = append(testCases, testCase{ |
| 5584 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5585 | name: "CustomExtensions-ParseError-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5586 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5587 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5588 | Bugs: ProtocolBugs{ |
| 5589 | CustomExtension: expectedContents + "foo", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5590 | ExpectedCustomExtension: &expectedContents, |
| 5591 | }, |
| 5592 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5593 | flags: []string{flag}, |
| 5594 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5595 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 5596 | }) |
| 5597 | |
| 5598 | // If the add callback fails, the handshake should also fail. |
| 5599 | testCases = append(testCases, testCase{ |
| 5600 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5601 | name: "CustomExtensions-FailAdd-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5602 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5603 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5604 | Bugs: ProtocolBugs{ |
| 5605 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5606 | ExpectedCustomExtension: &expectedContents, |
| 5607 | }, |
| 5608 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5609 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 5610 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5611 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 5612 | }) |
| 5613 | |
| 5614 | // If the add callback returns zero, no extension should be |
| 5615 | // added. |
| 5616 | skipCustomExtension := expectedContents |
| 5617 | if isClient { |
| 5618 | // For the case where the client skips sending the |
| 5619 | // custom extension, the server must not “echo” it. |
| 5620 | skipCustomExtension = "" |
| 5621 | } |
| 5622 | testCases = append(testCases, testCase{ |
| 5623 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5624 | name: "CustomExtensions-Skip-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5625 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5626 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5627 | Bugs: ProtocolBugs{ |
| 5628 | CustomExtension: skipCustomExtension, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5629 | ExpectedCustomExtension: &emptyString, |
| 5630 | }, |
| 5631 | }, |
| 5632 | flags: []string{flag, "-custom-extension-skip"}, |
| 5633 | }) |
| 5634 | } |
| 5635 | |
| 5636 | // The custom extension add callback should not be called if the client |
| 5637 | // doesn't send the extension. |
| 5638 | testCases = append(testCases, testCase{ |
| 5639 | testType: serverTest, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5640 | name: "CustomExtensions-NotCalled-Server", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5641 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5642 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 5643 | Bugs: ProtocolBugs{ |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5644 | ExpectedCustomExtension: &emptyString, |
| 5645 | }, |
| 5646 | }, |
| 5647 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 5648 | }) |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 5649 | |
| 5650 | // Test an unknown extension from the server. |
| 5651 | testCases = append(testCases, testCase{ |
| 5652 | testType: clientTest, |
| 5653 | name: "UnknownExtension-Client", |
| 5654 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5655 | MaxVersion: VersionTLS12, |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 5656 | Bugs: ProtocolBugs{ |
| 5657 | CustomExtension: expectedContents, |
| 5658 | }, |
| 5659 | }, |
| 5660 | shouldFail: true, |
| 5661 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 5662 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 5663 | } |
| 5664 | |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 5665 | func addRSAClientKeyExchangeTests() { |
| 5666 | for bad := RSABadValue(1); bad < NumRSABadValues; bad++ { |
| 5667 | testCases = append(testCases, testCase{ |
| 5668 | testType: serverTest, |
| 5669 | name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad), |
| 5670 | config: Config{ |
| 5671 | // Ensure the ClientHello version and final |
| 5672 | // version are different, to detect if the |
| 5673 | // server uses the wrong one. |
| 5674 | MaxVersion: VersionTLS11, |
| 5675 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 5676 | Bugs: ProtocolBugs{ |
| 5677 | BadRSAClientKeyExchange: bad, |
| 5678 | }, |
| 5679 | }, |
| 5680 | shouldFail: true, |
| 5681 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 5682 | }) |
| 5683 | } |
| 5684 | } |
| 5685 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 5686 | var testCurves = []struct { |
| 5687 | name string |
| 5688 | id CurveID |
| 5689 | }{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 5690 | {"P-256", CurveP256}, |
| 5691 | {"P-384", CurveP384}, |
| 5692 | {"P-521", CurveP521}, |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 5693 | {"X25519", CurveX25519}, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 5694 | } |
| 5695 | |
| 5696 | func addCurveTests() { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5697 | // TODO(davidben): Add a TLS 1.3 versions of these tests. |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 5698 | for _, curve := range testCurves { |
| 5699 | testCases = append(testCases, testCase{ |
| 5700 | name: "CurveTest-Client-" + curve.name, |
| 5701 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5702 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 5703 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5704 | CurvePreferences: []CurveID{curve.id}, |
| 5705 | }, |
| 5706 | flags: []string{"-enable-all-curves"}, |
| 5707 | }) |
| 5708 | testCases = append(testCases, testCase{ |
| 5709 | testType: serverTest, |
| 5710 | name: "CurveTest-Server-" + curve.name, |
| 5711 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5712 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 5713 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5714 | CurvePreferences: []CurveID{curve.id}, |
| 5715 | }, |
| 5716 | flags: []string{"-enable-all-curves"}, |
| 5717 | }) |
| 5718 | } |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 5719 | |
| 5720 | // The server must be tolerant to bogus curves. |
| 5721 | const bogusCurve = 0x1234 |
| 5722 | testCases = append(testCases, testCase{ |
| 5723 | testType: serverTest, |
| 5724 | name: "UnknownCurve", |
| 5725 | config: Config{ |
| 5726 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5727 | CurvePreferences: []CurveID{bogusCurve, CurveP256}, |
| 5728 | }, |
| 5729 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5730 | |
| 5731 | // The server must not consider ECDHE ciphers when there are no |
| 5732 | // supported curves. |
| 5733 | testCases = append(testCases, testCase{ |
| 5734 | testType: serverTest, |
| 5735 | name: "NoSupportedCurves", |
| 5736 | config: Config{ |
| 5737 | // TODO(davidben): Add a TLS 1.3 version of this. |
| 5738 | MaxVersion: VersionTLS12, |
| 5739 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5740 | Bugs: ProtocolBugs{ |
| 5741 | NoSupportedCurves: true, |
| 5742 | }, |
| 5743 | }, |
| 5744 | shouldFail: true, |
| 5745 | expectedError: ":NO_SHARED_CIPHER:", |
| 5746 | }) |
| 5747 | |
| 5748 | // The server must fall back to another cipher when there are no |
| 5749 | // supported curves. |
| 5750 | testCases = append(testCases, testCase{ |
| 5751 | testType: serverTest, |
| 5752 | name: "NoCommonCurves", |
| 5753 | config: Config{ |
| 5754 | MaxVersion: VersionTLS12, |
| 5755 | CipherSuites: []uint16{ |
| 5756 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 5757 | TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 5758 | }, |
| 5759 | CurvePreferences: []CurveID{CurveP224}, |
| 5760 | }, |
| 5761 | expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 5762 | }) |
| 5763 | |
| 5764 | // The client must reject bogus curves and disabled curves. |
| 5765 | testCases = append(testCases, testCase{ |
| 5766 | name: "BadECDHECurve", |
| 5767 | config: Config{ |
| 5768 | // TODO(davidben): Add a TLS 1.3 version of this. |
| 5769 | MaxVersion: VersionTLS12, |
| 5770 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5771 | Bugs: ProtocolBugs{ |
| 5772 | SendCurve: bogusCurve, |
| 5773 | }, |
| 5774 | }, |
| 5775 | shouldFail: true, |
| 5776 | expectedError: ":WRONG_CURVE:", |
| 5777 | }) |
| 5778 | |
| 5779 | testCases = append(testCases, testCase{ |
| 5780 | name: "UnsupportedCurve", |
| 5781 | config: Config{ |
| 5782 | // TODO(davidben): Add a TLS 1.3 version of this. |
| 5783 | MaxVersion: VersionTLS12, |
| 5784 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5785 | CurvePreferences: []CurveID{CurveP256}, |
| 5786 | Bugs: ProtocolBugs{ |
| 5787 | IgnorePeerCurvePreferences: true, |
| 5788 | }, |
| 5789 | }, |
| 5790 | flags: []string{"-p384-only"}, |
| 5791 | shouldFail: true, |
| 5792 | expectedError: ":WRONG_CURVE:", |
| 5793 | }) |
| 5794 | |
| 5795 | // Test invalid curve points. |
| 5796 | testCases = append(testCases, testCase{ |
| 5797 | name: "InvalidECDHPoint-Client", |
| 5798 | config: Config{ |
| 5799 | // TODO(davidben): Add a TLS 1.3 version of this test. |
| 5800 | MaxVersion: VersionTLS12, |
| 5801 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5802 | CurvePreferences: []CurveID{CurveP256}, |
| 5803 | Bugs: ProtocolBugs{ |
| 5804 | InvalidECDHPoint: true, |
| 5805 | }, |
| 5806 | }, |
| 5807 | shouldFail: true, |
| 5808 | expectedError: ":INVALID_ENCODING:", |
| 5809 | }) |
| 5810 | testCases = append(testCases, testCase{ |
| 5811 | testType: serverTest, |
| 5812 | name: "InvalidECDHPoint-Server", |
| 5813 | config: Config{ |
| 5814 | // TODO(davidben): Add a TLS 1.3 version of this test. |
| 5815 | MaxVersion: VersionTLS12, |
| 5816 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5817 | CurvePreferences: []CurveID{CurveP256}, |
| 5818 | Bugs: ProtocolBugs{ |
| 5819 | InvalidECDHPoint: true, |
| 5820 | }, |
| 5821 | }, |
| 5822 | shouldFail: true, |
| 5823 | expectedError: ":INVALID_ENCODING:", |
| 5824 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 5825 | } |
| 5826 | |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 5827 | func addCECPQ1Tests() { |
| 5828 | testCases = append(testCases, testCase{ |
| 5829 | testType: clientTest, |
| 5830 | name: "CECPQ1-Client-BadX25519Part", |
| 5831 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5832 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 5833 | MinVersion: VersionTLS12, |
| 5834 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 5835 | Bugs: ProtocolBugs{ |
| 5836 | CECPQ1BadX25519Part: true, |
| 5837 | }, |
| 5838 | }, |
| 5839 | flags: []string{"-cipher", "kCECPQ1"}, |
| 5840 | shouldFail: true, |
| 5841 | expectedLocalError: "local error: bad record MAC", |
| 5842 | }) |
| 5843 | testCases = append(testCases, testCase{ |
| 5844 | testType: clientTest, |
| 5845 | name: "CECPQ1-Client-BadNewhopePart", |
| 5846 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5847 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 5848 | MinVersion: VersionTLS12, |
| 5849 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 5850 | Bugs: ProtocolBugs{ |
| 5851 | CECPQ1BadNewhopePart: true, |
| 5852 | }, |
| 5853 | }, |
| 5854 | flags: []string{"-cipher", "kCECPQ1"}, |
| 5855 | shouldFail: true, |
| 5856 | expectedLocalError: "local error: bad record MAC", |
| 5857 | }) |
| 5858 | testCases = append(testCases, testCase{ |
| 5859 | testType: serverTest, |
| 5860 | name: "CECPQ1-Server-BadX25519Part", |
| 5861 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5862 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 5863 | MinVersion: VersionTLS12, |
| 5864 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 5865 | Bugs: ProtocolBugs{ |
| 5866 | CECPQ1BadX25519Part: true, |
| 5867 | }, |
| 5868 | }, |
| 5869 | flags: []string{"-cipher", "kCECPQ1"}, |
| 5870 | shouldFail: true, |
| 5871 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 5872 | }) |
| 5873 | testCases = append(testCases, testCase{ |
| 5874 | testType: serverTest, |
| 5875 | name: "CECPQ1-Server-BadNewhopePart", |
| 5876 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5877 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 5878 | MinVersion: VersionTLS12, |
| 5879 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 5880 | Bugs: ProtocolBugs{ |
| 5881 | CECPQ1BadNewhopePart: true, |
| 5882 | }, |
| 5883 | }, |
| 5884 | flags: []string{"-cipher", "kCECPQ1"}, |
| 5885 | shouldFail: true, |
| 5886 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 5887 | }) |
| 5888 | } |
| 5889 | |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5890 | func addKeyExchangeInfoTests() { |
| 5891 | testCases = append(testCases, testCase{ |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5892 | name: "KeyExchangeInfo-DHE-Client", |
| 5893 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5894 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5895 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5896 | Bugs: ProtocolBugs{ |
| 5897 | // This is a 1234-bit prime number, generated |
| 5898 | // with: |
| 5899 | // openssl gendh 1234 | openssl asn1parse -i |
| 5900 | DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"), |
| 5901 | }, |
| 5902 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 5903 | flags: []string{"-expect-dhe-group-size", "1234"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5904 | }) |
| 5905 | testCases = append(testCases, testCase{ |
| 5906 | testType: serverTest, |
| 5907 | name: "KeyExchangeInfo-DHE-Server", |
| 5908 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5909 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5910 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5911 | }, |
| 5912 | // bssl_shim as a server configures a 2048-bit DHE group. |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 5913 | flags: []string{"-expect-dhe-group-size", "2048"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5914 | }) |
| 5915 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5916 | // TODO(davidben): Add TLS 1.3 versions of these tests once the |
| 5917 | // handshake is separate. |
| 5918 | |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5919 | testCases = append(testCases, testCase{ |
| 5920 | name: "KeyExchangeInfo-ECDHE-Client", |
| 5921 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5922 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5923 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5924 | CurvePreferences: []CurveID{CurveX25519}, |
| 5925 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 5926 | flags: []string{"-expect-curve-id", "29", "-enable-all-curves"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5927 | }) |
| 5928 | testCases = append(testCases, testCase{ |
| 5929 | testType: serverTest, |
| 5930 | name: "KeyExchangeInfo-ECDHE-Server", |
| 5931 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 5932 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5933 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5934 | CurvePreferences: []CurveID{CurveX25519}, |
| 5935 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 5936 | flags: []string{"-expect-curve-id", "29", "-enable-all-curves"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 5937 | }) |
| 5938 | } |
| 5939 | |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 5940 | func addTLS13RecordTests() { |
| 5941 | testCases = append(testCases, testCase{ |
| 5942 | name: "TLS13-RecordPadding", |
| 5943 | config: Config{ |
| 5944 | MaxVersion: VersionTLS13, |
| 5945 | MinVersion: VersionTLS13, |
| 5946 | Bugs: ProtocolBugs{ |
| 5947 | RecordPadding: 10, |
| 5948 | }, |
| 5949 | }, |
| 5950 | }) |
| 5951 | |
| 5952 | testCases = append(testCases, testCase{ |
| 5953 | name: "TLS13-EmptyRecords", |
| 5954 | config: Config{ |
| 5955 | MaxVersion: VersionTLS13, |
| 5956 | MinVersion: VersionTLS13, |
| 5957 | Bugs: ProtocolBugs{ |
| 5958 | OmitRecordContents: true, |
| 5959 | }, |
| 5960 | }, |
| 5961 | shouldFail: true, |
| 5962 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 5963 | }) |
| 5964 | |
| 5965 | testCases = append(testCases, testCase{ |
| 5966 | name: "TLS13-OnlyPadding", |
| 5967 | config: Config{ |
| 5968 | MaxVersion: VersionTLS13, |
| 5969 | MinVersion: VersionTLS13, |
| 5970 | Bugs: ProtocolBugs{ |
| 5971 | OmitRecordContents: true, |
| 5972 | RecordPadding: 10, |
| 5973 | }, |
| 5974 | }, |
| 5975 | shouldFail: true, |
| 5976 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 5977 | }) |
| 5978 | |
| 5979 | testCases = append(testCases, testCase{ |
| 5980 | name: "TLS13-WrongOuterRecord", |
| 5981 | config: Config{ |
| 5982 | MaxVersion: VersionTLS13, |
| 5983 | MinVersion: VersionTLS13, |
| 5984 | Bugs: ProtocolBugs{ |
| 5985 | OuterRecordType: recordTypeHandshake, |
| 5986 | }, |
| 5987 | }, |
| 5988 | shouldFail: true, |
| 5989 | expectedError: ":INVALID_OUTER_RECORD_TYPE:", |
| 5990 | }) |
| 5991 | } |
| 5992 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 5993 | func addChangeCipherSpecTests() { |
| 5994 | // Test missing ChangeCipherSpecs. |
| 5995 | testCases = append(testCases, testCase{ |
| 5996 | name: "SkipChangeCipherSpec-Client", |
| 5997 | config: Config{ |
| 5998 | MaxVersion: VersionTLS12, |
| 5999 | Bugs: ProtocolBugs{ |
| 6000 | SkipChangeCipherSpec: true, |
| 6001 | }, |
| 6002 | }, |
| 6003 | shouldFail: true, |
| 6004 | expectedError: ":UNEXPECTED_RECORD:", |
| 6005 | }) |
| 6006 | testCases = append(testCases, testCase{ |
| 6007 | testType: serverTest, |
| 6008 | name: "SkipChangeCipherSpec-Server", |
| 6009 | config: Config{ |
| 6010 | MaxVersion: VersionTLS12, |
| 6011 | Bugs: ProtocolBugs{ |
| 6012 | SkipChangeCipherSpec: true, |
| 6013 | }, |
| 6014 | }, |
| 6015 | shouldFail: true, |
| 6016 | expectedError: ":UNEXPECTED_RECORD:", |
| 6017 | }) |
| 6018 | testCases = append(testCases, testCase{ |
| 6019 | testType: serverTest, |
| 6020 | name: "SkipChangeCipherSpec-Server-NPN", |
| 6021 | config: Config{ |
| 6022 | MaxVersion: VersionTLS12, |
| 6023 | NextProtos: []string{"bar"}, |
| 6024 | Bugs: ProtocolBugs{ |
| 6025 | SkipChangeCipherSpec: true, |
| 6026 | }, |
| 6027 | }, |
| 6028 | flags: []string{ |
| 6029 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 6030 | }, |
| 6031 | shouldFail: true, |
| 6032 | expectedError: ":UNEXPECTED_RECORD:", |
| 6033 | }) |
| 6034 | |
| 6035 | // Test synchronization between the handshake and ChangeCipherSpec. |
| 6036 | // Partial post-CCS handshake messages before ChangeCipherSpec should be |
| 6037 | // rejected. Test both with and without handshake packing to handle both |
| 6038 | // when the partial post-CCS message is in its own record and when it is |
| 6039 | // attached to the pre-CCS message. |
| 6040 | // |
| 6041 | // TODO(davidben): Fix and test DTLS as well. |
| 6042 | for _, packed := range []bool{false, true} { |
| 6043 | var suffix string |
| 6044 | if packed { |
| 6045 | suffix = "-Packed" |
| 6046 | } |
| 6047 | |
| 6048 | testCases = append(testCases, testCase{ |
| 6049 | name: "FragmentAcrossChangeCipherSpec-Client" + suffix, |
| 6050 | config: Config{ |
| 6051 | MaxVersion: VersionTLS12, |
| 6052 | Bugs: ProtocolBugs{ |
| 6053 | FragmentAcrossChangeCipherSpec: true, |
| 6054 | PackHandshakeFlight: packed, |
| 6055 | }, |
| 6056 | }, |
| 6057 | shouldFail: true, |
| 6058 | expectedError: ":UNEXPECTED_RECORD:", |
| 6059 | }) |
| 6060 | testCases = append(testCases, testCase{ |
| 6061 | name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix, |
| 6062 | config: Config{ |
| 6063 | MaxVersion: VersionTLS12, |
| 6064 | }, |
| 6065 | resumeSession: true, |
| 6066 | resumeConfig: &Config{ |
| 6067 | MaxVersion: VersionTLS12, |
| 6068 | Bugs: ProtocolBugs{ |
| 6069 | FragmentAcrossChangeCipherSpec: true, |
| 6070 | PackHandshakeFlight: packed, |
| 6071 | }, |
| 6072 | }, |
| 6073 | shouldFail: true, |
| 6074 | expectedError: ":UNEXPECTED_RECORD:", |
| 6075 | }) |
| 6076 | testCases = append(testCases, testCase{ |
| 6077 | testType: serverTest, |
| 6078 | name: "FragmentAcrossChangeCipherSpec-Server" + suffix, |
| 6079 | config: Config{ |
| 6080 | MaxVersion: VersionTLS12, |
| 6081 | Bugs: ProtocolBugs{ |
| 6082 | FragmentAcrossChangeCipherSpec: true, |
| 6083 | PackHandshakeFlight: packed, |
| 6084 | }, |
| 6085 | }, |
| 6086 | shouldFail: true, |
| 6087 | expectedError: ":UNEXPECTED_RECORD:", |
| 6088 | }) |
| 6089 | testCases = append(testCases, testCase{ |
| 6090 | testType: serverTest, |
| 6091 | name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix, |
| 6092 | config: Config{ |
| 6093 | MaxVersion: VersionTLS12, |
| 6094 | }, |
| 6095 | resumeSession: true, |
| 6096 | resumeConfig: &Config{ |
| 6097 | MaxVersion: VersionTLS12, |
| 6098 | Bugs: ProtocolBugs{ |
| 6099 | FragmentAcrossChangeCipherSpec: true, |
| 6100 | PackHandshakeFlight: packed, |
| 6101 | }, |
| 6102 | }, |
| 6103 | shouldFail: true, |
| 6104 | expectedError: ":UNEXPECTED_RECORD:", |
| 6105 | }) |
| 6106 | testCases = append(testCases, testCase{ |
| 6107 | testType: serverTest, |
| 6108 | name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix, |
| 6109 | config: Config{ |
| 6110 | MaxVersion: VersionTLS12, |
| 6111 | NextProtos: []string{"bar"}, |
| 6112 | Bugs: ProtocolBugs{ |
| 6113 | FragmentAcrossChangeCipherSpec: true, |
| 6114 | PackHandshakeFlight: packed, |
| 6115 | }, |
| 6116 | }, |
| 6117 | flags: []string{ |
| 6118 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 6119 | }, |
| 6120 | shouldFail: true, |
| 6121 | expectedError: ":UNEXPECTED_RECORD:", |
| 6122 | }) |
| 6123 | } |
| 6124 | |
| 6125 | // Test that early ChangeCipherSpecs are handled correctly. |
| 6126 | testCases = append(testCases, testCase{ |
| 6127 | testType: serverTest, |
| 6128 | name: "EarlyChangeCipherSpec-server-1", |
| 6129 | config: Config{ |
| 6130 | MaxVersion: VersionTLS12, |
| 6131 | Bugs: ProtocolBugs{ |
| 6132 | EarlyChangeCipherSpec: 1, |
| 6133 | }, |
| 6134 | }, |
| 6135 | shouldFail: true, |
| 6136 | expectedError: ":UNEXPECTED_RECORD:", |
| 6137 | }) |
| 6138 | testCases = append(testCases, testCase{ |
| 6139 | testType: serverTest, |
| 6140 | name: "EarlyChangeCipherSpec-server-2", |
| 6141 | config: Config{ |
| 6142 | MaxVersion: VersionTLS12, |
| 6143 | Bugs: ProtocolBugs{ |
| 6144 | EarlyChangeCipherSpec: 2, |
| 6145 | }, |
| 6146 | }, |
| 6147 | shouldFail: true, |
| 6148 | expectedError: ":UNEXPECTED_RECORD:", |
| 6149 | }) |
| 6150 | testCases = append(testCases, testCase{ |
| 6151 | protocol: dtls, |
| 6152 | name: "StrayChangeCipherSpec", |
| 6153 | config: Config{ |
| 6154 | // TODO(davidben): Once DTLS 1.3 exists, test |
| 6155 | // that stray ChangeCipherSpec messages are |
| 6156 | // rejected. |
| 6157 | MaxVersion: VersionTLS12, |
| 6158 | Bugs: ProtocolBugs{ |
| 6159 | StrayChangeCipherSpec: true, |
| 6160 | }, |
| 6161 | }, |
| 6162 | }) |
| 6163 | |
| 6164 | // Test that the contents of ChangeCipherSpec are checked. |
| 6165 | testCases = append(testCases, testCase{ |
| 6166 | name: "BadChangeCipherSpec-1", |
| 6167 | config: Config{ |
| 6168 | MaxVersion: VersionTLS12, |
| 6169 | Bugs: ProtocolBugs{ |
| 6170 | BadChangeCipherSpec: []byte{2}, |
| 6171 | }, |
| 6172 | }, |
| 6173 | shouldFail: true, |
| 6174 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 6175 | }) |
| 6176 | testCases = append(testCases, testCase{ |
| 6177 | name: "BadChangeCipherSpec-2", |
| 6178 | config: Config{ |
| 6179 | MaxVersion: VersionTLS12, |
| 6180 | Bugs: ProtocolBugs{ |
| 6181 | BadChangeCipherSpec: []byte{1, 1}, |
| 6182 | }, |
| 6183 | }, |
| 6184 | shouldFail: true, |
| 6185 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 6186 | }) |
| 6187 | testCases = append(testCases, testCase{ |
| 6188 | protocol: dtls, |
| 6189 | name: "BadChangeCipherSpec-DTLS-1", |
| 6190 | config: Config{ |
| 6191 | MaxVersion: VersionTLS12, |
| 6192 | Bugs: ProtocolBugs{ |
| 6193 | BadChangeCipherSpec: []byte{2}, |
| 6194 | }, |
| 6195 | }, |
| 6196 | shouldFail: true, |
| 6197 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 6198 | }) |
| 6199 | testCases = append(testCases, testCase{ |
| 6200 | protocol: dtls, |
| 6201 | name: "BadChangeCipherSpec-DTLS-2", |
| 6202 | config: Config{ |
| 6203 | MaxVersion: VersionTLS12, |
| 6204 | Bugs: ProtocolBugs{ |
| 6205 | BadChangeCipherSpec: []byte{1, 1}, |
| 6206 | }, |
| 6207 | }, |
| 6208 | shouldFail: true, |
| 6209 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 6210 | }) |
| 6211 | } |
| 6212 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6213 | 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] | 6214 | defer wg.Done() |
| 6215 | |
| 6216 | for test := range c { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 6217 | var err error |
| 6218 | |
| 6219 | if *mallocTest < 0 { |
| 6220 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6221 | err = runTest(test, shimPath, -1) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 6222 | } else { |
| 6223 | for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ { |
| 6224 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6225 | if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 6226 | if err != nil { |
| 6227 | fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err) |
| 6228 | } |
| 6229 | break |
| 6230 | } |
| 6231 | } |
| 6232 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6233 | statusChan <- statusMsg{test: test, err: err} |
| 6234 | } |
| 6235 | } |
| 6236 | |
| 6237 | type statusMsg struct { |
| 6238 | test *testCase |
| 6239 | started bool |
| 6240 | err error |
| 6241 | } |
| 6242 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 6243 | func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6244 | var started, done, failed, lineLen int |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6245 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 6246 | testOutput := newTestOutput() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6247 | for msg := range statusChan { |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 6248 | if !*pipe { |
| 6249 | // Erase the previous status line. |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 6250 | var erase string |
| 6251 | for i := 0; i < lineLen; i++ { |
| 6252 | erase += "\b \b" |
| 6253 | } |
| 6254 | fmt.Print(erase) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 6255 | } |
| 6256 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6257 | if msg.started { |
| 6258 | started++ |
| 6259 | } else { |
| 6260 | done++ |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 6261 | |
| 6262 | if msg.err != nil { |
| 6263 | fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err) |
| 6264 | failed++ |
| 6265 | testOutput.addResult(msg.test.name, "FAIL") |
| 6266 | } else { |
| 6267 | if *pipe { |
| 6268 | // Print each test instead of a status line. |
| 6269 | fmt.Printf("PASSED (%s)\n", msg.test.name) |
| 6270 | } |
| 6271 | testOutput.addResult(msg.test.name, "PASS") |
| 6272 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 6275 | if !*pipe { |
| 6276 | // Print a new status line. |
| 6277 | line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total) |
| 6278 | lineLen = len(line) |
| 6279 | os.Stdout.WriteString(line) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6280 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6281 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 6282 | |
| 6283 | doneChan <- testOutput |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6284 | } |
| 6285 | |
| 6286 | func main() { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6287 | flag.Parse() |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6288 | *resourceDir = path.Clean(*resourceDir) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 6289 | initCertificates() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6290 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6291 | addBasicTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6292 | addCipherSuiteTests() |
| 6293 | addBadECDSASignatureTests() |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6294 | addCBCPaddingTests() |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 6295 | addCBCSplittingTests() |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 6296 | addClientAuthTests() |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 6297 | addDDoSCallbackTests() |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 6298 | addVersionNegotiationTests() |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 6299 | addMinimumVersionTests() |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 6300 | addExtensionTests() |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 6301 | addResumptionVersionTests() |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 6302 | addExtendedMasterSecretTests() |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 6303 | addRenegotiationTests() |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 6304 | addDTLSReplayTests() |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 6305 | addSignatureAlgorithmTests() |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6306 | addDTLSRetransmitTests() |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 6307 | addExportKeyingMaterialTests() |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6308 | addTLSUniqueTests() |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6309 | addCustomExtensionTests() |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 6310 | addRSAClientKeyExchangeTests() |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6311 | addCurveTests() |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6312 | addCECPQ1Tests() |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6313 | addKeyExchangeInfoTests() |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 6314 | addTLS13RecordTests() |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 6315 | addAllStateMachineCoverageTests() |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 6316 | addChangeCipherSpecTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6317 | |
| 6318 | var wg sync.WaitGroup |
| 6319 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6320 | statusChan := make(chan statusMsg, *numWorkers) |
| 6321 | testChan := make(chan *testCase, *numWorkers) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 6322 | doneChan := make(chan *testOutput) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6323 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 6324 | go statusPrinter(doneChan, statusChan, len(testCases)) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6325 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6326 | for i := 0; i < *numWorkers; i++ { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6327 | wg.Add(1) |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6328 | go worker(statusChan, testChan, *shimPath, &wg) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6329 | } |
| 6330 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 6331 | var foundTest bool |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 6332 | for i := range testCases { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 6333 | if len(*testToRun) == 0 || *testToRun == testCases[i].name { |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 6334 | foundTest = true |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 6335 | testChan <- &testCases[i] |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6336 | } |
| 6337 | } |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 6338 | if !foundTest { |
| 6339 | fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun) |
| 6340 | os.Exit(1) |
| 6341 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6342 | |
| 6343 | close(testChan) |
| 6344 | wg.Wait() |
| 6345 | close(statusChan) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 6346 | testOutput := <-doneChan |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6347 | |
| 6348 | fmt.Printf("\n") |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 6349 | |
| 6350 | if *jsonOutput != "" { |
| 6351 | if err := testOutput.writeTo(*jsonOutput); err != nil { |
| 6352 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 6353 | } |
| 6354 | } |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 6355 | |
| 6356 | if !testOutput.allPassed { |
| 6357 | os.Exit(1) |
| 6358 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 6359 | } |