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