Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 5 | "crypto/ecdsa" |
| 6 | "crypto/elliptic" |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 7 | "crypto/x509" |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 8 | "encoding/base64" |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 9 | "encoding/pem" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 10 | "flag" |
| 11 | "fmt" |
| 12 | "io" |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 13 | "io/ioutil" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 14 | "net" |
| 15 | "os" |
| 16 | "os/exec" |
David Benjamin | 884fdf1 | 2014-08-02 15:28:23 -0400 | [diff] [blame] | 17 | "path" |
David Benjamin | 2bc8e6f | 2014-08-02 15:22:37 -0400 | [diff] [blame] | 18 | "runtime" |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 19 | "strconv" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 20 | "strings" |
| 21 | "sync" |
| 22 | "syscall" |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 23 | "time" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 24 | ) |
| 25 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 26 | var ( |
| 27 | useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind") |
| 28 | useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb") |
| 29 | flagDebug *bool = flag.Bool("debug", false, "Hexdump the contents of the connection") |
| 30 | mallocTest *int64 = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.") |
| 31 | mallocTestDebug *bool = 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.") |
| 32 | ) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 33 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 34 | const ( |
| 35 | rsaCertificateFile = "cert.pem" |
| 36 | ecdsaCertificateFile = "ecdsa_cert.pem" |
| 37 | ) |
| 38 | |
| 39 | const ( |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 40 | rsaKeyFile = "key.pem" |
| 41 | ecdsaKeyFile = "ecdsa_key.pem" |
| 42 | channelIDKeyFile = "channel_id_key.pem" |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 43 | ) |
| 44 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 45 | var rsaCertificate, ecdsaCertificate Certificate |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 46 | var channelIDKey *ecdsa.PrivateKey |
| 47 | var channelIDBytes []byte |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 48 | |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 49 | var testOCSPResponse = []byte{1, 2, 3, 4} |
| 50 | var testSCTList = []byte{5, 6, 7, 8} |
| 51 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 52 | func initCertificates() { |
| 53 | var err error |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 54 | rsaCertificate, err = LoadX509KeyPair(rsaCertificateFile, rsaKeyFile) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 55 | if err != nil { |
| 56 | panic(err) |
| 57 | } |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 58 | rsaCertificate.OCSPStaple = testOCSPResponse |
| 59 | rsaCertificate.SignedCertificateTimestampList = testSCTList |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 60 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 61 | ecdsaCertificate, err = LoadX509KeyPair(ecdsaCertificateFile, ecdsaKeyFile) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 62 | if err != nil { |
| 63 | panic(err) |
| 64 | } |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 65 | ecdsaCertificate.OCSPStaple = testOCSPResponse |
| 66 | ecdsaCertificate.SignedCertificateTimestampList = testSCTList |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 67 | |
| 68 | channelIDPEMBlock, err := ioutil.ReadFile(channelIDKeyFile) |
| 69 | if err != nil { |
| 70 | panic(err) |
| 71 | } |
| 72 | channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock) |
| 73 | if channelIDDERBlock.Type != "EC PRIVATE KEY" { |
| 74 | panic("bad key type") |
| 75 | } |
| 76 | channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes) |
| 77 | if err != nil { |
| 78 | panic(err) |
| 79 | } |
| 80 | if channelIDKey.Curve != elliptic.P256() { |
| 81 | panic("bad curve") |
| 82 | } |
| 83 | |
| 84 | channelIDBytes = make([]byte, 64) |
| 85 | writeIntPadded(channelIDBytes[:32], channelIDKey.X) |
| 86 | writeIntPadded(channelIDBytes[32:], channelIDKey.Y) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | var certificateOnce sync.Once |
| 90 | |
| 91 | func getRSACertificate() Certificate { |
| 92 | certificateOnce.Do(initCertificates) |
| 93 | return rsaCertificate |
| 94 | } |
| 95 | |
| 96 | func getECDSACertificate() Certificate { |
| 97 | certificateOnce.Do(initCertificates) |
| 98 | return ecdsaCertificate |
| 99 | } |
| 100 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 101 | type testType int |
| 102 | |
| 103 | const ( |
| 104 | clientTest testType = iota |
| 105 | serverTest |
| 106 | ) |
| 107 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 108 | type protocol int |
| 109 | |
| 110 | const ( |
| 111 | tls protocol = iota |
| 112 | dtls |
| 113 | ) |
| 114 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 115 | const ( |
| 116 | alpn = 1 |
| 117 | npn = 2 |
| 118 | ) |
| 119 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 120 | type testCase struct { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 121 | testType testType |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 122 | protocol protocol |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 123 | name string |
| 124 | config Config |
| 125 | shouldFail bool |
| 126 | expectedError string |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 127 | // expectedLocalError, if not empty, contains a substring that must be |
| 128 | // found in the local error. |
| 129 | expectedLocalError string |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 130 | // expectedVersion, if non-zero, specifies the TLS version that must be |
| 131 | // negotiated. |
| 132 | expectedVersion uint16 |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 133 | // expectedResumeVersion, if non-zero, specifies the TLS version that |
| 134 | // must be negotiated on resumption. If zero, expectedVersion is used. |
| 135 | expectedResumeVersion uint16 |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 136 | // expectChannelID controls whether the connection should have |
| 137 | // negotiated a Channel ID with channelIDKey. |
| 138 | expectChannelID bool |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 139 | // expectedNextProto controls whether the connection should |
| 140 | // negotiate a next protocol via NPN or ALPN. |
| 141 | expectedNextProto string |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 142 | // expectedNextProtoType, if non-zero, is the expected next |
| 143 | // protocol negotiation mechanism. |
| 144 | expectedNextProtoType int |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 145 | // expectedSRTPProtectionProfile is the DTLS-SRTP profile that |
| 146 | // should be negotiated. If zero, none should be negotiated. |
| 147 | expectedSRTPProtectionProfile uint16 |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 148 | // messageLen is the length, in bytes, of the test message that will be |
| 149 | // sent. |
| 150 | messageLen int |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 151 | // certFile is the path to the certificate to use for the server. |
| 152 | certFile string |
| 153 | // keyFile is the path to the private key to use for the server. |
| 154 | keyFile string |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 155 | // resumeSession controls whether a second connection should be tested |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 156 | // which attempts to resume the first session. |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 157 | resumeSession bool |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 158 | // resumeConfig, if not nil, points to a Config to be used on |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 159 | // resumption. Unless newSessionsOnResume is set, |
| 160 | // SessionTicketKey, ServerSessionCache, and |
| 161 | // ClientSessionCache are copied from the initial connection's |
| 162 | // config. If nil, the initial connection's config is used. |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 163 | resumeConfig *Config |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 164 | // newSessionsOnResume, if true, will cause resumeConfig to |
| 165 | // use a different session resumption context. |
| 166 | newSessionsOnResume bool |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 167 | // sendPrefix sends a prefix on the socket before actually performing a |
| 168 | // handshake. |
| 169 | sendPrefix string |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 170 | // shimWritesFirst controls whether the shim sends an initial "hello" |
| 171 | // message before doing a roundtrip with the runner. |
| 172 | shimWritesFirst bool |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 173 | // renegotiate indicates the the connection should be renegotiated |
| 174 | // during the exchange. |
| 175 | renegotiate bool |
| 176 | // renegotiateCiphers is a list of ciphersuite ids that will be |
| 177 | // switched in just before renegotiation. |
| 178 | renegotiateCiphers []uint16 |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 179 | // replayWrites, if true, configures the underlying transport |
| 180 | // to replay every write it makes in DTLS tests. |
| 181 | replayWrites bool |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 182 | // damageFirstWrite, if true, configures the underlying transport to |
| 183 | // damage the final byte of the first application data write. |
| 184 | damageFirstWrite bool |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 185 | // flags, if not empty, contains a list of command-line flags that will |
| 186 | // be passed to the shim program. |
| 187 | flags []string |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 188 | } |
| 189 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 190 | var testCases = []testCase{ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 191 | { |
| 192 | name: "BadRSASignature", |
| 193 | config: Config{ |
| 194 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 195 | Bugs: ProtocolBugs{ |
| 196 | InvalidSKXSignature: true, |
| 197 | }, |
| 198 | }, |
| 199 | shouldFail: true, |
| 200 | expectedError: ":BAD_SIGNATURE:", |
| 201 | }, |
| 202 | { |
| 203 | name: "BadECDSASignature", |
| 204 | config: Config{ |
| 205 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 206 | Bugs: ProtocolBugs{ |
| 207 | InvalidSKXSignature: true, |
| 208 | }, |
| 209 | Certificates: []Certificate{getECDSACertificate()}, |
| 210 | }, |
| 211 | shouldFail: true, |
| 212 | expectedError: ":BAD_SIGNATURE:", |
| 213 | }, |
| 214 | { |
| 215 | name: "BadECDSACurve", |
| 216 | config: Config{ |
| 217 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 218 | Bugs: ProtocolBugs{ |
| 219 | InvalidSKXCurve: true, |
| 220 | }, |
| 221 | Certificates: []Certificate{getECDSACertificate()}, |
| 222 | }, |
| 223 | shouldFail: true, |
| 224 | expectedError: ":WRONG_CURVE:", |
| 225 | }, |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 226 | { |
David Benjamin | a8e3e0e | 2014-08-06 22:11:10 -0400 | [diff] [blame] | 227 | testType: serverTest, |
| 228 | name: "BadRSAVersion", |
| 229 | config: Config{ |
| 230 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 231 | Bugs: ProtocolBugs{ |
| 232 | RsaClientKeyExchangeVersion: VersionTLS11, |
| 233 | }, |
| 234 | }, |
| 235 | shouldFail: true, |
| 236 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 237 | }, |
| 238 | { |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 239 | name: "NoFallbackSCSV", |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 240 | config: Config{ |
| 241 | Bugs: ProtocolBugs{ |
| 242 | FailIfNotFallbackSCSV: true, |
| 243 | }, |
| 244 | }, |
| 245 | shouldFail: true, |
| 246 | expectedLocalError: "no fallback SCSV found", |
| 247 | }, |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 248 | { |
David Benjamin | 2a0c496 | 2014-08-22 23:46:35 -0400 | [diff] [blame] | 249 | name: "SendFallbackSCSV", |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 250 | config: Config{ |
| 251 | Bugs: ProtocolBugs{ |
| 252 | FailIfNotFallbackSCSV: true, |
| 253 | }, |
| 254 | }, |
| 255 | flags: []string{"-fallback-scsv"}, |
| 256 | }, |
David Benjamin | 197b3ab | 2014-07-02 18:37:33 -0400 | [diff] [blame] | 257 | { |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 258 | name: "ClientCertificateTypes", |
| 259 | config: Config{ |
| 260 | ClientAuth: RequestClientCert, |
| 261 | ClientCertificateTypes: []byte{ |
| 262 | CertTypeDSSSign, |
| 263 | CertTypeRSASign, |
| 264 | CertTypeECDSASign, |
| 265 | }, |
| 266 | }, |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 267 | flags: []string{ |
| 268 | "-expect-certificate-types", |
| 269 | base64.StdEncoding.EncodeToString([]byte{ |
| 270 | CertTypeDSSSign, |
| 271 | CertTypeRSASign, |
| 272 | CertTypeECDSASign, |
| 273 | }), |
| 274 | }, |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 275 | }, |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 276 | { |
| 277 | name: "NoClientCertificate", |
| 278 | config: Config{ |
| 279 | ClientAuth: RequireAnyClientCert, |
| 280 | }, |
| 281 | shouldFail: true, |
| 282 | expectedLocalError: "client didn't provide a certificate", |
| 283 | }, |
David Benjamin | 1c375dd | 2014-07-12 00:48:23 -0400 | [diff] [blame] | 284 | { |
| 285 | name: "UnauthenticatedECDH", |
| 286 | config: Config{ |
| 287 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 288 | Bugs: ProtocolBugs{ |
| 289 | UnauthenticatedECDH: true, |
| 290 | }, |
| 291 | }, |
| 292 | shouldFail: true, |
David Benjamin | e8f3d66 | 2014-07-12 01:10:19 -0400 | [diff] [blame] | 293 | expectedError: ":UNEXPECTED_MESSAGE:", |
David Benjamin | 1c375dd | 2014-07-12 00:48:23 -0400 | [diff] [blame] | 294 | }, |
David Benjamin | 9c651c9 | 2014-07-12 13:27:45 -0400 | [diff] [blame] | 295 | { |
| 296 | name: "SkipServerKeyExchange", |
| 297 | config: Config{ |
| 298 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 299 | Bugs: ProtocolBugs{ |
| 300 | SkipServerKeyExchange: true, |
| 301 | }, |
| 302 | }, |
| 303 | shouldFail: true, |
| 304 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 305 | }, |
David Benjamin | 1f5f62b | 2014-07-12 16:18:02 -0400 | [diff] [blame] | 306 | { |
David Benjamin | a0e5223 | 2014-07-19 17:39:58 -0400 | [diff] [blame] | 307 | name: "SkipChangeCipherSpec-Client", |
| 308 | config: Config{ |
| 309 | Bugs: ProtocolBugs{ |
| 310 | SkipChangeCipherSpec: true, |
| 311 | }, |
| 312 | }, |
| 313 | shouldFail: true, |
David Benjamin | 86271ee | 2014-07-21 16:14:03 -0400 | [diff] [blame] | 314 | expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:", |
David Benjamin | a0e5223 | 2014-07-19 17:39:58 -0400 | [diff] [blame] | 315 | }, |
| 316 | { |
| 317 | testType: serverTest, |
| 318 | name: "SkipChangeCipherSpec-Server", |
| 319 | config: Config{ |
| 320 | Bugs: ProtocolBugs{ |
| 321 | SkipChangeCipherSpec: true, |
| 322 | }, |
| 323 | }, |
| 324 | shouldFail: true, |
David Benjamin | 86271ee | 2014-07-21 16:14:03 -0400 | [diff] [blame] | 325 | expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:", |
David Benjamin | a0e5223 | 2014-07-19 17:39:58 -0400 | [diff] [blame] | 326 | }, |
David Benjamin | 42be645 | 2014-07-21 14:50:23 -0400 | [diff] [blame] | 327 | { |
| 328 | testType: serverTest, |
| 329 | name: "SkipChangeCipherSpec-Server-NPN", |
| 330 | config: Config{ |
| 331 | NextProtos: []string{"bar"}, |
| 332 | Bugs: ProtocolBugs{ |
| 333 | SkipChangeCipherSpec: true, |
| 334 | }, |
| 335 | }, |
| 336 | flags: []string{ |
| 337 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 338 | }, |
| 339 | shouldFail: true, |
David Benjamin | 86271ee | 2014-07-21 16:14:03 -0400 | [diff] [blame] | 340 | expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:", |
| 341 | }, |
| 342 | { |
| 343 | name: "FragmentAcrossChangeCipherSpec-Client", |
| 344 | config: Config{ |
| 345 | Bugs: ProtocolBugs{ |
| 346 | FragmentAcrossChangeCipherSpec: true, |
| 347 | }, |
| 348 | }, |
| 349 | shouldFail: true, |
| 350 | expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:", |
| 351 | }, |
| 352 | { |
| 353 | testType: serverTest, |
| 354 | name: "FragmentAcrossChangeCipherSpec-Server", |
| 355 | config: Config{ |
| 356 | Bugs: ProtocolBugs{ |
| 357 | FragmentAcrossChangeCipherSpec: true, |
| 358 | }, |
| 359 | }, |
| 360 | shouldFail: true, |
| 361 | expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:", |
| 362 | }, |
| 363 | { |
| 364 | testType: serverTest, |
| 365 | name: "FragmentAcrossChangeCipherSpec-Server-NPN", |
| 366 | config: Config{ |
| 367 | NextProtos: []string{"bar"}, |
| 368 | Bugs: ProtocolBugs{ |
| 369 | FragmentAcrossChangeCipherSpec: true, |
| 370 | }, |
| 371 | }, |
| 372 | flags: []string{ |
| 373 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 374 | }, |
| 375 | shouldFail: true, |
| 376 | expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:", |
David Benjamin | 42be645 | 2014-07-21 14:50:23 -0400 | [diff] [blame] | 377 | }, |
David Benjamin | f3ec83d | 2014-07-21 22:42:34 -0400 | [diff] [blame] | 378 | { |
| 379 | testType: serverTest, |
Alex Chernyakhovsky | 4cd8c43 | 2014-11-01 19:39:08 -0400 | [diff] [blame] | 380 | name: "FragmentAlert", |
| 381 | config: Config{ |
| 382 | Bugs: ProtocolBugs{ |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 383 | FragmentAlert: true, |
Alex Chernyakhovsky | 4cd8c43 | 2014-11-01 19:39:08 -0400 | [diff] [blame] | 384 | SendSpuriousAlert: true, |
| 385 | }, |
| 386 | }, |
| 387 | shouldFail: true, |
| 388 | expectedError: ":BAD_ALERT:", |
| 389 | }, |
| 390 | { |
| 391 | testType: serverTest, |
David Benjamin | f3ec83d | 2014-07-21 22:42:34 -0400 | [diff] [blame] | 392 | name: "EarlyChangeCipherSpec-server-1", |
| 393 | config: Config{ |
| 394 | Bugs: ProtocolBugs{ |
| 395 | EarlyChangeCipherSpec: 1, |
| 396 | }, |
| 397 | }, |
| 398 | shouldFail: true, |
| 399 | expectedError: ":CCS_RECEIVED_EARLY:", |
| 400 | }, |
| 401 | { |
| 402 | testType: serverTest, |
| 403 | name: "EarlyChangeCipherSpec-server-2", |
| 404 | config: Config{ |
| 405 | Bugs: ProtocolBugs{ |
| 406 | EarlyChangeCipherSpec: 2, |
| 407 | }, |
| 408 | }, |
| 409 | shouldFail: true, |
| 410 | expectedError: ":CCS_RECEIVED_EARLY:", |
| 411 | }, |
David Benjamin | d23f412 | 2014-07-23 15:09:48 -0400 | [diff] [blame] | 412 | { |
David Benjamin | d23f412 | 2014-07-23 15:09:48 -0400 | [diff] [blame] | 413 | name: "SkipNewSessionTicket", |
| 414 | config: Config{ |
| 415 | Bugs: ProtocolBugs{ |
| 416 | SkipNewSessionTicket: true, |
| 417 | }, |
| 418 | }, |
| 419 | shouldFail: true, |
| 420 | expectedError: ":CCS_RECEIVED_EARLY:", |
| 421 | }, |
David Benjamin | 7e3305e | 2014-07-28 14:52:32 -0400 | [diff] [blame] | 422 | { |
David Benjamin | d86c767 | 2014-08-02 04:07:12 -0400 | [diff] [blame] | 423 | testType: serverTest, |
David Benjamin | bef270a | 2014-08-02 04:22:02 -0400 | [diff] [blame] | 424 | name: "FallbackSCSV", |
| 425 | config: Config{ |
| 426 | MaxVersion: VersionTLS11, |
| 427 | Bugs: ProtocolBugs{ |
| 428 | SendFallbackSCSV: true, |
| 429 | }, |
| 430 | }, |
| 431 | shouldFail: true, |
| 432 | expectedError: ":INAPPROPRIATE_FALLBACK:", |
| 433 | }, |
| 434 | { |
| 435 | testType: serverTest, |
| 436 | name: "FallbackSCSV-VersionMatch", |
| 437 | config: Config{ |
| 438 | Bugs: ProtocolBugs{ |
| 439 | SendFallbackSCSV: true, |
| 440 | }, |
| 441 | }, |
| 442 | }, |
David Benjamin | 9821454 | 2014-08-07 18:02:39 -0400 | [diff] [blame] | 443 | { |
| 444 | testType: serverTest, |
| 445 | name: "FragmentedClientVersion", |
| 446 | config: Config{ |
| 447 | Bugs: ProtocolBugs{ |
| 448 | MaxHandshakeRecordLength: 1, |
| 449 | FragmentClientVersion: true, |
| 450 | }, |
| 451 | }, |
David Benjamin | 82c9e90 | 2014-12-12 15:55:27 -0500 | [diff] [blame] | 452 | expectedVersion: VersionTLS12, |
David Benjamin | 9821454 | 2014-08-07 18:02:39 -0400 | [diff] [blame] | 453 | }, |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 454 | { |
| 455 | testType: serverTest, |
| 456 | name: "MinorVersionTolerance", |
| 457 | config: Config{ |
| 458 | Bugs: ProtocolBugs{ |
| 459 | SendClientVersion: 0x03ff, |
| 460 | }, |
| 461 | }, |
| 462 | expectedVersion: VersionTLS12, |
| 463 | }, |
| 464 | { |
| 465 | testType: serverTest, |
| 466 | name: "MajorVersionTolerance", |
| 467 | config: Config{ |
| 468 | Bugs: ProtocolBugs{ |
| 469 | SendClientVersion: 0x0400, |
| 470 | }, |
| 471 | }, |
| 472 | expectedVersion: VersionTLS12, |
| 473 | }, |
| 474 | { |
| 475 | testType: serverTest, |
| 476 | name: "VersionTooLow", |
| 477 | config: Config{ |
| 478 | Bugs: ProtocolBugs{ |
| 479 | SendClientVersion: 0x0200, |
| 480 | }, |
| 481 | }, |
| 482 | shouldFail: true, |
| 483 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 484 | }, |
| 485 | { |
| 486 | testType: serverTest, |
| 487 | name: "HttpGET", |
| 488 | sendPrefix: "GET / HTTP/1.0\n", |
| 489 | shouldFail: true, |
| 490 | expectedError: ":HTTP_REQUEST:", |
| 491 | }, |
| 492 | { |
| 493 | testType: serverTest, |
| 494 | name: "HttpPOST", |
| 495 | sendPrefix: "POST / HTTP/1.0\n", |
| 496 | shouldFail: true, |
| 497 | expectedError: ":HTTP_REQUEST:", |
| 498 | }, |
| 499 | { |
| 500 | testType: serverTest, |
| 501 | name: "HttpHEAD", |
| 502 | sendPrefix: "HEAD / HTTP/1.0\n", |
| 503 | shouldFail: true, |
| 504 | expectedError: ":HTTP_REQUEST:", |
| 505 | }, |
| 506 | { |
| 507 | testType: serverTest, |
| 508 | name: "HttpPUT", |
| 509 | sendPrefix: "PUT / HTTP/1.0\n", |
| 510 | shouldFail: true, |
| 511 | expectedError: ":HTTP_REQUEST:", |
| 512 | }, |
| 513 | { |
| 514 | testType: serverTest, |
| 515 | name: "HttpCONNECT", |
| 516 | sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n", |
| 517 | shouldFail: true, |
| 518 | expectedError: ":HTTPS_PROXY_REQUEST:", |
| 519 | }, |
David Benjamin | 39ebf53 | 2014-08-31 02:23:49 -0400 | [diff] [blame] | 520 | { |
David Benjamin | f080ecd | 2014-12-11 18:48:59 -0500 | [diff] [blame] | 521 | testType: serverTest, |
| 522 | name: "Garbage", |
| 523 | sendPrefix: "blah", |
| 524 | shouldFail: true, |
| 525 | expectedError: ":UNKNOWN_PROTOCOL:", |
| 526 | }, |
| 527 | { |
David Benjamin | 39ebf53 | 2014-08-31 02:23:49 -0400 | [diff] [blame] | 528 | name: "SkipCipherVersionCheck", |
| 529 | config: Config{ |
| 530 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 531 | MaxVersion: VersionTLS11, |
| 532 | Bugs: ProtocolBugs{ |
| 533 | SkipCipherVersionCheck: true, |
| 534 | }, |
| 535 | }, |
| 536 | shouldFail: true, |
| 537 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 538 | }, |
David Benjamin | 9114fae | 2014-11-08 11:41:14 -0500 | [diff] [blame] | 539 | { |
| 540 | name: "RSAServerKeyExchange", |
| 541 | config: Config{ |
| 542 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 543 | Bugs: ProtocolBugs{ |
| 544 | RSAServerKeyExchange: true, |
| 545 | }, |
| 546 | }, |
| 547 | shouldFail: true, |
| 548 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 549 | }, |
David Benjamin | 128dbc3 | 2014-12-01 01:27:42 -0500 | [diff] [blame] | 550 | { |
| 551 | name: "DisableEverything", |
| 552 | flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"}, |
| 553 | shouldFail: true, |
| 554 | expectedError: ":WRONG_SSL_VERSION:", |
| 555 | }, |
| 556 | { |
| 557 | protocol: dtls, |
| 558 | name: "DisableEverything-DTLS", |
| 559 | flags: []string{"-no-tls12", "-no-tls1"}, |
| 560 | shouldFail: true, |
| 561 | expectedError: ":WRONG_SSL_VERSION:", |
| 562 | }, |
David Benjamin | 780d6dd | 2015-01-06 12:03:19 -0500 | [diff] [blame] | 563 | { |
| 564 | name: "NoSharedCipher", |
| 565 | config: Config{ |
| 566 | CipherSuites: []uint16{}, |
| 567 | }, |
| 568 | shouldFail: true, |
| 569 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 570 | }, |
David Benjamin | 13be1de | 2015-01-11 16:29:36 -0500 | [diff] [blame] | 571 | { |
| 572 | protocol: dtls, |
| 573 | testType: serverTest, |
| 574 | name: "MTU", |
| 575 | config: Config{ |
| 576 | Bugs: ProtocolBugs{ |
| 577 | MaxPacketLength: 256, |
| 578 | }, |
| 579 | }, |
| 580 | flags: []string{"-mtu", "256"}, |
| 581 | }, |
| 582 | { |
| 583 | protocol: dtls, |
| 584 | testType: serverTest, |
| 585 | name: "MTUExceeded", |
| 586 | config: Config{ |
| 587 | Bugs: ProtocolBugs{ |
| 588 | MaxPacketLength: 255, |
| 589 | }, |
| 590 | }, |
| 591 | flags: []string{"-mtu", "256"}, |
| 592 | shouldFail: true, |
| 593 | expectedLocalError: "dtls: exceeded maximum packet length", |
| 594 | }, |
David Benjamin | 6095de8 | 2014-12-27 01:50:38 -0500 | [diff] [blame] | 595 | { |
| 596 | name: "CertMismatchRSA", |
| 597 | config: Config{ |
| 598 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 599 | Certificates: []Certificate{getECDSACertificate()}, |
| 600 | Bugs: ProtocolBugs{ |
| 601 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 602 | }, |
| 603 | }, |
| 604 | shouldFail: true, |
| 605 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 606 | }, |
| 607 | { |
| 608 | name: "CertMismatchECDSA", |
| 609 | config: Config{ |
| 610 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 611 | Certificates: []Certificate{getRSACertificate()}, |
| 612 | Bugs: ProtocolBugs{ |
| 613 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 614 | }, |
| 615 | }, |
| 616 | shouldFail: true, |
| 617 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 618 | }, |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 619 | { |
| 620 | name: "TLSFatalBadPackets", |
| 621 | damageFirstWrite: true, |
| 622 | shouldFail: true, |
| 623 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 624 | }, |
| 625 | { |
| 626 | protocol: dtls, |
| 627 | name: "DTLSIgnoreBadPackets", |
| 628 | damageFirstWrite: true, |
| 629 | }, |
| 630 | { |
| 631 | protocol: dtls, |
| 632 | name: "DTLSIgnoreBadPackets-Async", |
| 633 | damageFirstWrite: true, |
| 634 | flags: []string{"-async"}, |
| 635 | }, |
David Benjamin | 4189bd9 | 2015-01-25 23:52:39 -0500 | [diff] [blame] | 636 | { |
| 637 | name: "AppDataAfterChangeCipherSpec", |
| 638 | config: Config{ |
| 639 | Bugs: ProtocolBugs{ |
| 640 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 641 | }, |
| 642 | }, |
| 643 | shouldFail: true, |
| 644 | expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:", |
| 645 | }, |
| 646 | { |
| 647 | protocol: dtls, |
| 648 | name: "AppDataAfterChangeCipherSpec-DTLS", |
| 649 | config: Config{ |
| 650 | Bugs: ProtocolBugs{ |
| 651 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 652 | }, |
| 653 | }, |
| 654 | }, |
David Benjamin | b3774b9 | 2015-01-31 17:16:01 -0500 | [diff] [blame^] | 655 | { |
| 656 | protocol: dtls, |
| 657 | name: "ReorderHandshakeFragments-Small-DTLS", |
| 658 | config: Config{ |
| 659 | Bugs: ProtocolBugs{ |
| 660 | ReorderHandshakeFragments: true, |
| 661 | // Small enough that every handshake message is |
| 662 | // fragmented. |
| 663 | MaxHandshakeRecordLength: 2, |
| 664 | }, |
| 665 | }, |
| 666 | }, |
| 667 | { |
| 668 | protocol: dtls, |
| 669 | name: "ReorderHandshakeFragments-Large-DTLS", |
| 670 | config: Config{ |
| 671 | Bugs: ProtocolBugs{ |
| 672 | ReorderHandshakeFragments: true, |
| 673 | // Large enough that no handshake message is |
| 674 | // fragmented. |
| 675 | // |
| 676 | // TODO(davidben): Also test interaction of |
| 677 | // complete handshake messages with |
| 678 | // fragments. The current logic is full of bugs |
| 679 | // here, so the reassembly logic needs a rewrite |
| 680 | // before those tests will pass. |
| 681 | MaxHandshakeRecordLength: 2048, |
| 682 | }, |
| 683 | }, |
| 684 | }, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 685 | } |
| 686 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 687 | func doExchange(test *testCase, config *Config, conn net.Conn, messageLen int, isResume bool) error { |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 688 | var connDebug *recordingConn |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 689 | var connDamage *damageAdaptor |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 690 | if *flagDebug { |
| 691 | connDebug = &recordingConn{Conn: conn} |
| 692 | conn = connDebug |
| 693 | defer func() { |
| 694 | connDebug.WriteTo(os.Stdout) |
| 695 | }() |
| 696 | } |
| 697 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 698 | if test.protocol == dtls { |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 699 | config.Bugs.PacketAdaptor = newPacketAdaptor(conn) |
| 700 | conn = config.Bugs.PacketAdaptor |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 701 | if test.replayWrites { |
| 702 | conn = newReplayAdaptor(conn) |
| 703 | } |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 704 | } |
| 705 | |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 706 | if test.damageFirstWrite { |
| 707 | connDamage = newDamageAdaptor(conn) |
| 708 | conn = connDamage |
| 709 | } |
| 710 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 711 | if test.sendPrefix != "" { |
| 712 | if _, err := conn.Write([]byte(test.sendPrefix)); err != nil { |
| 713 | return err |
| 714 | } |
David Benjamin | 98e882e | 2014-08-08 13:24:34 -0400 | [diff] [blame] | 715 | } |
| 716 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 717 | var tlsConn *Conn |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 718 | if test.testType == clientTest { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 719 | if test.protocol == dtls { |
| 720 | tlsConn = DTLSServer(conn, config) |
| 721 | } else { |
| 722 | tlsConn = Server(conn, config) |
| 723 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 724 | } else { |
| 725 | config.InsecureSkipVerify = true |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 726 | if test.protocol == dtls { |
| 727 | tlsConn = DTLSClient(conn, config) |
| 728 | } else { |
| 729 | tlsConn = Client(conn, config) |
| 730 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 731 | } |
| 732 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 733 | if err := tlsConn.Handshake(); err != nil { |
| 734 | return err |
| 735 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 736 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 737 | // TODO(davidben): move all per-connection expectations into a dedicated |
| 738 | // expectations struct that can be specified separately for the two |
| 739 | // legs. |
| 740 | expectedVersion := test.expectedVersion |
| 741 | if isResume && test.expectedResumeVersion != 0 { |
| 742 | expectedVersion = test.expectedResumeVersion |
| 743 | } |
| 744 | if vers := tlsConn.ConnectionState().Version; expectedVersion != 0 && vers != expectedVersion { |
| 745 | return fmt.Errorf("got version %x, expected %x", vers, expectedVersion) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 746 | } |
| 747 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 748 | if test.expectChannelID { |
| 749 | channelID := tlsConn.ConnectionState().ChannelID |
| 750 | if channelID == nil { |
| 751 | return fmt.Errorf("no channel ID negotiated") |
| 752 | } |
| 753 | if channelID.Curve != channelIDKey.Curve || |
| 754 | channelIDKey.X.Cmp(channelIDKey.X) != 0 || |
| 755 | channelIDKey.Y.Cmp(channelIDKey.Y) != 0 { |
| 756 | return fmt.Errorf("incorrect channel ID") |
| 757 | } |
| 758 | } |
| 759 | |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 760 | if expected := test.expectedNextProto; expected != "" { |
| 761 | if actual := tlsConn.ConnectionState().NegotiatedProtocol; actual != expected { |
| 762 | return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected) |
| 763 | } |
| 764 | } |
| 765 | |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 766 | if test.expectedNextProtoType != 0 { |
| 767 | if (test.expectedNextProtoType == alpn) != tlsConn.ConnectionState().NegotiatedProtocolFromALPN { |
| 768 | return fmt.Errorf("next proto type mismatch") |
| 769 | } |
| 770 | } |
| 771 | |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 772 | if p := tlsConn.ConnectionState().SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile { |
| 773 | return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile) |
| 774 | } |
| 775 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 776 | if test.shimWritesFirst { |
| 777 | var buf [5]byte |
| 778 | _, err := io.ReadFull(tlsConn, buf[:]) |
| 779 | if err != nil { |
| 780 | return err |
| 781 | } |
| 782 | if string(buf[:]) != "hello" { |
| 783 | return fmt.Errorf("bad initial message") |
| 784 | } |
| 785 | } |
| 786 | |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 787 | if test.renegotiate { |
| 788 | if test.renegotiateCiphers != nil { |
| 789 | config.CipherSuites = test.renegotiateCiphers |
| 790 | } |
| 791 | if err := tlsConn.Renegotiate(); err != nil { |
| 792 | return err |
| 793 | } |
| 794 | } else if test.renegotiateCiphers != nil { |
| 795 | panic("renegotiateCiphers without renegotiate") |
| 796 | } |
| 797 | |
David Benjamin | 5fa3eba | 2015-01-22 16:35:40 -0500 | [diff] [blame] | 798 | if test.damageFirstWrite { |
| 799 | connDamage.setDamage(true) |
| 800 | tlsConn.Write([]byte("DAMAGED WRITE")) |
| 801 | connDamage.setDamage(false) |
| 802 | } |
| 803 | |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 804 | if messageLen < 0 { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 805 | if test.protocol == dtls { |
| 806 | return fmt.Errorf("messageLen < 0 not supported for DTLS tests") |
| 807 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 808 | // Read until EOF. |
| 809 | _, err := io.Copy(ioutil.Discard, tlsConn) |
| 810 | return err |
| 811 | } |
| 812 | |
David Benjamin | 4189bd9 | 2015-01-25 23:52:39 -0500 | [diff] [blame] | 813 | var testMessage []byte |
| 814 | if config.Bugs.AppDataAfterChangeCipherSpec != nil { |
| 815 | // We've already sent a message. Expect the shim to echo it |
| 816 | // back. |
| 817 | testMessage = config.Bugs.AppDataAfterChangeCipherSpec |
| 818 | } else { |
| 819 | if messageLen == 0 { |
| 820 | messageLen = 32 |
| 821 | } |
| 822 | testMessage = make([]byte, messageLen) |
| 823 | for i := range testMessage { |
| 824 | testMessage[i] = 0x42 |
| 825 | } |
| 826 | tlsConn.Write(testMessage) |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 827 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 828 | |
| 829 | buf := make([]byte, len(testMessage)) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 830 | if test.protocol == dtls { |
| 831 | bufTmp := make([]byte, len(buf)+1) |
| 832 | n, err := tlsConn.Read(bufTmp) |
| 833 | if err != nil { |
| 834 | return err |
| 835 | } |
| 836 | if n != len(buf) { |
| 837 | return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf)) |
| 838 | } |
| 839 | copy(buf, bufTmp) |
| 840 | } else { |
| 841 | _, err := io.ReadFull(tlsConn, buf) |
| 842 | if err != nil { |
| 843 | return err |
| 844 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | for i, v := range buf { |
| 848 | if v != testMessage[i]^0xff { |
| 849 | return fmt.Errorf("bad reply contents at byte %d", i) |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | return nil |
| 854 | } |
| 855 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 856 | func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd { |
| 857 | valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"} |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 858 | if dbAttach { |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 859 | 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] | 860 | } |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 861 | valgrindArgs = append(valgrindArgs, path) |
| 862 | valgrindArgs = append(valgrindArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 863 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 864 | return exec.Command("valgrind", valgrindArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 865 | } |
| 866 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 867 | func gdbOf(path string, args ...string) *exec.Cmd { |
| 868 | xtermArgs := []string{"-e", "gdb", "--args"} |
| 869 | xtermArgs = append(xtermArgs, path) |
| 870 | xtermArgs = append(xtermArgs, args...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 871 | |
David Benjamin | 325b5c3 | 2014-07-01 19:40:31 -0400 | [diff] [blame] | 872 | return exec.Command("xterm", xtermArgs...) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 873 | } |
| 874 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 875 | func openSocketPair() (shimEnd *os.File, conn net.Conn) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 876 | socks, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0) |
| 877 | if err != nil { |
| 878 | panic(err) |
| 879 | } |
| 880 | |
| 881 | syscall.CloseOnExec(socks[0]) |
| 882 | syscall.CloseOnExec(socks[1]) |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 883 | shimEnd = os.NewFile(uintptr(socks[0]), "shim end") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 884 | connFile := os.NewFile(uintptr(socks[1]), "our end") |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 885 | conn, err = net.FileConn(connFile) |
| 886 | if err != nil { |
| 887 | panic(err) |
| 888 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 889 | connFile.Close() |
| 890 | if err != nil { |
| 891 | panic(err) |
| 892 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 893 | return shimEnd, conn |
| 894 | } |
| 895 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 896 | type moreMallocsError struct{} |
| 897 | |
| 898 | func (moreMallocsError) Error() string { |
| 899 | return "child process did not exhaust all allocation calls" |
| 900 | } |
| 901 | |
| 902 | var errMoreMallocs = moreMallocsError{} |
| 903 | |
| 904 | func runTest(test *testCase, buildDir string, mallocNumToFail int64) error { |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 905 | if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) { |
| 906 | panic("Error expected without shouldFail in " + test.name) |
| 907 | } |
| 908 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 909 | shimEnd, conn := openSocketPair() |
| 910 | shimEndResume, connResume := openSocketPair() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 911 | |
David Benjamin | 884fdf1 | 2014-08-02 15:28:23 -0400 | [diff] [blame] | 912 | shim_path := path.Join(buildDir, "ssl/test/bssl_shim") |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 913 | var flags []string |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 914 | if test.testType == serverTest { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 915 | flags = append(flags, "-server") |
| 916 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 917 | flags = append(flags, "-key-file") |
| 918 | if test.keyFile == "" { |
| 919 | flags = append(flags, rsaKeyFile) |
| 920 | } else { |
| 921 | flags = append(flags, test.keyFile) |
| 922 | } |
| 923 | |
| 924 | flags = append(flags, "-cert-file") |
| 925 | if test.certFile == "" { |
| 926 | flags = append(flags, rsaCertificateFile) |
| 927 | } else { |
| 928 | flags = append(flags, test.certFile) |
| 929 | } |
| 930 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 931 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 932 | if test.protocol == dtls { |
| 933 | flags = append(flags, "-dtls") |
| 934 | } |
| 935 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 936 | if test.resumeSession { |
| 937 | flags = append(flags, "-resume") |
| 938 | } |
| 939 | |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 940 | if test.shimWritesFirst { |
| 941 | flags = append(flags, "-shim-writes-first") |
| 942 | } |
| 943 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 944 | flags = append(flags, test.flags...) |
| 945 | |
| 946 | var shim *exec.Cmd |
| 947 | if *useValgrind { |
| 948 | shim = valgrindOf(false, shim_path, flags...) |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 949 | } else if *useGDB { |
| 950 | shim = gdbOf(shim_path, flags...) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 951 | } else { |
| 952 | shim = exec.Command(shim_path, flags...) |
| 953 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 954 | shim.ExtraFiles = []*os.File{shimEnd, shimEndResume} |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 955 | shim.Stdin = os.Stdin |
| 956 | var stdoutBuf, stderrBuf bytes.Buffer |
| 957 | shim.Stdout = &stdoutBuf |
| 958 | shim.Stderr = &stderrBuf |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 959 | if mallocNumToFail >= 0 { |
| 960 | shim.Env = []string{"MALLOC_NUMBER_TO_FAIL=" + strconv.FormatInt(mallocNumToFail, 10)} |
| 961 | if *mallocTestDebug { |
| 962 | shim.Env = append(shim.Env, "MALLOC_ABORT_ON_FAIL=1") |
| 963 | } |
| 964 | shim.Env = append(shim.Env, "_MALLOC_CHECK=1") |
| 965 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 966 | |
| 967 | if err := shim.Start(); err != nil { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 968 | panic(err) |
| 969 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 970 | shimEnd.Close() |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 971 | shimEndResume.Close() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 972 | |
| 973 | config := test.config |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 974 | config.ClientSessionCache = NewLRUClientSessionCache(1) |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 975 | config.ServerSessionCache = NewLRUServerSessionCache(1) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 976 | if test.testType == clientTest { |
| 977 | if len(config.Certificates) == 0 { |
| 978 | config.Certificates = []Certificate{getRSACertificate()} |
| 979 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 980 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 981 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 982 | err := doExchange(test, &config, conn, test.messageLen, |
| 983 | false /* not a resumption */) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 984 | conn.Close() |
David Benjamin | 65ea8ff | 2014-11-23 03:01:00 -0500 | [diff] [blame] | 985 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 986 | if err == nil && test.resumeSession { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 987 | var resumeConfig Config |
| 988 | if test.resumeConfig != nil { |
| 989 | resumeConfig = *test.resumeConfig |
| 990 | if len(resumeConfig.Certificates) == 0 { |
| 991 | resumeConfig.Certificates = []Certificate{getRSACertificate()} |
| 992 | } |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 993 | if !test.newSessionsOnResume { |
| 994 | resumeConfig.SessionTicketKey = config.SessionTicketKey |
| 995 | resumeConfig.ClientSessionCache = config.ClientSessionCache |
| 996 | resumeConfig.ServerSessionCache = config.ServerSessionCache |
| 997 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 998 | } else { |
| 999 | resumeConfig = config |
| 1000 | } |
| 1001 | err = doExchange(test, &resumeConfig, connResume, test.messageLen, |
| 1002 | true /* resumption */) |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 1003 | } |
David Benjamin | 812152a | 2014-09-06 12:49:07 -0400 | [diff] [blame] | 1004 | connResume.Close() |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 1005 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 1006 | childErr := shim.Wait() |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 1007 | if exitError, ok := childErr.(*exec.ExitError); ok { |
| 1008 | if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 { |
| 1009 | return errMoreMallocs |
| 1010 | } |
| 1011 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1012 | |
| 1013 | stdout := string(stdoutBuf.Bytes()) |
| 1014 | stderr := string(stderrBuf.Bytes()) |
| 1015 | failed := err != nil || childErr != nil |
| 1016 | correctFailure := len(test.expectedError) == 0 || strings.Contains(stdout, test.expectedError) |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 1017 | localError := "none" |
| 1018 | if err != nil { |
| 1019 | localError = err.Error() |
| 1020 | } |
| 1021 | if len(test.expectedLocalError) != 0 { |
| 1022 | correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError) |
| 1023 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1024 | |
| 1025 | if failed != test.shouldFail || failed && !correctFailure { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1026 | childError := "none" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1027 | if childErr != nil { |
| 1028 | childError = childErr.Error() |
| 1029 | } |
| 1030 | |
| 1031 | var msg string |
| 1032 | switch { |
| 1033 | case failed && !test.shouldFail: |
| 1034 | msg = "unexpected failure" |
| 1035 | case !failed && test.shouldFail: |
| 1036 | msg = "unexpected success" |
| 1037 | case failed && !correctFailure: |
Adam Langley | ac61fa3 | 2014-06-23 12:03:11 -0700 | [diff] [blame] | 1038 | msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1039 | default: |
| 1040 | panic("internal error") |
| 1041 | } |
| 1042 | |
| 1043 | return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, string(stdoutBuf.Bytes()), stderr) |
| 1044 | } |
| 1045 | |
| 1046 | if !*useValgrind && len(stderr) > 0 { |
| 1047 | println(stderr) |
| 1048 | } |
| 1049 | |
| 1050 | return nil |
| 1051 | } |
| 1052 | |
| 1053 | var tlsVersions = []struct { |
| 1054 | name string |
| 1055 | version uint16 |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 1056 | flag string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1057 | hasDTLS bool |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1058 | }{ |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1059 | {"SSL3", VersionSSL30, "-no-ssl3", false}, |
| 1060 | {"TLS1", VersionTLS10, "-no-tls1", true}, |
| 1061 | {"TLS11", VersionTLS11, "-no-tls11", false}, |
| 1062 | {"TLS12", VersionTLS12, "-no-tls12", true}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | var testCipherSuites = []struct { |
| 1066 | name string |
| 1067 | id uint16 |
| 1068 | }{ |
| 1069 | {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1070 | {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1071 | {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1072 | {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1073 | {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1074 | {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1075 | {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1076 | {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1077 | {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1078 | {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1079 | {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384}, |
| 1080 | {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1081 | {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1082 | {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1083 | {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1084 | {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}, |
| 1085 | {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1086 | {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1087 | {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1088 | {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA}, |
David Benjamin | 2af684f | 2014-10-27 02:23:15 -0400 | [diff] [blame] | 1089 | {"ECDHE-PSK-WITH-AES-128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1090 | {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1091 | {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1092 | {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1093 | {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1094 | {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1095 | {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1096 | {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA}, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1097 | {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 1098 | {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA}, |
| 1099 | {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1100 | {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5}, |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 1101 | {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1104 | func hasComponent(suiteName, component string) bool { |
| 1105 | return strings.Contains("-"+suiteName+"-", "-"+component+"-") |
| 1106 | } |
| 1107 | |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1108 | func isTLS12Only(suiteName string) bool { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1109 | return hasComponent(suiteName, "GCM") || |
| 1110 | hasComponent(suiteName, "SHA256") || |
| 1111 | hasComponent(suiteName, "SHA384") |
| 1112 | } |
| 1113 | |
| 1114 | func isDTLSCipher(suiteName string) bool { |
David Benjamin | e95d20d | 2014-12-23 11:16:01 -0500 | [diff] [blame] | 1115 | return !hasComponent(suiteName, "RC4") |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1116 | } |
| 1117 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1118 | func addCipherSuiteTests() { |
| 1119 | for _, suite := range testCipherSuites { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1120 | const psk = "12345" |
| 1121 | const pskIdentity = "luggage combo" |
| 1122 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1123 | var cert Certificate |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 1124 | var certFile string |
| 1125 | var keyFile string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1126 | if hasComponent(suite.name, "ECDSA") { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1127 | cert = getECDSACertificate() |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 1128 | certFile = ecdsaCertificateFile |
| 1129 | keyFile = ecdsaKeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1130 | } else { |
| 1131 | cert = getRSACertificate() |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 1132 | certFile = rsaCertificateFile |
| 1133 | keyFile = rsaKeyFile |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1136 | var flags []string |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1137 | if hasComponent(suite.name, "PSK") { |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1138 | flags = append(flags, |
| 1139 | "-psk", psk, |
| 1140 | "-psk-identity", pskIdentity) |
| 1141 | } |
| 1142 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1143 | for _, ver := range tlsVersions { |
David Benjamin | f7768e4 | 2014-08-31 02:06:47 -0400 | [diff] [blame] | 1144 | if ver.version < VersionTLS12 && isTLS12Only(suite.name) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1145 | continue |
| 1146 | } |
| 1147 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 1148 | testCases = append(testCases, testCase{ |
| 1149 | testType: clientTest, |
| 1150 | name: ver.name + "-" + suite.name + "-client", |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1151 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1152 | MinVersion: ver.version, |
| 1153 | MaxVersion: ver.version, |
| 1154 | CipherSuites: []uint16{suite.id}, |
| 1155 | Certificates: []Certificate{cert}, |
| 1156 | PreSharedKey: []byte(psk), |
| 1157 | PreSharedKeyIdentity: pskIdentity, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1158 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1159 | flags: flags, |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1160 | resumeSession: true, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1161 | }) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 1162 | |
David Benjamin | 76d8abe | 2014-08-14 16:25:34 -0400 | [diff] [blame] | 1163 | testCases = append(testCases, testCase{ |
| 1164 | testType: serverTest, |
| 1165 | name: ver.name + "-" + suite.name + "-server", |
| 1166 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1167 | MinVersion: ver.version, |
| 1168 | MaxVersion: ver.version, |
| 1169 | CipherSuites: []uint16{suite.id}, |
| 1170 | Certificates: []Certificate{cert}, |
| 1171 | PreSharedKey: []byte(psk), |
| 1172 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 76d8abe | 2014-08-14 16:25:34 -0400 | [diff] [blame] | 1173 | }, |
| 1174 | certFile: certFile, |
| 1175 | keyFile: keyFile, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1176 | flags: flags, |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1177 | resumeSession: true, |
David Benjamin | 76d8abe | 2014-08-14 16:25:34 -0400 | [diff] [blame] | 1178 | }) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1179 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1180 | if ver.hasDTLS && isDTLSCipher(suite.name) { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1181 | testCases = append(testCases, testCase{ |
| 1182 | testType: clientTest, |
| 1183 | protocol: dtls, |
| 1184 | name: "D" + ver.name + "-" + suite.name + "-client", |
| 1185 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1186 | MinVersion: ver.version, |
| 1187 | MaxVersion: ver.version, |
| 1188 | CipherSuites: []uint16{suite.id}, |
| 1189 | Certificates: []Certificate{cert}, |
| 1190 | PreSharedKey: []byte(psk), |
| 1191 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1192 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1193 | flags: flags, |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1194 | resumeSession: true, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1195 | }) |
| 1196 | testCases = append(testCases, testCase{ |
| 1197 | testType: serverTest, |
| 1198 | protocol: dtls, |
| 1199 | name: "D" + ver.name + "-" + suite.name + "-server", |
| 1200 | config: Config{ |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1201 | MinVersion: ver.version, |
| 1202 | MaxVersion: ver.version, |
| 1203 | CipherSuites: []uint16{suite.id}, |
| 1204 | Certificates: []Certificate{cert}, |
| 1205 | PreSharedKey: []byte(psk), |
| 1206 | PreSharedKeyIdentity: pskIdentity, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1207 | }, |
| 1208 | certFile: certFile, |
| 1209 | keyFile: keyFile, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1210 | flags: flags, |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1211 | resumeSession: true, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1212 | }) |
| 1213 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | func addBadECDSASignatureTests() { |
| 1219 | for badR := BadValue(1); badR < NumBadValues; badR++ { |
| 1220 | for badS := BadValue(1); badS < NumBadValues; badS++ { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 1221 | testCases = append(testCases, testCase{ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1222 | name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS), |
| 1223 | config: Config{ |
| 1224 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1225 | Certificates: []Certificate{getECDSACertificate()}, |
| 1226 | Bugs: ProtocolBugs{ |
| 1227 | BadECDSAR: badR, |
| 1228 | BadECDSAS: badS, |
| 1229 | }, |
| 1230 | }, |
| 1231 | shouldFail: true, |
| 1232 | expectedError: "SIGNATURE", |
| 1233 | }) |
| 1234 | } |
| 1235 | } |
| 1236 | } |
| 1237 | |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1238 | func addCBCPaddingTests() { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 1239 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1240 | name: "MaxCBCPadding", |
| 1241 | config: Config{ |
| 1242 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1243 | Bugs: ProtocolBugs{ |
| 1244 | MaxPadding: true, |
| 1245 | }, |
| 1246 | }, |
| 1247 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 1248 | }) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 1249 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1250 | name: "BadCBCPadding", |
| 1251 | config: Config{ |
| 1252 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1253 | Bugs: ProtocolBugs{ |
| 1254 | PaddingFirstByteBad: true, |
| 1255 | }, |
| 1256 | }, |
| 1257 | shouldFail: true, |
| 1258 | expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC", |
| 1259 | }) |
| 1260 | // OpenSSL previously had an issue where the first byte of padding in |
| 1261 | // 255 bytes of padding wasn't checked. |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 1262 | testCases = append(testCases, testCase{ |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1263 | name: "BadCBCPadding255", |
| 1264 | config: Config{ |
| 1265 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1266 | Bugs: ProtocolBugs{ |
| 1267 | MaxPadding: true, |
| 1268 | PaddingFirstByteBadIf255: true, |
| 1269 | }, |
| 1270 | }, |
| 1271 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 1272 | shouldFail: true, |
| 1273 | expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC", |
| 1274 | }) |
| 1275 | } |
| 1276 | |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 1277 | func addCBCSplittingTests() { |
| 1278 | testCases = append(testCases, testCase{ |
| 1279 | name: "CBCRecordSplitting", |
| 1280 | config: Config{ |
| 1281 | MaxVersion: VersionTLS10, |
| 1282 | MinVersion: VersionTLS10, |
| 1283 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1284 | }, |
| 1285 | messageLen: -1, // read until EOF |
| 1286 | flags: []string{ |
| 1287 | "-async", |
| 1288 | "-write-different-record-sizes", |
| 1289 | "-cbc-record-splitting", |
| 1290 | }, |
David Benjamin | a8e3e0e | 2014-08-06 22:11:10 -0400 | [diff] [blame] | 1291 | }) |
| 1292 | testCases = append(testCases, testCase{ |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 1293 | name: "CBCRecordSplittingPartialWrite", |
| 1294 | config: Config{ |
| 1295 | MaxVersion: VersionTLS10, |
| 1296 | MinVersion: VersionTLS10, |
| 1297 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1298 | }, |
| 1299 | messageLen: -1, // read until EOF |
| 1300 | flags: []string{ |
| 1301 | "-async", |
| 1302 | "-write-different-record-sizes", |
| 1303 | "-cbc-record-splitting", |
| 1304 | "-partial-write", |
| 1305 | }, |
| 1306 | }) |
| 1307 | } |
| 1308 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 1309 | func addClientAuthTests() { |
David Benjamin | 407a10c | 2014-07-16 12:58:59 -0400 | [diff] [blame] | 1310 | // Add a dummy cert pool to stress certificate authority parsing. |
| 1311 | // TODO(davidben): Add tests that those values parse out correctly. |
| 1312 | certPool := x509.NewCertPool() |
| 1313 | cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0]) |
| 1314 | if err != nil { |
| 1315 | panic(err) |
| 1316 | } |
| 1317 | certPool.AddCert(cert) |
| 1318 | |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 1319 | for _, ver := range tlsVersions { |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 1320 | testCases = append(testCases, testCase{ |
| 1321 | testType: clientTest, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 1322 | name: ver.name + "-Client-ClientAuth-RSA", |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 1323 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 1324 | MinVersion: ver.version, |
| 1325 | MaxVersion: ver.version, |
| 1326 | ClientAuth: RequireAnyClientCert, |
| 1327 | ClientCAs: certPool, |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 1328 | }, |
| 1329 | flags: []string{ |
| 1330 | "-cert-file", rsaCertificateFile, |
| 1331 | "-key-file", rsaKeyFile, |
| 1332 | }, |
| 1333 | }) |
| 1334 | testCases = append(testCases, testCase{ |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 1335 | testType: serverTest, |
| 1336 | name: ver.name + "-Server-ClientAuth-RSA", |
| 1337 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 1338 | MinVersion: ver.version, |
| 1339 | MaxVersion: ver.version, |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 1340 | Certificates: []Certificate{rsaCertificate}, |
| 1341 | }, |
| 1342 | flags: []string{"-require-any-client-certificate"}, |
| 1343 | }) |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 1344 | if ver.version != VersionSSL30 { |
| 1345 | testCases = append(testCases, testCase{ |
| 1346 | testType: serverTest, |
| 1347 | name: ver.name + "-Server-ClientAuth-ECDSA", |
| 1348 | config: Config{ |
| 1349 | MinVersion: ver.version, |
| 1350 | MaxVersion: ver.version, |
| 1351 | Certificates: []Certificate{ecdsaCertificate}, |
| 1352 | }, |
| 1353 | flags: []string{"-require-any-client-certificate"}, |
| 1354 | }) |
| 1355 | testCases = append(testCases, testCase{ |
| 1356 | testType: clientTest, |
| 1357 | name: ver.name + "-Client-ClientAuth-ECDSA", |
| 1358 | config: Config{ |
| 1359 | MinVersion: ver.version, |
| 1360 | MaxVersion: ver.version, |
| 1361 | ClientAuth: RequireAnyClientCert, |
| 1362 | ClientCAs: certPool, |
| 1363 | }, |
| 1364 | flags: []string{ |
| 1365 | "-cert-file", ecdsaCertificateFile, |
| 1366 | "-key-file", ecdsaKeyFile, |
| 1367 | }, |
| 1368 | }) |
| 1369 | } |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 1370 | } |
| 1371 | } |
| 1372 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 1373 | func addExtendedMasterSecretTests() { |
| 1374 | const expectEMSFlag = "-expect-extended-master-secret" |
| 1375 | |
| 1376 | for _, with := range []bool{false, true} { |
| 1377 | prefix := "No" |
| 1378 | var flags []string |
| 1379 | if with { |
| 1380 | prefix = "" |
| 1381 | flags = []string{expectEMSFlag} |
| 1382 | } |
| 1383 | |
| 1384 | for _, isClient := range []bool{false, true} { |
| 1385 | suffix := "-Server" |
| 1386 | testType := serverTest |
| 1387 | if isClient { |
| 1388 | suffix = "-Client" |
| 1389 | testType = clientTest |
| 1390 | } |
| 1391 | |
| 1392 | for _, ver := range tlsVersions { |
| 1393 | test := testCase{ |
| 1394 | testType: testType, |
| 1395 | name: prefix + "ExtendedMasterSecret-" + ver.name + suffix, |
| 1396 | config: Config{ |
| 1397 | MinVersion: ver.version, |
| 1398 | MaxVersion: ver.version, |
| 1399 | Bugs: ProtocolBugs{ |
| 1400 | NoExtendedMasterSecret: !with, |
| 1401 | RequireExtendedMasterSecret: with, |
| 1402 | }, |
| 1403 | }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1404 | flags: flags, |
| 1405 | shouldFail: ver.version == VersionSSL30 && with, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 1406 | } |
| 1407 | if test.shouldFail { |
| 1408 | test.expectedLocalError = "extended master secret required but not supported by peer" |
| 1409 | } |
| 1410 | testCases = append(testCases, test) |
| 1411 | } |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | // When a session is resumed, it should still be aware that its master |
| 1416 | // secret was generated via EMS and thus it's safe to use tls-unique. |
| 1417 | testCases = append(testCases, testCase{ |
| 1418 | name: "ExtendedMasterSecret-Resume", |
| 1419 | config: Config{ |
| 1420 | Bugs: ProtocolBugs{ |
| 1421 | RequireExtendedMasterSecret: true, |
| 1422 | }, |
| 1423 | }, |
| 1424 | flags: []string{expectEMSFlag}, |
| 1425 | resumeSession: true, |
| 1426 | }) |
| 1427 | } |
| 1428 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1429 | // Adds tests that try to cover the range of the handshake state machine, under |
| 1430 | // various conditions. Some of these are redundant with other tests, but they |
| 1431 | // only cover the synchronous case. |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1432 | func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) { |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1433 | var suffix string |
| 1434 | var flags []string |
| 1435 | var maxHandshakeRecordLength int |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1436 | if protocol == dtls { |
| 1437 | suffix = "-DTLS" |
| 1438 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1439 | if async { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1440 | suffix += "-Async" |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1441 | flags = append(flags, "-async") |
| 1442 | } else { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1443 | suffix += "-Sync" |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1444 | } |
| 1445 | if splitHandshake { |
| 1446 | suffix += "-SplitHandshakeRecords" |
David Benjamin | 9821454 | 2014-08-07 18:02:39 -0400 | [diff] [blame] | 1447 | maxHandshakeRecordLength = 1 |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1448 | } |
| 1449 | |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1450 | // Basic handshake, with resumption. Client and server, |
| 1451 | // session ID and session ticket. |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1452 | testCases = append(testCases, testCase{ |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1453 | protocol: protocol, |
| 1454 | name: "Basic-Client" + suffix, |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1455 | config: Config{ |
| 1456 | Bugs: ProtocolBugs{ |
| 1457 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1458 | }, |
| 1459 | }, |
David Benjamin | bed9aae | 2014-08-07 19:13:38 -0400 | [diff] [blame] | 1460 | flags: flags, |
| 1461 | resumeSession: true, |
| 1462 | }) |
| 1463 | testCases = append(testCases, testCase{ |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1464 | protocol: protocol, |
| 1465 | name: "Basic-Client-RenewTicket" + suffix, |
David Benjamin | bed9aae | 2014-08-07 19:13:38 -0400 | [diff] [blame] | 1466 | config: Config{ |
| 1467 | Bugs: ProtocolBugs{ |
| 1468 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1469 | RenewTicketOnResume: true, |
| 1470 | }, |
| 1471 | }, |
| 1472 | flags: flags, |
| 1473 | resumeSession: true, |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1474 | }) |
| 1475 | testCases = append(testCases, testCase{ |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1476 | protocol: protocol, |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1477 | name: "Basic-Client-NoTicket" + suffix, |
| 1478 | config: Config{ |
| 1479 | SessionTicketsDisabled: true, |
| 1480 | Bugs: ProtocolBugs{ |
| 1481 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1482 | }, |
| 1483 | }, |
| 1484 | flags: flags, |
| 1485 | resumeSession: true, |
| 1486 | }) |
| 1487 | testCases = append(testCases, testCase{ |
| 1488 | protocol: protocol, |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1489 | testType: serverTest, |
| 1490 | name: "Basic-Server" + suffix, |
| 1491 | config: Config{ |
| 1492 | Bugs: ProtocolBugs{ |
| 1493 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1494 | }, |
| 1495 | }, |
David Benjamin | bed9aae | 2014-08-07 19:13:38 -0400 | [diff] [blame] | 1496 | flags: flags, |
| 1497 | resumeSession: true, |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1498 | }) |
David Benjamin | fe8eb9a | 2014-11-17 03:19:02 -0500 | [diff] [blame] | 1499 | testCases = append(testCases, testCase{ |
| 1500 | protocol: protocol, |
| 1501 | testType: serverTest, |
| 1502 | name: "Basic-Server-NoTickets" + suffix, |
| 1503 | config: Config{ |
| 1504 | SessionTicketsDisabled: true, |
| 1505 | Bugs: ProtocolBugs{ |
| 1506 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1507 | }, |
| 1508 | }, |
| 1509 | flags: flags, |
| 1510 | resumeSession: true, |
| 1511 | }) |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1512 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1513 | // TLS client auth. |
| 1514 | testCases = append(testCases, testCase{ |
| 1515 | protocol: protocol, |
| 1516 | testType: clientTest, |
| 1517 | name: "ClientAuth-Client" + suffix, |
| 1518 | config: Config{ |
David Benjamin | e098ec2 | 2014-08-27 23:13:20 -0400 | [diff] [blame] | 1519 | ClientAuth: RequireAnyClientCert, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1520 | Bugs: ProtocolBugs{ |
| 1521 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1522 | }, |
| 1523 | }, |
| 1524 | flags: append(flags, |
| 1525 | "-cert-file", rsaCertificateFile, |
| 1526 | "-key-file", rsaKeyFile), |
| 1527 | }) |
| 1528 | testCases = append(testCases, testCase{ |
| 1529 | protocol: protocol, |
| 1530 | testType: serverTest, |
| 1531 | name: "ClientAuth-Server" + suffix, |
| 1532 | config: Config{ |
| 1533 | Certificates: []Certificate{rsaCertificate}, |
| 1534 | }, |
| 1535 | flags: append(flags, "-require-any-client-certificate"), |
| 1536 | }) |
| 1537 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1538 | // No session ticket support; server doesn't send NewSessionTicket. |
| 1539 | testCases = append(testCases, testCase{ |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1540 | protocol: protocol, |
| 1541 | name: "SessionTicketsDisabled-Client" + suffix, |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1542 | config: Config{ |
| 1543 | SessionTicketsDisabled: true, |
| 1544 | Bugs: ProtocolBugs{ |
| 1545 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1546 | }, |
| 1547 | }, |
| 1548 | flags: flags, |
| 1549 | }) |
| 1550 | testCases = append(testCases, testCase{ |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1551 | protocol: protocol, |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1552 | testType: serverTest, |
| 1553 | name: "SessionTicketsDisabled-Server" + suffix, |
| 1554 | config: Config{ |
| 1555 | SessionTicketsDisabled: true, |
| 1556 | Bugs: ProtocolBugs{ |
| 1557 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1558 | }, |
| 1559 | }, |
| 1560 | flags: flags, |
| 1561 | }) |
| 1562 | |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 1563 | // Skip ServerKeyExchange in PSK key exchange if there's no |
| 1564 | // identity hint. |
| 1565 | testCases = append(testCases, testCase{ |
| 1566 | protocol: protocol, |
| 1567 | name: "EmptyPSKHint-Client" + suffix, |
| 1568 | config: Config{ |
| 1569 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 1570 | PreSharedKey: []byte("secret"), |
| 1571 | Bugs: ProtocolBugs{ |
| 1572 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1573 | }, |
| 1574 | }, |
| 1575 | flags: append(flags, "-psk", "secret"), |
| 1576 | }) |
| 1577 | testCases = append(testCases, testCase{ |
| 1578 | protocol: protocol, |
| 1579 | testType: serverTest, |
| 1580 | name: "EmptyPSKHint-Server" + suffix, |
| 1581 | config: Config{ |
| 1582 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 1583 | PreSharedKey: []byte("secret"), |
| 1584 | Bugs: ProtocolBugs{ |
| 1585 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1586 | }, |
| 1587 | }, |
| 1588 | flags: append(flags, "-psk", "secret"), |
| 1589 | }) |
| 1590 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1591 | if protocol == tls { |
| 1592 | // NPN on client and server; results in post-handshake message. |
| 1593 | testCases = append(testCases, testCase{ |
| 1594 | protocol: protocol, |
| 1595 | name: "NPN-Client" + suffix, |
| 1596 | config: Config{ |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 1597 | NextProtos: []string{"foo"}, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1598 | Bugs: ProtocolBugs{ |
| 1599 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1600 | }, |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1601 | }, |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 1602 | flags: append(flags, "-select-next-proto", "foo"), |
| 1603 | expectedNextProto: "foo", |
| 1604 | expectedNextProtoType: npn, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1605 | }) |
| 1606 | testCases = append(testCases, testCase{ |
| 1607 | protocol: protocol, |
| 1608 | testType: serverTest, |
| 1609 | name: "NPN-Server" + suffix, |
| 1610 | config: Config{ |
| 1611 | NextProtos: []string{"bar"}, |
| 1612 | Bugs: ProtocolBugs{ |
| 1613 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1614 | }, |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1615 | }, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1616 | flags: append(flags, |
| 1617 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 1618 | "-expect-next-proto", "bar"), |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 1619 | expectedNextProto: "bar", |
| 1620 | expectedNextProtoType: npn, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1621 | }) |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1622 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1623 | // Client does False Start and negotiates NPN. |
| 1624 | testCases = append(testCases, testCase{ |
| 1625 | protocol: protocol, |
| 1626 | name: "FalseStart" + suffix, |
| 1627 | config: Config{ |
| 1628 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1629 | NextProtos: []string{"foo"}, |
| 1630 | Bugs: ProtocolBugs{ |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 1631 | ExpectFalseStart: true, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1632 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1633 | }, |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1634 | }, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1635 | flags: append(flags, |
| 1636 | "-false-start", |
| 1637 | "-select-next-proto", "foo"), |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 1638 | shimWritesFirst: true, |
| 1639 | resumeSession: true, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1640 | }) |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1641 | |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 1642 | // Client does False Start and negotiates ALPN. |
| 1643 | testCases = append(testCases, testCase{ |
| 1644 | protocol: protocol, |
| 1645 | name: "FalseStart-ALPN" + suffix, |
| 1646 | config: Config{ |
| 1647 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1648 | NextProtos: []string{"foo"}, |
| 1649 | Bugs: ProtocolBugs{ |
| 1650 | ExpectFalseStart: true, |
| 1651 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1652 | }, |
| 1653 | }, |
| 1654 | flags: append(flags, |
| 1655 | "-false-start", |
| 1656 | "-advertise-alpn", "\x03foo"), |
| 1657 | shimWritesFirst: true, |
| 1658 | resumeSession: true, |
| 1659 | }) |
| 1660 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1661 | // False Start without session tickets. |
| 1662 | testCases = append(testCases, testCase{ |
| 1663 | name: "FalseStart-SessionTicketsDisabled", |
| 1664 | config: Config{ |
| 1665 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1666 | NextProtos: []string{"foo"}, |
| 1667 | SessionTicketsDisabled: true, |
David Benjamin | 4e99c52 | 2014-08-24 01:45:30 -0400 | [diff] [blame] | 1668 | Bugs: ProtocolBugs{ |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 1669 | ExpectFalseStart: true, |
David Benjamin | 4e99c52 | 2014-08-24 01:45:30 -0400 | [diff] [blame] | 1670 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1671 | }, |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1672 | }, |
David Benjamin | 4e99c52 | 2014-08-24 01:45:30 -0400 | [diff] [blame] | 1673 | flags: append(flags, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1674 | "-false-start", |
| 1675 | "-select-next-proto", "foo", |
David Benjamin | 4e99c52 | 2014-08-24 01:45:30 -0400 | [diff] [blame] | 1676 | ), |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 1677 | shimWritesFirst: true, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1678 | }) |
David Benjamin | 1e7f8d7 | 2014-08-08 12:27:04 -0400 | [diff] [blame] | 1679 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 1680 | // Server parses a V2ClientHello. |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1681 | testCases = append(testCases, testCase{ |
| 1682 | protocol: protocol, |
| 1683 | testType: serverTest, |
| 1684 | name: "SendV2ClientHello" + suffix, |
| 1685 | config: Config{ |
| 1686 | // Choose a cipher suite that does not involve |
| 1687 | // elliptic curves, so no extensions are |
| 1688 | // involved. |
| 1689 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 1690 | Bugs: ProtocolBugs{ |
| 1691 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1692 | SendV2ClientHello: true, |
| 1693 | }, |
David Benjamin | 1e7f8d7 | 2014-08-08 12:27:04 -0400 | [diff] [blame] | 1694 | }, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1695 | flags: flags, |
| 1696 | }) |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 1697 | |
| 1698 | // Client sends a Channel ID. |
| 1699 | testCases = append(testCases, testCase{ |
| 1700 | protocol: protocol, |
| 1701 | name: "ChannelID-Client" + suffix, |
| 1702 | config: Config{ |
| 1703 | RequestChannelID: true, |
| 1704 | Bugs: ProtocolBugs{ |
| 1705 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1706 | }, |
| 1707 | }, |
| 1708 | flags: append(flags, |
| 1709 | "-send-channel-id", channelIDKeyFile, |
| 1710 | ), |
| 1711 | resumeSession: true, |
| 1712 | expectChannelID: true, |
| 1713 | }) |
| 1714 | |
| 1715 | // Server accepts a Channel ID. |
| 1716 | testCases = append(testCases, testCase{ |
| 1717 | protocol: protocol, |
| 1718 | testType: serverTest, |
| 1719 | name: "ChannelID-Server" + suffix, |
| 1720 | config: Config{ |
| 1721 | ChannelID: channelIDKey, |
| 1722 | Bugs: ProtocolBugs{ |
| 1723 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1724 | }, |
| 1725 | }, |
| 1726 | flags: append(flags, |
| 1727 | "-expect-channel-id", |
| 1728 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 1729 | ), |
| 1730 | resumeSession: true, |
| 1731 | expectChannelID: true, |
| 1732 | }) |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 1733 | } else { |
| 1734 | testCases = append(testCases, testCase{ |
| 1735 | protocol: protocol, |
| 1736 | name: "SkipHelloVerifyRequest" + suffix, |
| 1737 | config: Config{ |
| 1738 | Bugs: ProtocolBugs{ |
| 1739 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1740 | SkipHelloVerifyRequest: true, |
| 1741 | }, |
| 1742 | }, |
| 1743 | flags: flags, |
| 1744 | }) |
| 1745 | |
| 1746 | testCases = append(testCases, testCase{ |
| 1747 | testType: serverTest, |
| 1748 | protocol: protocol, |
| 1749 | name: "CookieExchange" + suffix, |
| 1750 | config: Config{ |
| 1751 | Bugs: ProtocolBugs{ |
| 1752 | MaxHandshakeRecordLength: maxHandshakeRecordLength, |
| 1753 | }, |
| 1754 | }, |
| 1755 | flags: append(flags, "-cookie-exchange"), |
| 1756 | }) |
| 1757 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 1758 | } |
| 1759 | |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 1760 | func addVersionNegotiationTests() { |
| 1761 | for i, shimVers := range tlsVersions { |
| 1762 | // Assemble flags to disable all newer versions on the shim. |
| 1763 | var flags []string |
| 1764 | for _, vers := range tlsVersions[i+1:] { |
| 1765 | flags = append(flags, vers.flag) |
| 1766 | } |
| 1767 | |
| 1768 | for _, runnerVers := range tlsVersions { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1769 | protocols := []protocol{tls} |
| 1770 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 1771 | protocols = append(protocols, dtls) |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 1772 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1773 | for _, protocol := range protocols { |
| 1774 | expectedVersion := shimVers.version |
| 1775 | if runnerVers.version < shimVers.version { |
| 1776 | expectedVersion = runnerVers.version |
| 1777 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 1778 | |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1779 | suffix := shimVers.name + "-" + runnerVers.name |
| 1780 | if protocol == dtls { |
| 1781 | suffix += "-DTLS" |
| 1782 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 1783 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 1784 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 1785 | |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 1786 | clientVers := shimVers.version |
| 1787 | if clientVers > VersionTLS10 { |
| 1788 | clientVers = VersionTLS10 |
| 1789 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1790 | testCases = append(testCases, testCase{ |
| 1791 | protocol: protocol, |
| 1792 | testType: clientTest, |
| 1793 | name: "VersionNegotiation-Client-" + suffix, |
| 1794 | config: Config{ |
| 1795 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 1796 | Bugs: ProtocolBugs{ |
| 1797 | ExpectInitialRecordVersion: clientVers, |
| 1798 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1799 | }, |
| 1800 | flags: flags, |
| 1801 | expectedVersion: expectedVersion, |
| 1802 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 1803 | testCases = append(testCases, testCase{ |
| 1804 | protocol: protocol, |
| 1805 | testType: clientTest, |
| 1806 | name: "VersionNegotiation-Client2-" + suffix, |
| 1807 | config: Config{ |
| 1808 | MaxVersion: runnerVers.version, |
| 1809 | Bugs: ProtocolBugs{ |
| 1810 | ExpectInitialRecordVersion: clientVers, |
| 1811 | }, |
| 1812 | }, |
| 1813 | flags: []string{"-max-version", shimVersFlag}, |
| 1814 | expectedVersion: expectedVersion, |
| 1815 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1816 | |
| 1817 | testCases = append(testCases, testCase{ |
| 1818 | protocol: protocol, |
| 1819 | testType: serverTest, |
| 1820 | name: "VersionNegotiation-Server-" + suffix, |
| 1821 | config: Config{ |
| 1822 | MaxVersion: runnerVers.version, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 1823 | Bugs: ProtocolBugs{ |
| 1824 | ExpectInitialRecordVersion: expectedVersion, |
| 1825 | }, |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1826 | }, |
| 1827 | flags: flags, |
| 1828 | expectedVersion: expectedVersion, |
| 1829 | }) |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 1830 | testCases = append(testCases, testCase{ |
| 1831 | protocol: protocol, |
| 1832 | testType: serverTest, |
| 1833 | name: "VersionNegotiation-Server2-" + suffix, |
| 1834 | config: Config{ |
| 1835 | MaxVersion: runnerVers.version, |
| 1836 | Bugs: ProtocolBugs{ |
| 1837 | ExpectInitialRecordVersion: expectedVersion, |
| 1838 | }, |
| 1839 | }, |
| 1840 | flags: []string{"-max-version", shimVersFlag}, |
| 1841 | expectedVersion: expectedVersion, |
| 1842 | }) |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 1843 | } |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 1844 | } |
| 1845 | } |
| 1846 | } |
| 1847 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 1848 | func addMinimumVersionTests() { |
| 1849 | for i, shimVers := range tlsVersions { |
| 1850 | // Assemble flags to disable all older versions on the shim. |
| 1851 | var flags []string |
| 1852 | for _, vers := range tlsVersions[:i] { |
| 1853 | flags = append(flags, vers.flag) |
| 1854 | } |
| 1855 | |
| 1856 | for _, runnerVers := range tlsVersions { |
| 1857 | protocols := []protocol{tls} |
| 1858 | if runnerVers.hasDTLS && shimVers.hasDTLS { |
| 1859 | protocols = append(protocols, dtls) |
| 1860 | } |
| 1861 | for _, protocol := range protocols { |
| 1862 | suffix := shimVers.name + "-" + runnerVers.name |
| 1863 | if protocol == dtls { |
| 1864 | suffix += "-DTLS" |
| 1865 | } |
| 1866 | shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls))) |
| 1867 | |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 1868 | var expectedVersion uint16 |
| 1869 | var shouldFail bool |
| 1870 | var expectedError string |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 1871 | var expectedLocalError string |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 1872 | if runnerVers.version >= shimVers.version { |
| 1873 | expectedVersion = runnerVers.version |
| 1874 | } else { |
| 1875 | shouldFail = true |
| 1876 | expectedError = ":UNSUPPORTED_PROTOCOL:" |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 1877 | if runnerVers.version > VersionSSL30 { |
| 1878 | expectedLocalError = "remote error: protocol version not supported" |
| 1879 | } else { |
| 1880 | expectedLocalError = "remote error: handshake failure" |
| 1881 | } |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | testCases = append(testCases, testCase{ |
| 1885 | protocol: protocol, |
| 1886 | testType: clientTest, |
| 1887 | name: "MinimumVersion-Client-" + suffix, |
| 1888 | config: Config{ |
| 1889 | MaxVersion: runnerVers.version, |
| 1890 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 1891 | flags: flags, |
| 1892 | expectedVersion: expectedVersion, |
| 1893 | shouldFail: shouldFail, |
| 1894 | expectedError: expectedError, |
| 1895 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 1896 | }) |
| 1897 | testCases = append(testCases, testCase{ |
| 1898 | protocol: protocol, |
| 1899 | testType: clientTest, |
| 1900 | name: "MinimumVersion-Client2-" + suffix, |
| 1901 | config: Config{ |
| 1902 | MaxVersion: runnerVers.version, |
| 1903 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 1904 | flags: []string{"-min-version", shimVersFlag}, |
| 1905 | expectedVersion: expectedVersion, |
| 1906 | shouldFail: shouldFail, |
| 1907 | expectedError: expectedError, |
| 1908 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 1909 | }) |
| 1910 | |
| 1911 | testCases = append(testCases, testCase{ |
| 1912 | protocol: protocol, |
| 1913 | testType: serverTest, |
| 1914 | name: "MinimumVersion-Server-" + suffix, |
| 1915 | config: Config{ |
| 1916 | MaxVersion: runnerVers.version, |
| 1917 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 1918 | flags: flags, |
| 1919 | expectedVersion: expectedVersion, |
| 1920 | shouldFail: shouldFail, |
| 1921 | expectedError: expectedError, |
| 1922 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 1923 | }) |
| 1924 | testCases = append(testCases, testCase{ |
| 1925 | protocol: protocol, |
| 1926 | testType: serverTest, |
| 1927 | name: "MinimumVersion-Server2-" + suffix, |
| 1928 | config: Config{ |
| 1929 | MaxVersion: runnerVers.version, |
| 1930 | }, |
David Benjamin | 87909c0 | 2014-12-13 01:55:01 -0500 | [diff] [blame] | 1931 | flags: []string{"-min-version", shimVersFlag}, |
| 1932 | expectedVersion: expectedVersion, |
| 1933 | shouldFail: shouldFail, |
| 1934 | expectedError: expectedError, |
| 1935 | expectedLocalError: expectedLocalError, |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 1936 | }) |
| 1937 | } |
| 1938 | } |
| 1939 | } |
| 1940 | } |
| 1941 | |
David Benjamin | 5c24a1d | 2014-08-31 00:59:27 -0400 | [diff] [blame] | 1942 | func addD5BugTests() { |
| 1943 | testCases = append(testCases, testCase{ |
| 1944 | testType: serverTest, |
| 1945 | name: "D5Bug-NoQuirk-Reject", |
| 1946 | config: Config{ |
| 1947 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1948 | Bugs: ProtocolBugs{ |
| 1949 | SSL3RSAKeyExchange: true, |
| 1950 | }, |
| 1951 | }, |
| 1952 | shouldFail: true, |
| 1953 | expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:", |
| 1954 | }) |
| 1955 | testCases = append(testCases, testCase{ |
| 1956 | testType: serverTest, |
| 1957 | name: "D5Bug-Quirk-Normal", |
| 1958 | config: Config{ |
| 1959 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1960 | }, |
| 1961 | flags: []string{"-tls-d5-bug"}, |
| 1962 | }) |
| 1963 | testCases = append(testCases, testCase{ |
| 1964 | testType: serverTest, |
| 1965 | name: "D5Bug-Quirk-Bug", |
| 1966 | config: Config{ |
| 1967 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1968 | Bugs: ProtocolBugs{ |
| 1969 | SSL3RSAKeyExchange: true, |
| 1970 | }, |
| 1971 | }, |
| 1972 | flags: []string{"-tls-d5-bug"}, |
| 1973 | }) |
| 1974 | } |
| 1975 | |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 1976 | func addExtensionTests() { |
| 1977 | testCases = append(testCases, testCase{ |
| 1978 | testType: clientTest, |
| 1979 | name: "DuplicateExtensionClient", |
| 1980 | config: Config{ |
| 1981 | Bugs: ProtocolBugs{ |
| 1982 | DuplicateExtension: true, |
| 1983 | }, |
| 1984 | }, |
| 1985 | shouldFail: true, |
| 1986 | expectedLocalError: "remote error: error decoding message", |
| 1987 | }) |
| 1988 | testCases = append(testCases, testCase{ |
| 1989 | testType: serverTest, |
| 1990 | name: "DuplicateExtensionServer", |
| 1991 | config: Config{ |
| 1992 | Bugs: ProtocolBugs{ |
| 1993 | DuplicateExtension: true, |
| 1994 | }, |
| 1995 | }, |
| 1996 | shouldFail: true, |
| 1997 | expectedLocalError: "remote error: error decoding message", |
| 1998 | }) |
| 1999 | testCases = append(testCases, testCase{ |
| 2000 | testType: clientTest, |
| 2001 | name: "ServerNameExtensionClient", |
| 2002 | config: Config{ |
| 2003 | Bugs: ProtocolBugs{ |
| 2004 | ExpectServerName: "example.com", |
| 2005 | }, |
| 2006 | }, |
| 2007 | flags: []string{"-host-name", "example.com"}, |
| 2008 | }) |
| 2009 | testCases = append(testCases, testCase{ |
| 2010 | testType: clientTest, |
| 2011 | name: "ServerNameExtensionClient", |
| 2012 | config: Config{ |
| 2013 | Bugs: ProtocolBugs{ |
| 2014 | ExpectServerName: "mismatch.com", |
| 2015 | }, |
| 2016 | }, |
| 2017 | flags: []string{"-host-name", "example.com"}, |
| 2018 | shouldFail: true, |
| 2019 | expectedLocalError: "tls: unexpected server name", |
| 2020 | }) |
| 2021 | testCases = append(testCases, testCase{ |
| 2022 | testType: clientTest, |
| 2023 | name: "ServerNameExtensionClient", |
| 2024 | config: Config{ |
| 2025 | Bugs: ProtocolBugs{ |
| 2026 | ExpectServerName: "missing.com", |
| 2027 | }, |
| 2028 | }, |
| 2029 | shouldFail: true, |
| 2030 | expectedLocalError: "tls: unexpected server name", |
| 2031 | }) |
| 2032 | testCases = append(testCases, testCase{ |
| 2033 | testType: serverTest, |
| 2034 | name: "ServerNameExtensionServer", |
| 2035 | config: Config{ |
| 2036 | ServerName: "example.com", |
| 2037 | }, |
| 2038 | flags: []string{"-expect-server-name", "example.com"}, |
| 2039 | resumeSession: true, |
| 2040 | }) |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 2041 | testCases = append(testCases, testCase{ |
| 2042 | testType: clientTest, |
| 2043 | name: "ALPNClient", |
| 2044 | config: Config{ |
| 2045 | NextProtos: []string{"foo"}, |
| 2046 | }, |
| 2047 | flags: []string{ |
| 2048 | "-advertise-alpn", "\x03foo\x03bar\x03baz", |
| 2049 | "-expect-alpn", "foo", |
| 2050 | }, |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 2051 | expectedNextProto: "foo", |
| 2052 | expectedNextProtoType: alpn, |
| 2053 | resumeSession: true, |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 2054 | }) |
| 2055 | testCases = append(testCases, testCase{ |
| 2056 | testType: serverTest, |
| 2057 | name: "ALPNServer", |
| 2058 | config: Config{ |
| 2059 | NextProtos: []string{"foo", "bar", "baz"}, |
| 2060 | }, |
| 2061 | flags: []string{ |
| 2062 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 2063 | "-select-alpn", "foo", |
| 2064 | }, |
David Benjamin | fc7b086 | 2014-09-06 13:21:53 -0400 | [diff] [blame] | 2065 | expectedNextProto: "foo", |
| 2066 | expectedNextProtoType: alpn, |
| 2067 | resumeSession: true, |
| 2068 | }) |
| 2069 | // Test that the server prefers ALPN over NPN. |
| 2070 | testCases = append(testCases, testCase{ |
| 2071 | testType: serverTest, |
| 2072 | name: "ALPNServer-Preferred", |
| 2073 | config: Config{ |
| 2074 | NextProtos: []string{"foo", "bar", "baz"}, |
| 2075 | }, |
| 2076 | flags: []string{ |
| 2077 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 2078 | "-select-alpn", "foo", |
| 2079 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 2080 | }, |
| 2081 | expectedNextProto: "foo", |
| 2082 | expectedNextProtoType: alpn, |
| 2083 | resumeSession: true, |
| 2084 | }) |
| 2085 | testCases = append(testCases, testCase{ |
| 2086 | testType: serverTest, |
| 2087 | name: "ALPNServer-Preferred-Swapped", |
| 2088 | config: Config{ |
| 2089 | NextProtos: []string{"foo", "bar", "baz"}, |
| 2090 | Bugs: ProtocolBugs{ |
| 2091 | SwapNPNAndALPN: true, |
| 2092 | }, |
| 2093 | }, |
| 2094 | flags: []string{ |
| 2095 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 2096 | "-select-alpn", "foo", |
| 2097 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 2098 | }, |
| 2099 | expectedNextProto: "foo", |
| 2100 | expectedNextProtoType: alpn, |
| 2101 | resumeSession: true, |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 2102 | }) |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 2103 | // Resume with a corrupt ticket. |
| 2104 | testCases = append(testCases, testCase{ |
| 2105 | testType: serverTest, |
| 2106 | name: "CorruptTicket", |
| 2107 | config: Config{ |
| 2108 | Bugs: ProtocolBugs{ |
| 2109 | CorruptTicket: true, |
| 2110 | }, |
| 2111 | }, |
| 2112 | resumeSession: true, |
| 2113 | flags: []string{"-expect-session-miss"}, |
| 2114 | }) |
| 2115 | // Resume with an oversized session id. |
| 2116 | testCases = append(testCases, testCase{ |
| 2117 | testType: serverTest, |
| 2118 | name: "OversizedSessionId", |
| 2119 | config: Config{ |
| 2120 | Bugs: ProtocolBugs{ |
| 2121 | OversizedSessionId: true, |
| 2122 | }, |
| 2123 | }, |
| 2124 | resumeSession: true, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2125 | shouldFail: true, |
Adam Langley | 3831173 | 2014-10-16 19:04:35 -0700 | [diff] [blame] | 2126 | expectedError: ":DECODE_ERROR:", |
| 2127 | }) |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 2128 | // Basic DTLS-SRTP tests. Include fake profiles to ensure they |
| 2129 | // are ignored. |
| 2130 | testCases = append(testCases, testCase{ |
| 2131 | protocol: dtls, |
| 2132 | name: "SRTP-Client", |
| 2133 | config: Config{ |
| 2134 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 2135 | }, |
| 2136 | flags: []string{ |
| 2137 | "-srtp-profiles", |
| 2138 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 2139 | }, |
| 2140 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 2141 | }) |
| 2142 | testCases = append(testCases, testCase{ |
| 2143 | protocol: dtls, |
| 2144 | testType: serverTest, |
| 2145 | name: "SRTP-Server", |
| 2146 | config: Config{ |
| 2147 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 2148 | }, |
| 2149 | flags: []string{ |
| 2150 | "-srtp-profiles", |
| 2151 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 2152 | }, |
| 2153 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 2154 | }) |
| 2155 | // Test that the MKI is ignored. |
| 2156 | testCases = append(testCases, testCase{ |
| 2157 | protocol: dtls, |
| 2158 | testType: serverTest, |
| 2159 | name: "SRTP-Server-IgnoreMKI", |
| 2160 | config: Config{ |
| 2161 | SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80}, |
| 2162 | Bugs: ProtocolBugs{ |
| 2163 | SRTPMasterKeyIdentifer: "bogus", |
| 2164 | }, |
| 2165 | }, |
| 2166 | flags: []string{ |
| 2167 | "-srtp-profiles", |
| 2168 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 2169 | }, |
| 2170 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 2171 | }) |
| 2172 | // Test that SRTP isn't negotiated on the server if there were |
| 2173 | // no matching profiles. |
| 2174 | testCases = append(testCases, testCase{ |
| 2175 | protocol: dtls, |
| 2176 | testType: serverTest, |
| 2177 | name: "SRTP-Server-NoMatch", |
| 2178 | config: Config{ |
| 2179 | SRTPProtectionProfiles: []uint16{100, 101, 102}, |
| 2180 | }, |
| 2181 | flags: []string{ |
| 2182 | "-srtp-profiles", |
| 2183 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 2184 | }, |
| 2185 | expectedSRTPProtectionProfile: 0, |
| 2186 | }) |
| 2187 | // Test that the server returning an invalid SRTP profile is |
| 2188 | // flagged as an error by the client. |
| 2189 | testCases = append(testCases, testCase{ |
| 2190 | protocol: dtls, |
| 2191 | name: "SRTP-Client-NoMatch", |
| 2192 | config: Config{ |
| 2193 | Bugs: ProtocolBugs{ |
| 2194 | SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32, |
| 2195 | }, |
| 2196 | }, |
| 2197 | flags: []string{ |
| 2198 | "-srtp-profiles", |
| 2199 | "SRTP_AES128_CM_SHA1_80", |
| 2200 | }, |
| 2201 | shouldFail: true, |
| 2202 | expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:", |
| 2203 | }) |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 2204 | // Test OCSP stapling and SCT list. |
| 2205 | testCases = append(testCases, testCase{ |
| 2206 | name: "OCSPStapling", |
| 2207 | flags: []string{ |
| 2208 | "-enable-ocsp-stapling", |
| 2209 | "-expect-ocsp-response", |
| 2210 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 2211 | }, |
| 2212 | }) |
| 2213 | testCases = append(testCases, testCase{ |
| 2214 | name: "SignedCertificateTimestampList", |
| 2215 | flags: []string{ |
| 2216 | "-enable-signed-cert-timestamps", |
| 2217 | "-expect-signed-cert-timestamps", |
| 2218 | base64.StdEncoding.EncodeToString(testSCTList), |
| 2219 | }, |
| 2220 | }) |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 2221 | } |
| 2222 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 2223 | func addResumptionVersionTests() { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 2224 | for _, sessionVers := range tlsVersions { |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 2225 | for _, resumeVers := range tlsVersions { |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2226 | protocols := []protocol{tls} |
| 2227 | if sessionVers.hasDTLS && resumeVers.hasDTLS { |
| 2228 | protocols = append(protocols, dtls) |
David Benjamin | bdf5e72 | 2014-11-11 00:52:15 -0500 | [diff] [blame] | 2229 | } |
David Benjamin | 8b8c006 | 2014-11-23 02:47:52 -0500 | [diff] [blame] | 2230 | for _, protocol := range protocols { |
| 2231 | suffix := "-" + sessionVers.name + "-" + resumeVers.name |
| 2232 | if protocol == dtls { |
| 2233 | suffix += "-DTLS" |
| 2234 | } |
| 2235 | |
| 2236 | testCases = append(testCases, testCase{ |
| 2237 | protocol: protocol, |
| 2238 | name: "Resume-Client" + suffix, |
| 2239 | resumeSession: true, |
| 2240 | config: Config{ |
| 2241 | MaxVersion: sessionVers.version, |
| 2242 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 2243 | Bugs: ProtocolBugs{ |
| 2244 | AllowSessionVersionMismatch: true, |
| 2245 | }, |
| 2246 | }, |
| 2247 | expectedVersion: sessionVers.version, |
| 2248 | resumeConfig: &Config{ |
| 2249 | MaxVersion: resumeVers.version, |
| 2250 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 2251 | Bugs: ProtocolBugs{ |
| 2252 | AllowSessionVersionMismatch: true, |
| 2253 | }, |
| 2254 | }, |
| 2255 | expectedResumeVersion: resumeVers.version, |
| 2256 | }) |
| 2257 | |
| 2258 | testCases = append(testCases, testCase{ |
| 2259 | protocol: protocol, |
| 2260 | name: "Resume-Client-NoResume" + suffix, |
| 2261 | flags: []string{"-expect-session-miss"}, |
| 2262 | resumeSession: true, |
| 2263 | config: Config{ |
| 2264 | MaxVersion: sessionVers.version, |
| 2265 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 2266 | }, |
| 2267 | expectedVersion: sessionVers.version, |
| 2268 | resumeConfig: &Config{ |
| 2269 | MaxVersion: resumeVers.version, |
| 2270 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 2271 | }, |
| 2272 | newSessionsOnResume: true, |
| 2273 | expectedResumeVersion: resumeVers.version, |
| 2274 | }) |
| 2275 | |
| 2276 | var flags []string |
| 2277 | if sessionVers.version != resumeVers.version { |
| 2278 | flags = append(flags, "-expect-session-miss") |
| 2279 | } |
| 2280 | testCases = append(testCases, testCase{ |
| 2281 | protocol: protocol, |
| 2282 | testType: serverTest, |
| 2283 | name: "Resume-Server" + suffix, |
| 2284 | flags: flags, |
| 2285 | resumeSession: true, |
| 2286 | config: Config{ |
| 2287 | MaxVersion: sessionVers.version, |
| 2288 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 2289 | }, |
| 2290 | expectedVersion: sessionVers.version, |
| 2291 | resumeConfig: &Config{ |
| 2292 | MaxVersion: resumeVers.version, |
| 2293 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 2294 | }, |
| 2295 | expectedResumeVersion: resumeVers.version, |
| 2296 | }) |
| 2297 | } |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 2298 | } |
| 2299 | } |
| 2300 | } |
| 2301 | |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 2302 | func addRenegotiationTests() { |
| 2303 | testCases = append(testCases, testCase{ |
| 2304 | testType: serverTest, |
| 2305 | name: "Renegotiate-Server", |
| 2306 | flags: []string{"-renegotiate"}, |
| 2307 | shimWritesFirst: true, |
| 2308 | }) |
| 2309 | testCases = append(testCases, testCase{ |
| 2310 | testType: serverTest, |
| 2311 | name: "Renegotiate-Server-EmptyExt", |
| 2312 | config: Config{ |
| 2313 | Bugs: ProtocolBugs{ |
| 2314 | EmptyRenegotiationInfo: true, |
| 2315 | }, |
| 2316 | }, |
| 2317 | flags: []string{"-renegotiate"}, |
| 2318 | shimWritesFirst: true, |
| 2319 | shouldFail: true, |
| 2320 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 2321 | }) |
| 2322 | testCases = append(testCases, testCase{ |
| 2323 | testType: serverTest, |
| 2324 | name: "Renegotiate-Server-BadExt", |
| 2325 | config: Config{ |
| 2326 | Bugs: ProtocolBugs{ |
| 2327 | BadRenegotiationInfo: true, |
| 2328 | }, |
| 2329 | }, |
| 2330 | flags: []string{"-renegotiate"}, |
| 2331 | shimWritesFirst: true, |
| 2332 | shouldFail: true, |
| 2333 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 2334 | }) |
David Benjamin | ca6554b | 2014-11-08 12:31:52 -0500 | [diff] [blame] | 2335 | testCases = append(testCases, testCase{ |
| 2336 | testType: serverTest, |
| 2337 | name: "Renegotiate-Server-ClientInitiated", |
| 2338 | renegotiate: true, |
| 2339 | }) |
| 2340 | testCases = append(testCases, testCase{ |
| 2341 | testType: serverTest, |
| 2342 | name: "Renegotiate-Server-ClientInitiated-NoExt", |
| 2343 | renegotiate: true, |
| 2344 | config: Config{ |
| 2345 | Bugs: ProtocolBugs{ |
| 2346 | NoRenegotiationInfo: true, |
| 2347 | }, |
| 2348 | }, |
| 2349 | shouldFail: true, |
| 2350 | expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:", |
| 2351 | }) |
| 2352 | testCases = append(testCases, testCase{ |
| 2353 | testType: serverTest, |
| 2354 | name: "Renegotiate-Server-ClientInitiated-NoExt-Allowed", |
| 2355 | renegotiate: true, |
| 2356 | config: Config{ |
| 2357 | Bugs: ProtocolBugs{ |
| 2358 | NoRenegotiationInfo: true, |
| 2359 | }, |
| 2360 | }, |
| 2361 | flags: []string{"-allow-unsafe-legacy-renegotiation"}, |
| 2362 | }) |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 2363 | // TODO(agl): test the renegotiation info SCSV. |
Adam Langley | cf2d4f4 | 2014-10-28 19:06:14 -0700 | [diff] [blame] | 2364 | testCases = append(testCases, testCase{ |
| 2365 | name: "Renegotiate-Client", |
| 2366 | renegotiate: true, |
| 2367 | }) |
| 2368 | testCases = append(testCases, testCase{ |
| 2369 | name: "Renegotiate-Client-EmptyExt", |
| 2370 | renegotiate: true, |
| 2371 | config: Config{ |
| 2372 | Bugs: ProtocolBugs{ |
| 2373 | EmptyRenegotiationInfo: true, |
| 2374 | }, |
| 2375 | }, |
| 2376 | shouldFail: true, |
| 2377 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 2378 | }) |
| 2379 | testCases = append(testCases, testCase{ |
| 2380 | name: "Renegotiate-Client-BadExt", |
| 2381 | renegotiate: true, |
| 2382 | config: Config{ |
| 2383 | Bugs: ProtocolBugs{ |
| 2384 | BadRenegotiationInfo: true, |
| 2385 | }, |
| 2386 | }, |
| 2387 | shouldFail: true, |
| 2388 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 2389 | }) |
| 2390 | testCases = append(testCases, testCase{ |
| 2391 | name: "Renegotiate-Client-SwitchCiphers", |
| 2392 | renegotiate: true, |
| 2393 | config: Config{ |
| 2394 | CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2395 | }, |
| 2396 | renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2397 | }) |
| 2398 | testCases = append(testCases, testCase{ |
| 2399 | name: "Renegotiate-Client-SwitchCiphers2", |
| 2400 | renegotiate: true, |
| 2401 | config: Config{ |
| 2402 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2403 | }, |
| 2404 | renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA}, |
| 2405 | }) |
David Benjamin | c44b1df | 2014-11-23 12:11:01 -0500 | [diff] [blame] | 2406 | testCases = append(testCases, testCase{ |
| 2407 | name: "Renegotiate-SameClientVersion", |
| 2408 | renegotiate: true, |
| 2409 | config: Config{ |
| 2410 | MaxVersion: VersionTLS10, |
| 2411 | Bugs: ProtocolBugs{ |
| 2412 | RequireSameRenegoClientVersion: true, |
| 2413 | }, |
| 2414 | }, |
| 2415 | }) |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 2416 | } |
| 2417 | |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 2418 | func addDTLSReplayTests() { |
| 2419 | // Test that sequence number replays are detected. |
| 2420 | testCases = append(testCases, testCase{ |
| 2421 | protocol: dtls, |
| 2422 | name: "DTLS-Replay", |
| 2423 | replayWrites: true, |
| 2424 | }) |
| 2425 | |
| 2426 | // Test the outgoing sequence number skipping by values larger |
| 2427 | // than the retransmit window. |
| 2428 | testCases = append(testCases, testCase{ |
| 2429 | protocol: dtls, |
| 2430 | name: "DTLS-Replay-LargeGaps", |
| 2431 | config: Config{ |
| 2432 | Bugs: ProtocolBugs{ |
| 2433 | SequenceNumberIncrement: 127, |
| 2434 | }, |
| 2435 | }, |
| 2436 | replayWrites: true, |
| 2437 | }) |
| 2438 | } |
| 2439 | |
Feng Lu | 41aa325 | 2014-11-21 22:47:56 -0800 | [diff] [blame] | 2440 | func addFastRadioPaddingTests() { |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 2441 | testCases = append(testCases, testCase{ |
| 2442 | protocol: tls, |
| 2443 | name: "FastRadio-Padding", |
Feng Lu | 41aa325 | 2014-11-21 22:47:56 -0800 | [diff] [blame] | 2444 | config: Config{ |
| 2445 | Bugs: ProtocolBugs{ |
| 2446 | RequireFastradioPadding: true, |
| 2447 | }, |
| 2448 | }, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 2449 | flags: []string{"-fastradio-padding"}, |
Feng Lu | 41aa325 | 2014-11-21 22:47:56 -0800 | [diff] [blame] | 2450 | }) |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 2451 | testCases = append(testCases, testCase{ |
| 2452 | protocol: dtls, |
| 2453 | name: "FastRadio-Padding", |
Feng Lu | 41aa325 | 2014-11-21 22:47:56 -0800 | [diff] [blame] | 2454 | config: Config{ |
| 2455 | Bugs: ProtocolBugs{ |
| 2456 | RequireFastradioPadding: true, |
| 2457 | }, |
| 2458 | }, |
David Benjamin | 1e29a6b | 2014-12-10 02:27:24 -0500 | [diff] [blame] | 2459 | flags: []string{"-fastradio-padding"}, |
Feng Lu | 41aa325 | 2014-11-21 22:47:56 -0800 | [diff] [blame] | 2460 | }) |
| 2461 | } |
| 2462 | |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 2463 | var testHashes = []struct { |
| 2464 | name string |
| 2465 | id uint8 |
| 2466 | }{ |
| 2467 | {"SHA1", hashSHA1}, |
| 2468 | {"SHA224", hashSHA224}, |
| 2469 | {"SHA256", hashSHA256}, |
| 2470 | {"SHA384", hashSHA384}, |
| 2471 | {"SHA512", hashSHA512}, |
| 2472 | } |
| 2473 | |
| 2474 | func addSigningHashTests() { |
| 2475 | // Make sure each hash works. Include some fake hashes in the list and |
| 2476 | // ensure they're ignored. |
| 2477 | for _, hash := range testHashes { |
| 2478 | testCases = append(testCases, testCase{ |
| 2479 | name: "SigningHash-ClientAuth-" + hash.name, |
| 2480 | config: Config{ |
| 2481 | ClientAuth: RequireAnyClientCert, |
| 2482 | SignatureAndHashes: []signatureAndHash{ |
| 2483 | {signatureRSA, 42}, |
| 2484 | {signatureRSA, hash.id}, |
| 2485 | {signatureRSA, 255}, |
| 2486 | }, |
| 2487 | }, |
| 2488 | flags: []string{ |
| 2489 | "-cert-file", rsaCertificateFile, |
| 2490 | "-key-file", rsaKeyFile, |
| 2491 | }, |
| 2492 | }) |
| 2493 | |
| 2494 | testCases = append(testCases, testCase{ |
| 2495 | testType: serverTest, |
| 2496 | name: "SigningHash-ServerKeyExchange-Sign-" + hash.name, |
| 2497 | config: Config{ |
| 2498 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2499 | SignatureAndHashes: []signatureAndHash{ |
| 2500 | {signatureRSA, 42}, |
| 2501 | {signatureRSA, hash.id}, |
| 2502 | {signatureRSA, 255}, |
| 2503 | }, |
| 2504 | }, |
| 2505 | }) |
| 2506 | } |
| 2507 | |
| 2508 | // Test that hash resolution takes the signature type into account. |
| 2509 | testCases = append(testCases, testCase{ |
| 2510 | name: "SigningHash-ClientAuth-SignatureType", |
| 2511 | config: Config{ |
| 2512 | ClientAuth: RequireAnyClientCert, |
| 2513 | SignatureAndHashes: []signatureAndHash{ |
| 2514 | {signatureECDSA, hashSHA512}, |
| 2515 | {signatureRSA, hashSHA384}, |
| 2516 | {signatureECDSA, hashSHA1}, |
| 2517 | }, |
| 2518 | }, |
| 2519 | flags: []string{ |
| 2520 | "-cert-file", rsaCertificateFile, |
| 2521 | "-key-file", rsaKeyFile, |
| 2522 | }, |
| 2523 | }) |
| 2524 | |
| 2525 | testCases = append(testCases, testCase{ |
| 2526 | testType: serverTest, |
| 2527 | name: "SigningHash-ServerKeyExchange-SignatureType", |
| 2528 | config: Config{ |
| 2529 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2530 | SignatureAndHashes: []signatureAndHash{ |
| 2531 | {signatureECDSA, hashSHA512}, |
| 2532 | {signatureRSA, hashSHA384}, |
| 2533 | {signatureECDSA, hashSHA1}, |
| 2534 | }, |
| 2535 | }, |
| 2536 | }) |
| 2537 | |
| 2538 | // Test that, if the list is missing, the peer falls back to SHA-1. |
| 2539 | testCases = append(testCases, testCase{ |
| 2540 | name: "SigningHash-ClientAuth-Fallback", |
| 2541 | config: Config{ |
| 2542 | ClientAuth: RequireAnyClientCert, |
| 2543 | SignatureAndHashes: []signatureAndHash{ |
| 2544 | {signatureRSA, hashSHA1}, |
| 2545 | }, |
| 2546 | Bugs: ProtocolBugs{ |
| 2547 | NoSignatureAndHashes: true, |
| 2548 | }, |
| 2549 | }, |
| 2550 | flags: []string{ |
| 2551 | "-cert-file", rsaCertificateFile, |
| 2552 | "-key-file", rsaKeyFile, |
| 2553 | }, |
| 2554 | }) |
| 2555 | |
| 2556 | testCases = append(testCases, testCase{ |
| 2557 | testType: serverTest, |
| 2558 | name: "SigningHash-ServerKeyExchange-Fallback", |
| 2559 | config: Config{ |
| 2560 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2561 | SignatureAndHashes: []signatureAndHash{ |
| 2562 | {signatureRSA, hashSHA1}, |
| 2563 | }, |
| 2564 | Bugs: ProtocolBugs{ |
| 2565 | NoSignatureAndHashes: true, |
| 2566 | }, |
| 2567 | }, |
| 2568 | }) |
| 2569 | } |
| 2570 | |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 2571 | // timeouts is the retransmit schedule for BoringSSL. It doubles and |
| 2572 | // caps at 60 seconds. On the 13th timeout, it gives up. |
| 2573 | var timeouts = []time.Duration{ |
| 2574 | 1 * time.Second, |
| 2575 | 2 * time.Second, |
| 2576 | 4 * time.Second, |
| 2577 | 8 * time.Second, |
| 2578 | 16 * time.Second, |
| 2579 | 32 * time.Second, |
| 2580 | 60 * time.Second, |
| 2581 | 60 * time.Second, |
| 2582 | 60 * time.Second, |
| 2583 | 60 * time.Second, |
| 2584 | 60 * time.Second, |
| 2585 | 60 * time.Second, |
| 2586 | 60 * time.Second, |
| 2587 | } |
| 2588 | |
| 2589 | func addDTLSRetransmitTests() { |
| 2590 | // Test that this is indeed the timeout schedule. Stress all |
| 2591 | // four patterns of handshake. |
| 2592 | for i := 1; i < len(timeouts); i++ { |
| 2593 | number := strconv.Itoa(i) |
| 2594 | testCases = append(testCases, testCase{ |
| 2595 | protocol: dtls, |
| 2596 | name: "DTLS-Retransmit-Client-" + number, |
| 2597 | config: Config{ |
| 2598 | Bugs: ProtocolBugs{ |
| 2599 | TimeoutSchedule: timeouts[:i], |
| 2600 | }, |
| 2601 | }, |
| 2602 | resumeSession: true, |
| 2603 | flags: []string{"-async"}, |
| 2604 | }) |
| 2605 | testCases = append(testCases, testCase{ |
| 2606 | protocol: dtls, |
| 2607 | testType: serverTest, |
| 2608 | name: "DTLS-Retransmit-Server-" + number, |
| 2609 | config: Config{ |
| 2610 | Bugs: ProtocolBugs{ |
| 2611 | TimeoutSchedule: timeouts[:i], |
| 2612 | }, |
| 2613 | }, |
| 2614 | resumeSession: true, |
| 2615 | flags: []string{"-async"}, |
| 2616 | }) |
| 2617 | } |
| 2618 | |
| 2619 | // Test that exceeding the timeout schedule hits a read |
| 2620 | // timeout. |
| 2621 | testCases = append(testCases, testCase{ |
| 2622 | protocol: dtls, |
| 2623 | name: "DTLS-Retransmit-Timeout", |
| 2624 | config: Config{ |
| 2625 | Bugs: ProtocolBugs{ |
| 2626 | TimeoutSchedule: timeouts, |
| 2627 | }, |
| 2628 | }, |
| 2629 | resumeSession: true, |
| 2630 | flags: []string{"-async"}, |
| 2631 | shouldFail: true, |
| 2632 | expectedError: ":READ_TIMEOUT_EXPIRED:", |
| 2633 | }) |
| 2634 | |
| 2635 | // Test that timeout handling has a fudge factor, due to API |
| 2636 | // problems. |
| 2637 | testCases = append(testCases, testCase{ |
| 2638 | protocol: dtls, |
| 2639 | name: "DTLS-Retransmit-Fudge", |
| 2640 | config: Config{ |
| 2641 | Bugs: ProtocolBugs{ |
| 2642 | TimeoutSchedule: []time.Duration{ |
| 2643 | timeouts[0] - 10*time.Millisecond, |
| 2644 | }, |
| 2645 | }, |
| 2646 | }, |
| 2647 | resumeSession: true, |
| 2648 | flags: []string{"-async"}, |
| 2649 | }) |
| 2650 | } |
| 2651 | |
David Benjamin | 884fdf1 | 2014-08-02 15:28:23 -0400 | [diff] [blame] | 2652 | func worker(statusChan chan statusMsg, c chan *testCase, buildDir string, wg *sync.WaitGroup) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2653 | defer wg.Done() |
| 2654 | |
| 2655 | for test := range c { |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame] | 2656 | var err error |
| 2657 | |
| 2658 | if *mallocTest < 0 { |
| 2659 | statusChan <- statusMsg{test: test, started: true} |
| 2660 | err = runTest(test, buildDir, -1) |
| 2661 | } else { |
| 2662 | for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ { |
| 2663 | statusChan <- statusMsg{test: test, started: true} |
| 2664 | if err = runTest(test, buildDir, mallocNumToFail); err != errMoreMallocs { |
| 2665 | if err != nil { |
| 2666 | fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err) |
| 2667 | } |
| 2668 | break |
| 2669 | } |
| 2670 | } |
| 2671 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2672 | statusChan <- statusMsg{test: test, err: err} |
| 2673 | } |
| 2674 | } |
| 2675 | |
| 2676 | type statusMsg struct { |
| 2677 | test *testCase |
| 2678 | started bool |
| 2679 | err error |
| 2680 | } |
| 2681 | |
| 2682 | func statusPrinter(doneChan chan struct{}, statusChan chan statusMsg, total int) { |
| 2683 | var started, done, failed, lineLen int |
| 2684 | defer close(doneChan) |
| 2685 | |
| 2686 | for msg := range statusChan { |
| 2687 | if msg.started { |
| 2688 | started++ |
| 2689 | } else { |
| 2690 | done++ |
| 2691 | } |
| 2692 | |
| 2693 | fmt.Printf("\x1b[%dD\x1b[K", lineLen) |
| 2694 | |
| 2695 | if msg.err != nil { |
| 2696 | fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err) |
| 2697 | failed++ |
| 2698 | } |
| 2699 | line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total) |
| 2700 | lineLen = len(line) |
| 2701 | os.Stdout.WriteString(line) |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | func main() { |
| 2706 | var flagTest *string = flag.String("test", "", "The name of a test to run, or empty to run all tests") |
David Benjamin | 2bc8e6f | 2014-08-02 15:22:37 -0400 | [diff] [blame] | 2707 | var flagNumWorkers *int = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.") |
David Benjamin | 884fdf1 | 2014-08-02 15:28:23 -0400 | [diff] [blame] | 2708 | var flagBuildDir *string = flag.String("build-dir", "../../../build", "The build directory to run the shim from.") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2709 | |
| 2710 | flag.Parse() |
| 2711 | |
| 2712 | addCipherSuiteTests() |
| 2713 | addBadECDSASignatureTests() |
Adam Langley | 80842bd | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2714 | addCBCPaddingTests() |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 2715 | addCBCSplittingTests() |
David Benjamin | 636293b | 2014-07-08 17:59:18 -0400 | [diff] [blame] | 2716 | addClientAuthTests() |
David Benjamin | 7e2e6cf | 2014-08-07 17:44:24 -0400 | [diff] [blame] | 2717 | addVersionNegotiationTests() |
David Benjamin | accb454 | 2014-12-12 23:44:33 -0500 | [diff] [blame] | 2718 | addMinimumVersionTests() |
David Benjamin | 5c24a1d | 2014-08-31 00:59:27 -0400 | [diff] [blame] | 2719 | addD5BugTests() |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 2720 | addExtensionTests() |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 2721 | addResumptionVersionTests() |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 2722 | addExtendedMasterSecretTests() |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 2723 | addRenegotiationTests() |
David Benjamin | 5e961c1 | 2014-11-07 01:48:35 -0500 | [diff] [blame] | 2724 | addDTLSReplayTests() |
David Benjamin | 000800a | 2014-11-14 01:43:59 -0500 | [diff] [blame] | 2725 | addSigningHashTests() |
Feng Lu | 41aa325 | 2014-11-21 22:47:56 -0800 | [diff] [blame] | 2726 | addFastRadioPaddingTests() |
David Benjamin | 83f9040 | 2015-01-27 01:09:43 -0500 | [diff] [blame] | 2727 | addDTLSRetransmitTests() |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 2728 | for _, async := range []bool{false, true} { |
| 2729 | for _, splitHandshake := range []bool{false, true} { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 2730 | for _, protocol := range []protocol{tls, dtls} { |
| 2731 | addStateMachineCoverageTests(async, splitHandshake, protocol) |
| 2732 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 2733 | } |
| 2734 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2735 | |
| 2736 | var wg sync.WaitGroup |
| 2737 | |
David Benjamin | 2bc8e6f | 2014-08-02 15:22:37 -0400 | [diff] [blame] | 2738 | numWorkers := *flagNumWorkers |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2739 | |
| 2740 | statusChan := make(chan statusMsg, numWorkers) |
| 2741 | testChan := make(chan *testCase, numWorkers) |
| 2742 | doneChan := make(chan struct{}) |
| 2743 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2744 | go statusPrinter(doneChan, statusChan, len(testCases)) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2745 | |
| 2746 | for i := 0; i < numWorkers; i++ { |
| 2747 | wg.Add(1) |
David Benjamin | 884fdf1 | 2014-08-02 15:28:23 -0400 | [diff] [blame] | 2748 | go worker(statusChan, testChan, *flagBuildDir, &wg) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2749 | } |
| 2750 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 2751 | for i := range testCases { |
| 2752 | if len(*flagTest) == 0 || *flagTest == testCases[i].name { |
| 2753 | testChan <- &testCases[i] |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2754 | } |
| 2755 | } |
| 2756 | |
| 2757 | close(testChan) |
| 2758 | wg.Wait() |
| 2759 | close(statusChan) |
| 2760 | <-doneChan |
| 2761 | |
| 2762 | fmt.Printf("\n") |
| 2763 | } |