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