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