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