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