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