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