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