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