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