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