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