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