Adam Langley | 7fcfd3b | 2016-05-20 11:02:50 -0700 | [diff] [blame] | 1 | // Copyright (c) 2016, Google Inc. |
| 2 | // |
| 3 | // Permission to use, copy, modify, and/or distribute this software for any |
| 4 | // purpose with or without fee is hereby granted, provided that the above |
| 5 | // copyright notice and this permission notice appear in all copies. |
| 6 | // |
| 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 | |
Adam Langley | dc7e9c4 | 2015-09-29 15:21:04 -0700 | [diff] [blame] | 15 | package runner |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "bytes" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 19 | "crypto/ecdsa" |
| 20 | "crypto/elliptic" |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 21 | "crypto/x509" |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 22 | "encoding/base64" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 23 | "encoding/pem" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 24 | "flag" |
| 25 | "fmt" |
| 26 | "io" |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 27 | "io/ioutil" |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 28 | "math/big" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 29 | "net" |
| 30 | "os" |
| 31 | "os/exec" |
David Benjamin | 884fdf1 | 2014-08-02 15:28:23 -0400 | [diff] [blame] | 32 | "path" |
David Benjamin | 2bc8e6f | 2014-08-02 15:22:37 -0400 | [diff] [blame] | 33 | "runtime" |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 34 | "strconv" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 35 | "strings" |
| 36 | "sync" |
| 37 | "syscall" |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 38 | "time" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 39 | ) |
| 40 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 41 | var ( |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 42 | useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind") |
| 43 | useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb") |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 44 | useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb") |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 45 | flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection") |
| 46 | mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.") |
| 47 | mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.") |
| 48 | jsonOutput = flag.String("json-output", "", "The file to output JSON results to.") |
| 49 | pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.") |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 50 | testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests") |
| 51 | numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.") |
| 52 | shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.") |
| 53 | resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.") |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 54 | fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.") |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 55 | transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.") |
David Benjamin | 01784b4 | 2016-06-07 18:00:52 -0400 | [diff] [blame] | 56 | idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.") |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 57 | deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 58 | ) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 59 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 60 | type testCert int |
| 61 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 62 | const ( |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 63 | testCertRSA testCert = iota |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 64 | testCertRSA1024 |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 65 | testCertECDSAP256 |
| 66 | testCertECDSAP384 |
| 67 | testCertECDSAP521 |
| 68 | ) |
| 69 | |
| 70 | const ( |
| 71 | rsaCertificateFile = "cert.pem" |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 72 | rsa1024CertificateFile = "rsa_1024_cert.pem" |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 73 | ecdsaP256CertificateFile = "ecdsa_p256_cert.pem" |
| 74 | ecdsaP384CertificateFile = "ecdsa_p384_cert.pem" |
| 75 | ecdsaP521CertificateFile = "ecdsa_p521_cert.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 76 | ) |
| 77 | |
| 78 | const ( |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 79 | rsaKeyFile = "key.pem" |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 80 | rsa1024KeyFile = "rsa_1024_key.pem" |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 81 | ecdsaP256KeyFile = "ecdsa_p256_key.pem" |
| 82 | ecdsaP384KeyFile = "ecdsa_p384_key.pem" |
| 83 | ecdsaP521KeyFile = "ecdsa_p521_key.pem" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 84 | channelIDKeyFile = "channel_id_key.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 85 | ) |
| 86 | |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 87 | var ( |
| 88 | rsaCertificate Certificate |
| 89 | rsa1024Certificate Certificate |
| 90 | ecdsaP256Certificate Certificate |
| 91 | ecdsaP384Certificate Certificate |
| 92 | ecdsaP521Certificate Certificate |
| 93 | ) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 94 | |
| 95 | var testCerts = []struct { |
| 96 | id testCert |
| 97 | certFile, keyFile string |
| 98 | cert *Certificate |
| 99 | }{ |
| 100 | { |
| 101 | id: testCertRSA, |
| 102 | certFile: rsaCertificateFile, |
| 103 | keyFile: rsaKeyFile, |
| 104 | cert: &rsaCertificate, |
| 105 | }, |
| 106 | { |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 107 | id: testCertRSA1024, |
| 108 | certFile: rsa1024CertificateFile, |
| 109 | keyFile: rsa1024KeyFile, |
| 110 | cert: &rsa1024Certificate, |
| 111 | }, |
| 112 | { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 113 | id: testCertECDSAP256, |
| 114 | certFile: ecdsaP256CertificateFile, |
| 115 | keyFile: ecdsaP256KeyFile, |
| 116 | cert: &ecdsaP256Certificate, |
| 117 | }, |
| 118 | { |
| 119 | id: testCertECDSAP384, |
| 120 | certFile: ecdsaP384CertificateFile, |
| 121 | keyFile: ecdsaP384KeyFile, |
| 122 | cert: &ecdsaP384Certificate, |
| 123 | }, |
| 124 | { |
| 125 | id: testCertECDSAP521, |
| 126 | certFile: ecdsaP521CertificateFile, |
| 127 | keyFile: ecdsaP521KeyFile, |
| 128 | cert: &ecdsaP521Certificate, |
| 129 | }, |
| 130 | } |
| 131 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 132 | var channelIDKey *ecdsa.PrivateKey |
| 133 | var channelIDBytes []byte |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 134 | |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 135 | var testOCSPResponse = []byte{1, 2, 3, 4} |
| 136 | var testSCTList = []byte{5, 6, 7, 8} |
| 137 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 138 | func initCertificates() { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 139 | for i := range testCerts { |
| 140 | cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile)) |
| 141 | if err != nil { |
| 142 | panic(err) |
| 143 | } |
| 144 | cert.OCSPStaple = testOCSPResponse |
| 145 | cert.SignedCertificateTimestampList = testSCTList |
| 146 | *testCerts[i].cert = cert |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 147 | } |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 148 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 149 | channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile)) |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 150 | if err != nil { |
| 151 | panic(err) |
| 152 | } |
| 153 | channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock) |
| 154 | if channelIDDERBlock.Type != "EC PRIVATE KEY" { |
| 155 | panic("bad key type") |
| 156 | } |
| 157 | channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes) |
| 158 | if err != nil { |
| 159 | panic(err) |
| 160 | } |
| 161 | if channelIDKey.Curve != elliptic.P256() { |
| 162 | panic("bad curve") |
| 163 | } |
| 164 | |
| 165 | channelIDBytes = make([]byte, 64) |
| 166 | writeIntPadded(channelIDBytes[:32], channelIDKey.X) |
| 167 | writeIntPadded(channelIDBytes[32:], channelIDKey.Y) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 168 | } |
| 169 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 170 | func getRunnerCertificate(t testCert) Certificate { |
| 171 | for _, cert := range testCerts { |
| 172 | if cert.id == t { |
| 173 | return *cert.cert |
| 174 | } |
| 175 | } |
| 176 | panic("Unknown test certificate") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 177 | } |
| 178 | |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 179 | func getShimCertificate(t testCert) string { |
| 180 | for _, cert := range testCerts { |
| 181 | if cert.id == t { |
| 182 | return cert.certFile |
| 183 | } |
| 184 | } |
| 185 | panic("Unknown test certificate") |
| 186 | } |
| 187 | |
| 188 | func getShimKey(t testCert) string { |
| 189 | for _, cert := range testCerts { |
| 190 | if cert.id == t { |
| 191 | return cert.keyFile |
| 192 | } |
| 193 | } |
| 194 | panic("Unknown test certificate") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 195 | } |
| 196 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 197 | type testType int |
| 198 | |
| 199 | const ( |
| 200 | clientTest testType = iota |
| 201 | serverTest |
| 202 | ) |
| 203 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 204 | type protocol int |
| 205 | |
| 206 | const ( |
| 207 | tls protocol = iota |
| 208 | dtls |
| 209 | ) |
| 210 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 211 | const ( |
| 212 | alpn = 1 |
| 213 | npn = 2 |
| 214 | ) |
| 215 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 216 | type testCase struct { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 217 | testType testType |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 218 | protocol protocol |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 219 | name string |
| 220 | config Config |
| 221 | shouldFail bool |
| 222 | expectedError string |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 223 | // expectedLocalError, if not empty, contains a substring that must be |
| 224 | // found in the local error. |
| 225 | expectedLocalError string |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 226 | // expectedVersion, if non-zero, specifies the TLS version that must be |
| 227 | // negotiated. |
| 228 | expectedVersion uint16 |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 229 | // expectedResumeVersion, if non-zero, specifies the TLS version that |
| 230 | // must be negotiated on resumption. If zero, expectedVersion is used. |
| 231 | expectedResumeVersion uint16 |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 232 | // expectedCipher, if non-zero, specifies the TLS cipher suite that |
| 233 | // should be negotiated. |
| 234 | expectedCipher uint16 |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 235 | // expectChannelID controls whether the connection should have |
| 236 | // negotiated a Channel ID with channelIDKey. |
| 237 | expectChannelID bool |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 238 | // expectedNextProto controls whether the connection should |
| 239 | // negotiate a next protocol via NPN or ALPN. |
| 240 | expectedNextProto string |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 241 | // expectNoNextProto, if true, means that no next protocol should be |
| 242 | // negotiated. |
| 243 | expectNoNextProto bool |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 244 | // expectedNextProtoType, if non-zero, is the expected next |
| 245 | // protocol negotiation mechanism. |
| 246 | expectedNextProtoType int |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 247 | // expectedSRTPProtectionProfile is the DTLS-SRTP profile that |
| 248 | // should be negotiated. If zero, none should be negotiated. |
| 249 | expectedSRTPProtectionProfile uint16 |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 250 | // expectedOCSPResponse, if not nil, is the expected OCSP response to be received. |
| 251 | expectedOCSPResponse []uint8 |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 252 | // expectedSCTList, if not nil, is the expected SCT list to be received. |
| 253 | expectedSCTList []uint8 |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 254 | // expectedPeerSignatureAlgorithm, if not zero, is the signature |
| 255 | // algorithm that the peer should have used in the handshake. |
| 256 | expectedPeerSignatureAlgorithm signatureAlgorithm |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 257 | // expectedCurveID, if not zero, is the curve that the handshake should |
| 258 | // have used. |
| 259 | expectedCurveID CurveID |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 260 | // messageLen is the length, in bytes, of the test message that will be |
| 261 | // sent. |
| 262 | messageLen int |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 263 | // messageCount is the number of test messages that will be sent. |
| 264 | messageCount int |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 265 | // certFile is the path to the certificate to use for the server. |
| 266 | certFile string |
| 267 | // keyFile is the path to the private key to use for the server. |
| 268 | keyFile string |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 269 | // resumeSession controls whether a second connection should be tested |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 270 | // which attempts to resume the first session. |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 271 | resumeSession bool |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 272 | // expectResumeRejected, if true, specifies that the attempted |
| 273 | // resumption must be rejected by the client. This is only valid for a |
| 274 | // serverTest. |
| 275 | expectResumeRejected bool |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 276 | // resumeConfig, if not nil, points to a Config to be used on |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 277 | // resumption. Unless newSessionsOnResume is set, |
| 278 | // SessionTicketKey, ServerSessionCache, and |
| 279 | // ClientSessionCache are copied from the initial connection's |
| 280 | // config. If nil, the initial connection's config is used. |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 281 | resumeConfig *Config |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 282 | // newSessionsOnResume, if true, will cause resumeConfig to |
| 283 | // use a different session resumption context. |
| 284 | newSessionsOnResume bool |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 285 | // noSessionCache, if true, will cause the server to run without a |
| 286 | // session cache. |
| 287 | noSessionCache bool |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 288 | // sendPrefix sends a prefix on the socket before actually performing a |
| 289 | // handshake. |
| 290 | sendPrefix string |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 291 | // shimWritesFirst controls whether the shim sends an initial "hello" |
| 292 | // message before doing a roundtrip with the runner. |
| 293 | shimWritesFirst bool |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 294 | // shimShutsDown, if true, runs a test where the shim shuts down the |
| 295 | // connection immediately after the handshake rather than echoing |
| 296 | // messages from the runner. |
| 297 | shimShutsDown bool |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 298 | // renegotiate indicates the number of times the connection should be |
| 299 | // renegotiated during the exchange. |
| 300 | renegotiate int |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 301 | // renegotiateCiphers is a list of ciphersuite ids that will be |
| 302 | // switched in just before renegotiation. |
| 303 | renegotiateCiphers []uint16 |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 304 | // replayWrites, if true, configures the underlying transport |
| 305 | // to replay every write it makes in DTLS tests. |
| 306 | replayWrites bool |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 307 | // damageFirstWrite, if true, configures the underlying transport to |
| 308 | // damage the final byte of the first application data write. |
| 309 | damageFirstWrite bool |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 310 | // exportKeyingMaterial, if non-zero, configures the test to exchange |
| 311 | // keying material and verify they match. |
| 312 | exportKeyingMaterial int |
| 313 | exportLabel string |
| 314 | exportContext string |
| 315 | useExportContext bool |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 316 | // flags, if not empty, contains a list of command-line flags that will |
| 317 | // be passed to the shim program. |
| 318 | flags []string |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 319 | // testTLSUnique, if true, causes the shim to send the tls-unique value |
| 320 | // which will be compared against the expected value. |
| 321 | testTLSUnique bool |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 322 | // sendEmptyRecords is the number of consecutive empty records to send |
| 323 | // before and after the test message. |
| 324 | sendEmptyRecords int |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 325 | // sendWarningAlerts is the number of consecutive warning alerts to send |
| 326 | // before and after the test message. |
| 327 | sendWarningAlerts int |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 328 | // expectMessageDropped, if true, means the test message is expected to |
| 329 | // be dropped by the client rather than echoed back. |
| 330 | expectMessageDropped bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 333 | var testCases []testCase |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 334 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 335 | func writeTranscript(test *testCase, isResume bool, data []byte) { |
| 336 | if len(data) == 0 { |
| 337 | return |
| 338 | } |
| 339 | |
| 340 | protocol := "tls" |
| 341 | if test.protocol == dtls { |
| 342 | protocol = "dtls" |
| 343 | } |
| 344 | |
| 345 | side := "client" |
| 346 | if test.testType == serverTest { |
| 347 | side = "server" |
| 348 | } |
| 349 | |
| 350 | dir := path.Join(*transcriptDir, protocol, side) |
| 351 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 352 | fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err) |
| 353 | return |
| 354 | } |
| 355 | |
| 356 | name := test.name |
| 357 | if isResume { |
| 358 | name += "-Resume" |
| 359 | } else { |
| 360 | name += "-Normal" |
| 361 | } |
| 362 | |
| 363 | if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil { |
| 364 | fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err) |
| 365 | } |
| 366 | } |
| 367 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 368 | // A timeoutConn implements an idle timeout on each Read and Write operation. |
| 369 | type timeoutConn struct { |
| 370 | net.Conn |
| 371 | timeout time.Duration |
| 372 | } |
| 373 | |
| 374 | func (t *timeoutConn) Read(b []byte) (int, error) { |
| 375 | if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil { |
| 376 | return 0, err |
| 377 | } |
| 378 | return t.Conn.Read(b) |
| 379 | } |
| 380 | |
| 381 | func (t *timeoutConn) Write(b []byte) (int, error) { |
| 382 | if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil { |
| 383 | return 0, err |
| 384 | } |
| 385 | return t.Conn.Write(b) |
| 386 | } |
| 387 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 388 | func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error { |
David Benjamin | 01784b4 | 2016-06-07 18:00:52 -0400 | [diff] [blame] | 389 | conn = &timeoutConn{conn, *idleTimeout} |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 390 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 391 | if test.protocol == dtls { |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 392 | config.Bugs.PacketAdaptor = newPacketAdaptor(conn) |
| 393 | conn = config.Bugs.PacketAdaptor |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 394 | } |
| 395 | |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 396 | if *flagDebug || len(*transcriptDir) != 0 { |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 397 | local, peer := "client", "server" |
| 398 | if test.testType == clientTest { |
| 399 | local, peer = peer, local |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 400 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 401 | connDebug := &recordingConn{ |
| 402 | Conn: conn, |
| 403 | isDatagram: test.protocol == dtls, |
| 404 | local: local, |
| 405 | peer: peer, |
| 406 | } |
| 407 | conn = connDebug |
David Benjamin | 9867b7d | 2016-03-01 23:25:48 -0500 | [diff] [blame] | 408 | if *flagDebug { |
| 409 | defer connDebug.WriteTo(os.Stdout) |
| 410 | } |
| 411 | if len(*transcriptDir) != 0 { |
| 412 | defer func() { |
| 413 | writeTranscript(test, isResume, connDebug.Transcript()) |
| 414 | }() |
| 415 | } |
David Benjamin | ebda9b3 | 2015-11-02 15:33:18 -0500 | [diff] [blame] | 416 | |
| 417 | if config.Bugs.PacketAdaptor != nil { |
| 418 | config.Bugs.PacketAdaptor.debug = connDebug |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | if test.replayWrites { |
| 423 | conn = newReplayAdaptor(conn) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 424 | } |
| 425 | |
David Benjamin | 3ed5977 | 2016-03-08 12:50:21 -0500 | [diff] [blame] | 426 | var connDamage *damageAdaptor |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 427 | if test.damageFirstWrite { |
| 428 | connDamage = newDamageAdaptor(conn) |
| 429 | conn = connDamage |
| 430 | } |
| 431 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 432 | if test.sendPrefix != "" { |
| 433 | if _, err := conn.Write([]byte(test.sendPrefix)); err != nil { |
| 434 | return err |
| 435 | } |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 436 | } |
| 437 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 438 | var tlsConn *Conn |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 439 | if test.testType == clientTest { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 440 | if test.protocol == dtls { |
| 441 | tlsConn = DTLSServer(conn, config) |
| 442 | } else { |
| 443 | tlsConn = Server(conn, config) |
| 444 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 445 | } else { |
| 446 | config.InsecureSkipVerify = true |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 447 | if test.protocol == dtls { |
| 448 | tlsConn = DTLSClient(conn, config) |
| 449 | } else { |
| 450 | tlsConn = Client(conn, config) |
| 451 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 452 | } |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 453 | defer tlsConn.Close() |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 454 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 455 | if err := tlsConn.Handshake(); err != nil { |
| 456 | return err |
| 457 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 458 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 459 | // TODO(davidben): move all per-connection expectations into a dedicated |
| 460 | // expectations struct that can be specified separately for the two |
| 461 | // legs. |
| 462 | expectedVersion := test.expectedVersion |
| 463 | if isResume && test.expectedResumeVersion != 0 { |
| 464 | expectedVersion = test.expectedResumeVersion |
| 465 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 466 | connState := tlsConn.ConnectionState() |
| 467 | if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 468 | return fmt.Errorf("got version %x, expected %x", vers, expectedVersion) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 469 | } |
| 470 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 471 | if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher { |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 472 | return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher) |
| 473 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 474 | if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected { |
| 475 | return fmt.Errorf("didResume is %t, but we expected the opposite", didResume) |
| 476 | } |
David Benjamin | 90da8c8 | 2015-04-20 14:57:57 -0400 | [diff] [blame] | 477 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 478 | if test.expectChannelID { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 479 | channelID := connState.ChannelID |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 480 | if channelID == nil { |
| 481 | return fmt.Errorf("no channel ID negotiated") |
| 482 | } |
| 483 | if channelID.Curve != channelIDKey.Curve || |
| 484 | channelIDKey.X.Cmp(channelIDKey.X) != 0 || |
| 485 | channelIDKey.Y.Cmp(channelIDKey.Y) != 0 { |
| 486 | return fmt.Errorf("incorrect channel ID") |
| 487 | } |
| 488 | } |
| 489 | |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 490 | if expected := test.expectedNextProto; expected != "" { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 491 | if actual := connState.NegotiatedProtocol; actual != expected { |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 492 | return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected) |
| 493 | } |
| 494 | } |
| 495 | |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 496 | if test.expectNoNextProto { |
| 497 | if actual := connState.NegotiatedProtocol; actual != "" { |
| 498 | return fmt.Errorf("got unexpected next proto %s", actual) |
| 499 | } |
| 500 | } |
| 501 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 502 | if test.expectedNextProtoType != 0 { |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 503 | if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN { |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 504 | return fmt.Errorf("next proto type mismatch") |
| 505 | } |
| 506 | } |
| 507 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 508 | if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile { |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 509 | return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile) |
| 510 | } |
| 511 | |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 512 | if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) { |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 513 | return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 514 | } |
| 515 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 516 | if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) { |
| 517 | return fmt.Errorf("SCT list mismatch") |
| 518 | } |
| 519 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 520 | if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm { |
| 521 | 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] | 522 | } |
| 523 | |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 524 | if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID { |
| 525 | return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID) |
| 526 | } |
| 527 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 528 | if test.exportKeyingMaterial > 0 { |
| 529 | actual := make([]byte, test.exportKeyingMaterial) |
| 530 | if _, err := io.ReadFull(tlsConn, actual); err != nil { |
| 531 | return err |
| 532 | } |
| 533 | expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext) |
| 534 | if err != nil { |
| 535 | return err |
| 536 | } |
| 537 | if !bytes.Equal(actual, expected) { |
| 538 | return fmt.Errorf("keying material mismatch") |
| 539 | } |
| 540 | } |
| 541 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 542 | if test.testTLSUnique { |
| 543 | var peersValue [12]byte |
| 544 | if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil { |
| 545 | return err |
| 546 | } |
| 547 | expected := tlsConn.ConnectionState().TLSUnique |
| 548 | if !bytes.Equal(peersValue[:], expected) { |
| 549 | return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected) |
| 550 | } |
| 551 | } |
| 552 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 553 | if test.shimWritesFirst { |
| 554 | var buf [5]byte |
| 555 | _, err := io.ReadFull(tlsConn, buf[:]) |
| 556 | if err != nil { |
| 557 | return err |
| 558 | } |
| 559 | if string(buf[:]) != "hello" { |
| 560 | return fmt.Errorf("bad initial message") |
| 561 | } |
| 562 | } |
| 563 | |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 564 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 565 | tlsConn.Write(nil) |
| 566 | } |
| 567 | |
David Benjamin | 24f346d | 2015-06-06 03:28:08 -0400 | [diff] [blame] | 568 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 569 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 570 | } |
| 571 | |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 572 | if test.renegotiate > 0 { |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 573 | if test.renegotiateCiphers != nil { |
| 574 | config.CipherSuites = test.renegotiateCiphers |
| 575 | } |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 576 | for i := 0; i < test.renegotiate; i++ { |
| 577 | if err := tlsConn.Renegotiate(); err != nil { |
| 578 | return err |
| 579 | } |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 580 | } |
| 581 | } else if test.renegotiateCiphers != nil { |
| 582 | panic("renegotiateCiphers without renegotiate") |
| 583 | } |
| 584 | |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 585 | if test.damageFirstWrite { |
| 586 | connDamage.setDamage(true) |
| 587 | tlsConn.Write([]byte("DAMAGED WRITE")) |
| 588 | connDamage.setDamage(false) |
| 589 | } |
| 590 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 591 | messageLen := test.messageLen |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 592 | if messageLen < 0 { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 593 | if test.protocol == dtls { |
| 594 | return fmt.Errorf("messageLen < 0 not supported for DTLS tests") |
| 595 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 596 | // Read until EOF. |
| 597 | _, err := io.Copy(ioutil.Discard, tlsConn) |
| 598 | return err |
| 599 | } |
David Benjamin | 4417d05 | 2015-04-05 04:17:25 -0400 | [diff] [blame] | 600 | if messageLen == 0 { |
| 601 | messageLen = 32 |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 602 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 603 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 604 | messageCount := test.messageCount |
| 605 | if messageCount == 0 { |
| 606 | messageCount = 1 |
David Benjamin | a8ebe22 | 2015-06-06 03:04:39 -0400 | [diff] [blame] | 607 | } |
| 608 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 609 | for j := 0; j < messageCount; j++ { |
| 610 | testMessage := make([]byte, messageLen) |
| 611 | for i := range testMessage { |
| 612 | testMessage[i] = 0x42 ^ byte(j) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 613 | } |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 614 | tlsConn.Write(testMessage) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 615 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 616 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 617 | tlsConn.Write(nil) |
| 618 | } |
| 619 | |
| 620 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 621 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 622 | } |
| 623 | |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 624 | if test.shimShutsDown || test.expectMessageDropped { |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 625 | // The shim will not respond. |
| 626 | continue |
| 627 | } |
| 628 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 629 | buf := make([]byte, len(testMessage)) |
| 630 | if test.protocol == dtls { |
| 631 | bufTmp := make([]byte, len(buf)+1) |
| 632 | n, err := tlsConn.Read(bufTmp) |
| 633 | if err != nil { |
| 634 | return err |
| 635 | } |
| 636 | if n != len(buf) { |
| 637 | return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf)) |
| 638 | } |
| 639 | copy(buf, bufTmp) |
| 640 | } else { |
| 641 | _, err := io.ReadFull(tlsConn, buf) |
| 642 | if err != nil { |
| 643 | return err |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | for i, v := range buf { |
| 648 | if v != testMessage[i]^0xff { |
| 649 | return fmt.Errorf("bad reply contents at byte %d", i) |
| 650 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
| 654 | return nil |
| 655 | } |
| 656 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 657 | func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd { |
| 658 | valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"} |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 659 | if dbAttach { |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 660 | 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] | 661 | } |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 662 | valgrindArgs = append(valgrindArgs, path) |
| 663 | valgrindArgs = append(valgrindArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 664 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 665 | return exec.Command("valgrind", valgrindArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 666 | } |
| 667 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 668 | func gdbOf(path string, args ...string) *exec.Cmd { |
| 669 | xtermArgs := []string{"-e", "gdb", "--args"} |
| 670 | xtermArgs = append(xtermArgs, path) |
| 671 | xtermArgs = append(xtermArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 672 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 673 | return exec.Command("xterm", xtermArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 674 | } |
| 675 | |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 676 | func lldbOf(path string, args ...string) *exec.Cmd { |
| 677 | xtermArgs := []string{"-e", "lldb", "--"} |
| 678 | xtermArgs = append(xtermArgs, path) |
| 679 | xtermArgs = append(xtermArgs, args...) |
| 680 | |
| 681 | return exec.Command("xterm", xtermArgs...) |
| 682 | } |
| 683 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 684 | type moreMallocsError struct{} |
| 685 | |
| 686 | func (moreMallocsError) Error() string { |
| 687 | return "child process did not exhaust all allocation calls" |
| 688 | } |
| 689 | |
| 690 | var errMoreMallocs = moreMallocsError{} |
| 691 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 692 | // accept accepts a connection from listener, unless waitChan signals a process |
| 693 | // exit first. |
| 694 | func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) { |
| 695 | type connOrError struct { |
| 696 | conn net.Conn |
| 697 | err error |
| 698 | } |
| 699 | connChan := make(chan connOrError, 1) |
| 700 | go func() { |
| 701 | conn, err := listener.Accept() |
| 702 | connChan <- connOrError{conn, err} |
| 703 | close(connChan) |
| 704 | }() |
| 705 | select { |
| 706 | case result := <-connChan: |
| 707 | return result.conn, result.err |
| 708 | case childErr := <-waitChan: |
| 709 | waitChan <- childErr |
| 710 | return nil, fmt.Errorf("child exited early: %s", childErr) |
| 711 | } |
| 712 | } |
| 713 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 714 | func runTest(test *testCase, shimPath string, mallocNumToFail int64) error { |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 715 | if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) { |
| 716 | panic("Error expected without shouldFail in " + test.name) |
| 717 | } |
| 718 | |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 719 | if test.expectResumeRejected && !test.resumeSession { |
| 720 | panic("expectResumeRejected without resumeSession in " + test.name) |
| 721 | } |
| 722 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 723 | listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}}) |
| 724 | if err != nil { |
| 725 | panic(err) |
| 726 | } |
| 727 | defer func() { |
| 728 | if listener != nil { |
| 729 | listener.Close() |
| 730 | } |
| 731 | }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 732 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 733 | flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)} |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 734 | if test.testType == serverTest { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 735 | flags = append(flags, "-server") |
| 736 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 737 | flags = append(flags, "-key-file") |
| 738 | if test.keyFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 739 | flags = append(flags, path.Join(*resourceDir, rsaKeyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 740 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 741 | flags = append(flags, path.Join(*resourceDir, test.keyFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | flags = append(flags, "-cert-file") |
| 745 | if test.certFile == "" { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 746 | flags = append(flags, path.Join(*resourceDir, rsaCertificateFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 747 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 748 | flags = append(flags, path.Join(*resourceDir, test.certFile)) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 749 | } |
| 750 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 751 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 752 | if test.protocol == dtls { |
| 753 | flags = append(flags, "-dtls") |
| 754 | } |
| 755 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 756 | if test.resumeSession { |
| 757 | flags = append(flags, "-resume") |
| 758 | } |
| 759 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 760 | if test.shimWritesFirst { |
| 761 | flags = append(flags, "-shim-writes-first") |
| 762 | } |
| 763 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 764 | if test.shimShutsDown { |
| 765 | flags = append(flags, "-shim-shuts-down") |
| 766 | } |
| 767 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 768 | if test.exportKeyingMaterial > 0 { |
| 769 | flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial)) |
| 770 | flags = append(flags, "-export-label", test.exportLabel) |
| 771 | flags = append(flags, "-export-context", test.exportContext) |
| 772 | if test.useExportContext { |
| 773 | flags = append(flags, "-use-export-context") |
| 774 | } |
| 775 | } |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 776 | if test.expectResumeRejected { |
| 777 | flags = append(flags, "-expect-session-miss") |
| 778 | } |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 779 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 780 | if test.testTLSUnique { |
| 781 | flags = append(flags, "-tls-unique") |
| 782 | } |
| 783 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 784 | flags = append(flags, test.flags...) |
| 785 | |
| 786 | var shim *exec.Cmd |
| 787 | if *useValgrind { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 788 | shim = valgrindOf(false, shimPath, flags...) |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 789 | } else if *useGDB { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 790 | shim = gdbOf(shimPath, flags...) |
David Benjamin | d16bf34 | 2015-12-18 00:53:12 -0500 | [diff] [blame] | 791 | } else if *useLLDB { |
| 792 | shim = lldbOf(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 793 | } else { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 794 | shim = exec.Command(shimPath, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 795 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 796 | shim.Stdin = os.Stdin |
| 797 | var stdoutBuf, stderrBuf bytes.Buffer |
| 798 | shim.Stdout = &stdoutBuf |
| 799 | shim.Stderr = &stderrBuf |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 800 | if mallocNumToFail >= 0 { |
David Benjamin | 9e128b0 | 2015-02-09 13:13:09 -0500 | [diff] [blame] | 801 | shim.Env = os.Environ() |
| 802 | shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10)) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 803 | if *mallocTestDebug { |
David Benjamin | 184494d | 2015-06-12 18:23:47 -0400 | [diff] [blame] | 804 | shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1") |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 805 | } |
| 806 | shim.Env = append(shim.Env, "_MALLOC_CHECK=1") |
| 807 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 808 | |
| 809 | if err := shim.Start(); err != nil { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 810 | panic(err) |
| 811 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 812 | waitChan := make(chan error, 1) |
| 813 | go func() { waitChan <- shim.Wait() }() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 814 | |
| 815 | config := test.config |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 816 | if !test.noSessionCache { |
| 817 | config.ClientSessionCache = NewLRUClientSessionCache(1) |
| 818 | config.ServerSessionCache = NewLRUServerSessionCache(1) |
| 819 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 820 | if test.testType == clientTest { |
| 821 | if len(config.Certificates) == 0 { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 822 | config.Certificates = []Certificate{rsaCertificate} |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 823 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 824 | } else { |
| 825 | // Supply a ServerName to ensure a constant session cache key, |
| 826 | // rather than falling back to net.Conn.RemoteAddr. |
| 827 | if len(config.ServerName) == 0 { |
| 828 | config.ServerName = "test" |
| 829 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 830 | } |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 831 | if *fuzzer { |
| 832 | config.Bugs.NullAllCiphers = true |
| 833 | } |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 834 | if *deterministic { |
| 835 | config.Rand = &deterministicRand{} |
| 836 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 837 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 838 | conn, err := acceptOrWait(listener, waitChan) |
| 839 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 840 | err = doExchange(test, &config, conn, false /* not a resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 841 | conn.Close() |
| 842 | } |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 843 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 844 | if err == nil && test.resumeSession { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 845 | var resumeConfig Config |
| 846 | if test.resumeConfig != nil { |
| 847 | resumeConfig = *test.resumeConfig |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 848 | if len(resumeConfig.ServerName) == 0 { |
| 849 | resumeConfig.ServerName = config.ServerName |
| 850 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 851 | if len(resumeConfig.Certificates) == 0 { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 852 | resumeConfig.Certificates = []Certificate{rsaCertificate} |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 853 | } |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 854 | if test.newSessionsOnResume { |
| 855 | if !test.noSessionCache { |
| 856 | resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1) |
| 857 | resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1) |
| 858 | } |
| 859 | } else { |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 860 | resumeConfig.SessionTicketKey = config.SessionTicketKey |
| 861 | resumeConfig.ClientSessionCache = config.ClientSessionCache |
| 862 | resumeConfig.ServerSessionCache = config.ServerSessionCache |
| 863 | } |
David Benjamin | f2b8363 | 2016-03-01 22:57:46 -0500 | [diff] [blame] | 864 | if *fuzzer { |
| 865 | resumeConfig.Bugs.NullAllCiphers = true |
| 866 | } |
David Benjamin | 2e045a9 | 2016-06-08 13:09:56 -0400 | [diff] [blame] | 867 | resumeConfig.Rand = config.Rand |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 868 | } else { |
| 869 | resumeConfig = config |
| 870 | } |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 871 | var connResume net.Conn |
| 872 | connResume, err = acceptOrWait(listener, waitChan) |
| 873 | if err == nil { |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 874 | err = doExchange(test, &resumeConfig, connResume, true /* resumption */) |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 875 | connResume.Close() |
| 876 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 877 | } |
| 878 | |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 879 | // Close the listener now. This is to avoid hangs should the shim try to |
| 880 | // open more connections than expected. |
| 881 | listener.Close() |
| 882 | listener = nil |
| 883 | |
| 884 | childErr := <-waitChan |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 885 | if exitError, ok := childErr.(*exec.ExitError); ok { |
| 886 | if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 { |
| 887 | return errMoreMallocs |
| 888 | } |
| 889 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 890 | |
David Benjamin | 9bea349 | 2016-03-02 10:59:16 -0500 | [diff] [blame] | 891 | // Account for Windows line endings. |
| 892 | stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1) |
| 893 | stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1) |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 894 | |
| 895 | // Separate the errors from the shim and those from tools like |
| 896 | // AddressSanitizer. |
| 897 | var extraStderr string |
| 898 | if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 { |
| 899 | stderr = stderrParts[0] |
| 900 | extraStderr = stderrParts[1] |
| 901 | } |
| 902 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 903 | failed := err != nil || childErr != nil |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 904 | correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError) |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 905 | localError := "none" |
| 906 | if err != nil { |
| 907 | localError = err.Error() |
| 908 | } |
| 909 | if len(test.expectedLocalError) != 0 { |
| 910 | correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError) |
| 911 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 912 | |
| 913 | if failed != test.shouldFail || failed && !correctFailure { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 914 | childError := "none" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 915 | if childErr != nil { |
| 916 | childError = childErr.Error() |
| 917 | } |
| 918 | |
| 919 | var msg string |
| 920 | switch { |
| 921 | case failed && !test.shouldFail: |
| 922 | msg = "unexpected failure" |
| 923 | case !failed && test.shouldFail: |
| 924 | msg = "unexpected success" |
| 925 | case failed && !correctFailure: |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 926 | msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 927 | default: |
| 928 | panic("internal error") |
| 929 | } |
| 930 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 931 | return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 932 | } |
| 933 | |
David Benjamin | ff3a149 | 2016-03-02 10:12:06 -0500 | [diff] [blame] | 934 | if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) { |
| 935 | return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | return nil |
| 939 | } |
| 940 | |
| 941 | var tlsVersions = []struct { |
| 942 | name string |
| 943 | version uint16 |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 944 | flag string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 945 | hasDTLS bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 946 | }{ |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 947 | {"SSL3", VersionSSL30, "-no-ssl3", false}, |
| 948 | {"TLS1", VersionTLS10, "-no-tls1", true}, |
| 949 | {"TLS11", VersionTLS11, "-no-tls11", false}, |
| 950 | {"TLS12", VersionTLS12, "-no-tls12", true}, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 951 | {"TLS13", VersionTLS13, "-no-tls13", false}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | var testCipherSuites = []struct { |
| 955 | name string |
| 956 | id uint16 |
| 957 | }{ |
| 958 | {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 959 | {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 960 | {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 961 | {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 962 | {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 963 | {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 964 | {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 965 | {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 966 | {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 967 | {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 968 | {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384}, |
| 969 | {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 970 | {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 971 | {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 972 | {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 973 | {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}, |
| 974 | {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 975 | {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 976 | {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 977 | {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 978 | {"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] | 979 | {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 980 | {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 981 | {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 982 | {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 983 | {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 984 | {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 985 | {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384}, |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 986 | {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
David Benjamin | e320392 | 2015-12-09 21:21:31 -0500 | [diff] [blame] | 987 | {"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] | 988 | {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA}, |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 989 | {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 990 | {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 991 | {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 992 | {"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] | 993 | {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 994 | {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA}, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 995 | {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 996 | {"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] | 997 | {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256}, |
Steven Valdez | 3084e7b | 2016-06-02 12:07:20 -0400 | [diff] [blame] | 998 | {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256}, |
| 999 | {"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] | 1000 | {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1001 | {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1002 | {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA}, |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1003 | {"NULL-SHA", TLS_RSA_WITH_NULL_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1006 | func hasComponent(suiteName, component string) bool { |
| 1007 | return strings.Contains("-"+suiteName+"-", "-"+component+"-") |
| 1008 | } |
| 1009 | |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1010 | func isTLS12Only(suiteName string) bool { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1011 | return hasComponent(suiteName, "GCM") || |
| 1012 | hasComponent(suiteName, "SHA256") || |
David Benjamin | e9a80ff | 2015-04-07 00:46:46 -0400 | [diff] [blame] | 1013 | hasComponent(suiteName, "SHA384") || |
| 1014 | hasComponent(suiteName, "POLY1305") |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1015 | } |
| 1016 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1017 | func isTLS13Suite(suiteName string) bool { |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 1018 | // Only AEADs. |
| 1019 | if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") { |
| 1020 | return false |
| 1021 | } |
| 1022 | // No old CHACHA20_POLY1305. |
| 1023 | if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") { |
| 1024 | return false |
| 1025 | } |
| 1026 | // Must have ECDHE. |
| 1027 | // TODO(davidben,svaldez): Add pure PSK support. |
| 1028 | if !hasComponent(suiteName, "ECDHE") { |
| 1029 | return false |
| 1030 | } |
| 1031 | // TODO(davidben,svaldez): Add PSK support. |
| 1032 | if hasComponent(suiteName, "PSK") { |
| 1033 | return false |
| 1034 | } |
| 1035 | return true |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1038 | func isDTLSCipher(suiteName string) bool { |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1039 | return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL") |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 1042 | func bigFromHex(hex string) *big.Int { |
| 1043 | ret, ok := new(big.Int).SetString(hex, 16) |
| 1044 | if !ok { |
| 1045 | panic("failed to parse hex number 0x" + hex) |
| 1046 | } |
| 1047 | return ret |
| 1048 | } |
| 1049 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1050 | func addBasicTests() { |
| 1051 | basicTests := []testCase{ |
| 1052 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1053 | name: "NoFallbackSCSV", |
| 1054 | config: Config{ |
| 1055 | Bugs: ProtocolBugs{ |
| 1056 | FailIfNotFallbackSCSV: true, |
| 1057 | }, |
| 1058 | }, |
| 1059 | shouldFail: true, |
| 1060 | expectedLocalError: "no fallback SCSV found", |
| 1061 | }, |
| 1062 | { |
| 1063 | name: "SendFallbackSCSV", |
| 1064 | config: Config{ |
| 1065 | Bugs: ProtocolBugs{ |
| 1066 | FailIfNotFallbackSCSV: true, |
| 1067 | }, |
| 1068 | }, |
| 1069 | flags: []string{"-fallback-scsv"}, |
| 1070 | }, |
| 1071 | { |
| 1072 | name: "ClientCertificateTypes", |
| 1073 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1074 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1075 | ClientAuth: RequestClientCert, |
| 1076 | ClientCertificateTypes: []byte{ |
| 1077 | CertTypeDSSSign, |
| 1078 | CertTypeRSASign, |
| 1079 | CertTypeECDSASign, |
| 1080 | }, |
| 1081 | }, |
| 1082 | flags: []string{ |
| 1083 | "-expect-certificate-types", |
| 1084 | base64.StdEncoding.EncodeToString([]byte{ |
| 1085 | CertTypeDSSSign, |
| 1086 | CertTypeRSASign, |
| 1087 | CertTypeECDSASign, |
| 1088 | }), |
| 1089 | }, |
| 1090 | }, |
| 1091 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1092 | name: "UnauthenticatedECDH", |
| 1093 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1094 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1095 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1096 | Bugs: ProtocolBugs{ |
| 1097 | UnauthenticatedECDH: true, |
| 1098 | }, |
| 1099 | }, |
| 1100 | shouldFail: true, |
| 1101 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1102 | }, |
| 1103 | { |
| 1104 | name: "SkipCertificateStatus", |
| 1105 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1106 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1107 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1108 | Bugs: ProtocolBugs{ |
| 1109 | SkipCertificateStatus: true, |
| 1110 | }, |
| 1111 | }, |
| 1112 | flags: []string{ |
| 1113 | "-enable-ocsp-stapling", |
| 1114 | }, |
| 1115 | }, |
| 1116 | { |
| 1117 | name: "SkipServerKeyExchange", |
| 1118 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1119 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1120 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1121 | Bugs: ProtocolBugs{ |
| 1122 | SkipServerKeyExchange: true, |
| 1123 | }, |
| 1124 | }, |
| 1125 | shouldFail: true, |
| 1126 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1127 | }, |
| 1128 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1129 | testType: serverTest, |
| 1130 | name: "Alert", |
| 1131 | config: Config{ |
| 1132 | Bugs: ProtocolBugs{ |
| 1133 | SendSpuriousAlert: alertRecordOverflow, |
| 1134 | }, |
| 1135 | }, |
| 1136 | shouldFail: true, |
| 1137 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1138 | }, |
| 1139 | { |
| 1140 | protocol: dtls, |
| 1141 | testType: serverTest, |
| 1142 | name: "Alert-DTLS", |
| 1143 | config: Config{ |
| 1144 | Bugs: ProtocolBugs{ |
| 1145 | SendSpuriousAlert: alertRecordOverflow, |
| 1146 | }, |
| 1147 | }, |
| 1148 | shouldFail: true, |
| 1149 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1150 | }, |
| 1151 | { |
| 1152 | testType: serverTest, |
| 1153 | name: "FragmentAlert", |
| 1154 | config: Config{ |
| 1155 | Bugs: ProtocolBugs{ |
| 1156 | FragmentAlert: true, |
| 1157 | SendSpuriousAlert: alertRecordOverflow, |
| 1158 | }, |
| 1159 | }, |
| 1160 | shouldFail: true, |
| 1161 | expectedError: ":BAD_ALERT:", |
| 1162 | }, |
| 1163 | { |
| 1164 | protocol: dtls, |
| 1165 | testType: serverTest, |
| 1166 | name: "FragmentAlert-DTLS", |
| 1167 | config: Config{ |
| 1168 | Bugs: ProtocolBugs{ |
| 1169 | FragmentAlert: true, |
| 1170 | SendSpuriousAlert: alertRecordOverflow, |
| 1171 | }, |
| 1172 | }, |
| 1173 | shouldFail: true, |
| 1174 | expectedError: ":BAD_ALERT:", |
| 1175 | }, |
| 1176 | { |
| 1177 | testType: serverTest, |
David Benjamin | 0d3a8c6 | 2016-03-11 22:25:18 -0500 | [diff] [blame] | 1178 | name: "DoubleAlert", |
| 1179 | config: Config{ |
| 1180 | Bugs: ProtocolBugs{ |
| 1181 | DoubleAlert: true, |
| 1182 | SendSpuriousAlert: alertRecordOverflow, |
| 1183 | }, |
| 1184 | }, |
| 1185 | shouldFail: true, |
| 1186 | expectedError: ":BAD_ALERT:", |
| 1187 | }, |
| 1188 | { |
| 1189 | protocol: dtls, |
| 1190 | testType: serverTest, |
| 1191 | name: "DoubleAlert-DTLS", |
| 1192 | config: Config{ |
| 1193 | Bugs: ProtocolBugs{ |
| 1194 | DoubleAlert: true, |
| 1195 | SendSpuriousAlert: alertRecordOverflow, |
| 1196 | }, |
| 1197 | }, |
| 1198 | shouldFail: true, |
| 1199 | expectedError: ":BAD_ALERT:", |
| 1200 | }, |
| 1201 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1202 | name: "SkipNewSessionTicket", |
| 1203 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1204 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1205 | Bugs: ProtocolBugs{ |
| 1206 | SkipNewSessionTicket: true, |
| 1207 | }, |
| 1208 | }, |
| 1209 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1210 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1211 | }, |
| 1212 | { |
| 1213 | testType: serverTest, |
| 1214 | name: "FallbackSCSV", |
| 1215 | config: Config{ |
| 1216 | MaxVersion: VersionTLS11, |
| 1217 | Bugs: ProtocolBugs{ |
| 1218 | SendFallbackSCSV: true, |
| 1219 | }, |
| 1220 | }, |
| 1221 | shouldFail: true, |
| 1222 | expectedError: ":INAPPROPRIATE_FALLBACK:", |
| 1223 | }, |
| 1224 | { |
| 1225 | testType: serverTest, |
| 1226 | name: "FallbackSCSV-VersionMatch", |
| 1227 | config: Config{ |
| 1228 | Bugs: ProtocolBugs{ |
| 1229 | SendFallbackSCSV: true, |
| 1230 | }, |
| 1231 | }, |
| 1232 | }, |
| 1233 | { |
| 1234 | testType: serverTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1235 | name: "FallbackSCSV-VersionMatch-TLS12", |
| 1236 | config: Config{ |
| 1237 | MaxVersion: VersionTLS12, |
| 1238 | Bugs: ProtocolBugs{ |
| 1239 | SendFallbackSCSV: true, |
| 1240 | }, |
| 1241 | }, |
| 1242 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 1243 | }, |
| 1244 | { |
| 1245 | testType: serverTest, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1246 | name: "FragmentedClientVersion", |
| 1247 | config: Config{ |
| 1248 | Bugs: ProtocolBugs{ |
| 1249 | MaxHandshakeRecordLength: 1, |
| 1250 | FragmentClientVersion: true, |
| 1251 | }, |
| 1252 | }, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1253 | expectedVersion: VersionTLS13, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1254 | }, |
| 1255 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1256 | testType: serverTest, |
| 1257 | name: "HttpGET", |
| 1258 | sendPrefix: "GET / HTTP/1.0\n", |
| 1259 | shouldFail: true, |
| 1260 | expectedError: ":HTTP_REQUEST:", |
| 1261 | }, |
| 1262 | { |
| 1263 | testType: serverTest, |
| 1264 | name: "HttpPOST", |
| 1265 | sendPrefix: "POST / HTTP/1.0\n", |
| 1266 | shouldFail: true, |
| 1267 | expectedError: ":HTTP_REQUEST:", |
| 1268 | }, |
| 1269 | { |
| 1270 | testType: serverTest, |
| 1271 | name: "HttpHEAD", |
| 1272 | sendPrefix: "HEAD / HTTP/1.0\n", |
| 1273 | shouldFail: true, |
| 1274 | expectedError: ":HTTP_REQUEST:", |
| 1275 | }, |
| 1276 | { |
| 1277 | testType: serverTest, |
| 1278 | name: "HttpPUT", |
| 1279 | sendPrefix: "PUT / HTTP/1.0\n", |
| 1280 | shouldFail: true, |
| 1281 | expectedError: ":HTTP_REQUEST:", |
| 1282 | }, |
| 1283 | { |
| 1284 | testType: serverTest, |
| 1285 | name: "HttpCONNECT", |
| 1286 | sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n", |
| 1287 | shouldFail: true, |
| 1288 | expectedError: ":HTTPS_PROXY_REQUEST:", |
| 1289 | }, |
| 1290 | { |
| 1291 | testType: serverTest, |
| 1292 | name: "Garbage", |
| 1293 | sendPrefix: "blah", |
| 1294 | shouldFail: true, |
David Benjamin | 97760d5 | 2015-07-24 23:02:49 -0400 | [diff] [blame] | 1295 | expectedError: ":WRONG_VERSION_NUMBER:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1296 | }, |
| 1297 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1298 | name: "RSAEphemeralKey", |
| 1299 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1300 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1301 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 1302 | Bugs: ProtocolBugs{ |
| 1303 | RSAEphemeralKey: true, |
| 1304 | }, |
| 1305 | }, |
| 1306 | shouldFail: true, |
| 1307 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1308 | }, |
| 1309 | { |
| 1310 | name: "DisableEverything", |
Steven Valdez | 4f94b1c | 2016-05-24 12:31:07 -0400 | [diff] [blame] | 1311 | flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1312 | shouldFail: true, |
| 1313 | expectedError: ":WRONG_SSL_VERSION:", |
| 1314 | }, |
| 1315 | { |
| 1316 | protocol: dtls, |
| 1317 | name: "DisableEverything-DTLS", |
| 1318 | flags: []string{"-no-tls12", "-no-tls1"}, |
| 1319 | shouldFail: true, |
| 1320 | expectedError: ":WRONG_SSL_VERSION:", |
| 1321 | }, |
| 1322 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1323 | protocol: dtls, |
| 1324 | testType: serverTest, |
| 1325 | name: "MTU", |
| 1326 | config: Config{ |
| 1327 | Bugs: ProtocolBugs{ |
| 1328 | MaxPacketLength: 256, |
| 1329 | }, |
| 1330 | }, |
| 1331 | flags: []string{"-mtu", "256"}, |
| 1332 | }, |
| 1333 | { |
| 1334 | protocol: dtls, |
| 1335 | testType: serverTest, |
| 1336 | name: "MTUExceeded", |
| 1337 | config: Config{ |
| 1338 | Bugs: ProtocolBugs{ |
| 1339 | MaxPacketLength: 255, |
| 1340 | }, |
| 1341 | }, |
| 1342 | flags: []string{"-mtu", "256"}, |
| 1343 | shouldFail: true, |
| 1344 | expectedLocalError: "dtls: exceeded maximum packet length", |
| 1345 | }, |
| 1346 | { |
| 1347 | name: "CertMismatchRSA", |
| 1348 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1349 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1350 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1351 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1352 | Bugs: ProtocolBugs{ |
| 1353 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1354 | }, |
| 1355 | }, |
| 1356 | shouldFail: true, |
| 1357 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1358 | }, |
| 1359 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1360 | name: "CertMismatchRSA-TLS13", |
| 1361 | config: Config{ |
| 1362 | MaxVersion: VersionTLS13, |
| 1363 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1364 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 1365 | Bugs: ProtocolBugs{ |
| 1366 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 1367 | }, |
| 1368 | }, |
| 1369 | shouldFail: true, |
| 1370 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1371 | }, |
| 1372 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1373 | name: "CertMismatchECDSA", |
| 1374 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1375 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1376 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 1377 | Certificates: []Certificate{rsaCertificate}, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1378 | Bugs: ProtocolBugs{ |
| 1379 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1380 | }, |
| 1381 | }, |
| 1382 | shouldFail: true, |
| 1383 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1384 | }, |
| 1385 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1386 | name: "CertMismatchECDSA-TLS13", |
| 1387 | config: Config{ |
| 1388 | MaxVersion: VersionTLS13, |
| 1389 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1390 | Certificates: []Certificate{rsaCertificate}, |
| 1391 | Bugs: ProtocolBugs{ |
| 1392 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 1393 | }, |
| 1394 | }, |
| 1395 | shouldFail: true, |
| 1396 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 1397 | }, |
| 1398 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1399 | name: "EmptyCertificateList", |
| 1400 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1401 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1402 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1403 | Bugs: ProtocolBugs{ |
| 1404 | EmptyCertificateList: true, |
| 1405 | }, |
| 1406 | }, |
| 1407 | shouldFail: true, |
| 1408 | expectedError: ":DECODE_ERROR:", |
| 1409 | }, |
| 1410 | { |
David Benjamin | 9ec1c75 | 2016-07-14 12:45:01 -0400 | [diff] [blame] | 1411 | name: "EmptyCertificateList-TLS13", |
| 1412 | config: Config{ |
| 1413 | MaxVersion: VersionTLS13, |
| 1414 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1415 | Bugs: ProtocolBugs{ |
| 1416 | EmptyCertificateList: true, |
| 1417 | }, |
| 1418 | }, |
| 1419 | shouldFail: true, |
| 1420 | expectedError: ":DECODE_ERROR:", |
| 1421 | }, |
| 1422 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1423 | name: "TLSFatalBadPackets", |
| 1424 | damageFirstWrite: true, |
| 1425 | shouldFail: true, |
| 1426 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 1427 | }, |
| 1428 | { |
| 1429 | protocol: dtls, |
| 1430 | name: "DTLSIgnoreBadPackets", |
| 1431 | damageFirstWrite: true, |
| 1432 | }, |
| 1433 | { |
| 1434 | protocol: dtls, |
| 1435 | name: "DTLSIgnoreBadPackets-Async", |
| 1436 | damageFirstWrite: true, |
| 1437 | flags: []string{"-async"}, |
| 1438 | }, |
| 1439 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1440 | name: "AppDataBeforeHandshake", |
| 1441 | config: Config{ |
| 1442 | Bugs: ProtocolBugs{ |
| 1443 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1444 | }, |
| 1445 | }, |
| 1446 | shouldFail: true, |
| 1447 | expectedError: ":UNEXPECTED_RECORD:", |
| 1448 | }, |
| 1449 | { |
| 1450 | name: "AppDataBeforeHandshake-Empty", |
| 1451 | config: Config{ |
| 1452 | Bugs: ProtocolBugs{ |
| 1453 | AppDataBeforeHandshake: []byte{}, |
| 1454 | }, |
| 1455 | }, |
| 1456 | shouldFail: true, |
| 1457 | expectedError: ":UNEXPECTED_RECORD:", |
| 1458 | }, |
| 1459 | { |
| 1460 | protocol: dtls, |
| 1461 | name: "AppDataBeforeHandshake-DTLS", |
| 1462 | config: Config{ |
| 1463 | Bugs: ProtocolBugs{ |
| 1464 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 1465 | }, |
| 1466 | }, |
| 1467 | shouldFail: true, |
| 1468 | expectedError: ":UNEXPECTED_RECORD:", |
| 1469 | }, |
| 1470 | { |
| 1471 | protocol: dtls, |
| 1472 | name: "AppDataBeforeHandshake-DTLS-Empty", |
| 1473 | config: Config{ |
| 1474 | Bugs: ProtocolBugs{ |
| 1475 | AppDataBeforeHandshake: []byte{}, |
| 1476 | }, |
| 1477 | }, |
| 1478 | shouldFail: true, |
| 1479 | expectedError: ":UNEXPECTED_RECORD:", |
| 1480 | }, |
| 1481 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1482 | name: "AppDataAfterChangeCipherSpec", |
| 1483 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1484 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1485 | Bugs: ProtocolBugs{ |
| 1486 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1487 | }, |
| 1488 | }, |
| 1489 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1490 | expectedError: ":UNEXPECTED_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1491 | }, |
| 1492 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1493 | name: "AppDataAfterChangeCipherSpec-Empty", |
| 1494 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1495 | MaxVersion: VersionTLS12, |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1496 | Bugs: ProtocolBugs{ |
| 1497 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1498 | }, |
| 1499 | }, |
| 1500 | shouldFail: true, |
David Benjamin | a41280d | 2015-11-26 02:16:49 -0500 | [diff] [blame] | 1501 | expectedError: ":UNEXPECTED_RECORD:", |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1502 | }, |
| 1503 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1504 | protocol: dtls, |
| 1505 | name: "AppDataAfterChangeCipherSpec-DTLS", |
| 1506 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1507 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1508 | Bugs: ProtocolBugs{ |
| 1509 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 1510 | }, |
| 1511 | }, |
| 1512 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1513 | // application data. |
| 1514 | }, |
| 1515 | { |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1516 | protocol: dtls, |
| 1517 | name: "AppDataAfterChangeCipherSpec-DTLS-Empty", |
| 1518 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1519 | MaxVersion: VersionTLS12, |
David Benjamin | 4cf369b | 2015-08-22 01:35:43 -0400 | [diff] [blame] | 1520 | Bugs: ProtocolBugs{ |
| 1521 | AppDataAfterChangeCipherSpec: []byte{}, |
| 1522 | }, |
| 1523 | }, |
| 1524 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 1525 | // application data. |
| 1526 | }, |
| 1527 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1528 | name: "AlertAfterChangeCipherSpec", |
| 1529 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1530 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1531 | Bugs: ProtocolBugs{ |
| 1532 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1533 | }, |
| 1534 | }, |
| 1535 | shouldFail: true, |
| 1536 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1537 | }, |
| 1538 | { |
| 1539 | protocol: dtls, |
| 1540 | name: "AlertAfterChangeCipherSpec-DTLS", |
| 1541 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1542 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1543 | Bugs: ProtocolBugs{ |
| 1544 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 1545 | }, |
| 1546 | }, |
| 1547 | shouldFail: true, |
| 1548 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1549 | }, |
| 1550 | { |
| 1551 | protocol: dtls, |
| 1552 | name: "ReorderHandshakeFragments-Small-DTLS", |
| 1553 | config: Config{ |
| 1554 | Bugs: ProtocolBugs{ |
| 1555 | ReorderHandshakeFragments: true, |
| 1556 | // Small enough that every handshake message is |
| 1557 | // fragmented. |
| 1558 | MaxHandshakeRecordLength: 2, |
| 1559 | }, |
| 1560 | }, |
| 1561 | }, |
| 1562 | { |
| 1563 | protocol: dtls, |
| 1564 | name: "ReorderHandshakeFragments-Large-DTLS", |
| 1565 | config: Config{ |
| 1566 | Bugs: ProtocolBugs{ |
| 1567 | ReorderHandshakeFragments: true, |
| 1568 | // Large enough that no handshake message is |
| 1569 | // fragmented. |
| 1570 | MaxHandshakeRecordLength: 2048, |
| 1571 | }, |
| 1572 | }, |
| 1573 | }, |
| 1574 | { |
| 1575 | protocol: dtls, |
| 1576 | name: "MixCompleteMessageWithFragments-DTLS", |
| 1577 | config: Config{ |
| 1578 | Bugs: ProtocolBugs{ |
| 1579 | ReorderHandshakeFragments: true, |
| 1580 | MixCompleteMessageWithFragments: true, |
| 1581 | MaxHandshakeRecordLength: 2, |
| 1582 | }, |
| 1583 | }, |
| 1584 | }, |
| 1585 | { |
| 1586 | name: "SendInvalidRecordType", |
| 1587 | config: Config{ |
| 1588 | Bugs: ProtocolBugs{ |
| 1589 | SendInvalidRecordType: true, |
| 1590 | }, |
| 1591 | }, |
| 1592 | shouldFail: true, |
| 1593 | expectedError: ":UNEXPECTED_RECORD:", |
| 1594 | }, |
| 1595 | { |
| 1596 | protocol: dtls, |
| 1597 | name: "SendInvalidRecordType-DTLS", |
| 1598 | config: Config{ |
| 1599 | Bugs: ProtocolBugs{ |
| 1600 | SendInvalidRecordType: true, |
| 1601 | }, |
| 1602 | }, |
| 1603 | shouldFail: true, |
| 1604 | expectedError: ":UNEXPECTED_RECORD:", |
| 1605 | }, |
| 1606 | { |
| 1607 | name: "FalseStart-SkipServerSecondLeg", |
| 1608 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1609 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1610 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1611 | NextProtos: []string{"foo"}, |
| 1612 | Bugs: ProtocolBugs{ |
| 1613 | SkipNewSessionTicket: true, |
| 1614 | SkipChangeCipherSpec: true, |
| 1615 | SkipFinished: true, |
| 1616 | ExpectFalseStart: true, |
| 1617 | }, |
| 1618 | }, |
| 1619 | flags: []string{ |
| 1620 | "-false-start", |
| 1621 | "-handshake-never-done", |
| 1622 | "-advertise-alpn", "\x03foo", |
| 1623 | }, |
| 1624 | shimWritesFirst: true, |
| 1625 | shouldFail: true, |
| 1626 | expectedError: ":UNEXPECTED_RECORD:", |
| 1627 | }, |
| 1628 | { |
| 1629 | name: "FalseStart-SkipServerSecondLeg-Implicit", |
| 1630 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1631 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1632 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1633 | NextProtos: []string{"foo"}, |
| 1634 | Bugs: ProtocolBugs{ |
| 1635 | SkipNewSessionTicket: true, |
| 1636 | SkipChangeCipherSpec: true, |
| 1637 | SkipFinished: true, |
| 1638 | }, |
| 1639 | }, |
| 1640 | flags: []string{ |
| 1641 | "-implicit-handshake", |
| 1642 | "-false-start", |
| 1643 | "-handshake-never-done", |
| 1644 | "-advertise-alpn", "\x03foo", |
| 1645 | }, |
| 1646 | shouldFail: true, |
| 1647 | expectedError: ":UNEXPECTED_RECORD:", |
| 1648 | }, |
| 1649 | { |
| 1650 | testType: serverTest, |
| 1651 | name: "FailEarlyCallback", |
| 1652 | flags: []string{"-fail-early-callback"}, |
| 1653 | shouldFail: true, |
| 1654 | expectedError: ":CONNECTION_REJECTED:", |
| 1655 | expectedLocalError: "remote error: access denied", |
| 1656 | }, |
| 1657 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1658 | protocol: dtls, |
| 1659 | name: "FragmentMessageTypeMismatch-DTLS", |
| 1660 | config: Config{ |
| 1661 | Bugs: ProtocolBugs{ |
| 1662 | MaxHandshakeRecordLength: 2, |
| 1663 | FragmentMessageTypeMismatch: true, |
| 1664 | }, |
| 1665 | }, |
| 1666 | shouldFail: true, |
| 1667 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1668 | }, |
| 1669 | { |
| 1670 | protocol: dtls, |
| 1671 | name: "FragmentMessageLengthMismatch-DTLS", |
| 1672 | config: Config{ |
| 1673 | Bugs: ProtocolBugs{ |
| 1674 | MaxHandshakeRecordLength: 2, |
| 1675 | FragmentMessageLengthMismatch: true, |
| 1676 | }, |
| 1677 | }, |
| 1678 | shouldFail: true, |
| 1679 | expectedError: ":FRAGMENT_MISMATCH:", |
| 1680 | }, |
| 1681 | { |
| 1682 | protocol: dtls, |
| 1683 | name: "SplitFragments-Header-DTLS", |
| 1684 | config: Config{ |
| 1685 | Bugs: ProtocolBugs{ |
| 1686 | SplitFragments: 2, |
| 1687 | }, |
| 1688 | }, |
| 1689 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1690 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1691 | }, |
| 1692 | { |
| 1693 | protocol: dtls, |
| 1694 | name: "SplitFragments-Boundary-DTLS", |
| 1695 | config: Config{ |
| 1696 | Bugs: ProtocolBugs{ |
| 1697 | SplitFragments: dtlsRecordHeaderLen, |
| 1698 | }, |
| 1699 | }, |
| 1700 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1701 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1702 | }, |
| 1703 | { |
| 1704 | protocol: dtls, |
| 1705 | name: "SplitFragments-Body-DTLS", |
| 1706 | config: Config{ |
| 1707 | Bugs: ProtocolBugs{ |
| 1708 | SplitFragments: dtlsRecordHeaderLen + 1, |
| 1709 | }, |
| 1710 | }, |
| 1711 | shouldFail: true, |
David Benjamin | c660417 | 2016-06-02 16:38:35 -0400 | [diff] [blame] | 1712 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1713 | }, |
| 1714 | { |
| 1715 | protocol: dtls, |
| 1716 | name: "SendEmptyFragments-DTLS", |
| 1717 | config: Config{ |
| 1718 | Bugs: ProtocolBugs{ |
| 1719 | SendEmptyFragments: true, |
| 1720 | }, |
| 1721 | }, |
| 1722 | }, |
| 1723 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1724 | name: "BadFinished-Client", |
| 1725 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1726 | MaxVersion: VersionTLS12, |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1727 | Bugs: ProtocolBugs{ |
| 1728 | BadFinished: true, |
| 1729 | }, |
| 1730 | }, |
| 1731 | shouldFail: true, |
| 1732 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1733 | }, |
| 1734 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1735 | name: "BadFinished-Client-TLS13", |
| 1736 | config: Config{ |
| 1737 | MaxVersion: VersionTLS13, |
| 1738 | Bugs: ProtocolBugs{ |
| 1739 | BadFinished: true, |
| 1740 | }, |
| 1741 | }, |
| 1742 | shouldFail: true, |
| 1743 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1744 | }, |
| 1745 | { |
David Benjamin | bf82aed | 2016-03-01 22:57:40 -0500 | [diff] [blame] | 1746 | testType: serverTest, |
| 1747 | name: "BadFinished-Server", |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1748 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1749 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1750 | Bugs: ProtocolBugs{ |
| 1751 | BadFinished: true, |
| 1752 | }, |
| 1753 | }, |
| 1754 | shouldFail: true, |
| 1755 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1756 | }, |
| 1757 | { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1758 | testType: serverTest, |
| 1759 | name: "BadFinished-Server-TLS13", |
| 1760 | config: Config{ |
| 1761 | MaxVersion: VersionTLS13, |
| 1762 | Bugs: ProtocolBugs{ |
| 1763 | BadFinished: true, |
| 1764 | }, |
| 1765 | }, |
| 1766 | shouldFail: true, |
| 1767 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1768 | }, |
| 1769 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1770 | name: "FalseStart-BadFinished", |
| 1771 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1772 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1773 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1774 | NextProtos: []string{"foo"}, |
| 1775 | Bugs: ProtocolBugs{ |
| 1776 | BadFinished: true, |
| 1777 | ExpectFalseStart: true, |
| 1778 | }, |
| 1779 | }, |
| 1780 | flags: []string{ |
| 1781 | "-false-start", |
| 1782 | "-handshake-never-done", |
| 1783 | "-advertise-alpn", "\x03foo", |
| 1784 | }, |
| 1785 | shimWritesFirst: true, |
| 1786 | shouldFail: true, |
| 1787 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 1788 | }, |
| 1789 | { |
| 1790 | name: "NoFalseStart-NoALPN", |
| 1791 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1792 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1793 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1794 | Bugs: ProtocolBugs{ |
| 1795 | ExpectFalseStart: true, |
| 1796 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1797 | }, |
| 1798 | }, |
| 1799 | flags: []string{ |
| 1800 | "-false-start", |
| 1801 | }, |
| 1802 | shimWritesFirst: true, |
| 1803 | shouldFail: true, |
| 1804 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1805 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1806 | }, |
| 1807 | { |
| 1808 | name: "NoFalseStart-NoAEAD", |
| 1809 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1810 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1811 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1812 | NextProtos: []string{"foo"}, |
| 1813 | Bugs: ProtocolBugs{ |
| 1814 | ExpectFalseStart: true, |
| 1815 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1816 | }, |
| 1817 | }, |
| 1818 | flags: []string{ |
| 1819 | "-false-start", |
| 1820 | "-advertise-alpn", "\x03foo", |
| 1821 | }, |
| 1822 | shimWritesFirst: true, |
| 1823 | shouldFail: true, |
| 1824 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1825 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1826 | }, |
| 1827 | { |
| 1828 | name: "NoFalseStart-RSA", |
| 1829 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1830 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1831 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1832 | NextProtos: []string{"foo"}, |
| 1833 | Bugs: ProtocolBugs{ |
| 1834 | ExpectFalseStart: true, |
| 1835 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1836 | }, |
| 1837 | }, |
| 1838 | flags: []string{ |
| 1839 | "-false-start", |
| 1840 | "-advertise-alpn", "\x03foo", |
| 1841 | }, |
| 1842 | shimWritesFirst: true, |
| 1843 | shouldFail: true, |
| 1844 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1845 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1846 | }, |
| 1847 | { |
| 1848 | name: "NoFalseStart-DHE_RSA", |
| 1849 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1850 | MaxVersion: VersionTLS12, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1851 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1852 | NextProtos: []string{"foo"}, |
| 1853 | Bugs: ProtocolBugs{ |
| 1854 | ExpectFalseStart: true, |
| 1855 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 1856 | }, |
| 1857 | }, |
| 1858 | flags: []string{ |
| 1859 | "-false-start", |
| 1860 | "-advertise-alpn", "\x03foo", |
| 1861 | }, |
| 1862 | shimWritesFirst: true, |
| 1863 | shouldFail: true, |
| 1864 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 1865 | expectedLocalError: "tls: peer did not false start: EOF", |
| 1866 | }, |
| 1867 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1868 | protocol: dtls, |
| 1869 | name: "SendSplitAlert-Sync", |
| 1870 | config: Config{ |
| 1871 | Bugs: ProtocolBugs{ |
| 1872 | SendSplitAlert: true, |
| 1873 | }, |
| 1874 | }, |
| 1875 | }, |
| 1876 | { |
| 1877 | protocol: dtls, |
| 1878 | name: "SendSplitAlert-Async", |
| 1879 | config: Config{ |
| 1880 | Bugs: ProtocolBugs{ |
| 1881 | SendSplitAlert: true, |
| 1882 | }, |
| 1883 | }, |
| 1884 | flags: []string{"-async"}, |
| 1885 | }, |
| 1886 | { |
| 1887 | protocol: dtls, |
| 1888 | name: "PackDTLSHandshake", |
| 1889 | config: Config{ |
| 1890 | Bugs: ProtocolBugs{ |
| 1891 | MaxHandshakeRecordLength: 2, |
| 1892 | PackHandshakeFragments: 20, |
| 1893 | PackHandshakeRecords: 200, |
| 1894 | }, |
| 1895 | }, |
| 1896 | }, |
| 1897 | { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 1898 | name: "SendEmptyRecords-Pass", |
| 1899 | sendEmptyRecords: 32, |
| 1900 | }, |
| 1901 | { |
| 1902 | name: "SendEmptyRecords", |
| 1903 | sendEmptyRecords: 33, |
| 1904 | shouldFail: true, |
| 1905 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1906 | }, |
| 1907 | { |
| 1908 | name: "SendEmptyRecords-Async", |
| 1909 | sendEmptyRecords: 33, |
| 1910 | flags: []string{"-async"}, |
| 1911 | shouldFail: true, |
| 1912 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 1913 | }, |
| 1914 | { |
| 1915 | name: "SendWarningAlerts-Pass", |
| 1916 | sendWarningAlerts: 4, |
| 1917 | }, |
| 1918 | { |
| 1919 | protocol: dtls, |
| 1920 | name: "SendWarningAlerts-DTLS-Pass", |
| 1921 | sendWarningAlerts: 4, |
| 1922 | }, |
| 1923 | { |
| 1924 | name: "SendWarningAlerts", |
| 1925 | sendWarningAlerts: 5, |
| 1926 | shouldFail: true, |
| 1927 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 1928 | }, |
| 1929 | { |
| 1930 | name: "SendWarningAlerts-Async", |
| 1931 | sendWarningAlerts: 5, |
| 1932 | flags: []string{"-async"}, |
| 1933 | shouldFail: true, |
| 1934 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 1935 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 1936 | { |
| 1937 | name: "EmptySessionID", |
| 1938 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 1939 | MaxVersion: VersionTLS12, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 1940 | SessionTicketsDisabled: true, |
| 1941 | }, |
| 1942 | noSessionCache: true, |
| 1943 | flags: []string{"-expect-no-session"}, |
| 1944 | }, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 1945 | { |
| 1946 | name: "Unclean-Shutdown", |
| 1947 | config: Config{ |
| 1948 | Bugs: ProtocolBugs{ |
| 1949 | NoCloseNotify: true, |
| 1950 | ExpectCloseNotify: true, |
| 1951 | }, |
| 1952 | }, |
| 1953 | shimShutsDown: true, |
| 1954 | flags: []string{"-check-close-notify"}, |
| 1955 | shouldFail: true, |
| 1956 | expectedError: "Unexpected SSL_shutdown result: -1 != 1", |
| 1957 | }, |
| 1958 | { |
| 1959 | name: "Unclean-Shutdown-Ignored", |
| 1960 | config: Config{ |
| 1961 | Bugs: ProtocolBugs{ |
| 1962 | NoCloseNotify: true, |
| 1963 | }, |
| 1964 | }, |
| 1965 | shimShutsDown: true, |
| 1966 | }, |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 1967 | { |
David Benjamin | fa214e4 | 2016-05-10 17:03:10 -0400 | [diff] [blame] | 1968 | name: "Unclean-Shutdown-Alert", |
| 1969 | config: Config{ |
| 1970 | Bugs: ProtocolBugs{ |
| 1971 | SendAlertOnShutdown: alertDecompressionFailure, |
| 1972 | ExpectCloseNotify: true, |
| 1973 | }, |
| 1974 | }, |
| 1975 | shimShutsDown: true, |
| 1976 | flags: []string{"-check-close-notify"}, |
| 1977 | shouldFail: true, |
| 1978 | expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:", |
| 1979 | }, |
| 1980 | { |
David Benjamin | 4f75aaf | 2015-09-01 16:53:10 -0400 | [diff] [blame] | 1981 | name: "LargePlaintext", |
| 1982 | config: Config{ |
| 1983 | Bugs: ProtocolBugs{ |
| 1984 | SendLargeRecords: true, |
| 1985 | }, |
| 1986 | }, |
| 1987 | messageLen: maxPlaintext + 1, |
| 1988 | shouldFail: true, |
| 1989 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 1990 | }, |
| 1991 | { |
| 1992 | protocol: dtls, |
| 1993 | name: "LargePlaintext-DTLS", |
| 1994 | config: Config{ |
| 1995 | Bugs: ProtocolBugs{ |
| 1996 | SendLargeRecords: true, |
| 1997 | }, |
| 1998 | }, |
| 1999 | messageLen: maxPlaintext + 1, |
| 2000 | shouldFail: true, |
| 2001 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2002 | }, |
| 2003 | { |
| 2004 | name: "LargeCiphertext", |
| 2005 | config: Config{ |
| 2006 | Bugs: ProtocolBugs{ |
| 2007 | SendLargeRecords: true, |
| 2008 | }, |
| 2009 | }, |
| 2010 | messageLen: maxPlaintext * 2, |
| 2011 | shouldFail: true, |
| 2012 | expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:", |
| 2013 | }, |
| 2014 | { |
| 2015 | protocol: dtls, |
| 2016 | name: "LargeCiphertext-DTLS", |
| 2017 | config: Config{ |
| 2018 | Bugs: ProtocolBugs{ |
| 2019 | SendLargeRecords: true, |
| 2020 | }, |
| 2021 | }, |
| 2022 | messageLen: maxPlaintext * 2, |
| 2023 | // Unlike the other four cases, DTLS drops records which |
| 2024 | // are invalid before authentication, so the connection |
| 2025 | // does not fail. |
| 2026 | expectMessageDropped: true, |
| 2027 | }, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2028 | { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2029 | // In TLS 1.2 and below, empty NewSessionTicket messages |
| 2030 | // mean the server changed its mind on sending a ticket. |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2031 | name: "SendEmptySessionTicket", |
| 2032 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2033 | MaxVersion: VersionTLS12, |
David Benjamin | dd6fed9 | 2015-10-23 17:41:12 -0400 | [diff] [blame] | 2034 | Bugs: ProtocolBugs{ |
| 2035 | SendEmptySessionTicket: true, |
| 2036 | FailIfSessionOffered: true, |
| 2037 | }, |
| 2038 | }, |
| 2039 | flags: []string{"-expect-no-session"}, |
| 2040 | resumeSession: true, |
| 2041 | expectResumeRejected: true, |
| 2042 | }, |
David Benjamin | 99fdfb9 | 2015-11-02 12:11:35 -0500 | [diff] [blame] | 2043 | { |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2044 | name: "BadHelloRequest-1", |
| 2045 | renegotiate: 1, |
| 2046 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2047 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2048 | Bugs: ProtocolBugs{ |
| 2049 | BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1}, |
| 2050 | }, |
| 2051 | }, |
| 2052 | flags: []string{ |
| 2053 | "-renegotiate-freely", |
| 2054 | "-expect-total-renegotiations", "1", |
| 2055 | }, |
| 2056 | shouldFail: true, |
| 2057 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2058 | }, |
| 2059 | { |
| 2060 | name: "BadHelloRequest-2", |
| 2061 | renegotiate: 1, |
| 2062 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2063 | MaxVersion: VersionTLS12, |
David Benjamin | ef5dfd2 | 2015-12-06 13:17:07 -0500 | [diff] [blame] | 2064 | Bugs: ProtocolBugs{ |
| 2065 | BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0}, |
| 2066 | }, |
| 2067 | }, |
| 2068 | flags: []string{ |
| 2069 | "-renegotiate-freely", |
| 2070 | "-expect-total-renegotiations", "1", |
| 2071 | }, |
| 2072 | shouldFail: true, |
| 2073 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2074 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2075 | { |
| 2076 | testType: serverTest, |
| 2077 | name: "SupportTicketsWithSessionID", |
| 2078 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2079 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2080 | SessionTicketsDisabled: true, |
| 2081 | }, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2082 | resumeConfig: &Config{ |
| 2083 | MaxVersion: VersionTLS12, |
| 2084 | }, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2085 | resumeSession: true, |
| 2086 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2087 | } |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2088 | testCases = append(testCases, basicTests...) |
| 2089 | } |
| 2090 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2091 | func addCipherSuiteTests() { |
David Benjamin | e470e66 | 2016-07-18 15:47:32 +0200 | [diff] [blame] | 2092 | const bogusCipher = 0xfe00 |
| 2093 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2094 | for _, suite := range testCipherSuites { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2095 | const psk = "12345" |
| 2096 | const pskIdentity = "luggage combo" |
| 2097 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2098 | var cert Certificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2099 | var certFile string |
| 2100 | var keyFile string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2101 | if hasComponent(suite.name, "ECDSA") { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2102 | cert = ecdsaP256Certificate |
| 2103 | certFile = ecdsaP256CertificateFile |
| 2104 | keyFile = ecdsaP256KeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2105 | } else { |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2106 | cert = rsaCertificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2107 | certFile = rsaCertificateFile |
| 2108 | keyFile = rsaKeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2111 | var flags []string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2112 | if hasComponent(suite.name, "PSK") { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2113 | flags = append(flags, |
| 2114 | "-psk", psk, |
| 2115 | "-psk-identity", pskIdentity) |
| 2116 | } |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 2117 | if hasComponent(suite.name, "NULL") { |
| 2118 | // NULL ciphers must be explicitly enabled. |
| 2119 | flags = append(flags, "-cipher", "DEFAULT:NULL-SHA") |
| 2120 | } |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 2121 | if hasComponent(suite.name, "CECPQ1") { |
| 2122 | // CECPQ1 ciphers must be explicitly enabled. |
| 2123 | flags = append(flags, "-cipher", "DEFAULT:kCECPQ1") |
| 2124 | } |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2125 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2126 | for _, ver := range tlsVersions { |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2127 | for _, protocol := range []protocol{tls, dtls} { |
| 2128 | var prefix string |
| 2129 | if protocol == dtls { |
| 2130 | if !ver.hasDTLS { |
| 2131 | continue |
| 2132 | } |
| 2133 | prefix = "D" |
| 2134 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2135 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2136 | var shouldServerFail, shouldClientFail bool |
| 2137 | if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 { |
| 2138 | // BoringSSL clients accept ECDHE on SSLv3, but |
| 2139 | // a BoringSSL server will never select it |
| 2140 | // because the extension is missing. |
| 2141 | shouldServerFail = true |
| 2142 | } |
| 2143 | if isTLS12Only(suite.name) && ver.version < VersionTLS12 { |
| 2144 | shouldClientFail = true |
| 2145 | shouldServerFail = true |
| 2146 | } |
David Benjamin | 54c217c | 2016-07-13 12:35:25 -0400 | [diff] [blame] | 2147 | if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2148 | shouldClientFail = true |
| 2149 | shouldServerFail = true |
| 2150 | } |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2151 | if !isDTLSCipher(suite.name) && protocol == dtls { |
| 2152 | shouldClientFail = true |
| 2153 | shouldServerFail = true |
| 2154 | } |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 2155 | |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2156 | var expectedServerError, expectedClientError string |
| 2157 | if shouldServerFail { |
| 2158 | expectedServerError = ":NO_SHARED_CIPHER:" |
| 2159 | } |
| 2160 | if shouldClientFail { |
| 2161 | expectedClientError = ":WRONG_CIPHER_RETURNED:" |
| 2162 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2163 | |
David Benjamin | 9deb117 | 2016-07-13 17:13:49 -0400 | [diff] [blame] | 2164 | // TODO(davidben,svaldez): Implement resumption for TLS 1.3. |
| 2165 | resumeSession := ver.version < VersionTLS13 |
| 2166 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2167 | testCases = append(testCases, testCase{ |
| 2168 | testType: serverTest, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2169 | protocol: protocol, |
| 2170 | |
| 2171 | name: prefix + ver.name + "-" + suite.name + "-server", |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2172 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2173 | MinVersion: ver.version, |
| 2174 | MaxVersion: ver.version, |
| 2175 | CipherSuites: []uint16{suite.id}, |
| 2176 | Certificates: []Certificate{cert}, |
| 2177 | PreSharedKey: []byte(psk), |
| 2178 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2179 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2180 | EnableAllCiphers: shouldServerFail, |
| 2181 | IgnorePeerCipherPreferences: shouldServerFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2182 | }, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2183 | }, |
| 2184 | certFile: certFile, |
| 2185 | keyFile: keyFile, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2186 | flags: flags, |
David Benjamin | 9deb117 | 2016-07-13 17:13:49 -0400 | [diff] [blame] | 2187 | resumeSession: resumeSession, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2188 | shouldFail: shouldServerFail, |
| 2189 | expectedError: expectedServerError, |
| 2190 | }) |
| 2191 | |
| 2192 | testCases = append(testCases, testCase{ |
| 2193 | testType: clientTest, |
| 2194 | protocol: protocol, |
| 2195 | name: prefix + ver.name + "-" + suite.name + "-client", |
| 2196 | config: Config{ |
| 2197 | MinVersion: ver.version, |
| 2198 | MaxVersion: ver.version, |
| 2199 | CipherSuites: []uint16{suite.id}, |
| 2200 | Certificates: []Certificate{cert}, |
| 2201 | PreSharedKey: []byte(psk), |
| 2202 | PreSharedKeyIdentity: pskIdentity, |
| 2203 | Bugs: ProtocolBugs{ |
David Benjamin | 9acf0ca | 2016-06-25 00:01:28 -0400 | [diff] [blame] | 2204 | EnableAllCiphers: shouldClientFail, |
| 2205 | IgnorePeerCipherPreferences: shouldClientFail, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2206 | }, |
| 2207 | }, |
| 2208 | flags: flags, |
David Benjamin | 9deb117 | 2016-07-13 17:13:49 -0400 | [diff] [blame] | 2209 | resumeSession: resumeSession, |
David Benjamin | 0407e76 | 2016-06-17 16:41:18 -0400 | [diff] [blame] | 2210 | shouldFail: shouldClientFail, |
| 2211 | expectedError: expectedClientError, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2212 | }) |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2213 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2214 | if !shouldClientFail { |
| 2215 | // Ensure the maximum record size is accepted. |
| 2216 | testCases = append(testCases, testCase{ |
| 2217 | name: prefix + ver.name + "-" + suite.name + "-LargeRecord", |
| 2218 | config: Config{ |
| 2219 | MinVersion: ver.version, |
| 2220 | MaxVersion: ver.version, |
| 2221 | CipherSuites: []uint16{suite.id}, |
| 2222 | Certificates: []Certificate{cert}, |
| 2223 | PreSharedKey: []byte(psk), |
| 2224 | PreSharedKeyIdentity: pskIdentity, |
| 2225 | }, |
| 2226 | flags: flags, |
| 2227 | messageLen: maxPlaintext, |
| 2228 | }) |
| 2229 | } |
| 2230 | } |
David Benjamin | 2c99d28 | 2015-09-01 10:23:00 -0400 | [diff] [blame] | 2231 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2232 | } |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2233 | |
| 2234 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2235 | name: "NoSharedCipher", |
| 2236 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2237 | MaxVersion: VersionTLS12, |
| 2238 | CipherSuites: []uint16{}, |
| 2239 | }, |
| 2240 | shouldFail: true, |
| 2241 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2242 | }) |
| 2243 | |
| 2244 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2245 | name: "NoSharedCipher-TLS13", |
| 2246 | config: Config{ |
| 2247 | MaxVersion: VersionTLS13, |
| 2248 | CipherSuites: []uint16{}, |
| 2249 | }, |
| 2250 | shouldFail: true, |
| 2251 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 2252 | }) |
| 2253 | |
| 2254 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2255 | name: "UnsupportedCipherSuite", |
| 2256 | config: Config{ |
| 2257 | MaxVersion: VersionTLS12, |
| 2258 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2259 | Bugs: ProtocolBugs{ |
| 2260 | IgnorePeerCipherPreferences: true, |
| 2261 | }, |
| 2262 | }, |
| 2263 | flags: []string{"-cipher", "DEFAULT:!RC4"}, |
| 2264 | shouldFail: true, |
| 2265 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 2266 | }) |
| 2267 | |
| 2268 | testCases = append(testCases, testCase{ |
David Benjamin | e470e66 | 2016-07-18 15:47:32 +0200 | [diff] [blame] | 2269 | name: "ServerHelloBogusCipher", |
| 2270 | config: Config{ |
| 2271 | MaxVersion: VersionTLS12, |
| 2272 | Bugs: ProtocolBugs{ |
| 2273 | SendCipherSuite: bogusCipher, |
| 2274 | }, |
| 2275 | }, |
| 2276 | shouldFail: true, |
| 2277 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2278 | }) |
| 2279 | testCases = append(testCases, testCase{ |
| 2280 | name: "ServerHelloBogusCipher-TLS13", |
| 2281 | config: Config{ |
| 2282 | MaxVersion: VersionTLS13, |
| 2283 | Bugs: ProtocolBugs{ |
| 2284 | SendCipherSuite: bogusCipher, |
| 2285 | }, |
| 2286 | }, |
| 2287 | shouldFail: true, |
| 2288 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 2289 | }) |
| 2290 | |
| 2291 | testCases = append(testCases, testCase{ |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2292 | name: "WeakDH", |
| 2293 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2294 | MaxVersion: VersionTLS12, |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2295 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2296 | Bugs: ProtocolBugs{ |
| 2297 | // This is a 1023-bit prime number, generated |
| 2298 | // with: |
| 2299 | // openssl gendh 1023 | openssl asn1parse -i |
| 2300 | DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"), |
| 2301 | }, |
| 2302 | }, |
| 2303 | shouldFail: true, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2304 | expectedError: ":BAD_DH_P_LENGTH:", |
Adam Langley | a7997f1 | 2015-05-14 17:38:50 -0700 | [diff] [blame] | 2305 | }) |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2306 | |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2307 | testCases = append(testCases, testCase{ |
| 2308 | name: "SillyDH", |
| 2309 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2310 | MaxVersion: VersionTLS12, |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2311 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2312 | Bugs: ProtocolBugs{ |
| 2313 | // This is a 4097-bit prime number, generated |
| 2314 | // with: |
| 2315 | // openssl gendh 4097 | openssl asn1parse -i |
| 2316 | DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"), |
| 2317 | }, |
| 2318 | }, |
| 2319 | shouldFail: true, |
| 2320 | expectedError: ":DH_P_TOO_LONG:", |
| 2321 | }) |
| 2322 | |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2323 | // This test ensures that Diffie-Hellman public values are padded with |
| 2324 | // zeros so that they're the same length as the prime. This is to avoid |
| 2325 | // hitting a bug in yaSSL. |
| 2326 | testCases = append(testCases, testCase{ |
| 2327 | testType: serverTest, |
| 2328 | name: "DHPublicValuePadded", |
| 2329 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2330 | MaxVersion: VersionTLS12, |
Adam Langley | c4f25ce | 2015-11-26 16:39:08 -0800 | [diff] [blame] | 2331 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2332 | Bugs: ProtocolBugs{ |
| 2333 | RequireDHPublicValueLen: (1025 + 7) / 8, |
| 2334 | }, |
| 2335 | }, |
| 2336 | flags: []string{"-use-sparse-dh-prime"}, |
| 2337 | }) |
David Benjamin | cd24a39 | 2015-11-11 13:23:05 -0800 | [diff] [blame] | 2338 | |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2339 | // The server must be tolerant to bogus ciphers. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 2340 | testCases = append(testCases, testCase{ |
| 2341 | testType: serverTest, |
| 2342 | name: "UnknownCipher", |
| 2343 | config: Config{ |
| 2344 | CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2345 | }, |
| 2346 | }) |
| 2347 | |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 2348 | // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS |
| 2349 | // 1.1 specific cipher suite settings. A server is setup with the given |
| 2350 | // cipher lists and then a connection is made for each member of |
| 2351 | // expectations. The cipher suite that the server selects must match |
| 2352 | // the specified one. |
| 2353 | var versionSpecificCiphersTest = []struct { |
| 2354 | ciphersDefault, ciphersTLS10, ciphersTLS11 string |
| 2355 | // expectations is a map from TLS version to cipher suite id. |
| 2356 | expectations map[uint16]uint16 |
| 2357 | }{ |
| 2358 | { |
| 2359 | // Test that the null case (where no version-specific ciphers are set) |
| 2360 | // works as expected. |
| 2361 | "RC4-SHA:AES128-SHA", // default ciphers |
| 2362 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2363 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2364 | map[uint16]uint16{ |
| 2365 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2366 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2367 | VersionTLS11: TLS_RSA_WITH_RC4_128_SHA, |
| 2368 | VersionTLS12: TLS_RSA_WITH_RC4_128_SHA, |
| 2369 | }, |
| 2370 | }, |
| 2371 | { |
| 2372 | // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different |
| 2373 | // cipher. |
| 2374 | "RC4-SHA:AES128-SHA", // default |
| 2375 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2376 | "", // no ciphers specifically for TLS ≥ 1.1 |
| 2377 | map[uint16]uint16{ |
| 2378 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2379 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2380 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2381 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2382 | }, |
| 2383 | }, |
| 2384 | { |
| 2385 | // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different |
| 2386 | // cipher. |
| 2387 | "RC4-SHA:AES128-SHA", // default |
| 2388 | "", // no ciphers specifically for TLS ≥ 1.0 |
| 2389 | "AES128-SHA", // these ciphers for TLS ≥ 1.1 |
| 2390 | map[uint16]uint16{ |
| 2391 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2392 | VersionTLS10: TLS_RSA_WITH_RC4_128_SHA, |
| 2393 | VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2394 | VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2395 | }, |
| 2396 | }, |
| 2397 | { |
| 2398 | // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should |
| 2399 | // mask ciphers_tls10 for TLS 1.1 and 1.2. |
| 2400 | "RC4-SHA:AES128-SHA", // default |
| 2401 | "AES128-SHA", // these ciphers for TLS ≥ 1.0 |
| 2402 | "AES256-SHA", // these ciphers for TLS ≥ 1.1 |
| 2403 | map[uint16]uint16{ |
| 2404 | VersionSSL30: TLS_RSA_WITH_RC4_128_SHA, |
| 2405 | VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 2406 | VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2407 | VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA, |
| 2408 | }, |
| 2409 | }, |
| 2410 | } |
| 2411 | |
| 2412 | for i, test := range versionSpecificCiphersTest { |
| 2413 | for version, expectedCipherSuite := range test.expectations { |
| 2414 | flags := []string{"-cipher", test.ciphersDefault} |
| 2415 | if len(test.ciphersTLS10) > 0 { |
| 2416 | flags = append(flags, "-cipher-tls10", test.ciphersTLS10) |
| 2417 | } |
| 2418 | if len(test.ciphersTLS11) > 0 { |
| 2419 | flags = append(flags, "-cipher-tls11", test.ciphersTLS11) |
| 2420 | } |
| 2421 | |
| 2422 | testCases = append(testCases, testCase{ |
| 2423 | testType: serverTest, |
| 2424 | name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version), |
| 2425 | config: Config{ |
| 2426 | MaxVersion: version, |
| 2427 | MinVersion: version, |
| 2428 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA}, |
| 2429 | }, |
| 2430 | flags: flags, |
| 2431 | expectedCipher: expectedCipherSuite, |
| 2432 | }) |
| 2433 | } |
| 2434 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | func addBadECDSASignatureTests() { |
| 2438 | for badR := BadValue(1); badR < NumBadValues; badR++ { |
| 2439 | for badS := BadValue(1); badS < NumBadValues; badS++ { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2440 | testCases = append(testCases, testCase{ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2441 | name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS), |
| 2442 | config: Config{ |
| 2443 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2444 | Certificates: []Certificate{ecdsaP256Certificate}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2445 | Bugs: ProtocolBugs{ |
| 2446 | BadECDSAR: badR, |
| 2447 | BadECDSAS: badS, |
| 2448 | }, |
| 2449 | }, |
| 2450 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2451 | expectedError: ":BAD_SIGNATURE:", |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2452 | }) |
| 2453 | } |
| 2454 | } |
| 2455 | } |
| 2456 | |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2457 | func addCBCPaddingTests() { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2458 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2459 | name: "MaxCBCPadding", |
| 2460 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2461 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2462 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2463 | Bugs: ProtocolBugs{ |
| 2464 | MaxPadding: true, |
| 2465 | }, |
| 2466 | }, |
| 2467 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2468 | }) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2469 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2470 | name: "BadCBCPadding", |
| 2471 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2472 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2473 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2474 | Bugs: ProtocolBugs{ |
| 2475 | PaddingFirstByteBad: true, |
| 2476 | }, |
| 2477 | }, |
| 2478 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2479 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2480 | }) |
| 2481 | // OpenSSL previously had an issue where the first byte of padding in |
| 2482 | // 255 bytes of padding wasn't checked. |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2483 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2484 | name: "BadCBCPadding255", |
| 2485 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2486 | MaxVersion: VersionTLS12, |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2487 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2488 | Bugs: ProtocolBugs{ |
| 2489 | MaxPadding: true, |
| 2490 | PaddingFirstByteBadIf255: true, |
| 2491 | }, |
| 2492 | }, |
| 2493 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 2494 | shouldFail: true, |
David Benjamin | 11d50f9 | 2016-03-10 15:55:45 -0500 | [diff] [blame] | 2495 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2496 | }) |
| 2497 | } |
| 2498 | |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2499 | func addCBCSplittingTests() { |
| 2500 | testCases = append(testCases, testCase{ |
| 2501 | name: "CBCRecordSplitting", |
| 2502 | config: Config{ |
| 2503 | MaxVersion: VersionTLS10, |
| 2504 | MinVersion: VersionTLS10, |
| 2505 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2506 | }, |
David Benjamin | ac8302a | 2015-09-01 17:18:15 -0400 | [diff] [blame] | 2507 | messageLen: -1, // read until EOF |
| 2508 | resumeSession: true, |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2509 | flags: []string{ |
| 2510 | "-async", |
| 2511 | "-write-different-record-sizes", |
| 2512 | "-cbc-record-splitting", |
| 2513 | }, |
David Benjamin | a8e3e0e | 2014-08-06 22:11:10 -0400 | [diff] [blame] | 2514 | }) |
| 2515 | testCases = append(testCases, testCase{ |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2516 | name: "CBCRecordSplittingPartialWrite", |
| 2517 | config: Config{ |
| 2518 | MaxVersion: VersionTLS10, |
| 2519 | MinVersion: VersionTLS10, |
| 2520 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2521 | }, |
| 2522 | messageLen: -1, // read until EOF |
| 2523 | flags: []string{ |
| 2524 | "-async", |
| 2525 | "-write-different-record-sizes", |
| 2526 | "-cbc-record-splitting", |
| 2527 | "-partial-write", |
| 2528 | }, |
| 2529 | }) |
| 2530 | } |
| 2531 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2532 | func addClientAuthTests() { |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 2533 | // Add a dummy cert pool to stress certificate authority parsing. |
| 2534 | // TODO(davidben): Add tests that those values parse out correctly. |
| 2535 | certPool := x509.NewCertPool() |
| 2536 | cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0]) |
| 2537 | if err != nil { |
| 2538 | panic(err) |
| 2539 | } |
| 2540 | certPool.AddCert(cert) |
| 2541 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2542 | for _, ver := range tlsVersions { |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2543 | testCases = append(testCases, testCase{ |
| 2544 | testType: clientTest, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2545 | name: ver.name + "-Client-ClientAuth-RSA", |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2546 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2547 | MinVersion: ver.version, |
| 2548 | MaxVersion: ver.version, |
| 2549 | ClientAuth: RequireAnyClientCert, |
| 2550 | ClientCAs: certPool, |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2551 | }, |
| 2552 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 2553 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2554 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2555 | }, |
| 2556 | }) |
| 2557 | testCases = append(testCases, testCase{ |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2558 | testType: serverTest, |
| 2559 | name: ver.name + "-Server-ClientAuth-RSA", |
| 2560 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2561 | MinVersion: ver.version, |
| 2562 | MaxVersion: ver.version, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 2563 | Certificates: []Certificate{rsaCertificate}, |
| 2564 | }, |
| 2565 | flags: []string{"-require-any-client-certificate"}, |
| 2566 | }) |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2567 | if ver.version != VersionSSL30 { |
| 2568 | testCases = append(testCases, testCase{ |
| 2569 | testType: serverTest, |
| 2570 | name: ver.name + "-Server-ClientAuth-ECDSA", |
| 2571 | config: Config{ |
| 2572 | MinVersion: ver.version, |
| 2573 | MaxVersion: ver.version, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2574 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2575 | }, |
| 2576 | flags: []string{"-require-any-client-certificate"}, |
| 2577 | }) |
| 2578 | testCases = append(testCases, testCase{ |
| 2579 | testType: clientTest, |
| 2580 | name: ver.name + "-Client-ClientAuth-ECDSA", |
| 2581 | config: Config{ |
| 2582 | MinVersion: ver.version, |
| 2583 | MaxVersion: ver.version, |
| 2584 | ClientAuth: RequireAnyClientCert, |
| 2585 | ClientCAs: certPool, |
| 2586 | }, |
| 2587 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 2588 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 2589 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 2590 | }, |
| 2591 | }) |
| 2592 | } |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2593 | } |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2594 | |
| 2595 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2596 | name: "NoClientCertificate", |
| 2597 | config: Config{ |
| 2598 | MaxVersion: VersionTLS12, |
| 2599 | ClientAuth: RequireAnyClientCert, |
| 2600 | }, |
| 2601 | shouldFail: true, |
| 2602 | expectedLocalError: "client didn't provide a certificate", |
| 2603 | }) |
| 2604 | |
| 2605 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2606 | name: "NoClientCertificate-TLS13", |
| 2607 | config: Config{ |
| 2608 | MaxVersion: VersionTLS13, |
| 2609 | ClientAuth: RequireAnyClientCert, |
| 2610 | }, |
| 2611 | shouldFail: true, |
| 2612 | expectedLocalError: "client didn't provide a certificate", |
| 2613 | }) |
| 2614 | |
| 2615 | testCases = append(testCases, testCase{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2616 | testType: serverTest, |
| 2617 | name: "RequireAnyClientCertificate", |
| 2618 | config: Config{ |
| 2619 | MaxVersion: VersionTLS12, |
| 2620 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2621 | flags: []string{"-require-any-client-certificate"}, |
| 2622 | shouldFail: true, |
| 2623 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2624 | }) |
| 2625 | |
| 2626 | testCases = append(testCases, testCase{ |
| 2627 | testType: serverTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2628 | name: "RequireAnyClientCertificate-TLS13", |
| 2629 | config: Config{ |
| 2630 | MaxVersion: VersionTLS13, |
| 2631 | }, |
| 2632 | flags: []string{"-require-any-client-certificate"}, |
| 2633 | shouldFail: true, |
| 2634 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2635 | }) |
| 2636 | |
| 2637 | testCases = append(testCases, testCase{ |
| 2638 | testType: serverTest, |
David Benjamin | df28c3a | 2016-03-10 16:11:51 -0500 | [diff] [blame] | 2639 | name: "RequireAnyClientCertificate-SSL3", |
| 2640 | config: Config{ |
| 2641 | MaxVersion: VersionSSL30, |
| 2642 | }, |
| 2643 | flags: []string{"-require-any-client-certificate"}, |
| 2644 | shouldFail: true, |
| 2645 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2646 | }) |
| 2647 | |
| 2648 | testCases = append(testCases, testCase{ |
| 2649 | testType: serverTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2650 | name: "SkipClientCertificate", |
| 2651 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2652 | MaxVersion: VersionTLS12, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2653 | Bugs: ProtocolBugs{ |
| 2654 | SkipClientCertificate: true, |
| 2655 | }, |
| 2656 | }, |
| 2657 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2658 | flags: []string{"-verify-peer"}, |
| 2659 | shouldFail: true, |
David Benjamin | df28c3a | 2016-03-10 16:11:51 -0500 | [diff] [blame] | 2660 | expectedError: ":UNEXPECTED_MESSAGE:", |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2661 | }) |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2662 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2663 | testCases = append(testCases, testCase{ |
| 2664 | testType: serverTest, |
| 2665 | name: "SkipClientCertificate-TLS13", |
| 2666 | config: Config{ |
| 2667 | MaxVersion: VersionTLS13, |
| 2668 | Bugs: ProtocolBugs{ |
| 2669 | SkipClientCertificate: true, |
| 2670 | }, |
| 2671 | }, |
| 2672 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 2673 | flags: []string{"-verify-peer"}, |
| 2674 | shouldFail: true, |
| 2675 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2676 | }) |
| 2677 | |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2678 | // Client auth is only legal in certificate-based ciphers. |
| 2679 | testCases = append(testCases, testCase{ |
| 2680 | testType: clientTest, |
| 2681 | name: "ClientAuth-PSK", |
| 2682 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2683 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2684 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 2685 | PreSharedKey: []byte("secret"), |
| 2686 | ClientAuth: RequireAnyClientCert, |
| 2687 | }, |
| 2688 | flags: []string{ |
| 2689 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2690 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2691 | "-psk", "secret", |
| 2692 | }, |
| 2693 | shouldFail: true, |
| 2694 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2695 | }) |
| 2696 | testCases = append(testCases, testCase{ |
| 2697 | testType: clientTest, |
| 2698 | name: "ClientAuth-ECDHE_PSK", |
| 2699 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 2700 | MaxVersion: VersionTLS12, |
David Benjamin | c032dfa | 2016-05-12 14:54:57 -0400 | [diff] [blame] | 2701 | CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 2702 | PreSharedKey: []byte("secret"), |
| 2703 | ClientAuth: RequireAnyClientCert, |
| 2704 | }, |
| 2705 | flags: []string{ |
| 2706 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 2707 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 2708 | "-psk", "secret", |
| 2709 | }, |
| 2710 | shouldFail: true, |
| 2711 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 2712 | }) |
David Benjamin | 2f8935d | 2016-07-13 19:47:39 -0400 | [diff] [blame] | 2713 | |
| 2714 | // Regression test for a bug where the client CA list, if explicitly |
| 2715 | // set to NULL, was mis-encoded. |
| 2716 | testCases = append(testCases, testCase{ |
| 2717 | testType: serverTest, |
| 2718 | name: "Null-Client-CA-List", |
| 2719 | config: Config{ |
| 2720 | MaxVersion: VersionTLS12, |
| 2721 | Certificates: []Certificate{rsaCertificate}, |
| 2722 | }, |
| 2723 | flags: []string{ |
| 2724 | "-require-any-client-certificate", |
| 2725 | "-use-null-client-ca-list", |
| 2726 | }, |
| 2727 | }) |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2728 | } |
| 2729 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2730 | func addExtendedMasterSecretTests() { |
| 2731 | const expectEMSFlag = "-expect-extended-master-secret" |
| 2732 | |
| 2733 | for _, with := range []bool{false, true} { |
| 2734 | prefix := "No" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2735 | if with { |
| 2736 | prefix = "" |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | for _, isClient := range []bool{false, true} { |
| 2740 | suffix := "-Server" |
| 2741 | testType := serverTest |
| 2742 | if isClient { |
| 2743 | suffix = "-Client" |
| 2744 | testType = clientTest |
| 2745 | } |
| 2746 | |
| 2747 | for _, ver := range tlsVersions { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2748 | // In TLS 1.3, the extension is irrelevant and |
| 2749 | // always reports as enabled. |
| 2750 | var flags []string |
| 2751 | if with || ver.version >= VersionTLS13 { |
| 2752 | flags = []string{expectEMSFlag} |
| 2753 | } |
| 2754 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2755 | test := testCase{ |
| 2756 | testType: testType, |
| 2757 | name: prefix + "ExtendedMasterSecret-" + ver.name + suffix, |
| 2758 | config: Config{ |
| 2759 | MinVersion: ver.version, |
| 2760 | MaxVersion: ver.version, |
| 2761 | Bugs: ProtocolBugs{ |
| 2762 | NoExtendedMasterSecret: !with, |
| 2763 | RequireExtendedMasterSecret: with, |
| 2764 | }, |
| 2765 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 2766 | flags: flags, |
| 2767 | shouldFail: ver.version == VersionSSL30 && with, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2768 | } |
| 2769 | if test.shouldFail { |
| 2770 | test.expectedLocalError = "extended master secret required but not supported by peer" |
| 2771 | } |
| 2772 | testCases = append(testCases, test) |
| 2773 | } |
| 2774 | } |
| 2775 | } |
| 2776 | |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2777 | for _, isClient := range []bool{false, true} { |
| 2778 | for _, supportedInFirstConnection := range []bool{false, true} { |
| 2779 | for _, supportedInResumeConnection := range []bool{false, true} { |
| 2780 | boolToWord := func(b bool) string { |
| 2781 | if b { |
| 2782 | return "Yes" |
| 2783 | } |
| 2784 | return "No" |
| 2785 | } |
| 2786 | suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-" |
| 2787 | if isClient { |
| 2788 | suffix += "Client" |
| 2789 | } else { |
| 2790 | suffix += "Server" |
| 2791 | } |
| 2792 | |
| 2793 | supportedConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2794 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2795 | Bugs: ProtocolBugs{ |
| 2796 | RequireExtendedMasterSecret: true, |
| 2797 | }, |
| 2798 | } |
| 2799 | |
| 2800 | noSupportConfig := Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2801 | MaxVersion: VersionTLS12, |
Adam Langley | ba5934b | 2015-06-02 10:50:35 -0700 | [diff] [blame] | 2802 | Bugs: ProtocolBugs{ |
| 2803 | NoExtendedMasterSecret: true, |
| 2804 | }, |
| 2805 | } |
| 2806 | |
| 2807 | test := testCase{ |
| 2808 | name: "ExtendedMasterSecret-" + suffix, |
| 2809 | resumeSession: true, |
| 2810 | } |
| 2811 | |
| 2812 | if !isClient { |
| 2813 | test.testType = serverTest |
| 2814 | } |
| 2815 | |
| 2816 | if supportedInFirstConnection { |
| 2817 | test.config = supportedConfig |
| 2818 | } else { |
| 2819 | test.config = noSupportConfig |
| 2820 | } |
| 2821 | |
| 2822 | if supportedInResumeConnection { |
| 2823 | test.resumeConfig = &supportedConfig |
| 2824 | } else { |
| 2825 | test.resumeConfig = &noSupportConfig |
| 2826 | } |
| 2827 | |
| 2828 | switch suffix { |
| 2829 | case "YesToYes-Client", "YesToYes-Server": |
| 2830 | // When a session is resumed, it should |
| 2831 | // still be aware that its master |
| 2832 | // secret was generated via EMS and |
| 2833 | // thus it's safe to use tls-unique. |
| 2834 | test.flags = []string{expectEMSFlag} |
| 2835 | case "NoToYes-Server": |
| 2836 | // If an original connection did not |
| 2837 | // contain EMS, but a resumption |
| 2838 | // handshake does, then a server should |
| 2839 | // not resume the session. |
| 2840 | test.expectResumeRejected = true |
| 2841 | case "YesToNo-Server": |
| 2842 | // Resuming an EMS session without the |
| 2843 | // EMS extension should cause the |
| 2844 | // server to abort the connection. |
| 2845 | test.shouldFail = true |
| 2846 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 2847 | case "NoToYes-Client": |
| 2848 | // A client should abort a connection |
| 2849 | // where the server resumed a non-EMS |
| 2850 | // session but echoed the EMS |
| 2851 | // extension. |
| 2852 | test.shouldFail = true |
| 2853 | test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:" |
| 2854 | case "YesToNo-Client": |
| 2855 | // A client should abort a connection |
| 2856 | // where the server didn't echo EMS |
| 2857 | // when the session used it. |
| 2858 | test.shouldFail = true |
| 2859 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 2860 | } |
| 2861 | |
| 2862 | testCases = append(testCases, test) |
| 2863 | } |
| 2864 | } |
| 2865 | } |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2866 | } |
| 2867 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 2868 | type stateMachineTestConfig struct { |
| 2869 | protocol protocol |
| 2870 | async bool |
| 2871 | splitHandshake, packHandshakeFlight bool |
| 2872 | } |
| 2873 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 2874 | // Adds tests that try to cover the range of the handshake state machine, under |
| 2875 | // various conditions. Some of these are redundant with other tests, but they |
| 2876 | // only cover the synchronous case. |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 2877 | func addAllStateMachineCoverageTests() { |
| 2878 | for _, async := range []bool{false, true} { |
| 2879 | for _, protocol := range []protocol{tls, dtls} { |
| 2880 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 2881 | protocol: protocol, |
| 2882 | async: async, |
| 2883 | }) |
| 2884 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 2885 | protocol: protocol, |
| 2886 | async: async, |
| 2887 | splitHandshake: true, |
| 2888 | }) |
| 2889 | if protocol == tls { |
| 2890 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 2891 | protocol: protocol, |
| 2892 | async: async, |
| 2893 | packHandshakeFlight: true, |
| 2894 | }) |
| 2895 | } |
| 2896 | } |
| 2897 | } |
| 2898 | } |
| 2899 | |
| 2900 | func addStateMachineCoverageTests(config stateMachineTestConfig) { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2901 | var tests []testCase |
| 2902 | |
| 2903 | // Basic handshake, with resumption. Client and server, |
| 2904 | // session ID and session ticket. |
| 2905 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2906 | name: "Basic-Client", |
| 2907 | config: Config{ |
| 2908 | MaxVersion: VersionTLS12, |
| 2909 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2910 | resumeSession: true, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2911 | // Ensure session tickets are used, not session IDs. |
| 2912 | noSessionCache: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2913 | }) |
| 2914 | tests = append(tests, testCase{ |
| 2915 | name: "Basic-Client-RenewTicket", |
| 2916 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2917 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2918 | Bugs: ProtocolBugs{ |
| 2919 | RenewTicketOnResume: true, |
| 2920 | }, |
| 2921 | }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 2922 | flags: []string{"-expect-ticket-renewal"}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2923 | resumeSession: true, |
| 2924 | }) |
| 2925 | tests = append(tests, testCase{ |
| 2926 | name: "Basic-Client-NoTicket", |
| 2927 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2928 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2929 | SessionTicketsDisabled: true, |
| 2930 | }, |
| 2931 | resumeSession: true, |
| 2932 | }) |
| 2933 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2934 | name: "Basic-Client-Implicit", |
| 2935 | config: Config{ |
| 2936 | MaxVersion: VersionTLS12, |
| 2937 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2938 | flags: []string{"-implicit-handshake"}, |
| 2939 | resumeSession: true, |
| 2940 | }) |
| 2941 | tests = append(tests, testCase{ |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2942 | testType: serverTest, |
| 2943 | name: "Basic-Server", |
| 2944 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2945 | MaxVersion: VersionTLS12, |
David Benjamin | ef1b009 | 2015-11-21 14:05:44 -0500 | [diff] [blame] | 2946 | Bugs: ProtocolBugs{ |
| 2947 | RequireSessionTickets: true, |
| 2948 | }, |
| 2949 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2950 | resumeSession: true, |
| 2951 | }) |
| 2952 | tests = append(tests, testCase{ |
| 2953 | testType: serverTest, |
| 2954 | name: "Basic-Server-NoTickets", |
| 2955 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2956 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2957 | SessionTicketsDisabled: true, |
| 2958 | }, |
| 2959 | resumeSession: true, |
| 2960 | }) |
| 2961 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2962 | testType: serverTest, |
| 2963 | name: "Basic-Server-Implicit", |
| 2964 | config: Config{ |
| 2965 | MaxVersion: VersionTLS12, |
| 2966 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2967 | flags: []string{"-implicit-handshake"}, |
| 2968 | resumeSession: true, |
| 2969 | }) |
| 2970 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 2971 | testType: serverTest, |
| 2972 | name: "Basic-Server-EarlyCallback", |
| 2973 | config: Config{ |
| 2974 | MaxVersion: VersionTLS12, |
| 2975 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2976 | flags: []string{"-use-early-callback"}, |
| 2977 | resumeSession: true, |
| 2978 | }) |
| 2979 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 2980 | // TLS 1.3 basic handshake shapes. |
| 2981 | tests = append(tests, testCase{ |
| 2982 | name: "TLS13-1RTT-Client", |
| 2983 | config: Config{ |
| 2984 | MaxVersion: VersionTLS13, |
| 2985 | }, |
| 2986 | }) |
| 2987 | tests = append(tests, testCase{ |
| 2988 | testType: serverTest, |
| 2989 | name: "TLS13-1RTT-Server", |
| 2990 | config: Config{ |
| 2991 | MaxVersion: VersionTLS13, |
| 2992 | }, |
| 2993 | }) |
| 2994 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 2995 | // TLS client auth. |
| 2996 | tests = append(tests, testCase{ |
| 2997 | testType: clientTest, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 2998 | name: "ClientAuth-NoCertificate-Client", |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 2999 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3000 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3001 | ClientAuth: RequestClientCert, |
| 3002 | }, |
| 3003 | }) |
| 3004 | tests = append(tests, testCase{ |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3005 | testType: serverTest, |
| 3006 | name: "ClientAuth-NoCertificate-Server", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3007 | config: Config{ |
| 3008 | MaxVersion: VersionTLS12, |
| 3009 | }, |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3010 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3011 | flags: []string{"-verify-peer"}, |
| 3012 | }) |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3013 | if config.protocol == tls { |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3014 | tests = append(tests, testCase{ |
| 3015 | testType: clientTest, |
| 3016 | name: "ClientAuth-NoCertificate-Client-SSL3", |
| 3017 | config: Config{ |
| 3018 | MaxVersion: VersionSSL30, |
| 3019 | ClientAuth: RequestClientCert, |
| 3020 | }, |
| 3021 | }) |
| 3022 | tests = append(tests, testCase{ |
| 3023 | testType: serverTest, |
| 3024 | name: "ClientAuth-NoCertificate-Server-SSL3", |
| 3025 | config: Config{ |
| 3026 | MaxVersion: VersionSSL30, |
| 3027 | }, |
| 3028 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3029 | flags: []string{"-verify-peer"}, |
| 3030 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3031 | tests = append(tests, testCase{ |
| 3032 | testType: clientTest, |
| 3033 | name: "ClientAuth-NoCertificate-Client-TLS13", |
| 3034 | config: Config{ |
| 3035 | MaxVersion: VersionTLS13, |
| 3036 | ClientAuth: RequestClientCert, |
| 3037 | }, |
| 3038 | }) |
| 3039 | tests = append(tests, testCase{ |
| 3040 | testType: serverTest, |
| 3041 | name: "ClientAuth-NoCertificate-Server-TLS13", |
| 3042 | config: Config{ |
| 3043 | MaxVersion: VersionTLS13, |
| 3044 | }, |
| 3045 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 3046 | flags: []string{"-verify-peer"}, |
| 3047 | }) |
David Benjamin | 0b7ca7d | 2016-03-10 15:44:22 -0500 | [diff] [blame] | 3048 | } |
| 3049 | tests = append(tests, testCase{ |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3050 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3051 | name: "ClientAuth-RSA-Client", |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3052 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3053 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3054 | ClientAuth: RequireAnyClientCert, |
| 3055 | }, |
| 3056 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3057 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3058 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3059 | }, |
| 3060 | }) |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3061 | tests = append(tests, testCase{ |
| 3062 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3063 | name: "ClientAuth-RSA-Client-TLS13", |
| 3064 | config: Config{ |
| 3065 | MaxVersion: VersionTLS13, |
| 3066 | ClientAuth: RequireAnyClientCert, |
| 3067 | }, |
| 3068 | flags: []string{ |
| 3069 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3070 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3071 | }, |
| 3072 | }) |
| 3073 | tests = append(tests, testCase{ |
| 3074 | testType: clientTest, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3075 | name: "ClientAuth-ECDSA-Client", |
| 3076 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3077 | MaxVersion: VersionTLS12, |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3078 | ClientAuth: RequireAnyClientCert, |
| 3079 | }, |
| 3080 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3081 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3082 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
nagendra modadugu | 3398dbf | 2015-08-07 14:07:52 -0700 | [diff] [blame] | 3083 | }, |
| 3084 | }) |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3085 | tests = append(tests, testCase{ |
| 3086 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3087 | name: "ClientAuth-ECDSA-Client-TLS13", |
| 3088 | config: Config{ |
| 3089 | MaxVersion: VersionTLS13, |
| 3090 | ClientAuth: RequireAnyClientCert, |
| 3091 | }, |
| 3092 | flags: []string{ |
| 3093 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3094 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 3095 | }, |
| 3096 | }) |
| 3097 | tests = append(tests, testCase{ |
| 3098 | testType: clientTest, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3099 | name: "ClientAuth-NoCertificate-OldCallback", |
| 3100 | config: Config{ |
| 3101 | MaxVersion: VersionTLS12, |
| 3102 | ClientAuth: RequestClientCert, |
| 3103 | }, |
| 3104 | flags: []string{"-use-old-client-cert-callback"}, |
| 3105 | }) |
| 3106 | tests = append(tests, testCase{ |
| 3107 | testType: clientTest, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3108 | name: "ClientAuth-NoCertificate-OldCallback-TLS13", |
| 3109 | config: Config{ |
| 3110 | MaxVersion: VersionTLS13, |
| 3111 | ClientAuth: RequestClientCert, |
| 3112 | }, |
| 3113 | flags: []string{"-use-old-client-cert-callback"}, |
| 3114 | }) |
| 3115 | tests = append(tests, testCase{ |
| 3116 | testType: clientTest, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3117 | name: "ClientAuth-OldCallback", |
| 3118 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3119 | MaxVersion: VersionTLS12, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 3120 | ClientAuth: RequireAnyClientCert, |
| 3121 | }, |
| 3122 | flags: []string{ |
| 3123 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3124 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3125 | "-use-old-client-cert-callback", |
| 3126 | }, |
| 3127 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3128 | tests = append(tests, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3129 | testType: clientTest, |
| 3130 | name: "ClientAuth-OldCallback-TLS13", |
| 3131 | config: Config{ |
| 3132 | MaxVersion: VersionTLS13, |
| 3133 | ClientAuth: RequireAnyClientCert, |
| 3134 | }, |
| 3135 | flags: []string{ |
| 3136 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3137 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3138 | "-use-old-client-cert-callback", |
| 3139 | }, |
| 3140 | }) |
| 3141 | tests = append(tests, testCase{ |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3142 | testType: serverTest, |
| 3143 | name: "ClientAuth-Server", |
| 3144 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3145 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3146 | Certificates: []Certificate{rsaCertificate}, |
| 3147 | }, |
| 3148 | flags: []string{"-require-any-client-certificate"}, |
| 3149 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3150 | tests = append(tests, testCase{ |
| 3151 | testType: serverTest, |
| 3152 | name: "ClientAuth-Server-TLS13", |
| 3153 | config: Config{ |
| 3154 | MaxVersion: VersionTLS13, |
| 3155 | Certificates: []Certificate{rsaCertificate}, |
| 3156 | }, |
| 3157 | flags: []string{"-require-any-client-certificate"}, |
| 3158 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3159 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3160 | // Test each key exchange on the server side for async keys. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3161 | tests = append(tests, testCase{ |
| 3162 | testType: serverTest, |
| 3163 | name: "Basic-Server-RSA", |
| 3164 | config: Config{ |
| 3165 | MaxVersion: VersionTLS12, |
| 3166 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 3167 | }, |
| 3168 | flags: []string{ |
| 3169 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3170 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3171 | }, |
| 3172 | }) |
| 3173 | tests = append(tests, testCase{ |
| 3174 | testType: serverTest, |
| 3175 | name: "Basic-Server-ECDHE-RSA", |
| 3176 | config: Config{ |
| 3177 | MaxVersion: VersionTLS12, |
| 3178 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3179 | }, |
| 3180 | flags: []string{ |
| 3181 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3182 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3183 | }, |
| 3184 | }) |
| 3185 | tests = append(tests, testCase{ |
| 3186 | testType: serverTest, |
| 3187 | name: "Basic-Server-ECDHE-ECDSA", |
| 3188 | config: Config{ |
| 3189 | MaxVersion: VersionTLS12, |
| 3190 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 3191 | }, |
| 3192 | flags: []string{ |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 3193 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3194 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3195 | }, |
| 3196 | }) |
| 3197 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3198 | // No session ticket support; server doesn't send NewSessionTicket. |
| 3199 | tests = append(tests, testCase{ |
| 3200 | name: "SessionTicketsDisabled-Client", |
| 3201 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3202 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3203 | SessionTicketsDisabled: true, |
| 3204 | }, |
| 3205 | }) |
| 3206 | tests = append(tests, testCase{ |
| 3207 | testType: serverTest, |
| 3208 | name: "SessionTicketsDisabled-Server", |
| 3209 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3210 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3211 | SessionTicketsDisabled: true, |
| 3212 | }, |
| 3213 | }) |
| 3214 | |
| 3215 | // Skip ServerKeyExchange in PSK key exchange if there's no |
| 3216 | // identity hint. |
| 3217 | tests = append(tests, testCase{ |
| 3218 | name: "EmptyPSKHint-Client", |
| 3219 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3220 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3221 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3222 | PreSharedKey: []byte("secret"), |
| 3223 | }, |
| 3224 | flags: []string{"-psk", "secret"}, |
| 3225 | }) |
| 3226 | tests = append(tests, testCase{ |
| 3227 | testType: serverTest, |
| 3228 | name: "EmptyPSKHint-Server", |
| 3229 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3230 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3231 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3232 | PreSharedKey: []byte("secret"), |
| 3233 | }, |
| 3234 | flags: []string{"-psk", "secret"}, |
| 3235 | }) |
| 3236 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3237 | // OCSP stapling tests. |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3238 | tests = append(tests, testCase{ |
| 3239 | testType: clientTest, |
| 3240 | name: "OCSPStapling-Client", |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3241 | config: Config{ |
| 3242 | MaxVersion: VersionTLS12, |
| 3243 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3244 | flags: []string{ |
| 3245 | "-enable-ocsp-stapling", |
| 3246 | "-expect-ocsp-response", |
| 3247 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3248 | "-verify-peer", |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3249 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3250 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3251 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3252 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3253 | testType: serverTest, |
| 3254 | name: "OCSPStapling-Server", |
| 3255 | config: Config{ |
| 3256 | MaxVersion: VersionTLS12, |
| 3257 | }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3258 | expectedOCSPResponse: testOCSPResponse, |
| 3259 | flags: []string{ |
| 3260 | "-ocsp-response", |
| 3261 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3262 | }, |
Paul Lietar | 62be8ac | 2015-09-16 10:03:30 +0100 | [diff] [blame] | 3263 | resumeSession: true, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3264 | }) |
David Benjamin | 942f4ed | 2016-07-16 19:03:49 +0300 | [diff] [blame] | 3265 | tests = append(tests, testCase{ |
| 3266 | testType: clientTest, |
| 3267 | name: "OCSPStapling-Client-TLS13", |
| 3268 | config: Config{ |
| 3269 | MaxVersion: VersionTLS13, |
| 3270 | }, |
| 3271 | flags: []string{ |
| 3272 | "-enable-ocsp-stapling", |
| 3273 | "-expect-ocsp-response", |
| 3274 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3275 | "-verify-peer", |
| 3276 | }, |
| 3277 | // TODO(davidben): Enable this when resumption is implemented |
| 3278 | // in TLS 1.3. |
| 3279 | resumeSession: false, |
| 3280 | }) |
| 3281 | tests = append(tests, testCase{ |
| 3282 | testType: serverTest, |
| 3283 | name: "OCSPStapling-Server-TLS13", |
| 3284 | config: Config{ |
| 3285 | MaxVersion: VersionTLS13, |
| 3286 | }, |
| 3287 | expectedOCSPResponse: testOCSPResponse, |
| 3288 | flags: []string{ |
| 3289 | "-ocsp-response", |
| 3290 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 3291 | }, |
| 3292 | // TODO(davidben): Enable this when resumption is implemented |
| 3293 | // in TLS 1.3. |
| 3294 | resumeSession: false, |
| 3295 | }) |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 3296 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3297 | // Certificate verification tests. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3298 | for _, vers := range tlsVersions { |
| 3299 | if config.protocol == dtls && !vers.hasDTLS { |
| 3300 | continue |
| 3301 | } |
| 3302 | tests = append(tests, testCase{ |
| 3303 | testType: clientTest, |
| 3304 | name: "CertificateVerificationSucceed-" + vers.name, |
| 3305 | config: Config{ |
| 3306 | MaxVersion: vers.version, |
| 3307 | }, |
| 3308 | flags: []string{ |
| 3309 | "-verify-peer", |
| 3310 | }, |
| 3311 | }) |
| 3312 | tests = append(tests, testCase{ |
| 3313 | testType: clientTest, |
| 3314 | name: "CertificateVerificationFail-" + vers.name, |
| 3315 | config: Config{ |
| 3316 | MaxVersion: vers.version, |
| 3317 | }, |
| 3318 | flags: []string{ |
| 3319 | "-verify-fail", |
| 3320 | "-verify-peer", |
| 3321 | }, |
| 3322 | shouldFail: true, |
| 3323 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 3324 | }) |
| 3325 | tests = append(tests, testCase{ |
| 3326 | testType: clientTest, |
| 3327 | name: "CertificateVerificationSoftFail-" + vers.name, |
| 3328 | config: Config{ |
| 3329 | MaxVersion: vers.version, |
| 3330 | }, |
| 3331 | flags: []string{ |
| 3332 | "-verify-fail", |
| 3333 | "-expect-verify-result", |
| 3334 | }, |
| 3335 | }) |
| 3336 | } |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 3337 | |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3338 | if config.protocol == tls { |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3339 | tests = append(tests, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3340 | name: "Renegotiate-Client", |
| 3341 | config: Config{ |
| 3342 | MaxVersion: VersionTLS12, |
| 3343 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 3344 | renegotiate: 1, |
| 3345 | flags: []string{ |
| 3346 | "-renegotiate-freely", |
| 3347 | "-expect-total-renegotiations", "1", |
| 3348 | }, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3349 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3350 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3351 | // NPN on client and server; results in post-handshake message. |
| 3352 | tests = append(tests, testCase{ |
| 3353 | name: "NPN-Client", |
| 3354 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3355 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3356 | NextProtos: []string{"foo"}, |
| 3357 | }, |
| 3358 | flags: []string{"-select-next-proto", "foo"}, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3359 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3360 | expectedNextProto: "foo", |
| 3361 | expectedNextProtoType: npn, |
| 3362 | }) |
| 3363 | tests = append(tests, testCase{ |
| 3364 | testType: serverTest, |
| 3365 | name: "NPN-Server", |
| 3366 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3367 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3368 | NextProtos: []string{"bar"}, |
| 3369 | }, |
| 3370 | flags: []string{ |
| 3371 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3372 | "-expect-next-proto", "bar", |
| 3373 | }, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3374 | resumeSession: true, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3375 | expectedNextProto: "bar", |
| 3376 | expectedNextProtoType: npn, |
| 3377 | }) |
| 3378 | |
| 3379 | // TODO(davidben): Add tests for when False Start doesn't trigger. |
| 3380 | |
| 3381 | // Client does False Start and negotiates NPN. |
| 3382 | tests = append(tests, testCase{ |
| 3383 | name: "FalseStart", |
| 3384 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3385 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3386 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3387 | NextProtos: []string{"foo"}, |
| 3388 | Bugs: ProtocolBugs{ |
| 3389 | ExpectFalseStart: true, |
| 3390 | }, |
| 3391 | }, |
| 3392 | flags: []string{ |
| 3393 | "-false-start", |
| 3394 | "-select-next-proto", "foo", |
| 3395 | }, |
| 3396 | shimWritesFirst: true, |
| 3397 | resumeSession: true, |
| 3398 | }) |
| 3399 | |
| 3400 | // Client does False Start and negotiates ALPN. |
| 3401 | tests = append(tests, testCase{ |
| 3402 | name: "FalseStart-ALPN", |
| 3403 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3404 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3405 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3406 | NextProtos: []string{"foo"}, |
| 3407 | Bugs: ProtocolBugs{ |
| 3408 | ExpectFalseStart: true, |
| 3409 | }, |
| 3410 | }, |
| 3411 | flags: []string{ |
| 3412 | "-false-start", |
| 3413 | "-advertise-alpn", "\x03foo", |
| 3414 | }, |
| 3415 | shimWritesFirst: true, |
| 3416 | resumeSession: true, |
| 3417 | }) |
| 3418 | |
| 3419 | // Client does False Start but doesn't explicitly call |
| 3420 | // SSL_connect. |
| 3421 | tests = append(tests, testCase{ |
| 3422 | name: "FalseStart-Implicit", |
| 3423 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3424 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3425 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3426 | NextProtos: []string{"foo"}, |
| 3427 | }, |
| 3428 | flags: []string{ |
| 3429 | "-implicit-handshake", |
| 3430 | "-false-start", |
| 3431 | "-advertise-alpn", "\x03foo", |
| 3432 | }, |
| 3433 | }) |
| 3434 | |
| 3435 | // False Start without session tickets. |
| 3436 | tests = append(tests, testCase{ |
| 3437 | name: "FalseStart-SessionTicketsDisabled", |
| 3438 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3439 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3440 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3441 | NextProtos: []string{"foo"}, |
| 3442 | SessionTicketsDisabled: true, |
| 3443 | Bugs: ProtocolBugs{ |
| 3444 | ExpectFalseStart: true, |
| 3445 | }, |
| 3446 | }, |
| 3447 | flags: []string{ |
| 3448 | "-false-start", |
| 3449 | "-select-next-proto", "foo", |
| 3450 | }, |
| 3451 | shimWritesFirst: true, |
| 3452 | }) |
| 3453 | |
Adam Langley | df759b5 | 2016-07-11 15:24:37 -0700 | [diff] [blame] | 3454 | tests = append(tests, testCase{ |
| 3455 | name: "FalseStart-CECPQ1", |
| 3456 | config: Config{ |
| 3457 | MaxVersion: VersionTLS12, |
| 3458 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 3459 | NextProtos: []string{"foo"}, |
| 3460 | Bugs: ProtocolBugs{ |
| 3461 | ExpectFalseStart: true, |
| 3462 | }, |
| 3463 | }, |
| 3464 | flags: []string{ |
| 3465 | "-false-start", |
| 3466 | "-cipher", "DEFAULT:kCECPQ1", |
| 3467 | "-select-next-proto", "foo", |
| 3468 | }, |
| 3469 | shimWritesFirst: true, |
| 3470 | resumeSession: true, |
| 3471 | }) |
| 3472 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3473 | // Server parses a V2ClientHello. |
| 3474 | tests = append(tests, testCase{ |
| 3475 | testType: serverTest, |
| 3476 | name: "SendV2ClientHello", |
| 3477 | config: Config{ |
| 3478 | // Choose a cipher suite that does not involve |
| 3479 | // elliptic curves, so no extensions are |
| 3480 | // involved. |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3481 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3482 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 3483 | Bugs: ProtocolBugs{ |
| 3484 | SendV2ClientHello: true, |
| 3485 | }, |
| 3486 | }, |
| 3487 | }) |
| 3488 | |
| 3489 | // Client sends a Channel ID. |
| 3490 | tests = append(tests, testCase{ |
| 3491 | name: "ChannelID-Client", |
| 3492 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3493 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3494 | RequestChannelID: true, |
| 3495 | }, |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 3496 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3497 | resumeSession: true, |
| 3498 | expectChannelID: true, |
| 3499 | }) |
| 3500 | |
| 3501 | // Server accepts a Channel ID. |
| 3502 | tests = append(tests, testCase{ |
| 3503 | testType: serverTest, |
| 3504 | name: "ChannelID-Server", |
| 3505 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3506 | MaxVersion: VersionTLS12, |
| 3507 | ChannelID: channelIDKey, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3508 | }, |
| 3509 | flags: []string{ |
| 3510 | "-expect-channel-id", |
| 3511 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3512 | }, |
| 3513 | resumeSession: true, |
| 3514 | expectChannelID: true, |
| 3515 | }) |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3516 | |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3517 | // Channel ID and NPN at the same time, to ensure their relative |
| 3518 | // ordering is correct. |
| 3519 | tests = append(tests, testCase{ |
| 3520 | name: "ChannelID-NPN-Client", |
| 3521 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3522 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3523 | RequestChannelID: true, |
| 3524 | NextProtos: []string{"foo"}, |
| 3525 | }, |
| 3526 | flags: []string{ |
| 3527 | "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile), |
| 3528 | "-select-next-proto", "foo", |
| 3529 | }, |
| 3530 | resumeSession: true, |
| 3531 | expectChannelID: true, |
| 3532 | expectedNextProto: "foo", |
| 3533 | expectedNextProtoType: npn, |
| 3534 | }) |
| 3535 | tests = append(tests, testCase{ |
| 3536 | testType: serverTest, |
| 3537 | name: "ChannelID-NPN-Server", |
| 3538 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3539 | MaxVersion: VersionTLS12, |
David Benjamin | f8fcdf3 | 2016-06-08 15:56:13 -0400 | [diff] [blame] | 3540 | ChannelID: channelIDKey, |
| 3541 | NextProtos: []string{"bar"}, |
| 3542 | }, |
| 3543 | flags: []string{ |
| 3544 | "-expect-channel-id", |
| 3545 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 3546 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 3547 | "-expect-next-proto", "bar", |
| 3548 | }, |
| 3549 | resumeSession: true, |
| 3550 | expectChannelID: true, |
| 3551 | expectedNextProto: "bar", |
| 3552 | expectedNextProtoType: npn, |
| 3553 | }) |
| 3554 | |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 3555 | // Bidirectional shutdown with the runner initiating. |
| 3556 | tests = append(tests, testCase{ |
| 3557 | name: "Shutdown-Runner", |
| 3558 | config: Config{ |
| 3559 | Bugs: ProtocolBugs{ |
| 3560 | ExpectCloseNotify: true, |
| 3561 | }, |
| 3562 | }, |
| 3563 | flags: []string{"-check-close-notify"}, |
| 3564 | }) |
| 3565 | |
| 3566 | // Bidirectional shutdown with the shim initiating. The runner, |
| 3567 | // in the meantime, sends garbage before the close_notify which |
| 3568 | // the shim must ignore. |
| 3569 | tests = append(tests, testCase{ |
| 3570 | name: "Shutdown-Shim", |
| 3571 | config: Config{ |
| 3572 | Bugs: ProtocolBugs{ |
| 3573 | ExpectCloseNotify: true, |
| 3574 | }, |
| 3575 | }, |
| 3576 | shimShutsDown: true, |
| 3577 | sendEmptyRecords: 1, |
| 3578 | sendWarningAlerts: 1, |
| 3579 | flags: []string{"-check-close-notify"}, |
| 3580 | }) |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3581 | } else { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3582 | // TODO(davidben): DTLS 1.3 will want a similar thing for |
| 3583 | // HelloRetryRequest. |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3584 | tests = append(tests, testCase{ |
| 3585 | name: "SkipHelloVerifyRequest", |
| 3586 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3587 | MaxVersion: VersionTLS12, |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3588 | Bugs: ProtocolBugs{ |
| 3589 | SkipHelloVerifyRequest: true, |
| 3590 | }, |
| 3591 | }, |
| 3592 | }) |
| 3593 | } |
| 3594 | |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3595 | for _, test := range tests { |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3596 | test.protocol = config.protocol |
| 3597 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3598 | test.name += "-DTLS" |
| 3599 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3600 | if config.async { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3601 | test.name += "-Async" |
| 3602 | test.flags = append(test.flags, "-async") |
| 3603 | } else { |
| 3604 | test.name += "-Sync" |
| 3605 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3606 | if config.splitHandshake { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3607 | test.name += "-SplitHandshakeRecords" |
| 3608 | test.config.Bugs.MaxHandshakeRecordLength = 1 |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3609 | if config.protocol == dtls { |
David Benjamin | 16285ea | 2015-11-03 15:39:45 -0500 | [diff] [blame] | 3610 | test.config.Bugs.MaxPacketLength = 256 |
| 3611 | test.flags = append(test.flags, "-mtu", "256") |
| 3612 | } |
| 3613 | } |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 3614 | if config.packHandshakeFlight { |
| 3615 | test.name += "-PackHandshakeFlight" |
| 3616 | test.config.Bugs.PackHandshakeFlight = true |
| 3617 | } |
David Benjamin | 760b1dd | 2015-05-15 23:33:48 -0400 | [diff] [blame] | 3618 | testCases = append(testCases, test) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 3619 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 3620 | } |
| 3621 | |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3622 | func addDDoSCallbackTests() { |
| 3623 | // DDoS callback. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3624 | // TODO(davidben): Implement DDoS resumption tests for TLS 1.3. |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3625 | for _, resume := range []bool{false, true} { |
| 3626 | suffix := "Resume" |
| 3627 | if resume { |
| 3628 | suffix = "No" + suffix |
| 3629 | } |
| 3630 | |
| 3631 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3632 | testType: serverTest, |
| 3633 | name: "Server-DDoS-OK-" + suffix, |
| 3634 | config: Config{ |
| 3635 | MaxVersion: VersionTLS12, |
| 3636 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3637 | flags: []string{"-install-ddos-callback"}, |
| 3638 | resumeSession: resume, |
| 3639 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3640 | if !resume { |
| 3641 | testCases = append(testCases, testCase{ |
| 3642 | testType: serverTest, |
| 3643 | name: "Server-DDoS-OK-" + suffix + "-TLS13", |
| 3644 | config: Config{ |
| 3645 | MaxVersion: VersionTLS13, |
| 3646 | }, |
| 3647 | flags: []string{"-install-ddos-callback"}, |
| 3648 | resumeSession: resume, |
| 3649 | }) |
| 3650 | } |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3651 | |
| 3652 | failFlag := "-fail-ddos-callback" |
| 3653 | if resume { |
| 3654 | failFlag = "-fail-second-ddos-callback" |
| 3655 | } |
| 3656 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 3657 | testType: serverTest, |
| 3658 | name: "Server-DDoS-Reject-" + suffix, |
| 3659 | config: Config{ |
| 3660 | MaxVersion: VersionTLS12, |
| 3661 | }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3662 | flags: []string{"-install-ddos-callback", failFlag}, |
| 3663 | resumeSession: resume, |
| 3664 | shouldFail: true, |
| 3665 | expectedError: ":CONNECTION_REJECTED:", |
| 3666 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 3667 | if !resume { |
| 3668 | testCases = append(testCases, testCase{ |
| 3669 | testType: serverTest, |
| 3670 | name: "Server-DDoS-Reject-" + suffix + "-TLS13", |
| 3671 | config: Config{ |
| 3672 | MaxVersion: VersionTLS13, |
| 3673 | }, |
| 3674 | flags: []string{"-install-ddos-callback", failFlag}, |
| 3675 | resumeSession: resume, |
| 3676 | shouldFail: true, |
| 3677 | expectedError: ":CONNECTION_REJECTED:", |
| 3678 | }) |
| 3679 | } |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 3680 | } |
| 3681 | } |
| 3682 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3683 | func addVersionNegotiationTests() { |
| 3684 | for i, shimVers := range tlsVersions { |
| 3685 | // Assemble flags to disable all newer versions on the shim. |
| 3686 | var flags []string |
| 3687 | for _, vers := range tlsVersions[i+1:] { |
| 3688 | flags = append(flags, vers.flag) |
| 3689 | } |
| 3690 | |
| 3691 | for _, runnerVers := range tlsVersions { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3692 | protocols := []protocol{tls} |
| 3693 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 3694 | protocols = append(protocols, dtls) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3695 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3696 | for _, protocol := range protocols { |
| 3697 | expectedVersion := shimVers.version |
| 3698 | if runnerVers.version < shimVers.version { |
| 3699 | expectedVersion = runnerVers.version |
| 3700 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3701 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3702 | suffix := shimVers.name + "-" + runnerVers.name |
| 3703 | if protocol == dtls { |
| 3704 | suffix += "-DTLS" |
| 3705 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3706 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3707 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 3708 | |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3709 | clientVers := shimVers.version |
| 3710 | if clientVers > VersionTLS10 { |
| 3711 | clientVers = VersionTLS10 |
| 3712 | } |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3713 | serverVers := expectedVersion |
| 3714 | if expectedVersion >= VersionTLS13 { |
| 3715 | serverVers = VersionTLS10 |
| 3716 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3717 | testCases = append(testCases, testCase{ |
| 3718 | protocol: protocol, |
| 3719 | testType: clientTest, |
| 3720 | name: "VersionNegotiation-Client-" + suffix, |
| 3721 | config: Config{ |
| 3722 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3723 | Bugs: ProtocolBugs{ |
| 3724 | ExpectInitialRecordVersion: clientVers, |
| 3725 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3726 | }, |
| 3727 | flags: flags, |
| 3728 | expectedVersion: expectedVersion, |
| 3729 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3730 | testCases = append(testCases, testCase{ |
| 3731 | protocol: protocol, |
| 3732 | testType: clientTest, |
| 3733 | name: "VersionNegotiation-Client2-" + suffix, |
| 3734 | config: Config{ |
| 3735 | MaxVersion: runnerVers.version, |
| 3736 | Bugs: ProtocolBugs{ |
| 3737 | ExpectInitialRecordVersion: clientVers, |
| 3738 | }, |
| 3739 | }, |
| 3740 | flags: []string{"-max-version", shimVersFlag}, |
| 3741 | expectedVersion: expectedVersion, |
| 3742 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3743 | |
| 3744 | testCases = append(testCases, testCase{ |
| 3745 | protocol: protocol, |
| 3746 | testType: serverTest, |
| 3747 | name: "VersionNegotiation-Server-" + suffix, |
| 3748 | config: Config{ |
| 3749 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3750 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3751 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 3752 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3753 | }, |
| 3754 | flags: flags, |
| 3755 | expectedVersion: expectedVersion, |
| 3756 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3757 | testCases = append(testCases, testCase{ |
| 3758 | protocol: protocol, |
| 3759 | testType: serverTest, |
| 3760 | name: "VersionNegotiation-Server2-" + suffix, |
| 3761 | config: Config{ |
| 3762 | MaxVersion: runnerVers.version, |
| 3763 | Bugs: ProtocolBugs{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 3764 | ExpectInitialRecordVersion: serverVers, |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 3765 | }, |
| 3766 | }, |
| 3767 | flags: []string{"-max-version", shimVersFlag}, |
| 3768 | expectedVersion: expectedVersion, |
| 3769 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 3770 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3771 | } |
| 3772 | } |
David Benjamin | 95c6956 | 2016-06-29 18:15:03 -0400 | [diff] [blame] | 3773 | |
| 3774 | // Test for version tolerance. |
| 3775 | testCases = append(testCases, testCase{ |
| 3776 | testType: serverTest, |
| 3777 | name: "MinorVersionTolerance", |
| 3778 | config: Config{ |
| 3779 | Bugs: ProtocolBugs{ |
| 3780 | SendClientVersion: 0x03ff, |
| 3781 | }, |
| 3782 | }, |
| 3783 | expectedVersion: VersionTLS13, |
| 3784 | }) |
| 3785 | testCases = append(testCases, testCase{ |
| 3786 | testType: serverTest, |
| 3787 | name: "MajorVersionTolerance", |
| 3788 | config: Config{ |
| 3789 | Bugs: ProtocolBugs{ |
| 3790 | SendClientVersion: 0x0400, |
| 3791 | }, |
| 3792 | }, |
| 3793 | expectedVersion: VersionTLS13, |
| 3794 | }) |
| 3795 | testCases = append(testCases, testCase{ |
| 3796 | protocol: dtls, |
| 3797 | testType: serverTest, |
| 3798 | name: "MinorVersionTolerance-DTLS", |
| 3799 | config: Config{ |
| 3800 | Bugs: ProtocolBugs{ |
| 3801 | SendClientVersion: 0x03ff, |
| 3802 | }, |
| 3803 | }, |
| 3804 | expectedVersion: VersionTLS12, |
| 3805 | }) |
| 3806 | testCases = append(testCases, testCase{ |
| 3807 | protocol: dtls, |
| 3808 | testType: serverTest, |
| 3809 | name: "MajorVersionTolerance-DTLS", |
| 3810 | config: Config{ |
| 3811 | Bugs: ProtocolBugs{ |
| 3812 | SendClientVersion: 0x0400, |
| 3813 | }, |
| 3814 | }, |
| 3815 | expectedVersion: VersionTLS12, |
| 3816 | }) |
| 3817 | |
| 3818 | // Test that versions below 3.0 are rejected. |
| 3819 | testCases = append(testCases, testCase{ |
| 3820 | testType: serverTest, |
| 3821 | name: "VersionTooLow", |
| 3822 | config: Config{ |
| 3823 | Bugs: ProtocolBugs{ |
| 3824 | SendClientVersion: 0x0200, |
| 3825 | }, |
| 3826 | }, |
| 3827 | shouldFail: true, |
| 3828 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 3829 | }) |
| 3830 | testCases = append(testCases, testCase{ |
| 3831 | protocol: dtls, |
| 3832 | testType: serverTest, |
| 3833 | name: "VersionTooLow-DTLS", |
| 3834 | config: Config{ |
| 3835 | Bugs: ProtocolBugs{ |
| 3836 | // 0x0201 is the lowest version expressable in |
| 3837 | // DTLS. |
| 3838 | SendClientVersion: 0x0201, |
| 3839 | }, |
| 3840 | }, |
| 3841 | shouldFail: true, |
| 3842 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 3843 | }) |
David Benjamin | 1f61f0d | 2016-07-10 12:20:35 -0400 | [diff] [blame] | 3844 | |
| 3845 | // Test TLS 1.3's downgrade signal. |
| 3846 | testCases = append(testCases, testCase{ |
| 3847 | name: "Downgrade-TLS12-Client", |
| 3848 | config: Config{ |
| 3849 | Bugs: ProtocolBugs{ |
| 3850 | NegotiateVersion: VersionTLS12, |
| 3851 | }, |
| 3852 | }, |
| 3853 | shouldFail: true, |
| 3854 | expectedError: ":DOWNGRADE_DETECTED:", |
| 3855 | }) |
| 3856 | testCases = append(testCases, testCase{ |
| 3857 | testType: serverTest, |
| 3858 | name: "Downgrade-TLS12-Server", |
| 3859 | config: Config{ |
| 3860 | Bugs: ProtocolBugs{ |
| 3861 | SendClientVersion: VersionTLS12, |
| 3862 | }, |
| 3863 | }, |
| 3864 | shouldFail: true, |
| 3865 | expectedLocalError: "tls: downgrade from TLS 1.3 detected", |
| 3866 | }) |
David Benjamin | 5e7e7cc | 2016-07-21 12:55:28 +0200 | [diff] [blame] | 3867 | |
| 3868 | // Test that FALLBACK_SCSV is sent and that the downgrade signal works |
| 3869 | // behave correctly when both real maximum and fallback versions are |
| 3870 | // set. |
| 3871 | testCases = append(testCases, testCase{ |
| 3872 | name: "Downgrade-TLS12-Client-Fallback", |
| 3873 | config: Config{ |
| 3874 | Bugs: ProtocolBugs{ |
| 3875 | FailIfNotFallbackSCSV: true, |
| 3876 | }, |
| 3877 | }, |
| 3878 | flags: []string{ |
| 3879 | "-max-version", strconv.Itoa(VersionTLS13), |
| 3880 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 3881 | }, |
| 3882 | shouldFail: true, |
| 3883 | expectedError: ":DOWNGRADE_DETECTED:", |
| 3884 | }) |
| 3885 | testCases = append(testCases, testCase{ |
| 3886 | name: "Downgrade-TLS12-Client-FallbackEqualsMax", |
| 3887 | flags: []string{ |
| 3888 | "-max-version", strconv.Itoa(VersionTLS12), |
| 3889 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 3890 | }, |
| 3891 | }) |
| 3892 | |
| 3893 | // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather |
| 3894 | // just have such connections fail than risk getting confused because we |
| 3895 | // didn't sent the 1.3 ClientHello.) |
| 3896 | testCases = append(testCases, testCase{ |
| 3897 | name: "Downgrade-TLS12-Fallback-CheckVersion", |
| 3898 | config: Config{ |
| 3899 | Bugs: ProtocolBugs{ |
| 3900 | NegotiateVersion: VersionTLS13, |
| 3901 | FailIfNotFallbackSCSV: true, |
| 3902 | }, |
| 3903 | }, |
| 3904 | flags: []string{ |
| 3905 | "-max-version", strconv.Itoa(VersionTLS13), |
| 3906 | "-fallback-version", strconv.Itoa(VersionTLS12), |
| 3907 | }, |
| 3908 | shouldFail: true, |
| 3909 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 3910 | }) |
| 3911 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 3912 | } |
| 3913 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3914 | func addMinimumVersionTests() { |
| 3915 | for i, shimVers := range tlsVersions { |
| 3916 | // Assemble flags to disable all older versions on the shim. |
| 3917 | var flags []string |
| 3918 | for _, vers := range tlsVersions[:i] { |
| 3919 | flags = append(flags, vers.flag) |
| 3920 | } |
| 3921 | |
| 3922 | for _, runnerVers := range tlsVersions { |
| 3923 | protocols := []protocol{tls} |
| 3924 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 3925 | protocols = append(protocols, dtls) |
| 3926 | } |
| 3927 | for _, protocol := range protocols { |
| 3928 | suffix := shimVers.name + "-" + runnerVers.name |
| 3929 | if protocol == dtls { |
| 3930 | suffix += "-DTLS" |
| 3931 | } |
| 3932 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 3933 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3934 | var expectedVersion uint16 |
| 3935 | var shouldFail bool |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 3936 | var expectedClientError, expectedServerError string |
| 3937 | var expectedClientLocalError, expectedServerLocalError string |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3938 | if runnerVers.version >= shimVers.version { |
| 3939 | expectedVersion = runnerVers.version |
| 3940 | } else { |
| 3941 | shouldFail = true |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 3942 | expectedServerError = ":UNSUPPORTED_PROTOCOL:" |
| 3943 | expectedServerLocalError = "remote error: protocol version not supported" |
| 3944 | if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 { |
| 3945 | // If the client's minimum version is TLS 1.3 and the runner's |
| 3946 | // maximum is below TLS 1.2, the runner will fail to select a |
| 3947 | // cipher before the shim rejects the selected version. |
| 3948 | expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:" |
| 3949 | expectedClientLocalError = "tls: no cipher suite supported by both client and server" |
| 3950 | } else { |
| 3951 | expectedClientError = expectedServerError |
| 3952 | expectedClientLocalError = expectedServerLocalError |
| 3953 | } |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3954 | } |
| 3955 | |
| 3956 | testCases = append(testCases, testCase{ |
| 3957 | protocol: protocol, |
| 3958 | testType: clientTest, |
| 3959 | name: "MinimumVersion-Client-" + suffix, |
| 3960 | config: Config{ |
| 3961 | MaxVersion: runnerVers.version, |
| 3962 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3963 | flags: flags, |
| 3964 | expectedVersion: expectedVersion, |
| 3965 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 3966 | expectedError: expectedClientError, |
| 3967 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3968 | }) |
| 3969 | testCases = append(testCases, testCase{ |
| 3970 | protocol: protocol, |
| 3971 | testType: clientTest, |
| 3972 | name: "MinimumVersion-Client2-" + suffix, |
| 3973 | config: Config{ |
| 3974 | MaxVersion: runnerVers.version, |
| 3975 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3976 | flags: []string{"-min-version", shimVersFlag}, |
| 3977 | expectedVersion: expectedVersion, |
| 3978 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 3979 | expectedError: expectedClientError, |
| 3980 | expectedLocalError: expectedClientLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3981 | }) |
| 3982 | |
| 3983 | testCases = append(testCases, testCase{ |
| 3984 | protocol: protocol, |
| 3985 | testType: serverTest, |
| 3986 | name: "MinimumVersion-Server-" + suffix, |
| 3987 | config: Config{ |
| 3988 | MaxVersion: runnerVers.version, |
| 3989 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 3990 | flags: flags, |
| 3991 | expectedVersion: expectedVersion, |
| 3992 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 3993 | expectedError: expectedServerError, |
| 3994 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 3995 | }) |
| 3996 | testCases = append(testCases, testCase{ |
| 3997 | protocol: protocol, |
| 3998 | testType: serverTest, |
| 3999 | name: "MinimumVersion-Server2-" + suffix, |
| 4000 | config: Config{ |
| 4001 | MaxVersion: runnerVers.version, |
| 4002 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 4003 | flags: []string{"-min-version", shimVersFlag}, |
| 4004 | expectedVersion: expectedVersion, |
| 4005 | shouldFail: shouldFail, |
David Benjamin | 929d4ee | 2016-06-24 23:55:58 -0400 | [diff] [blame] | 4006 | expectedError: expectedServerError, |
| 4007 | expectedLocalError: expectedServerLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 4008 | }) |
| 4009 | } |
| 4010 | } |
| 4011 | } |
| 4012 | } |
| 4013 | |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4014 | func addExtensionTests() { |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4015 | // TODO(davidben): Extensions, where applicable, all move their server |
| 4016 | // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these |
| 4017 | // tests for both. Also test interaction with 0-RTT when implemented. |
| 4018 | |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4019 | // Repeat extensions tests all versions except SSL 3.0. |
| 4020 | for _, ver := range tlsVersions { |
| 4021 | if ver.version == VersionSSL30 { |
| 4022 | continue |
| 4023 | } |
| 4024 | |
| 4025 | // TODO(davidben): Implement resumption in TLS 1.3. |
| 4026 | resumeSession := ver.version < VersionTLS13 |
| 4027 | |
| 4028 | // Test that duplicate extensions are rejected. |
| 4029 | testCases = append(testCases, testCase{ |
| 4030 | testType: clientTest, |
| 4031 | name: "DuplicateExtensionClient-" + ver.name, |
| 4032 | config: Config{ |
| 4033 | MaxVersion: ver.version, |
| 4034 | Bugs: ProtocolBugs{ |
| 4035 | DuplicateExtension: true, |
| 4036 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4037 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4038 | shouldFail: true, |
| 4039 | expectedLocalError: "remote error: error decoding message", |
| 4040 | }) |
| 4041 | testCases = append(testCases, testCase{ |
| 4042 | testType: serverTest, |
| 4043 | name: "DuplicateExtensionServer-" + ver.name, |
| 4044 | config: Config{ |
| 4045 | MaxVersion: ver.version, |
| 4046 | Bugs: ProtocolBugs{ |
| 4047 | DuplicateExtension: true, |
| 4048 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4049 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4050 | shouldFail: true, |
| 4051 | expectedLocalError: "remote error: error decoding message", |
| 4052 | }) |
| 4053 | |
| 4054 | // Test SNI. |
| 4055 | testCases = append(testCases, testCase{ |
| 4056 | testType: clientTest, |
| 4057 | name: "ServerNameExtensionClient-" + ver.name, |
| 4058 | config: Config{ |
| 4059 | MaxVersion: ver.version, |
| 4060 | Bugs: ProtocolBugs{ |
| 4061 | ExpectServerName: "example.com", |
| 4062 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4063 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4064 | flags: []string{"-host-name", "example.com"}, |
| 4065 | }) |
| 4066 | testCases = append(testCases, testCase{ |
| 4067 | testType: clientTest, |
| 4068 | name: "ServerNameExtensionClientMismatch-" + ver.name, |
| 4069 | config: Config{ |
| 4070 | MaxVersion: ver.version, |
| 4071 | Bugs: ProtocolBugs{ |
| 4072 | ExpectServerName: "mismatch.com", |
| 4073 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4074 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4075 | flags: []string{"-host-name", "example.com"}, |
| 4076 | shouldFail: true, |
| 4077 | expectedLocalError: "tls: unexpected server name", |
| 4078 | }) |
| 4079 | testCases = append(testCases, testCase{ |
| 4080 | testType: clientTest, |
| 4081 | name: "ServerNameExtensionClientMissing-" + ver.name, |
| 4082 | config: Config{ |
| 4083 | MaxVersion: ver.version, |
| 4084 | Bugs: ProtocolBugs{ |
| 4085 | ExpectServerName: "missing.com", |
| 4086 | }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4087 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4088 | shouldFail: true, |
| 4089 | expectedLocalError: "tls: unexpected server name", |
| 4090 | }) |
| 4091 | testCases = append(testCases, testCase{ |
| 4092 | testType: serverTest, |
| 4093 | name: "ServerNameExtensionServer-" + ver.name, |
| 4094 | config: Config{ |
| 4095 | MaxVersion: ver.version, |
| 4096 | ServerName: "example.com", |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 4097 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4098 | flags: []string{"-expect-server-name", "example.com"}, |
| 4099 | resumeSession: resumeSession, |
| 4100 | }) |
| 4101 | |
| 4102 | // Test ALPN. |
| 4103 | testCases = append(testCases, testCase{ |
| 4104 | testType: clientTest, |
| 4105 | name: "ALPNClient-" + ver.name, |
| 4106 | config: Config{ |
| 4107 | MaxVersion: ver.version, |
| 4108 | NextProtos: []string{"foo"}, |
| 4109 | }, |
| 4110 | flags: []string{ |
| 4111 | "-advertise-alpn", "\x03foo\x03bar\x03baz", |
| 4112 | "-expect-alpn", "foo", |
| 4113 | }, |
| 4114 | expectedNextProto: "foo", |
| 4115 | expectedNextProtoType: alpn, |
| 4116 | resumeSession: resumeSession, |
| 4117 | }) |
| 4118 | testCases = append(testCases, testCase{ |
| 4119 | testType: serverTest, |
| 4120 | name: "ALPNServer-" + ver.name, |
| 4121 | config: Config{ |
| 4122 | MaxVersion: ver.version, |
| 4123 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4124 | }, |
| 4125 | flags: []string{ |
| 4126 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4127 | "-select-alpn", "foo", |
| 4128 | }, |
| 4129 | expectedNextProto: "foo", |
| 4130 | expectedNextProtoType: alpn, |
| 4131 | resumeSession: resumeSession, |
| 4132 | }) |
| 4133 | testCases = append(testCases, testCase{ |
| 4134 | testType: serverTest, |
| 4135 | name: "ALPNServer-Decline-" + ver.name, |
| 4136 | config: Config{ |
| 4137 | MaxVersion: ver.version, |
| 4138 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4139 | }, |
| 4140 | flags: []string{"-decline-alpn"}, |
| 4141 | expectNoNextProto: true, |
| 4142 | resumeSession: resumeSession, |
| 4143 | }) |
| 4144 | |
| 4145 | var emptyString string |
| 4146 | testCases = append(testCases, testCase{ |
| 4147 | testType: clientTest, |
| 4148 | name: "ALPNClient-EmptyProtocolName-" + ver.name, |
| 4149 | config: Config{ |
| 4150 | MaxVersion: ver.version, |
| 4151 | NextProtos: []string{""}, |
| 4152 | Bugs: ProtocolBugs{ |
| 4153 | // A server returning an empty ALPN protocol |
| 4154 | // should be rejected. |
| 4155 | ALPNProtocol: &emptyString, |
| 4156 | }, |
| 4157 | }, |
| 4158 | flags: []string{ |
| 4159 | "-advertise-alpn", "\x03foo", |
| 4160 | }, |
| 4161 | shouldFail: true, |
| 4162 | expectedError: ":PARSE_TLSEXT:", |
| 4163 | }) |
| 4164 | testCases = append(testCases, testCase{ |
| 4165 | testType: serverTest, |
| 4166 | name: "ALPNServer-EmptyProtocolName-" + ver.name, |
| 4167 | config: Config{ |
| 4168 | MaxVersion: ver.version, |
| 4169 | // A ClientHello containing an empty ALPN protocol |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4170 | // should be rejected. |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4171 | NextProtos: []string{"foo", "", "baz"}, |
Adam Langley | efb0e16 | 2015-07-09 11:35:04 -0700 | [diff] [blame] | 4172 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4173 | flags: []string{ |
| 4174 | "-select-alpn", "foo", |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 4175 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4176 | shouldFail: true, |
| 4177 | expectedError: ":PARSE_TLSEXT:", |
| 4178 | }) |
| 4179 | |
| 4180 | // Test NPN and the interaction with ALPN. |
| 4181 | if ver.version < VersionTLS13 { |
| 4182 | // Test that the server prefers ALPN over NPN. |
| 4183 | testCases = append(testCases, testCase{ |
| 4184 | testType: serverTest, |
| 4185 | name: "ALPNServer-Preferred-" + ver.name, |
| 4186 | config: Config{ |
| 4187 | MaxVersion: ver.version, |
| 4188 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4189 | }, |
| 4190 | flags: []string{ |
| 4191 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4192 | "-select-alpn", "foo", |
| 4193 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4194 | }, |
| 4195 | expectedNextProto: "foo", |
| 4196 | expectedNextProtoType: alpn, |
| 4197 | resumeSession: resumeSession, |
| 4198 | }) |
| 4199 | testCases = append(testCases, testCase{ |
| 4200 | testType: serverTest, |
| 4201 | name: "ALPNServer-Preferred-Swapped-" + ver.name, |
| 4202 | config: Config{ |
| 4203 | MaxVersion: ver.version, |
| 4204 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4205 | Bugs: ProtocolBugs{ |
| 4206 | SwapNPNAndALPN: true, |
| 4207 | }, |
| 4208 | }, |
| 4209 | flags: []string{ |
| 4210 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 4211 | "-select-alpn", "foo", |
| 4212 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 4213 | }, |
| 4214 | expectedNextProto: "foo", |
| 4215 | expectedNextProtoType: alpn, |
| 4216 | resumeSession: resumeSession, |
| 4217 | }) |
| 4218 | |
| 4219 | // Test that negotiating both NPN and ALPN is forbidden. |
| 4220 | testCases = append(testCases, testCase{ |
| 4221 | name: "NegotiateALPNAndNPN-" + ver.name, |
| 4222 | config: Config{ |
| 4223 | MaxVersion: ver.version, |
| 4224 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4225 | Bugs: ProtocolBugs{ |
| 4226 | NegotiateALPNAndNPN: true, |
| 4227 | }, |
| 4228 | }, |
| 4229 | flags: []string{ |
| 4230 | "-advertise-alpn", "\x03foo", |
| 4231 | "-select-next-proto", "foo", |
| 4232 | }, |
| 4233 | shouldFail: true, |
| 4234 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4235 | }) |
| 4236 | testCases = append(testCases, testCase{ |
| 4237 | name: "NegotiateALPNAndNPN-Swapped-" + ver.name, |
| 4238 | config: Config{ |
| 4239 | MaxVersion: ver.version, |
| 4240 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4241 | Bugs: ProtocolBugs{ |
| 4242 | NegotiateALPNAndNPN: true, |
| 4243 | SwapNPNAndALPN: true, |
| 4244 | }, |
| 4245 | }, |
| 4246 | flags: []string{ |
| 4247 | "-advertise-alpn", "\x03foo", |
| 4248 | "-select-next-proto", "foo", |
| 4249 | }, |
| 4250 | shouldFail: true, |
| 4251 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 4252 | }) |
| 4253 | |
| 4254 | // Test that NPN can be disabled with SSL_OP_DISABLE_NPN. |
| 4255 | testCases = append(testCases, testCase{ |
| 4256 | name: "DisableNPN-" + ver.name, |
| 4257 | config: Config{ |
| 4258 | MaxVersion: ver.version, |
| 4259 | NextProtos: []string{"foo"}, |
| 4260 | }, |
| 4261 | flags: []string{ |
| 4262 | "-select-next-proto", "foo", |
| 4263 | "-disable-npn", |
| 4264 | }, |
| 4265 | expectNoNextProto: true, |
| 4266 | }) |
| 4267 | } |
| 4268 | |
| 4269 | // Test ticket behavior. |
| 4270 | // |
| 4271 | // TODO(davidben): Add TLS 1.3 versions of these. |
| 4272 | if ver.version < VersionTLS13 { |
| 4273 | // Resume with a corrupt ticket. |
| 4274 | testCases = append(testCases, testCase{ |
| 4275 | testType: serverTest, |
| 4276 | name: "CorruptTicket-" + ver.name, |
| 4277 | config: Config{ |
| 4278 | MaxVersion: ver.version, |
| 4279 | Bugs: ProtocolBugs{ |
| 4280 | CorruptTicket: true, |
| 4281 | }, |
| 4282 | }, |
| 4283 | resumeSession: true, |
| 4284 | expectResumeRejected: true, |
| 4285 | }) |
| 4286 | // Test the ticket callback, with and without renewal. |
| 4287 | testCases = append(testCases, testCase{ |
| 4288 | testType: serverTest, |
| 4289 | name: "TicketCallback-" + ver.name, |
| 4290 | config: Config{ |
| 4291 | MaxVersion: ver.version, |
| 4292 | }, |
| 4293 | resumeSession: true, |
| 4294 | flags: []string{"-use-ticket-callback"}, |
| 4295 | }) |
| 4296 | testCases = append(testCases, testCase{ |
| 4297 | testType: serverTest, |
| 4298 | name: "TicketCallback-Renew-" + ver.name, |
| 4299 | config: Config{ |
| 4300 | MaxVersion: ver.version, |
| 4301 | Bugs: ProtocolBugs{ |
| 4302 | ExpectNewTicket: true, |
| 4303 | }, |
| 4304 | }, |
| 4305 | flags: []string{"-use-ticket-callback", "-renew-ticket"}, |
| 4306 | resumeSession: true, |
| 4307 | }) |
| 4308 | |
| 4309 | // Resume with an oversized session id. |
| 4310 | testCases = append(testCases, testCase{ |
| 4311 | testType: serverTest, |
| 4312 | name: "OversizedSessionId-" + ver.name, |
| 4313 | config: Config{ |
| 4314 | MaxVersion: ver.version, |
| 4315 | Bugs: ProtocolBugs{ |
| 4316 | OversizedSessionId: true, |
| 4317 | }, |
| 4318 | }, |
| 4319 | resumeSession: true, |
| 4320 | shouldFail: true, |
| 4321 | expectedError: ":DECODE_ERROR:", |
| 4322 | }) |
| 4323 | } |
| 4324 | |
| 4325 | // Basic DTLS-SRTP tests. Include fake profiles to ensure they |
| 4326 | // are ignored. |
| 4327 | if ver.hasDTLS { |
| 4328 | testCases = append(testCases, testCase{ |
| 4329 | protocol: dtls, |
| 4330 | name: "SRTP-Client-" + ver.name, |
| 4331 | config: Config{ |
| 4332 | MaxVersion: ver.version, |
| 4333 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4334 | }, |
| 4335 | flags: []string{ |
| 4336 | "-srtp-profiles", |
| 4337 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4338 | }, |
| 4339 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4340 | }) |
| 4341 | testCases = append(testCases, testCase{ |
| 4342 | protocol: dtls, |
| 4343 | testType: serverTest, |
| 4344 | name: "SRTP-Server-" + ver.name, |
| 4345 | config: Config{ |
| 4346 | MaxVersion: ver.version, |
| 4347 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 4348 | }, |
| 4349 | flags: []string{ |
| 4350 | "-srtp-profiles", |
| 4351 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4352 | }, |
| 4353 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4354 | }) |
| 4355 | // Test that the MKI is ignored. |
| 4356 | testCases = append(testCases, testCase{ |
| 4357 | protocol: dtls, |
| 4358 | testType: serverTest, |
| 4359 | name: "SRTP-Server-IgnoreMKI-" + ver.name, |
| 4360 | config: Config{ |
| 4361 | MaxVersion: ver.version, |
| 4362 | SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80}, |
| 4363 | Bugs: ProtocolBugs{ |
| 4364 | SRTPMasterKeyIdentifer: "bogus", |
| 4365 | }, |
| 4366 | }, |
| 4367 | flags: []string{ |
| 4368 | "-srtp-profiles", |
| 4369 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4370 | }, |
| 4371 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 4372 | }) |
| 4373 | // Test that SRTP isn't negotiated on the server if there were |
| 4374 | // no matching profiles. |
| 4375 | testCases = append(testCases, testCase{ |
| 4376 | protocol: dtls, |
| 4377 | testType: serverTest, |
| 4378 | name: "SRTP-Server-NoMatch-" + ver.name, |
| 4379 | config: Config{ |
| 4380 | MaxVersion: ver.version, |
| 4381 | SRTPProtectionProfiles: []uint16{100, 101, 102}, |
| 4382 | }, |
| 4383 | flags: []string{ |
| 4384 | "-srtp-profiles", |
| 4385 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 4386 | }, |
| 4387 | expectedSRTPProtectionProfile: 0, |
| 4388 | }) |
| 4389 | // Test that the server returning an invalid SRTP profile is |
| 4390 | // flagged as an error by the client. |
| 4391 | testCases = append(testCases, testCase{ |
| 4392 | protocol: dtls, |
| 4393 | name: "SRTP-Client-NoMatch-" + ver.name, |
| 4394 | config: Config{ |
| 4395 | MaxVersion: ver.version, |
| 4396 | Bugs: ProtocolBugs{ |
| 4397 | SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32, |
| 4398 | }, |
| 4399 | }, |
| 4400 | flags: []string{ |
| 4401 | "-srtp-profiles", |
| 4402 | "SRTP_AES128_CM_SHA1_80", |
| 4403 | }, |
| 4404 | shouldFail: true, |
| 4405 | expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:", |
| 4406 | }) |
| 4407 | } |
| 4408 | |
| 4409 | // Test SCT list. |
| 4410 | testCases = append(testCases, testCase{ |
| 4411 | name: "SignedCertificateTimestampList-Client-" + ver.name, |
| 4412 | testType: clientTest, |
| 4413 | config: Config{ |
| 4414 | MaxVersion: ver.version, |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 4415 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4416 | flags: []string{ |
| 4417 | "-enable-signed-cert-timestamps", |
| 4418 | "-expect-signed-cert-timestamps", |
| 4419 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 4420 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4421 | resumeSession: resumeSession, |
| 4422 | }) |
| 4423 | testCases = append(testCases, testCase{ |
| 4424 | name: "SendSCTListOnResume-" + ver.name, |
| 4425 | config: Config{ |
| 4426 | MaxVersion: ver.version, |
| 4427 | Bugs: ProtocolBugs{ |
| 4428 | SendSCTListOnResume: []byte("bogus"), |
| 4429 | }, |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 4430 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4431 | flags: []string{ |
| 4432 | "-enable-signed-cert-timestamps", |
| 4433 | "-expect-signed-cert-timestamps", |
| 4434 | base64.StdEncoding.EncodeToString(testSCTList), |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 4435 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4436 | resumeSession: resumeSession, |
| 4437 | }) |
| 4438 | testCases = append(testCases, testCase{ |
| 4439 | name: "SignedCertificateTimestampList-Server-" + ver.name, |
| 4440 | testType: serverTest, |
| 4441 | config: Config{ |
| 4442 | MaxVersion: ver.version, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4443 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4444 | flags: []string{ |
| 4445 | "-signed-cert-timestamps", |
| 4446 | base64.StdEncoding.EncodeToString(testSCTList), |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 4447 | }, |
David Benjamin | 97d17d9 | 2016-07-14 16:12:00 -0400 | [diff] [blame] | 4448 | expectedSCTList: testSCTList, |
| 4449 | resumeSession: resumeSession, |
| 4450 | }) |
| 4451 | } |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4452 | |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 4453 | testCases = append(testCases, testCase{ |
Adam Langley | 33ad2b5 | 2015-07-20 17:43:53 -0700 | [diff] [blame] | 4454 | testType: clientTest, |
| 4455 | name: "ClientHelloPadding", |
| 4456 | config: Config{ |
| 4457 | Bugs: ProtocolBugs{ |
| 4458 | RequireClientHelloSize: 512, |
| 4459 | }, |
| 4460 | }, |
| 4461 | // This hostname just needs to be long enough to push the |
| 4462 | // ClientHello into F5's danger zone between 256 and 511 bytes |
| 4463 | // long. |
| 4464 | flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"}, |
| 4465 | }) |
David Benjamin | c7ce977 | 2015-10-09 19:32:41 -0400 | [diff] [blame] | 4466 | |
| 4467 | // Extensions should not function in SSL 3.0. |
| 4468 | testCases = append(testCases, testCase{ |
| 4469 | testType: serverTest, |
| 4470 | name: "SSLv3Extensions-NoALPN", |
| 4471 | config: Config{ |
| 4472 | MaxVersion: VersionSSL30, |
| 4473 | NextProtos: []string{"foo", "bar", "baz"}, |
| 4474 | }, |
| 4475 | flags: []string{ |
| 4476 | "-select-alpn", "foo", |
| 4477 | }, |
| 4478 | expectNoNextProto: true, |
| 4479 | }) |
| 4480 | |
| 4481 | // Test session tickets separately as they follow a different codepath. |
| 4482 | testCases = append(testCases, testCase{ |
| 4483 | testType: serverTest, |
| 4484 | name: "SSLv3Extensions-NoTickets", |
| 4485 | config: Config{ |
| 4486 | MaxVersion: VersionSSL30, |
| 4487 | Bugs: ProtocolBugs{ |
| 4488 | // Historically, session tickets in SSL 3.0 |
| 4489 | // failed in different ways depending on whether |
| 4490 | // the client supported renegotiation_info. |
| 4491 | NoRenegotiationInfo: true, |
| 4492 | }, |
| 4493 | }, |
| 4494 | resumeSession: true, |
| 4495 | }) |
| 4496 | testCases = append(testCases, testCase{ |
| 4497 | testType: serverTest, |
| 4498 | name: "SSLv3Extensions-NoTickets2", |
| 4499 | config: Config{ |
| 4500 | MaxVersion: VersionSSL30, |
| 4501 | }, |
| 4502 | resumeSession: true, |
| 4503 | }) |
| 4504 | |
| 4505 | // But SSL 3.0 does send and process renegotiation_info. |
| 4506 | testCases = append(testCases, testCase{ |
| 4507 | testType: serverTest, |
| 4508 | name: "SSLv3Extensions-RenegotiationInfo", |
| 4509 | config: Config{ |
| 4510 | MaxVersion: VersionSSL30, |
| 4511 | Bugs: ProtocolBugs{ |
| 4512 | RequireRenegotiationInfo: true, |
| 4513 | }, |
| 4514 | }, |
| 4515 | }) |
| 4516 | testCases = append(testCases, testCase{ |
| 4517 | testType: serverTest, |
| 4518 | name: "SSLv3Extensions-RenegotiationInfo-SCSV", |
| 4519 | config: Config{ |
| 4520 | MaxVersion: VersionSSL30, |
| 4521 | Bugs: ProtocolBugs{ |
| 4522 | NoRenegotiationInfo: true, |
| 4523 | SendRenegotiationSCSV: true, |
| 4524 | RequireRenegotiationInfo: true, |
| 4525 | }, |
| 4526 | }, |
| 4527 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 4528 | |
| 4529 | // Test that illegal extensions in TLS 1.3 are rejected by the client if |
| 4530 | // in ServerHello. |
| 4531 | testCases = append(testCases, testCase{ |
| 4532 | name: "NPN-Forbidden-TLS13", |
| 4533 | config: Config{ |
| 4534 | MaxVersion: VersionTLS13, |
| 4535 | NextProtos: []string{"foo"}, |
| 4536 | Bugs: ProtocolBugs{ |
| 4537 | NegotiateNPNAtAllVersions: true, |
| 4538 | }, |
| 4539 | }, |
| 4540 | flags: []string{"-select-next-proto", "foo"}, |
| 4541 | shouldFail: true, |
| 4542 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4543 | }) |
| 4544 | testCases = append(testCases, testCase{ |
| 4545 | name: "EMS-Forbidden-TLS13", |
| 4546 | config: Config{ |
| 4547 | MaxVersion: VersionTLS13, |
| 4548 | Bugs: ProtocolBugs{ |
| 4549 | NegotiateEMSAtAllVersions: true, |
| 4550 | }, |
| 4551 | }, |
| 4552 | shouldFail: true, |
| 4553 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4554 | }) |
| 4555 | testCases = append(testCases, testCase{ |
| 4556 | name: "RenegotiationInfo-Forbidden-TLS13", |
| 4557 | config: Config{ |
| 4558 | MaxVersion: VersionTLS13, |
| 4559 | Bugs: ProtocolBugs{ |
| 4560 | NegotiateRenegotiationInfoAtAllVersions: true, |
| 4561 | }, |
| 4562 | }, |
| 4563 | shouldFail: true, |
| 4564 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4565 | }) |
| 4566 | testCases = append(testCases, testCase{ |
| 4567 | name: "ChannelID-Forbidden-TLS13", |
| 4568 | config: Config{ |
| 4569 | MaxVersion: VersionTLS13, |
| 4570 | RequestChannelID: true, |
| 4571 | Bugs: ProtocolBugs{ |
| 4572 | NegotiateChannelIDAtAllVersions: true, |
| 4573 | }, |
| 4574 | }, |
| 4575 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
| 4576 | shouldFail: true, |
| 4577 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4578 | }) |
| 4579 | testCases = append(testCases, testCase{ |
| 4580 | name: "Ticket-Forbidden-TLS13", |
| 4581 | config: Config{ |
| 4582 | MaxVersion: VersionTLS12, |
| 4583 | }, |
| 4584 | resumeConfig: &Config{ |
| 4585 | MaxVersion: VersionTLS13, |
| 4586 | Bugs: ProtocolBugs{ |
| 4587 | AdvertiseTicketExtension: true, |
| 4588 | }, |
| 4589 | }, |
| 4590 | resumeSession: true, |
| 4591 | shouldFail: true, |
| 4592 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 4593 | }) |
| 4594 | |
| 4595 | // Test that illegal extensions in TLS 1.3 are declined by the server if |
| 4596 | // offered in ClientHello. The runner's server will fail if this occurs, |
| 4597 | // so we exercise the offering path. (EMS and Renegotiation Info are |
| 4598 | // implicit in every test.) |
| 4599 | testCases = append(testCases, testCase{ |
| 4600 | testType: serverTest, |
| 4601 | name: "ChannelID-Declined-TLS13", |
| 4602 | config: Config{ |
| 4603 | MaxVersion: VersionTLS13, |
| 4604 | ChannelID: channelIDKey, |
| 4605 | }, |
| 4606 | flags: []string{"-enable-channel-id"}, |
| 4607 | }) |
| 4608 | testCases = append(testCases, testCase{ |
| 4609 | testType: serverTest, |
| 4610 | name: "NPN-Server", |
| 4611 | config: Config{ |
| 4612 | MaxVersion: VersionTLS13, |
| 4613 | NextProtos: []string{"bar"}, |
| 4614 | }, |
| 4615 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 4616 | }) |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 4617 | } |
| 4618 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4619 | func addResumptionVersionTests() { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4620 | for _, sessionVers := range tlsVersions { |
David Benjamin | 6e6abe1 | 2016-07-13 20:57:22 -0400 | [diff] [blame] | 4621 | // TODO(davidben,svaldez): Implement resumption in TLS 1.3. |
| 4622 | if sessionVers.version >= VersionTLS13 { |
| 4623 | continue |
| 4624 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4625 | for _, resumeVers := range tlsVersions { |
David Benjamin | 6e6abe1 | 2016-07-13 20:57:22 -0400 | [diff] [blame] | 4626 | if resumeVers.version >= VersionTLS13 { |
| 4627 | continue |
| 4628 | } |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4629 | cipher := TLS_RSA_WITH_AES_128_CBC_SHA |
| 4630 | if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 { |
| 4631 | // TLS 1.3 only shares ciphers with TLS 1.2, so |
| 4632 | // we skip certain combinations and use a |
| 4633 | // different cipher to test with. |
| 4634 | cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
| 4635 | if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 { |
| 4636 | continue |
| 4637 | } |
| 4638 | } |
| 4639 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4640 | protocols := []protocol{tls} |
| 4641 | if sessionVers.hasDTLS && resumeVers.hasDTLS { |
| 4642 | protocols = append(protocols, dtls) |
David Benjamin | bdf5e72 | 2014-11-11 00:52:15 -0500 | [diff] [blame] | 4643 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4644 | for _, protocol := range protocols { |
| 4645 | suffix := "-" + sessionVers.name + "-" + resumeVers.name |
| 4646 | if protocol == dtls { |
| 4647 | suffix += "-DTLS" |
| 4648 | } |
| 4649 | |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4650 | if sessionVers.version == resumeVers.version { |
| 4651 | testCases = append(testCases, testCase{ |
| 4652 | protocol: protocol, |
| 4653 | name: "Resume-Client" + suffix, |
| 4654 | resumeSession: true, |
| 4655 | config: Config{ |
| 4656 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4657 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4658 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4659 | expectedVersion: sessionVers.version, |
| 4660 | expectedResumeVersion: resumeVers.version, |
| 4661 | }) |
| 4662 | } else { |
| 4663 | testCases = append(testCases, testCase{ |
| 4664 | protocol: protocol, |
| 4665 | name: "Resume-Client-Mismatch" + suffix, |
| 4666 | resumeSession: true, |
| 4667 | config: Config{ |
| 4668 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4669 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4670 | }, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4671 | expectedVersion: sessionVers.version, |
| 4672 | resumeConfig: &Config{ |
| 4673 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4674 | CipherSuites: []uint16{cipher}, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4675 | Bugs: ProtocolBugs{ |
| 4676 | AllowSessionVersionMismatch: true, |
| 4677 | }, |
| 4678 | }, |
| 4679 | expectedResumeVersion: resumeVers.version, |
| 4680 | shouldFail: true, |
| 4681 | expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:", |
| 4682 | }) |
| 4683 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4684 | |
| 4685 | testCases = append(testCases, testCase{ |
| 4686 | protocol: protocol, |
| 4687 | name: "Resume-Client-NoResume" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4688 | resumeSession: true, |
| 4689 | config: Config{ |
| 4690 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4691 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4692 | }, |
| 4693 | expectedVersion: sessionVers.version, |
| 4694 | resumeConfig: &Config{ |
| 4695 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4696 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4697 | }, |
| 4698 | newSessionsOnResume: true, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 4699 | expectResumeRejected: true, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4700 | expectedResumeVersion: resumeVers.version, |
| 4701 | }) |
| 4702 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4703 | testCases = append(testCases, testCase{ |
| 4704 | protocol: protocol, |
| 4705 | testType: serverTest, |
| 4706 | name: "Resume-Server" + suffix, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4707 | resumeSession: true, |
| 4708 | config: Config{ |
| 4709 | MaxVersion: sessionVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4710 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4711 | }, |
Adam Langley | b0eef0a | 2015-06-02 10:47:39 -0700 | [diff] [blame] | 4712 | expectedVersion: sessionVers.version, |
| 4713 | expectResumeRejected: sessionVers.version != resumeVers.version, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4714 | resumeConfig: &Config{ |
| 4715 | MaxVersion: resumeVers.version, |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4716 | CipherSuites: []uint16{cipher}, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 4717 | }, |
| 4718 | expectedResumeVersion: resumeVers.version, |
| 4719 | }) |
| 4720 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4721 | } |
| 4722 | } |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4723 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4724 | // TODO(davidben): This test should have a TLS 1.3 variant later. |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4725 | testCases = append(testCases, testCase{ |
| 4726 | name: "Resume-Client-CipherMismatch", |
| 4727 | resumeSession: true, |
| 4728 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4729 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4730 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 4731 | }, |
| 4732 | resumeConfig: &Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4733 | MaxVersion: VersionTLS12, |
David Benjamin | ece3de9 | 2015-03-16 18:02:20 -0400 | [diff] [blame] | 4734 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 4735 | Bugs: ProtocolBugs{ |
| 4736 | SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 4737 | }, |
| 4738 | }, |
| 4739 | shouldFail: true, |
| 4740 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 4741 | }) |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 4742 | } |
| 4743 | |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 4744 | func addRenegotiationTests() { |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 4745 | // Servers cannot renegotiate. |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 4746 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4747 | testType: serverTest, |
| 4748 | name: "Renegotiate-Server-Forbidden", |
| 4749 | config: Config{ |
| 4750 | MaxVersion: VersionTLS12, |
| 4751 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4752 | renegotiate: 1, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 4753 | shouldFail: true, |
| 4754 | expectedError: ":NO_RENEGOTIATION:", |
| 4755 | expectedLocalError: "remote error: no renegotiation", |
| 4756 | }) |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 4757 | // The server shouldn't echo the renegotiation extension unless |
| 4758 | // requested by the client. |
| 4759 | testCases = append(testCases, testCase{ |
| 4760 | testType: serverTest, |
| 4761 | name: "Renegotiate-Server-NoExt", |
| 4762 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4763 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 4764 | Bugs: ProtocolBugs{ |
| 4765 | NoRenegotiationInfo: true, |
| 4766 | RequireRenegotiationInfo: true, |
| 4767 | }, |
| 4768 | }, |
| 4769 | shouldFail: true, |
| 4770 | expectedLocalError: "renegotiation extension missing", |
| 4771 | }) |
| 4772 | // The renegotiation SCSV should be sufficient for the server to echo |
| 4773 | // the extension. |
| 4774 | testCases = append(testCases, testCase{ |
| 4775 | testType: serverTest, |
| 4776 | name: "Renegotiate-Server-NoExt-SCSV", |
| 4777 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4778 | MaxVersion: VersionTLS12, |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 4779 | Bugs: ProtocolBugs{ |
| 4780 | NoRenegotiationInfo: true, |
| 4781 | SendRenegotiationSCSV: true, |
| 4782 | RequireRenegotiationInfo: true, |
| 4783 | }, |
| 4784 | }, |
| 4785 | }) |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4786 | testCases = append(testCases, testCase{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 4787 | name: "Renegotiate-Client", |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4788 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4789 | MaxVersion: VersionTLS12, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4790 | Bugs: ProtocolBugs{ |
David Benjamin | 4b27d9f | 2015-05-12 22:42:52 -0400 | [diff] [blame] | 4791 | FailIfResumeOnRenego: true, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4792 | }, |
| 4793 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4794 | renegotiate: 1, |
| 4795 | flags: []string{ |
| 4796 | "-renegotiate-freely", |
| 4797 | "-expect-total-renegotiations", "1", |
| 4798 | }, |
David Benjamin | cdea40c | 2015-03-19 14:09:43 -0400 | [diff] [blame] | 4799 | }) |
| 4800 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4801 | name: "Renegotiate-Client-EmptyExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4802 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4803 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4804 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4805 | Bugs: ProtocolBugs{ |
| 4806 | EmptyRenegotiationInfo: true, |
| 4807 | }, |
| 4808 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4809 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4810 | shouldFail: true, |
| 4811 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4812 | }) |
| 4813 | testCases = append(testCases, testCase{ |
| 4814 | name: "Renegotiate-Client-BadExt", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4815 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4816 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4817 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4818 | Bugs: ProtocolBugs{ |
| 4819 | BadRenegotiationInfo: true, |
| 4820 | }, |
| 4821 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4822 | flags: []string{"-renegotiate-freely"}, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4823 | shouldFail: true, |
| 4824 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4825 | }) |
| 4826 | testCases = append(testCases, testCase{ |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 4827 | name: "Renegotiate-Client-Downgrade", |
| 4828 | renegotiate: 1, |
| 4829 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4830 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 4831 | Bugs: ProtocolBugs{ |
| 4832 | NoRenegotiationInfoAfterInitial: true, |
| 4833 | }, |
| 4834 | }, |
| 4835 | flags: []string{"-renegotiate-freely"}, |
| 4836 | shouldFail: true, |
| 4837 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4838 | }) |
| 4839 | testCases = append(testCases, testCase{ |
| 4840 | name: "Renegotiate-Client-Upgrade", |
| 4841 | renegotiate: 1, |
| 4842 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4843 | MaxVersion: VersionTLS12, |
David Benjamin | 3e052de | 2015-11-25 20:10:31 -0500 | [diff] [blame] | 4844 | Bugs: ProtocolBugs{ |
| 4845 | NoRenegotiationInfoInInitial: true, |
| 4846 | }, |
| 4847 | }, |
| 4848 | flags: []string{"-renegotiate-freely"}, |
| 4849 | shouldFail: true, |
| 4850 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 4851 | }) |
| 4852 | testCases = append(testCases, testCase{ |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4853 | name: "Renegotiate-Client-NoExt-Allowed", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4854 | renegotiate: 1, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4855 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4856 | MaxVersion: VersionTLS12, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4857 | Bugs: ProtocolBugs{ |
| 4858 | NoRenegotiationInfo: true, |
| 4859 | }, |
| 4860 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4861 | flags: []string{ |
| 4862 | "-renegotiate-freely", |
| 4863 | "-expect-total-renegotiations", "1", |
| 4864 | }, |
David Benjamin | cff0b90 | 2015-05-15 23:09:47 -0400 | [diff] [blame] | 4865 | }) |
| 4866 | testCases = append(testCases, testCase{ |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4867 | name: "Renegotiate-Client-SwitchCiphers", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4868 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4869 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4870 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4871 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 4872 | }, |
| 4873 | renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4874 | flags: []string{ |
| 4875 | "-renegotiate-freely", |
| 4876 | "-expect-total-renegotiations", "1", |
| 4877 | }, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4878 | }) |
| 4879 | testCases = append(testCases, testCase{ |
| 4880 | name: "Renegotiate-Client-SwitchCiphers2", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4881 | renegotiate: 1, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4882 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4883 | MaxVersion: VersionTLS12, |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 4884 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4885 | }, |
| 4886 | renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4887 | flags: []string{ |
| 4888 | "-renegotiate-freely", |
| 4889 | "-expect-total-renegotiations", "1", |
| 4890 | }, |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 4891 | }) |
| 4892 | testCases = append(testCases, testCase{ |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 4893 | name: "Renegotiate-SameClientVersion", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4894 | renegotiate: 1, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 4895 | config: Config{ |
| 4896 | MaxVersion: VersionTLS10, |
| 4897 | Bugs: ProtocolBugs{ |
| 4898 | RequireSameRenegoClientVersion: true, |
| 4899 | }, |
| 4900 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4901 | flags: []string{ |
| 4902 | "-renegotiate-freely", |
| 4903 | "-expect-total-renegotiations", "1", |
| 4904 | }, |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 4905 | }) |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 4906 | testCases = append(testCases, testCase{ |
| 4907 | name: "Renegotiate-FalseStart", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4908 | renegotiate: 1, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 4909 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 4910 | MaxVersion: VersionTLS12, |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 4911 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4912 | NextProtos: []string{"foo"}, |
| 4913 | }, |
| 4914 | flags: []string{ |
| 4915 | "-false-start", |
| 4916 | "-select-next-proto", "foo", |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4917 | "-renegotiate-freely", |
David Benjamin | 324dce4 | 2015-10-12 19:49:00 -0400 | [diff] [blame] | 4918 | "-expect-total-renegotiations", "1", |
Adam Langley | b558c4c | 2015-07-08 12:16:38 -0700 | [diff] [blame] | 4919 | }, |
| 4920 | shimWritesFirst: true, |
| 4921 | }) |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4922 | |
| 4923 | // Client-side renegotiation controls. |
| 4924 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4925 | name: "Renegotiate-Client-Forbidden-1", |
| 4926 | config: Config{ |
| 4927 | MaxVersion: VersionTLS12, |
| 4928 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4929 | renegotiate: 1, |
| 4930 | shouldFail: true, |
| 4931 | expectedError: ":NO_RENEGOTIATION:", |
| 4932 | expectedLocalError: "remote error: no renegotiation", |
| 4933 | }) |
| 4934 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4935 | name: "Renegotiate-Client-Once-1", |
| 4936 | config: Config{ |
| 4937 | MaxVersion: VersionTLS12, |
| 4938 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4939 | renegotiate: 1, |
| 4940 | flags: []string{ |
| 4941 | "-renegotiate-once", |
| 4942 | "-expect-total-renegotiations", "1", |
| 4943 | }, |
| 4944 | }) |
| 4945 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4946 | name: "Renegotiate-Client-Freely-1", |
| 4947 | config: Config{ |
| 4948 | MaxVersion: VersionTLS12, |
| 4949 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4950 | renegotiate: 1, |
| 4951 | flags: []string{ |
| 4952 | "-renegotiate-freely", |
| 4953 | "-expect-total-renegotiations", "1", |
| 4954 | }, |
| 4955 | }) |
| 4956 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4957 | name: "Renegotiate-Client-Once-2", |
| 4958 | config: Config{ |
| 4959 | MaxVersion: VersionTLS12, |
| 4960 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4961 | renegotiate: 2, |
| 4962 | flags: []string{"-renegotiate-once"}, |
| 4963 | shouldFail: true, |
| 4964 | expectedError: ":NO_RENEGOTIATION:", |
| 4965 | expectedLocalError: "remote error: no renegotiation", |
| 4966 | }) |
| 4967 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4968 | name: "Renegotiate-Client-Freely-2", |
| 4969 | config: Config{ |
| 4970 | MaxVersion: VersionTLS12, |
| 4971 | }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 4972 | renegotiate: 2, |
| 4973 | flags: []string{ |
| 4974 | "-renegotiate-freely", |
| 4975 | "-expect-total-renegotiations", "2", |
| 4976 | }, |
| 4977 | }) |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 4978 | testCases = append(testCases, testCase{ |
| 4979 | name: "Renegotiate-Client-NoIgnore", |
| 4980 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4981 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 4982 | Bugs: ProtocolBugs{ |
| 4983 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 4984 | }, |
| 4985 | }, |
| 4986 | shouldFail: true, |
| 4987 | expectedError: ":NO_RENEGOTIATION:", |
| 4988 | }) |
| 4989 | testCases = append(testCases, testCase{ |
| 4990 | name: "Renegotiate-Client-Ignore", |
| 4991 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 4992 | MaxVersion: VersionTLS12, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 4993 | Bugs: ProtocolBugs{ |
| 4994 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 4995 | }, |
| 4996 | }, |
| 4997 | flags: []string{ |
| 4998 | "-renegotiate-ignore", |
| 4999 | "-expect-total-renegotiations", "0", |
| 5000 | }, |
| 5001 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5002 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5003 | // Stray HelloRequests during the handshake are ignored in TLS 1.2. |
David Benjamin | 71dd666 | 2016-07-08 14:10:48 -0700 | [diff] [blame] | 5004 | testCases = append(testCases, testCase{ |
| 5005 | name: "StrayHelloRequest", |
| 5006 | config: Config{ |
| 5007 | MaxVersion: VersionTLS12, |
| 5008 | Bugs: ProtocolBugs{ |
| 5009 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5010 | }, |
| 5011 | }, |
| 5012 | }) |
| 5013 | testCases = append(testCases, testCase{ |
| 5014 | name: "StrayHelloRequest-Packed", |
| 5015 | config: Config{ |
| 5016 | MaxVersion: VersionTLS12, |
| 5017 | Bugs: ProtocolBugs{ |
| 5018 | PackHandshakeFlight: true, |
| 5019 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5020 | }, |
| 5021 | }, |
| 5022 | }) |
| 5023 | |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5024 | // Renegotiation is forbidden in TLS 1.3. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5025 | // |
| 5026 | // TODO(davidben): This test current asserts that we ignore |
| 5027 | // HelloRequests, but we actually should hard reject them. Fix this |
| 5028 | // test once we actually parse post-handshake messages. |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5029 | testCases = append(testCases, testCase{ |
| 5030 | name: "Renegotiate-Client-TLS13", |
| 5031 | config: Config{ |
| 5032 | MaxVersion: VersionTLS13, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5033 | Bugs: ProtocolBugs{ |
| 5034 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5035 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5036 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5037 | flags: []string{ |
| 5038 | "-renegotiate-freely", |
| 5039 | }, |
David Benjamin | 397c8e6 | 2016-07-08 14:14:36 -0700 | [diff] [blame] | 5040 | }) |
| 5041 | |
| 5042 | // Stray HelloRequests during the handshake are forbidden in TLS 1.3. |
| 5043 | testCases = append(testCases, testCase{ |
| 5044 | name: "StrayHelloRequest-TLS13", |
| 5045 | config: Config{ |
| 5046 | MaxVersion: VersionTLS13, |
| 5047 | Bugs: ProtocolBugs{ |
| 5048 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 5049 | }, |
| 5050 | }, |
| 5051 | shouldFail: true, |
| 5052 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 5053 | }) |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 5054 | } |
| 5055 | |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5056 | func addDTLSReplayTests() { |
| 5057 | // Test that sequence number replays are detected. |
| 5058 | testCases = append(testCases, testCase{ |
| 5059 | protocol: dtls, |
| 5060 | name: "DTLS-Replay", |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5061 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5062 | replayWrites: true, |
| 5063 | }) |
| 5064 | |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5065 | // Test the incoming sequence number skipping by values larger |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5066 | // than the retransmit window. |
| 5067 | testCases = append(testCases, testCase{ |
| 5068 | protocol: dtls, |
| 5069 | name: "DTLS-Replay-LargeGaps", |
| 5070 | config: Config{ |
| 5071 | Bugs: ProtocolBugs{ |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5072 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5073 | return in * 127 |
| 5074 | }, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5075 | }, |
| 5076 | }, |
David Benjamin | 8e6db49 | 2015-07-25 18:29:23 -0400 | [diff] [blame] | 5077 | messageCount: 200, |
| 5078 | replayWrites: true, |
| 5079 | }) |
| 5080 | |
| 5081 | // Test the incoming sequence number changing non-monotonically. |
| 5082 | testCases = append(testCases, testCase{ |
| 5083 | protocol: dtls, |
| 5084 | name: "DTLS-Replay-NonMonotonic", |
| 5085 | config: Config{ |
| 5086 | Bugs: ProtocolBugs{ |
| 5087 | SequenceNumberMapping: func(in uint64) uint64 { |
| 5088 | return in ^ 31 |
| 5089 | }, |
| 5090 | }, |
| 5091 | }, |
| 5092 | messageCount: 200, |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 5093 | replayWrites: true, |
| 5094 | }) |
| 5095 | } |
| 5096 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5097 | var testSignatureAlgorithms = []struct { |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5098 | name string |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5099 | id signatureAlgorithm |
| 5100 | cert testCert |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5101 | }{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5102 | {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA}, |
| 5103 | {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA}, |
| 5104 | {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA}, |
| 5105 | {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5106 | {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5107 | {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256}, |
| 5108 | {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384}, |
| 5109 | {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521}, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5110 | {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA}, |
| 5111 | {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA}, |
| 5112 | {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5113 | // Tests for key types prior to TLS 1.2. |
| 5114 | {"RSA", 0, testCertRSA}, |
| 5115 | {"ECDSA", 0, testCertECDSAP256}, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5116 | } |
| 5117 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5118 | const fakeSigAlg1 signatureAlgorithm = 0x2a01 |
| 5119 | const fakeSigAlg2 signatureAlgorithm = 0xff01 |
| 5120 | |
| 5121 | func addSignatureAlgorithmTests() { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5122 | // Not all ciphers involve a signature. Advertise a list which gives all |
| 5123 | // versions a signing cipher. |
| 5124 | signingCiphers := []uint16{ |
| 5125 | TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 5126 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 5127 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 5128 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 5129 | TLS_DHE_RSA_WITH_AES_128_CBC_SHA, |
| 5130 | } |
| 5131 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5132 | var allAlgorithms []signatureAlgorithm |
| 5133 | for _, alg := range testSignatureAlgorithms { |
| 5134 | if alg.id != 0 { |
| 5135 | allAlgorithms = append(allAlgorithms, alg.id) |
| 5136 | } |
| 5137 | } |
| 5138 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5139 | // Make sure each signature algorithm works. Include some fake values in |
| 5140 | // the list and ensure they're ignored. |
| 5141 | for _, alg := range testSignatureAlgorithms { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5142 | for _, ver := range tlsVersions { |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5143 | if (ver.version < VersionTLS12) != (alg.id == 0) { |
| 5144 | continue |
| 5145 | } |
| 5146 | |
| 5147 | // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing |
| 5148 | // or remove it in C. |
| 5149 | if ver.version == VersionSSL30 && alg.cert != testCertRSA { |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5150 | continue |
| 5151 | } |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5152 | |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5153 | var shouldFail bool |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5154 | // ecdsa_sha1 does not exist in TLS 1.3. |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5155 | if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 { |
| 5156 | shouldFail = true |
| 5157 | } |
| 5158 | // RSA-PSS does not exist in TLS 1.2. |
| 5159 | if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") { |
| 5160 | shouldFail = true |
| 5161 | } |
| 5162 | |
| 5163 | var signError, verifyError string |
| 5164 | if shouldFail { |
| 5165 | signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:" |
| 5166 | verifyError = ":WRONG_SIGNATURE_TYPE:" |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5167 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5168 | |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5169 | suffix := "-" + alg.name + "-" + ver.name |
David Benjamin | 6e80765 | 2015-11-02 12:02:20 -0500 | [diff] [blame] | 5170 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5171 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5172 | name: "ClientAuth-Sign" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5173 | config: Config{ |
| 5174 | MaxVersion: ver.version, |
| 5175 | ClientAuth: RequireAnyClientCert, |
| 5176 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5177 | fakeSigAlg1, |
| 5178 | alg.id, |
| 5179 | fakeSigAlg2, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5180 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5181 | }, |
| 5182 | flags: []string{ |
| 5183 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5184 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5185 | "-enable-all-curves", |
| 5186 | }, |
| 5187 | shouldFail: shouldFail, |
| 5188 | expectedError: signError, |
| 5189 | expectedPeerSignatureAlgorithm: alg.id, |
| 5190 | }) |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5191 | |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5192 | testCases = append(testCases, testCase{ |
| 5193 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5194 | name: "ClientAuth-Verify" + suffix, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5195 | config: Config{ |
| 5196 | MaxVersion: ver.version, |
| 5197 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5198 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5199 | alg.id, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5200 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5201 | Bugs: ProtocolBugs{ |
| 5202 | SkipECDSACurveCheck: shouldFail, |
| 5203 | IgnoreSignatureVersionChecks: shouldFail, |
| 5204 | // The client won't advertise 1.3-only algorithms after |
| 5205 | // version negotiation. |
| 5206 | IgnorePeerSignatureAlgorithmPreferences: shouldFail, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5207 | }, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5208 | }, |
| 5209 | flags: []string{ |
| 5210 | "-require-any-client-certificate", |
| 5211 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5212 | "-enable-all-curves", |
| 5213 | }, |
| 5214 | shouldFail: shouldFail, |
| 5215 | expectedError: verifyError, |
| 5216 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5217 | |
| 5218 | testCases = append(testCases, testCase{ |
| 5219 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5220 | name: "ServerAuth-Sign" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5221 | config: Config{ |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5222 | MaxVersion: ver.version, |
| 5223 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5224 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5225 | fakeSigAlg1, |
| 5226 | alg.id, |
| 5227 | fakeSigAlg2, |
| 5228 | }, |
| 5229 | }, |
| 5230 | flags: []string{ |
| 5231 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5232 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5233 | "-enable-all-curves", |
| 5234 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5235 | shouldFail: shouldFail, |
| 5236 | expectedError: signError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5237 | expectedPeerSignatureAlgorithm: alg.id, |
| 5238 | }) |
| 5239 | |
| 5240 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5241 | name: "ServerAuth-Verify" + suffix, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5242 | config: Config{ |
| 5243 | MaxVersion: ver.version, |
| 5244 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5245 | CipherSuites: signingCiphers, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5246 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5247 | alg.id, |
| 5248 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5249 | Bugs: ProtocolBugs{ |
| 5250 | SkipECDSACurveCheck: shouldFail, |
| 5251 | IgnoreSignatureVersionChecks: shouldFail, |
| 5252 | }, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5253 | }, |
| 5254 | flags: []string{ |
| 5255 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 5256 | "-enable-all-curves", |
| 5257 | }, |
Steven Valdez | eff1e8d | 2016-07-06 14:24:47 -0400 | [diff] [blame] | 5258 | shouldFail: shouldFail, |
| 5259 | expectedError: verifyError, |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5260 | }) |
David Benjamin | 5208fd4 | 2016-07-13 21:43:25 -0400 | [diff] [blame] | 5261 | |
| 5262 | if !shouldFail { |
| 5263 | testCases = append(testCases, testCase{ |
| 5264 | testType: serverTest, |
| 5265 | name: "ClientAuth-InvalidSignature" + suffix, |
| 5266 | config: Config{ |
| 5267 | MaxVersion: ver.version, |
| 5268 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5269 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5270 | alg.id, |
| 5271 | }, |
| 5272 | Bugs: ProtocolBugs{ |
| 5273 | InvalidSignature: true, |
| 5274 | }, |
| 5275 | }, |
| 5276 | flags: []string{ |
| 5277 | "-require-any-client-certificate", |
| 5278 | "-enable-all-curves", |
| 5279 | }, |
| 5280 | shouldFail: true, |
| 5281 | expectedError: ":BAD_SIGNATURE:", |
| 5282 | }) |
| 5283 | |
| 5284 | testCases = append(testCases, testCase{ |
| 5285 | name: "ServerAuth-InvalidSignature" + suffix, |
| 5286 | config: Config{ |
| 5287 | MaxVersion: ver.version, |
| 5288 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 5289 | CipherSuites: signingCiphers, |
| 5290 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5291 | alg.id, |
| 5292 | }, |
| 5293 | Bugs: ProtocolBugs{ |
| 5294 | InvalidSignature: true, |
| 5295 | }, |
| 5296 | }, |
| 5297 | flags: []string{"-enable-all-curves"}, |
| 5298 | shouldFail: true, |
| 5299 | expectedError: ":BAD_SIGNATURE:", |
| 5300 | }) |
| 5301 | } |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5302 | |
| 5303 | if ver.version >= VersionTLS12 && !shouldFail { |
| 5304 | testCases = append(testCases, testCase{ |
| 5305 | name: "ClientAuth-Sign-Negotiate" + suffix, |
| 5306 | config: Config{ |
| 5307 | MaxVersion: ver.version, |
| 5308 | ClientAuth: RequireAnyClientCert, |
| 5309 | VerifySignatureAlgorithms: allAlgorithms, |
| 5310 | }, |
| 5311 | flags: []string{ |
| 5312 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5313 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5314 | "-enable-all-curves", |
| 5315 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 5316 | }, |
| 5317 | expectedPeerSignatureAlgorithm: alg.id, |
| 5318 | }) |
| 5319 | |
| 5320 | testCases = append(testCases, testCase{ |
| 5321 | testType: serverTest, |
| 5322 | name: "ServerAuth-Sign-Negotiate" + suffix, |
| 5323 | config: Config{ |
| 5324 | MaxVersion: ver.version, |
| 5325 | CipherSuites: signingCiphers, |
| 5326 | VerifySignatureAlgorithms: allAlgorithms, |
| 5327 | }, |
| 5328 | flags: []string{ |
| 5329 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 5330 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 5331 | "-enable-all-curves", |
| 5332 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 5333 | }, |
| 5334 | expectedPeerSignatureAlgorithm: alg.id, |
| 5335 | }) |
| 5336 | } |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5337 | } |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5338 | } |
| 5339 | |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5340 | // Test that algorithm selection takes the key type into account. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5341 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5342 | name: "ClientAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5343 | config: Config{ |
| 5344 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5345 | MaxVersion: VersionTLS12, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5346 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5347 | signatureECDSAWithP521AndSHA512, |
| 5348 | signatureRSAPKCS1WithSHA384, |
| 5349 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5350 | }, |
| 5351 | }, |
| 5352 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5353 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5354 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5355 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5356 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5357 | }) |
| 5358 | |
| 5359 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5360 | name: "ClientAuth-SignatureType-TLS13", |
| 5361 | config: Config{ |
| 5362 | ClientAuth: RequireAnyClientCert, |
| 5363 | MaxVersion: VersionTLS13, |
| 5364 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5365 | signatureECDSAWithP521AndSHA512, |
| 5366 | signatureRSAPKCS1WithSHA384, |
| 5367 | signatureRSAPSSWithSHA384, |
| 5368 | signatureECDSAWithSHA1, |
| 5369 | }, |
| 5370 | }, |
| 5371 | flags: []string{ |
| 5372 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5373 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5374 | }, |
| 5375 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 5376 | }) |
| 5377 | |
| 5378 | testCases = append(testCases, testCase{ |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5379 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5380 | name: "ServerAuth-SignatureType", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5381 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5382 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5383 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5384 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5385 | signatureECDSAWithP521AndSHA512, |
| 5386 | signatureRSAPKCS1WithSHA384, |
| 5387 | signatureECDSAWithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5388 | }, |
| 5389 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5390 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5391 | }) |
| 5392 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5393 | testCases = append(testCases, testCase{ |
| 5394 | testType: serverTest, |
| 5395 | name: "ServerAuth-SignatureType-TLS13", |
| 5396 | config: Config{ |
| 5397 | MaxVersion: VersionTLS13, |
| 5398 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5399 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5400 | signatureECDSAWithP521AndSHA512, |
| 5401 | signatureRSAPKCS1WithSHA384, |
| 5402 | signatureRSAPSSWithSHA384, |
| 5403 | signatureECDSAWithSHA1, |
| 5404 | }, |
| 5405 | }, |
| 5406 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 5407 | }) |
| 5408 | |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5409 | // Test that signature verification takes the key type into account. |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5410 | testCases = append(testCases, testCase{ |
| 5411 | testType: serverTest, |
| 5412 | name: "Verify-ClientAuth-SignatureType", |
| 5413 | config: Config{ |
| 5414 | MaxVersion: VersionTLS12, |
| 5415 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5416 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5417 | signatureRSAPKCS1WithSHA256, |
| 5418 | }, |
| 5419 | Bugs: ProtocolBugs{ |
| 5420 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5421 | }, |
| 5422 | }, |
| 5423 | flags: []string{ |
| 5424 | "-require-any-client-certificate", |
| 5425 | }, |
| 5426 | shouldFail: true, |
| 5427 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5428 | }) |
| 5429 | |
| 5430 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5431 | testType: serverTest, |
| 5432 | name: "Verify-ClientAuth-SignatureType-TLS13", |
| 5433 | config: Config{ |
| 5434 | MaxVersion: VersionTLS13, |
| 5435 | Certificates: []Certificate{rsaCertificate}, |
| 5436 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5437 | signatureRSAPSSWithSHA256, |
| 5438 | }, |
| 5439 | Bugs: ProtocolBugs{ |
| 5440 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5441 | }, |
| 5442 | }, |
| 5443 | flags: []string{ |
| 5444 | "-require-any-client-certificate", |
| 5445 | }, |
| 5446 | shouldFail: true, |
| 5447 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5448 | }) |
| 5449 | |
| 5450 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5451 | name: "Verify-ServerAuth-SignatureType", |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5452 | config: Config{ |
| 5453 | MaxVersion: VersionTLS12, |
| 5454 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5455 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | a95e9f3 | 2016-07-08 16:28:04 -0700 | [diff] [blame] | 5456 | signatureRSAPKCS1WithSHA256, |
| 5457 | }, |
| 5458 | Bugs: ProtocolBugs{ |
| 5459 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5460 | }, |
| 5461 | }, |
| 5462 | shouldFail: true, |
| 5463 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5464 | }) |
| 5465 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5466 | testCases = append(testCases, testCase{ |
| 5467 | name: "Verify-ServerAuth-SignatureType-TLS13", |
| 5468 | config: Config{ |
| 5469 | MaxVersion: VersionTLS13, |
| 5470 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5471 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5472 | signatureRSAPSSWithSHA256, |
| 5473 | }, |
| 5474 | Bugs: ProtocolBugs{ |
| 5475 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5476 | }, |
| 5477 | }, |
| 5478 | shouldFail: true, |
| 5479 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5480 | }) |
| 5481 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5482 | // Test that, if the list is missing, the peer falls back to SHA-1 in |
| 5483 | // TLS 1.2, but not TLS 1.3. |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5484 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5485 | name: "ClientAuth-SHA1-Fallback", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5486 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5487 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5488 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5489 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5490 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5491 | }, |
| 5492 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5493 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5494 | }, |
| 5495 | }, |
| 5496 | flags: []string{ |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 5497 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5498 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5499 | }, |
| 5500 | }) |
| 5501 | |
| 5502 | testCases = append(testCases, testCase{ |
| 5503 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5504 | name: "ServerAuth-SHA1-Fallback", |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5505 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5506 | MaxVersion: VersionTLS12, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5507 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5508 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5509 | signatureRSAPKCS1WithSHA1, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5510 | }, |
| 5511 | Bugs: ProtocolBugs{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5512 | NoSignatureAlgorithms: true, |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5513 | }, |
| 5514 | }, |
| 5515 | }) |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5516 | |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5517 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5518 | name: "ClientAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5519 | config: Config{ |
| 5520 | MaxVersion: VersionTLS13, |
| 5521 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5522 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5523 | signatureRSAPKCS1WithSHA1, |
| 5524 | }, |
| 5525 | Bugs: ProtocolBugs{ |
| 5526 | NoSignatureAlgorithms: true, |
| 5527 | }, |
| 5528 | }, |
| 5529 | flags: []string{ |
| 5530 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5531 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5532 | }, |
| 5533 | shouldFail: true, |
| 5534 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5535 | }) |
| 5536 | |
| 5537 | testCases = append(testCases, testCase{ |
| 5538 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5539 | name: "ServerAuth-NoFallback-TLS13", |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5540 | config: Config{ |
| 5541 | MaxVersion: VersionTLS13, |
| 5542 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5543 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 51dd7d6 | 2016-07-08 16:07:01 -0700 | [diff] [blame] | 5544 | signatureRSAPKCS1WithSHA1, |
| 5545 | }, |
| 5546 | Bugs: ProtocolBugs{ |
| 5547 | NoSignatureAlgorithms: true, |
| 5548 | }, |
| 5549 | }, |
| 5550 | shouldFail: true, |
| 5551 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5552 | }) |
| 5553 | |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 5554 | // Test that hash preferences are enforced. BoringSSL does not implement |
| 5555 | // MD5 signatures. |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5556 | testCases = append(testCases, testCase{ |
| 5557 | testType: serverTest, |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5558 | name: "ClientAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5559 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5560 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5561 | Certificates: []Certificate{rsaCertificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5562 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5563 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5564 | }, |
| 5565 | Bugs: ProtocolBugs{ |
| 5566 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5567 | }, |
| 5568 | }, |
| 5569 | flags: []string{"-require-any-client-certificate"}, |
| 5570 | shouldFail: true, |
| 5571 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5572 | }) |
| 5573 | |
| 5574 | testCases = append(testCases, testCase{ |
David Benjamin | bbfff7c | 2016-07-13 21:08:33 -0400 | [diff] [blame] | 5575 | name: "ServerAuth-Enforced", |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5576 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5577 | MaxVersion: VersionTLS12, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5578 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5579 | SignSignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5580 | signatureRSAPKCS1WithMD5, |
David Benjamin | 72dc783 | 2015-03-16 17:49:43 -0400 | [diff] [blame] | 5581 | }, |
| 5582 | Bugs: ProtocolBugs{ |
| 5583 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5584 | }, |
| 5585 | }, |
| 5586 | shouldFail: true, |
| 5587 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5588 | }) |
David Benjamin | b62d287 | 2016-07-18 14:55:02 +0200 | [diff] [blame] | 5589 | testCases = append(testCases, testCase{ |
| 5590 | testType: serverTest, |
| 5591 | name: "ClientAuth-Enforced-TLS13", |
| 5592 | config: Config{ |
| 5593 | MaxVersion: VersionTLS13, |
| 5594 | Certificates: []Certificate{rsaCertificate}, |
| 5595 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5596 | signatureRSAPKCS1WithMD5, |
| 5597 | }, |
| 5598 | Bugs: ProtocolBugs{ |
| 5599 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5600 | IgnoreSignatureVersionChecks: true, |
| 5601 | }, |
| 5602 | }, |
| 5603 | flags: []string{"-require-any-client-certificate"}, |
| 5604 | shouldFail: true, |
| 5605 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5606 | }) |
| 5607 | |
| 5608 | testCases = append(testCases, testCase{ |
| 5609 | name: "ServerAuth-Enforced-TLS13", |
| 5610 | config: Config{ |
| 5611 | MaxVersion: VersionTLS13, |
| 5612 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5613 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 5614 | signatureRSAPKCS1WithMD5, |
| 5615 | }, |
| 5616 | Bugs: ProtocolBugs{ |
| 5617 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 5618 | IgnoreSignatureVersionChecks: true, |
| 5619 | }, |
| 5620 | }, |
| 5621 | shouldFail: true, |
| 5622 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5623 | }) |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5624 | |
| 5625 | // Test that the agreed upon digest respects the client preferences and |
| 5626 | // the server digests. |
| 5627 | testCases = append(testCases, testCase{ |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5628 | name: "NoCommonAlgorithms-Digests", |
| 5629 | config: Config{ |
| 5630 | MaxVersion: VersionTLS12, |
| 5631 | ClientAuth: RequireAnyClientCert, |
| 5632 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5633 | signatureRSAPKCS1WithSHA512, |
| 5634 | signatureRSAPKCS1WithSHA1, |
| 5635 | }, |
| 5636 | }, |
| 5637 | flags: []string{ |
| 5638 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5639 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5640 | "-digest-prefs", "SHA256", |
| 5641 | }, |
| 5642 | shouldFail: true, |
| 5643 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5644 | }) |
| 5645 | testCases = append(testCases, testCase{ |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 5646 | name: "NoCommonAlgorithms", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5647 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5648 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5649 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5650 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5651 | signatureRSAPKCS1WithSHA512, |
| 5652 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5653 | }, |
| 5654 | }, |
| 5655 | flags: []string{ |
| 5656 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5657 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5658 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5659 | }, |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5660 | shouldFail: true, |
| 5661 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5662 | }) |
| 5663 | testCases = append(testCases, testCase{ |
| 5664 | name: "NoCommonAlgorithms-TLS13", |
| 5665 | config: Config{ |
| 5666 | MaxVersion: VersionTLS13, |
| 5667 | ClientAuth: RequireAnyClientCert, |
| 5668 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5669 | signatureRSAPSSWithSHA512, |
| 5670 | signatureRSAPSSWithSHA384, |
| 5671 | }, |
| 5672 | }, |
| 5673 | flags: []string{ |
| 5674 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5675 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5676 | "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)), |
| 5677 | }, |
David Benjamin | ea9a0d5 | 2016-07-08 15:52:59 -0700 | [diff] [blame] | 5678 | shouldFail: true, |
| 5679 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5680 | }) |
| 5681 | testCases = append(testCases, testCase{ |
| 5682 | name: "Agree-Digest-SHA256", |
| 5683 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5684 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5685 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5686 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5687 | signatureRSAPKCS1WithSHA1, |
| 5688 | signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5689 | }, |
| 5690 | }, |
| 5691 | flags: []string{ |
| 5692 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5693 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5694 | "-digest-prefs", "SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5695 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5696 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5697 | }) |
| 5698 | testCases = append(testCases, testCase{ |
| 5699 | name: "Agree-Digest-SHA1", |
| 5700 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5701 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5702 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5703 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5704 | signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5705 | }, |
| 5706 | }, |
| 5707 | flags: []string{ |
| 5708 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5709 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5710 | "-digest-prefs", "SHA512,SHA256,SHA1", |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5711 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5712 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5713 | }) |
| 5714 | testCases = append(testCases, testCase{ |
| 5715 | name: "Agree-Digest-Default", |
| 5716 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5717 | MaxVersion: VersionTLS12, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5718 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5719 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5720 | signatureRSAPKCS1WithSHA256, |
| 5721 | signatureECDSAWithP256AndSHA256, |
| 5722 | signatureRSAPKCS1WithSHA1, |
| 5723 | signatureECDSAWithSHA1, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5724 | }, |
| 5725 | }, |
| 5726 | flags: []string{ |
| 5727 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5728 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5729 | }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 5730 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 5731 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5732 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 5733 | // Test that the signing preference list may include extra algorithms |
| 5734 | // without negotiation problems. |
| 5735 | testCases = append(testCases, testCase{ |
| 5736 | testType: serverTest, |
| 5737 | name: "FilterExtraAlgorithms", |
| 5738 | config: Config{ |
| 5739 | MaxVersion: VersionTLS12, |
| 5740 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5741 | signatureRSAPKCS1WithSHA256, |
| 5742 | }, |
| 5743 | }, |
| 5744 | flags: []string{ |
| 5745 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 5746 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 5747 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)), |
| 5748 | "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)), |
| 5749 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
| 5750 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)), |
| 5751 | }, |
| 5752 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
| 5753 | }) |
| 5754 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5755 | // In TLS 1.2 and below, ECDSA uses the curve list rather than the |
| 5756 | // signature algorithms. |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5757 | testCases = append(testCases, testCase{ |
| 5758 | name: "CheckLeafCurve", |
| 5759 | config: Config{ |
| 5760 | MaxVersion: VersionTLS12, |
| 5761 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 5762 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5763 | }, |
| 5764 | flags: []string{"-p384-only"}, |
| 5765 | shouldFail: true, |
| 5766 | expectedError: ":BAD_ECC_CERT:", |
| 5767 | }) |
David Benjamin | 75ea5bb | 2016-07-08 17:43:29 -0700 | [diff] [blame] | 5768 | |
| 5769 | // In TLS 1.3, ECDSA does not use the ECDHE curve list. |
| 5770 | testCases = append(testCases, testCase{ |
| 5771 | name: "CheckLeafCurve-TLS13", |
| 5772 | config: Config{ |
| 5773 | MaxVersion: VersionTLS13, |
| 5774 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 5775 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 5776 | }, |
| 5777 | flags: []string{"-p384-only"}, |
| 5778 | }) |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5779 | |
| 5780 | // In TLS 1.2, the ECDSA curve is not in the signature algorithm. |
| 5781 | testCases = append(testCases, testCase{ |
| 5782 | name: "ECDSACurveMismatch-Verify-TLS12", |
| 5783 | config: Config{ |
| 5784 | MaxVersion: VersionTLS12, |
| 5785 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 5786 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5787 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5788 | signatureECDSAWithP384AndSHA384, |
| 5789 | }, |
| 5790 | }, |
| 5791 | }) |
| 5792 | |
| 5793 | // In TLS 1.3, the ECDSA curve comes from the signature algorithm. |
| 5794 | testCases = append(testCases, testCase{ |
| 5795 | name: "ECDSACurveMismatch-Verify-TLS13", |
| 5796 | config: Config{ |
| 5797 | MaxVersion: VersionTLS13, |
| 5798 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 5799 | Certificates: []Certificate{ecdsaP256Certificate}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5800 | SignSignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5801 | signatureECDSAWithP384AndSHA384, |
| 5802 | }, |
| 5803 | Bugs: ProtocolBugs{ |
| 5804 | SkipECDSACurveCheck: true, |
| 5805 | }, |
| 5806 | }, |
| 5807 | shouldFail: true, |
| 5808 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 5809 | }) |
| 5810 | |
| 5811 | // Signature algorithm selection in TLS 1.3 should take the curve into |
| 5812 | // account. |
| 5813 | testCases = append(testCases, testCase{ |
| 5814 | testType: serverTest, |
| 5815 | name: "ECDSACurveMismatch-Sign-TLS13", |
| 5816 | config: Config{ |
| 5817 | MaxVersion: VersionTLS13, |
| 5818 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
David Benjamin | 7a41d37 | 2016-07-09 11:21:54 -0700 | [diff] [blame] | 5819 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
David Benjamin | 1fb125c | 2016-07-08 18:52:12 -0700 | [diff] [blame] | 5820 | signatureECDSAWithP384AndSHA384, |
| 5821 | signatureECDSAWithP256AndSHA256, |
| 5822 | }, |
| 5823 | }, |
| 5824 | flags: []string{ |
| 5825 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 5826 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 5827 | }, |
| 5828 | expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 5829 | }) |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 5830 | |
| 5831 | // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the |
| 5832 | // server does not attempt to sign in that case. |
| 5833 | testCases = append(testCases, testCase{ |
| 5834 | testType: serverTest, |
| 5835 | name: "RSA-PSS-Large", |
| 5836 | config: Config{ |
| 5837 | MaxVersion: VersionTLS13, |
| 5838 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 5839 | signatureRSAPSSWithSHA512, |
| 5840 | }, |
| 5841 | }, |
| 5842 | flags: []string{ |
| 5843 | "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile), |
| 5844 | "-key-file", path.Join(*resourceDir, rsa1024KeyFile), |
| 5845 | }, |
| 5846 | shouldFail: true, |
| 5847 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 5848 | }) |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 5849 | } |
| 5850 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5851 | // timeouts is the retransmit schedule for BoringSSL. It doubles and |
| 5852 | // caps at 60 seconds. On the 13th timeout, it gives up. |
| 5853 | var timeouts = []time.Duration{ |
| 5854 | 1 * time.Second, |
| 5855 | 2 * time.Second, |
| 5856 | 4 * time.Second, |
| 5857 | 8 * time.Second, |
| 5858 | 16 * time.Second, |
| 5859 | 32 * time.Second, |
| 5860 | 60 * time.Second, |
| 5861 | 60 * time.Second, |
| 5862 | 60 * time.Second, |
| 5863 | 60 * time.Second, |
| 5864 | 60 * time.Second, |
| 5865 | 60 * time.Second, |
| 5866 | 60 * time.Second, |
| 5867 | } |
| 5868 | |
Taylor Brandstetter | 376a0fe | 2016-05-10 19:30:28 -0700 | [diff] [blame] | 5869 | // shortTimeouts is an alternate set of timeouts which would occur if the |
| 5870 | // initial timeout duration was set to 250ms. |
| 5871 | var shortTimeouts = []time.Duration{ |
| 5872 | 250 * time.Millisecond, |
| 5873 | 500 * time.Millisecond, |
| 5874 | 1 * time.Second, |
| 5875 | 2 * time.Second, |
| 5876 | 4 * time.Second, |
| 5877 | 8 * time.Second, |
| 5878 | 16 * time.Second, |
| 5879 | 32 * time.Second, |
| 5880 | 60 * time.Second, |
| 5881 | 60 * time.Second, |
| 5882 | 60 * time.Second, |
| 5883 | 60 * time.Second, |
| 5884 | 60 * time.Second, |
| 5885 | } |
| 5886 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5887 | func addDTLSRetransmitTests() { |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5888 | // These tests work by coordinating some behavior on both the shim and |
| 5889 | // the runner. |
| 5890 | // |
| 5891 | // TimeoutSchedule configures the runner to send a series of timeout |
| 5892 | // opcodes to the shim (see packetAdaptor) immediately before reading |
| 5893 | // each peer handshake flight N. The timeout opcode both simulates a |
| 5894 | // timeout in the shim and acts as a synchronization point to help the |
| 5895 | // runner bracket each handshake flight. |
| 5896 | // |
| 5897 | // We assume the shim does not read from the channel eagerly. It must |
| 5898 | // first wait until it has sent flight N and is ready to receive |
| 5899 | // handshake flight N+1. At this point, it will process the timeout |
| 5900 | // opcode. It must then immediately respond with a timeout ACK and act |
| 5901 | // as if the shim was idle for the specified amount of time. |
| 5902 | // |
| 5903 | // The runner then drops all packets received before the ACK and |
| 5904 | // continues waiting for flight N. This ordering results in one attempt |
| 5905 | // at sending flight N to be dropped. For the test to complete, the |
| 5906 | // shim must send flight N again, testing that the shim implements DTLS |
| 5907 | // retransmit on a timeout. |
| 5908 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 5909 | // TODO(davidben): Add DTLS 1.3 versions of these tests. There will |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5910 | // likely be more epochs to cross and the final message's retransmit may |
| 5911 | // be more complex. |
| 5912 | |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5913 | for _, async := range []bool{true, false} { |
| 5914 | var tests []testCase |
| 5915 | |
| 5916 | // Test that this is indeed the timeout schedule. Stress all |
| 5917 | // four patterns of handshake. |
| 5918 | for i := 1; i < len(timeouts); i++ { |
| 5919 | number := strconv.Itoa(i) |
| 5920 | tests = append(tests, testCase{ |
| 5921 | protocol: dtls, |
| 5922 | name: "DTLS-Retransmit-Client-" + number, |
| 5923 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5924 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5925 | Bugs: ProtocolBugs{ |
| 5926 | TimeoutSchedule: timeouts[:i], |
| 5927 | }, |
| 5928 | }, |
| 5929 | resumeSession: true, |
| 5930 | }) |
| 5931 | tests = append(tests, testCase{ |
| 5932 | protocol: dtls, |
| 5933 | testType: serverTest, |
| 5934 | name: "DTLS-Retransmit-Server-" + number, |
| 5935 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5936 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5937 | Bugs: ProtocolBugs{ |
| 5938 | TimeoutSchedule: timeouts[:i], |
| 5939 | }, |
| 5940 | }, |
| 5941 | resumeSession: true, |
| 5942 | }) |
| 5943 | } |
| 5944 | |
| 5945 | // Test that exceeding the timeout schedule hits a read |
| 5946 | // timeout. |
| 5947 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5948 | protocol: dtls, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5949 | name: "DTLS-Retransmit-Timeout", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5950 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5951 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5952 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5953 | TimeoutSchedule: timeouts, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5954 | }, |
| 5955 | }, |
| 5956 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5957 | shouldFail: true, |
| 5958 | expectedError: ":READ_TIMEOUT_EXPIRED:", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 5959 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5960 | |
| 5961 | if async { |
| 5962 | // Test that timeout handling has a fudge factor, due to API |
| 5963 | // problems. |
| 5964 | tests = append(tests, testCase{ |
| 5965 | protocol: dtls, |
| 5966 | name: "DTLS-Retransmit-Fudge", |
| 5967 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5968 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5969 | Bugs: ProtocolBugs{ |
| 5970 | TimeoutSchedule: []time.Duration{ |
| 5971 | timeouts[0] - 10*time.Millisecond, |
| 5972 | }, |
| 5973 | }, |
| 5974 | }, |
| 5975 | resumeSession: true, |
| 5976 | }) |
| 5977 | } |
| 5978 | |
| 5979 | // Test that the final Finished retransmitting isn't |
| 5980 | // duplicated if the peer badly fragments everything. |
| 5981 | tests = append(tests, testCase{ |
| 5982 | testType: serverTest, |
| 5983 | protocol: dtls, |
| 5984 | name: "DTLS-Retransmit-Fragmented", |
| 5985 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5986 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 5987 | Bugs: ProtocolBugs{ |
| 5988 | TimeoutSchedule: []time.Duration{timeouts[0]}, |
| 5989 | MaxHandshakeRecordLength: 2, |
| 5990 | }, |
| 5991 | }, |
| 5992 | }) |
| 5993 | |
| 5994 | // Test the timeout schedule when a shorter initial timeout duration is set. |
| 5995 | tests = append(tests, testCase{ |
| 5996 | protocol: dtls, |
| 5997 | name: "DTLS-Retransmit-Short-Client", |
| 5998 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 5999 | MaxVersion: VersionTLS12, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6000 | Bugs: ProtocolBugs{ |
| 6001 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
| 6002 | }, |
| 6003 | }, |
| 6004 | resumeSession: true, |
| 6005 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
| 6006 | }) |
| 6007 | tests = append(tests, testCase{ |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6008 | protocol: dtls, |
| 6009 | testType: serverTest, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6010 | name: "DTLS-Retransmit-Short-Server", |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6011 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6012 | MaxVersion: VersionTLS12, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6013 | Bugs: ProtocolBugs{ |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6014 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6015 | }, |
| 6016 | }, |
| 6017 | resumeSession: true, |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6018 | flags: []string{"-initial-timeout-duration-ms", "250"}, |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6019 | }) |
David Benjamin | 585d7a4 | 2016-06-02 14:58:00 -0400 | [diff] [blame] | 6020 | |
| 6021 | for _, test := range tests { |
| 6022 | if async { |
| 6023 | test.name += "-Async" |
| 6024 | test.flags = append(test.flags, "-async") |
| 6025 | } |
| 6026 | |
| 6027 | testCases = append(testCases, test) |
| 6028 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6029 | } |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 6030 | } |
| 6031 | |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 6032 | func addExportKeyingMaterialTests() { |
| 6033 | for _, vers := range tlsVersions { |
| 6034 | if vers.version == VersionSSL30 { |
| 6035 | continue |
| 6036 | } |
| 6037 | testCases = append(testCases, testCase{ |
| 6038 | name: "ExportKeyingMaterial-" + vers.name, |
| 6039 | config: Config{ |
| 6040 | MaxVersion: vers.version, |
| 6041 | }, |
| 6042 | exportKeyingMaterial: 1024, |
| 6043 | exportLabel: "label", |
| 6044 | exportContext: "context", |
| 6045 | useExportContext: true, |
| 6046 | }) |
| 6047 | testCases = append(testCases, testCase{ |
| 6048 | name: "ExportKeyingMaterial-NoContext-" + vers.name, |
| 6049 | config: Config{ |
| 6050 | MaxVersion: vers.version, |
| 6051 | }, |
| 6052 | exportKeyingMaterial: 1024, |
| 6053 | }) |
| 6054 | testCases = append(testCases, testCase{ |
| 6055 | name: "ExportKeyingMaterial-EmptyContext-" + vers.name, |
| 6056 | config: Config{ |
| 6057 | MaxVersion: vers.version, |
| 6058 | }, |
| 6059 | exportKeyingMaterial: 1024, |
| 6060 | useExportContext: true, |
| 6061 | }) |
| 6062 | testCases = append(testCases, testCase{ |
| 6063 | name: "ExportKeyingMaterial-Small-" + vers.name, |
| 6064 | config: Config{ |
| 6065 | MaxVersion: vers.version, |
| 6066 | }, |
| 6067 | exportKeyingMaterial: 1, |
| 6068 | exportLabel: "label", |
| 6069 | exportContext: "context", |
| 6070 | useExportContext: true, |
| 6071 | }) |
| 6072 | } |
| 6073 | testCases = append(testCases, testCase{ |
| 6074 | name: "ExportKeyingMaterial-SSL3", |
| 6075 | config: Config{ |
| 6076 | MaxVersion: VersionSSL30, |
| 6077 | }, |
| 6078 | exportKeyingMaterial: 1024, |
| 6079 | exportLabel: "label", |
| 6080 | exportContext: "context", |
| 6081 | useExportContext: true, |
| 6082 | shouldFail: true, |
| 6083 | expectedError: "failed to export keying material", |
| 6084 | }) |
| 6085 | } |
| 6086 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6087 | func addTLSUniqueTests() { |
| 6088 | for _, isClient := range []bool{false, true} { |
| 6089 | for _, isResumption := range []bool{false, true} { |
| 6090 | for _, hasEMS := range []bool{false, true} { |
| 6091 | var suffix string |
| 6092 | if isResumption { |
| 6093 | suffix = "Resume-" |
| 6094 | } else { |
| 6095 | suffix = "Full-" |
| 6096 | } |
| 6097 | |
| 6098 | if hasEMS { |
| 6099 | suffix += "EMS-" |
| 6100 | } else { |
| 6101 | suffix += "NoEMS-" |
| 6102 | } |
| 6103 | |
| 6104 | if isClient { |
| 6105 | suffix += "Client" |
| 6106 | } else { |
| 6107 | suffix += "Server" |
| 6108 | } |
| 6109 | |
| 6110 | test := testCase{ |
| 6111 | name: "TLSUnique-" + suffix, |
| 6112 | testTLSUnique: true, |
| 6113 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6114 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6115 | Bugs: ProtocolBugs{ |
| 6116 | NoExtendedMasterSecret: !hasEMS, |
| 6117 | }, |
| 6118 | }, |
| 6119 | } |
| 6120 | |
| 6121 | if isResumption { |
| 6122 | test.resumeSession = true |
| 6123 | test.resumeConfig = &Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6124 | MaxVersion: VersionTLS12, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 6125 | Bugs: ProtocolBugs{ |
| 6126 | NoExtendedMasterSecret: !hasEMS, |
| 6127 | }, |
| 6128 | } |
| 6129 | } |
| 6130 | |
| 6131 | if isResumption && !hasEMS { |
| 6132 | test.shouldFail = true |
| 6133 | test.expectedError = "failed to get tls-unique" |
| 6134 | } |
| 6135 | |
| 6136 | testCases = append(testCases, test) |
| 6137 | } |
| 6138 | } |
| 6139 | } |
| 6140 | } |
| 6141 | |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6142 | func addCustomExtensionTests() { |
| 6143 | expectedContents := "custom extension" |
| 6144 | emptyString := "" |
| 6145 | |
| 6146 | for _, isClient := range []bool{false, true} { |
| 6147 | suffix := "Server" |
| 6148 | flag := "-enable-server-custom-extension" |
| 6149 | testType := serverTest |
| 6150 | if isClient { |
| 6151 | suffix = "Client" |
| 6152 | flag = "-enable-client-custom-extension" |
| 6153 | testType = clientTest |
| 6154 | } |
| 6155 | |
| 6156 | testCases = append(testCases, testCase{ |
| 6157 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6158 | name: "CustomExtensions-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6159 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6160 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6161 | Bugs: ProtocolBugs{ |
| 6162 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6163 | ExpectedCustomExtension: &expectedContents, |
| 6164 | }, |
| 6165 | }, |
| 6166 | flags: []string{flag}, |
| 6167 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6168 | testCases = append(testCases, testCase{ |
| 6169 | testType: testType, |
| 6170 | name: "CustomExtensions-" + suffix + "-TLS13", |
| 6171 | config: Config{ |
| 6172 | MaxVersion: VersionTLS13, |
| 6173 | Bugs: ProtocolBugs{ |
| 6174 | CustomExtension: expectedContents, |
| 6175 | ExpectedCustomExtension: &expectedContents, |
| 6176 | }, |
| 6177 | }, |
| 6178 | flags: []string{flag}, |
| 6179 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6180 | |
| 6181 | // If the parse callback fails, the handshake should also fail. |
| 6182 | testCases = append(testCases, testCase{ |
| 6183 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6184 | name: "CustomExtensions-ParseError-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6185 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6186 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6187 | Bugs: ProtocolBugs{ |
| 6188 | CustomExtension: expectedContents + "foo", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6189 | ExpectedCustomExtension: &expectedContents, |
| 6190 | }, |
| 6191 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6192 | flags: []string{flag}, |
| 6193 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6194 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6195 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6196 | testCases = append(testCases, testCase{ |
| 6197 | testType: testType, |
| 6198 | name: "CustomExtensions-ParseError-" + suffix + "-TLS13", |
| 6199 | config: Config{ |
| 6200 | MaxVersion: VersionTLS13, |
| 6201 | Bugs: ProtocolBugs{ |
| 6202 | CustomExtension: expectedContents + "foo", |
| 6203 | ExpectedCustomExtension: &expectedContents, |
| 6204 | }, |
| 6205 | }, |
| 6206 | flags: []string{flag}, |
| 6207 | shouldFail: true, |
| 6208 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6209 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6210 | |
| 6211 | // If the add callback fails, the handshake should also fail. |
| 6212 | testCases = append(testCases, testCase{ |
| 6213 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6214 | name: "CustomExtensions-FailAdd-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6215 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6216 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6217 | Bugs: ProtocolBugs{ |
| 6218 | CustomExtension: expectedContents, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6219 | ExpectedCustomExtension: &expectedContents, |
| 6220 | }, |
| 6221 | }, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6222 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 6223 | shouldFail: true, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6224 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6225 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6226 | testCases = append(testCases, testCase{ |
| 6227 | testType: testType, |
| 6228 | name: "CustomExtensions-FailAdd-" + suffix + "-TLS13", |
| 6229 | config: Config{ |
| 6230 | MaxVersion: VersionTLS13, |
| 6231 | Bugs: ProtocolBugs{ |
| 6232 | CustomExtension: expectedContents, |
| 6233 | ExpectedCustomExtension: &expectedContents, |
| 6234 | }, |
| 6235 | }, |
| 6236 | flags: []string{flag, "-custom-extension-fail-add"}, |
| 6237 | shouldFail: true, |
| 6238 | expectedError: ":CUSTOM_EXTENSION_ERROR:", |
| 6239 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6240 | |
| 6241 | // If the add callback returns zero, no extension should be |
| 6242 | // added. |
| 6243 | skipCustomExtension := expectedContents |
| 6244 | if isClient { |
| 6245 | // For the case where the client skips sending the |
| 6246 | // custom extension, the server must not “echo” it. |
| 6247 | skipCustomExtension = "" |
| 6248 | } |
| 6249 | testCases = append(testCases, testCase{ |
| 6250 | testType: testType, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6251 | name: "CustomExtensions-Skip-" + suffix, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6252 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6253 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6254 | Bugs: ProtocolBugs{ |
| 6255 | CustomExtension: skipCustomExtension, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6256 | ExpectedCustomExtension: &emptyString, |
| 6257 | }, |
| 6258 | }, |
| 6259 | flags: []string{flag, "-custom-extension-skip"}, |
| 6260 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6261 | testCases = append(testCases, testCase{ |
| 6262 | testType: testType, |
| 6263 | name: "CustomExtensions-Skip-" + suffix + "-TLS13", |
| 6264 | config: Config{ |
| 6265 | MaxVersion: VersionTLS13, |
| 6266 | Bugs: ProtocolBugs{ |
| 6267 | CustomExtension: skipCustomExtension, |
| 6268 | ExpectedCustomExtension: &emptyString, |
| 6269 | }, |
| 6270 | }, |
| 6271 | flags: []string{flag, "-custom-extension-skip"}, |
| 6272 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
| 6275 | // The custom extension add callback should not be called if the client |
| 6276 | // doesn't send the extension. |
| 6277 | testCases = append(testCases, testCase{ |
| 6278 | testType: serverTest, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6279 | name: "CustomExtensions-NotCalled-Server", |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6280 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6281 | MaxVersion: VersionTLS12, |
David Benjamin | 399e7c9 | 2015-07-30 23:01:27 -0400 | [diff] [blame] | 6282 | Bugs: ProtocolBugs{ |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6283 | ExpectedCustomExtension: &emptyString, |
| 6284 | }, |
| 6285 | }, |
| 6286 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 6287 | }) |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6288 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6289 | testCases = append(testCases, testCase{ |
| 6290 | testType: serverTest, |
| 6291 | name: "CustomExtensions-NotCalled-Server-TLS13", |
| 6292 | config: Config{ |
| 6293 | MaxVersion: VersionTLS13, |
| 6294 | Bugs: ProtocolBugs{ |
| 6295 | ExpectedCustomExtension: &emptyString, |
| 6296 | }, |
| 6297 | }, |
| 6298 | flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"}, |
| 6299 | }) |
| 6300 | |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6301 | // Test an unknown extension from the server. |
| 6302 | testCases = append(testCases, testCase{ |
| 6303 | testType: clientTest, |
| 6304 | name: "UnknownExtension-Client", |
| 6305 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6306 | MaxVersion: VersionTLS12, |
Adam Langley | 2deb984 | 2015-08-07 11:15:37 -0700 | [diff] [blame] | 6307 | Bugs: ProtocolBugs{ |
| 6308 | CustomExtension: expectedContents, |
| 6309 | }, |
| 6310 | }, |
| 6311 | shouldFail: true, |
| 6312 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6313 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6314 | testCases = append(testCases, testCase{ |
| 6315 | testType: clientTest, |
| 6316 | name: "UnknownExtension-Client-TLS13", |
| 6317 | config: Config{ |
| 6318 | MaxVersion: VersionTLS13, |
| 6319 | Bugs: ProtocolBugs{ |
| 6320 | CustomExtension: expectedContents, |
| 6321 | }, |
| 6322 | }, |
| 6323 | shouldFail: true, |
| 6324 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6325 | }) |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 6326 | } |
| 6327 | |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 6328 | func addRSAClientKeyExchangeTests() { |
| 6329 | for bad := RSABadValue(1); bad < NumRSABadValues; bad++ { |
| 6330 | testCases = append(testCases, testCase{ |
| 6331 | testType: serverTest, |
| 6332 | name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad), |
| 6333 | config: Config{ |
| 6334 | // Ensure the ClientHello version and final |
| 6335 | // version are different, to detect if the |
| 6336 | // server uses the wrong one. |
| 6337 | MaxVersion: VersionTLS11, |
| 6338 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 6339 | Bugs: ProtocolBugs{ |
| 6340 | BadRSAClientKeyExchange: bad, |
| 6341 | }, |
| 6342 | }, |
| 6343 | shouldFail: true, |
| 6344 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6345 | }) |
| 6346 | } |
| 6347 | } |
| 6348 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6349 | var testCurves = []struct { |
| 6350 | name string |
| 6351 | id CurveID |
| 6352 | }{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6353 | {"P-256", CurveP256}, |
| 6354 | {"P-384", CurveP384}, |
| 6355 | {"P-521", CurveP521}, |
David Benjamin | 4298d77 | 2015-12-19 00:18:25 -0500 | [diff] [blame] | 6356 | {"X25519", CurveX25519}, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6357 | } |
| 6358 | |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6359 | const bogusCurve = 0x1234 |
| 6360 | |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6361 | func addCurveTests() { |
| 6362 | for _, curve := range testCurves { |
| 6363 | testCases = append(testCases, testCase{ |
| 6364 | name: "CurveTest-Client-" + curve.name, |
| 6365 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6366 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6367 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6368 | CurvePreferences: []CurveID{curve.id}, |
| 6369 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6370 | flags: []string{"-enable-all-curves"}, |
| 6371 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6372 | }) |
| 6373 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6374 | name: "CurveTest-Client-" + curve.name + "-TLS13", |
| 6375 | config: Config{ |
| 6376 | MaxVersion: VersionTLS13, |
| 6377 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6378 | CurvePreferences: []CurveID{curve.id}, |
| 6379 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6380 | flags: []string{"-enable-all-curves"}, |
| 6381 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6382 | }) |
| 6383 | testCases = append(testCases, testCase{ |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6384 | testType: serverTest, |
| 6385 | name: "CurveTest-Server-" + curve.name, |
| 6386 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6387 | MaxVersion: VersionTLS12, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6388 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6389 | CurvePreferences: []CurveID{curve.id}, |
| 6390 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6391 | flags: []string{"-enable-all-curves"}, |
| 6392 | expectedCurveID: curve.id, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6393 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6394 | testCases = append(testCases, testCase{ |
| 6395 | testType: serverTest, |
| 6396 | name: "CurveTest-Server-" + curve.name + "-TLS13", |
| 6397 | config: Config{ |
| 6398 | MaxVersion: VersionTLS13, |
| 6399 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6400 | CurvePreferences: []CurveID{curve.id}, |
| 6401 | }, |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 6402 | flags: []string{"-enable-all-curves"}, |
| 6403 | expectedCurveID: curve.id, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6404 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6405 | } |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 6406 | |
| 6407 | // The server must be tolerant to bogus curves. |
David Benjamin | 241ae83 | 2016-01-15 03:04:54 -0500 | [diff] [blame] | 6408 | testCases = append(testCases, testCase{ |
| 6409 | testType: serverTest, |
| 6410 | name: "UnknownCurve", |
| 6411 | config: Config{ |
| 6412 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6413 | CurvePreferences: []CurveID{bogusCurve, CurveP256}, |
| 6414 | }, |
| 6415 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6416 | |
| 6417 | // The server must not consider ECDHE ciphers when there are no |
| 6418 | // supported curves. |
| 6419 | testCases = append(testCases, testCase{ |
| 6420 | testType: serverTest, |
| 6421 | name: "NoSupportedCurves", |
| 6422 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6423 | MaxVersion: VersionTLS12, |
| 6424 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6425 | Bugs: ProtocolBugs{ |
| 6426 | NoSupportedCurves: true, |
| 6427 | }, |
| 6428 | }, |
| 6429 | shouldFail: true, |
| 6430 | expectedError: ":NO_SHARED_CIPHER:", |
| 6431 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6432 | testCases = append(testCases, testCase{ |
| 6433 | testType: serverTest, |
| 6434 | name: "NoSupportedCurves-TLS13", |
| 6435 | config: Config{ |
| 6436 | MaxVersion: VersionTLS13, |
| 6437 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6438 | Bugs: ProtocolBugs{ |
| 6439 | NoSupportedCurves: true, |
| 6440 | }, |
| 6441 | }, |
| 6442 | shouldFail: true, |
| 6443 | expectedError: ":NO_SHARED_CIPHER:", |
| 6444 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6445 | |
| 6446 | // The server must fall back to another cipher when there are no |
| 6447 | // supported curves. |
| 6448 | testCases = append(testCases, testCase{ |
| 6449 | testType: serverTest, |
| 6450 | name: "NoCommonCurves", |
| 6451 | config: Config{ |
| 6452 | MaxVersion: VersionTLS12, |
| 6453 | CipherSuites: []uint16{ |
| 6454 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6455 | TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6456 | }, |
| 6457 | CurvePreferences: []CurveID{CurveP224}, |
| 6458 | }, |
| 6459 | expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 6460 | }) |
| 6461 | |
| 6462 | // The client must reject bogus curves and disabled curves. |
| 6463 | testCases = append(testCases, testCase{ |
| 6464 | name: "BadECDHECurve", |
| 6465 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6466 | MaxVersion: VersionTLS12, |
| 6467 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6468 | Bugs: ProtocolBugs{ |
| 6469 | SendCurve: bogusCurve, |
| 6470 | }, |
| 6471 | }, |
| 6472 | shouldFail: true, |
| 6473 | expectedError: ":WRONG_CURVE:", |
| 6474 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6475 | testCases = append(testCases, testCase{ |
| 6476 | name: "BadECDHECurve-TLS13", |
| 6477 | config: Config{ |
| 6478 | MaxVersion: VersionTLS13, |
| 6479 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6480 | Bugs: ProtocolBugs{ |
| 6481 | SendCurve: bogusCurve, |
| 6482 | }, |
| 6483 | }, |
| 6484 | shouldFail: true, |
| 6485 | expectedError: ":WRONG_CURVE:", |
| 6486 | }) |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6487 | |
| 6488 | testCases = append(testCases, testCase{ |
| 6489 | name: "UnsupportedCurve", |
| 6490 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6491 | MaxVersion: VersionTLS12, |
| 6492 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6493 | CurvePreferences: []CurveID{CurveP256}, |
| 6494 | Bugs: ProtocolBugs{ |
| 6495 | IgnorePeerCurvePreferences: true, |
| 6496 | }, |
| 6497 | }, |
| 6498 | flags: []string{"-p384-only"}, |
| 6499 | shouldFail: true, |
| 6500 | expectedError: ":WRONG_CURVE:", |
| 6501 | }) |
| 6502 | |
David Benjamin | 4f92157 | 2016-07-17 14:20:10 +0200 | [diff] [blame] | 6503 | testCases = append(testCases, testCase{ |
| 6504 | // TODO(davidben): Add a TLS 1.3 version where |
| 6505 | // HelloRetryRequest requests an unsupported curve. |
| 6506 | name: "UnsupportedCurve-ServerHello-TLS13", |
| 6507 | config: Config{ |
| 6508 | MaxVersion: VersionTLS12, |
| 6509 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6510 | CurvePreferences: []CurveID{CurveP384}, |
| 6511 | Bugs: ProtocolBugs{ |
| 6512 | SendCurve: CurveP256, |
| 6513 | }, |
| 6514 | }, |
| 6515 | flags: []string{"-p384-only"}, |
| 6516 | shouldFail: true, |
| 6517 | expectedError: ":WRONG_CURVE:", |
| 6518 | }) |
| 6519 | |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6520 | // Test invalid curve points. |
| 6521 | testCases = append(testCases, testCase{ |
| 6522 | name: "InvalidECDHPoint-Client", |
| 6523 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6524 | MaxVersion: VersionTLS12, |
| 6525 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6526 | CurvePreferences: []CurveID{CurveP256}, |
| 6527 | Bugs: ProtocolBugs{ |
| 6528 | InvalidECDHPoint: true, |
| 6529 | }, |
| 6530 | }, |
| 6531 | shouldFail: true, |
| 6532 | expectedError: ":INVALID_ENCODING:", |
| 6533 | }) |
| 6534 | testCases = append(testCases, testCase{ |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6535 | name: "InvalidECDHPoint-Client-TLS13", |
| 6536 | config: Config{ |
| 6537 | MaxVersion: VersionTLS13, |
| 6538 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6539 | CurvePreferences: []CurveID{CurveP256}, |
| 6540 | Bugs: ProtocolBugs{ |
| 6541 | InvalidECDHPoint: true, |
| 6542 | }, |
| 6543 | }, |
| 6544 | shouldFail: true, |
| 6545 | expectedError: ":INVALID_ENCODING:", |
| 6546 | }) |
| 6547 | testCases = append(testCases, testCase{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6548 | testType: serverTest, |
| 6549 | name: "InvalidECDHPoint-Server", |
| 6550 | config: Config{ |
David Benjamin | 4c3ddf7 | 2016-06-29 18:13:53 -0400 | [diff] [blame] | 6551 | MaxVersion: VersionTLS12, |
| 6552 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6553 | CurvePreferences: []CurveID{CurveP256}, |
| 6554 | Bugs: ProtocolBugs{ |
| 6555 | InvalidECDHPoint: true, |
| 6556 | }, |
| 6557 | }, |
| 6558 | shouldFail: true, |
| 6559 | expectedError: ":INVALID_ENCODING:", |
| 6560 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6561 | testCases = append(testCases, testCase{ |
| 6562 | testType: serverTest, |
| 6563 | name: "InvalidECDHPoint-Server-TLS13", |
| 6564 | config: Config{ |
| 6565 | MaxVersion: VersionTLS13, |
| 6566 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6567 | CurvePreferences: []CurveID{CurveP256}, |
| 6568 | Bugs: ProtocolBugs{ |
| 6569 | InvalidECDHPoint: true, |
| 6570 | }, |
| 6571 | }, |
| 6572 | shouldFail: true, |
| 6573 | expectedError: ":INVALID_ENCODING:", |
| 6574 | }) |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 6575 | } |
| 6576 | |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6577 | func addCECPQ1Tests() { |
| 6578 | testCases = append(testCases, testCase{ |
| 6579 | testType: clientTest, |
| 6580 | name: "CECPQ1-Client-BadX25519Part", |
| 6581 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6582 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6583 | MinVersion: VersionTLS12, |
| 6584 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6585 | Bugs: ProtocolBugs{ |
| 6586 | CECPQ1BadX25519Part: true, |
| 6587 | }, |
| 6588 | }, |
| 6589 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6590 | shouldFail: true, |
| 6591 | expectedLocalError: "local error: bad record MAC", |
| 6592 | }) |
| 6593 | testCases = append(testCases, testCase{ |
| 6594 | testType: clientTest, |
| 6595 | name: "CECPQ1-Client-BadNewhopePart", |
| 6596 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6597 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6598 | MinVersion: VersionTLS12, |
| 6599 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6600 | Bugs: ProtocolBugs{ |
| 6601 | CECPQ1BadNewhopePart: true, |
| 6602 | }, |
| 6603 | }, |
| 6604 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6605 | shouldFail: true, |
| 6606 | expectedLocalError: "local error: bad record MAC", |
| 6607 | }) |
| 6608 | testCases = append(testCases, testCase{ |
| 6609 | testType: serverTest, |
| 6610 | name: "CECPQ1-Server-BadX25519Part", |
| 6611 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6612 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6613 | MinVersion: VersionTLS12, |
| 6614 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6615 | Bugs: ProtocolBugs{ |
| 6616 | CECPQ1BadX25519Part: true, |
| 6617 | }, |
| 6618 | }, |
| 6619 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6620 | shouldFail: true, |
| 6621 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6622 | }) |
| 6623 | testCases = append(testCases, testCase{ |
| 6624 | testType: serverTest, |
| 6625 | name: "CECPQ1-Server-BadNewhopePart", |
| 6626 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6627 | MaxVersion: VersionTLS12, |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 6628 | MinVersion: VersionTLS12, |
| 6629 | CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384}, |
| 6630 | Bugs: ProtocolBugs{ |
| 6631 | CECPQ1BadNewhopePart: true, |
| 6632 | }, |
| 6633 | }, |
| 6634 | flags: []string{"-cipher", "kCECPQ1"}, |
| 6635 | shouldFail: true, |
| 6636 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6637 | }) |
| 6638 | } |
| 6639 | |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6640 | func addKeyExchangeInfoTests() { |
| 6641 | testCases = append(testCases, testCase{ |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6642 | name: "KeyExchangeInfo-DHE-Client", |
| 6643 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6644 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6645 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6646 | Bugs: ProtocolBugs{ |
| 6647 | // This is a 1234-bit prime number, generated |
| 6648 | // with: |
| 6649 | // openssl gendh 1234 | openssl asn1parse -i |
| 6650 | DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"), |
| 6651 | }, |
| 6652 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 6653 | flags: []string{"-expect-dhe-group-size", "1234"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6654 | }) |
| 6655 | testCases = append(testCases, testCase{ |
| 6656 | testType: serverTest, |
| 6657 | name: "KeyExchangeInfo-DHE-Server", |
| 6658 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6659 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6660 | CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6661 | }, |
| 6662 | // bssl_shim as a server configures a 2048-bit DHE group. |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 6663 | flags: []string{"-expect-dhe-group-size", "2048"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6664 | }) |
| 6665 | |
| 6666 | testCases = append(testCases, testCase{ |
| 6667 | name: "KeyExchangeInfo-ECDHE-Client", |
| 6668 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6669 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6670 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6671 | CurvePreferences: []CurveID{CurveX25519}, |
| 6672 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 6673 | flags: []string{"-expect-curve-id", "29", "-enable-all-curves"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6674 | }) |
| 6675 | testCases = append(testCases, testCase{ |
| 6676 | testType: serverTest, |
| 6677 | name: "KeyExchangeInfo-ECDHE-Server", |
| 6678 | config: Config{ |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 6679 | MaxVersion: VersionTLS12, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6680 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 6681 | CurvePreferences: []CurveID{CurveX25519}, |
| 6682 | }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 6683 | flags: []string{"-expect-curve-id", "29", "-enable-all-curves"}, |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 6684 | }) |
| 6685 | } |
| 6686 | |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 6687 | func addTLS13RecordTests() { |
| 6688 | testCases = append(testCases, testCase{ |
| 6689 | name: "TLS13-RecordPadding", |
| 6690 | config: Config{ |
| 6691 | MaxVersion: VersionTLS13, |
| 6692 | MinVersion: VersionTLS13, |
| 6693 | Bugs: ProtocolBugs{ |
| 6694 | RecordPadding: 10, |
| 6695 | }, |
| 6696 | }, |
| 6697 | }) |
| 6698 | |
| 6699 | testCases = append(testCases, testCase{ |
| 6700 | name: "TLS13-EmptyRecords", |
| 6701 | config: Config{ |
| 6702 | MaxVersion: VersionTLS13, |
| 6703 | MinVersion: VersionTLS13, |
| 6704 | Bugs: ProtocolBugs{ |
| 6705 | OmitRecordContents: true, |
| 6706 | }, |
| 6707 | }, |
| 6708 | shouldFail: true, |
| 6709 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6710 | }) |
| 6711 | |
| 6712 | testCases = append(testCases, testCase{ |
| 6713 | name: "TLS13-OnlyPadding", |
| 6714 | config: Config{ |
| 6715 | MaxVersion: VersionTLS13, |
| 6716 | MinVersion: VersionTLS13, |
| 6717 | Bugs: ProtocolBugs{ |
| 6718 | OmitRecordContents: true, |
| 6719 | RecordPadding: 10, |
| 6720 | }, |
| 6721 | }, |
| 6722 | shouldFail: true, |
| 6723 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 6724 | }) |
| 6725 | |
| 6726 | testCases = append(testCases, testCase{ |
| 6727 | name: "TLS13-WrongOuterRecord", |
| 6728 | config: Config{ |
| 6729 | MaxVersion: VersionTLS13, |
| 6730 | MinVersion: VersionTLS13, |
| 6731 | Bugs: ProtocolBugs{ |
| 6732 | OuterRecordType: recordTypeHandshake, |
| 6733 | }, |
| 6734 | }, |
| 6735 | shouldFail: true, |
| 6736 | expectedError: ":INVALID_OUTER_RECORD_TYPE:", |
| 6737 | }) |
| 6738 | } |
| 6739 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 6740 | func addChangeCipherSpecTests() { |
| 6741 | // Test missing ChangeCipherSpecs. |
| 6742 | testCases = append(testCases, testCase{ |
| 6743 | name: "SkipChangeCipherSpec-Client", |
| 6744 | config: Config{ |
| 6745 | MaxVersion: VersionTLS12, |
| 6746 | Bugs: ProtocolBugs{ |
| 6747 | SkipChangeCipherSpec: true, |
| 6748 | }, |
| 6749 | }, |
| 6750 | shouldFail: true, |
| 6751 | expectedError: ":UNEXPECTED_RECORD:", |
| 6752 | }) |
| 6753 | testCases = append(testCases, testCase{ |
| 6754 | testType: serverTest, |
| 6755 | name: "SkipChangeCipherSpec-Server", |
| 6756 | config: Config{ |
| 6757 | MaxVersion: VersionTLS12, |
| 6758 | Bugs: ProtocolBugs{ |
| 6759 | SkipChangeCipherSpec: true, |
| 6760 | }, |
| 6761 | }, |
| 6762 | shouldFail: true, |
| 6763 | expectedError: ":UNEXPECTED_RECORD:", |
| 6764 | }) |
| 6765 | testCases = append(testCases, testCase{ |
| 6766 | testType: serverTest, |
| 6767 | name: "SkipChangeCipherSpec-Server-NPN", |
| 6768 | config: Config{ |
| 6769 | MaxVersion: VersionTLS12, |
| 6770 | NextProtos: []string{"bar"}, |
| 6771 | Bugs: ProtocolBugs{ |
| 6772 | SkipChangeCipherSpec: true, |
| 6773 | }, |
| 6774 | }, |
| 6775 | flags: []string{ |
| 6776 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 6777 | }, |
| 6778 | shouldFail: true, |
| 6779 | expectedError: ":UNEXPECTED_RECORD:", |
| 6780 | }) |
| 6781 | |
| 6782 | // Test synchronization between the handshake and ChangeCipherSpec. |
| 6783 | // Partial post-CCS handshake messages before ChangeCipherSpec should be |
| 6784 | // rejected. Test both with and without handshake packing to handle both |
| 6785 | // when the partial post-CCS message is in its own record and when it is |
| 6786 | // attached to the pre-CCS message. |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 6787 | for _, packed := range []bool{false, true} { |
| 6788 | var suffix string |
| 6789 | if packed { |
| 6790 | suffix = "-Packed" |
| 6791 | } |
| 6792 | |
| 6793 | testCases = append(testCases, testCase{ |
| 6794 | name: "FragmentAcrossChangeCipherSpec-Client" + suffix, |
| 6795 | config: Config{ |
| 6796 | MaxVersion: VersionTLS12, |
| 6797 | Bugs: ProtocolBugs{ |
| 6798 | FragmentAcrossChangeCipherSpec: true, |
| 6799 | PackHandshakeFlight: packed, |
| 6800 | }, |
| 6801 | }, |
| 6802 | shouldFail: true, |
| 6803 | expectedError: ":UNEXPECTED_RECORD:", |
| 6804 | }) |
| 6805 | testCases = append(testCases, testCase{ |
| 6806 | name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix, |
| 6807 | config: Config{ |
| 6808 | MaxVersion: VersionTLS12, |
| 6809 | }, |
| 6810 | resumeSession: true, |
| 6811 | resumeConfig: &Config{ |
| 6812 | MaxVersion: VersionTLS12, |
| 6813 | Bugs: ProtocolBugs{ |
| 6814 | FragmentAcrossChangeCipherSpec: true, |
| 6815 | PackHandshakeFlight: packed, |
| 6816 | }, |
| 6817 | }, |
| 6818 | shouldFail: true, |
| 6819 | expectedError: ":UNEXPECTED_RECORD:", |
| 6820 | }) |
| 6821 | testCases = append(testCases, testCase{ |
| 6822 | testType: serverTest, |
| 6823 | name: "FragmentAcrossChangeCipherSpec-Server" + suffix, |
| 6824 | config: Config{ |
| 6825 | MaxVersion: VersionTLS12, |
| 6826 | Bugs: ProtocolBugs{ |
| 6827 | FragmentAcrossChangeCipherSpec: true, |
| 6828 | PackHandshakeFlight: packed, |
| 6829 | }, |
| 6830 | }, |
| 6831 | shouldFail: true, |
| 6832 | expectedError: ":UNEXPECTED_RECORD:", |
| 6833 | }) |
| 6834 | testCases = append(testCases, testCase{ |
| 6835 | testType: serverTest, |
| 6836 | name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix, |
| 6837 | config: Config{ |
| 6838 | MaxVersion: VersionTLS12, |
| 6839 | }, |
| 6840 | resumeSession: true, |
| 6841 | resumeConfig: &Config{ |
| 6842 | MaxVersion: VersionTLS12, |
| 6843 | Bugs: ProtocolBugs{ |
| 6844 | FragmentAcrossChangeCipherSpec: true, |
| 6845 | PackHandshakeFlight: packed, |
| 6846 | }, |
| 6847 | }, |
| 6848 | shouldFail: true, |
| 6849 | expectedError: ":UNEXPECTED_RECORD:", |
| 6850 | }) |
| 6851 | testCases = append(testCases, testCase{ |
| 6852 | testType: serverTest, |
| 6853 | name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix, |
| 6854 | config: Config{ |
| 6855 | MaxVersion: VersionTLS12, |
| 6856 | NextProtos: []string{"bar"}, |
| 6857 | Bugs: ProtocolBugs{ |
| 6858 | FragmentAcrossChangeCipherSpec: true, |
| 6859 | PackHandshakeFlight: packed, |
| 6860 | }, |
| 6861 | }, |
| 6862 | flags: []string{ |
| 6863 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 6864 | }, |
| 6865 | shouldFail: true, |
| 6866 | expectedError: ":UNEXPECTED_RECORD:", |
| 6867 | }) |
| 6868 | } |
| 6869 | |
David Benjamin | 6167281 | 2016-07-14 23:10:43 -0400 | [diff] [blame] | 6870 | // Test that, in DTLS, ChangeCipherSpec is not allowed when there are |
| 6871 | // messages in the handshake queue. Do this by testing the server |
| 6872 | // reading the client Finished, reversing the flight so Finished comes |
| 6873 | // first. |
| 6874 | testCases = append(testCases, testCase{ |
| 6875 | protocol: dtls, |
| 6876 | testType: serverTest, |
| 6877 | name: "SendUnencryptedFinished-DTLS", |
| 6878 | config: Config{ |
| 6879 | MaxVersion: VersionTLS12, |
| 6880 | Bugs: ProtocolBugs{ |
| 6881 | SendUnencryptedFinished: true, |
| 6882 | ReverseHandshakeFragments: true, |
| 6883 | }, |
| 6884 | }, |
| 6885 | shouldFail: true, |
| 6886 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 6887 | }) |
| 6888 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 6889 | // Test synchronization between encryption changes and the handshake in |
| 6890 | // TLS 1.3, where ChangeCipherSpec is implicit. |
| 6891 | testCases = append(testCases, testCase{ |
| 6892 | name: "PartialEncryptedExtensionsWithServerHello", |
| 6893 | config: Config{ |
| 6894 | MaxVersion: VersionTLS13, |
| 6895 | Bugs: ProtocolBugs{ |
| 6896 | PartialEncryptedExtensionsWithServerHello: true, |
| 6897 | }, |
| 6898 | }, |
| 6899 | shouldFail: true, |
| 6900 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 6901 | }) |
| 6902 | testCases = append(testCases, testCase{ |
| 6903 | testType: serverTest, |
| 6904 | name: "PartialClientFinishedWithClientHello", |
| 6905 | config: Config{ |
| 6906 | MaxVersion: VersionTLS13, |
| 6907 | Bugs: ProtocolBugs{ |
| 6908 | PartialClientFinishedWithClientHello: true, |
| 6909 | }, |
| 6910 | }, |
| 6911 | shouldFail: true, |
| 6912 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 6913 | }) |
| 6914 | |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 6915 | // Test that early ChangeCipherSpecs are handled correctly. |
| 6916 | testCases = append(testCases, testCase{ |
| 6917 | testType: serverTest, |
| 6918 | name: "EarlyChangeCipherSpec-server-1", |
| 6919 | config: Config{ |
| 6920 | MaxVersion: VersionTLS12, |
| 6921 | Bugs: ProtocolBugs{ |
| 6922 | EarlyChangeCipherSpec: 1, |
| 6923 | }, |
| 6924 | }, |
| 6925 | shouldFail: true, |
| 6926 | expectedError: ":UNEXPECTED_RECORD:", |
| 6927 | }) |
| 6928 | testCases = append(testCases, testCase{ |
| 6929 | testType: serverTest, |
| 6930 | name: "EarlyChangeCipherSpec-server-2", |
| 6931 | config: Config{ |
| 6932 | MaxVersion: VersionTLS12, |
| 6933 | Bugs: ProtocolBugs{ |
| 6934 | EarlyChangeCipherSpec: 2, |
| 6935 | }, |
| 6936 | }, |
| 6937 | shouldFail: true, |
| 6938 | expectedError: ":UNEXPECTED_RECORD:", |
| 6939 | }) |
| 6940 | testCases = append(testCases, testCase{ |
| 6941 | protocol: dtls, |
| 6942 | name: "StrayChangeCipherSpec", |
| 6943 | config: Config{ |
| 6944 | // TODO(davidben): Once DTLS 1.3 exists, test |
| 6945 | // that stray ChangeCipherSpec messages are |
| 6946 | // rejected. |
| 6947 | MaxVersion: VersionTLS12, |
| 6948 | Bugs: ProtocolBugs{ |
| 6949 | StrayChangeCipherSpec: true, |
| 6950 | }, |
| 6951 | }, |
| 6952 | }) |
| 6953 | |
| 6954 | // Test that the contents of ChangeCipherSpec are checked. |
| 6955 | testCases = append(testCases, testCase{ |
| 6956 | name: "BadChangeCipherSpec-1", |
| 6957 | config: Config{ |
| 6958 | MaxVersion: VersionTLS12, |
| 6959 | Bugs: ProtocolBugs{ |
| 6960 | BadChangeCipherSpec: []byte{2}, |
| 6961 | }, |
| 6962 | }, |
| 6963 | shouldFail: true, |
| 6964 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 6965 | }) |
| 6966 | testCases = append(testCases, testCase{ |
| 6967 | name: "BadChangeCipherSpec-2", |
| 6968 | config: Config{ |
| 6969 | MaxVersion: VersionTLS12, |
| 6970 | Bugs: ProtocolBugs{ |
| 6971 | BadChangeCipherSpec: []byte{1, 1}, |
| 6972 | }, |
| 6973 | }, |
| 6974 | shouldFail: true, |
| 6975 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 6976 | }) |
| 6977 | testCases = append(testCases, testCase{ |
| 6978 | protocol: dtls, |
| 6979 | name: "BadChangeCipherSpec-DTLS-1", |
| 6980 | config: Config{ |
| 6981 | MaxVersion: VersionTLS12, |
| 6982 | Bugs: ProtocolBugs{ |
| 6983 | BadChangeCipherSpec: []byte{2}, |
| 6984 | }, |
| 6985 | }, |
| 6986 | shouldFail: true, |
| 6987 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 6988 | }) |
| 6989 | testCases = append(testCases, testCase{ |
| 6990 | protocol: dtls, |
| 6991 | name: "BadChangeCipherSpec-DTLS-2", |
| 6992 | config: Config{ |
| 6993 | MaxVersion: VersionTLS12, |
| 6994 | Bugs: ProtocolBugs{ |
| 6995 | BadChangeCipherSpec: []byte{1, 1}, |
| 6996 | }, |
| 6997 | }, |
| 6998 | shouldFail: true, |
| 6999 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 7000 | }) |
| 7001 | } |
| 7002 | |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7003 | func addWrongMessageTypeTests() { |
| 7004 | for _, protocol := range []protocol{tls, dtls} { |
| 7005 | var suffix string |
| 7006 | if protocol == dtls { |
| 7007 | suffix = "-DTLS" |
| 7008 | } |
| 7009 | |
| 7010 | testCases = append(testCases, testCase{ |
| 7011 | protocol: protocol, |
| 7012 | testType: serverTest, |
| 7013 | name: "WrongMessageType-ClientHello" + suffix, |
| 7014 | config: Config{ |
| 7015 | MaxVersion: VersionTLS12, |
| 7016 | Bugs: ProtocolBugs{ |
| 7017 | SendWrongMessageType: typeClientHello, |
| 7018 | }, |
| 7019 | }, |
| 7020 | shouldFail: true, |
| 7021 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7022 | expectedLocalError: "remote error: unexpected message", |
| 7023 | }) |
| 7024 | |
| 7025 | if protocol == dtls { |
| 7026 | testCases = append(testCases, testCase{ |
| 7027 | protocol: protocol, |
| 7028 | name: "WrongMessageType-HelloVerifyRequest" + suffix, |
| 7029 | config: Config{ |
| 7030 | MaxVersion: VersionTLS12, |
| 7031 | Bugs: ProtocolBugs{ |
| 7032 | SendWrongMessageType: typeHelloVerifyRequest, |
| 7033 | }, |
| 7034 | }, |
| 7035 | shouldFail: true, |
| 7036 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7037 | expectedLocalError: "remote error: unexpected message", |
| 7038 | }) |
| 7039 | } |
| 7040 | |
| 7041 | testCases = append(testCases, testCase{ |
| 7042 | protocol: protocol, |
| 7043 | name: "WrongMessageType-ServerHello" + suffix, |
| 7044 | config: Config{ |
| 7045 | MaxVersion: VersionTLS12, |
| 7046 | Bugs: ProtocolBugs{ |
| 7047 | SendWrongMessageType: typeServerHello, |
| 7048 | }, |
| 7049 | }, |
| 7050 | shouldFail: true, |
| 7051 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7052 | expectedLocalError: "remote error: unexpected message", |
| 7053 | }) |
| 7054 | |
| 7055 | testCases = append(testCases, testCase{ |
| 7056 | protocol: protocol, |
| 7057 | name: "WrongMessageType-ServerCertificate" + suffix, |
| 7058 | config: Config{ |
| 7059 | MaxVersion: VersionTLS12, |
| 7060 | Bugs: ProtocolBugs{ |
| 7061 | SendWrongMessageType: typeCertificate, |
| 7062 | }, |
| 7063 | }, |
| 7064 | shouldFail: true, |
| 7065 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7066 | expectedLocalError: "remote error: unexpected message", |
| 7067 | }) |
| 7068 | |
| 7069 | testCases = append(testCases, testCase{ |
| 7070 | protocol: protocol, |
| 7071 | name: "WrongMessageType-CertificateStatus" + suffix, |
| 7072 | config: Config{ |
| 7073 | MaxVersion: VersionTLS12, |
| 7074 | Bugs: ProtocolBugs{ |
| 7075 | SendWrongMessageType: typeCertificateStatus, |
| 7076 | }, |
| 7077 | }, |
| 7078 | flags: []string{"-enable-ocsp-stapling"}, |
| 7079 | shouldFail: true, |
| 7080 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7081 | expectedLocalError: "remote error: unexpected message", |
| 7082 | }) |
| 7083 | |
| 7084 | testCases = append(testCases, testCase{ |
| 7085 | protocol: protocol, |
| 7086 | name: "WrongMessageType-ServerKeyExchange" + suffix, |
| 7087 | config: Config{ |
| 7088 | MaxVersion: VersionTLS12, |
| 7089 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7090 | Bugs: ProtocolBugs{ |
| 7091 | SendWrongMessageType: typeServerKeyExchange, |
| 7092 | }, |
| 7093 | }, |
| 7094 | shouldFail: true, |
| 7095 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7096 | expectedLocalError: "remote error: unexpected message", |
| 7097 | }) |
| 7098 | |
| 7099 | testCases = append(testCases, testCase{ |
| 7100 | protocol: protocol, |
| 7101 | name: "WrongMessageType-CertificateRequest" + suffix, |
| 7102 | config: Config{ |
| 7103 | MaxVersion: VersionTLS12, |
| 7104 | ClientAuth: RequireAnyClientCert, |
| 7105 | Bugs: ProtocolBugs{ |
| 7106 | SendWrongMessageType: typeCertificateRequest, |
| 7107 | }, |
| 7108 | }, |
| 7109 | shouldFail: true, |
| 7110 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7111 | expectedLocalError: "remote error: unexpected message", |
| 7112 | }) |
| 7113 | |
| 7114 | testCases = append(testCases, testCase{ |
| 7115 | protocol: protocol, |
| 7116 | name: "WrongMessageType-ServerHelloDone" + suffix, |
| 7117 | config: Config{ |
| 7118 | MaxVersion: VersionTLS12, |
| 7119 | Bugs: ProtocolBugs{ |
| 7120 | SendWrongMessageType: typeServerHelloDone, |
| 7121 | }, |
| 7122 | }, |
| 7123 | shouldFail: true, |
| 7124 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7125 | expectedLocalError: "remote error: unexpected message", |
| 7126 | }) |
| 7127 | |
| 7128 | testCases = append(testCases, testCase{ |
| 7129 | testType: serverTest, |
| 7130 | protocol: protocol, |
| 7131 | name: "WrongMessageType-ClientCertificate" + suffix, |
| 7132 | config: Config{ |
| 7133 | Certificates: []Certificate{rsaCertificate}, |
| 7134 | MaxVersion: VersionTLS12, |
| 7135 | Bugs: ProtocolBugs{ |
| 7136 | SendWrongMessageType: typeCertificate, |
| 7137 | }, |
| 7138 | }, |
| 7139 | flags: []string{"-require-any-client-certificate"}, |
| 7140 | shouldFail: true, |
| 7141 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7142 | expectedLocalError: "remote error: unexpected message", |
| 7143 | }) |
| 7144 | |
| 7145 | testCases = append(testCases, testCase{ |
| 7146 | testType: serverTest, |
| 7147 | protocol: protocol, |
| 7148 | name: "WrongMessageType-CertificateVerify" + suffix, |
| 7149 | config: Config{ |
| 7150 | Certificates: []Certificate{rsaCertificate}, |
| 7151 | MaxVersion: VersionTLS12, |
| 7152 | Bugs: ProtocolBugs{ |
| 7153 | SendWrongMessageType: typeCertificateVerify, |
| 7154 | }, |
| 7155 | }, |
| 7156 | flags: []string{"-require-any-client-certificate"}, |
| 7157 | shouldFail: true, |
| 7158 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7159 | expectedLocalError: "remote error: unexpected message", |
| 7160 | }) |
| 7161 | |
| 7162 | testCases = append(testCases, testCase{ |
| 7163 | testType: serverTest, |
| 7164 | protocol: protocol, |
| 7165 | name: "WrongMessageType-ClientKeyExchange" + suffix, |
| 7166 | config: Config{ |
| 7167 | MaxVersion: VersionTLS12, |
| 7168 | Bugs: ProtocolBugs{ |
| 7169 | SendWrongMessageType: typeClientKeyExchange, |
| 7170 | }, |
| 7171 | }, |
| 7172 | shouldFail: true, |
| 7173 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7174 | expectedLocalError: "remote error: unexpected message", |
| 7175 | }) |
| 7176 | |
| 7177 | if protocol != dtls { |
| 7178 | testCases = append(testCases, testCase{ |
| 7179 | testType: serverTest, |
| 7180 | protocol: protocol, |
| 7181 | name: "WrongMessageType-NextProtocol" + suffix, |
| 7182 | config: Config{ |
| 7183 | MaxVersion: VersionTLS12, |
| 7184 | NextProtos: []string{"bar"}, |
| 7185 | Bugs: ProtocolBugs{ |
| 7186 | SendWrongMessageType: typeNextProtocol, |
| 7187 | }, |
| 7188 | }, |
| 7189 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 7190 | shouldFail: true, |
| 7191 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7192 | expectedLocalError: "remote error: unexpected message", |
| 7193 | }) |
| 7194 | |
| 7195 | testCases = append(testCases, testCase{ |
| 7196 | testType: serverTest, |
| 7197 | protocol: protocol, |
| 7198 | name: "WrongMessageType-ChannelID" + suffix, |
| 7199 | config: Config{ |
| 7200 | MaxVersion: VersionTLS12, |
| 7201 | ChannelID: channelIDKey, |
| 7202 | Bugs: ProtocolBugs{ |
| 7203 | SendWrongMessageType: typeChannelID, |
| 7204 | }, |
| 7205 | }, |
| 7206 | flags: []string{ |
| 7207 | "-expect-channel-id", |
| 7208 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 7209 | }, |
| 7210 | shouldFail: true, |
| 7211 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7212 | expectedLocalError: "remote error: unexpected message", |
| 7213 | }) |
| 7214 | } |
| 7215 | |
| 7216 | testCases = append(testCases, testCase{ |
| 7217 | testType: serverTest, |
| 7218 | protocol: protocol, |
| 7219 | name: "WrongMessageType-ClientFinished" + suffix, |
| 7220 | config: Config{ |
| 7221 | MaxVersion: VersionTLS12, |
| 7222 | Bugs: ProtocolBugs{ |
| 7223 | SendWrongMessageType: typeFinished, |
| 7224 | }, |
| 7225 | }, |
| 7226 | shouldFail: true, |
| 7227 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7228 | expectedLocalError: "remote error: unexpected message", |
| 7229 | }) |
| 7230 | |
| 7231 | testCases = append(testCases, testCase{ |
| 7232 | protocol: protocol, |
| 7233 | name: "WrongMessageType-NewSessionTicket" + suffix, |
| 7234 | config: Config{ |
| 7235 | MaxVersion: VersionTLS12, |
| 7236 | Bugs: ProtocolBugs{ |
| 7237 | SendWrongMessageType: typeNewSessionTicket, |
| 7238 | }, |
| 7239 | }, |
| 7240 | shouldFail: true, |
| 7241 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7242 | expectedLocalError: "remote error: unexpected message", |
| 7243 | }) |
| 7244 | |
| 7245 | testCases = append(testCases, testCase{ |
| 7246 | protocol: protocol, |
| 7247 | name: "WrongMessageType-ServerFinished" + suffix, |
| 7248 | config: Config{ |
| 7249 | MaxVersion: VersionTLS12, |
| 7250 | Bugs: ProtocolBugs{ |
| 7251 | SendWrongMessageType: typeFinished, |
| 7252 | }, |
| 7253 | }, |
| 7254 | shouldFail: true, |
| 7255 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7256 | expectedLocalError: "remote error: unexpected message", |
| 7257 | }) |
| 7258 | |
| 7259 | } |
| 7260 | } |
| 7261 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7262 | func addTLS13WrongMessageTypeTests() { |
| 7263 | testCases = append(testCases, testCase{ |
| 7264 | testType: serverTest, |
| 7265 | name: "WrongMessageType-TLS13-ClientHello", |
| 7266 | config: Config{ |
| 7267 | MaxVersion: VersionTLS13, |
| 7268 | Bugs: ProtocolBugs{ |
| 7269 | SendWrongMessageType: typeClientHello, |
| 7270 | }, |
| 7271 | }, |
| 7272 | shouldFail: true, |
| 7273 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7274 | expectedLocalError: "remote error: unexpected message", |
| 7275 | }) |
| 7276 | |
| 7277 | testCases = append(testCases, testCase{ |
| 7278 | name: "WrongMessageType-TLS13-ServerHello", |
| 7279 | config: Config{ |
| 7280 | MaxVersion: VersionTLS13, |
| 7281 | Bugs: ProtocolBugs{ |
| 7282 | SendWrongMessageType: typeServerHello, |
| 7283 | }, |
| 7284 | }, |
| 7285 | shouldFail: true, |
| 7286 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7287 | // The alert comes in with the wrong encryption. |
| 7288 | expectedLocalError: "local error: bad record MAC", |
| 7289 | }) |
| 7290 | |
| 7291 | testCases = append(testCases, testCase{ |
| 7292 | name: "WrongMessageType-TLS13-EncryptedExtensions", |
| 7293 | config: Config{ |
| 7294 | MaxVersion: VersionTLS13, |
| 7295 | Bugs: ProtocolBugs{ |
| 7296 | SendWrongMessageType: typeEncryptedExtensions, |
| 7297 | }, |
| 7298 | }, |
| 7299 | shouldFail: true, |
| 7300 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7301 | expectedLocalError: "remote error: unexpected message", |
| 7302 | }) |
| 7303 | |
| 7304 | testCases = append(testCases, testCase{ |
| 7305 | name: "WrongMessageType-TLS13-CertificateRequest", |
| 7306 | config: Config{ |
| 7307 | MaxVersion: VersionTLS13, |
| 7308 | ClientAuth: RequireAnyClientCert, |
| 7309 | Bugs: ProtocolBugs{ |
| 7310 | SendWrongMessageType: typeCertificateRequest, |
| 7311 | }, |
| 7312 | }, |
| 7313 | shouldFail: true, |
| 7314 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7315 | expectedLocalError: "remote error: unexpected message", |
| 7316 | }) |
| 7317 | |
| 7318 | testCases = append(testCases, testCase{ |
| 7319 | name: "WrongMessageType-TLS13-ServerCertificate", |
| 7320 | config: Config{ |
| 7321 | MaxVersion: VersionTLS13, |
| 7322 | Bugs: ProtocolBugs{ |
| 7323 | SendWrongMessageType: typeCertificate, |
| 7324 | }, |
| 7325 | }, |
| 7326 | shouldFail: true, |
| 7327 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7328 | expectedLocalError: "remote error: unexpected message", |
| 7329 | }) |
| 7330 | |
| 7331 | testCases = append(testCases, testCase{ |
| 7332 | name: "WrongMessageType-TLS13-ServerCertificateVerify", |
| 7333 | config: Config{ |
| 7334 | MaxVersion: VersionTLS13, |
| 7335 | Bugs: ProtocolBugs{ |
| 7336 | SendWrongMessageType: typeCertificateVerify, |
| 7337 | }, |
| 7338 | }, |
| 7339 | shouldFail: true, |
| 7340 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7341 | expectedLocalError: "remote error: unexpected message", |
| 7342 | }) |
| 7343 | |
| 7344 | testCases = append(testCases, testCase{ |
| 7345 | name: "WrongMessageType-TLS13-ServerFinished", |
| 7346 | config: Config{ |
| 7347 | MaxVersion: VersionTLS13, |
| 7348 | Bugs: ProtocolBugs{ |
| 7349 | SendWrongMessageType: typeFinished, |
| 7350 | }, |
| 7351 | }, |
| 7352 | shouldFail: true, |
| 7353 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7354 | expectedLocalError: "remote error: unexpected message", |
| 7355 | }) |
| 7356 | |
| 7357 | testCases = append(testCases, testCase{ |
| 7358 | testType: serverTest, |
| 7359 | name: "WrongMessageType-TLS13-ClientCertificate", |
| 7360 | config: Config{ |
| 7361 | Certificates: []Certificate{rsaCertificate}, |
| 7362 | MaxVersion: VersionTLS13, |
| 7363 | Bugs: ProtocolBugs{ |
| 7364 | SendWrongMessageType: typeCertificate, |
| 7365 | }, |
| 7366 | }, |
| 7367 | flags: []string{"-require-any-client-certificate"}, |
| 7368 | shouldFail: true, |
| 7369 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7370 | expectedLocalError: "remote error: unexpected message", |
| 7371 | }) |
| 7372 | |
| 7373 | testCases = append(testCases, testCase{ |
| 7374 | testType: serverTest, |
| 7375 | name: "WrongMessageType-TLS13-ClientCertificateVerify", |
| 7376 | config: Config{ |
| 7377 | Certificates: []Certificate{rsaCertificate}, |
| 7378 | MaxVersion: VersionTLS13, |
| 7379 | Bugs: ProtocolBugs{ |
| 7380 | SendWrongMessageType: typeCertificateVerify, |
| 7381 | }, |
| 7382 | }, |
| 7383 | flags: []string{"-require-any-client-certificate"}, |
| 7384 | shouldFail: true, |
| 7385 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7386 | expectedLocalError: "remote error: unexpected message", |
| 7387 | }) |
| 7388 | |
| 7389 | testCases = append(testCases, testCase{ |
| 7390 | testType: serverTest, |
| 7391 | name: "WrongMessageType-TLS13-ClientFinished", |
| 7392 | config: Config{ |
| 7393 | MaxVersion: VersionTLS13, |
| 7394 | Bugs: ProtocolBugs{ |
| 7395 | SendWrongMessageType: typeFinished, |
| 7396 | }, |
| 7397 | }, |
| 7398 | shouldFail: true, |
| 7399 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7400 | expectedLocalError: "remote error: unexpected message", |
| 7401 | }) |
| 7402 | } |
| 7403 | |
| 7404 | func addTLS13HandshakeTests() { |
| 7405 | testCases = append(testCases, testCase{ |
| 7406 | testType: clientTest, |
| 7407 | name: "MissingKeyShare-Client", |
| 7408 | config: Config{ |
| 7409 | MaxVersion: VersionTLS13, |
| 7410 | Bugs: ProtocolBugs{ |
| 7411 | MissingKeyShare: true, |
| 7412 | }, |
| 7413 | }, |
| 7414 | shouldFail: true, |
| 7415 | expectedError: ":MISSING_KEY_SHARE:", |
| 7416 | }) |
| 7417 | |
| 7418 | testCases = append(testCases, testCase{ |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7419 | testType: serverTest, |
| 7420 | name: "MissingKeyShare-Server", |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7421 | config: Config{ |
| 7422 | MaxVersion: VersionTLS13, |
| 7423 | Bugs: ProtocolBugs{ |
| 7424 | MissingKeyShare: true, |
| 7425 | }, |
| 7426 | }, |
| 7427 | shouldFail: true, |
| 7428 | expectedError: ":MISSING_KEY_SHARE:", |
| 7429 | }) |
| 7430 | |
| 7431 | testCases = append(testCases, testCase{ |
| 7432 | testType: clientTest, |
| 7433 | name: "ClientHelloMissingKeyShare", |
| 7434 | config: Config{ |
| 7435 | MaxVersion: VersionTLS13, |
| 7436 | Bugs: ProtocolBugs{ |
| 7437 | MissingKeyShare: true, |
| 7438 | }, |
| 7439 | }, |
| 7440 | shouldFail: true, |
| 7441 | expectedError: ":MISSING_KEY_SHARE:", |
| 7442 | }) |
| 7443 | |
| 7444 | testCases = append(testCases, testCase{ |
| 7445 | testType: clientTest, |
| 7446 | name: "MissingKeyShare", |
| 7447 | config: Config{ |
| 7448 | MaxVersion: VersionTLS13, |
| 7449 | Bugs: ProtocolBugs{ |
| 7450 | MissingKeyShare: true, |
| 7451 | }, |
| 7452 | }, |
| 7453 | shouldFail: true, |
| 7454 | expectedError: ":MISSING_KEY_SHARE:", |
| 7455 | }) |
| 7456 | |
| 7457 | testCases = append(testCases, testCase{ |
| 7458 | testType: serverTest, |
| 7459 | name: "DuplicateKeyShares", |
| 7460 | config: Config{ |
| 7461 | MaxVersion: VersionTLS13, |
| 7462 | Bugs: ProtocolBugs{ |
| 7463 | DuplicateKeyShares: true, |
| 7464 | }, |
| 7465 | }, |
| 7466 | }) |
| 7467 | |
| 7468 | testCases = append(testCases, testCase{ |
| 7469 | testType: clientTest, |
| 7470 | name: "EmptyEncryptedExtensions", |
| 7471 | config: Config{ |
| 7472 | MaxVersion: VersionTLS13, |
| 7473 | Bugs: ProtocolBugs{ |
| 7474 | EmptyEncryptedExtensions: true, |
| 7475 | }, |
| 7476 | }, |
| 7477 | shouldFail: true, |
| 7478 | expectedLocalError: "remote error: error decoding message", |
| 7479 | }) |
| 7480 | |
| 7481 | testCases = append(testCases, testCase{ |
| 7482 | testType: clientTest, |
| 7483 | name: "EncryptedExtensionsWithKeyShare", |
| 7484 | config: Config{ |
| 7485 | MaxVersion: VersionTLS13, |
| 7486 | Bugs: ProtocolBugs{ |
| 7487 | EncryptedExtensionsWithKeyShare: true, |
| 7488 | }, |
| 7489 | }, |
| 7490 | shouldFail: true, |
| 7491 | expectedLocalError: "remote error: unsupported extension", |
| 7492 | }) |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 7493 | |
| 7494 | testCases = append(testCases, testCase{ |
| 7495 | testType: serverTest, |
| 7496 | name: "SendHelloRetryRequest", |
| 7497 | config: Config{ |
| 7498 | MaxVersion: VersionTLS13, |
| 7499 | // Require a HelloRetryRequest for every curve. |
| 7500 | DefaultCurves: []CurveID{}, |
| 7501 | }, |
| 7502 | expectedCurveID: CurveX25519, |
| 7503 | }) |
| 7504 | |
| 7505 | testCases = append(testCases, testCase{ |
| 7506 | testType: serverTest, |
| 7507 | name: "SendHelloRetryRequest-2", |
| 7508 | config: Config{ |
| 7509 | MaxVersion: VersionTLS13, |
| 7510 | DefaultCurves: []CurveID{CurveP384}, |
| 7511 | }, |
| 7512 | // Although the ClientHello did not predict our preferred curve, |
| 7513 | // we always select it whether it is predicted or not. |
| 7514 | expectedCurveID: CurveX25519, |
| 7515 | }) |
| 7516 | |
| 7517 | testCases = append(testCases, testCase{ |
| 7518 | name: "UnknownCurve-HelloRetryRequest", |
| 7519 | config: Config{ |
| 7520 | MaxVersion: VersionTLS13, |
| 7521 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7522 | CurvePreferences: []CurveID{CurveP384}, |
| 7523 | Bugs: ProtocolBugs{ |
| 7524 | SendHelloRetryRequestCurve: bogusCurve, |
| 7525 | }, |
| 7526 | }, |
| 7527 | shouldFail: true, |
| 7528 | expectedError: ":WRONG_CURVE:", |
| 7529 | }) |
| 7530 | |
| 7531 | testCases = append(testCases, testCase{ |
| 7532 | name: "DisabledCurve-HelloRetryRequest", |
| 7533 | config: Config{ |
| 7534 | MaxVersion: VersionTLS13, |
| 7535 | CurvePreferences: []CurveID{CurveP256}, |
| 7536 | Bugs: ProtocolBugs{ |
| 7537 | IgnorePeerCurvePreferences: true, |
| 7538 | }, |
| 7539 | }, |
| 7540 | flags: []string{"-p384-only"}, |
| 7541 | shouldFail: true, |
| 7542 | expectedError: ":WRONG_CURVE:", |
| 7543 | }) |
| 7544 | |
| 7545 | testCases = append(testCases, testCase{ |
| 7546 | name: "UnnecessaryHelloRetryRequest", |
| 7547 | config: Config{ |
| 7548 | MaxVersion: VersionTLS13, |
| 7549 | Bugs: ProtocolBugs{ |
| 7550 | UnnecessaryHelloRetryRequest: true, |
| 7551 | }, |
| 7552 | }, |
| 7553 | shouldFail: true, |
| 7554 | expectedError: ":WRONG_CURVE:", |
| 7555 | }) |
| 7556 | |
| 7557 | testCases = append(testCases, testCase{ |
| 7558 | name: "SecondHelloRetryRequest", |
| 7559 | config: Config{ |
| 7560 | MaxVersion: VersionTLS13, |
| 7561 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7562 | CurvePreferences: []CurveID{CurveP384}, |
| 7563 | Bugs: ProtocolBugs{ |
| 7564 | SecondHelloRetryRequest: true, |
| 7565 | }, |
| 7566 | }, |
| 7567 | shouldFail: true, |
| 7568 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 7569 | }) |
| 7570 | |
| 7571 | testCases = append(testCases, testCase{ |
| 7572 | testType: serverTest, |
| 7573 | name: "SecondClientHelloMissingKeyShare", |
| 7574 | config: Config{ |
| 7575 | MaxVersion: VersionTLS13, |
| 7576 | DefaultCurves: []CurveID{}, |
| 7577 | Bugs: ProtocolBugs{ |
| 7578 | SecondClientHelloMissingKeyShare: true, |
| 7579 | }, |
| 7580 | }, |
| 7581 | shouldFail: true, |
| 7582 | expectedError: ":MISSING_KEY_SHARE:", |
| 7583 | }) |
| 7584 | |
| 7585 | testCases = append(testCases, testCase{ |
| 7586 | testType: serverTest, |
| 7587 | name: "SecondClientHelloWrongCurve", |
| 7588 | config: Config{ |
| 7589 | MaxVersion: VersionTLS13, |
| 7590 | DefaultCurves: []CurveID{}, |
| 7591 | Bugs: ProtocolBugs{ |
| 7592 | MisinterpretHelloRetryRequestCurve: CurveP521, |
| 7593 | }, |
| 7594 | }, |
| 7595 | shouldFail: true, |
| 7596 | expectedError: ":WRONG_CURVE:", |
| 7597 | }) |
| 7598 | |
| 7599 | testCases = append(testCases, testCase{ |
| 7600 | name: "HelloRetryRequestVersionMismatch", |
| 7601 | config: Config{ |
| 7602 | MaxVersion: VersionTLS13, |
| 7603 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7604 | CurvePreferences: []CurveID{CurveP384}, |
| 7605 | Bugs: ProtocolBugs{ |
| 7606 | SendServerHelloVersion: 0x0305, |
| 7607 | }, |
| 7608 | }, |
| 7609 | shouldFail: true, |
| 7610 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 7611 | }) |
| 7612 | |
| 7613 | testCases = append(testCases, testCase{ |
| 7614 | name: "HelloRetryRequestCurveMismatch", |
| 7615 | config: Config{ |
| 7616 | MaxVersion: VersionTLS13, |
| 7617 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7618 | CurvePreferences: []CurveID{CurveP384}, |
| 7619 | Bugs: ProtocolBugs{ |
| 7620 | // Send P-384 (correct) in the HelloRetryRequest. |
| 7621 | SendHelloRetryRequestCurve: CurveP384, |
| 7622 | // But send P-256 in the ServerHello. |
| 7623 | SendCurve: CurveP256, |
| 7624 | }, |
| 7625 | }, |
| 7626 | shouldFail: true, |
| 7627 | expectedError: ":WRONG_CURVE:", |
| 7628 | }) |
| 7629 | |
| 7630 | // Test the server selecting a curve that requires a HelloRetryRequest |
| 7631 | // without sending it. |
| 7632 | testCases = append(testCases, testCase{ |
| 7633 | name: "SkipHelloRetryRequest", |
| 7634 | config: Config{ |
| 7635 | MaxVersion: VersionTLS13, |
| 7636 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 7637 | CurvePreferences: []CurveID{CurveP384}, |
| 7638 | Bugs: ProtocolBugs{ |
| 7639 | SkipHelloRetryRequest: true, |
| 7640 | }, |
| 7641 | }, |
| 7642 | shouldFail: true, |
| 7643 | expectedError: ":WRONG_CURVE:", |
| 7644 | }) |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7645 | } |
| 7646 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7647 | 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] | 7648 | defer wg.Done() |
| 7649 | |
| 7650 | for test := range c { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 7651 | var err error |
| 7652 | |
| 7653 | if *mallocTest < 0 { |
| 7654 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7655 | err = runTest(test, shimPath, -1) |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 7656 | } else { |
| 7657 | for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ { |
| 7658 | statusChan <- statusMsg{test: test, started: true} |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7659 | if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 7660 | if err != nil { |
| 7661 | fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err) |
| 7662 | } |
| 7663 | break |
| 7664 | } |
| 7665 | } |
| 7666 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7667 | statusChan <- statusMsg{test: test, err: err} |
| 7668 | } |
| 7669 | } |
| 7670 | |
| 7671 | type statusMsg struct { |
| 7672 | test *testCase |
| 7673 | started bool |
| 7674 | err error |
| 7675 | } |
| 7676 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7677 | func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7678 | var started, done, failed, lineLen int |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7679 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7680 | testOutput := newTestOutput() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7681 | for msg := range statusChan { |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7682 | if !*pipe { |
| 7683 | // Erase the previous status line. |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 7684 | var erase string |
| 7685 | for i := 0; i < lineLen; i++ { |
| 7686 | erase += "\b \b" |
| 7687 | } |
| 7688 | fmt.Print(erase) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7689 | } |
| 7690 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7691 | if msg.started { |
| 7692 | started++ |
| 7693 | } else { |
| 7694 | done++ |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7695 | |
| 7696 | if msg.err != nil { |
| 7697 | fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err) |
| 7698 | failed++ |
| 7699 | testOutput.addResult(msg.test.name, "FAIL") |
| 7700 | } else { |
| 7701 | if *pipe { |
| 7702 | // Print each test instead of a status line. |
| 7703 | fmt.Printf("PASSED (%s)\n", msg.test.name) |
| 7704 | } |
| 7705 | testOutput.addResult(msg.test.name, "PASS") |
| 7706 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7707 | } |
| 7708 | |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7709 | if !*pipe { |
| 7710 | // Print a new status line. |
| 7711 | line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total) |
| 7712 | lineLen = len(line) |
| 7713 | os.Stdout.WriteString(line) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7714 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7715 | } |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7716 | |
| 7717 | doneChan <- testOutput |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7718 | } |
| 7719 | |
| 7720 | func main() { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7721 | flag.Parse() |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7722 | *resourceDir = path.Clean(*resourceDir) |
David Benjamin | 3386326 | 2016-07-08 17:20:12 -0700 | [diff] [blame] | 7723 | initCertificates() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7724 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7725 | addBasicTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7726 | addCipherSuiteTests() |
| 7727 | addBadECDSASignatureTests() |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7728 | addCBCPaddingTests() |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 7729 | addCBCSplittingTests() |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 7730 | addClientAuthTests() |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 7731 | addDDoSCallbackTests() |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 7732 | addVersionNegotiationTests() |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 7733 | addMinimumVersionTests() |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 7734 | addExtensionTests() |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 7735 | addResumptionVersionTests() |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 7736 | addExtendedMasterSecretTests() |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 7737 | addRenegotiationTests() |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 7738 | addDTLSReplayTests() |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 7739 | addSignatureAlgorithmTests() |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 7740 | addDTLSRetransmitTests() |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 7741 | addExportKeyingMaterialTests() |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 7742 | addTLSUniqueTests() |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 7743 | addCustomExtensionTests() |
David Benjamin | b36a395 | 2015-12-01 18:53:13 -0500 | [diff] [blame] | 7744 | addRSAClientKeyExchangeTests() |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 7745 | addCurveTests() |
Matt Braithwaite | 54217e4 | 2016-06-13 13:03:47 -0700 | [diff] [blame] | 7746 | addCECPQ1Tests() |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 7747 | addKeyExchangeInfoTests() |
David Benjamin | c9ae27c | 2016-06-24 22:56:37 -0400 | [diff] [blame] | 7748 | addTLS13RecordTests() |
David Benjamin | 582ba04 | 2016-07-07 12:33:25 -0700 | [diff] [blame] | 7749 | addAllStateMachineCoverageTests() |
David Benjamin | 82261be | 2016-07-07 14:32:50 -0700 | [diff] [blame] | 7750 | addChangeCipherSpecTests() |
David Benjamin | 0b8d5da | 2016-07-15 00:39:56 -0400 | [diff] [blame] | 7751 | addWrongMessageTypeTests() |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 7752 | addTLS13WrongMessageTypeTests() |
| 7753 | addTLS13HandshakeTests() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7754 | |
| 7755 | var wg sync.WaitGroup |
| 7756 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7757 | statusChan := make(chan statusMsg, *numWorkers) |
| 7758 | testChan := make(chan *testCase, *numWorkers) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7759 | doneChan := make(chan *testOutput) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7760 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 7761 | go statusPrinter(doneChan, statusChan, len(testCases)) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7762 | |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7763 | for i := 0; i < *numWorkers; i++ { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7764 | wg.Add(1) |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7765 | go worker(statusChan, testChan, *shimPath, &wg) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7766 | } |
| 7767 | |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 7768 | var foundTest bool |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 7769 | for i := range testCases { |
Adam Langley | 7c803a6 | 2015-06-15 15:35:05 -0700 | [diff] [blame] | 7770 | if len(*testToRun) == 0 || *testToRun == testCases[i].name { |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 7771 | foundTest = true |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 7772 | testChan <- &testCases[i] |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7773 | } |
| 7774 | } |
David Benjamin | 270f0a7 | 2016-03-17 14:41:36 -0400 | [diff] [blame] | 7775 | if !foundTest { |
| 7776 | fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun) |
| 7777 | os.Exit(1) |
| 7778 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7779 | |
| 7780 | close(testChan) |
| 7781 | wg.Wait() |
| 7782 | close(statusChan) |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7783 | testOutput := <-doneChan |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7784 | |
| 7785 | fmt.Printf("\n") |
David Benjamin | 5f237bc | 2015-02-11 17:14:15 -0500 | [diff] [blame] | 7786 | |
| 7787 | if *jsonOutput != "" { |
| 7788 | if err := testOutput.writeTo(*jsonOutput); err != nil { |
| 7789 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 7790 | } |
| 7791 | } |
David Benjamin | 2ab7a86 | 2015-04-04 17:02:18 -0400 | [diff] [blame] | 7792 | |
| 7793 | if !testOutput.allPassed { |
| 7794 | os.Exit(1) |
| 7795 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 7796 | } |