| // |
| 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 |
| 15 | package runner |
| 16 |
| 17 | import ( |
| 18 | "bytes" |
| 19 | "crypto" |
| 20 | "crypto/ecdsa" |
| 21 | "crypto/elliptic" |
| 22 | "crypto/rand" |
| 23 | "crypto/rsa" |
| 24 | "crypto/x509" |
| 25 | "crypto/x509/pkix" |
| 26 | "encoding/base64" |
| 27 | "encoding/binary" |
| 28 | "encoding/hex" |
| 29 | "encoding/json" |
| 30 | "encoding/pem" |
| 31 | "errors" |
| 32 | "flag" |
| 33 | "fmt" |
| 34 | "io" |
| 35 | "io/ioutil" |
| 36 | "math/big" |
| 37 | "net" |
| 38 | "os" |
| 39 | "os/exec" |
| 40 | "path" |
| 41 | "path/filepath" |
| 42 | "runtime" |
| 43 | "strconv" |
| 44 | "strings" |
| 45 | "sync" |
| 46 | "syscall" |
| 47 | "time" |
| 48 |
| 49 | "boringssl.googlesource.com/boringssl/util/testresult" |
| 50 | ) |
| 51 |
| 52 | var ( |
| 53 | useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind") |
| 54 | useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb") |
| 55 | useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb") |
| 56 | flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection") |
| 57 | mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.") |
| 58 | 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.") |
| 59 | jsonOutput = flag.String("json-output", "", "The file to output JSON results to.") |
| 60 | pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.") |
| 61 | testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests") |
| 62 | numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.") |
| 63 | shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.") |
| 64 | handshakerPath = flag.String("handshaker-path", "../../../build/ssl/test/handshaker", "The location of the handshaker binary.") |
| 65 | resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.") |
| 66 | fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.") |
| 67 | transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.") |
| 68 | idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.") |
| 69 | deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.") |
| 70 | allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.") |
| 71 | looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.") |
| 72 | shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.") |
| 73 | includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.") |
| 74 | repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.") |
| 75 | ) |
| 76 |
| 77 | // ShimConfigurations is used with the “json” package and represents a shim |
| 78 | // config file. |
| 79 | type ShimConfiguration struct { |
| 80 | // DisabledTests maps from a glob-based pattern to a freeform string. |
| 81 | // The glob pattern is used to exclude tests from being run and the |
| 82 | // freeform string is unparsed but expected to explain why the test is |
| 83 | // disabled. |
| 84 | DisabledTests map[string]string |
| 85 |
| 86 | // ErrorMap maps from expected error strings to the correct error |
| 87 | // string for the shim in question. For example, it might map |
| 88 | // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something |
| 89 | // like “SSL_ERROR_NO_CYPHER_OVERLAP”. |
| 90 | ErrorMap map[string]string |
| 91 |
| 92 | // HalfRTTTickets is the number of half-RTT tickets the client should |
| 93 | // expect before half-RTT data when testing 0-RTT. |
| 94 | HalfRTTTickets int |
| 95 | } |
| 96 |
| 97 | // Setup shimConfig defaults aligning with BoringSSL. |
| 98 | var shimConfig ShimConfiguration = ShimConfiguration{ |
| 99 | HalfRTTTickets: 2, |
| 100 | } |
| 101 |
| 102 | type testCert int |
| 103 |
| 104 | const ( |
| 105 | testCertRSA testCert = iota |
| 106 | testCertRSA1024 |
| 107 | testCertRSAChain |
| 108 | testCertECDSAP224 |
| 109 | testCertECDSAP256 |
| 110 | testCertECDSAP384 |
| 111 | testCertECDSAP521 |
| 112 | testCertEd25519 |
| 113 | ) |
| 114 |
| 115 | const ( |
| 116 | rsaCertificateFile = "cert.pem" |
| 117 | rsa1024CertificateFile = "rsa_1024_cert.pem" |
| 118 | rsaChainCertificateFile = "rsa_chain_cert.pem" |
| 119 | ecdsaP224CertificateFile = "ecdsa_p224_cert.pem" |
| 120 | ecdsaP256CertificateFile = "ecdsa_p256_cert.pem" |
| 121 | ecdsaP384CertificateFile = "ecdsa_p384_cert.pem" |
| 122 | ecdsaP521CertificateFile = "ecdsa_p521_cert.pem" |
| 123 | ed25519CertificateFile = "ed25519_cert.pem" |
| 124 | ) |
| 125 |
| 126 | const ( |
| 127 | rsaKeyFile = "key.pem" |
| 128 | rsa1024KeyFile = "rsa_1024_key.pem" |
| 129 | rsaChainKeyFile = "rsa_chain_key.pem" |
| 130 | ecdsaP224KeyFile = "ecdsa_p224_key.pem" |
| 131 | ecdsaP256KeyFile = "ecdsa_p256_key.pem" |
| 132 | ecdsaP384KeyFile = "ecdsa_p384_key.pem" |
| 133 | ecdsaP521KeyFile = "ecdsa_p521_key.pem" |
| 134 | ed25519KeyFile = "ed25519_key.pem" |
| 135 | channelIDKeyFile = "channel_id_key.pem" |
| 136 | ) |
| 137 |
| 138 | var ( |
| 139 | rsaCertificate Certificate |
| 140 | rsa1024Certificate Certificate |
| 141 | rsaChainCertificate Certificate |
| 142 | ecdsaP224Certificate Certificate |
| 143 | ecdsaP256Certificate Certificate |
| 144 | ecdsaP384Certificate Certificate |
| 145 | ecdsaP521Certificate Certificate |
| 146 | ed25519Certificate Certificate |
| 147 | garbageCertificate Certificate |
| 148 | ) |
| 149 |
| 150 | var testCerts = []struct { |
| 151 | id testCert |
| 152 | certFile, keyFile string |
| 153 | cert *Certificate |
| 154 | }{ |
| 155 | { |
| 156 | id: testCertRSA, |
| 157 | certFile: rsaCertificateFile, |
| 158 | keyFile: rsaKeyFile, |
| 159 | cert: &rsaCertificate, |
| 160 | }, |
| 161 | { |
| 162 | id: testCertRSA1024, |
| 163 | certFile: rsa1024CertificateFile, |
| 164 | keyFile: rsa1024KeyFile, |
| 165 | cert: &rsa1024Certificate, |
| 166 | }, |
| 167 | { |
| 168 | id: testCertRSAChain, |
| 169 | certFile: rsaChainCertificateFile, |
| 170 | keyFile: rsaChainKeyFile, |
| 171 | cert: &rsaChainCertificate, |
| 172 | }, |
| 173 | { |
| 174 | id: testCertECDSAP224, |
| 175 | certFile: ecdsaP224CertificateFile, |
| 176 | keyFile: ecdsaP224KeyFile, |
| 177 | cert: &ecdsaP224Certificate, |
| 178 | }, |
| 179 | { |
| 180 | id: testCertECDSAP256, |
| 181 | certFile: ecdsaP256CertificateFile, |
| 182 | keyFile: ecdsaP256KeyFile, |
| 183 | cert: &ecdsaP256Certificate, |
| 184 | }, |
| 185 | { |
| 186 | id: testCertECDSAP384, |
| 187 | certFile: ecdsaP384CertificateFile, |
| 188 | keyFile: ecdsaP384KeyFile, |
| 189 | cert: &ecdsaP384Certificate, |
| 190 | }, |
| 191 | { |
| 192 | id: testCertECDSAP521, |
| 193 | certFile: ecdsaP521CertificateFile, |
| 194 | keyFile: ecdsaP521KeyFile, |
| 195 | cert: &ecdsaP521Certificate, |
| 196 | }, |
| 197 | { |
| 198 | id: testCertEd25519, |
| 199 | certFile: ed25519CertificateFile, |
| 200 | keyFile: ed25519KeyFile, |
| 201 | cert: &ed25519Certificate, |
| 202 | }, |
| 203 | } |
| 204 |
| 205 | var channelIDKey *ecdsa.PrivateKey |
| 206 | var channelIDBytes []byte |
| 207 |
| 208 | var testOCSPResponse = []byte{1, 2, 3, 4} |
| 209 | var testOCSPResponse2 = []byte{5, 6, 7, 8} |
| 210 | var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8} |
| 211 | var testSCTList2 = []byte{0, 6, 0, 4, 1, 2, 3, 4} |
| 212 |
| 213 | var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...) |
| 214 | var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...) |
| 215 |
| 216 | func initCertificates() { |
| 217 | for i := range testCerts { |
| 218 | cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile)) |
| 219 | if err != nil { |
| 220 | panic(err) |
| 221 | } |
| 222 | cert.OCSPStaple = testOCSPResponse |
| 223 | cert.SignedCertificateTimestampList = testSCTList |
| 224 | *testCerts[i].cert = cert |
| 225 | } |
| 226 |
| 227 | channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile)) |
| 228 | if err != nil { |
| 229 | panic(err) |
| 230 | } |
| 231 | channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock) |
| 232 | if channelIDDERBlock.Type != "EC PRIVATE KEY" { |
| 233 | panic("bad key type") |
| 234 | } |
| 235 | channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes) |
| 236 | if err != nil { |
| 237 | panic(err) |
| 238 | } |
| 239 | if channelIDKey.Curve != elliptic.P256() { |
| 240 | panic("bad curve") |
| 241 | } |
| 242 |
| 243 | channelIDBytes = make([]byte, 64) |
| 244 | writeIntPadded(channelIDBytes[:32], channelIDKey.X) |
| 245 | writeIntPadded(channelIDBytes[32:], channelIDKey.Y) |
| 246 |
| 247 | garbageCertificate.Certificate = [][]byte{[]byte("GARBAGE")} |
| 248 | garbageCertificate.PrivateKey = rsaCertificate.PrivateKey |
| 249 | } |
| 250 |
| 251 | // delegatedCredentialConfig specifies the shape of a delegated credential, not |
| 252 | // including the keys themselves. |
| 253 | type delegatedCredentialConfig struct { |
| 254 | // lifetime is the amount of time, from the notBefore of the parent |
| 255 | // certificate, that the delegated credential is valid for. If zero, then 24 |
| 256 | // hours is assumed. |
| 257 | lifetime time.Duration |
| 258 | // expectedAlgo is the signature scheme that should be used with this |
| 259 | // delegated credential. If zero, ECDSA with P-256 is assumed. |
| 260 | expectedAlgo signatureAlgorithm |
| 261 | // tlsVersion is the version of TLS that should be used with this delegated |
| 262 | // credential. If zero, TLS 1.3 is assumed. |
| 263 | tlsVersion uint16 |
| 264 | // algo is the signature algorithm that the delegated credential itself is |
| 265 | // signed with. Cannot be zero. |
| 266 | algo signatureAlgorithm |
| 267 | } |
| 268 |
| 269 | func loadRSAPrivateKey(filename string) (priv *rsa.PrivateKey, privPKCS8 []byte, err error) { |
| 270 | pemPath := path.Join(*resourceDir, filename) |
| 271 | pemBytes, err := ioutil.ReadFile(pemPath) |
| 272 | if err != nil { |
| 273 | return nil, nil, err |
| 274 | } |
| 275 |
| 276 | block, _ := pem.Decode(pemBytes) |
| 277 | if block == nil { |
| 278 | return nil, nil, fmt.Errorf("no PEM block found in %q", pemPath) |
| 279 | } |
| 280 | privPKCS8 = block.Bytes |
| 281 |
| 282 | parsed, err := x509.ParsePKCS8PrivateKey(privPKCS8) |
| 283 | if err != nil { |
| 284 | return nil, nil, fmt.Errorf("failed to parse PKCS#8 key from %q", pemPath) |
| 285 | } |
| 286 |
| 287 | priv, ok := parsed.(*rsa.PrivateKey) |
| 288 | if !ok { |
| 289 | return nil, nil, fmt.Errorf("found %T in %q rather than an RSA private key", parsed, pemPath) |
| 290 | } |
| 291 |
| 292 | return priv, privPKCS8, nil |
| 293 | } |
| 294 |
| 295 | func createDelegatedCredential(config delegatedCredentialConfig, parentDER []byte, parentPriv crypto.PrivateKey) (dc, privPKCS8 []uint8, err error) { |
| 296 | expectedAlgo := config.expectedAlgo |
| 297 | if expectedAlgo == signatureAlgorithm(0) { |
| 298 | expectedAlgo = signatureECDSAWithP256AndSHA256 |
| 299 | } |
| 300 |
| 301 | var pub crypto.PublicKey |
| 302 |
| 303 | switch expectedAlgo { |
| 304 | case signatureRSAPKCS1WithMD5, signatureRSAPKCS1WithSHA1, signatureRSAPKCS1WithSHA256, signatureRSAPKCS1WithSHA384, signatureRSAPKCS1WithSHA512, signatureRSAPSSWithSHA256, signatureRSAPSSWithSHA384, signatureRSAPSSWithSHA512: |
| 305 | // RSA keys are expensive to generate so load from disk instead. |
| 306 | var priv *rsa.PrivateKey |
| 307 | if priv, privPKCS8, err = loadRSAPrivateKey(rsaKeyFile); err != nil { |
| 308 | return nil, nil, err |
| 309 | } |
| 310 |
| 311 | pub = &priv.PublicKey |
| 312 |
| 313 | case signatureECDSAWithSHA1, signatureECDSAWithP256AndSHA256, signatureECDSAWithP384AndSHA384, signatureECDSAWithP521AndSHA512: |
| 314 | var curve elliptic.Curve |
| 315 | switch expectedAlgo { |
| 316 | case signatureECDSAWithSHA1, signatureECDSAWithP256AndSHA256: |
| 317 | curve = elliptic.P256() |
| 318 | case signatureECDSAWithP384AndSHA384: |
| 319 | curve = elliptic.P384() |
| 320 | case signatureECDSAWithP521AndSHA512: |
| 321 | curve = elliptic.P521() |
| 322 | default: |
| 323 | panic("internal error") |
| 324 | } |
| 325 |
| 326 | priv, err := ecdsa.GenerateKey(curve, rand.Reader) |
| 327 | if err != nil { |
| 328 | return nil, nil, err |
| 329 | } |
| 330 |
| 331 | if privPKCS8, err = x509.MarshalPKCS8PrivateKey(priv); err != nil { |
| 332 | return nil, nil, err |
| 333 | } |
| 334 |
| 335 | pub = &priv.PublicKey |
| 336 |
| 337 | default: |
| 338 | return nil, nil, fmt.Errorf("unsupported expected signature algorithm: %x", expectedAlgo) |
| 339 | } |
| 340 |
| 341 | lifetime := config.lifetime |
| 342 | if lifetime == 0 { |
| 343 | lifetime = 24 * time.Hour |
| 344 | } |
| 345 | lifetimeSecs := int64(lifetime.Seconds()) |
| 346 | if lifetimeSecs > 1<<32 { |
| 347 | return nil, nil, fmt.Errorf("lifetime %s is too long to be expressed", lifetime) |
| 348 | } |
| 349 | tlsVersion := config.tlsVersion |
| 350 | if tlsVersion == 0 { |
| 351 | tlsVersion = VersionTLS13 |
| 352 | } |
| 353 |
| 354 | if tlsVersion < VersionTLS13 { |
| 355 | return nil, nil, fmt.Errorf("delegated credentials require TLS 1.3") |
| 356 | } |
| 357 |
| 358 | // https://tools.ietf.org/html/draft-ietf-tls-subcerts-03#section-3 |
| 359 | dc = append(dc, byte(lifetimeSecs>>24), byte(lifetimeSecs>>16), byte(lifetimeSecs>>8), byte(lifetimeSecs)) |
| 360 | dc = append(dc, byte(expectedAlgo>>8), byte(expectedAlgo)) |
| 361 |
| 362 | pubBytes, err := x509.MarshalPKIXPublicKey(pub) |
| 363 | if err != nil { |
| 364 | return nil, nil, err |
| 365 | } |
| 366 |
| 367 | dc = append(dc, byte(len(pubBytes)>>16), byte(len(pubBytes)>>8), byte(len(pubBytes))) |
| 368 | dc = append(dc, pubBytes...) |
| 369 |
| 370 | var dummyConfig Config |
| 371 | parentSigner, err := getSigner(tlsVersion, parentPriv, &dummyConfig, config.algo, false /* not for verification */) |
| 372 | if err != nil { |
| 373 | return nil, nil, err |
| 374 | } |
| 375 |
| 376 | parentSignature, err := parentSigner.signMessage(parentPriv, &dummyConfig, delegatedCredentialSignedMessage(dc, config.algo, parentDER)) |
| 377 | if err != nil { |
| 378 | return nil, nil, err |
| 379 | } |
| 380 |
| 381 | dc = append(dc, byte(config.algo>>8), byte(config.algo)) |
| 382 | dc = append(dc, byte(len(parentSignature)>>8), byte(len(parentSignature))) |
| 383 | dc = append(dc, parentSignature...) |
| 384 |
| 385 | return dc, privPKCS8, nil |
| 386 | } |
| 387 |
| 388 | func getRunnerCertificate(t testCert) Certificate { |
| 389 | for _, cert := range testCerts { |
| 390 | if cert.id == t { |
| 391 | return *cert.cert |
| 392 | } |
| 393 | } |
| 394 | panic("Unknown test certificate") |
| 395 | } |
| 396 |
| 397 | func getShimCertificate(t testCert) string { |
| 398 | for _, cert := range testCerts { |
| 399 | if cert.id == t { |
| 400 | return cert.certFile |
| 401 | } |
| 402 | } |
| 403 | panic("Unknown test certificate") |
| 404 | } |
| 405 |
| 406 | func getShimKey(t testCert) string { |
| 407 | for _, cert := range testCerts { |
| 408 | if cert.id == t { |
| 409 | return cert.keyFile |
| 410 | } |
| 411 | } |
| 412 | panic("Unknown test certificate") |
| 413 | } |
| 414 |
| 415 | // recordVersionToWire maps a record-layer protocol version to its wire |
| 416 | // representation. |
| 417 | func recordVersionToWire(vers uint16, protocol protocol) uint16 { |
| 418 | if protocol == dtls { |
| 419 | switch vers { |
| 420 | case VersionTLS12: |
| 421 | return VersionDTLS12 |
| 422 | case VersionTLS10: |
| 423 | return VersionDTLS10 |
| 424 | } |
| 425 | } else { |
| 426 | switch vers { |
| 427 | case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12: |
| 428 | return vers |
| 429 | } |
| 430 | } |
| 431 |
| 432 | panic("unknown version") |
| 433 | } |
| 434 |
| 435 | // encodeDERValues encodes a series of bytestrings in comma-separated-hex form. |
| 436 | func encodeDERValues(values [][]byte) string { |
| 437 | var ret string |
| 438 | for i, v := range values { |
| 439 | if i > 0 { |
| 440 | ret += "," |
| 441 | } |
| 442 | ret += hex.EncodeToString(v) |
| 443 | } |
| 444 |
| 445 | return ret |
| 446 | } |
| 447 |
| 448 | func decodeHexOrPanic(in string) []byte { |
| 449 | ret, err := hex.DecodeString(in) |
| 450 | if err != nil { |
| 451 | panic(err) |
| 452 | } |
| 453 | return ret |
| 454 | } |
| 455 |
| 456 | type testType int |
| 457 |
| 458 | const ( |
| 459 | clientTest testType = iota |
| 460 | serverTest |
| 461 | ) |
| 462 |
| 463 | type protocol int |
| 464 |
| 465 | const ( |
| 466 | tls protocol = iota |
| 467 | dtls |
| 468 | ) |
| 469 |
| 470 | const ( |
| 471 | alpn = 1 |
| 472 | npn = 2 |
| 473 | ) |
| 474 |
| 475 | type testCase struct { |
| 476 | testType testType |
| 477 | protocol protocol |
| 478 | name string |
| 479 | config Config |
| 480 | shouldFail bool |
| 481 | expectedError string |
| 482 | // expectedLocalError, if not empty, contains a substring that must be |
| 483 | // found in the local error. |
| 484 | expectedLocalError string |
| 485 | // expectedVersion, if non-zero, specifies the TLS version that must be |
| 486 | // negotiated. |
| 487 | expectedVersion uint16 |
| 488 | // expectedResumeVersion, if non-zero, specifies the TLS version that |
| 489 | // must be negotiated on resumption. If zero, expectedVersion is used. |
| 490 | expectedResumeVersion uint16 |
| 491 | // expectedCipher, if non-zero, specifies the TLS cipher suite that |
| 492 | // should be negotiated. |
| 493 | expectedCipher uint16 |
| 494 | // expectChannelID controls whether the connection should have |
| 495 | // negotiated a Channel ID with channelIDKey. |
| 496 | expectChannelID bool |
| 497 | // expectTokenBinding controls whether the connection should have |
| 498 | // negotiated Token Binding. |
| 499 | expectTokenBinding bool |
| 500 | // expectedTokenBindingParam is the Token Binding parameter that should |
| 501 | // have been negotiated (if expectTokenBinding is true). |
| 502 | expectedTokenBindingParam uint8 |
| 503 | // expectedNextProto controls whether the connection should |
| 504 | // negotiate a next protocol via NPN or ALPN. |
| 505 | expectedNextProto string |
| 506 | // expectNoNextProto, if true, means that no next protocol should be |
| 507 | // negotiated. |
| 508 | expectNoNextProto bool |
| 509 | // expectedNextProtoType, if non-zero, is the expected next |
| 510 | // protocol negotiation mechanism. |
| 511 | expectedNextProtoType int |
| 512 | // expectedSRTPProtectionProfile is the DTLS-SRTP profile that |
| 513 | // should be negotiated. If zero, none should be negotiated. |
| 514 | expectedSRTPProtectionProfile uint16 |
| 515 | // expectedOCSPResponse, if not nil, is the expected OCSP response to be received. |
| 516 | expectedOCSPResponse []uint8 |
| 517 | // expectedSCTList, if not nil, is the expected SCT list to be received. |
| 518 | expectedSCTList []uint8 |
| 519 | // expectedPeerSignatureAlgorithm, if not zero, is the signature |
| 520 | // algorithm that the peer should have used in the handshake. |
| 521 | expectedPeerSignatureAlgorithm signatureAlgorithm |
| 522 | // expectedCurveID, if not zero, is the curve that the handshake should |
| 523 | // have used. |
| 524 | expectedCurveID CurveID |
| 525 | // messageLen is the length, in bytes, of the test message that will be |
| 526 | // sent. |
| 527 | messageLen int |
| 528 | // messageCount is the number of test messages that will be sent. |
| 529 | messageCount int |
| 530 | // certFile is the path to the certificate to use for the server. |
| 531 | certFile string |
| 532 | // keyFile is the path to the private key to use for the server. |
| 533 | keyFile string |
| 534 | // resumeSession controls whether a second connection should be tested |
| 535 | // which attempts to resume the first session. |
| 536 | resumeSession bool |
| 537 | // resumeRenewedSession controls whether a third connection should be |
| 538 | // tested which attempts to resume the second connection's session. |
| 539 | resumeRenewedSession bool |
| 540 | // expectResumeRejected, if true, specifies that the attempted |
| 541 | // resumption must be rejected by the client. This is only valid for a |
| 542 | // serverTest. |
| 543 | expectResumeRejected bool |
| 544 | // resumeConfig, if not nil, points to a Config to be used on |
| 545 | // resumption. Unless newSessionsOnResume is set, |
| 546 | // SessionTicketKey, ServerSessionCache, and |
| 547 | // ClientSessionCache are copied from the initial connection's |
| 548 | // config. If nil, the initial connection's config is used. |
| 549 | resumeConfig *Config |
| 550 | // newSessionsOnResume, if true, will cause resumeConfig to |
| 551 | // use a different session resumption context. |
| 552 | newSessionsOnResume bool |
| 553 | // noSessionCache, if true, will cause the server to run without a |
| 554 | // session cache. |
| 555 | noSessionCache bool |
| 556 | // sendPrefix sends a prefix on the socket before actually performing a |
| 557 | // handshake. |
| 558 | sendPrefix string |
| 559 | // shimWritesFirst controls whether the shim sends an initial "hello" |
| 560 | // message before doing a roundtrip with the runner. |
| 561 | shimWritesFirst bool |
| 562 | // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim |
| 563 | // does not complete the write until responding to the first runner |
| 564 | // message. |
| 565 | readWithUnfinishedWrite bool |
| 566 | // shimShutsDown, if true, runs a test where the shim shuts down the |
| 567 | // connection immediately after the handshake rather than echoing |
| 568 | // messages from the runner. The runner will default to not sending |
| 569 | // application data. |
| 570 | shimShutsDown bool |
| 571 | // renegotiate indicates the number of times the connection should be |
| 572 | // renegotiated during the exchange. |
| 573 | renegotiate int |
| 574 | // sendHalfHelloRequest, if true, causes the server to send half a |
| 575 | // HelloRequest when the handshake completes. |
| 576 | sendHalfHelloRequest bool |
| 577 | // renegotiateCiphers is a list of ciphersuite ids that will be |
| 578 | // switched in just before renegotiation. |
| 579 | renegotiateCiphers []uint16 |
| 580 | // replayWrites, if true, configures the underlying transport |
| 581 | // to replay every write it makes in DTLS tests. |
| 582 | replayWrites bool |
| 583 | // damageFirstWrite, if true, configures the underlying transport to |
| 584 | // damage the final byte of the first application data write. |
| 585 | damageFirstWrite bool |
| 586 | // exportKeyingMaterial, if non-zero, configures the test to exchange |
| 587 | // keying material and verify they match. |
| 588 | exportKeyingMaterial int |
| 589 | exportLabel string |
| 590 | exportContext string |
| 591 | useExportContext bool |
| 592 | // flags, if not empty, contains a list of command-line flags that will |
| 593 | // be passed to the shim program. |
| 594 | flags []string |
| 595 | // testTLSUnique, if true, causes the shim to send the tls-unique value |
| 596 | // which will be compared against the expected value. |
| 597 | testTLSUnique bool |
| 598 | // sendEmptyRecords is the number of consecutive empty records to send |
| 599 | // before each test message. |
| 600 | sendEmptyRecords int |
| 601 | // sendWarningAlerts is the number of consecutive warning alerts to send |
| 602 | // before each test message. |
| 603 | sendWarningAlerts int |
| 604 | // sendBogusAlertType, if true, causes a bogus alert of invalid type to |
| 605 | // be sent before each test message. |
| 606 | sendBogusAlertType bool |
| 607 | // sendKeyUpdates is the number of consecutive key updates to send |
| 608 | // before and after the test message. |
| 609 | sendKeyUpdates int |
| 610 | // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages. |
| 611 | keyUpdateRequest byte |
| 612 | // expectUnsolicitedKeyUpdate makes the test expect a one or more KeyUpdate |
| 613 | // messages while reading data from the shim. Don't use this in combination |
| 614 | // with any of the fields that send a KeyUpdate otherwise any received |
| 615 | // KeyUpdate might not be as unsolicited as expected. |
| 616 | expectUnsolicitedKeyUpdate bool |
| 617 | // expectMessageDropped, if true, means the test message is expected to |
| 618 | // be dropped by the client rather than echoed back. |
| 619 | expectMessageDropped bool |
| 620 | // expectPeerCertificate, if not nil, is the certificate chain the peer |
| 621 | // is expected to send. |
| 622 | expectPeerCertificate *Certificate |
| 623 | // shimPrefix is the prefix that the shim will send to the server. |
| 624 | shimPrefix string |
| 625 | // resumeShimPrefix is the prefix that the shim will send to the server on a |
| 626 | // resumption. |
| 627 | resumeShimPrefix string |
| 628 | // expectedQUICTransportParams contains the QUIC transport |
| 629 | // parameters that are expected to be sent by the peer. |
| 630 | expectedQUICTransportParams []byte |
| 631 | // exportTrafficSecrets, if true, configures the test to export the TLS 1.3 |
| 632 | // traffic secrets and confirms that they match. |
| 633 | exportTrafficSecrets bool |
| 634 | } |
| 635 |
| 636 | var testCases []testCase |
| 637 |
| 638 | func appendTranscript(path string, data []byte) error { |
| 639 | if len(data) == 0 { |
| 640 | return nil |
| 641 | } |
| 642 |
| 643 | settings, err := ioutil.ReadFile(path) |
| 644 | if err != nil { |
| 645 | if !os.IsNotExist(err) { |
| 646 | return err |
| 647 | } |
| 648 | // If the shim aborted before writing a file, use a default |
| 649 | // settings block, so the transcript is still somewhat valid. |
| 650 | settings = []byte{0, 0} // kDataTag |
| 651 | } |
| 652 |
| 653 | settings = append(settings, data...) |
| 654 | return ioutil.WriteFile(path, settings, 0644) |
| 655 | } |
| 656 |
| 657 | // A timeoutConn implements an idle timeout on each Read and Write operation. |
| 658 | type timeoutConn struct { |
| 659 | net.Conn |
| 660 | timeout time.Duration |
| 661 | } |
| 662 |
| 663 | func (t *timeoutConn) Read(b []byte) (int, error) { |
| 664 | if !*useGDB { |
| 665 | if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil { |
| 666 | return 0, err |
| 667 | } |
| 668 | } |
| 669 | return t.Conn.Read(b) |
| 670 | } |
| 671 |
| 672 | func (t *timeoutConn) Write(b []byte) (int, error) { |
| 673 | if !*useGDB { |
| 674 | if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil { |
| 675 | return 0, err |
| 676 | } |
| 677 | } |
| 678 | return t.Conn.Write(b) |
| 679 | } |
| 680 |
| 681 | func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcripts *[][]byte, num int) error { |
| 682 | if !test.noSessionCache { |
| 683 | if config.ClientSessionCache == nil { |
| 684 | config.ClientSessionCache = NewLRUClientSessionCache(1) |
| 685 | } |
| 686 | if config.ServerSessionCache == nil { |
| 687 | config.ServerSessionCache = NewLRUServerSessionCache(1) |
| 688 | } |
| 689 | } |
| 690 | if test.testType == clientTest { |
| 691 | if len(config.Certificates) == 0 { |
| 692 | config.Certificates = []Certificate{rsaCertificate} |
| 693 | } |
| 694 | } else { |
| 695 | // Supply a ServerName to ensure a constant session cache key, |
| 696 | // rather than falling back to net.Conn.RemoteAddr. |
| 697 | if len(config.ServerName) == 0 { |
| 698 | config.ServerName = "test" |
| 699 | } |
| 700 | } |
| 701 | if *fuzzer { |
| 702 | config.Bugs.NullAllCiphers = true |
| 703 | } |
| 704 | if *deterministic { |
| 705 | config.Time = func() time.Time { return time.Unix(1234, 1234) } |
| 706 | } |
| 707 |
| 708 | conn = &timeoutConn{conn, *idleTimeout} |
| 709 |
| 710 | if test.protocol == dtls { |
| 711 | config.Bugs.PacketAdaptor = newPacketAdaptor(conn) |
| 712 | conn = config.Bugs.PacketAdaptor |
| 713 | } |
| 714 |
| 715 | if *flagDebug || len(*transcriptDir) != 0 { |
| 716 | local, peer := "client", "server" |
| 717 | if test.testType == clientTest { |
| 718 | local, peer = peer, local |
| 719 | } |
| 720 | connDebug := &recordingConn{ |
| 721 | Conn: conn, |
| 722 | isDatagram: test.protocol == dtls, |
| 723 | local: local, |
| 724 | peer: peer, |
| 725 | } |
| 726 | conn = connDebug |
| 727 | if *flagDebug { |
| 728 | defer connDebug.WriteTo(os.Stdout) |
| 729 | } |
| 730 | if len(*transcriptDir) != 0 { |
| 731 | defer func() { |
| 732 | if num == len(*transcripts) { |
| 733 | *transcripts = append(*transcripts, connDebug.Transcript()) |
| 734 | } else { |
| 735 | panic("transcripts are out of sync") |
| 736 | } |
| 737 | }() |
| 738 | } |
| 739 |
| 740 | if config.Bugs.PacketAdaptor != nil { |
| 741 | config.Bugs.PacketAdaptor.debug = connDebug |
| 742 | } |
| 743 | } |
| 744 |
| 745 | if test.replayWrites { |
| 746 | conn = newReplayAdaptor(conn) |
| 747 | } |
| 748 |
| 749 | var connDamage *damageAdaptor |
| 750 | if test.damageFirstWrite { |
| 751 | connDamage = newDamageAdaptor(conn) |
| 752 | conn = connDamage |
| 753 | } |
| 754 |
| 755 | if test.sendPrefix != "" { |
| 756 | if _, err := conn.Write([]byte(test.sendPrefix)); err != nil { |
| 757 | return err |
| 758 | } |
| 759 | } |
| 760 |
| 761 | var tlsConn *Conn |
| 762 | if test.testType == clientTest { |
| 763 | if test.protocol == dtls { |
| 764 | tlsConn = DTLSServer(conn, config) |
| 765 | } else { |
| 766 | tlsConn = Server(conn, config) |
| 767 | } |
| 768 | } else { |
| 769 | config.InsecureSkipVerify = true |
| 770 | if test.protocol == dtls { |
| 771 | tlsConn = DTLSClient(conn, config) |
| 772 | } else { |
| 773 | tlsConn = Client(conn, config) |
| 774 | } |
| 775 | } |
| 776 | defer tlsConn.Close() |
| 777 |
| 778 | if err := tlsConn.Handshake(); err != nil { |
| 779 | return err |
| 780 | } |
| 781 |
| 782 | // TODO(davidben): move all per-connection expectations into a dedicated |
| 783 | // expectations struct that can be specified separately for the two |
| 784 | // legs. |
| 785 | expectedVersion := test.expectedVersion |
| 786 | if isResume && test.expectedResumeVersion != 0 { |
| 787 | expectedVersion = test.expectedResumeVersion |
| 788 | } |
| 789 | connState := tlsConn.ConnectionState() |
| 790 | if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion { |
| 791 | return fmt.Errorf("got version %x, expected %x", vers, expectedVersion) |
| 792 | } |
| 793 |
| 794 | if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher { |
| 795 | return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher) |
| 796 | } |
| 797 | if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected { |
| 798 | return fmt.Errorf("didResume is %t, but we expected the opposite", didResume) |
| 799 | } |
| 800 |
| 801 | if test.expectChannelID { |
| 802 | channelID := connState.ChannelID |
| 803 | if channelID == nil { |
| 804 | return fmt.Errorf("no channel ID negotiated") |
| 805 | } |
| 806 | if channelID.Curve != channelIDKey.Curve || |
| 807 | channelIDKey.X.Cmp(channelIDKey.X) != 0 || |
| 808 | channelIDKey.Y.Cmp(channelIDKey.Y) != 0 { |
| 809 | return fmt.Errorf("incorrect channel ID") |
| 810 | } |
| 811 | } else if connState.ChannelID != nil { |
| 812 | return fmt.Errorf("channel ID unexpectedly negotiated") |
| 813 | } |
| 814 |
| 815 | if test.expectTokenBinding { |
| 816 | if !connState.TokenBindingNegotiated { |
| 817 | return errors.New("no Token Binding negotiated") |
| 818 | } |
| 819 | if connState.TokenBindingParam != test.expectedTokenBindingParam { |
| 820 | return fmt.Errorf("expected param %02x, but got %02x", test.expectedTokenBindingParam, connState.TokenBindingParam) |
| 821 | } |
| 822 | } else if connState.TokenBindingNegotiated { |
| 823 | return errors.New("Token Binding unexpectedly negotiated") |
| 824 | } |
| 825 |
| 826 | if expected := test.expectedNextProto; expected != "" { |
| 827 | if actual := connState.NegotiatedProtocol; actual != expected { |
| 828 | return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected) |
| 829 | } |
| 830 | } |
| 831 |
| 832 | if test.expectNoNextProto { |
| 833 | if actual := connState.NegotiatedProtocol; actual != "" { |
| 834 | return fmt.Errorf("got unexpected next proto %s", actual) |
| 835 | } |
| 836 | } |
| 837 |
| 838 | if test.expectedNextProtoType != 0 { |
| 839 | if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN { |
| 840 | return fmt.Errorf("next proto type mismatch") |
| 841 | } |
| 842 | } |
| 843 |
| 844 | if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile { |
| 845 | return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile) |
| 846 | } |
| 847 |
| 848 | if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) { |
| 849 | return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse) |
| 850 | } |
| 851 |
| 852 | if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) { |
| 853 | return fmt.Errorf("SCT list mismatch") |
| 854 | } |
| 855 |
| 856 | if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm { |
| 857 | return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm) |
| 858 | } |
| 859 |
| 860 | if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID { |
| 861 | return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID) |
| 862 | } |
| 863 |
| 864 | if test.expectPeerCertificate != nil { |
| 865 | if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) { |
| 866 | return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate)) |
| 867 | } |
| 868 | for i, cert := range connState.PeerCertificates { |
| 869 | if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) { |
| 870 | return fmt.Errorf("peer certificate %d did not match", i+1) |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 |
| 875 | if len(test.expectedQUICTransportParams) > 0 { |
| 876 | if !bytes.Equal(test.expectedQUICTransportParams, connState.QUICTransportParams) { |
| 877 | return errors.New("Peer did not send expected QUIC transport params") |
| 878 | } |
| 879 | } |
| 880 |
| 881 | if test.exportKeyingMaterial > 0 { |
| 882 | actual := make([]byte, test.exportKeyingMaterial) |
| 883 | if _, err := io.ReadFull(tlsConn, actual); err != nil { |
| 884 | return err |
| 885 | } |
| 886 | expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext) |
| 887 | if err != nil { |
| 888 | return err |
| 889 | } |
| 890 | if !bytes.Equal(actual, expected) { |
| 891 | return fmt.Errorf("keying material mismatch; got %x, wanted %x", actual, expected) |
| 892 | } |
| 893 | } |
| 894 |
| 895 | if test.exportTrafficSecrets { |
| 896 | secretLenBytes := make([]byte, 2) |
| 897 | if _, err := io.ReadFull(tlsConn, secretLenBytes); err != nil { |
| 898 | return err |
| 899 | } |
| 900 | secretLen := binary.LittleEndian.Uint16(secretLenBytes) |
| 901 |
| 902 | theirReadSecret := make([]byte, secretLen) |
| 903 | theirWriteSecret := make([]byte, secretLen) |
| 904 | if _, err := io.ReadFull(tlsConn, theirReadSecret); err != nil { |
| 905 | return err |
| 906 | } |
| 907 | if _, err := io.ReadFull(tlsConn, theirWriteSecret); err != nil { |
| 908 | return err |
| 909 | } |
| 910 |
| 911 | myReadSecret := tlsConn.in.trafficSecret |
| 912 | myWriteSecret := tlsConn.out.trafficSecret |
| 913 | if !bytes.Equal(myWriteSecret, theirReadSecret) { |
| 914 | return fmt.Errorf("read traffic-secret mismatch; got %x, wanted %x", theirReadSecret, myWriteSecret) |
| 915 | } |
| 916 | if !bytes.Equal(myReadSecret, theirWriteSecret) { |
| 917 | return fmt.Errorf("write traffic-secret mismatch; got %x, wanted %x", theirWriteSecret, myReadSecret) |
| 918 | } |
| 919 | } |
| 920 |
| 921 | if test.testTLSUnique { |
| 922 | var peersValue [12]byte |
| 923 | if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil { |
| 924 | return err |
| 925 | } |
| 926 | expected := tlsConn.ConnectionState().TLSUnique |
| 927 | if !bytes.Equal(peersValue[:], expected) { |
| 928 | return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected) |
| 929 | } |
| 930 | } |
| 931 |
| 932 | if test.sendHalfHelloRequest { |
| 933 | tlsConn.SendHalfHelloRequest() |
| 934 | } |
| 935 |
| 936 | shimPrefix := test.shimPrefix |
| 937 | if isResume { |
| 938 | shimPrefix = test.resumeShimPrefix |
| 939 | } |
| 940 | if test.shimWritesFirst || test.readWithUnfinishedWrite { |
| 941 | shimPrefix = "hello" |
| 942 | } |
| 943 | if test.renegotiate > 0 { |
| 944 | // If readWithUnfinishedWrite is set, the shim prefix will be |
| 945 | // available later. |
| 946 | if shimPrefix != "" && !test.readWithUnfinishedWrite { |
| 947 | var buf = make([]byte, len(shimPrefix)) |
| 948 | _, err := io.ReadFull(tlsConn, buf) |
| 949 | if err != nil { |
| 950 | return err |
| 951 | } |
| 952 | if string(buf) != shimPrefix { |
| 953 | return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix) |
| 954 | } |
| 955 | shimPrefix = "" |
| 956 | } |
| 957 |
| 958 | if test.renegotiateCiphers != nil { |
| 959 | config.CipherSuites = test.renegotiateCiphers |
| 960 | } |
| 961 | for i := 0; i < test.renegotiate; i++ { |
| 962 | if err := tlsConn.Renegotiate(); err != nil { |
| 963 | return err |
| 964 | } |
| 965 | } |
| 966 | } else if test.renegotiateCiphers != nil { |
| 967 | panic("renegotiateCiphers without renegotiate") |
| 968 | } |
| 969 |
| 970 | if test.damageFirstWrite { |
| 971 | connDamage.setDamage(true) |
| 972 | tlsConn.Write([]byte("DAMAGED WRITE")) |
| 973 | connDamage.setDamage(false) |
| 974 | } |
| 975 |
| 976 | messageLen := test.messageLen |
| 977 | if messageLen < 0 { |
| 978 | if test.protocol == dtls { |
| 979 | return fmt.Errorf("messageLen < 0 not supported for DTLS tests") |
| 980 | } |
| 981 | // Read until EOF. |
| 982 | _, err := io.Copy(ioutil.Discard, tlsConn) |
| 983 | return err |
| 984 | } |
| 985 | if messageLen == 0 { |
| 986 | messageLen = 32 |
| 987 | } |
| 988 |
| 989 | messageCount := test.messageCount |
| 990 | // shimShutsDown sets the default message count to zero. |
| 991 | if messageCount == 0 && !test.shimShutsDown { |
| 992 | messageCount = 1 |
| 993 | } |
| 994 |
| 995 | for j := 0; j < messageCount; j++ { |
| 996 | for i := 0; i < test.sendKeyUpdates; i++ { |
| 997 | tlsConn.SendKeyUpdate(test.keyUpdateRequest) |
| 998 | } |
| 999 |
| 1000 | for i := 0; i < test.sendEmptyRecords; i++ { |
| 1001 | tlsConn.Write(nil) |
| 1002 | } |
| 1003 |
| 1004 | for i := 0; i < test.sendWarningAlerts; i++ { |
| 1005 | tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage) |
| 1006 | } |
| 1007 |
| 1008 | if test.sendBogusAlertType { |
| 1009 | tlsConn.SendAlert(0x42, alertUnexpectedMessage) |
| 1010 | } |
| 1011 |
| 1012 | testMessage := make([]byte, messageLen) |
| 1013 | for i := range testMessage { |
| 1014 | testMessage[i] = 0x42 ^ byte(j) |
| 1015 | } |
| 1016 | tlsConn.Write(testMessage) |
| 1017 |
| 1018 | // Consume the shim prefix if needed. |
| 1019 | if shimPrefix != "" { |
| 1020 | var buf = make([]byte, len(shimPrefix)) |
| 1021 | _, err := io.ReadFull(tlsConn, buf) |
| 1022 | if err != nil { |
| 1023 | return err |
| 1024 | } |
| 1025 | if string(buf) != shimPrefix { |
| 1026 | return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix) |
| 1027 | } |
| 1028 | shimPrefix = "" |
| 1029 | } |
| 1030 |
| 1031 | if test.shimShutsDown || test.expectMessageDropped { |
| 1032 | // The shim will not respond. |
| 1033 | continue |
| 1034 | } |
| 1035 |
| 1036 | // Process the KeyUpdate ACK. However many KeyUpdates the runner |
| 1037 | // sends, the shim should respond only once. |
| 1038 | if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested { |
| 1039 | if err := tlsConn.ReadKeyUpdateACK(); err != nil { |
| 1040 | return err |
| 1041 | } |
| 1042 | } |
| 1043 |
| 1044 | buf := make([]byte, len(testMessage)) |
| 1045 | if test.protocol == dtls { |
| 1046 | bufTmp := make([]byte, len(buf)+1) |
| 1047 | n, err := tlsConn.Read(bufTmp) |
| 1048 | if err != nil { |
| 1049 | return err |
| 1050 | } |
| 1051 | if config.Bugs.SplitAndPackAppData { |
| 1052 | m, err := tlsConn.Read(bufTmp[n:]) |
| 1053 | if err != nil { |
| 1054 | return err |
| 1055 | } |
| 1056 | n += m |
| 1057 | } |
| 1058 | if n != len(buf) { |
| 1059 | return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf)) |
| 1060 | } |
| 1061 | copy(buf, bufTmp) |
| 1062 | } else { |
| 1063 | _, err := io.ReadFull(tlsConn, buf) |
| 1064 | if err != nil { |
| 1065 | return err |
| 1066 | } |
| 1067 | } |
| 1068 |
| 1069 | for i, v := range buf { |
| 1070 | if v != testMessage[i]^0xff { |
| 1071 | return fmt.Errorf("bad reply contents at byte %d; got %q and wanted %q", i, buf, testMessage) |
| 1072 | } |
| 1073 | } |
| 1074 |
| 1075 | if seen := tlsConn.keyUpdateSeen; seen != test.expectUnsolicitedKeyUpdate { |
| 1076 | return fmt.Errorf("keyUpdateSeen (%t) != expectUnsolicitedKeyUpdate", seen) |
| 1077 | } |
| 1078 | } |
| 1079 |
| 1080 | return nil |
| 1081 | } |
| 1082 |
| 1083 | const xtermSize = "140x50" |
| 1084 |
| 1085 | func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd { |
| 1086 | valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"} |
| 1087 | if dbAttach { |
| 1088 | valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -geometry "+xtermSize+" -e gdb -nw %f %p") |
| 1089 | } |
| 1090 | valgrindArgs = append(valgrindArgs, path) |
| 1091 | valgrindArgs = append(valgrindArgs, args...) |
| 1092 |
| 1093 | return exec.Command("valgrind", valgrindArgs...) |
| 1094 | } |
| 1095 |
| 1096 | func gdbOf(path string, args ...string) *exec.Cmd { |
| 1097 | xtermArgs := []string{"-geometry", xtermSize, "-e", "gdb", "--args"} |
| 1098 | xtermArgs = append(xtermArgs, path) |
| 1099 | xtermArgs = append(xtermArgs, args...) |
| 1100 |
| 1101 | return exec.Command("xterm", xtermArgs...) |
| 1102 | } |
| 1103 |
| 1104 | func lldbOf(path string, args ...string) *exec.Cmd { |
| 1105 | xtermArgs := []string{"-geometry", xtermSize, "-e", "lldb", "--"} |
| 1106 | xtermArgs = append(xtermArgs, path) |
| 1107 | xtermArgs = append(xtermArgs, args...) |
| 1108 |
| 1109 | return exec.Command("xterm", xtermArgs...) |
| 1110 | } |
| 1111 |
| 1112 | func removeFirstLineIfSuffix(s, suffix string) string { |
| 1113 | idx := strings.IndexByte(s, '\n') |
| 1114 | if idx < 0 { |
| 1115 | return s |
| 1116 | } |
| 1117 | if strings.HasSuffix(s[:idx], suffix) { |
| 1118 | return s[idx+1:] |
| 1119 | } |
| 1120 | return s |
| 1121 | } |
| 1122 |
| 1123 | var ( |
| 1124 | errMoreMallocs = errors.New("child process did not exhaust all allocation calls") |
| 1125 | errUnimplemented = errors.New("child process does not implement needed flags") |
| 1126 | ) |
| 1127 |
| 1128 | // accept accepts a connection from listener, unless waitChan signals a process |
| 1129 | // exit first. |
| 1130 | func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) { |
| 1131 | type connOrError struct { |
| 1132 | conn net.Conn |
| 1133 | err error |
| 1134 | } |
| 1135 | connChan := make(chan connOrError, 1) |
| 1136 | go func() { |
| 1137 | if !*useGDB { |
| 1138 | listener.SetDeadline(time.Now().Add(*idleTimeout)) |
| 1139 | } |
| 1140 | conn, err := listener.Accept() |
| 1141 | connChan <- connOrError{conn, err} |
| 1142 | close(connChan) |
| 1143 | }() |
| 1144 | select { |
| 1145 | case result := <-connChan: |
| 1146 | return result.conn, result.err |
| 1147 | case childErr := <-waitChan: |
| 1148 | waitChan <- childErr |
| 1149 | return nil, fmt.Errorf("child exited early: %s", childErr) |
| 1150 | } |
| 1151 | } |
| 1152 |
| 1153 | func translateExpectedError(errorStr string) string { |
| 1154 | if translated, ok := shimConfig.ErrorMap[errorStr]; ok { |
| 1155 | return translated |
| 1156 | } |
| 1157 |
| 1158 | if *looseErrors { |
| 1159 | return "" |
| 1160 | } |
| 1161 |
| 1162 | return errorStr |
| 1163 | } |
| 1164 |
| 1165 | func runTest(test *testCase, shimPath string, mallocNumToFail int64) error { |
| 1166 | // Help debugging panics on the Go side. |
| 1167 | defer func() { |
| 1168 | if r := recover(); r != nil { |
| 1169 | fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name) |
| 1170 | panic(r) |
| 1171 | } |
| 1172 | }() |
| 1173 |
| 1174 | if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) { |
| 1175 | panic("Error expected without shouldFail in " + test.name) |
| 1176 | } |
| 1177 |
| 1178 | if test.expectResumeRejected && !test.resumeSession { |
| 1179 | panic("expectResumeRejected without resumeSession in " + test.name) |
| 1180 | } |
| 1181 |
| 1182 | for _, ver := range tlsVersions { |
| 1183 | if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") { |
| 1184 | continue |
| 1185 | } |
| 1186 |
| 1187 | if test.config.MaxVersion == 0 && test.config.MinVersion == 0 && test.expectedVersion == 0 { |
| 1188 | panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version)) |
| 1189 | } |
| 1190 | } |
| 1191 |
| 1192 | listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback}) |
| 1193 | if err != nil { |
| 1194 | listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}}) |
| 1195 | } |
| 1196 | if err != nil { |
| 1197 | panic(err) |
| 1198 | } |
| 1199 | defer func() { |
| 1200 | if listener != nil { |
| 1201 | listener.Close() |
| 1202 | } |
| 1203 | }() |
| 1204 |
| 1205 | flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)} |
| 1206 | if test.testType == serverTest { |
| 1207 | flags = append(flags, "-server") |
| 1208 |
| 1209 | flags = append(flags, "-key-file") |
| 1210 | if test.keyFile == "" { |
| 1211 | flags = append(flags, path.Join(*resourceDir, rsaKeyFile)) |
| 1212 | } else { |
| 1213 | flags = append(flags, path.Join(*resourceDir, test.keyFile)) |
| 1214 | } |
| 1215 |
| 1216 | flags = append(flags, "-cert-file") |
| 1217 | if test.certFile == "" { |
| 1218 | flags = append(flags, path.Join(*resourceDir, rsaCertificateFile)) |
| 1219 | } else { |
| 1220 | flags = append(flags, path.Join(*resourceDir, test.certFile)) |
| 1221 | } |
| 1222 | } |
| 1223 |
| 1224 | if test.protocol == dtls { |
| 1225 | flags = append(flags, "-dtls") |
| 1226 | } |
| 1227 |
| 1228 | var resumeCount int |
| 1229 | if test.resumeSession { |
| 1230 | resumeCount++ |
| 1231 | if test.resumeRenewedSession { |
| 1232 | resumeCount++ |
| 1233 | } |
| 1234 | } |
| 1235 |
| 1236 | if resumeCount > 0 { |
| 1237 | flags = append(flags, "-resume-count", strconv.Itoa(resumeCount)) |
| 1238 | } |
| 1239 |
| 1240 | if test.shimWritesFirst { |
| 1241 | flags = append(flags, "-shim-writes-first") |
| 1242 | } |
| 1243 |
| 1244 | if test.readWithUnfinishedWrite { |
| 1245 | flags = append(flags, "-read-with-unfinished-write") |
| 1246 | } |
| 1247 |
| 1248 | if test.shimShutsDown { |
| 1249 | flags = append(flags, "-shim-shuts-down") |
| 1250 | } |
| 1251 |
| 1252 | if test.exportKeyingMaterial > 0 { |
| 1253 | flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial)) |
| 1254 | if test.useExportContext { |
| 1255 | flags = append(flags, "-use-export-context") |
| 1256 | } |
| 1257 | } |
| 1258 | if test.exportKeyingMaterial > 0 { |
| 1259 | flags = append(flags, "-export-label", test.exportLabel) |
| 1260 | flags = append(flags, "-export-context", test.exportContext) |
| 1261 | } |
| 1262 |
| 1263 | if test.exportTrafficSecrets { |
| 1264 | flags = append(flags, "-export-traffic-secrets") |
| 1265 | } |
| 1266 |
| 1267 | if test.expectResumeRejected { |
| 1268 | flags = append(flags, "-expect-session-miss") |
| 1269 | } |
| 1270 |
| 1271 | if test.testTLSUnique { |
| 1272 | flags = append(flags, "-tls-unique") |
| 1273 | } |
| 1274 |
| 1275 | flags = append(flags, "-handshaker-path", *handshakerPath) |
| 1276 |
| 1277 | var transcriptPrefix string |
| 1278 | var transcripts [][]byte |
| 1279 | if len(*transcriptDir) != 0 { |
| 1280 | protocol := "tls" |
| 1281 | if test.protocol == dtls { |
| 1282 | protocol = "dtls" |
| 1283 | } |
| 1284 |
| 1285 | side := "client" |
| 1286 | if test.testType == serverTest { |
| 1287 | side = "server" |
| 1288 | } |
| 1289 |
| 1290 | dir := filepath.Join(*transcriptDir, protocol, side) |
| 1291 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 1292 | return err |
| 1293 | } |
| 1294 | transcriptPrefix = filepath.Join(dir, test.name+"-") |
| 1295 | flags = append(flags, "-write-settings", transcriptPrefix) |
| 1296 | } |
| 1297 |
| 1298 | flags = append(flags, test.flags...) |
| 1299 |
| 1300 | var shim *exec.Cmd |
| 1301 | if *useValgrind { |
| 1302 | shim = valgrindOf(false, shimPath, flags...) |
| 1303 | } else if *useGDB { |
| 1304 | shim = gdbOf(shimPath, flags...) |
| 1305 | } else if *useLLDB { |
| 1306 | shim = lldbOf(shimPath, flags...) |
| 1307 | } else { |
| 1308 | shim = exec.Command(shimPath, flags...) |
| 1309 | } |
| 1310 | shim.Stdin = os.Stdin |
| 1311 | var stdoutBuf, stderrBuf bytes.Buffer |
| 1312 | shim.Stdout = &stdoutBuf |
| 1313 | shim.Stderr = &stderrBuf |
| 1314 | if mallocNumToFail >= 0 { |
| 1315 | shim.Env = os.Environ() |
| 1316 | shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10)) |
| 1317 | if *mallocTestDebug { |
| 1318 | shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1") |
| 1319 | } |
| 1320 | shim.Env = append(shim.Env, "_MALLOC_CHECK=1") |
| 1321 | } |
| 1322 |
| 1323 | if err := shim.Start(); err != nil { |
| 1324 | panic(err) |
| 1325 | } |
| 1326 | waitChan := make(chan error, 1) |
| 1327 | go func() { waitChan <- shim.Wait() }() |
| 1328 |
| 1329 | config := test.config |
| 1330 |
| 1331 | if *deterministic { |
| 1332 | config.Rand = &deterministicRand{} |
| 1333 | } |
| 1334 |
| 1335 | conn, err := acceptOrWait(listener, waitChan) |
| 1336 | if err == nil { |
| 1337 | err = doExchange(test, &config, conn, false /* not a resumption */, &transcripts, 0) |
| 1338 | conn.Close() |
| 1339 | } |
| 1340 |
| 1341 | for i := 0; err == nil && i < resumeCount; i++ { |
| 1342 | var resumeConfig Config |
| 1343 | if test.resumeConfig != nil { |
| 1344 | resumeConfig = *test.resumeConfig |
| 1345 | if !test.newSessionsOnResume { |
| 1346 | resumeConfig.SessionTicketKey = config.SessionTicketKey |
| 1347 | resumeConfig.ClientSessionCache = config.ClientSessionCache |
| 1348 | resumeConfig.ServerSessionCache = config.ServerSessionCache |
| 1349 | } |
| 1350 | resumeConfig.Rand = config.Rand |
| 1351 | } else { |
| 1352 | resumeConfig = config |
| 1353 | } |
| 1354 | var connResume net.Conn |
| 1355 | connResume, err = acceptOrWait(listener, waitChan) |
| 1356 | if err == nil { |
| 1357 | err = doExchange(test, &resumeConfig, connResume, true /* resumption */, &transcripts, i+1) |
| 1358 | connResume.Close() |
| 1359 | } |
| 1360 | } |
| 1361 |
| 1362 | // Close the listener now. This is to avoid hangs should the shim try to |
| 1363 | // open more connections than expected. |
| 1364 | listener.Close() |
| 1365 | listener = nil |
| 1366 |
| 1367 | var childErr error |
| 1368 | if *useGDB { |
| 1369 | childErr = <-waitChan |
| 1370 | } else { |
| 1371 | waitTimeout := time.AfterFunc(*idleTimeout, func() { |
| 1372 | shim.Process.Kill() |
| 1373 | }) |
| 1374 | childErr = <-waitChan |
| 1375 | waitTimeout.Stop() |
| 1376 | } |
| 1377 |
| 1378 | // Now that the shim has exitted, all the settings files have been |
| 1379 | // written. Append the saved transcripts. |
| 1380 | for i, transcript := range transcripts { |
| 1381 | if err := appendTranscript(transcriptPrefix+strconv.Itoa(i), transcript); err != nil { |
| 1382 | return err |
| 1383 | } |
| 1384 | } |
| 1385 |
| 1386 | var isValgrindError, mustFail bool |
| 1387 | if exitError, ok := childErr.(*exec.ExitError); ok { |
| 1388 | switch exitError.Sys().(syscall.WaitStatus).ExitStatus() { |
| 1389 | case 88: |
| 1390 | return errMoreMallocs |
| 1391 | case 89: |
| 1392 | return errUnimplemented |
| 1393 | case 90: |
| 1394 | mustFail = true |
| 1395 | case 99: |
| 1396 | isValgrindError = true |
| 1397 | } |
| 1398 | } |
| 1399 |
| 1400 | // Account for Windows line endings. |
| 1401 | stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1) |
| 1402 | stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1) |
| 1403 |
| 1404 | // Work around an NDK / Android bug. The NDK r16 sometimes generates |
| 1405 | // binaries with the DF_1_PIE, which the runtime linker on Android N |
| 1406 | // complains about. The next NDK revision should work around this but, |
| 1407 | // in the meantime, strip its error out. |
| 1408 | // |
| 1409 | // https://github.com/android-ndk/ndk/issues/602 |
| 1410 | // https://android-review.googlesource.com/c/platform/bionic/+/259790 |
| 1411 | // https://android-review.googlesource.com/c/toolchain/binutils/+/571550 |
| 1412 | // |
| 1413 | // Remove this after switching to the r17 NDK. |
| 1414 | stderr = removeFirstLineIfSuffix(stderr, ": unsupported flags DT_FLAGS_1=0x8000001") |
| 1415 |
| 1416 | // Separate the errors from the shim and those from tools like |
| 1417 | // AddressSanitizer. |
| 1418 | var extraStderr string |
| 1419 | if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 { |
| 1420 | stderr = stderrParts[0] |
| 1421 | extraStderr = stderrParts[1] |
| 1422 | } |
| 1423 |
| 1424 | failed := err != nil || childErr != nil |
| 1425 | expectedError := translateExpectedError(test.expectedError) |
| 1426 | correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError) |
| 1427 |
| 1428 | localError := "none" |
| 1429 | if err != nil { |
| 1430 | localError = err.Error() |
| 1431 | } |
| 1432 | if len(test.expectedLocalError) != 0 { |
| 1433 | correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError) |
| 1434 | } |
| 1435 |
| 1436 | if failed != test.shouldFail || failed && !correctFailure || mustFail { |
| 1437 | childError := "none" |
| 1438 | if childErr != nil { |
| 1439 | childError = childErr.Error() |
| 1440 | } |
| 1441 |
| 1442 | var msg string |
| 1443 | switch { |
| 1444 | case failed && !test.shouldFail: |
| 1445 | msg = "unexpected failure" |
| 1446 | case !failed && test.shouldFail: |
| 1447 | msg = "unexpected success" |
| 1448 | case failed && !correctFailure: |
| 1449 | msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')" |
| 1450 | case mustFail: |
| 1451 | msg = "test failure" |
| 1452 | default: |
| 1453 | panic("internal error") |
| 1454 | } |
| 1455 |
| 1456 | return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr) |
| 1457 | } |
| 1458 |
| 1459 | if len(extraStderr) > 0 || (!failed && len(stderr) > 0) { |
| 1460 | return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr) |
| 1461 | } |
| 1462 |
| 1463 | if *useValgrind && isValgrindError { |
| 1464 | return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr) |
| 1465 | } |
| 1466 |
| 1467 | return nil |
| 1468 | } |
| 1469 |
| 1470 | type tlsVersion struct { |
| 1471 | name string |
| 1472 | // version is the protocol version. |
| 1473 | version uint16 |
| 1474 | // excludeFlag is the legacy shim flag to disable the version. |
| 1475 | excludeFlag string |
| 1476 | hasDTLS bool |
| 1477 | // versionDTLS, if non-zero, is the DTLS-specific representation of the version. |
| 1478 | versionDTLS uint16 |
| 1479 | // versionWire, if non-zero, is the wire representation of the |
| 1480 | // version. Otherwise the wire version is the protocol version or |
| 1481 | // versionDTLS. |
| 1482 | versionWire uint16 |
| 1483 | } |
| 1484 |
| 1485 | func (vers tlsVersion) shimFlag(protocol protocol) string { |
| 1486 | // The shim uses the protocol version in its public API, but uses the |
| 1487 | // DTLS-specific version if it exists. |
| 1488 | if protocol == dtls && vers.versionDTLS != 0 { |
| 1489 | return strconv.Itoa(int(vers.versionDTLS)) |
| 1490 | } |
| 1491 | return strconv.Itoa(int(vers.version)) |
| 1492 | } |
| 1493 |
| 1494 | func (vers tlsVersion) wire(protocol protocol) uint16 { |
| 1495 | if protocol == dtls && vers.versionDTLS != 0 { |
| 1496 | return vers.versionDTLS |
| 1497 | } |
| 1498 | if vers.versionWire != 0 { |
| 1499 | return vers.versionWire |
| 1500 | } |
| 1501 | return vers.version |
| 1502 | } |
| 1503 |
| 1504 | var tlsVersions = []tlsVersion{ |
| 1505 | { |
| 1506 | name: "TLS1", |
| 1507 | version: VersionTLS10, |
| 1508 | excludeFlag: "-no-tls1", |
| 1509 | hasDTLS: true, |
| 1510 | versionDTLS: VersionDTLS10, |
| 1511 | }, |
| 1512 | { |
| 1513 | name: "TLS11", |
| 1514 | version: VersionTLS11, |
| 1515 | excludeFlag: "-no-tls11", |
| 1516 | }, |
| 1517 | { |
| 1518 | name: "TLS12", |
| 1519 | version: VersionTLS12, |
| 1520 | excludeFlag: "-no-tls12", |
| 1521 | hasDTLS: true, |
| 1522 | versionDTLS: VersionDTLS12, |
| 1523 | }, |
| 1524 | { |
| 1525 | name: "TLS13", |
| 1526 | version: VersionTLS13, |
| 1527 | excludeFlag: "-no-tls13", |
| 1528 | versionWire: VersionTLS13, |
| 1529 | }, |
| 1530 | } |
| 1531 |
| 1532 | func allVersions(protocol protocol) []tlsVersion { |
| 1533 | if protocol == tls { |
| 1534 | return tlsVersions |
| 1535 | } |
| 1536 |
| 1537 | var ret []tlsVersion |
| 1538 | for _, vers := range tlsVersions { |
| 1539 | if vers.hasDTLS { |
| 1540 | ret = append(ret, vers) |
| 1541 | } |
| 1542 | } |
| 1543 | return ret |
| 1544 | } |
| 1545 |
| 1546 | type testCipherSuite struct { |
| 1547 | name string |
| 1548 | id uint16 |
| 1549 | } |
| 1550 |
| 1551 | var testCipherSuites = []testCipherSuite{ |
| 1552 | {"RSA_WITH_3DES_EDE_CBC_SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
| 1553 | {"RSA_WITH_AES_128_GCM_SHA256", TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 1554 | {"RSA_WITH_AES_128_CBC_SHA", TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 1555 | {"RSA_WITH_AES_256_GCM_SHA384", TLS_RSA_WITH_AES_256_GCM_SHA384}, |
| 1556 | {"RSA_WITH_AES_256_CBC_SHA", TLS_RSA_WITH_AES_256_CBC_SHA}, |
| 1557 | {"ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 1558 | {"ECDHE_ECDSA_WITH_AES_128_CBC_SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA}, |
| 1559 | {"ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384}, |
| 1560 | {"ECDHE_ECDSA_WITH_AES_256_CBC_SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA}, |
| 1561 | {"ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 1562 | {"ECDHE_RSA_WITH_AES_128_GCM_SHA256", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1563 | {"ECDHE_RSA_WITH_AES_128_CBC_SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 1564 | {"ECDHE_RSA_WITH_AES_256_GCM_SHA384", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384}, |
| 1565 | {"ECDHE_RSA_WITH_AES_256_CBC_SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, |
| 1566 | {"ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 1567 | {"PSK_WITH_AES_128_CBC_SHA", TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 1568 | {"PSK_WITH_AES_256_CBC_SHA", TLS_PSK_WITH_AES_256_CBC_SHA}, |
| 1569 | {"ECDHE_PSK_WITH_AES_128_CBC_SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 1570 | {"ECDHE_PSK_WITH_AES_256_CBC_SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA}, |
| 1571 | {"ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256}, |
| 1572 | {"CHACHA20_POLY1305_SHA256", TLS_CHACHA20_POLY1305_SHA256}, |
| 1573 | {"AES_128_GCM_SHA256", TLS_AES_128_GCM_SHA256}, |
| 1574 | {"AES_256_GCM_SHA384", TLS_AES_256_GCM_SHA384}, |
| 1575 | {"RSA_WITH_NULL_SHA", TLS_RSA_WITH_NULL_SHA}, |
| 1576 | } |
| 1577 |
| 1578 | func hasComponent(suiteName, component string) bool { |
| 1579 | return strings.Contains("_"+suiteName+"_", "_"+component+"_") |
| 1580 | } |
| 1581 |
| 1582 | func isTLS12Only(suiteName string) bool { |
| 1583 | return hasComponent(suiteName, "GCM") || |
| 1584 | hasComponent(suiteName, "SHA256") || |
| 1585 | hasComponent(suiteName, "SHA384") || |
| 1586 | hasComponent(suiteName, "POLY1305") |
| 1587 | } |
| 1588 |
| 1589 | func isTLS13Suite(suiteName string) bool { |
| 1590 | return !hasComponent(suiteName, "WITH") |
| 1591 | } |
| 1592 |
| 1593 | func bigFromHex(hex string) *big.Int { |
| 1594 | ret, ok := new(big.Int).SetString(hex, 16) |
| 1595 | if !ok { |
| 1596 | panic("failed to parse hex number 0x" + hex) |
| 1597 | } |
| 1598 | return ret |
| 1599 | } |
| 1600 |
| 1601 | func convertToSplitHandshakeTests(tests []testCase) (splitHandshakeTests []testCase) { |
| 1602 | var stdout bytes.Buffer |
| 1603 | shim := exec.Command(*shimPath, "-is-handshaker-supported") |
| 1604 | shim.Stdout = &stdout |
| 1605 | if err := shim.Run(); err != nil { |
| 1606 | panic(err) |
| 1607 | } |
| 1608 |
| 1609 | switch strings.TrimSpace(string(stdout.Bytes())) { |
| 1610 | case "No": |
| 1611 | return |
| 1612 | case "Yes": |
| 1613 | break |
| 1614 | default: |
| 1615 | panic("Unknown output from shim: 0x" + hex.EncodeToString(stdout.Bytes())) |
| 1616 | } |
| 1617 |
| 1618 | NextTest: |
| 1619 | for _, test := range tests { |
| 1620 | if test.protocol != tls || |
| 1621 | test.testType != serverTest || |
| 1622 | test.config.MaxVersion >= VersionTLS13 || |
| 1623 | test.config.MaxVersion < VersionTLS10 || |
| 1624 | (test.resumeConfig != nil && (test.resumeConfig.MaxVersion < VersionTLS10 || test.resumeConfig.MaxVersion >= VersionTLS13)) || |
| 1625 | strings.HasPrefix(test.name, "VersionNegotiation-") { |
| 1626 | continue |
| 1627 | } |
| 1628 |
| 1629 | for _, flag := range test.flags { |
| 1630 | if flag == "-implicit-handshake" { |
| 1631 | continue NextTest |
| 1632 | } |
| 1633 | } |
| 1634 |
| 1635 | shTest := test |
| 1636 | shTest.name += "-Split" |
| 1637 | shTest.flags = make([]string, len(test.flags), len(test.flags)+1) |
| 1638 | copy(shTest.flags, test.flags) |
| 1639 | shTest.flags = append(shTest.flags, "-handoff") |
| 1640 |
| 1641 | splitHandshakeTests = append(splitHandshakeTests, shTest) |
| 1642 | } |
| 1643 |
| 1644 | return splitHandshakeTests |
| 1645 | } |
| 1646 |
| 1647 | func addBasicTests() { |
| 1648 | basicTests := []testCase{ |
| 1649 | { |
| 1650 | name: "NoFallbackSCSV", |
| 1651 | config: Config{ |
| 1652 | Bugs: ProtocolBugs{ |
| 1653 | FailIfNotFallbackSCSV: true, |
| 1654 | }, |
| 1655 | }, |
| 1656 | shouldFail: true, |
| 1657 | expectedLocalError: "no fallback SCSV found", |
| 1658 | }, |
| 1659 | { |
| 1660 | name: "SendFallbackSCSV", |
| 1661 | config: Config{ |
| 1662 | Bugs: ProtocolBugs{ |
| 1663 | FailIfNotFallbackSCSV: true, |
| 1664 | }, |
| 1665 | }, |
| 1666 | flags: []string{"-fallback-scsv"}, |
| 1667 | }, |
| 1668 | { |
| 1669 | name: "ClientCertificateTypes", |
| 1670 | config: Config{ |
| 1671 | MaxVersion: VersionTLS12, |
| 1672 | ClientAuth: RequestClientCert, |
| 1673 | ClientCertificateTypes: []byte{ |
| 1674 | CertTypeDSSSign, |
| 1675 | CertTypeRSASign, |
| 1676 | CertTypeECDSASign, |
| 1677 | }, |
| 1678 | }, |
| 1679 | flags: []string{ |
| 1680 | "-expect-certificate-types", |
| 1681 | base64.StdEncoding.EncodeToString([]byte{ |
| 1682 | CertTypeDSSSign, |
| 1683 | CertTypeRSASign, |
| 1684 | CertTypeECDSASign, |
| 1685 | }), |
| 1686 | }, |
| 1687 | }, |
| 1688 | { |
| 1689 | name: "UnauthenticatedECDH", |
| 1690 | config: Config{ |
| 1691 | MaxVersion: VersionTLS12, |
| 1692 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1693 | Bugs: ProtocolBugs{ |
| 1694 | UnauthenticatedECDH: true, |
| 1695 | }, |
| 1696 | }, |
| 1697 | shouldFail: true, |
| 1698 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1699 | }, |
| 1700 | { |
| 1701 | name: "SkipCertificateStatus", |
| 1702 | config: Config{ |
| 1703 | MaxVersion: VersionTLS12, |
| 1704 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1705 | Bugs: ProtocolBugs{ |
| 1706 | SkipCertificateStatus: true, |
| 1707 | }, |
| 1708 | }, |
| 1709 | flags: []string{ |
| 1710 | "-enable-ocsp-stapling", |
| 1711 | // This test involves an optional message. Test the message callback |
| 1712 | // trace to ensure we do not miss or double-report any. |
| 1713 | "-expect-msg-callback", |
| 1714 | `write hs 1 |
| 1715 | read hs 2 |
| 1716 | read hs 11 |
| 1717 | read hs 12 |
| 1718 | read hs 14 |
| 1719 | write hs 16 |
| 1720 | write ccs |
| 1721 | write hs 20 |
| 1722 | read hs 4 |
| 1723 | read ccs |
| 1724 | read hs 20 |
| 1725 | read alert 1 0 |
| 1726 | `, |
| 1727 | }, |
| 1728 | }, |
| 1729 | { |
| 1730 | protocol: dtls, |
| 1731 | name: "SkipCertificateStatus-DTLS", |
| 1732 | config: Config{ |
| 1733 | MaxVersion: VersionTLS12, |
| 1734 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1735 | Bugs: ProtocolBugs{ |
| 1736 | SkipCertificateStatus: true, |
| 1737 | }, |
| 1738 | }, |
| 1739 | flags: []string{ |
| 1740 | "-enable-ocsp-stapling", |
| 1741 | // This test involves an optional message. Test the message callback |
| 1742 | // trace to ensure we do not miss or double-report any. |
| 1743 | "-expect-msg-callback", |
| 1744 | `write hs 1 |
| 1745 | read hs 3 |
| 1746 | write hs 1 |
| 1747 | read hs 2 |
| 1748 | read hs 11 |
| 1749 | read hs 12 |
| 1750 | read hs 14 |
| 1751 | write hs 16 |
| 1752 | write ccs |
| 1753 | write hs 20 |
| 1754 | read hs 4 |
| 1755 | read ccs |
| 1756 | read hs 20 |
| 1757 | read alert 1 0 |
| 1758 | `, |
| 1759 | }, |
| 1760 | }, |
| 1761 | { |
| 1762 | name: "SkipServerKeyExchange", |
| 1763 | config: Config{ |
| 1764 | MaxVersion: VersionTLS12, |
| 1765 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 1766 | Bugs: ProtocolBugs{ |
| 1767 | SkipServerKeyExchange: true, |
| 1768 | }, |
| 1769 | }, |
| 1770 | shouldFail: true, |
| 1771 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1772 | }, |
| 1773 | { |
| 1774 | testType: serverTest, |
| 1775 | name: "ServerSkipCertificateVerify", |
| 1776 | config: Config{ |
| 1777 | MaxVersion: VersionTLS12, |
| 1778 | Certificates: []Certificate{rsaChainCertificate}, |
| 1779 | Bugs: ProtocolBugs{ |
| 1780 | SkipCertificateVerify: true, |
| 1781 | }, |
| 1782 | }, |
| 1783 | expectPeerCertificate: &rsaChainCertificate, |
| 1784 | flags: []string{ |
| 1785 | "-require-any-client-certificate", |
| 1786 | }, |
| 1787 | shouldFail: true, |
| 1788 | expectedError: ":UNEXPECTED_RECORD:", |
| 1789 | expectedLocalError: "remote error: unexpected message", |
| 1790 | }, |
| 1791 | { |
| 1792 | testType: serverTest, |
| 1793 | name: "Alert", |
| 1794 | config: Config{ |
| 1795 | Bugs: ProtocolBugs{ |
| 1796 | SendSpuriousAlert: alertRecordOverflow, |
| 1797 | }, |
| 1798 | }, |
| 1799 | shouldFail: true, |
| 1800 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1801 | }, |
| 1802 | { |
| 1803 | protocol: dtls, |
| 1804 | testType: serverTest, |
| 1805 | name: "Alert-DTLS", |
| 1806 | config: Config{ |
| 1807 | Bugs: ProtocolBugs{ |
| 1808 | SendSpuriousAlert: alertRecordOverflow, |
| 1809 | }, |
| 1810 | }, |
| 1811 | shouldFail: true, |
| 1812 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 1813 | }, |
| 1814 | { |
| 1815 | testType: serverTest, |
| 1816 | name: "FragmentAlert", |
| 1817 | config: Config{ |
| 1818 | Bugs: ProtocolBugs{ |
| 1819 | FragmentAlert: true, |
| 1820 | SendSpuriousAlert: alertRecordOverflow, |
| 1821 | }, |
| 1822 | }, |
| 1823 | shouldFail: true, |
| 1824 | expectedError: ":BAD_ALERT:", |
| 1825 | }, |
| 1826 | { |
| 1827 | protocol: dtls, |
| 1828 | testType: serverTest, |
| 1829 | name: "FragmentAlert-DTLS", |
| 1830 | config: Config{ |
| 1831 | Bugs: ProtocolBugs{ |
| 1832 | FragmentAlert: true, |
| 1833 | SendSpuriousAlert: alertRecordOverflow, |
| 1834 | }, |
| 1835 | }, |
| 1836 | shouldFail: true, |
| 1837 | expectedError: ":BAD_ALERT:", |
| 1838 | }, |
| 1839 | { |
| 1840 | testType: serverTest, |
| 1841 | name: "DoubleAlert", |
| 1842 | config: Config{ |
| 1843 | Bugs: ProtocolBugs{ |
| 1844 | DoubleAlert: true, |
| 1845 | SendSpuriousAlert: alertRecordOverflow, |
| 1846 | }, |
| 1847 | }, |
| 1848 | shouldFail: true, |
| 1849 | expectedError: ":BAD_ALERT:", |
| 1850 | }, |
| 1851 | { |
| 1852 | protocol: dtls, |
| 1853 | testType: serverTest, |
| 1854 | name: "DoubleAlert-DTLS", |
| 1855 | config: Config{ |
| 1856 | Bugs: ProtocolBugs{ |
| 1857 | DoubleAlert: true, |
| 1858 | SendSpuriousAlert: alertRecordOverflow, |
| 1859 | }, |
| 1860 | }, |
| 1861 | shouldFail: true, |
| 1862 | expectedError: ":BAD_ALERT:", |
| 1863 | }, |
| 1864 | { |
| 1865 | name: "SkipNewSessionTicket", |
| 1866 | config: Config{ |
| 1867 | MaxVersion: VersionTLS12, |
| 1868 | Bugs: ProtocolBugs{ |
| 1869 | SkipNewSessionTicket: true, |
| 1870 | }, |
| 1871 | }, |
| 1872 | shouldFail: true, |
| 1873 | expectedError: ":UNEXPECTED_RECORD:", |
| 1874 | }, |
| 1875 | { |
| 1876 | testType: serverTest, |
| 1877 | name: "FallbackSCSV", |
| 1878 | config: Config{ |
| 1879 | MaxVersion: VersionTLS11, |
| 1880 | Bugs: ProtocolBugs{ |
| 1881 | SendFallbackSCSV: true, |
| 1882 | }, |
| 1883 | }, |
| 1884 | shouldFail: true, |
| 1885 | expectedError: ":INAPPROPRIATE_FALLBACK:", |
| 1886 | expectedLocalError: "remote error: inappropriate fallback", |
| 1887 | }, |
| 1888 | { |
| 1889 | testType: serverTest, |
| 1890 | name: "FallbackSCSV-VersionMatch-TLS13", |
| 1891 | config: Config{ |
| 1892 | MaxVersion: VersionTLS13, |
| 1893 | Bugs: ProtocolBugs{ |
| 1894 | SendFallbackSCSV: true, |
| 1895 | }, |
| 1896 | }, |
| 1897 | }, |
| 1898 | { |
| 1899 | testType: serverTest, |
| 1900 | name: "FallbackSCSV-VersionMatch-TLS12", |
| 1901 | config: Config{ |
| 1902 | MaxVersion: VersionTLS12, |
| 1903 | Bugs: ProtocolBugs{ |
| 1904 | SendFallbackSCSV: true, |
| 1905 | }, |
| 1906 | }, |
| 1907 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 1908 | }, |
| 1909 | { |
| 1910 | testType: serverTest, |
| 1911 | name: "FragmentedClientVersion", |
| 1912 | config: Config{ |
| 1913 | Bugs: ProtocolBugs{ |
| 1914 | MaxHandshakeRecordLength: 1, |
| 1915 | FragmentClientVersion: true, |
| 1916 | }, |
| 1917 | }, |
| 1918 | expectedVersion: VersionTLS13, |
| 1919 | }, |
| 1920 | { |
| 1921 | testType: serverTest, |
| 1922 | name: "HttpGET", |
| 1923 | sendPrefix: "GET / HTTP/1.0\n", |
| 1924 | shouldFail: true, |
| 1925 | expectedError: ":HTTP_REQUEST:", |
| 1926 | }, |
| 1927 | { |
| 1928 | testType: serverTest, |
| 1929 | name: "HttpPOST", |
| 1930 | sendPrefix: "POST / HTTP/1.0\n", |
| 1931 | shouldFail: true, |
| 1932 | expectedError: ":HTTP_REQUEST:", |
| 1933 | }, |
| 1934 | { |
| 1935 | testType: serverTest, |
| 1936 | name: "HttpHEAD", |
| 1937 | sendPrefix: "HEAD / HTTP/1.0\n", |
| 1938 | shouldFail: true, |
| 1939 | expectedError: ":HTTP_REQUEST:", |
| 1940 | }, |
| 1941 | { |
| 1942 | testType: serverTest, |
| 1943 | name: "HttpPUT", |
| 1944 | sendPrefix: "PUT / HTTP/1.0\n", |
| 1945 | shouldFail: true, |
| 1946 | expectedError: ":HTTP_REQUEST:", |
| 1947 | }, |
| 1948 | { |
| 1949 | testType: serverTest, |
| 1950 | name: "HttpCONNECT", |
| 1951 | sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n", |
| 1952 | shouldFail: true, |
| 1953 | expectedError: ":HTTPS_PROXY_REQUEST:", |
| 1954 | }, |
| 1955 | { |
| 1956 | testType: serverTest, |
| 1957 | name: "Garbage", |
| 1958 | sendPrefix: "blah", |
| 1959 | shouldFail: true, |
| 1960 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 1961 | }, |
| 1962 | { |
| 1963 | name: "RSAEphemeralKey", |
| 1964 | config: Config{ |
| 1965 | MaxVersion: VersionTLS12, |
| 1966 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 1967 | Bugs: ProtocolBugs{ |
| 1968 | RSAEphemeralKey: true, |
| 1969 | }, |
| 1970 | }, |
| 1971 | shouldFail: true, |
| 1972 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 1973 | }, |
| 1974 | { |
| 1975 | name: "DisableEverything", |
| 1976 | flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1"}, |
| 1977 | shouldFail: true, |
| 1978 | expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:", |
| 1979 | }, |
| 1980 | { |
| 1981 | protocol: dtls, |
| 1982 | name: "DisableEverything-DTLS", |
| 1983 | flags: []string{"-no-tls12", "-no-tls1"}, |
| 1984 | shouldFail: true, |
| 1985 | expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:", |
| 1986 | }, |
| 1987 | { |
| 1988 | protocol: dtls, |
| 1989 | testType: serverTest, |
| 1990 | name: "MTU", |
| 1991 | config: Config{ |
| 1992 | Bugs: ProtocolBugs{ |
| 1993 | MaxPacketLength: 256, |
| 1994 | }, |
| 1995 | }, |
| 1996 | flags: []string{"-mtu", "256"}, |
| 1997 | }, |
| 1998 | { |
| 1999 | protocol: dtls, |
| 2000 | testType: serverTest, |
| 2001 | name: "MTUExceeded", |
| 2002 | config: Config{ |
| 2003 | Bugs: ProtocolBugs{ |
| 2004 | MaxPacketLength: 255, |
| 2005 | }, |
| 2006 | }, |
| 2007 | flags: []string{"-mtu", "256"}, |
| 2008 | shouldFail: true, |
| 2009 | expectedLocalError: "dtls: exceeded maximum packet length", |
| 2010 | }, |
| 2011 | { |
| 2012 | name: "EmptyCertificateList", |
| 2013 | config: Config{ |
| 2014 | MaxVersion: VersionTLS12, |
| 2015 | Bugs: ProtocolBugs{ |
| 2016 | EmptyCertificateList: true, |
| 2017 | }, |
| 2018 | }, |
| 2019 | shouldFail: true, |
| 2020 | expectedError: ":DECODE_ERROR:", |
| 2021 | }, |
| 2022 | { |
| 2023 | name: "EmptyCertificateList-TLS13", |
| 2024 | config: Config{ |
| 2025 | MaxVersion: VersionTLS13, |
| 2026 | Bugs: ProtocolBugs{ |
| 2027 | EmptyCertificateList: true, |
| 2028 | }, |
| 2029 | }, |
| 2030 | shouldFail: true, |
| 2031 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 2032 | }, |
| 2033 | { |
| 2034 | name: "TLSFatalBadPackets", |
| 2035 | damageFirstWrite: true, |
| 2036 | shouldFail: true, |
| 2037 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 2038 | }, |
| 2039 | { |
| 2040 | protocol: dtls, |
| 2041 | name: "DTLSIgnoreBadPackets", |
| 2042 | damageFirstWrite: true, |
| 2043 | }, |
| 2044 | { |
| 2045 | protocol: dtls, |
| 2046 | name: "DTLSIgnoreBadPackets-Async", |
| 2047 | damageFirstWrite: true, |
| 2048 | flags: []string{"-async"}, |
| 2049 | }, |
| 2050 | { |
| 2051 | name: "AppDataBeforeHandshake", |
| 2052 | config: Config{ |
| 2053 | Bugs: ProtocolBugs{ |
| 2054 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 2055 | }, |
| 2056 | }, |
| 2057 | shouldFail: true, |
| 2058 | expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:", |
| 2059 | }, |
| 2060 | { |
| 2061 | name: "AppDataBeforeHandshake-Empty", |
| 2062 | config: Config{ |
| 2063 | Bugs: ProtocolBugs{ |
| 2064 | AppDataBeforeHandshake: []byte{}, |
| 2065 | }, |
| 2066 | }, |
| 2067 | shouldFail: true, |
| 2068 | expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:", |
| 2069 | }, |
| 2070 | { |
| 2071 | protocol: dtls, |
| 2072 | name: "AppDataBeforeHandshake-DTLS", |
| 2073 | config: Config{ |
| 2074 | Bugs: ProtocolBugs{ |
| 2075 | AppDataBeforeHandshake: []byte("TEST MESSAGE"), |
| 2076 | }, |
| 2077 | }, |
| 2078 | shouldFail: true, |
| 2079 | expectedError: ":UNEXPECTED_RECORD:", |
| 2080 | }, |
| 2081 | { |
| 2082 | protocol: dtls, |
| 2083 | name: "AppDataBeforeHandshake-DTLS-Empty", |
| 2084 | config: Config{ |
| 2085 | Bugs: ProtocolBugs{ |
| 2086 | AppDataBeforeHandshake: []byte{}, |
| 2087 | }, |
| 2088 | }, |
| 2089 | shouldFail: true, |
| 2090 | expectedError: ":UNEXPECTED_RECORD:", |
| 2091 | }, |
| 2092 | { |
| 2093 | name: "AppDataAfterChangeCipherSpec", |
| 2094 | config: Config{ |
| 2095 | MaxVersion: VersionTLS12, |
| 2096 | Bugs: ProtocolBugs{ |
| 2097 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 2098 | }, |
| 2099 | }, |
| 2100 | shouldFail: true, |
| 2101 | expectedError: ":UNEXPECTED_RECORD:", |
| 2102 | }, |
| 2103 | { |
| 2104 | name: "AppDataAfterChangeCipherSpec-Empty", |
| 2105 | config: Config{ |
| 2106 | MaxVersion: VersionTLS12, |
| 2107 | Bugs: ProtocolBugs{ |
| 2108 | AppDataAfterChangeCipherSpec: []byte{}, |
| 2109 | }, |
| 2110 | }, |
| 2111 | shouldFail: true, |
| 2112 | expectedError: ":UNEXPECTED_RECORD:", |
| 2113 | }, |
| 2114 | { |
| 2115 | protocol: dtls, |
| 2116 | name: "AppDataAfterChangeCipherSpec-DTLS", |
| 2117 | config: Config{ |
| 2118 | MaxVersion: VersionTLS12, |
| 2119 | Bugs: ProtocolBugs{ |
| 2120 | AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"), |
| 2121 | }, |
| 2122 | }, |
| 2123 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 2124 | // application data. |
| 2125 | }, |
| 2126 | { |
| 2127 | protocol: dtls, |
| 2128 | name: "AppDataAfterChangeCipherSpec-DTLS-Empty", |
| 2129 | config: Config{ |
| 2130 | MaxVersion: VersionTLS12, |
| 2131 | Bugs: ProtocolBugs{ |
| 2132 | AppDataAfterChangeCipherSpec: []byte{}, |
| 2133 | }, |
| 2134 | }, |
| 2135 | // BoringSSL's DTLS implementation will drop the out-of-order |
| 2136 | // application data. |
| 2137 | }, |
| 2138 | { |
| 2139 | name: "AlertAfterChangeCipherSpec", |
| 2140 | config: Config{ |
| 2141 | MaxVersion: VersionTLS12, |
| 2142 | Bugs: ProtocolBugs{ |
| 2143 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 2144 | }, |
| 2145 | }, |
| 2146 | shouldFail: true, |
| 2147 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 2148 | }, |
| 2149 | { |
| 2150 | protocol: dtls, |
| 2151 | name: "AlertAfterChangeCipherSpec-DTLS", |
| 2152 | config: Config{ |
| 2153 | MaxVersion: VersionTLS12, |
| 2154 | Bugs: ProtocolBugs{ |
| 2155 | AlertAfterChangeCipherSpec: alertRecordOverflow, |
| 2156 | }, |
| 2157 | }, |
| 2158 | shouldFail: true, |
| 2159 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 2160 | }, |
| 2161 | { |
| 2162 | protocol: dtls, |
| 2163 | name: "ReorderHandshakeFragments-Small-DTLS", |
| 2164 | config: Config{ |
| 2165 | Bugs: ProtocolBugs{ |
| 2166 | ReorderHandshakeFragments: true, |
| 2167 | // Small enough that every handshake message is |
| 2168 | // fragmented. |
| 2169 | MaxHandshakeRecordLength: 2, |
| 2170 | }, |
| 2171 | }, |
| 2172 | }, |
| 2173 | { |
| 2174 | protocol: dtls, |
| 2175 | name: "ReorderHandshakeFragments-Large-DTLS", |
| 2176 | config: Config{ |
| 2177 | Bugs: ProtocolBugs{ |
| 2178 | ReorderHandshakeFragments: true, |
| 2179 | // Large enough that no handshake message is |
| 2180 | // fragmented. |
| 2181 | MaxHandshakeRecordLength: 2048, |
| 2182 | }, |
| 2183 | }, |
| 2184 | }, |
| 2185 | { |
| 2186 | protocol: dtls, |
| 2187 | name: "MixCompleteMessageWithFragments-DTLS", |
| 2188 | config: Config{ |
| 2189 | Bugs: ProtocolBugs{ |
| 2190 | ReorderHandshakeFragments: true, |
| 2191 | MixCompleteMessageWithFragments: true, |
| 2192 | MaxHandshakeRecordLength: 2, |
| 2193 | }, |
| 2194 | }, |
| 2195 | }, |
| 2196 | { |
| 2197 | name: "SendInvalidRecordType", |
| 2198 | config: Config{ |
| 2199 | Bugs: ProtocolBugs{ |
| 2200 | SendInvalidRecordType: true, |
| 2201 | }, |
| 2202 | }, |
| 2203 | shouldFail: true, |
| 2204 | expectedError: ":UNEXPECTED_RECORD:", |
| 2205 | }, |
| 2206 | { |
| 2207 | protocol: dtls, |
| 2208 | name: "SendInvalidRecordType-DTLS", |
| 2209 | config: Config{ |
| 2210 | Bugs: ProtocolBugs{ |
| 2211 | SendInvalidRecordType: true, |
| 2212 | }, |
| 2213 | }, |
| 2214 | shouldFail: true, |
| 2215 | expectedError: ":UNEXPECTED_RECORD:", |
| 2216 | }, |
| 2217 | { |
| 2218 | name: "FalseStart-SkipServerSecondLeg", |
| 2219 | config: Config{ |
| 2220 | MaxVersion: VersionTLS12, |
| 2221 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2222 | NextProtos: []string{"foo"}, |
| 2223 | Bugs: ProtocolBugs{ |
| 2224 | SkipNewSessionTicket: true, |
| 2225 | SkipChangeCipherSpec: true, |
| 2226 | SkipFinished: true, |
| 2227 | ExpectFalseStart: true, |
| 2228 | }, |
| 2229 | }, |
| 2230 | flags: []string{ |
| 2231 | "-false-start", |
| 2232 | "-handshake-never-done", |
| 2233 | "-advertise-alpn", "\x03foo", |
| 2234 | "-expect-alpn", "foo", |
| 2235 | }, |
| 2236 | shimWritesFirst: true, |
| 2237 | shouldFail: true, |
| 2238 | expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:", |
| 2239 | }, |
| 2240 | { |
| 2241 | name: "FalseStart-SkipServerSecondLeg-Implicit", |
| 2242 | config: Config{ |
| 2243 | MaxVersion: VersionTLS12, |
| 2244 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2245 | NextProtos: []string{"foo"}, |
| 2246 | Bugs: ProtocolBugs{ |
| 2247 | SkipNewSessionTicket: true, |
| 2248 | SkipChangeCipherSpec: true, |
| 2249 | SkipFinished: true, |
| 2250 | }, |
| 2251 | }, |
| 2252 | flags: []string{ |
| 2253 | "-implicit-handshake", |
| 2254 | "-false-start", |
| 2255 | "-handshake-never-done", |
| 2256 | "-advertise-alpn", "\x03foo", |
| 2257 | }, |
| 2258 | shouldFail: true, |
| 2259 | expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:", |
| 2260 | }, |
| 2261 | { |
| 2262 | testType: serverTest, |
| 2263 | name: "FailEarlyCallback", |
| 2264 | flags: []string{"-fail-early-callback"}, |
| 2265 | shouldFail: true, |
| 2266 | expectedError: ":CONNECTION_REJECTED:", |
| 2267 | expectedLocalError: "remote error: handshake failure", |
| 2268 | }, |
| 2269 | { |
| 2270 | name: "FailCertCallback-Client-TLS12", |
| 2271 | config: Config{ |
| 2272 | MaxVersion: VersionTLS12, |
| 2273 | ClientAuth: RequestClientCert, |
| 2274 | }, |
| 2275 | flags: []string{"-fail-cert-callback"}, |
| 2276 | shouldFail: true, |
| 2277 | expectedError: ":CERT_CB_ERROR:", |
| 2278 | expectedLocalError: "remote error: internal error", |
| 2279 | }, |
| 2280 | { |
| 2281 | testType: serverTest, |
| 2282 | name: "FailCertCallback-Server-TLS12", |
| 2283 | config: Config{ |
| 2284 | MaxVersion: VersionTLS12, |
| 2285 | }, |
| 2286 | flags: []string{"-fail-cert-callback"}, |
| 2287 | shouldFail: true, |
| 2288 | expectedError: ":CERT_CB_ERROR:", |
| 2289 | expectedLocalError: "remote error: internal error", |
| 2290 | }, |
| 2291 | { |
| 2292 | name: "FailCertCallback-Client-TLS13", |
| 2293 | config: Config{ |
| 2294 | MaxVersion: VersionTLS13, |
| 2295 | ClientAuth: RequestClientCert, |
| 2296 | }, |
| 2297 | flags: []string{"-fail-cert-callback"}, |
| 2298 | shouldFail: true, |
| 2299 | expectedError: ":CERT_CB_ERROR:", |
| 2300 | expectedLocalError: "remote error: internal error", |
| 2301 | }, |
| 2302 | { |
| 2303 | testType: serverTest, |
| 2304 | name: "FailCertCallback-Server-TLS13", |
| 2305 | config: Config{ |
| 2306 | MaxVersion: VersionTLS13, |
| 2307 | }, |
| 2308 | flags: []string{"-fail-cert-callback"}, |
| 2309 | shouldFail: true, |
| 2310 | expectedError: ":CERT_CB_ERROR:", |
| 2311 | expectedLocalError: "remote error: internal error", |
| 2312 | }, |
| 2313 | { |
| 2314 | protocol: dtls, |
| 2315 | name: "FragmentMessageTypeMismatch-DTLS", |
| 2316 | config: Config{ |
| 2317 | Bugs: ProtocolBugs{ |
| 2318 | MaxHandshakeRecordLength: 2, |
| 2319 | FragmentMessageTypeMismatch: true, |
| 2320 | }, |
| 2321 | }, |
| 2322 | shouldFail: true, |
| 2323 | expectedError: ":FRAGMENT_MISMATCH:", |
| 2324 | }, |
| 2325 | { |
| 2326 | protocol: dtls, |
| 2327 | name: "FragmentMessageLengthMismatch-DTLS", |
| 2328 | config: Config{ |
| 2329 | Bugs: ProtocolBugs{ |
| 2330 | MaxHandshakeRecordLength: 2, |
| 2331 | FragmentMessageLengthMismatch: true, |
| 2332 | }, |
| 2333 | }, |
| 2334 | shouldFail: true, |
| 2335 | expectedError: ":FRAGMENT_MISMATCH:", |
| 2336 | }, |
| 2337 | { |
| 2338 | protocol: dtls, |
| 2339 | name: "SplitFragments-Header-DTLS", |
| 2340 | config: Config{ |
| 2341 | Bugs: ProtocolBugs{ |
| 2342 | SplitFragments: 2, |
| 2343 | }, |
| 2344 | }, |
| 2345 | shouldFail: true, |
| 2346 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
| 2347 | }, |
| 2348 | { |
| 2349 | protocol: dtls, |
| 2350 | name: "SplitFragments-Boundary-DTLS", |
| 2351 | config: Config{ |
| 2352 | Bugs: ProtocolBugs{ |
| 2353 | SplitFragments: dtlsRecordHeaderLen, |
| 2354 | }, |
| 2355 | }, |
| 2356 | shouldFail: true, |
| 2357 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
| 2358 | }, |
| 2359 | { |
| 2360 | protocol: dtls, |
| 2361 | name: "SplitFragments-Body-DTLS", |
| 2362 | config: Config{ |
| 2363 | Bugs: ProtocolBugs{ |
| 2364 | SplitFragments: dtlsRecordHeaderLen + 1, |
| 2365 | }, |
| 2366 | }, |
| 2367 | shouldFail: true, |
| 2368 | expectedError: ":BAD_HANDSHAKE_RECORD:", |
| 2369 | }, |
| 2370 | { |
| 2371 | protocol: dtls, |
| 2372 | name: "SendEmptyFragments-DTLS", |
| 2373 | config: Config{ |
| 2374 | Bugs: ProtocolBugs{ |
| 2375 | SendEmptyFragments: true, |
| 2376 | }, |
| 2377 | }, |
| 2378 | }, |
| 2379 | { |
| 2380 | testType: serverTest, |
| 2381 | protocol: dtls, |
| 2382 | name: "SendEmptyFragments-Padded-DTLS", |
| 2383 | config: Config{ |
| 2384 | Bugs: ProtocolBugs{ |
| 2385 | // Test empty fragments for a message with a |
| 2386 | // nice power-of-two length. |
| 2387 | PadClientHello: 64, |
| 2388 | SendEmptyFragments: true, |
| 2389 | }, |
| 2390 | }, |
| 2391 | }, |
| 2392 | { |
| 2393 | name: "BadFinished-Client", |
| 2394 | config: Config{ |
| 2395 | MaxVersion: VersionTLS12, |
| 2396 | Bugs: ProtocolBugs{ |
| 2397 | BadFinished: true, |
| 2398 | }, |
| 2399 | }, |
| 2400 | shouldFail: true, |
| 2401 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 2402 | }, |
| 2403 | { |
| 2404 | name: "BadFinished-Client-TLS13", |
| 2405 | config: Config{ |
| 2406 | MaxVersion: VersionTLS13, |
| 2407 | Bugs: ProtocolBugs{ |
| 2408 | BadFinished: true, |
| 2409 | }, |
| 2410 | }, |
| 2411 | shouldFail: true, |
| 2412 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 2413 | }, |
| 2414 | { |
| 2415 | testType: serverTest, |
| 2416 | name: "BadFinished-Server", |
| 2417 | config: Config{ |
| 2418 | MaxVersion: VersionTLS12, |
| 2419 | Bugs: ProtocolBugs{ |
| 2420 | BadFinished: true, |
| 2421 | }, |
| 2422 | }, |
| 2423 | shouldFail: true, |
| 2424 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 2425 | }, |
| 2426 | { |
| 2427 | testType: serverTest, |
| 2428 | name: "BadFinished-Server-TLS13", |
| 2429 | config: Config{ |
| 2430 | MaxVersion: VersionTLS13, |
| 2431 | Bugs: ProtocolBugs{ |
| 2432 | BadFinished: true, |
| 2433 | }, |
| 2434 | }, |
| 2435 | shouldFail: true, |
| 2436 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 2437 | }, |
| 2438 | { |
| 2439 | name: "FalseStart-BadFinished", |
| 2440 | config: Config{ |
| 2441 | MaxVersion: VersionTLS12, |
| 2442 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2443 | NextProtos: []string{"foo"}, |
| 2444 | Bugs: ProtocolBugs{ |
| 2445 | BadFinished: true, |
| 2446 | ExpectFalseStart: true, |
| 2447 | }, |
| 2448 | }, |
| 2449 | flags: []string{ |
| 2450 | "-false-start", |
| 2451 | "-handshake-never-done", |
| 2452 | "-advertise-alpn", "\x03foo", |
| 2453 | "-expect-alpn", "foo", |
| 2454 | }, |
| 2455 | shimWritesFirst: true, |
| 2456 | shouldFail: true, |
| 2457 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 2458 | }, |
| 2459 | { |
| 2460 | name: "NoFalseStart-NoALPN", |
| 2461 | config: Config{ |
| 2462 | MaxVersion: VersionTLS12, |
| 2463 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2464 | Bugs: ProtocolBugs{ |
| 2465 | ExpectFalseStart: true, |
| 2466 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 2467 | }, |
| 2468 | }, |
| 2469 | flags: []string{ |
| 2470 | "-false-start", |
| 2471 | }, |
| 2472 | shimWritesFirst: true, |
| 2473 | shouldFail: true, |
| 2474 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 2475 | expectedLocalError: "tls: peer did not false start: EOF", |
| 2476 | }, |
| 2477 | { |
| 2478 | name: "FalseStart-NoALPNAllowed", |
| 2479 | config: Config{ |
| 2480 | MaxVersion: VersionTLS12, |
| 2481 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 2482 | Bugs: ProtocolBugs{ |
| 2483 | ExpectFalseStart: true, |
| 2484 | }, |
| 2485 | }, |
| 2486 | flags: []string{ |
| 2487 | "-false-start", |
| 2488 | "-allow-false-start-without-alpn", |
| 2489 | }, |
| 2490 | shimWritesFirst: true, |
| 2491 | }, |
| 2492 | { |
| 2493 | name: "NoFalseStart-NoAEAD", |
| 2494 | config: Config{ |
| 2495 | MaxVersion: VersionTLS12, |
| 2496 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 2497 | NextProtos: []string{"foo"}, |
| 2498 | Bugs: ProtocolBugs{ |
| 2499 | ExpectFalseStart: true, |
| 2500 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 2501 | }, |
| 2502 | }, |
| 2503 | flags: []string{ |
| 2504 | "-false-start", |
| 2505 | "-advertise-alpn", "\x03foo", |
| 2506 | }, |
| 2507 | shimWritesFirst: true, |
| 2508 | shouldFail: true, |
| 2509 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 2510 | expectedLocalError: "tls: peer did not false start: EOF", |
| 2511 | }, |
| 2512 | { |
| 2513 | name: "NoFalseStart-RSA", |
| 2514 | config: Config{ |
| 2515 | MaxVersion: VersionTLS12, |
| 2516 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 2517 | NextProtos: []string{"foo"}, |
| 2518 | Bugs: ProtocolBugs{ |
| 2519 | ExpectFalseStart: true, |
| 2520 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 2521 | }, |
| 2522 | }, |
| 2523 | flags: []string{ |
| 2524 | "-false-start", |
| 2525 | "-advertise-alpn", "\x03foo", |
| 2526 | }, |
| 2527 | shimWritesFirst: true, |
| 2528 | shouldFail: true, |
| 2529 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 2530 | expectedLocalError: "tls: peer did not false start: EOF", |
| 2531 | }, |
| 2532 | { |
| 2533 | protocol: dtls, |
| 2534 | name: "SendSplitAlert-Sync", |
| 2535 | config: Config{ |
| 2536 | Bugs: ProtocolBugs{ |
| 2537 | SendSplitAlert: true, |
| 2538 | }, |
| 2539 | }, |
| 2540 | }, |
| 2541 | { |
| 2542 | protocol: dtls, |
| 2543 | name: "SendSplitAlert-Async", |
| 2544 | config: Config{ |
| 2545 | Bugs: ProtocolBugs{ |
| 2546 | SendSplitAlert: true, |
| 2547 | }, |
| 2548 | }, |
| 2549 | flags: []string{"-async"}, |
| 2550 | }, |
| 2551 | { |
| 2552 | name: "SendEmptyRecords-Pass", |
| 2553 | sendEmptyRecords: 32, |
| 2554 | }, |
| 2555 | { |
| 2556 | name: "SendEmptyRecords", |
| 2557 | sendEmptyRecords: 33, |
| 2558 | shouldFail: true, |
| 2559 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 2560 | }, |
| 2561 | { |
| 2562 | name: "SendEmptyRecords-Async", |
| 2563 | sendEmptyRecords: 33, |
| 2564 | flags: []string{"-async"}, |
| 2565 | shouldFail: true, |
| 2566 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 2567 | }, |
| 2568 | { |
| 2569 | name: "SendWarningAlerts-Pass", |
| 2570 | config: Config{ |
| 2571 | MaxVersion: VersionTLS12, |
| 2572 | }, |
| 2573 | sendWarningAlerts: 4, |
| 2574 | }, |
| 2575 | { |
| 2576 | protocol: dtls, |
| 2577 | name: "SendWarningAlerts-DTLS-Pass", |
| 2578 | config: Config{ |
| 2579 | MaxVersion: VersionTLS12, |
| 2580 | }, |
| 2581 | sendWarningAlerts: 4, |
| 2582 | }, |
| 2583 | { |
| 2584 | name: "SendWarningAlerts-TLS13", |
| 2585 | config: Config{ |
| 2586 | MaxVersion: VersionTLS13, |
| 2587 | }, |
| 2588 | sendWarningAlerts: 4, |
| 2589 | shouldFail: true, |
| 2590 | expectedError: ":BAD_ALERT:", |
| 2591 | expectedLocalError: "remote error: error decoding message", |
| 2592 | }, |
| 2593 | { |
| 2594 | name: "SendWarningAlerts", |
| 2595 | config: Config{ |
| 2596 | MaxVersion: VersionTLS12, |
| 2597 | }, |
| 2598 | sendWarningAlerts: 5, |
| 2599 | shouldFail: true, |
| 2600 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 2601 | }, |
| 2602 | { |
| 2603 | name: "SendWarningAlerts-Async", |
| 2604 | config: Config{ |
| 2605 | MaxVersion: VersionTLS12, |
| 2606 | }, |
| 2607 | sendWarningAlerts: 5, |
| 2608 | flags: []string{"-async"}, |
| 2609 | shouldFail: true, |
| 2610 | expectedError: ":TOO_MANY_WARNING_ALERTS:", |
| 2611 | }, |
| 2612 | { |
| 2613 | name: "SendBogusAlertType", |
| 2614 | sendBogusAlertType: true, |
| 2615 | shouldFail: true, |
| 2616 | expectedError: ":UNKNOWN_ALERT_TYPE:", |
| 2617 | expectedLocalError: "remote error: illegal parameter", |
| 2618 | }, |
| 2619 | { |
| 2620 | protocol: dtls, |
| 2621 | name: "SendBogusAlertType-DTLS", |
| 2622 | sendBogusAlertType: true, |
| 2623 | shouldFail: true, |
| 2624 | expectedError: ":UNKNOWN_ALERT_TYPE:", |
| 2625 | expectedLocalError: "remote error: illegal parameter", |
| 2626 | }, |
| 2627 | { |
| 2628 | name: "TooManyKeyUpdates", |
| 2629 | config: Config{ |
| 2630 | MaxVersion: VersionTLS13, |
| 2631 | }, |
| 2632 | sendKeyUpdates: 33, |
| 2633 | keyUpdateRequest: keyUpdateNotRequested, |
| 2634 | shouldFail: true, |
| 2635 | expectedError: ":TOO_MANY_KEY_UPDATES:", |
| 2636 | }, |
| 2637 | { |
| 2638 | name: "EmptySessionID", |
| 2639 | config: Config{ |
| 2640 | MaxVersion: VersionTLS12, |
| 2641 | SessionTicketsDisabled: true, |
| 2642 | }, |
| 2643 | noSessionCache: true, |
| 2644 | flags: []string{"-expect-no-session"}, |
| 2645 | }, |
| 2646 | { |
| 2647 | name: "Unclean-Shutdown", |
| 2648 | config: Config{ |
| 2649 | Bugs: ProtocolBugs{ |
| 2650 | NoCloseNotify: true, |
| 2651 | ExpectCloseNotify: true, |
| 2652 | }, |
| 2653 | }, |
| 2654 | shimShutsDown: true, |
| 2655 | flags: []string{"-check-close-notify"}, |
| 2656 | shouldFail: true, |
| 2657 | expectedError: "Unexpected SSL_shutdown result: -1 != 1", |
| 2658 | }, |
| 2659 | { |
| 2660 | name: "Unclean-Shutdown-Ignored", |
| 2661 | config: Config{ |
| 2662 | Bugs: ProtocolBugs{ |
| 2663 | NoCloseNotify: true, |
| 2664 | }, |
| 2665 | }, |
| 2666 | shimShutsDown: true, |
| 2667 | }, |
| 2668 | { |
| 2669 | name: "Unclean-Shutdown-Alert", |
| 2670 | config: Config{ |
| 2671 | Bugs: ProtocolBugs{ |
| 2672 | SendAlertOnShutdown: alertDecompressionFailure, |
| 2673 | ExpectCloseNotify: true, |
| 2674 | }, |
| 2675 | }, |
| 2676 | shimShutsDown: true, |
| 2677 | flags: []string{"-check-close-notify"}, |
| 2678 | shouldFail: true, |
| 2679 | expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:", |
| 2680 | }, |
| 2681 | { |
| 2682 | name: "LargePlaintext", |
| 2683 | config: Config{ |
| 2684 | Bugs: ProtocolBugs{ |
| 2685 | SendLargeRecords: true, |
| 2686 | }, |
| 2687 | }, |
| 2688 | messageLen: maxPlaintext + 1, |
| 2689 | shouldFail: true, |
| 2690 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2691 | expectedLocalError: "remote error: record overflow", |
| 2692 | }, |
| 2693 | { |
| 2694 | protocol: dtls, |
| 2695 | name: "LargePlaintext-DTLS", |
| 2696 | config: Config{ |
| 2697 | Bugs: ProtocolBugs{ |
| 2698 | SendLargeRecords: true, |
| 2699 | }, |
| 2700 | }, |
| 2701 | messageLen: maxPlaintext + 1, |
| 2702 | shouldFail: true, |
| 2703 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2704 | expectedLocalError: "remote error: record overflow", |
| 2705 | }, |
| 2706 | { |
| 2707 | name: "LargePlaintext-TLS13-Padded-8192-8192", |
| 2708 | config: Config{ |
| 2709 | MinVersion: VersionTLS13, |
| 2710 | MaxVersion: VersionTLS13, |
| 2711 | Bugs: ProtocolBugs{ |
| 2712 | RecordPadding: 8192, |
| 2713 | SendLargeRecords: true, |
| 2714 | }, |
| 2715 | }, |
| 2716 | messageLen: 8192, |
| 2717 | }, |
| 2718 | { |
| 2719 | name: "LargePlaintext-TLS13-Padded-8193-8192", |
| 2720 | config: Config{ |
| 2721 | MinVersion: VersionTLS13, |
| 2722 | MaxVersion: VersionTLS13, |
| 2723 | Bugs: ProtocolBugs{ |
| 2724 | RecordPadding: 8193, |
| 2725 | SendLargeRecords: true, |
| 2726 | }, |
| 2727 | }, |
| 2728 | messageLen: 8192, |
| 2729 | shouldFail: true, |
| 2730 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2731 | expectedLocalError: "remote error: record overflow", |
| 2732 | }, |
| 2733 | { |
| 2734 | name: "LargePlaintext-TLS13-Padded-16383-1", |
| 2735 | config: Config{ |
| 2736 | MinVersion: VersionTLS13, |
| 2737 | MaxVersion: VersionTLS13, |
| 2738 | Bugs: ProtocolBugs{ |
| 2739 | RecordPadding: 1, |
| 2740 | SendLargeRecords: true, |
| 2741 | }, |
| 2742 | }, |
| 2743 | messageLen: 16383, |
| 2744 | }, |
| 2745 | { |
| 2746 | name: "LargePlaintext-TLS13-Padded-16384-1", |
| 2747 | config: Config{ |
| 2748 | MinVersion: VersionTLS13, |
| 2749 | MaxVersion: VersionTLS13, |
| 2750 | Bugs: ProtocolBugs{ |
| 2751 | RecordPadding: 1, |
| 2752 | SendLargeRecords: true, |
| 2753 | }, |
| 2754 | }, |
| 2755 | messageLen: 16384, |
| 2756 | shouldFail: true, |
| 2757 | expectedError: ":DATA_LENGTH_TOO_LONG:", |
| 2758 | expectedLocalError: "remote error: record overflow", |
| 2759 | }, |
| 2760 | { |
| 2761 | name: "LargeCiphertext", |
| 2762 | config: Config{ |
| 2763 | Bugs: ProtocolBugs{ |
| 2764 | SendLargeRecords: true, |
| 2765 | }, |
| 2766 | }, |
| 2767 | messageLen: maxPlaintext * 2, |
| 2768 | shouldFail: true, |
| 2769 | expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:", |
| 2770 | }, |
| 2771 | { |
| 2772 | protocol: dtls, |
| 2773 | name: "LargeCiphertext-DTLS", |
| 2774 | config: Config{ |
| 2775 | Bugs: ProtocolBugs{ |
| 2776 | SendLargeRecords: true, |
| 2777 | }, |
| 2778 | }, |
| 2779 | messageLen: maxPlaintext * 2, |
| 2780 | // Unlike the other four cases, DTLS drops records which |
| 2781 | // are invalid before authentication, so the connection |
| 2782 | // does not fail. |
| 2783 | expectMessageDropped: true, |
| 2784 | }, |
| 2785 | { |
| 2786 | name: "BadHelloRequest-1", |
| 2787 | renegotiate: 1, |
| 2788 | config: Config{ |
| 2789 | MaxVersion: VersionTLS12, |
| 2790 | Bugs: ProtocolBugs{ |
| 2791 | BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1}, |
| 2792 | }, |
| 2793 | }, |
| 2794 | flags: []string{ |
| 2795 | "-renegotiate-freely", |
| 2796 | "-expect-total-renegotiations", "1", |
| 2797 | }, |
| 2798 | shouldFail: true, |
| 2799 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2800 | }, |
| 2801 | { |
| 2802 | name: "BadHelloRequest-2", |
| 2803 | renegotiate: 1, |
| 2804 | config: Config{ |
| 2805 | MaxVersion: VersionTLS12, |
| 2806 | Bugs: ProtocolBugs{ |
| 2807 | BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0}, |
| 2808 | }, |
| 2809 | }, |
| 2810 | flags: []string{ |
| 2811 | "-renegotiate-freely", |
| 2812 | "-expect-total-renegotiations", "1", |
| 2813 | }, |
| 2814 | shouldFail: true, |
| 2815 | expectedError: ":BAD_HELLO_REQUEST:", |
| 2816 | }, |
| 2817 | { |
| 2818 | testType: serverTest, |
| 2819 | name: "SupportTicketsWithSessionID", |
| 2820 | config: Config{ |
| 2821 | MaxVersion: VersionTLS12, |
| 2822 | SessionTicketsDisabled: true, |
| 2823 | }, |
| 2824 | resumeConfig: &Config{ |
| 2825 | MaxVersion: VersionTLS12, |
| 2826 | }, |
| 2827 | resumeSession: true, |
| 2828 | }, |
| 2829 | { |
| 2830 | protocol: dtls, |
| 2831 | name: "DTLS-SendExtraFinished", |
| 2832 | config: Config{ |
| 2833 | Bugs: ProtocolBugs{ |
| 2834 | SendExtraFinished: true, |
| 2835 | }, |
| 2836 | }, |
| 2837 | shouldFail: true, |
| 2838 | expectedError: ":UNEXPECTED_RECORD:", |
| 2839 | }, |
| 2840 | { |
| 2841 | protocol: dtls, |
| 2842 | name: "DTLS-SendExtraFinished-Reordered", |
| 2843 | config: Config{ |
| 2844 | Bugs: ProtocolBugs{ |
| 2845 | MaxHandshakeRecordLength: 2, |
| 2846 | ReorderHandshakeFragments: true, |
| 2847 | SendExtraFinished: true, |
| 2848 | }, |
| 2849 | }, |
| 2850 | shouldFail: true, |
| 2851 | expectedError: ":UNEXPECTED_RECORD:", |
| 2852 | }, |
| 2853 | { |
| 2854 | testType: serverTest, |
| 2855 | name: "V2ClientHello-EmptyRecordPrefix", |
| 2856 | config: Config{ |
| 2857 | // Choose a cipher suite that does not involve |
| 2858 | // elliptic curves, so no extensions are |
| 2859 | // involved. |
| 2860 | MaxVersion: VersionTLS12, |
| 2861 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
| 2862 | Bugs: ProtocolBugs{ |
| 2863 | SendV2ClientHello: true, |
| 2864 | }, |
| 2865 | }, |
| 2866 | sendPrefix: string([]byte{ |
| 2867 | byte(recordTypeHandshake), |
| 2868 | 3, 1, // version |
| 2869 | 0, 0, // length |
| 2870 | }), |
| 2871 | // A no-op empty record may not be sent before V2ClientHello. |
| 2872 | shouldFail: true, |
| 2873 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 2874 | }, |
| 2875 | { |
| 2876 | testType: serverTest, |
| 2877 | name: "V2ClientHello-WarningAlertPrefix", |
| 2878 | config: Config{ |
| 2879 | // Choose a cipher suite that does not involve |
| 2880 | // elliptic curves, so no extensions are |
| 2881 | // involved. |
| 2882 | MaxVersion: VersionTLS12, |
| 2883 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
| 2884 | Bugs: ProtocolBugs{ |
| 2885 | SendV2ClientHello: true, |
| 2886 | }, |
| 2887 | }, |
| 2888 | sendPrefix: string([]byte{ |
| 2889 | byte(recordTypeAlert), |
| 2890 | 3, 1, // version |
| 2891 | 0, 2, // length |
| 2892 | alertLevelWarning, byte(alertDecompressionFailure), |
| 2893 | }), |
| 2894 | // A no-op warning alert may not be sent before V2ClientHello. |
| 2895 | shouldFail: true, |
| 2896 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 2897 | }, |
| 2898 | { |
| 2899 | name: "KeyUpdate-ToClient", |
| 2900 | config: Config{ |
| 2901 | MaxVersion: VersionTLS13, |
| 2902 | }, |
| 2903 | sendKeyUpdates: 1, |
| 2904 | keyUpdateRequest: keyUpdateNotRequested, |
| 2905 | }, |
| 2906 | { |
| 2907 | testType: serverTest, |
| 2908 | name: "KeyUpdate-ToServer", |
| 2909 | config: Config{ |
| 2910 | MaxVersion: VersionTLS13, |
| 2911 | }, |
| 2912 | sendKeyUpdates: 1, |
| 2913 | keyUpdateRequest: keyUpdateNotRequested, |
| 2914 | }, |
| 2915 | { |
| 2916 | name: "KeyUpdate-FromClient", |
| 2917 | config: Config{ |
| 2918 | MaxVersion: VersionTLS13, |
| 2919 | }, |
| 2920 | expectUnsolicitedKeyUpdate: true, |
| 2921 | flags: []string{"-key-update"}, |
| 2922 | }, |
| 2923 | { |
| 2924 | testType: serverTest, |
| 2925 | name: "KeyUpdate-FromServer", |
| 2926 | config: Config{ |
| 2927 | MaxVersion: VersionTLS13, |
| 2928 | }, |
| 2929 | expectUnsolicitedKeyUpdate: true, |
| 2930 | flags: []string{"-key-update"}, |
| 2931 | }, |
| 2932 | { |
| 2933 | name: "KeyUpdate-InvalidRequestMode", |
| 2934 | config: Config{ |
| 2935 | MaxVersion: VersionTLS13, |
| 2936 | }, |
| 2937 | sendKeyUpdates: 1, |
| 2938 | keyUpdateRequest: 42, |
| 2939 | shouldFail: true, |
| 2940 | expectedError: ":DECODE_ERROR:", |
| 2941 | }, |
| 2942 | { |
| 2943 | // Test that KeyUpdates are acknowledged properly. |
| 2944 | name: "KeyUpdate-RequestACK", |
| 2945 | config: Config{ |
| 2946 | MaxVersion: VersionTLS13, |
| 2947 | Bugs: ProtocolBugs{ |
| 2948 | RejectUnsolicitedKeyUpdate: true, |
| 2949 | }, |
| 2950 | }, |
| 2951 | // Test the shim receiving many KeyUpdates in a row. |
| 2952 | sendKeyUpdates: 5, |
| 2953 | messageCount: 5, |
| 2954 | keyUpdateRequest: keyUpdateRequested, |
| 2955 | }, |
| 2956 | { |
| 2957 | // Test that KeyUpdates are acknowledged properly if the |
| 2958 | // peer's KeyUpdate is discovered while a write is |
| 2959 | // pending. |
| 2960 | name: "KeyUpdate-RequestACK-UnfinishedWrite", |
| 2961 | config: Config{ |
| 2962 | MaxVersion: VersionTLS13, |
| 2963 | Bugs: ProtocolBugs{ |
| 2964 | RejectUnsolicitedKeyUpdate: true, |
| 2965 | }, |
| 2966 | }, |
| 2967 | // Test the shim receiving many KeyUpdates in a row. |
| 2968 | sendKeyUpdates: 5, |
| 2969 | messageCount: 5, |
| 2970 | keyUpdateRequest: keyUpdateRequested, |
| 2971 | readWithUnfinishedWrite: true, |
| 2972 | flags: []string{"-async"}, |
| 2973 | }, |
| 2974 | { |
| 2975 | name: "SendSNIWarningAlert", |
| 2976 | config: Config{ |
| 2977 | MaxVersion: VersionTLS12, |
| 2978 | Bugs: ProtocolBugs{ |
| 2979 | SendSNIWarningAlert: true, |
| 2980 | }, |
| 2981 | }, |
| 2982 | }, |
| 2983 | { |
| 2984 | testType: serverTest, |
| 2985 | name: "ExtraCompressionMethods-TLS12", |
| 2986 | config: Config{ |
| 2987 | MaxVersion: VersionTLS12, |
| 2988 | Bugs: ProtocolBugs{ |
| 2989 | SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6}, |
| 2990 | }, |
| 2991 | }, |
| 2992 | }, |
| 2993 | { |
| 2994 | testType: serverTest, |
| 2995 | name: "ExtraCompressionMethods-TLS13", |
| 2996 | config: Config{ |
| 2997 | MaxVersion: VersionTLS13, |
| 2998 | Bugs: ProtocolBugs{ |
| 2999 | SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6}, |
| 3000 | }, |
| 3001 | }, |
| 3002 | shouldFail: true, |
| 3003 | expectedError: ":INVALID_COMPRESSION_LIST:", |
| 3004 | expectedLocalError: "remote error: illegal parameter", |
| 3005 | }, |
| 3006 | { |
| 3007 | testType: serverTest, |
| 3008 | name: "NoNullCompression-TLS12", |
| 3009 | config: Config{ |
| 3010 | MaxVersion: VersionTLS12, |
| 3011 | Bugs: ProtocolBugs{ |
| 3012 | SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6}, |
| 3013 | }, |
| 3014 | }, |
| 3015 | shouldFail: true, |
| 3016 | expectedError: ":INVALID_COMPRESSION_LIST:", |
| 3017 | expectedLocalError: "remote error: illegal parameter", |
| 3018 | }, |
| 3019 | { |
| 3020 | testType: serverTest, |
| 3021 | name: "NoNullCompression-TLS13", |
| 3022 | config: Config{ |
| 3023 | MaxVersion: VersionTLS13, |
| 3024 | Bugs: ProtocolBugs{ |
| 3025 | SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6}, |
| 3026 | }, |
| 3027 | }, |
| 3028 | shouldFail: true, |
| 3029 | expectedError: ":INVALID_COMPRESSION_LIST:", |
| 3030 | expectedLocalError: "remote error: illegal parameter", |
| 3031 | }, |
| 3032 | // Test that the client rejects invalid compression methods |
| 3033 | // from the server. |
| 3034 | { |
| 3035 | testType: clientTest, |
| 3036 | name: "InvalidCompressionMethod", |
| 3037 | config: Config{ |
| 3038 | MaxVersion: VersionTLS12, |
| 3039 | Bugs: ProtocolBugs{ |
| 3040 | SendCompressionMethod: 1, |
| 3041 | }, |
| 3042 | }, |
| 3043 | shouldFail: true, |
| 3044 | expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:", |
| 3045 | expectedLocalError: "remote error: illegal parameter", |
| 3046 | }, |
| 3047 | { |
| 3048 | testType: clientTest, |
| 3049 | name: "TLS13-InvalidCompressionMethod", |
| 3050 | config: Config{ |
| 3051 | MaxVersion: VersionTLS13, |
| 3052 | Bugs: ProtocolBugs{ |
| 3053 | SendCompressionMethod: 1, |
| 3054 | }, |
| 3055 | }, |
| 3056 | shouldFail: true, |
| 3057 | expectedError: ":DECODE_ERROR:", |
| 3058 | }, |
| 3059 | { |
| 3060 | testType: clientTest, |
| 3061 | name: "TLS13-HRR-InvalidCompressionMethod", |
| 3062 | config: Config{ |
| 3063 | MaxVersion: VersionTLS13, |
| 3064 | CurvePreferences: []CurveID{CurveP384}, |
| 3065 | Bugs: ProtocolBugs{ |
| 3066 | SendCompressionMethod: 1, |
| 3067 | }, |
| 3068 | }, |
| 3069 | shouldFail: true, |
| 3070 | expectedError: ":DECODE_ERROR:", |
| 3071 | expectedLocalError: "remote error: error decoding message", |
| 3072 | }, |
| 3073 | { |
| 3074 | name: "GREASE-Client-TLS12", |
| 3075 | config: Config{ |
| 3076 | MaxVersion: VersionTLS12, |
| 3077 | Bugs: ProtocolBugs{ |
| 3078 | ExpectGREASE: true, |
| 3079 | }, |
| 3080 | }, |
| 3081 | flags: []string{"-enable-grease"}, |
| 3082 | }, |
| 3083 | { |
| 3084 | name: "GREASE-Client-TLS13", |
| 3085 | config: Config{ |
| 3086 | MaxVersion: VersionTLS13, |
| 3087 | Bugs: ProtocolBugs{ |
| 3088 | ExpectGREASE: true, |
| 3089 | }, |
| 3090 | }, |
| 3091 | flags: []string{"-enable-grease"}, |
| 3092 | }, |
| 3093 | { |
| 3094 | testType: serverTest, |
| 3095 | name: "GREASE-Server-TLS13", |
| 3096 | config: Config{ |
| 3097 | MaxVersion: VersionTLS13, |
| 3098 | Bugs: ProtocolBugs{ |
| 3099 | // TLS 1.3 servers are expected to |
| 3100 | // always enable GREASE. TLS 1.3 is new, |
| 3101 | // so there is no existing ecosystem to |
| 3102 | // worry about. |
| 3103 | ExpectGREASE: true, |
| 3104 | }, |
| 3105 | }, |
| 3106 | }, |
| 3107 | { |
| 3108 | // Test the TLS 1.2 server so there is a large |
| 3109 | // unencrypted certificate as well as application data. |
| 3110 | testType: serverTest, |
| 3111 | name: "MaxSendFragment-TLS12", |
| 3112 | config: Config{ |
| 3113 | MaxVersion: VersionTLS12, |
| 3114 | Bugs: ProtocolBugs{ |
| 3115 | MaxReceivePlaintext: 512, |
| 3116 | }, |
| 3117 | }, |
| 3118 | messageLen: 1024, |
| 3119 | flags: []string{ |
| 3120 | "-max-send-fragment", "512", |
| 3121 | "-read-size", "1024", |
| 3122 | }, |
| 3123 | }, |
| 3124 | { |
| 3125 | // Test the TLS 1.2 server so there is a large |
| 3126 | // unencrypted certificate as well as application data. |
| 3127 | testType: serverTest, |
| 3128 | name: "MaxSendFragment-TLS12-TooLarge", |
| 3129 | config: Config{ |
| 3130 | MaxVersion: VersionTLS12, |
| 3131 | Bugs: ProtocolBugs{ |
| 3132 | // Ensure that some of the records are |
| 3133 | // 512. |
| 3134 | MaxReceivePlaintext: 511, |
| 3135 | }, |
| 3136 | }, |
| 3137 | messageLen: 1024, |
| 3138 | flags: []string{ |
| 3139 | "-max-send-fragment", "512", |
| 3140 | "-read-size", "1024", |
| 3141 | }, |
| 3142 | shouldFail: true, |
| 3143 | expectedLocalError: "local error: record overflow", |
| 3144 | }, |
| 3145 | { |
| 3146 | // Test the TLS 1.3 server so there is a large encrypted |
| 3147 | // certificate as well as application data. |
| 3148 | testType: serverTest, |
| 3149 | name: "MaxSendFragment-TLS13", |
| 3150 | config: Config{ |
| 3151 | MaxVersion: VersionTLS13, |
| 3152 | Bugs: ProtocolBugs{ |
| 3153 | MaxReceivePlaintext: 512, |
| 3154 | ExpectPackedEncryptedHandshake: 512, |
| 3155 | }, |
| 3156 | }, |
| 3157 | messageLen: 1024, |
| 3158 | flags: []string{ |
| 3159 | "-max-send-fragment", "512", |
| 3160 | "-read-size", "1024", |
| 3161 | }, |
| 3162 | }, |
| 3163 | { |
| 3164 | // Test the TLS 1.3 server so there is a large encrypted |
| 3165 | // certificate as well as application data. |
| 3166 | testType: serverTest, |
| 3167 | name: "MaxSendFragment-TLS13-TooLarge", |
| 3168 | config: Config{ |
| 3169 | MaxVersion: VersionTLS13, |
| 3170 | Bugs: ProtocolBugs{ |
| 3171 | // Ensure that some of the records are |
| 3172 | // 512. |
| 3173 | MaxReceivePlaintext: 511, |
| 3174 | }, |
| 3175 | }, |
| 3176 | messageLen: 1024, |
| 3177 | flags: []string{ |
| 3178 | "-max-send-fragment", "512", |
| 3179 | "-read-size", "1024", |
| 3180 | }, |
| 3181 | shouldFail: true, |
| 3182 | expectedLocalError: "local error: record overflow", |
| 3183 | }, |
| 3184 | { |
| 3185 | // Test that handshake data is tightly packed in TLS 1.3. |
| 3186 | testType: serverTest, |
| 3187 | name: "PackedEncryptedHandshake-TLS13", |
| 3188 | config: Config{ |
| 3189 | MaxVersion: VersionTLS13, |
| 3190 | Bugs: ProtocolBugs{ |
| 3191 | ExpectPackedEncryptedHandshake: 16384, |
| 3192 | }, |
| 3193 | }, |
| 3194 | }, |
| 3195 | { |
| 3196 | // Test that DTLS can handle multiple application data |
| 3197 | // records in a single packet. |
| 3198 | protocol: dtls, |
| 3199 | name: "SplitAndPackAppData-DTLS", |
| 3200 | config: Config{ |
| 3201 | Bugs: ProtocolBugs{ |
| 3202 | SplitAndPackAppData: true, |
| 3203 | }, |
| 3204 | }, |
| 3205 | }, |
| 3206 | { |
| 3207 | protocol: dtls, |
| 3208 | name: "SplitAndPackAppData-DTLS-Async", |
| 3209 | config: Config{ |
| 3210 | Bugs: ProtocolBugs{ |
| 3211 | SplitAndPackAppData: true, |
| 3212 | }, |
| 3213 | }, |
| 3214 | flags: []string{"-async"}, |
| 3215 | }, |
| 3216 | } |
| 3217 | testCases = append(testCases, basicTests...) |
| 3218 |
| 3219 | // Test that very large messages can be received. |
| 3220 | cert := rsaCertificate |
| 3221 | for i := 0; i < 50; i++ { |
| 3222 | cert.Certificate = append(cert.Certificate, cert.Certificate[0]) |
| 3223 | } |
| 3224 | testCases = append(testCases, testCase{ |
| 3225 | name: "LargeMessage", |
| 3226 | config: Config{ |
| 3227 | Certificates: []Certificate{cert}, |
| 3228 | }, |
| 3229 | }) |
| 3230 | testCases = append(testCases, testCase{ |
| 3231 | protocol: dtls, |
| 3232 | name: "LargeMessage-DTLS", |
| 3233 | config: Config{ |
| 3234 | Certificates: []Certificate{cert}, |
| 3235 | }, |
| 3236 | }) |
| 3237 |
| 3238 | // They are rejected if the maximum certificate chain length is capped. |
| 3239 | testCases = append(testCases, testCase{ |
| 3240 | name: "LargeMessage-Reject", |
| 3241 | config: Config{ |
| 3242 | Certificates: []Certificate{cert}, |
| 3243 | }, |
| 3244 | flags: []string{"-max-cert-list", "16384"}, |
| 3245 | shouldFail: true, |
| 3246 | expectedError: ":EXCESSIVE_MESSAGE_SIZE:", |
| 3247 | }) |
| 3248 | testCases = append(testCases, testCase{ |
| 3249 | protocol: dtls, |
| 3250 | name: "LargeMessage-Reject-DTLS", |
| 3251 | config: Config{ |
| 3252 | Certificates: []Certificate{cert}, |
| 3253 | }, |
| 3254 | flags: []string{"-max-cert-list", "16384"}, |
| 3255 | shouldFail: true, |
| 3256 | expectedError: ":EXCESSIVE_MESSAGE_SIZE:", |
| 3257 | }) |
| 3258 |
| 3259 | // Servers echoing the TLS 1.3 compatibility mode session ID should be |
| 3260 | // rejected. |
| 3261 | testCases = append(testCases, testCase{ |
| 3262 | name: "EchoTLS13CompatibilitySessionID", |
| 3263 | config: Config{ |
| 3264 | MaxVersion: VersionTLS12, |
| 3265 | Bugs: ProtocolBugs{ |
| 3266 | EchoSessionIDInFullHandshake: true, |
| 3267 | }, |
| 3268 | }, |
| 3269 | shouldFail: true, |
| 3270 | expectedError: ":SERVER_ECHOED_INVALID_SESSION_ID:", |
| 3271 | expectedLocalError: "remote error: illegal parameter", |
| 3272 | }) |
| 3273 | } |
| 3274 |
| 3275 | func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) { |
| 3276 | const psk = "12345" |
| 3277 | const pskIdentity = "luggage combo" |
| 3278 |
| 3279 | var prefix string |
| 3280 | if protocol == dtls { |
| 3281 | if !ver.hasDTLS { |
| 3282 | return |
| 3283 | } |
| 3284 | prefix = "D" |
| 3285 | } |
| 3286 |
| 3287 | var cert Certificate |
| 3288 | var certFile string |
| 3289 | var keyFile string |
| 3290 | if hasComponent(suite.name, "ECDSA") { |
| 3291 | cert = ecdsaP256Certificate |
| 3292 | certFile = ecdsaP256CertificateFile |
| 3293 | keyFile = ecdsaP256KeyFile |
| 3294 | } else { |
| 3295 | cert = rsaCertificate |
| 3296 | certFile = rsaCertificateFile |
| 3297 | keyFile = rsaKeyFile |
| 3298 | } |
| 3299 |
| 3300 | var flags []string |
| 3301 | if hasComponent(suite.name, "PSK") { |
| 3302 | flags = append(flags, |
| 3303 | "-psk", psk, |
| 3304 | "-psk-identity", pskIdentity) |
| 3305 | } |
| 3306 | if hasComponent(suite.name, "NULL") { |
| 3307 | // NULL ciphers must be explicitly enabled. |
| 3308 | flags = append(flags, "-cipher", "DEFAULT:NULL-SHA") |
| 3309 | } |
| 3310 |
| 3311 | var shouldFail bool |
| 3312 | if isTLS12Only(suite.name) && ver.version < VersionTLS12 { |
| 3313 | shouldFail = true |
| 3314 | } |
| 3315 | if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 { |
| 3316 | shouldFail = true |
| 3317 | } |
| 3318 | if isTLS13Suite(suite.name) && ver.version < VersionTLS13 { |
| 3319 | shouldFail = true |
| 3320 | } |
| 3321 |
| 3322 | var sendCipherSuite uint16 |
| 3323 | var expectedServerError, expectedClientError string |
| 3324 | serverCipherSuites := []uint16{suite.id} |
| 3325 | if shouldFail { |
| 3326 | expectedServerError = ":NO_SHARED_CIPHER:" |
| 3327 | expectedClientError = ":WRONG_CIPHER_RETURNED:" |
| 3328 | // Configure the server to select ciphers as normal but |
| 3329 | // select an incompatible cipher in ServerHello. |
| 3330 | serverCipherSuites = nil |
| 3331 | sendCipherSuite = suite.id |
| 3332 | } |
| 3333 |
| 3334 | // Verify exporters interoperate. |
| 3335 | exportKeyingMaterial := 1024 |
| 3336 |
| 3337 | testCases = append(testCases, testCase{ |
| 3338 | testType: serverTest, |
| 3339 | protocol: protocol, |
| 3340 | name: prefix + ver.name + "-" + suite.name + "-server", |
| 3341 | config: Config{ |
| 3342 | MinVersion: ver.version, |
| 3343 | MaxVersion: ver.version, |
| 3344 | CipherSuites: []uint16{suite.id}, |
| 3345 | Certificates: []Certificate{cert}, |
| 3346 | PreSharedKey: []byte(psk), |
| 3347 | PreSharedKeyIdentity: pskIdentity, |
| 3348 | Bugs: ProtocolBugs{ |
| 3349 | AdvertiseAllConfiguredCiphers: true, |
| 3350 | }, |
| 3351 | }, |
| 3352 | certFile: certFile, |
| 3353 | keyFile: keyFile, |
| 3354 | flags: flags, |
| 3355 | resumeSession: true, |
| 3356 | shouldFail: shouldFail, |
| 3357 | expectedError: expectedServerError, |
| 3358 | exportKeyingMaterial: exportKeyingMaterial, |
| 3359 | }) |
| 3360 |
| 3361 | testCases = append(testCases, testCase{ |
| 3362 | testType: clientTest, |
| 3363 | protocol: protocol, |
| 3364 | name: prefix + ver.name + "-" + suite.name + "-client", |
| 3365 | config: Config{ |
| 3366 | MinVersion: ver.version, |
| 3367 | MaxVersion: ver.version, |
| 3368 | CipherSuites: serverCipherSuites, |
| 3369 | Certificates: []Certificate{cert}, |
| 3370 | PreSharedKey: []byte(psk), |
| 3371 | PreSharedKeyIdentity: pskIdentity, |
| 3372 | Bugs: ProtocolBugs{ |
| 3373 | IgnorePeerCipherPreferences: shouldFail, |
| 3374 | SendCipherSuite: sendCipherSuite, |
| 3375 | }, |
| 3376 | }, |
| 3377 | flags: flags, |
| 3378 | resumeSession: true, |
| 3379 | shouldFail: shouldFail, |
| 3380 | expectedError: expectedClientError, |
| 3381 | exportKeyingMaterial: exportKeyingMaterial, |
| 3382 | }) |
| 3383 |
| 3384 | if shouldFail { |
| 3385 | return |
| 3386 | } |
| 3387 |
| 3388 | // Ensure the maximum record size is accepted. |
| 3389 | testCases = append(testCases, testCase{ |
| 3390 | protocol: protocol, |
| 3391 | name: prefix + ver.name + "-" + suite.name + "-LargeRecord", |
| 3392 | config: Config{ |
| 3393 | MinVersion: ver.version, |
| 3394 | MaxVersion: ver.version, |
| 3395 | CipherSuites: []uint16{suite.id}, |
| 3396 | Certificates: []Certificate{cert}, |
| 3397 | PreSharedKey: []byte(psk), |
| 3398 | PreSharedKeyIdentity: pskIdentity, |
| 3399 | }, |
| 3400 | flags: flags, |
| 3401 | messageLen: maxPlaintext, |
| 3402 | }) |
| 3403 |
| 3404 | // Test bad records for all ciphers. Bad records are fatal in TLS |
| 3405 | // and ignored in DTLS. |
| 3406 | shouldFail = protocol == tls |
| 3407 | var expectedError string |
| 3408 | if shouldFail { |
| 3409 | expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:" |
| 3410 | } |
| 3411 |
| 3412 | testCases = append(testCases, testCase{ |
| 3413 | protocol: protocol, |
| 3414 | name: prefix + ver.name + "-" + suite.name + "-BadRecord", |
| 3415 | config: Config{ |
| 3416 | MinVersion: ver.version, |
| 3417 | MaxVersion: ver.version, |
| 3418 | CipherSuites: []uint16{suite.id}, |
| 3419 | Certificates: []Certificate{cert}, |
| 3420 | PreSharedKey: []byte(psk), |
| 3421 | PreSharedKeyIdentity: pskIdentity, |
| 3422 | }, |
| 3423 | flags: flags, |
| 3424 | damageFirstWrite: true, |
| 3425 | messageLen: maxPlaintext, |
| 3426 | shouldFail: shouldFail, |
| 3427 | expectedError: expectedError, |
| 3428 | }) |
| 3429 | } |
| 3430 |
| 3431 | func addCipherSuiteTests() { |
| 3432 | const bogusCipher = 0xfe00 |
| 3433 |
| 3434 | for _, suite := range testCipherSuites { |
| 3435 | for _, ver := range tlsVersions { |
| 3436 | for _, protocol := range []protocol{tls, dtls} { |
| 3437 | addTestForCipherSuite(suite, ver, protocol) |
| 3438 | } |
| 3439 | } |
| 3440 | } |
| 3441 |
| 3442 | testCases = append(testCases, testCase{ |
| 3443 | name: "NoSharedCipher", |
| 3444 | config: Config{ |
| 3445 | MaxVersion: VersionTLS12, |
| 3446 | CipherSuites: []uint16{}, |
| 3447 | }, |
| 3448 | shouldFail: true, |
| 3449 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 3450 | }) |
| 3451 |
| 3452 | testCases = append(testCases, testCase{ |
| 3453 | name: "NoSharedCipher-TLS13", |
| 3454 | config: Config{ |
| 3455 | MaxVersion: VersionTLS13, |
| 3456 | CipherSuites: []uint16{}, |
| 3457 | }, |
| 3458 | shouldFail: true, |
| 3459 | expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:", |
| 3460 | }) |
| 3461 |
| 3462 | testCases = append(testCases, testCase{ |
| 3463 | name: "UnsupportedCipherSuite", |
| 3464 | config: Config{ |
| 3465 | MaxVersion: VersionTLS12, |
| 3466 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 3467 | Bugs: ProtocolBugs{ |
| 3468 | IgnorePeerCipherPreferences: true, |
| 3469 | }, |
| 3470 | }, |
| 3471 | flags: []string{"-cipher", "DEFAULT:!AES"}, |
| 3472 | shouldFail: true, |
| 3473 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 3474 | }) |
| 3475 |
| 3476 | testCases = append(testCases, testCase{ |
| 3477 | name: "ServerHelloBogusCipher", |
| 3478 | config: Config{ |
| 3479 | MaxVersion: VersionTLS12, |
| 3480 | Bugs: ProtocolBugs{ |
| 3481 | SendCipherSuite: bogusCipher, |
| 3482 | }, |
| 3483 | }, |
| 3484 | shouldFail: true, |
| 3485 | expectedError: ":UNKNOWN_CIPHER_RETURNED:", |
| 3486 | }) |
| 3487 | testCases = append(testCases, testCase{ |
| 3488 | name: "ServerHelloBogusCipher-TLS13", |
| 3489 | config: Config{ |
| 3490 | MaxVersion: VersionTLS13, |
| 3491 | Bugs: ProtocolBugs{ |
| 3492 | SendCipherSuite: bogusCipher, |
| 3493 | }, |
| 3494 | }, |
| 3495 | shouldFail: true, |
| 3496 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 3497 | }) |
| 3498 |
| 3499 | // The server must be tolerant to bogus ciphers. |
| 3500 | testCases = append(testCases, testCase{ |
| 3501 | testType: serverTest, |
| 3502 | name: "UnknownCipher", |
| 3503 | config: Config{ |
| 3504 | MaxVersion: VersionTLS12, |
| 3505 | CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3506 | Bugs: ProtocolBugs{ |
| 3507 | AdvertiseAllConfiguredCiphers: true, |
| 3508 | }, |
| 3509 | }, |
| 3510 | }) |
| 3511 |
| 3512 | // The server must be tolerant to bogus ciphers. |
| 3513 | testCases = append(testCases, testCase{ |
| 3514 | testType: serverTest, |
| 3515 | name: "UnknownCipher-TLS13", |
| 3516 | config: Config{ |
| 3517 | MaxVersion: VersionTLS13, |
| 3518 | CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256}, |
| 3519 | Bugs: ProtocolBugs{ |
| 3520 | AdvertiseAllConfiguredCiphers: true, |
| 3521 | }, |
| 3522 | }, |
| 3523 | }) |
| 3524 |
| 3525 | // Test empty ECDHE_PSK identity hints work as expected. |
| 3526 | testCases = append(testCases, testCase{ |
| 3527 | name: "EmptyECDHEPSKHint", |
| 3528 | config: Config{ |
| 3529 | MaxVersion: VersionTLS12, |
| 3530 | CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 3531 | PreSharedKey: []byte("secret"), |
| 3532 | }, |
| 3533 | flags: []string{"-psk", "secret"}, |
| 3534 | }) |
| 3535 |
| 3536 | // Test empty PSK identity hints work as expected, even if an explicit |
| 3537 | // ServerKeyExchange is sent. |
| 3538 | testCases = append(testCases, testCase{ |
| 3539 | name: "ExplicitEmptyPSKHint", |
| 3540 | config: Config{ |
| 3541 | MaxVersion: VersionTLS12, |
| 3542 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 3543 | PreSharedKey: []byte("secret"), |
| 3544 | Bugs: ProtocolBugs{ |
| 3545 | AlwaysSendPreSharedKeyIdentityHint: true, |
| 3546 | }, |
| 3547 | }, |
| 3548 | flags: []string{"-psk", "secret"}, |
| 3549 | }) |
| 3550 |
| 3551 | // Test that clients enforce that the server-sent certificate and cipher |
| 3552 | // suite match in TLS 1.2. |
| 3553 | testCases = append(testCases, testCase{ |
| 3554 | name: "CertificateCipherMismatch-RSA", |
| 3555 | config: Config{ |
| 3556 | MaxVersion: VersionTLS12, |
| 3557 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3558 | Certificates: []Certificate{rsaCertificate}, |
| 3559 | Bugs: ProtocolBugs{ |
| 3560 | SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 3561 | }, |
| 3562 | }, |
| 3563 | shouldFail: true, |
| 3564 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 3565 | }) |
| 3566 | testCases = append(testCases, testCase{ |
| 3567 | name: "CertificateCipherMismatch-ECDSA", |
| 3568 | config: Config{ |
| 3569 | MaxVersion: VersionTLS12, |
| 3570 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 3571 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 3572 | Bugs: ProtocolBugs{ |
| 3573 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 3574 | }, |
| 3575 | }, |
| 3576 | shouldFail: true, |
| 3577 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 3578 | }) |
| 3579 | testCases = append(testCases, testCase{ |
| 3580 | name: "CertificateCipherMismatch-Ed25519", |
| 3581 | config: Config{ |
| 3582 | MaxVersion: VersionTLS12, |
| 3583 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 3584 | Certificates: []Certificate{ed25519Certificate}, |
| 3585 | Bugs: ProtocolBugs{ |
| 3586 | SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 3587 | }, |
| 3588 | }, |
| 3589 | shouldFail: true, |
| 3590 | expectedError: ":WRONG_CERTIFICATE_TYPE:", |
| 3591 | }) |
| 3592 |
| 3593 | // Test that servers decline to select a cipher suite which is |
| 3594 | // inconsistent with their configured certificate. |
| 3595 | testCases = append(testCases, testCase{ |
| 3596 | testType: serverTest, |
| 3597 | name: "ServerCipherFilter-RSA", |
| 3598 | config: Config{ |
| 3599 | MaxVersion: VersionTLS12, |
| 3600 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 3601 | }, |
| 3602 | flags: []string{ |
| 3603 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3604 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3605 | }, |
| 3606 | shouldFail: true, |
| 3607 | expectedError: ":NO_SHARED_CIPHER:", |
| 3608 | }) |
| 3609 | testCases = append(testCases, testCase{ |
| 3610 | testType: serverTest, |
| 3611 | name: "ServerCipherFilter-ECDSA", |
| 3612 | config: Config{ |
| 3613 | MaxVersion: VersionTLS12, |
| 3614 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3615 | }, |
| 3616 | flags: []string{ |
| 3617 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3618 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 3619 | }, |
| 3620 | shouldFail: true, |
| 3621 | expectedError: ":NO_SHARED_CIPHER:", |
| 3622 | }) |
| 3623 | testCases = append(testCases, testCase{ |
| 3624 | testType: serverTest, |
| 3625 | name: "ServerCipherFilter-Ed25519", |
| 3626 | config: Config{ |
| 3627 | MaxVersion: VersionTLS12, |
| 3628 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 3629 | }, |
| 3630 | flags: []string{ |
| 3631 | "-cert-file", path.Join(*resourceDir, ed25519CertificateFile), |
| 3632 | "-key-file", path.Join(*resourceDir, ed25519KeyFile), |
| 3633 | }, |
| 3634 | shouldFail: true, |
| 3635 | expectedError: ":NO_SHARED_CIPHER:", |
| 3636 | }) |
| 3637 |
| 3638 | // Test cipher suite negotiation works as expected. Configure a |
| 3639 | // complicated cipher suite configuration. |
| 3640 | const negotiationTestCiphers = "" + |
| 3641 | "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" + |
| 3642 | "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" + |
| 3643 | "TLS_RSA_WITH_AES_128_GCM_SHA256:" + |
| 3644 | "TLS_RSA_WITH_AES_128_CBC_SHA:" + |
| 3645 | "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]" |
| 3646 | negotiationTests := []struct { |
| 3647 | ciphers []uint16 |
| 3648 | expected uint16 |
| 3649 | }{ |
| 3650 | // Server preferences are honored, including when |
| 3651 | // equipreference groups are involved. |
| 3652 | { |
| 3653 | []uint16{ |
| 3654 | TLS_RSA_WITH_AES_256_GCM_SHA384, |
| 3655 | TLS_RSA_WITH_AES_128_CBC_SHA, |
| 3656 | TLS_RSA_WITH_AES_128_GCM_SHA256, |
| 3657 | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, |
| 3658 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 3659 | }, |
| 3660 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 3661 | }, |
| 3662 | { |
| 3663 | []uint16{ |
| 3664 | TLS_RSA_WITH_AES_256_GCM_SHA384, |
| 3665 | TLS_RSA_WITH_AES_128_CBC_SHA, |
| 3666 | TLS_RSA_WITH_AES_128_GCM_SHA256, |
| 3667 | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, |
| 3668 | }, |
| 3669 | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, |
| 3670 | }, |
| 3671 | { |
| 3672 | []uint16{ |
| 3673 | TLS_RSA_WITH_AES_256_GCM_SHA384, |
| 3674 | TLS_RSA_WITH_AES_128_CBC_SHA, |
| 3675 | TLS_RSA_WITH_AES_128_GCM_SHA256, |
| 3676 | }, |
| 3677 | TLS_RSA_WITH_AES_128_GCM_SHA256, |
| 3678 | }, |
| 3679 | { |
| 3680 | []uint16{ |
| 3681 | TLS_RSA_WITH_AES_256_GCM_SHA384, |
| 3682 | TLS_RSA_WITH_AES_128_CBC_SHA, |
| 3683 | }, |
| 3684 | TLS_RSA_WITH_AES_128_CBC_SHA, |
| 3685 | }, |
| 3686 | // Equipreference groups use the client preference. |
| 3687 | { |
| 3688 | []uint16{ |
| 3689 | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, |
| 3690 | TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, |
| 3691 | TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
| 3692 | }, |
| 3693 | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, |
| 3694 | }, |
| 3695 | { |
| 3696 | []uint16{ |
| 3697 | TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, |
| 3698 | TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
| 3699 | }, |
| 3700 | TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, |
| 3701 | }, |
| 3702 | { |
| 3703 | []uint16{ |
| 3704 | TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
| 3705 | TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, |
| 3706 | }, |
| 3707 | TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
| 3708 | }, |
| 3709 | { |
| 3710 | []uint16{ |
| 3711 | TLS_RSA_WITH_AES_256_GCM_SHA384, |
| 3712 | TLS_RSA_WITH_AES_256_CBC_SHA, |
| 3713 | }, |
| 3714 | TLS_RSA_WITH_AES_256_GCM_SHA384, |
| 3715 | }, |
| 3716 | { |
| 3717 | []uint16{ |
| 3718 | TLS_RSA_WITH_AES_256_CBC_SHA, |
| 3719 | TLS_RSA_WITH_AES_256_GCM_SHA384, |
| 3720 | }, |
| 3721 | TLS_RSA_WITH_AES_256_CBC_SHA, |
| 3722 | }, |
| 3723 | // If there are two equipreference groups, the preferred one |
| 3724 | // takes precedence. |
| 3725 | { |
| 3726 | []uint16{ |
| 3727 | TLS_RSA_WITH_AES_256_GCM_SHA384, |
| 3728 | TLS_RSA_WITH_AES_256_CBC_SHA, |
| 3729 | TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
| 3730 | TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, |
| 3731 | }, |
| 3732 | TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
| 3733 | }, |
| 3734 | } |
| 3735 | for i, t := range negotiationTests { |
| 3736 | testCases = append(testCases, testCase{ |
| 3737 | testType: serverTest, |
| 3738 | name: "CipherNegotiation-" + strconv.Itoa(i), |
| 3739 | config: Config{ |
| 3740 | MaxVersion: VersionTLS12, |
| 3741 | CipherSuites: t.ciphers, |
| 3742 | }, |
| 3743 | flags: []string{"-cipher", negotiationTestCiphers}, |
| 3744 | expectedCipher: t.expected, |
| 3745 | }) |
| 3746 | } |
| 3747 | } |
| 3748 |
| 3749 | func addBadECDSASignatureTests() { |
| 3750 | for badR := BadValue(1); badR < NumBadValues; badR++ { |
| 3751 | for badS := BadValue(1); badS < NumBadValues; badS++ { |
| 3752 | testCases = append(testCases, testCase{ |
| 3753 | name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS), |
| 3754 | config: Config{ |
| 3755 | MaxVersion: VersionTLS12, |
| 3756 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 3757 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 3758 | Bugs: ProtocolBugs{ |
| 3759 | BadECDSAR: badR, |
| 3760 | BadECDSAS: badS, |
| 3761 | }, |
| 3762 | }, |
| 3763 | shouldFail: true, |
| 3764 | expectedError: ":BAD_SIGNATURE:", |
| 3765 | }) |
| 3766 | testCases = append(testCases, testCase{ |
| 3767 | name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS), |
| 3768 | config: Config{ |
| 3769 | MaxVersion: VersionTLS13, |
| 3770 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 3771 | Bugs: ProtocolBugs{ |
| 3772 | BadECDSAR: badR, |
| 3773 | BadECDSAS: badS, |
| 3774 | }, |
| 3775 | }, |
| 3776 | shouldFail: true, |
| 3777 | expectedError: ":BAD_SIGNATURE:", |
| 3778 | }) |
| 3779 | } |
| 3780 | } |
| 3781 | } |
| 3782 |
| 3783 | func addCBCPaddingTests() { |
| 3784 | testCases = append(testCases, testCase{ |
| 3785 | name: "MaxCBCPadding", |
| 3786 | config: Config{ |
| 3787 | MaxVersion: VersionTLS12, |
| 3788 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 3789 | Bugs: ProtocolBugs{ |
| 3790 | MaxPadding: true, |
| 3791 | }, |
| 3792 | }, |
| 3793 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 3794 | }) |
| 3795 | testCases = append(testCases, testCase{ |
| 3796 | name: "BadCBCPadding", |
| 3797 | config: Config{ |
| 3798 | MaxVersion: VersionTLS12, |
| 3799 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 3800 | Bugs: ProtocolBugs{ |
| 3801 | PaddingFirstByteBad: true, |
| 3802 | }, |
| 3803 | }, |
| 3804 | shouldFail: true, |
| 3805 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 3806 | }) |
| 3807 | // OpenSSL previously had an issue where the first byte of padding in |
| 3808 | // 255 bytes of padding wasn't checked. |
| 3809 | testCases = append(testCases, testCase{ |
| 3810 | name: "BadCBCPadding255", |
| 3811 | config: Config{ |
| 3812 | MaxVersion: VersionTLS12, |
| 3813 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 3814 | Bugs: ProtocolBugs{ |
| 3815 | MaxPadding: true, |
| 3816 | PaddingFirstByteBadIf255: true, |
| 3817 | }, |
| 3818 | }, |
| 3819 | messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size |
| 3820 | shouldFail: true, |
| 3821 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 3822 | }) |
| 3823 | } |
| 3824 |
| 3825 | func addCBCSplittingTests() { |
| 3826 | var cbcCiphers = []struct { |
| 3827 | name string |
| 3828 | cipher uint16 |
| 3829 | }{ |
| 3830 | {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
| 3831 | {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 3832 | {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, |
| 3833 | } |
| 3834 | for _, t := range cbcCiphers { |
| 3835 | testCases = append(testCases, testCase{ |
| 3836 | name: "CBCRecordSplitting-" + t.name, |
| 3837 | config: Config{ |
| 3838 | MaxVersion: VersionTLS10, |
| 3839 | MinVersion: VersionTLS10, |
| 3840 | CipherSuites: []uint16{t.cipher}, |
| 3841 | Bugs: ProtocolBugs{ |
| 3842 | ExpectRecordSplitting: true, |
| 3843 | }, |
| 3844 | }, |
| 3845 | messageLen: -1, // read until EOF |
| 3846 | resumeSession: true, |
| 3847 | flags: []string{ |
| 3848 | "-async", |
| 3849 | "-write-different-record-sizes", |
| 3850 | "-cbc-record-splitting", |
| 3851 | }, |
| 3852 | }) |
| 3853 | testCases = append(testCases, testCase{ |
| 3854 | name: "CBCRecordSplittingPartialWrite-" + t.name, |
| 3855 | config: Config{ |
| 3856 | MaxVersion: VersionTLS10, |
| 3857 | MinVersion: VersionTLS10, |
| 3858 | CipherSuites: []uint16{t.cipher}, |
| 3859 | Bugs: ProtocolBugs{ |
| 3860 | ExpectRecordSplitting: true, |
| 3861 | }, |
| 3862 | }, |
| 3863 | messageLen: -1, // read until EOF |
| 3864 | flags: []string{ |
| 3865 | "-async", |
| 3866 | "-write-different-record-sizes", |
| 3867 | "-cbc-record-splitting", |
| 3868 | "-partial-write", |
| 3869 | }, |
| 3870 | }) |
| 3871 | } |
| 3872 | } |
| 3873 |
| 3874 | func addClientAuthTests() { |
| 3875 | // Add a dummy cert pool to stress certificate authority parsing. |
| 3876 | certPool := x509.NewCertPool() |
| 3877 | for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} { |
| 3878 | cert, err := x509.ParseCertificate(cert.Certificate[0]) |
| 3879 | if err != nil { |
| 3880 | panic(err) |
| 3881 | } |
| 3882 | certPool.AddCert(cert) |
| 3883 | } |
| 3884 | caNames := certPool.Subjects() |
| 3885 |
| 3886 | for _, ver := range tlsVersions { |
| 3887 | testCases = append(testCases, testCase{ |
| 3888 | testType: clientTest, |
| 3889 | name: ver.name + "-Client-ClientAuth-RSA", |
| 3890 | config: Config{ |
| 3891 | MinVersion: ver.version, |
| 3892 | MaxVersion: ver.version, |
| 3893 | ClientAuth: RequireAnyClientCert, |
| 3894 | ClientCAs: certPool, |
| 3895 | }, |
| 3896 | flags: []string{ |
| 3897 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 3898 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 3899 | }, |
| 3900 | }) |
| 3901 | testCases = append(testCases, testCase{ |
| 3902 | testType: serverTest, |
| 3903 | name: ver.name + "-Server-ClientAuth-RSA", |
| 3904 | config: Config{ |
| 3905 | MinVersion: ver.version, |
| 3906 | MaxVersion: ver.version, |
| 3907 | Certificates: []Certificate{rsaCertificate}, |
| 3908 | }, |
| 3909 | flags: []string{"-require-any-client-certificate"}, |
| 3910 | }) |
| 3911 | testCases = append(testCases, testCase{ |
| 3912 | testType: serverTest, |
| 3913 | name: ver.name + "-Server-ClientAuth-ECDSA", |
| 3914 | config: Config{ |
| 3915 | MinVersion: ver.version, |
| 3916 | MaxVersion: ver.version, |
| 3917 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 3918 | }, |
| 3919 | flags: []string{"-require-any-client-certificate"}, |
| 3920 | }) |
| 3921 | testCases = append(testCases, testCase{ |
| 3922 | testType: clientTest, |
| 3923 | name: ver.name + "-Client-ClientAuth-ECDSA", |
| 3924 | config: Config{ |
| 3925 | MinVersion: ver.version, |
| 3926 | MaxVersion: ver.version, |
| 3927 | ClientAuth: RequireAnyClientCert, |
| 3928 | ClientCAs: certPool, |
| 3929 | }, |
| 3930 | flags: []string{ |
| 3931 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 3932 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 3933 | }, |
| 3934 | }) |
| 3935 |
| 3936 | testCases = append(testCases, testCase{ |
| 3937 | name: "NoClientCertificate-" + ver.name, |
| 3938 | config: Config{ |
| 3939 | MinVersion: ver.version, |
| 3940 | MaxVersion: ver.version, |
| 3941 | ClientAuth: RequireAnyClientCert, |
| 3942 | }, |
| 3943 | shouldFail: true, |
| 3944 | expectedLocalError: "client didn't provide a certificate", |
| 3945 | }) |
| 3946 |
| 3947 | testCases = append(testCases, testCase{ |
| 3948 | // Even if not configured to expect a certificate, OpenSSL will |
| 3949 | // return X509_V_OK as the verify_result. |
| 3950 | testType: serverTest, |
| 3951 | name: "NoClientCertificateRequested-Server-" + ver.name, |
| 3952 | config: Config{ |
| 3953 | MinVersion: ver.version, |
| 3954 | MaxVersion: ver.version, |
| 3955 | }, |
| 3956 | flags: []string{ |
| 3957 | "-expect-verify-result", |
| 3958 | }, |
| 3959 | resumeSession: true, |
| 3960 | }) |
| 3961 |
| 3962 | testCases = append(testCases, testCase{ |
| 3963 | // If a client certificate is not provided, OpenSSL will still |
| 3964 | // return X509_V_OK as the verify_result. |
| 3965 | testType: serverTest, |
| 3966 | name: "NoClientCertificate-Server-" + ver.name, |
| 3967 | config: Config{ |
| 3968 | MinVersion: ver.version, |
| 3969 | MaxVersion: ver.version, |
| 3970 | }, |
| 3971 | flags: []string{ |
| 3972 | "-expect-verify-result", |
| 3973 | "-verify-peer", |
| 3974 | }, |
| 3975 | resumeSession: true, |
| 3976 | }) |
| 3977 |
| 3978 | certificateRequired := "remote error: certificate required" |
| 3979 | if ver.version < VersionTLS13 { |
| 3980 | // Prior to TLS 1.3, the generic handshake_failure alert |
| 3981 | // was used. |
| 3982 | certificateRequired = "remote error: handshake failure" |
| 3983 | } |
| 3984 | testCases = append(testCases, testCase{ |
| 3985 | testType: serverTest, |
| 3986 | name: "RequireAnyClientCertificate-" + ver.name, |
| 3987 | config: Config{ |
| 3988 | MinVersion: ver.version, |
| 3989 | MaxVersion: ver.version, |
| 3990 | }, |
| 3991 | flags: []string{"-require-any-client-certificate"}, |
| 3992 | shouldFail: true, |
| 3993 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 3994 | expectedLocalError: certificateRequired, |
| 3995 | }) |
| 3996 |
| 3997 | testCases = append(testCases, testCase{ |
| 3998 | testType: serverTest, |
| 3999 | name: "SkipClientCertificate-" + ver.name, |
| 4000 | config: Config{ |
| 4001 | MinVersion: ver.version, |
| 4002 | MaxVersion: ver.version, |
| 4003 | Bugs: ProtocolBugs{ |
| 4004 | SkipClientCertificate: true, |
| 4005 | }, |
| 4006 | }, |
| 4007 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 4008 | flags: []string{"-verify-peer"}, |
| 4009 | shouldFail: true, |
| 4010 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 4011 | }) |
| 4012 |
| 4013 | testCases = append(testCases, testCase{ |
| 4014 | testType: serverTest, |
| 4015 | name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name, |
| 4016 | config: Config{ |
| 4017 | MinVersion: ver.version, |
| 4018 | MaxVersion: ver.version, |
| 4019 | }, |
| 4020 | flags: []string{ |
| 4021 | "-enable-channel-id", |
| 4022 | "-verify-peer-if-no-obc", |
| 4023 | }, |
| 4024 | shouldFail: true, |
| 4025 | expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:", |
| 4026 | expectedLocalError: certificateRequired, |
| 4027 | }) |
| 4028 |
| 4029 | testCases = append(testCases, testCase{ |
| 4030 | testType: serverTest, |
| 4031 | name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name, |
| 4032 | config: Config{ |
| 4033 | MinVersion: ver.version, |
| 4034 | MaxVersion: ver.version, |
| 4035 | ChannelID: channelIDKey, |
| 4036 | }, |
| 4037 | expectChannelID: true, |
| 4038 | flags: []string{ |
| 4039 | "-enable-channel-id", |
| 4040 | "-verify-peer-if-no-obc", |
| 4041 | }, |
| 4042 | }) |
| 4043 |
| 4044 | testCases = append(testCases, testCase{ |
| 4045 | testType: serverTest, |
| 4046 | name: ver.name + "-Server-CertReq-CA-List", |
| 4047 | config: Config{ |
| 4048 | MinVersion: ver.version, |
| 4049 | MaxVersion: ver.version, |
| 4050 | Certificates: []Certificate{rsaCertificate}, |
| 4051 | Bugs: ProtocolBugs{ |
| 4052 | ExpectCertificateReqNames: caNames, |
| 4053 | }, |
| 4054 | }, |
| 4055 | flags: []string{ |
| 4056 | "-require-any-client-certificate", |
| 4057 | "-use-client-ca-list", encodeDERValues(caNames), |
| 4058 | }, |
| 4059 | }) |
| 4060 |
| 4061 | testCases = append(testCases, testCase{ |
| 4062 | testType: clientTest, |
| 4063 | name: ver.name + "-Client-CertReq-CA-List", |
| 4064 | config: Config{ |
| 4065 | MinVersion: ver.version, |
| 4066 | MaxVersion: ver.version, |
| 4067 | Certificates: []Certificate{rsaCertificate}, |
| 4068 | ClientAuth: RequireAnyClientCert, |
| 4069 | ClientCAs: certPool, |
| 4070 | }, |
| 4071 | flags: []string{ |
| 4072 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4073 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4074 | "-expect-client-ca-list", encodeDERValues(caNames), |
| 4075 | }, |
| 4076 | }) |
| 4077 | } |
| 4078 |
| 4079 | // Client auth is only legal in certificate-based ciphers. |
| 4080 | testCases = append(testCases, testCase{ |
| 4081 | testType: clientTest, |
| 4082 | name: "ClientAuth-PSK", |
| 4083 | config: Config{ |
| 4084 | MaxVersion: VersionTLS12, |
| 4085 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 4086 | PreSharedKey: []byte("secret"), |
| 4087 | ClientAuth: RequireAnyClientCert, |
| 4088 | }, |
| 4089 | flags: []string{ |
| 4090 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4091 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4092 | "-psk", "secret", |
| 4093 | }, |
| 4094 | shouldFail: true, |
| 4095 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 4096 | }) |
| 4097 | testCases = append(testCases, testCase{ |
| 4098 | testType: clientTest, |
| 4099 | name: "ClientAuth-ECDHE_PSK", |
| 4100 | config: Config{ |
| 4101 | MaxVersion: VersionTLS12, |
| 4102 | CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA}, |
| 4103 | PreSharedKey: []byte("secret"), |
| 4104 | ClientAuth: RequireAnyClientCert, |
| 4105 | }, |
| 4106 | flags: []string{ |
| 4107 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4108 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4109 | "-psk", "secret", |
| 4110 | }, |
| 4111 | shouldFail: true, |
| 4112 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 4113 | }) |
| 4114 |
| 4115 | // Regression test for a bug where the client CA list, if explicitly |
| 4116 | // set to NULL, was mis-encoded. |
| 4117 | testCases = append(testCases, testCase{ |
| 4118 | testType: serverTest, |
| 4119 | name: "Null-Client-CA-List", |
| 4120 | config: Config{ |
| 4121 | MaxVersion: VersionTLS12, |
| 4122 | Certificates: []Certificate{rsaCertificate}, |
| 4123 | Bugs: ProtocolBugs{ |
| 4124 | ExpectCertificateReqNames: [][]byte{}, |
| 4125 | }, |
| 4126 | }, |
| 4127 | flags: []string{ |
| 4128 | "-require-any-client-certificate", |
| 4129 | "-use-client-ca-list", "<NULL>", |
| 4130 | }, |
| 4131 | }) |
| 4132 |
| 4133 | // Test that an empty client CA list doesn't send a CA extension. |
| 4134 | testCases = append(testCases, testCase{ |
| 4135 | testType: serverTest, |
| 4136 | name: "TLS13-Empty-Client-CA-List", |
| 4137 | config: Config{ |
| 4138 | MaxVersion: VersionTLS13, |
| 4139 | Certificates: []Certificate{rsaCertificate}, |
| 4140 | Bugs: ProtocolBugs{ |
| 4141 | ExpectNoCertificateAuthoritiesExtension: true, |
| 4142 | }, |
| 4143 | }, |
| 4144 | flags: []string{ |
| 4145 | "-require-any-client-certificate", |
| 4146 | "-use-client-ca-list", "<EMPTY>", |
| 4147 | }, |
| 4148 | }) |
| 4149 |
| 4150 | } |
| 4151 |
| 4152 | func addExtendedMasterSecretTests() { |
| 4153 | const expectEMSFlag = "-expect-extended-master-secret" |
| 4154 |
| 4155 | for _, with := range []bool{false, true} { |
| 4156 | prefix := "No" |
| 4157 | if with { |
| 4158 | prefix = "" |
| 4159 | } |
| 4160 |
| 4161 | for _, isClient := range []bool{false, true} { |
| 4162 | suffix := "-Server" |
| 4163 | testType := serverTest |
| 4164 | if isClient { |
| 4165 | suffix = "-Client" |
| 4166 | testType = clientTest |
| 4167 | } |
| 4168 |
| 4169 | for _, ver := range tlsVersions { |
| 4170 | // In TLS 1.3, the extension is irrelevant and |
| 4171 | // always reports as enabled. |
| 4172 | var flags []string |
| 4173 | if with || ver.version >= VersionTLS13 { |
| 4174 | flags = []string{expectEMSFlag} |
| 4175 | } |
| 4176 |
| 4177 | testCases = append(testCases, testCase{ |
| 4178 | testType: testType, |
| 4179 | name: prefix + "ExtendedMasterSecret-" + ver.name + suffix, |
| 4180 | config: Config{ |
| 4181 | MinVersion: ver.version, |
| 4182 | MaxVersion: ver.version, |
| 4183 | Bugs: ProtocolBugs{ |
| 4184 | NoExtendedMasterSecret: !with, |
| 4185 | RequireExtendedMasterSecret: with, |
| 4186 | }, |
| 4187 | }, |
| 4188 | flags: flags, |
| 4189 | }) |
| 4190 | } |
| 4191 | } |
| 4192 | } |
| 4193 |
| 4194 | for _, isClient := range []bool{false, true} { |
| 4195 | for _, supportedInFirstConnection := range []bool{false, true} { |
| 4196 | for _, supportedInResumeConnection := range []bool{false, true} { |
| 4197 | boolToWord := func(b bool) string { |
| 4198 | if b { |
| 4199 | return "Yes" |
| 4200 | } |
| 4201 | return "No" |
| 4202 | } |
| 4203 | suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-" |
| 4204 | if isClient { |
| 4205 | suffix += "Client" |
| 4206 | } else { |
| 4207 | suffix += "Server" |
| 4208 | } |
| 4209 |
| 4210 | supportedConfig := Config{ |
| 4211 | MaxVersion: VersionTLS12, |
| 4212 | Bugs: ProtocolBugs{ |
| 4213 | RequireExtendedMasterSecret: true, |
| 4214 | }, |
| 4215 | } |
| 4216 |
| 4217 | noSupportConfig := Config{ |
| 4218 | MaxVersion: VersionTLS12, |
| 4219 | Bugs: ProtocolBugs{ |
| 4220 | NoExtendedMasterSecret: true, |
| 4221 | }, |
| 4222 | } |
| 4223 |
| 4224 | test := testCase{ |
| 4225 | name: "ExtendedMasterSecret-" + suffix, |
| 4226 | resumeSession: true, |
| 4227 | } |
| 4228 |
| 4229 | if !isClient { |
| 4230 | test.testType = serverTest |
| 4231 | } |
| 4232 |
| 4233 | if supportedInFirstConnection { |
| 4234 | test.config = supportedConfig |
| 4235 | } else { |
| 4236 | test.config = noSupportConfig |
| 4237 | } |
| 4238 |
| 4239 | if supportedInResumeConnection { |
| 4240 | test.resumeConfig = &supportedConfig |
| 4241 | } else { |
| 4242 | test.resumeConfig = &noSupportConfig |
| 4243 | } |
| 4244 |
| 4245 | switch suffix { |
| 4246 | case "YesToYes-Client", "YesToYes-Server": |
| 4247 | // When a session is resumed, it should |
| 4248 | // still be aware that its master |
| 4249 | // secret was generated via EMS and |
| 4250 | // thus it's safe to use tls-unique. |
| 4251 | test.flags = []string{expectEMSFlag} |
| 4252 | case "NoToYes-Server": |
| 4253 | // If an original connection did not |
| 4254 | // contain EMS, but a resumption |
| 4255 | // handshake does, then a server should |
| 4256 | // not resume the session. |
| 4257 | test.expectResumeRejected = true |
| 4258 | case "YesToNo-Server": |
| 4259 | // Resuming an EMS session without the |
| 4260 | // EMS extension should cause the |
| 4261 | // server to abort the connection. |
| 4262 | test.shouldFail = true |
| 4263 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 4264 | case "NoToYes-Client": |
| 4265 | // A client should abort a connection |
| 4266 | // where the server resumed a non-EMS |
| 4267 | // session but echoed the EMS |
| 4268 | // extension. |
| 4269 | test.shouldFail = true |
| 4270 | test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:" |
| 4271 | case "YesToNo-Client": |
| 4272 | // A client should abort a connection |
| 4273 | // where the server didn't echo EMS |
| 4274 | // when the session used it. |
| 4275 | test.shouldFail = true |
| 4276 | test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:" |
| 4277 | } |
| 4278 |
| 4279 | testCases = append(testCases, test) |
| 4280 | } |
| 4281 | } |
| 4282 | } |
| 4283 |
| 4284 | // Switching EMS on renegotiation is forbidden. |
| 4285 | testCases = append(testCases, testCase{ |
| 4286 | name: "ExtendedMasterSecret-Renego-NoEMS", |
| 4287 | config: Config{ |
| 4288 | MaxVersion: VersionTLS12, |
| 4289 | Bugs: ProtocolBugs{ |
| 4290 | NoExtendedMasterSecret: true, |
| 4291 | NoExtendedMasterSecretOnRenegotiation: true, |
| 4292 | }, |
| 4293 | }, |
| 4294 | renegotiate: 1, |
| 4295 | flags: []string{ |
| 4296 | "-renegotiate-freely", |
| 4297 | "-expect-total-renegotiations", "1", |
| 4298 | }, |
| 4299 | }) |
| 4300 |
| 4301 | testCases = append(testCases, testCase{ |
| 4302 | name: "ExtendedMasterSecret-Renego-Upgrade", |
| 4303 | config: Config{ |
| 4304 | MaxVersion: VersionTLS12, |
| 4305 | Bugs: ProtocolBugs{ |
| 4306 | NoExtendedMasterSecret: true, |
| 4307 | }, |
| 4308 | }, |
| 4309 | renegotiate: 1, |
| 4310 | flags: []string{ |
| 4311 | "-renegotiate-freely", |
| 4312 | "-expect-total-renegotiations", "1", |
| 4313 | }, |
| 4314 | shouldFail: true, |
| 4315 | expectedError: ":RENEGOTIATION_EMS_MISMATCH:", |
| 4316 | }) |
| 4317 |
| 4318 | testCases = append(testCases, testCase{ |
| 4319 | name: "ExtendedMasterSecret-Renego-Downgrade", |
| 4320 | config: Config{ |
| 4321 | MaxVersion: VersionTLS12, |
| 4322 | Bugs: ProtocolBugs{ |
| 4323 | NoExtendedMasterSecretOnRenegotiation: true, |
| 4324 | }, |
| 4325 | }, |
| 4326 | renegotiate: 1, |
| 4327 | flags: []string{ |
| 4328 | "-renegotiate-freely", |
| 4329 | "-expect-total-renegotiations", "1", |
| 4330 | }, |
| 4331 | shouldFail: true, |
| 4332 | expectedError: ":RENEGOTIATION_EMS_MISMATCH:", |
| 4333 | }) |
| 4334 | } |
| 4335 |
| 4336 | type stateMachineTestConfig struct { |
| 4337 | protocol protocol |
| 4338 | async bool |
| 4339 | splitHandshake bool |
| 4340 | packHandshake bool |
| 4341 | implicitHandshake bool |
| 4342 | } |
| 4343 |
| 4344 | // Adds tests that try to cover the range of the handshake state machine, under |
| 4345 | // various conditions. Some of these are redundant with other tests, but they |
| 4346 | // only cover the synchronous case. |
| 4347 | func addAllStateMachineCoverageTests() { |
| 4348 | for _, async := range []bool{false, true} { |
| 4349 | for _, protocol := range []protocol{tls, dtls} { |
| 4350 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 4351 | protocol: protocol, |
| 4352 | async: async, |
| 4353 | }) |
| 4354 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 4355 | protocol: protocol, |
| 4356 | async: async, |
| 4357 | implicitHandshake: true, |
| 4358 | }) |
| 4359 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 4360 | protocol: protocol, |
| 4361 | async: async, |
| 4362 | splitHandshake: true, |
| 4363 | }) |
| 4364 | addStateMachineCoverageTests(stateMachineTestConfig{ |
| 4365 | protocol: protocol, |
| 4366 | async: async, |
| 4367 | packHandshake: true, |
| 4368 | }) |
| 4369 | } |
| 4370 | } |
| 4371 | } |
| 4372 |
| 4373 | func addStateMachineCoverageTests(config stateMachineTestConfig) { |
| 4374 | var tests []testCase |
| 4375 |
| 4376 | // Basic handshake, with resumption. Client and server, |
| 4377 | // session ID and session ticket. |
| 4378 | tests = append(tests, testCase{ |
| 4379 | name: "Basic-Client", |
| 4380 | config: Config{ |
| 4381 | MaxVersion: VersionTLS12, |
| 4382 | }, |
| 4383 | resumeSession: true, |
| 4384 | // Ensure session tickets are used, not session IDs. |
| 4385 | noSessionCache: true, |
| 4386 | }) |
| 4387 | tests = append(tests, testCase{ |
| 4388 | name: "Basic-Client-RenewTicket", |
| 4389 | config: Config{ |
| 4390 | MaxVersion: VersionTLS12, |
| 4391 | Bugs: ProtocolBugs{ |
| 4392 | RenewTicketOnResume: true, |
| 4393 | }, |
| 4394 | }, |
| 4395 | flags: []string{"-expect-ticket-renewal"}, |
| 4396 | resumeSession: true, |
| 4397 | resumeRenewedSession: true, |
| 4398 | }) |
| 4399 | tests = append(tests, testCase{ |
| 4400 | name: "Basic-Client-NoTicket", |
| 4401 | config: Config{ |
| 4402 | MaxVersion: VersionTLS12, |
| 4403 | SessionTicketsDisabled: true, |
| 4404 | }, |
| 4405 | resumeSession: true, |
| 4406 | }) |
| 4407 | tests = append(tests, testCase{ |
| 4408 | testType: serverTest, |
| 4409 | name: "Basic-Server", |
| 4410 | config: Config{ |
| 4411 | MaxVersion: VersionTLS12, |
| 4412 | Bugs: ProtocolBugs{ |
| 4413 | RequireSessionTickets: true, |
| 4414 | }, |
| 4415 | }, |
| 4416 | resumeSession: true, |
| 4417 | flags: []string{"-expect-no-session-id"}, |
| 4418 | }) |
| 4419 | tests = append(tests, testCase{ |
| 4420 | testType: serverTest, |
| 4421 | name: "Basic-Server-NoTickets", |
| 4422 | config: Config{ |
| 4423 | MaxVersion: VersionTLS12, |
| 4424 | SessionTicketsDisabled: true, |
| 4425 | }, |
| 4426 | resumeSession: true, |
| 4427 | flags: []string{"-expect-session-id"}, |
| 4428 | }) |
| 4429 | tests = append(tests, testCase{ |
| 4430 | testType: serverTest, |
| 4431 | name: "Basic-Server-EarlyCallback", |
| 4432 | config: Config{ |
| 4433 | MaxVersion: VersionTLS12, |
| 4434 | }, |
| 4435 | flags: []string{"-use-early-callback"}, |
| 4436 | resumeSession: true, |
| 4437 | }) |
| 4438 |
| 4439 | // TLS 1.3 basic handshake shapes. |
| 4440 | if config.protocol == tls { |
| 4441 | tests = append(tests, testCase{ |
| 4442 | name: "TLS13-1RTT-Client", |
| 4443 | config: Config{ |
| 4444 | MaxVersion: VersionTLS13, |
| 4445 | MinVersion: VersionTLS13, |
| 4446 | }, |
| 4447 | resumeSession: true, |
| 4448 | resumeRenewedSession: true, |
| 4449 | // 0-RTT being disabled overrides all other 0-RTT reasons. |
| 4450 | flags: []string{"-expect-early-data-reason", "disabled"}, |
| 4451 | }) |
| 4452 |
| 4453 | tests = append(tests, testCase{ |
| 4454 | testType: serverTest, |
| 4455 | name: "TLS13-1RTT-Server", |
| 4456 | config: Config{ |
| 4457 | MaxVersion: VersionTLS13, |
| 4458 | MinVersion: VersionTLS13, |
| 4459 | }, |
| 4460 | resumeSession: true, |
| 4461 | resumeRenewedSession: true, |
| 4462 | flags: []string{ |
| 4463 | // TLS 1.3 uses tickets, so the session should not be |
| 4464 | // cached statefully. |
| 4465 | "-expect-no-session-id", |
| 4466 | // 0-RTT being disabled overrides all other 0-RTT reasons. |
| 4467 | "-expect-early-data-reason", "disabled", |
| 4468 | }, |
| 4469 | }) |
| 4470 |
| 4471 | tests = append(tests, testCase{ |
| 4472 | name: "TLS13-HelloRetryRequest-Client", |
| 4473 | config: Config{ |
| 4474 | MaxVersion: VersionTLS13, |
| 4475 | MinVersion: VersionTLS13, |
| 4476 | // P-384 requires a HelloRetryRequest against BoringSSL's default |
| 4477 | // configuration. Assert this with ExpectMissingKeyShare. |
| 4478 | CurvePreferences: []CurveID{CurveP384}, |
| 4479 | Bugs: ProtocolBugs{ |
| 4480 | ExpectMissingKeyShare: true, |
| 4481 | }, |
| 4482 | }, |
| 4483 | // Cover HelloRetryRequest during an ECDHE-PSK resumption. |
| 4484 | resumeSession: true, |
| 4485 | }) |
| 4486 |
| 4487 | tests = append(tests, testCase{ |
| 4488 | testType: serverTest, |
| 4489 | name: "TLS13-HelloRetryRequest-Server", |
| 4490 | config: Config{ |
| 4491 | MaxVersion: VersionTLS13, |
| 4492 | MinVersion: VersionTLS13, |
| 4493 | // Require a HelloRetryRequest for every curve. |
| 4494 | DefaultCurves: []CurveID{}, |
| 4495 | }, |
| 4496 | // Cover HelloRetryRequest during an ECDHE-PSK resumption. |
| 4497 | resumeSession: true, |
| 4498 | }) |
| 4499 |
| 4500 | tests = append(tests, testCase{ |
| 4501 | testType: clientTest, |
| 4502 | name: "TLS13-EarlyData-TooMuchData-Client", |
| 4503 | config: Config{ |
| 4504 | MaxVersion: VersionTLS13, |
| 4505 | MinVersion: VersionTLS13, |
| 4506 | MaxEarlyDataSize: 2, |
| 4507 | }, |
| 4508 | resumeConfig: &Config{ |
| 4509 | MaxVersion: VersionTLS13, |
| 4510 | MinVersion: VersionTLS13, |
| 4511 | MaxEarlyDataSize: 2, |
| 4512 | Bugs: ProtocolBugs{ |
| 4513 | ExpectEarlyData: [][]byte{{'h', 'e'}}, |
| 4514 | }, |
| 4515 | }, |
| 4516 | resumeShimPrefix: "llo", |
| 4517 | resumeSession: true, |
| 4518 | flags: []string{ |
| 4519 | "-enable-early-data", |
| 4520 | "-expect-ticket-supports-early-data", |
| 4521 | "-on-resume-expect-accept-early-data", |
| 4522 | "-on-resume-shim-writes-first", |
| 4523 | }, |
| 4524 | }) |
| 4525 |
| 4526 | // Unfinished writes can only be tested when operations are async. EarlyData |
| 4527 | // can't be tested as part of an ImplicitHandshake in this case since |
| 4528 | // otherwise the early data will be sent as normal data. |
| 4529 | if config.async && !config.implicitHandshake { |
| 4530 | tests = append(tests, testCase{ |
| 4531 | testType: clientTest, |
| 4532 | name: "TLS13-EarlyData-UnfinishedWrite-Client", |
| 4533 | config: Config{ |
| 4534 | MaxVersion: VersionTLS13, |
| 4535 | MinVersion: VersionTLS13, |
| 4536 | MaxEarlyDataSize: 16384, |
| 4537 | }, |
| 4538 | resumeConfig: &Config{ |
| 4539 | MaxVersion: VersionTLS13, |
| 4540 | MinVersion: VersionTLS13, |
| 4541 | MaxEarlyDataSize: 16384, |
| 4542 | Bugs: ProtocolBugs{ |
| 4543 | ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}}, |
| 4544 | }, |
| 4545 | }, |
| 4546 | resumeSession: true, |
| 4547 | flags: []string{ |
| 4548 | "-enable-early-data", |
| 4549 | "-expect-ticket-supports-early-data", |
| 4550 | "-on-resume-expect-accept-early-data", |
| 4551 | "-on-resume-read-with-unfinished-write", |
| 4552 | "-on-resume-shim-writes-first", |
| 4553 | }, |
| 4554 | }) |
| 4555 |
| 4556 | // Rejected unfinished writes are discarded (from the |
| 4557 | // perspective of the calling application) on 0-RTT |
| 4558 | // reject. |
| 4559 | tests = append(tests, testCase{ |
| 4560 | testType: clientTest, |
| 4561 | name: "TLS13-EarlyData-RejectUnfinishedWrite-Client", |
| 4562 | config: Config{ |
| 4563 | MaxVersion: VersionTLS13, |
| 4564 | MinVersion: VersionTLS13, |
| 4565 | MaxEarlyDataSize: 16384, |
| 4566 | }, |
| 4567 | resumeConfig: &Config{ |
| 4568 | MaxVersion: VersionTLS13, |
| 4569 | MinVersion: VersionTLS13, |
| 4570 | MaxEarlyDataSize: 16384, |
| 4571 | Bugs: ProtocolBugs{ |
| 4572 | AlwaysRejectEarlyData: true, |
| 4573 | }, |
| 4574 | }, |
| 4575 | resumeSession: true, |
| 4576 | flags: []string{ |
| 4577 | "-enable-early-data", |
| 4578 | "-expect-ticket-supports-early-data", |
| 4579 | "-expect-reject-early-data", |
| 4580 | "-on-resume-read-with-unfinished-write", |
| 4581 | "-on-resume-shim-writes-first", |
| 4582 | }, |
| 4583 | }) |
| 4584 | } |
| 4585 |
| 4586 | tests = append(tests, testCase{ |
| 4587 | testType: serverTest, |
| 4588 | name: "TLS13-MaxEarlyData-Server", |
| 4589 | config: Config{ |
| 4590 | MaxVersion: VersionTLS13, |
| 4591 | MinVersion: VersionTLS13, |
| 4592 | Bugs: ProtocolBugs{ |
| 4593 | SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)}, |
| 4594 | ExpectEarlyDataAccepted: true, |
| 4595 | }, |
| 4596 | }, |
| 4597 | messageCount: 2, |
| 4598 | resumeSession: true, |
| 4599 | flags: []string{ |
| 4600 | "-enable-early-data", |
| 4601 | "-on-resume-expect-accept-early-data", |
| 4602 | }, |
| 4603 | shouldFail: true, |
| 4604 | expectedError: ":TOO_MUCH_READ_EARLY_DATA:", |
| 4605 | }) |
| 4606 | } |
| 4607 |
| 4608 | // TLS client auth. |
| 4609 | tests = append(tests, testCase{ |
| 4610 | testType: clientTest, |
| 4611 | name: "ClientAuth-NoCertificate-Client", |
| 4612 | config: Config{ |
| 4613 | MaxVersion: VersionTLS12, |
| 4614 | ClientAuth: RequestClientCert, |
| 4615 | }, |
| 4616 | }) |
| 4617 | tests = append(tests, testCase{ |
| 4618 | testType: serverTest, |
| 4619 | name: "ClientAuth-NoCertificate-Server", |
| 4620 | config: Config{ |
| 4621 | MaxVersion: VersionTLS12, |
| 4622 | }, |
| 4623 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 4624 | flags: []string{"-verify-peer"}, |
| 4625 | }) |
| 4626 | if config.protocol == tls { |
| 4627 | tests = append(tests, testCase{ |
| 4628 | testType: clientTest, |
| 4629 | name: "ClientAuth-NoCertificate-Client-TLS13", |
| 4630 | config: Config{ |
| 4631 | MaxVersion: VersionTLS13, |
| 4632 | ClientAuth: RequestClientCert, |
| 4633 | }, |
| 4634 | }) |
| 4635 | tests = append(tests, testCase{ |
| 4636 | testType: serverTest, |
| 4637 | name: "ClientAuth-NoCertificate-Server-TLS13", |
| 4638 | config: Config{ |
| 4639 | MaxVersion: VersionTLS13, |
| 4640 | }, |
| 4641 | // Setting SSL_VERIFY_PEER allows anonymous clients. |
| 4642 | flags: []string{"-verify-peer"}, |
| 4643 | }) |
| 4644 | } |
| 4645 | tests = append(tests, testCase{ |
| 4646 | testType: clientTest, |
| 4647 | name: "ClientAuth-RSA-Client", |
| 4648 | config: Config{ |
| 4649 | MaxVersion: VersionTLS12, |
| 4650 | ClientAuth: RequireAnyClientCert, |
| 4651 | }, |
| 4652 | flags: []string{ |
| 4653 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4654 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4655 | }, |
| 4656 | }) |
| 4657 | tests = append(tests, testCase{ |
| 4658 | testType: clientTest, |
| 4659 | name: "ClientAuth-RSA-Client-TLS13", |
| 4660 | config: Config{ |
| 4661 | MaxVersion: VersionTLS13, |
| 4662 | ClientAuth: RequireAnyClientCert, |
| 4663 | }, |
| 4664 | flags: []string{ |
| 4665 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4666 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4667 | }, |
| 4668 | }) |
| 4669 | tests = append(tests, testCase{ |
| 4670 | testType: clientTest, |
| 4671 | name: "ClientAuth-ECDSA-Client", |
| 4672 | config: Config{ |
| 4673 | MaxVersion: VersionTLS12, |
| 4674 | ClientAuth: RequireAnyClientCert, |
| 4675 | }, |
| 4676 | flags: []string{ |
| 4677 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 4678 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 4679 | }, |
| 4680 | }) |
| 4681 | tests = append(tests, testCase{ |
| 4682 | testType: clientTest, |
| 4683 | name: "ClientAuth-ECDSA-Client-TLS13", |
| 4684 | config: Config{ |
| 4685 | MaxVersion: VersionTLS13, |
| 4686 | ClientAuth: RequireAnyClientCert, |
| 4687 | }, |
| 4688 | flags: []string{ |
| 4689 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 4690 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 4691 | }, |
| 4692 | }) |
| 4693 | tests = append(tests, testCase{ |
| 4694 | testType: clientTest, |
| 4695 | name: "ClientAuth-NoCertificate-OldCallback", |
| 4696 | config: Config{ |
| 4697 | MaxVersion: VersionTLS12, |
| 4698 | ClientAuth: RequestClientCert, |
| 4699 | }, |
| 4700 | flags: []string{"-use-old-client-cert-callback"}, |
| 4701 | }) |
| 4702 | tests = append(tests, testCase{ |
| 4703 | testType: clientTest, |
| 4704 | name: "ClientAuth-NoCertificate-OldCallback-TLS13", |
| 4705 | config: Config{ |
| 4706 | MaxVersion: VersionTLS13, |
| 4707 | ClientAuth: RequestClientCert, |
| 4708 | }, |
| 4709 | flags: []string{"-use-old-client-cert-callback"}, |
| 4710 | }) |
| 4711 | tests = append(tests, testCase{ |
| 4712 | testType: clientTest, |
| 4713 | name: "ClientAuth-OldCallback", |
| 4714 | config: Config{ |
| 4715 | MaxVersion: VersionTLS12, |
| 4716 | ClientAuth: RequireAnyClientCert, |
| 4717 | }, |
| 4718 | flags: []string{ |
| 4719 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4720 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4721 | "-use-old-client-cert-callback", |
| 4722 | }, |
| 4723 | }) |
| 4724 | tests = append(tests, testCase{ |
| 4725 | testType: clientTest, |
| 4726 | name: "ClientAuth-OldCallback-TLS13", |
| 4727 | config: Config{ |
| 4728 | MaxVersion: VersionTLS13, |
| 4729 | ClientAuth: RequireAnyClientCert, |
| 4730 | }, |
| 4731 | flags: []string{ |
| 4732 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4733 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4734 | "-use-old-client-cert-callback", |
| 4735 | }, |
| 4736 | }) |
| 4737 | tests = append(tests, testCase{ |
| 4738 | testType: serverTest, |
| 4739 | name: "ClientAuth-Server", |
| 4740 | config: Config{ |
| 4741 | MaxVersion: VersionTLS12, |
| 4742 | Certificates: []Certificate{rsaCertificate}, |
| 4743 | }, |
| 4744 | flags: []string{"-require-any-client-certificate"}, |
| 4745 | }) |
| 4746 | tests = append(tests, testCase{ |
| 4747 | testType: serverTest, |
| 4748 | name: "ClientAuth-Server-TLS13", |
| 4749 | config: Config{ |
| 4750 | MaxVersion: VersionTLS13, |
| 4751 | Certificates: []Certificate{rsaCertificate}, |
| 4752 | }, |
| 4753 | flags: []string{"-require-any-client-certificate"}, |
| 4754 | }) |
| 4755 |
| 4756 | // Test each key exchange on the server side for async keys. |
| 4757 | tests = append(tests, testCase{ |
| 4758 | testType: serverTest, |
| 4759 | name: "Basic-Server-RSA", |
| 4760 | config: Config{ |
| 4761 | MaxVersion: VersionTLS12, |
| 4762 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 4763 | }, |
| 4764 | flags: []string{ |
| 4765 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4766 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4767 | }, |
| 4768 | }) |
| 4769 | tests = append(tests, testCase{ |
| 4770 | testType: serverTest, |
| 4771 | name: "Basic-Server-ECDHE-RSA", |
| 4772 | config: Config{ |
| 4773 | MaxVersion: VersionTLS12, |
| 4774 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 4775 | }, |
| 4776 | flags: []string{ |
| 4777 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 4778 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 4779 | }, |
| 4780 | }) |
| 4781 | tests = append(tests, testCase{ |
| 4782 | testType: serverTest, |
| 4783 | name: "Basic-Server-ECDHE-ECDSA", |
| 4784 | config: Config{ |
| 4785 | MaxVersion: VersionTLS12, |
| 4786 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 4787 | }, |
| 4788 | flags: []string{ |
| 4789 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 4790 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 4791 | }, |
| 4792 | }) |
| 4793 | tests = append(tests, testCase{ |
| 4794 | testType: serverTest, |
| 4795 | name: "Basic-Server-Ed25519", |
| 4796 | config: Config{ |
| 4797 | MaxVersion: VersionTLS12, |
| 4798 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 4799 | }, |
| 4800 | flags: []string{ |
| 4801 | "-cert-file", path.Join(*resourceDir, ed25519CertificateFile), |
| 4802 | "-key-file", path.Join(*resourceDir, ed25519KeyFile), |
| 4803 | "-enable-ed25519", |
| 4804 | }, |
| 4805 | }) |
| 4806 |
| 4807 | // No session ticket support; server doesn't send NewSessionTicket. |
| 4808 | tests = append(tests, testCase{ |
| 4809 | name: "SessionTicketsDisabled-Client", |
| 4810 | config: Config{ |
| 4811 | MaxVersion: VersionTLS12, |
| 4812 | SessionTicketsDisabled: true, |
| 4813 | }, |
| 4814 | }) |
| 4815 | tests = append(tests, testCase{ |
| 4816 | testType: serverTest, |
| 4817 | name: "SessionTicketsDisabled-Server", |
| 4818 | config: Config{ |
| 4819 | MaxVersion: VersionTLS12, |
| 4820 | SessionTicketsDisabled: true, |
| 4821 | }, |
| 4822 | }) |
| 4823 |
| 4824 | // Skip ServerKeyExchange in PSK key exchange if there's no |
| 4825 | // identity hint. |
| 4826 | tests = append(tests, testCase{ |
| 4827 | name: "EmptyPSKHint-Client", |
| 4828 | config: Config{ |
| 4829 | MaxVersion: VersionTLS12, |
| 4830 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 4831 | PreSharedKey: []byte("secret"), |
| 4832 | }, |
| 4833 | flags: []string{"-psk", "secret"}, |
| 4834 | }) |
| 4835 | tests = append(tests, testCase{ |
| 4836 | testType: serverTest, |
| 4837 | name: "EmptyPSKHint-Server", |
| 4838 | config: Config{ |
| 4839 | MaxVersion: VersionTLS12, |
| 4840 | CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA}, |
| 4841 | PreSharedKey: []byte("secret"), |
| 4842 | }, |
| 4843 | flags: []string{"-psk", "secret"}, |
| 4844 | }) |
| 4845 |
| 4846 | // OCSP stapling tests. |
| 4847 | for _, vers := range tlsVersions { |
| 4848 | if config.protocol == dtls && !vers.hasDTLS { |
| 4849 | continue |
| 4850 | } |
| 4851 | tests = append(tests, testCase{ |
| 4852 | testType: clientTest, |
| 4853 | name: "OCSPStapling-Client-" + vers.name, |
| 4854 | config: Config{ |
| 4855 | MaxVersion: vers.version, |
| 4856 | }, |
| 4857 | flags: []string{ |
| 4858 | "-enable-ocsp-stapling", |
| 4859 | "-expect-ocsp-response", |
| 4860 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 4861 | "-verify-peer", |
| 4862 | }, |
| 4863 | resumeSession: true, |
| 4864 | }) |
| 4865 | tests = append(tests, testCase{ |
| 4866 | testType: serverTest, |
| 4867 | name: "OCSPStapling-Server-" + vers.name, |
| 4868 | config: Config{ |
| 4869 | MaxVersion: vers.version, |
| 4870 | }, |
| 4871 | expectedOCSPResponse: testOCSPResponse, |
| 4872 | flags: []string{ |
| 4873 | "-ocsp-response", |
| 4874 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 4875 | }, |
| 4876 | resumeSession: true, |
| 4877 | }) |
| 4878 |
| 4879 | // The client OCSP callback is an alternate certificate |
| 4880 | // verification callback. |
| 4881 | tests = append(tests, testCase{ |
| 4882 | testType: clientTest, |
| 4883 | name: "ClientOCSPCallback-Pass-" + vers.name, |
| 4884 | config: Config{ |
| 4885 | MaxVersion: vers.version, |
| 4886 | Certificates: []Certificate{rsaCertificate}, |
| 4887 | }, |
| 4888 | flags: []string{ |
| 4889 | "-enable-ocsp-stapling", |
| 4890 | "-use-ocsp-callback", |
| 4891 | }, |
| 4892 | }) |
| 4893 | var expectedLocalError string |
| 4894 | if !config.async { |
| 4895 | // TODO(davidben): Asynchronous fatal alerts are never |
| 4896 | // sent. https://crbug.com/boringssl/130. |
| 4897 | expectedLocalError = "remote error: bad certificate status response" |
| 4898 | } |
| 4899 | tests = append(tests, testCase{ |
| 4900 | testType: clientTest, |
| 4901 | name: "ClientOCSPCallback-Fail-" + vers.name, |
| 4902 | config: Config{ |
| 4903 | MaxVersion: vers.version, |
| 4904 | Certificates: []Certificate{rsaCertificate}, |
| 4905 | }, |
| 4906 | flags: []string{ |
| 4907 | "-enable-ocsp-stapling", |
| 4908 | "-use-ocsp-callback", |
| 4909 | "-fail-ocsp-callback", |
| 4910 | }, |
| 4911 | shouldFail: true, |
| 4912 | expectedLocalError: expectedLocalError, |
| 4913 | expectedError: ":OCSP_CB_ERROR:", |
| 4914 | }) |
| 4915 | // The callback still runs if the server does not send an OCSP |
| 4916 | // response. |
| 4917 | certNoStaple := rsaCertificate |
| 4918 | certNoStaple.OCSPStaple = nil |
| 4919 | tests = append(tests, testCase{ |
| 4920 | testType: clientTest, |
| 4921 | name: "ClientOCSPCallback-FailNoStaple-" + vers.name, |
| 4922 | config: Config{ |
| 4923 | MaxVersion: vers.version, |
| 4924 | Certificates: []Certificate{certNoStaple}, |
| 4925 | }, |
| 4926 | flags: []string{ |
| 4927 | "-enable-ocsp-stapling", |
| 4928 | "-use-ocsp-callback", |
| 4929 | "-fail-ocsp-callback", |
| 4930 | }, |
| 4931 | shouldFail: true, |
| 4932 | expectedLocalError: expectedLocalError, |
| 4933 | expectedError: ":OCSP_CB_ERROR:", |
| 4934 | }) |
| 4935 |
| 4936 | // The server OCSP callback is a legacy mechanism for |
| 4937 | // configuring OCSP, used by unreliable server software. |
| 4938 | tests = append(tests, testCase{ |
| 4939 | testType: serverTest, |
| 4940 | name: "ServerOCSPCallback-SetInCallback-" + vers.name, |
| 4941 | config: Config{ |
| 4942 | MaxVersion: vers.version, |
| 4943 | }, |
| 4944 | expectedOCSPResponse: testOCSPResponse, |
| 4945 | flags: []string{ |
| 4946 | "-use-ocsp-callback", |
| 4947 | "-set-ocsp-in-callback", |
| 4948 | "-ocsp-response", |
| 4949 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 4950 | }, |
| 4951 | resumeSession: true, |
| 4952 | }) |
| 4953 |
| 4954 | // The callback may decline OCSP, in which case we act as if |
| 4955 | // the client did not support it, even if a response was |
| 4956 | // configured. |
| 4957 | tests = append(tests, testCase{ |
| 4958 | testType: serverTest, |
| 4959 | name: "ServerOCSPCallback-Decline-" + vers.name, |
| 4960 | config: Config{ |
| 4961 | MaxVersion: vers.version, |
| 4962 | }, |
| 4963 | expectedOCSPResponse: []byte{}, |
| 4964 | flags: []string{ |
| 4965 | "-use-ocsp-callback", |
| 4966 | "-decline-ocsp-callback", |
| 4967 | "-ocsp-response", |
| 4968 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 4969 | }, |
| 4970 | resumeSession: true, |
| 4971 | }) |
| 4972 |
| 4973 | // The callback may also signal an internal error. |
| 4974 | tests = append(tests, testCase{ |
| 4975 | testType: serverTest, |
| 4976 | name: "ServerOCSPCallback-Fail-" + vers.name, |
| 4977 | config: Config{ |
| 4978 | MaxVersion: vers.version, |
| 4979 | }, |
| 4980 | flags: []string{ |
| 4981 | "-use-ocsp-callback", |
| 4982 | "-fail-ocsp-callback", |
| 4983 | "-ocsp-response", |
| 4984 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 4985 | }, |
| 4986 | shouldFail: true, |
| 4987 | expectedError: ":OCSP_CB_ERROR:", |
| 4988 | }) |
| 4989 | } |
| 4990 |
| 4991 | // Certificate verification tests. |
| 4992 | for _, vers := range tlsVersions { |
| 4993 | if config.protocol == dtls && !vers.hasDTLS { |
| 4994 | continue |
| 4995 | } |
| 4996 | for _, useCustomCallback := range []bool{false, true} { |
| 4997 | for _, testType := range []testType{clientTest, serverTest} { |
| 4998 | suffix := "-Client" |
| 4999 | if testType == serverTest { |
| 5000 | suffix = "-Server" |
| 5001 | } |
| 5002 | suffix += "-" + vers.name |
| 5003 | if useCustomCallback { |
| 5004 | suffix += "-CustomCallback" |
| 5005 | } |
| 5006 |
| 5007 | flags := []string{"-verify-peer"} |
| 5008 | if testType == serverTest { |
| 5009 | flags = append(flags, "-require-any-client-certificate") |
| 5010 | } |
| 5011 | if useCustomCallback { |
| 5012 | flags = append(flags, "-use-custom-verify-callback") |
| 5013 | } |
| 5014 |
| 5015 | tests = append(tests, testCase{ |
| 5016 | testType: testType, |
| 5017 | name: "CertificateVerificationSucceed" + suffix, |
| 5018 | config: Config{ |
| 5019 | MaxVersion: vers.version, |
| 5020 | Certificates: []Certificate{rsaCertificate}, |
| 5021 | }, |
| 5022 | flags: append([]string{"-expect-verify-result"}, flags...), |
| 5023 | resumeSession: true, |
| 5024 | }) |
| 5025 | tests = append(tests, testCase{ |
| 5026 | testType: testType, |
| 5027 | name: "CertificateVerificationFail" + suffix, |
| 5028 | config: Config{ |
| 5029 | MaxVersion: vers.version, |
| 5030 | Certificates: []Certificate{rsaCertificate}, |
| 5031 | }, |
| 5032 | flags: append([]string{"-verify-fail"}, flags...), |
| 5033 | shouldFail: true, |
| 5034 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 5035 | }) |
| 5036 | // Tests that although the verify callback fails on resumption, by default we don't call it. |
| 5037 | tests = append(tests, testCase{ |
| 5038 | testType: testType, |
| 5039 | name: "CertificateVerificationDoesNotFailOnResume" + suffix, |
| 5040 | config: Config{ |
| 5041 | MaxVersion: vers.version, |
| 5042 | Certificates: []Certificate{rsaCertificate}, |
| 5043 | }, |
| 5044 | flags: append([]string{"-on-resume-verify-fail"}, flags...), |
| 5045 | resumeSession: true, |
| 5046 | }) |
| 5047 | if testType == clientTest && useCustomCallback { |
| 5048 | tests = append(tests, testCase{ |
| 5049 | testType: testType, |
| 5050 | name: "CertificateVerificationFailsOnResume" + suffix, |
| 5051 | config: Config{ |
| 5052 | MaxVersion: vers.version, |
| 5053 | Certificates: []Certificate{rsaCertificate}, |
| 5054 | }, |
| 5055 | flags: append([]string{ |
| 5056 | "-on-resume-verify-fail", |
| 5057 | "-reverify-on-resume", |
| 5058 | }, flags...), |
| 5059 | resumeSession: true, |
| 5060 | shouldFail: true, |
| 5061 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 5062 | }) |
| 5063 | tests = append(tests, testCase{ |
| 5064 | testType: testType, |
| 5065 | name: "CertificateVerificationPassesOnResume" + suffix, |
| 5066 | config: Config{ |
| 5067 | MaxVersion: vers.version, |
| 5068 | Certificates: []Certificate{rsaCertificate}, |
| 5069 | }, |
| 5070 | flags: append([]string{ |
| 5071 | "-reverify-on-resume", |
| 5072 | }, flags...), |
| 5073 | resumeSession: true, |
| 5074 | }) |
| 5075 | if vers.version >= VersionTLS13 { |
| 5076 | tests = append(tests, testCase{ |
| 5077 | testType: testType, |
| 5078 | name: "EarlyData-RejectTicket-Client-Reverify" + suffix, |
| 5079 | config: Config{ |
| 5080 | MaxVersion: vers.version, |
| 5081 | MaxEarlyDataSize: 16384, |
| 5082 | }, |
| 5083 | resumeConfig: &Config{ |
| 5084 | MaxVersion: vers.version, |
| 5085 | MaxEarlyDataSize: 16384, |
| 5086 | SessionTicketsDisabled: true, |
| 5087 | }, |
| 5088 | resumeSession: true, |
| 5089 | expectResumeRejected: true, |
| 5090 | flags: append([]string{ |
| 5091 | "-enable-early-data", |
| 5092 | "-expect-ticket-supports-early-data", |
| 5093 | "-reverify-on-resume", |
| 5094 | "-on-resume-shim-writes-first", |
| 5095 | // Session tickets are disabled, so the runner will not send a ticket. |
| 5096 | "-on-retry-expect-no-session", |
| 5097 | "-expect-reject-early-data", |
| 5098 | }, flags...), |
| 5099 | }) |
| 5100 | tests = append(tests, testCase{ |
| 5101 | testType: testType, |
| 5102 | name: "EarlyData-Reject0RTT-Client-Reverify" + suffix, |
| 5103 | config: Config{ |
| 5104 | MaxVersion: vers.version, |
| 5105 | MaxEarlyDataSize: 16384, |
| 5106 | }, |
| 5107 | resumeConfig: &Config{ |
| 5108 | MaxVersion: vers.version, |
| 5109 | MaxEarlyDataSize: 16384, |
| 5110 | Bugs: ProtocolBugs{ |
| 5111 | AlwaysRejectEarlyData: true, |
| 5112 | }, |
| 5113 | }, |
| 5114 | resumeSession: true, |
| 5115 | expectResumeRejected: false, |
| 5116 | flags: append([]string{ |
| 5117 | "-enable-early-data", |
| 5118 | "-expect-reject-early-data", |
| 5119 | "-expect-ticket-supports-early-data", |
| 5120 | "-reverify-on-resume", |
| 5121 | "-on-resume-shim-writes-first", |
| 5122 | }, flags...), |
| 5123 | }) |
| 5124 | tests = append(tests, testCase{ |
| 5125 | testType: testType, |
| 5126 | name: "EarlyData-RejectTicket-Client-ReverifyFails" + suffix, |
| 5127 | config: Config{ |
| 5128 | MaxVersion: vers.version, |
| 5129 | MaxEarlyDataSize: 16384, |
| 5130 | }, |
| 5131 | resumeConfig: &Config{ |
| 5132 | MaxVersion: vers.version, |
| 5133 | MaxEarlyDataSize: 16384, |
| 5134 | SessionTicketsDisabled: true, |
| 5135 | }, |
| 5136 | resumeSession: true, |
| 5137 | expectResumeRejected: true, |
| 5138 | shouldFail: true, |
| 5139 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 5140 | flags: append([]string{ |
| 5141 | "-enable-early-data", |
| 5142 | "-expect-ticket-supports-early-data", |
| 5143 | "-reverify-on-resume", |
| 5144 | "-on-resume-shim-writes-first", |
| 5145 | // Session tickets are disabled, so the runner will not send a ticket. |
| 5146 | "-on-retry-expect-no-session", |
| 5147 | "-on-retry-verify-fail", |
| 5148 | "-expect-reject-early-data", |
| 5149 | }, flags...), |
| 5150 | }) |
| 5151 | tests = append(tests, testCase{ |
| 5152 | testType: testType, |
| 5153 | name: "EarlyData-Reject0RTT-Client-ReverifyFails" + suffix, |
| 5154 | config: Config{ |
| 5155 | MaxVersion: vers.version, |
| 5156 | MaxEarlyDataSize: 16384, |
| 5157 | }, |
| 5158 | resumeConfig: &Config{ |
| 5159 | MaxVersion: vers.version, |
| 5160 | MaxEarlyDataSize: 16384, |
| 5161 | Bugs: ProtocolBugs{ |
| 5162 | AlwaysRejectEarlyData: true, |
| 5163 | }, |
| 5164 | }, |
| 5165 | resumeSession: true, |
| 5166 | expectResumeRejected: false, |
| 5167 | shouldFail: true, |
| 5168 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 5169 | flags: append([]string{ |
| 5170 | "-enable-early-data", |
| 5171 | "-expect-reject-early-data", |
| 5172 | "-expect-ticket-supports-early-data", |
| 5173 | "-reverify-on-resume", |
| 5174 | "-on-resume-shim-writes-first", |
| 5175 | "-on-retry-verify-fail", |
| 5176 | }, flags...), |
| 5177 | }) |
| 5178 | // This tests that we only call the verify callback once. |
| 5179 | tests = append(tests, testCase{ |
| 5180 | testType: testType, |
| 5181 | name: "EarlyData-Accept0RTT-Client-Reverify" + suffix, |
| 5182 | config: Config{ |
| 5183 | MaxVersion: vers.version, |
| 5184 | MaxEarlyDataSize: 16384, |
| 5185 | }, |
| 5186 | resumeConfig: &Config{ |
| 5187 | MaxVersion: vers.version, |
| 5188 | MaxEarlyDataSize: 16384, |
| 5189 | Bugs: ProtocolBugs{ |
| 5190 | ExpectEarlyData: [][]byte{[]byte("hello")}, |
| 5191 | }, |
| 5192 | }, |
| 5193 | resumeSession: true, |
| 5194 | expectResumeRejected: false, |
| 5195 | flags: append([]string{ |
| 5196 | "-enable-early-data", |
| 5197 | "-expect-ticket-supports-early-data", |
| 5198 | "-reverify-on-resume", |
| 5199 | "-on-resume-shim-writes-first", |
| 5200 | }, flags...), |
| 5201 | }) |
| 5202 | tests = append(tests, testCase{ |
| 5203 | testType: testType, |
| 5204 | name: "EarlyData-Accept0RTT-Client-ReverifyFails" + suffix, |
| 5205 | config: Config{ |
| 5206 | MaxVersion: vers.version, |
| 5207 | MaxEarlyDataSize: 16384, |
| 5208 | }, |
| 5209 | resumeConfig: &Config{ |
| 5210 | MaxVersion: vers.version, |
| 5211 | MaxEarlyDataSize: 16384, |
| 5212 | Bugs: ProtocolBugs{ |
| 5213 | ExpectEarlyData: [][]byte{[]byte("hello")}, |
| 5214 | }, |
| 5215 | }, |
| 5216 | resumeSession: true, |
| 5217 | shouldFail: true, |
| 5218 | expectedError: ":CERTIFICATE_VERIFY_FAILED:", |
| 5219 | flags: append([]string{ |
| 5220 | "-enable-early-data", |
| 5221 | "-expect-ticket-supports-early-data", |
| 5222 | "-reverify-on-resume", |
| 5223 | "-on-resume-verify-fail", |
| 5224 | "-on-resume-shim-writes-first", |
| 5225 | }, flags...), |
| 5226 | }) |
| 5227 | } |
| 5228 | } |
| 5229 | } |
| 5230 | } |
| 5231 |
| 5232 | // By default, the client is in a soft fail mode where the peer |
| 5233 | // certificate is verified but failures are non-fatal. |
| 5234 | tests = append(tests, testCase{ |
| 5235 | testType: clientTest, |
| 5236 | name: "CertificateVerificationSoftFail-" + vers.name, |
| 5237 | config: Config{ |
| 5238 | MaxVersion: vers.version, |
| 5239 | Certificates: []Certificate{rsaCertificate}, |
| 5240 | }, |
| 5241 | flags: []string{ |
| 5242 | "-verify-fail", |
| 5243 | "-expect-verify-result", |
| 5244 | }, |
| 5245 | resumeSession: true, |
| 5246 | }) |
| 5247 | } |
| 5248 |
| 5249 | tests = append(tests, testCase{ |
| 5250 | name: "ShimSendAlert", |
| 5251 | flags: []string{"-send-alert"}, |
| 5252 | shimWritesFirst: true, |
| 5253 | shouldFail: true, |
| 5254 | expectedLocalError: "remote error: decompression failure", |
| 5255 | }) |
| 5256 |
| 5257 | if config.protocol == tls { |
| 5258 | tests = append(tests, testCase{ |
| 5259 | name: "Renegotiate-Client", |
| 5260 | config: Config{ |
| 5261 | MaxVersion: VersionTLS12, |
| 5262 | }, |
| 5263 | renegotiate: 1, |
| 5264 | flags: []string{ |
| 5265 | "-renegotiate-freely", |
| 5266 | "-expect-total-renegotiations", "1", |
| 5267 | }, |
| 5268 | }) |
| 5269 |
| 5270 | tests = append(tests, testCase{ |
| 5271 | name: "SendHalfHelloRequest", |
| 5272 | config: Config{ |
| 5273 | MaxVersion: VersionTLS12, |
| 5274 | Bugs: ProtocolBugs{ |
| 5275 | PackHelloRequestWithFinished: config.packHandshake, |
| 5276 | }, |
| 5277 | }, |
| 5278 | sendHalfHelloRequest: true, |
| 5279 | flags: []string{"-renegotiate-ignore"}, |
| 5280 | shouldFail: true, |
| 5281 | expectedError: ":UNEXPECTED_RECORD:", |
| 5282 | }) |
| 5283 |
| 5284 | // NPN on client and server; results in post-handshake message. |
| 5285 | tests = append(tests, testCase{ |
| 5286 | name: "NPN-Client", |
| 5287 | config: Config{ |
| 5288 | MaxVersion: VersionTLS12, |
| 5289 | NextProtos: []string{"foo"}, |
| 5290 | }, |
| 5291 | flags: []string{"-select-next-proto", "foo"}, |
| 5292 | resumeSession: true, |
| 5293 | expectedNextProto: "foo", |
| 5294 | expectedNextProtoType: npn, |
| 5295 | }) |
| 5296 | tests = append(tests, testCase{ |
| 5297 | testType: serverTest, |
| 5298 | name: "NPN-Server", |
| 5299 | config: Config{ |
| 5300 | MaxVersion: VersionTLS12, |
| 5301 | NextProtos: []string{"bar"}, |
| 5302 | }, |
| 5303 | flags: []string{ |
| 5304 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 5305 | "-expect-next-proto", "bar", |
| 5306 | }, |
| 5307 | resumeSession: true, |
| 5308 | expectedNextProto: "bar", |
| 5309 | expectedNextProtoType: npn, |
| 5310 | }) |
| 5311 |
| 5312 | // Client does False Start and negotiates NPN. |
| 5313 | tests = append(tests, testCase{ |
| 5314 | name: "FalseStart", |
| 5315 | config: Config{ |
| 5316 | MaxVersion: VersionTLS12, |
| 5317 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5318 | NextProtos: []string{"foo"}, |
| 5319 | Bugs: ProtocolBugs{ |
| 5320 | ExpectFalseStart: true, |
| 5321 | }, |
| 5322 | }, |
| 5323 | flags: []string{ |
| 5324 | "-false-start", |
| 5325 | "-select-next-proto", "foo", |
| 5326 | }, |
| 5327 | shimWritesFirst: true, |
| 5328 | resumeSession: true, |
| 5329 | }) |
| 5330 |
| 5331 | // Client does False Start and negotiates ALPN. |
| 5332 | tests = append(tests, testCase{ |
| 5333 | name: "FalseStart-ALPN", |
| 5334 | config: Config{ |
| 5335 | MaxVersion: VersionTLS12, |
| 5336 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5337 | NextProtos: []string{"foo"}, |
| 5338 | Bugs: ProtocolBugs{ |
| 5339 | ExpectFalseStart: true, |
| 5340 | }, |
| 5341 | }, |
| 5342 | flags: []string{ |
| 5343 | "-false-start", |
| 5344 | "-advertise-alpn", "\x03foo", |
| 5345 | "-expect-alpn", "foo", |
| 5346 | }, |
| 5347 | shimWritesFirst: true, |
| 5348 | resumeSession: true, |
| 5349 | }) |
| 5350 |
| 5351 | // False Start without session tickets. |
| 5352 | tests = append(tests, testCase{ |
| 5353 | name: "FalseStart-SessionTicketsDisabled", |
| 5354 | config: Config{ |
| 5355 | MaxVersion: VersionTLS12, |
| 5356 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 5357 | NextProtos: []string{"foo"}, |
| 5358 | SessionTicketsDisabled: true, |
| 5359 | Bugs: ProtocolBugs{ |
| 5360 | ExpectFalseStart: true, |
| 5361 | }, |
| 5362 | }, |
| 5363 | flags: []string{ |
| 5364 | "-false-start", |
| 5365 | "-select-next-proto", "foo", |
| 5366 | }, |
| 5367 | shimWritesFirst: true, |
| 5368 | }) |
| 5369 |
| 5370 | // Server parses a V2ClientHello. |
| 5371 | tests = append(tests, testCase{ |
| 5372 | testType: serverTest, |
| 5373 | name: "SendV2ClientHello", |
| 5374 | config: Config{ |
| 5375 | // Choose a cipher suite that does not involve |
| 5376 | // elliptic curves, so no extensions are |
| 5377 | // involved. |
| 5378 | MaxVersion: VersionTLS12, |
| 5379 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
| 5380 | Bugs: ProtocolBugs{ |
| 5381 | SendV2ClientHello: true, |
| 5382 | }, |
| 5383 | }, |
| 5384 | flags: []string{ |
| 5385 | "-expect-msg-callback", |
| 5386 | `read v2clienthello |
| 5387 | write hs 2 |
| 5388 | write hs 11 |
| 5389 | write hs 14 |
| 5390 | read hs 16 |
| 5391 | read ccs |
| 5392 | read hs 20 |
| 5393 | write ccs |
| 5394 | write hs 20 |
| 5395 | read alert 1 0 |
| 5396 | `, |
| 5397 | }, |
| 5398 | }) |
| 5399 |
| 5400 | // Test Channel ID |
| 5401 | for _, ver := range tlsVersions { |
| 5402 | if ver.version < VersionTLS10 { |
| 5403 | continue |
| 5404 | } |
| 5405 | // Client sends a Channel ID. |
| 5406 | tests = append(tests, testCase{ |
| 5407 | name: "ChannelID-Client-" + ver.name, |
| 5408 | config: Config{ |
| 5409 | MaxVersion: ver.version, |
| 5410 | RequestChannelID: true, |
| 5411 | }, |
| 5412 | flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)}, |
| 5413 | resumeSession: true, |
| 5414 | expectChannelID: true, |
| 5415 | }) |
| 5416 |
| 5417 | // Server accepts a Channel ID. |
| 5418 | tests = append(tests, testCase{ |
| 5419 | testType: serverTest, |
| 5420 | name: "ChannelID-Server-" + ver.name, |
| 5421 | config: Config{ |
| 5422 | MaxVersion: ver.version, |
| 5423 | ChannelID: channelIDKey, |
| 5424 | }, |
| 5425 | flags: []string{ |
| 5426 | "-expect-channel-id", |
| 5427 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 5428 | }, |
| 5429 | resumeSession: true, |
| 5430 | expectChannelID: true, |
| 5431 | }) |
| 5432 |
| 5433 | tests = append(tests, testCase{ |
| 5434 | testType: serverTest, |
| 5435 | name: "InvalidChannelIDSignature-" + ver.name, |
| 5436 | config: Config{ |
| 5437 | MaxVersion: ver.version, |
| 5438 | ChannelID: channelIDKey, |
| 5439 | Bugs: ProtocolBugs{ |
| 5440 | InvalidChannelIDSignature: true, |
| 5441 | }, |
| 5442 | }, |
| 5443 | flags: []string{"-enable-channel-id"}, |
| 5444 | shouldFail: true, |
| 5445 | expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:", |
| 5446 | }) |
| 5447 |
| 5448 | if ver.version < VersionTLS13 { |
| 5449 | // Channel ID requires ECDHE ciphers. |
| 5450 | tests = append(tests, testCase{ |
| 5451 | testType: serverTest, |
| 5452 | name: "ChannelID-NoECDHE-" + ver.name, |
| 5453 | config: Config{ |
| 5454 | MaxVersion: ver.version, |
| 5455 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 5456 | ChannelID: channelIDKey, |
| 5457 | }, |
| 5458 | expectChannelID: false, |
| 5459 | flags: []string{"-enable-channel-id"}, |
| 5460 | }) |
| 5461 |
| 5462 | // Sanity-check setting expectChannelID false works. |
| 5463 | tests = append(tests, testCase{ |
| 5464 | testType: serverTest, |
| 5465 | name: "ChannelID-ECDHE-" + ver.name, |
| 5466 | config: Config{ |
| 5467 | MaxVersion: ver.version, |
| 5468 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}, |
| 5469 | ChannelID: channelIDKey, |
| 5470 | }, |
| 5471 | expectChannelID: false, |
| 5472 | flags: []string{"-enable-channel-id"}, |
| 5473 | shouldFail: true, |
| 5474 | expectedLocalError: "channel ID unexpectedly negotiated", |
| 5475 | }) |
| 5476 | } |
| 5477 | } |
| 5478 |
| 5479 | // Channel ID and NPN at the same time, to ensure their relative |
| 5480 | // ordering is correct. |
| 5481 | tests = append(tests, testCase{ |
| 5482 | name: "ChannelID-NPN-Client", |
| 5483 | config: Config{ |
| 5484 | MaxVersion: VersionTLS12, |
| 5485 | RequestChannelID: true, |
| 5486 | NextProtos: []string{"foo"}, |
| 5487 | }, |
| 5488 | flags: []string{ |
| 5489 | "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile), |
| 5490 | "-select-next-proto", "foo", |
| 5491 | }, |
| 5492 | resumeSession: true, |
| 5493 | expectChannelID: true, |
| 5494 | expectedNextProto: "foo", |
| 5495 | expectedNextProtoType: npn, |
| 5496 | }) |
| 5497 | tests = append(tests, testCase{ |
| 5498 | testType: serverTest, |
| 5499 | name: "ChannelID-NPN-Server", |
| 5500 | config: Config{ |
| 5501 | MaxVersion: VersionTLS12, |
| 5502 | ChannelID: channelIDKey, |
| 5503 | NextProtos: []string{"bar"}, |
| 5504 | }, |
| 5505 | flags: []string{ |
| 5506 | "-expect-channel-id", |
| 5507 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 5508 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 5509 | "-expect-next-proto", "bar", |
| 5510 | }, |
| 5511 | resumeSession: true, |
| 5512 | expectChannelID: true, |
| 5513 | expectedNextProto: "bar", |
| 5514 | expectedNextProtoType: npn, |
| 5515 | }) |
| 5516 |
| 5517 | // Bidirectional shutdown with the runner initiating. |
| 5518 | tests = append(tests, testCase{ |
| 5519 | name: "Shutdown-Runner", |
| 5520 | config: Config{ |
| 5521 | Bugs: ProtocolBugs{ |
| 5522 | ExpectCloseNotify: true, |
| 5523 | }, |
| 5524 | }, |
| 5525 | flags: []string{"-check-close-notify"}, |
| 5526 | }) |
| 5527 |
| 5528 | if !config.implicitHandshake { |
| 5529 | // Bidirectional shutdown with the shim initiating. The runner, |
| 5530 | // in the meantime, sends garbage before the close_notify which |
| 5531 | // the shim must ignore. This test is disabled under implicit |
| 5532 | // handshake tests because the shim never reads or writes. |
| 5533 | tests = append(tests, testCase{ |
| 5534 | name: "Shutdown-Shim", |
| 5535 | config: Config{ |
| 5536 | MaxVersion: VersionTLS12, |
| 5537 | Bugs: ProtocolBugs{ |
| 5538 | ExpectCloseNotify: true, |
| 5539 | }, |
| 5540 | }, |
| 5541 | shimShutsDown: true, |
| 5542 | sendEmptyRecords: 1, |
| 5543 | sendWarningAlerts: 1, |
| 5544 | flags: []string{"-check-close-notify"}, |
| 5545 | }) |
| 5546 |
| 5547 | // The shim should reject unexpected application data |
| 5548 | // when shutting down. |
| 5549 | tests = append(tests, testCase{ |
| 5550 | name: "Shutdown-Shim-ApplicationData", |
| 5551 | config: Config{ |
| 5552 | MaxVersion: VersionTLS12, |
| 5553 | Bugs: ProtocolBugs{ |
| 5554 | ExpectCloseNotify: true, |
| 5555 | }, |
| 5556 | }, |
| 5557 | shimShutsDown: true, |
| 5558 | messageCount: 1, |
| 5559 | sendEmptyRecords: 1, |
| 5560 | sendWarningAlerts: 1, |
| 5561 | flags: []string{"-check-close-notify"}, |
| 5562 | shouldFail: true, |
| 5563 | expectedError: ":APPLICATION_DATA_ON_SHUTDOWN:", |
| 5564 | }) |
| 5565 |
| 5566 | // Test that SSL_shutdown still processes KeyUpdate. |
| 5567 | tests = append(tests, testCase{ |
| 5568 | name: "Shutdown-Shim-KeyUpdate", |
| 5569 | config: Config{ |
| 5570 | MinVersion: VersionTLS13, |
| 5571 | MaxVersion: VersionTLS13, |
| 5572 | Bugs: ProtocolBugs{ |
| 5573 | ExpectCloseNotify: true, |
| 5574 | }, |
| 5575 | }, |
| 5576 | shimShutsDown: true, |
| 5577 | sendKeyUpdates: 1, |
| 5578 | keyUpdateRequest: keyUpdateRequested, |
| 5579 | flags: []string{"-check-close-notify"}, |
| 5580 | }) |
| 5581 |
| 5582 | // Test that SSL_shutdown processes HelloRequest |
| 5583 | // correctly. |
| 5584 | tests = append(tests, testCase{ |
| 5585 | name: "Shutdown-Shim-HelloRequest-Ignore", |
| 5586 | config: Config{ |
| 5587 | MinVersion: VersionTLS12, |
| 5588 | MaxVersion: VersionTLS12, |
| 5589 | Bugs: ProtocolBugs{ |
| 5590 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 5591 | ExpectCloseNotify: true, |
| 5592 | }, |
| 5593 | }, |
| 5594 | shimShutsDown: true, |
| 5595 | flags: []string{ |
| 5596 | "-renegotiate-ignore", |
| 5597 | "-check-close-notify", |
| 5598 | }, |
| 5599 | }) |
| 5600 | tests = append(tests, testCase{ |
| 5601 | name: "Shutdown-Shim-HelloRequest-Reject", |
| 5602 | config: Config{ |
| 5603 | MinVersion: VersionTLS12, |
| 5604 | MaxVersion: VersionTLS12, |
| 5605 | Bugs: ProtocolBugs{ |
| 5606 | ExpectCloseNotify: true, |
| 5607 | }, |
| 5608 | }, |
| 5609 | shimShutsDown: true, |
| 5610 | renegotiate: 1, |
| 5611 | shouldFail: true, |
| 5612 | expectedError: ":NO_RENEGOTIATION:", |
| 5613 | flags: []string{"-check-close-notify"}, |
| 5614 | }) |
| 5615 | tests = append(tests, testCase{ |
| 5616 | name: "Shutdown-Shim-HelloRequest-CannotHandshake", |
| 5617 | config: Config{ |
| 5618 | MinVersion: VersionTLS12, |
| 5619 | MaxVersion: VersionTLS12, |
| 5620 | Bugs: ProtocolBugs{ |
| 5621 | ExpectCloseNotify: true, |
| 5622 | }, |
| 5623 | }, |
| 5624 | shimShutsDown: true, |
| 5625 | renegotiate: 1, |
| 5626 | shouldFail: true, |
| 5627 | expectedError: ":NO_RENEGOTIATION:", |
| 5628 | flags: []string{ |
| 5629 | "-check-close-notify", |
| 5630 | "-renegotiate-freely", |
| 5631 | }, |
| 5632 | }) |
| 5633 |
| 5634 | tests = append(tests, testCase{ |
| 5635 | testType: serverTest, |
| 5636 | name: "Shutdown-Shim-Renegotiate-Server-Forbidden", |
| 5637 | config: Config{ |
| 5638 | MaxVersion: VersionTLS12, |
| 5639 | Bugs: ProtocolBugs{ |
| 5640 | ExpectCloseNotify: true, |
| 5641 | }, |
| 5642 | }, |
| 5643 | shimShutsDown: true, |
| 5644 | renegotiate: 1, |
| 5645 | shouldFail: true, |
| 5646 | expectedError: ":NO_RENEGOTIATION:", |
| 5647 | flags: []string{ |
| 5648 | "-check-close-notify", |
| 5649 | }, |
| 5650 | }) |
| 5651 | } |
| 5652 | } else { |
| 5653 | // TODO(davidben): DTLS 1.3 will want a similar thing for |
| 5654 | // HelloRetryRequest. |
| 5655 | tests = append(tests, testCase{ |
| 5656 | name: "SkipHelloVerifyRequest", |
| 5657 | config: Config{ |
| 5658 | MaxVersion: VersionTLS12, |
| 5659 | Bugs: ProtocolBugs{ |
| 5660 | SkipHelloVerifyRequest: true, |
| 5661 | }, |
| 5662 | }, |
| 5663 | }) |
| 5664 | } |
| 5665 |
| 5666 | for _, test := range tests { |
| 5667 | test.protocol = config.protocol |
| 5668 | if config.protocol == dtls { |
| 5669 | test.name += "-DTLS" |
| 5670 | } |
| 5671 | if config.async { |
| 5672 | test.name += "-Async" |
| 5673 | test.flags = append(test.flags, "-async") |
| 5674 | } else { |
| 5675 | test.name += "-Sync" |
| 5676 | } |
| 5677 | if config.splitHandshake { |
| 5678 | test.name += "-SplitHandshakeRecords" |
| 5679 | test.config.Bugs.MaxHandshakeRecordLength = 1 |
| 5680 | if config.protocol == dtls { |
| 5681 | test.config.Bugs.MaxPacketLength = 256 |
| 5682 | test.flags = append(test.flags, "-mtu", "256") |
| 5683 | } |
| 5684 | } |
| 5685 | if config.packHandshake { |
| 5686 | test.name += "-PackHandshake" |
| 5687 | if config.protocol == dtls { |
| 5688 | test.config.Bugs.MaxHandshakeRecordLength = 2 |
| 5689 | test.config.Bugs.PackHandshakeFragments = 20 |
| 5690 | test.config.Bugs.PackHandshakeRecords = 1500 |
| 5691 | test.config.Bugs.PackAppDataWithHandshake = true |
| 5692 | } else { |
| 5693 | test.config.Bugs.PackHandshakeFlight = true |
| 5694 | } |
| 5695 | } |
| 5696 | if config.implicitHandshake { |
| 5697 | test.name += "-ImplicitHandshake" |
| 5698 | test.flags = append(test.flags, "-implicit-handshake") |
| 5699 | } |
| 5700 | testCases = append(testCases, test) |
| 5701 | } |
| 5702 | } |
| 5703 |
| 5704 | func addDDoSCallbackTests() { |
| 5705 | // DDoS callback. |
| 5706 | for _, resume := range []bool{false, true} { |
| 5707 | suffix := "Resume" |
| 5708 | if resume { |
| 5709 | suffix = "No" + suffix |
| 5710 | } |
| 5711 |
| 5712 | testCases = append(testCases, testCase{ |
| 5713 | testType: serverTest, |
| 5714 | name: "Server-DDoS-OK-" + suffix, |
| 5715 | config: Config{ |
| 5716 | MaxVersion: VersionTLS12, |
| 5717 | }, |
| 5718 | flags: []string{"-install-ddos-callback"}, |
| 5719 | resumeSession: resume, |
| 5720 | }) |
| 5721 | testCases = append(testCases, testCase{ |
| 5722 | testType: serverTest, |
| 5723 | name: "Server-DDoS-OK-" + suffix + "-TLS13", |
| 5724 | config: Config{ |
| 5725 | MaxVersion: VersionTLS13, |
| 5726 | }, |
| 5727 | flags: []string{"-install-ddos-callback"}, |
| 5728 | resumeSession: resume, |
| 5729 | }) |
| 5730 |
| 5731 | failFlag := "-fail-ddos-callback" |
| 5732 | if resume { |
| 5733 | failFlag = "-on-resume-fail-ddos-callback" |
| 5734 | } |
| 5735 | testCases = append(testCases, testCase{ |
| 5736 | testType: serverTest, |
| 5737 | name: "Server-DDoS-Reject-" + suffix, |
| 5738 | config: Config{ |
| 5739 | MaxVersion: VersionTLS12, |
| 5740 | }, |
| 5741 | flags: []string{"-install-ddos-callback", failFlag}, |
| 5742 | resumeSession: resume, |
| 5743 | shouldFail: true, |
| 5744 | expectedError: ":CONNECTION_REJECTED:", |
| 5745 | expectedLocalError: "remote error: internal error", |
| 5746 | }) |
| 5747 | testCases = append(testCases, testCase{ |
| 5748 | testType: serverTest, |
| 5749 | name: "Server-DDoS-Reject-" + suffix + "-TLS13", |
| 5750 | config: Config{ |
| 5751 | MaxVersion: VersionTLS13, |
| 5752 | }, |
| 5753 | flags: []string{"-install-ddos-callback", failFlag}, |
| 5754 | resumeSession: resume, |
| 5755 | shouldFail: true, |
| 5756 | expectedError: ":CONNECTION_REJECTED:", |
| 5757 | expectedLocalError: "remote error: internal error", |
| 5758 | }) |
| 5759 | } |
| 5760 | } |
| 5761 |
| 5762 | func addVersionNegotiationTests() { |
| 5763 | for _, protocol := range []protocol{tls, dtls} { |
| 5764 | for _, shimVers := range allVersions(protocol) { |
| 5765 | // Assemble flags to disable all newer versions on the shim. |
| 5766 | var flags []string |
| 5767 | for _, vers := range allVersions(protocol) { |
| 5768 | if vers.version > shimVers.version { |
| 5769 | flags = append(flags, vers.excludeFlag) |
| 5770 | } |
| 5771 | } |
| 5772 |
| 5773 | flags2 := []string{"-max-version", shimVers.shimFlag(protocol)} |
| 5774 |
| 5775 | // Test configuring the runner's maximum version. |
| 5776 | for _, runnerVers := range allVersions(protocol) { |
| 5777 | expectedVersion := shimVers.version |
| 5778 | if runnerVers.version < shimVers.version { |
| 5779 | expectedVersion = runnerVers.version |
| 5780 | } |
| 5781 |
| 5782 | suffix := shimVers.name + "-" + runnerVers.name |
| 5783 | if protocol == dtls { |
| 5784 | suffix += "-DTLS" |
| 5785 | } |
| 5786 |
| 5787 | // Determine the expected initial record-layer versions. |
| 5788 | clientVers := shimVers.version |
| 5789 | if clientVers > VersionTLS10 { |
| 5790 | clientVers = VersionTLS10 |
| 5791 | } |
| 5792 | clientVers = recordVersionToWire(clientVers, protocol) |
| 5793 | serverVers := expectedVersion |
| 5794 | if expectedVersion >= VersionTLS13 { |
| 5795 | serverVers = VersionTLS12 |
| 5796 | } |
| 5797 | serverVers = recordVersionToWire(serverVers, protocol) |
| 5798 |
| 5799 | testCases = append(testCases, testCase{ |
| 5800 | protocol: protocol, |
| 5801 | testType: clientTest, |
| 5802 | name: "VersionNegotiation-Client-" + suffix, |
| 5803 | config: Config{ |
| 5804 | MaxVersion: runnerVers.version, |
| 5805 | Bugs: ProtocolBugs{ |
| 5806 | ExpectInitialRecordVersion: clientVers, |
| 5807 | }, |
| 5808 | }, |
| 5809 | flags: flags, |
| 5810 | expectedVersion: expectedVersion, |
| 5811 | }) |
| 5812 | testCases = append(testCases, testCase{ |
| 5813 | protocol: protocol, |
| 5814 | testType: clientTest, |
| 5815 | name: "VersionNegotiation-Client2-" + suffix, |
| 5816 | config: Config{ |
| 5817 | MaxVersion: runnerVers.version, |
| 5818 | Bugs: ProtocolBugs{ |
| 5819 | ExpectInitialRecordVersion: clientVers, |
| 5820 | }, |
| 5821 | }, |
| 5822 | flags: flags2, |
| 5823 | expectedVersion: expectedVersion, |
| 5824 | }) |
| 5825 |
| 5826 | testCases = append(testCases, testCase{ |
| 5827 | protocol: protocol, |
| 5828 | testType: serverTest, |
| 5829 | name: "VersionNegotiation-Server-" + suffix, |
| 5830 | config: Config{ |
| 5831 | MaxVersion: runnerVers.version, |
| 5832 | Bugs: ProtocolBugs{ |
| 5833 | ExpectInitialRecordVersion: serverVers, |
| 5834 | }, |
| 5835 | }, |
| 5836 | flags: flags, |
| 5837 | expectedVersion: expectedVersion, |
| 5838 | }) |
| 5839 | testCases = append(testCases, testCase{ |
| 5840 | protocol: protocol, |
| 5841 | testType: serverTest, |
| 5842 | name: "VersionNegotiation-Server2-" + suffix, |
| 5843 | config: Config{ |
| 5844 | MaxVersion: runnerVers.version, |
| 5845 | Bugs: ProtocolBugs{ |
| 5846 | ExpectInitialRecordVersion: serverVers, |
| 5847 | }, |
| 5848 | }, |
| 5849 | flags: flags2, |
| 5850 | expectedVersion: expectedVersion, |
| 5851 | }) |
| 5852 | } |
| 5853 | } |
| 5854 | } |
| 5855 |
| 5856 | // Test the version extension at all versions. |
| 5857 | for _, vers := range tlsVersions { |
| 5858 | protocols := []protocol{tls} |
| 5859 | if vers.hasDTLS { |
| 5860 | protocols = append(protocols, dtls) |
| 5861 | } |
| 5862 | for _, protocol := range protocols { |
| 5863 | suffix := vers.name |
| 5864 | if protocol == dtls { |
| 5865 | suffix += "-DTLS" |
| 5866 | } |
| 5867 |
| 5868 | testCases = append(testCases, testCase{ |
| 5869 | protocol: protocol, |
| 5870 | testType: serverTest, |
| 5871 | name: "VersionNegotiationExtension-" + suffix, |
| 5872 | config: Config{ |
| 5873 | Bugs: ProtocolBugs{ |
| 5874 | SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222}, |
| 5875 | IgnoreTLS13DowngradeRandom: true, |
| 5876 | }, |
| 5877 | }, |
| 5878 | expectedVersion: vers.version, |
| 5879 | }) |
| 5880 | } |
| 5881 | } |
| 5882 |
| 5883 | // If all versions are unknown, negotiation fails. |
| 5884 | testCases = append(testCases, testCase{ |
| 5885 | testType: serverTest, |
| 5886 | name: "NoSupportedVersions", |
| 5887 | config: Config{ |
| 5888 | Bugs: ProtocolBugs{ |
| 5889 | SendSupportedVersions: []uint16{0x1111}, |
| 5890 | }, |
| 5891 | }, |
| 5892 | shouldFail: true, |
| 5893 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 5894 | }) |
| 5895 | testCases = append(testCases, testCase{ |
| 5896 | protocol: dtls, |
| 5897 | testType: serverTest, |
| 5898 | name: "NoSupportedVersions-DTLS", |
| 5899 | config: Config{ |
| 5900 | Bugs: ProtocolBugs{ |
| 5901 | SendSupportedVersions: []uint16{0x1111}, |
| 5902 | }, |
| 5903 | }, |
| 5904 | shouldFail: true, |
| 5905 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 5906 | }) |
| 5907 |
| 5908 | testCases = append(testCases, testCase{ |
| 5909 | testType: serverTest, |
| 5910 | name: "ClientHelloVersionTooHigh", |
| 5911 | config: Config{ |
| 5912 | MaxVersion: VersionTLS13, |
| 5913 | Bugs: ProtocolBugs{ |
| 5914 | SendClientVersion: 0x0304, |
| 5915 | OmitSupportedVersions: true, |
| 5916 | IgnoreTLS13DowngradeRandom: true, |
| 5917 | }, |
| 5918 | }, |
| 5919 | expectedVersion: VersionTLS12, |
| 5920 | }) |
| 5921 |
| 5922 | testCases = append(testCases, testCase{ |
| 5923 | testType: serverTest, |
| 5924 | name: "ConflictingVersionNegotiation", |
| 5925 | config: Config{ |
| 5926 | Bugs: ProtocolBugs{ |
| 5927 | SendClientVersion: VersionTLS12, |
| 5928 | SendSupportedVersions: []uint16{VersionTLS11}, |
| 5929 | IgnoreTLS13DowngradeRandom: true, |
| 5930 | }, |
| 5931 | }, |
| 5932 | // The extension takes precedence over the ClientHello version. |
| 5933 | expectedVersion: VersionTLS11, |
| 5934 | }) |
| 5935 |
| 5936 | testCases = append(testCases, testCase{ |
| 5937 | testType: serverTest, |
| 5938 | name: "ConflictingVersionNegotiation-2", |
| 5939 | config: Config{ |
| 5940 | Bugs: ProtocolBugs{ |
| 5941 | SendClientVersion: VersionTLS11, |
| 5942 | SendSupportedVersions: []uint16{VersionTLS12}, |
| 5943 | IgnoreTLS13DowngradeRandom: true, |
| 5944 | }, |
| 5945 | }, |
| 5946 | // The extension takes precedence over the ClientHello version. |
| 5947 | expectedVersion: VersionTLS12, |
| 5948 | }) |
| 5949 |
| 5950 | // Test that TLS 1.2 isn't negotiated by the supported_versions extension in |
| 5951 | // the ServerHello. |
| 5952 | testCases = append(testCases, testCase{ |
| 5953 | testType: clientTest, |
| 5954 | name: "SupportedVersionSelection-TLS12", |
| 5955 | config: Config{ |
| 5956 | MaxVersion: VersionTLS12, |
| 5957 | Bugs: ProtocolBugs{ |
| 5958 | SendServerSupportedVersionExtension: VersionTLS12, |
| 5959 | }, |
| 5960 | }, |
| 5961 | shouldFail: true, |
| 5962 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 5963 | }) |
| 5964 |
| 5965 | // Test that the maximum version is selected regardless of the |
| 5966 | // client-sent order. |
| 5967 | testCases = append(testCases, testCase{ |
| 5968 | testType: serverTest, |
| 5969 | name: "IgnoreClientVersionOrder", |
| 5970 | config: Config{ |
| 5971 | Bugs: ProtocolBugs{ |
| 5972 | SendSupportedVersions: []uint16{VersionTLS12, VersionTLS13}, |
| 5973 | }, |
| 5974 | }, |
| 5975 | expectedVersion: VersionTLS13, |
| 5976 | }) |
| 5977 |
| 5978 | // Test for version tolerance. |
| 5979 | testCases = append(testCases, testCase{ |
| 5980 | testType: serverTest, |
| 5981 | name: "MinorVersionTolerance", |
| 5982 | config: Config{ |
| 5983 | Bugs: ProtocolBugs{ |
| 5984 | SendClientVersion: 0x03ff, |
| 5985 | OmitSupportedVersions: true, |
| 5986 | IgnoreTLS13DowngradeRandom: true, |
| 5987 | }, |
| 5988 | }, |
| 5989 | expectedVersion: VersionTLS12, |
| 5990 | }) |
| 5991 | testCases = append(testCases, testCase{ |
| 5992 | testType: serverTest, |
| 5993 | name: "MajorVersionTolerance", |
| 5994 | config: Config{ |
| 5995 | Bugs: ProtocolBugs{ |
| 5996 | SendClientVersion: 0x0400, |
| 5997 | OmitSupportedVersions: true, |
| 5998 | IgnoreTLS13DowngradeRandom: true, |
| 5999 | }, |
| 6000 | }, |
| 6001 | // TLS 1.3 must be negotiated with the supported_versions |
| 6002 | // extension, not ClientHello.version. |
| 6003 | expectedVersion: VersionTLS12, |
| 6004 | }) |
| 6005 | testCases = append(testCases, testCase{ |
| 6006 | testType: serverTest, |
| 6007 | name: "VersionTolerance-TLS13", |
| 6008 | config: Config{ |
| 6009 | Bugs: ProtocolBugs{ |
| 6010 | // Although TLS 1.3 does not use |
| 6011 | // ClientHello.version, it still tolerates high |
| 6012 | // values there. |
| 6013 | SendClientVersion: 0x0400, |
| 6014 | }, |
| 6015 | }, |
| 6016 | expectedVersion: VersionTLS13, |
| 6017 | }) |
| 6018 |
| 6019 | testCases = append(testCases, testCase{ |
| 6020 | protocol: dtls, |
| 6021 | testType: serverTest, |
| 6022 | name: "MinorVersionTolerance-DTLS", |
| 6023 | config: Config{ |
| 6024 | Bugs: ProtocolBugs{ |
| 6025 | SendClientVersion: 0xfe00, |
| 6026 | OmitSupportedVersions: true, |
| 6027 | }, |
| 6028 | }, |
| 6029 | expectedVersion: VersionTLS12, |
| 6030 | }) |
| 6031 | testCases = append(testCases, testCase{ |
| 6032 | protocol: dtls, |
| 6033 | testType: serverTest, |
| 6034 | name: "MajorVersionTolerance-DTLS", |
| 6035 | config: Config{ |
| 6036 | Bugs: ProtocolBugs{ |
| 6037 | SendClientVersion: 0xfdff, |
| 6038 | OmitSupportedVersions: true, |
| 6039 | }, |
| 6040 | }, |
| 6041 | expectedVersion: VersionTLS12, |
| 6042 | }) |
| 6043 |
| 6044 | // Test that versions below 3.0 are rejected. |
| 6045 | testCases = append(testCases, testCase{ |
| 6046 | testType: serverTest, |
| 6047 | name: "VersionTooLow", |
| 6048 | config: Config{ |
| 6049 | Bugs: ProtocolBugs{ |
| 6050 | SendClientVersion: 0x0200, |
| 6051 | OmitSupportedVersions: true, |
| 6052 | }, |
| 6053 | }, |
| 6054 | shouldFail: true, |
| 6055 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 6056 | }) |
| 6057 | testCases = append(testCases, testCase{ |
| 6058 | protocol: dtls, |
| 6059 | testType: serverTest, |
| 6060 | name: "VersionTooLow-DTLS", |
| 6061 | config: Config{ |
| 6062 | Bugs: ProtocolBugs{ |
| 6063 | SendClientVersion: 0xffff, |
| 6064 | }, |
| 6065 | }, |
| 6066 | shouldFail: true, |
| 6067 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 6068 | }) |
| 6069 |
| 6070 | testCases = append(testCases, testCase{ |
| 6071 | name: "ServerBogusVersion", |
| 6072 | config: Config{ |
| 6073 | Bugs: ProtocolBugs{ |
| 6074 | SendServerHelloVersion: 0x1234, |
| 6075 | }, |
| 6076 | }, |
| 6077 | shouldFail: true, |
| 6078 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 6079 | }) |
| 6080 |
| 6081 | // Test TLS 1.3's downgrade signal. |
| 6082 | var downgradeTests = []struct { |
| 6083 | name string |
| 6084 | version uint16 |
| 6085 | clientShimError string |
| 6086 | }{ |
| 6087 | {"TLS12", VersionTLS12, "tls: downgrade from TLS 1.3 detected"}, |
| 6088 | {"TLS11", VersionTLS11, "tls: downgrade from TLS 1.2 detected"}, |
| 6089 | // TLS 1.0 does not have a dedicated value. |
| 6090 | {"TLS10", VersionTLS10, "tls: downgrade from TLS 1.2 detected"}, |
| 6091 | } |
| 6092 |
| 6093 | for _, test := range downgradeTests { |
| 6094 | // The client should enforce the downgrade sentinel. |
| 6095 | testCases = append(testCases, testCase{ |
| 6096 | name: "Downgrade-" + test.name + "-Client", |
| 6097 | config: Config{ |
| 6098 | Bugs: ProtocolBugs{ |
| 6099 | NegotiateVersion: test.version, |
| 6100 | }, |
| 6101 | }, |
| 6102 | expectedVersion: test.version, |
| 6103 | shouldFail: true, |
| 6104 | expectedError: ":TLS13_DOWNGRADE:", |
| 6105 | expectedLocalError: "remote error: illegal parameter", |
| 6106 | }) |
| 6107 |
| 6108 | // The client should ignore the downgrade sentinel if |
| 6109 | // configured. |
| 6110 | testCases = append(testCases, testCase{ |
| 6111 | name: "Downgrade-" + test.name + "-Client-Ignore", |
| 6112 | config: Config{ |
| 6113 | Bugs: ProtocolBugs{ |
| 6114 | NegotiateVersion: test.version, |
| 6115 | }, |
| 6116 | }, |
| 6117 | expectedVersion: test.version, |
| 6118 | flags: []string{ |
| 6119 | "-ignore-tls13-downgrade", |
| 6120 | "-expect-tls13-downgrade", |
| 6121 | }, |
| 6122 | }) |
| 6123 |
| 6124 | // The server should emit the downgrade signal. |
| 6125 | testCases = append(testCases, testCase{ |
| 6126 | testType: serverTest, |
| 6127 | name: "Downgrade-" + test.name + "-Server", |
| 6128 | config: Config{ |
| 6129 | Bugs: ProtocolBugs{ |
| 6130 | SendSupportedVersions: []uint16{test.version}, |
| 6131 | }, |
| 6132 | }, |
| 6133 | expectedVersion: test.version, |
| 6134 | shouldFail: true, |
| 6135 | expectedLocalError: test.clientShimError, |
| 6136 | }) |
| 6137 | } |
| 6138 |
| 6139 | // Test that False Start is disabled when the downgrade logic triggers. |
| 6140 | testCases = append(testCases, testCase{ |
| 6141 | name: "Downgrade-FalseStart", |
| 6142 | config: Config{ |
| 6143 | NextProtos: []string{"foo"}, |
| 6144 | Bugs: ProtocolBugs{ |
| 6145 | NegotiateVersion: VersionTLS12, |
| 6146 | ExpectFalseStart: true, |
| 6147 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 6148 | }, |
| 6149 | }, |
| 6150 | expectedVersion: VersionTLS12, |
| 6151 | flags: []string{ |
| 6152 | "-false-start", |
| 6153 | "-advertise-alpn", "\x03foo", |
| 6154 | "-ignore-tls13-downgrade", |
| 6155 | }, |
| 6156 | shimWritesFirst: true, |
| 6157 | shouldFail: true, |
| 6158 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 6159 | expectedLocalError: "tls: peer did not false start: EOF", |
| 6160 | }) |
| 6161 |
| 6162 | // SSL 3.0 support has been removed. Test that the shim does not |
| 6163 | // support it. |
| 6164 | testCases = append(testCases, testCase{ |
| 6165 | name: "NoSSL3-Client", |
| 6166 | config: Config{ |
| 6167 | MinVersion: VersionSSL30, |
| 6168 | MaxVersion: VersionSSL30, |
| 6169 | }, |
| 6170 | shouldFail: true, |
| 6171 | expectedLocalError: "tls: client did not offer any supported protocol versions", |
| 6172 | }) |
| 6173 | testCases = append(testCases, testCase{ |
| 6174 | name: "NoSSL3-Client-Unsolicited", |
| 6175 | config: Config{ |
| 6176 | MinVersion: VersionSSL30, |
| 6177 | MaxVersion: VersionSSL30, |
| 6178 | Bugs: ProtocolBugs{ |
| 6179 | // The above test asserts the client does not |
| 6180 | // offer SSL 3.0 in the supported_versions |
| 6181 | // list. Additionally assert that it rejects an |
| 6182 | // unsolicited SSL 3.0 ServerHello. |
| 6183 | NegotiateVersion: VersionSSL30, |
| 6184 | }, |
| 6185 | }, |
| 6186 | shouldFail: true, |
| 6187 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 6188 | expectedLocalError: "remote error: protocol version not supported", |
| 6189 | }) |
| 6190 | testCases = append(testCases, testCase{ |
| 6191 | testType: serverTest, |
| 6192 | name: "NoSSL3-Server", |
| 6193 | config: Config{ |
| 6194 | MinVersion: VersionSSL30, |
| 6195 | MaxVersion: VersionSSL30, |
| 6196 | }, |
| 6197 | shouldFail: true, |
| 6198 | expectedError: ":UNSUPPORTED_PROTOCOL:", |
| 6199 | expectedLocalError: "remote error: protocol version not supported", |
| 6200 | }) |
| 6201 | } |
| 6202 |
| 6203 | func addMinimumVersionTests() { |
| 6204 | for _, protocol := range []protocol{tls, dtls} { |
| 6205 | for _, shimVers := range allVersions(protocol) { |
| 6206 | // Assemble flags to disable all older versions on the shim. |
| 6207 | var flags []string |
| 6208 | for _, vers := range allVersions(protocol) { |
| 6209 | if vers.version < shimVers.version { |
| 6210 | flags = append(flags, vers.excludeFlag) |
| 6211 | } |
| 6212 | } |
| 6213 |
| 6214 | flags2 := []string{"-min-version", shimVers.shimFlag(protocol)} |
| 6215 |
| 6216 | for _, runnerVers := range allVersions(protocol) { |
| 6217 | suffix := shimVers.name + "-" + runnerVers.name |
| 6218 | if protocol == dtls { |
| 6219 | suffix += "-DTLS" |
| 6220 | } |
| 6221 |
| 6222 | var expectedVersion uint16 |
| 6223 | var shouldFail bool |
| 6224 | var expectedError, expectedLocalError string |
| 6225 | if runnerVers.version >= shimVers.version { |
| 6226 | expectedVersion = runnerVers.version |
| 6227 | } else { |
| 6228 | shouldFail = true |
| 6229 | expectedError = ":UNSUPPORTED_PROTOCOL:" |
| 6230 | expectedLocalError = "remote error: protocol version not supported" |
| 6231 | } |
| 6232 |
| 6233 | testCases = append(testCases, testCase{ |
| 6234 | protocol: protocol, |
| 6235 | testType: clientTest, |
| 6236 | name: "MinimumVersion-Client-" + suffix, |
| 6237 | config: Config{ |
| 6238 | MaxVersion: runnerVers.version, |
| 6239 | Bugs: ProtocolBugs{ |
| 6240 | // Ensure the server does not decline to |
| 6241 | // select a version (versions extension) or |
| 6242 | // cipher (some ciphers depend on versions). |
| 6243 | NegotiateVersion: runnerVers.wire(protocol), |
| 6244 | IgnorePeerCipherPreferences: shouldFail, |
| 6245 | }, |
| 6246 | }, |
| 6247 | flags: flags, |
| 6248 | expectedVersion: expectedVersion, |
| 6249 | shouldFail: shouldFail, |
| 6250 | expectedError: expectedError, |
| 6251 | expectedLocalError: expectedLocalError, |
| 6252 | }) |
| 6253 | testCases = append(testCases, testCase{ |
| 6254 | protocol: protocol, |
| 6255 | testType: clientTest, |
| 6256 | name: "MinimumVersion-Client2-" + suffix, |
| 6257 | config: Config{ |
| 6258 | MaxVersion: runnerVers.version, |
| 6259 | Bugs: ProtocolBugs{ |
| 6260 | // Ensure the server does not decline to |
| 6261 | // select a version (versions extension) or |
| 6262 | // cipher (some ciphers depend on versions). |
| 6263 | NegotiateVersion: runnerVers.wire(protocol), |
| 6264 | IgnorePeerCipherPreferences: shouldFail, |
| 6265 | }, |
| 6266 | }, |
| 6267 | flags: flags2, |
| 6268 | expectedVersion: expectedVersion, |
| 6269 | shouldFail: shouldFail, |
| 6270 | expectedError: expectedError, |
| 6271 | expectedLocalError: expectedLocalError, |
| 6272 | }) |
| 6273 |
| 6274 | testCases = append(testCases, testCase{ |
| 6275 | protocol: protocol, |
| 6276 | testType: serverTest, |
| 6277 | name: "MinimumVersion-Server-" + suffix, |
| 6278 | config: Config{ |
| 6279 | MaxVersion: runnerVers.version, |
| 6280 | }, |
| 6281 | flags: flags, |
| 6282 | expectedVersion: expectedVersion, |
| 6283 | shouldFail: shouldFail, |
| 6284 | expectedError: expectedError, |
| 6285 | expectedLocalError: expectedLocalError, |
| 6286 | }) |
| 6287 | testCases = append(testCases, testCase{ |
| 6288 | protocol: protocol, |
| 6289 | testType: serverTest, |
| 6290 | name: "MinimumVersion-Server2-" + suffix, |
| 6291 | config: Config{ |
| 6292 | MaxVersion: runnerVers.version, |
| 6293 | }, |
| 6294 | flags: flags2, |
| 6295 | expectedVersion: expectedVersion, |
| 6296 | shouldFail: shouldFail, |
| 6297 | expectedError: expectedError, |
| 6298 | expectedLocalError: expectedLocalError, |
| 6299 | }) |
| 6300 | } |
| 6301 | } |
| 6302 | } |
| 6303 | } |
| 6304 |
| 6305 | func addExtensionTests() { |
| 6306 | // TODO(davidben): Extensions, where applicable, all move their server |
| 6307 | // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these |
| 6308 | // tests for both. Also test interaction with 0-RTT when implemented. |
| 6309 |
| 6310 | // Repeat extensions tests at all versions. |
| 6311 | for _, ver := range tlsVersions { |
| 6312 | // Test that duplicate extensions are rejected. |
| 6313 | testCases = append(testCases, testCase{ |
| 6314 | testType: clientTest, |
| 6315 | name: "DuplicateExtensionClient-" + ver.name, |
| 6316 | config: Config{ |
| 6317 | MaxVersion: ver.version, |
| 6318 | Bugs: ProtocolBugs{ |
| 6319 | DuplicateExtension: true, |
| 6320 | }, |
| 6321 | }, |
| 6322 | shouldFail: true, |
| 6323 | expectedLocalError: "remote error: error decoding message", |
| 6324 | }) |
| 6325 | testCases = append(testCases, testCase{ |
| 6326 | testType: serverTest, |
| 6327 | name: "DuplicateExtensionServer-" + ver.name, |
| 6328 | config: Config{ |
| 6329 | MaxVersion: ver.version, |
| 6330 | Bugs: ProtocolBugs{ |
| 6331 | DuplicateExtension: true, |
| 6332 | }, |
| 6333 | }, |
| 6334 | shouldFail: true, |
| 6335 | expectedLocalError: "remote error: error decoding message", |
| 6336 | }) |
| 6337 |
| 6338 | // Test SNI. |
| 6339 | testCases = append(testCases, testCase{ |
| 6340 | testType: clientTest, |
| 6341 | name: "ServerNameExtensionClient-" + ver.name, |
| 6342 | config: Config{ |
| 6343 | MaxVersion: ver.version, |
| 6344 | Bugs: ProtocolBugs{ |
| 6345 | ExpectServerName: "example.com", |
| 6346 | }, |
| 6347 | }, |
| 6348 | flags: []string{"-host-name", "example.com"}, |
| 6349 | }) |
| 6350 | testCases = append(testCases, testCase{ |
| 6351 | testType: clientTest, |
| 6352 | name: "ServerNameExtensionClientMismatch-" + ver.name, |
| 6353 | config: Config{ |
| 6354 | MaxVersion: ver.version, |
| 6355 | Bugs: ProtocolBugs{ |
| 6356 | ExpectServerName: "mismatch.com", |
| 6357 | }, |
| 6358 | }, |
| 6359 | flags: []string{"-host-name", "example.com"}, |
| 6360 | shouldFail: true, |
| 6361 | expectedLocalError: "tls: unexpected server name", |
| 6362 | }) |
| 6363 | testCases = append(testCases, testCase{ |
| 6364 | testType: clientTest, |
| 6365 | name: "ServerNameExtensionClientMissing-" + ver.name, |
| 6366 | config: Config{ |
| 6367 | MaxVersion: ver.version, |
| 6368 | Bugs: ProtocolBugs{ |
| 6369 | ExpectServerName: "missing.com", |
| 6370 | }, |
| 6371 | }, |
| 6372 | shouldFail: true, |
| 6373 | expectedLocalError: "tls: unexpected server name", |
| 6374 | }) |
| 6375 | testCases = append(testCases, testCase{ |
| 6376 | testType: clientTest, |
| 6377 | name: "TolerateServerNameAck-" + ver.name, |
| 6378 | config: Config{ |
| 6379 | MaxVersion: ver.version, |
| 6380 | Bugs: ProtocolBugs{ |
| 6381 | SendServerNameAck: true, |
| 6382 | }, |
| 6383 | }, |
| 6384 | flags: []string{"-host-name", "example.com"}, |
| 6385 | resumeSession: true, |
| 6386 | }) |
| 6387 | testCases = append(testCases, testCase{ |
| 6388 | testType: clientTest, |
| 6389 | name: "UnsolicitedServerNameAck-" + ver.name, |
| 6390 | config: Config{ |
| 6391 | MaxVersion: ver.version, |
| 6392 | Bugs: ProtocolBugs{ |
| 6393 | SendServerNameAck: true, |
| 6394 | }, |
| 6395 | }, |
| 6396 | shouldFail: true, |
| 6397 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6398 | expectedLocalError: "remote error: unsupported extension", |
| 6399 | }) |
| 6400 | testCases = append(testCases, testCase{ |
| 6401 | testType: serverTest, |
| 6402 | name: "ServerNameExtensionServer-" + ver.name, |
| 6403 | config: Config{ |
| 6404 | MaxVersion: ver.version, |
| 6405 | ServerName: "example.com", |
| 6406 | }, |
| 6407 | flags: []string{"-expect-server-name", "example.com"}, |
| 6408 | resumeSession: true, |
| 6409 | }) |
| 6410 |
| 6411 | // Test ALPN. |
| 6412 | testCases = append(testCases, testCase{ |
| 6413 | testType: clientTest, |
| 6414 | name: "ALPNClient-" + ver.name, |
| 6415 | config: Config{ |
| 6416 | MaxVersion: ver.version, |
| 6417 | NextProtos: []string{"foo"}, |
| 6418 | }, |
| 6419 | flags: []string{ |
| 6420 | "-advertise-alpn", "\x03foo\x03bar\x03baz", |
| 6421 | "-expect-alpn", "foo", |
| 6422 | }, |
| 6423 | expectedNextProto: "foo", |
| 6424 | expectedNextProtoType: alpn, |
| 6425 | resumeSession: true, |
| 6426 | }) |
| 6427 | testCases = append(testCases, testCase{ |
| 6428 | testType: clientTest, |
| 6429 | name: "ALPNClient-RejectUnknown-" + ver.name, |
| 6430 | config: Config{ |
| 6431 | MaxVersion: ver.version, |
| 6432 | Bugs: ProtocolBugs{ |
| 6433 | SendALPN: "baz", |
| 6434 | }, |
| 6435 | }, |
| 6436 | flags: []string{ |
| 6437 | "-advertise-alpn", "\x03foo\x03bar", |
| 6438 | }, |
| 6439 | shouldFail: true, |
| 6440 | expectedError: ":INVALID_ALPN_PROTOCOL:", |
| 6441 | expectedLocalError: "remote error: illegal parameter", |
| 6442 | }) |
| 6443 | testCases = append(testCases, testCase{ |
| 6444 | testType: clientTest, |
| 6445 | name: "ALPNClient-AllowUnknown-" + ver.name, |
| 6446 | config: Config{ |
| 6447 | MaxVersion: ver.version, |
| 6448 | Bugs: ProtocolBugs{ |
| 6449 | SendALPN: "baz", |
| 6450 | }, |
| 6451 | }, |
| 6452 | flags: []string{ |
| 6453 | "-advertise-alpn", "\x03foo\x03bar", |
| 6454 | "-allow-unknown-alpn-protos", |
| 6455 | "-expect-alpn", "baz", |
| 6456 | }, |
| 6457 | }) |
| 6458 | testCases = append(testCases, testCase{ |
| 6459 | testType: serverTest, |
| 6460 | name: "ALPNServer-" + ver.name, |
| 6461 | config: Config{ |
| 6462 | MaxVersion: ver.version, |
| 6463 | NextProtos: []string{"foo", "bar", "baz"}, |
| 6464 | }, |
| 6465 | flags: []string{ |
| 6466 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 6467 | "-select-alpn", "foo", |
| 6468 | }, |
| 6469 | expectedNextProto: "foo", |
| 6470 | expectedNextProtoType: alpn, |
| 6471 | resumeSession: true, |
| 6472 | }) |
| 6473 | testCases = append(testCases, testCase{ |
| 6474 | testType: serverTest, |
| 6475 | name: "ALPNServer-Decline-" + ver.name, |
| 6476 | config: Config{ |
| 6477 | MaxVersion: ver.version, |
| 6478 | NextProtos: []string{"foo", "bar", "baz"}, |
| 6479 | }, |
| 6480 | flags: []string{"-decline-alpn"}, |
| 6481 | expectNoNextProto: true, |
| 6482 | resumeSession: true, |
| 6483 | }) |
| 6484 | // Test that the server implementation catches itself if the |
| 6485 | // callback tries to return an invalid empty ALPN protocol. |
| 6486 | testCases = append(testCases, testCase{ |
| 6487 | testType: serverTest, |
| 6488 | name: "ALPNServer-SelectEmpty-" + ver.name, |
| 6489 | config: Config{ |
| 6490 | MaxVersion: ver.version, |
| 6491 | NextProtos: []string{"foo", "bar", "baz"}, |
| 6492 | }, |
| 6493 | flags: []string{ |
| 6494 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 6495 | "-select-empty-alpn", |
| 6496 | }, |
| 6497 | shouldFail: true, |
| 6498 | expectedLocalError: "remote error: internal error", |
| 6499 | expectedError: ":INVALID_ALPN_PROTOCOL:", |
| 6500 | }) |
| 6501 |
| 6502 | // Test ALPN in async mode as well to ensure that extensions callbacks are only |
| 6503 | // called once. |
| 6504 | testCases = append(testCases, testCase{ |
| 6505 | testType: serverTest, |
| 6506 | name: "ALPNServer-Async-" + ver.name, |
| 6507 | config: Config{ |
| 6508 | MaxVersion: ver.version, |
| 6509 | NextProtos: []string{"foo", "bar", "baz"}, |
| 6510 | // Prior to TLS 1.3, exercise the asynchronous session callback. |
| 6511 | SessionTicketsDisabled: ver.version < VersionTLS13, |
| 6512 | }, |
| 6513 | flags: []string{ |
| 6514 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 6515 | "-select-alpn", "foo", |
| 6516 | "-async", |
| 6517 | }, |
| 6518 | expectedNextProto: "foo", |
| 6519 | expectedNextProtoType: alpn, |
| 6520 | resumeSession: true, |
| 6521 | }) |
| 6522 |
| 6523 | var emptyString string |
| 6524 | testCases = append(testCases, testCase{ |
| 6525 | testType: clientTest, |
| 6526 | name: "ALPNClient-EmptyProtocolName-" + ver.name, |
| 6527 | config: Config{ |
| 6528 | MaxVersion: ver.version, |
| 6529 | NextProtos: []string{""}, |
| 6530 | Bugs: ProtocolBugs{ |
| 6531 | // A server returning an empty ALPN protocol |
| 6532 | // should be rejected. |
| 6533 | ALPNProtocol: &emptyString, |
| 6534 | }, |
| 6535 | }, |
| 6536 | flags: []string{ |
| 6537 | "-advertise-alpn", "\x03foo", |
| 6538 | }, |
| 6539 | shouldFail: true, |
| 6540 | expectedError: ":PARSE_TLSEXT:", |
| 6541 | }) |
| 6542 | testCases = append(testCases, testCase{ |
| 6543 | testType: serverTest, |
| 6544 | name: "ALPNServer-EmptyProtocolName-" + ver.name, |
| 6545 | config: Config{ |
| 6546 | MaxVersion: ver.version, |
| 6547 | // A ClientHello containing an empty ALPN protocol |
| 6548 | // should be rejected. |
| 6549 | NextProtos: []string{"foo", "", "baz"}, |
| 6550 | }, |
| 6551 | flags: []string{ |
| 6552 | "-select-alpn", "foo", |
| 6553 | }, |
| 6554 | shouldFail: true, |
| 6555 | expectedError: ":PARSE_TLSEXT:", |
| 6556 | }) |
| 6557 |
| 6558 | // Test NPN and the interaction with ALPN. |
| 6559 | if ver.version < VersionTLS13 { |
| 6560 | // Test that the server prefers ALPN over NPN. |
| 6561 | testCases = append(testCases, testCase{ |
| 6562 | testType: serverTest, |
| 6563 | name: "ALPNServer-Preferred-" + ver.name, |
| 6564 | config: Config{ |
| 6565 | MaxVersion: ver.version, |
| 6566 | NextProtos: []string{"foo", "bar", "baz"}, |
| 6567 | }, |
| 6568 | flags: []string{ |
| 6569 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 6570 | "-select-alpn", "foo", |
| 6571 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 6572 | }, |
| 6573 | expectedNextProto: "foo", |
| 6574 | expectedNextProtoType: alpn, |
| 6575 | resumeSession: true, |
| 6576 | }) |
| 6577 | testCases = append(testCases, testCase{ |
| 6578 | testType: serverTest, |
| 6579 | name: "ALPNServer-Preferred-Swapped-" + ver.name, |
| 6580 | config: Config{ |
| 6581 | MaxVersion: ver.version, |
| 6582 | NextProtos: []string{"foo", "bar", "baz"}, |
| 6583 | Bugs: ProtocolBugs{ |
| 6584 | SwapNPNAndALPN: true, |
| 6585 | }, |
| 6586 | }, |
| 6587 | flags: []string{ |
| 6588 | "-expect-advertised-alpn", "\x03foo\x03bar\x03baz", |
| 6589 | "-select-alpn", "foo", |
| 6590 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 6591 | }, |
| 6592 | expectedNextProto: "foo", |
| 6593 | expectedNextProtoType: alpn, |
| 6594 | resumeSession: true, |
| 6595 | }) |
| 6596 |
| 6597 | // Test that negotiating both NPN and ALPN is forbidden. |
| 6598 | testCases = append(testCases, testCase{ |
| 6599 | name: "NegotiateALPNAndNPN-" + ver.name, |
| 6600 | config: Config{ |
| 6601 | MaxVersion: ver.version, |
| 6602 | NextProtos: []string{"foo", "bar", "baz"}, |
| 6603 | Bugs: ProtocolBugs{ |
| 6604 | NegotiateALPNAndNPN: true, |
| 6605 | }, |
| 6606 | }, |
| 6607 | flags: []string{ |
| 6608 | "-advertise-alpn", "\x03foo", |
| 6609 | "-select-next-proto", "foo", |
| 6610 | }, |
| 6611 | shouldFail: true, |
| 6612 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 6613 | }) |
| 6614 | testCases = append(testCases, testCase{ |
| 6615 | name: "NegotiateALPNAndNPN-Swapped-" + ver.name, |
| 6616 | config: Config{ |
| 6617 | MaxVersion: ver.version, |
| 6618 | NextProtos: []string{"foo", "bar", "baz"}, |
| 6619 | Bugs: ProtocolBugs{ |
| 6620 | NegotiateALPNAndNPN: true, |
| 6621 | SwapNPNAndALPN: true, |
| 6622 | }, |
| 6623 | }, |
| 6624 | flags: []string{ |
| 6625 | "-advertise-alpn", "\x03foo", |
| 6626 | "-select-next-proto", "foo", |
| 6627 | }, |
| 6628 | shouldFail: true, |
| 6629 | expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:", |
| 6630 | }) |
| 6631 | } |
| 6632 |
| 6633 | // Test Token Binding. |
| 6634 |
| 6635 | const maxTokenBindingVersion = 16 |
| 6636 | const minTokenBindingVersion = 13 |
| 6637 | testCases = append(testCases, testCase{ |
| 6638 | testType: serverTest, |
| 6639 | name: "TokenBinding-Server-" + ver.name, |
| 6640 |
| 6641 | config: Config{ |
| 6642 | MinVersion: ver.version, |
| 6643 | MaxVersion: ver.version, |
| 6644 | TokenBindingParams: []byte{0, 1, 2}, |
| 6645 | TokenBindingVersion: maxTokenBindingVersion, |
| 6646 | }, |
| 6647 | expectTokenBinding: true, |
| 6648 | expectedTokenBindingParam: 2, |
| 6649 | flags: []string{ |
| 6650 | "-token-binding-params", |
| 6651 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 6652 | "-expect-token-binding-param", |
| 6653 | "2", |
| 6654 | }, |
| 6655 | }) |
| 6656 | testCases = append(testCases, testCase{ |
| 6657 | testType: serverTest, |
| 6658 | name: "TokenBinding-Server-UnsupportedParam-" + ver.name, |
| 6659 |
| 6660 | config: Config{ |
| 6661 | MinVersion: ver.version, |
| 6662 | MaxVersion: ver.version, |
| 6663 | TokenBindingParams: []byte{3}, |
| 6664 | TokenBindingVersion: maxTokenBindingVersion, |
| 6665 | }, |
| 6666 | flags: []string{ |
| 6667 | "-token-binding-params", |
| 6668 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 6669 | }, |
| 6670 | }) |
| 6671 | testCases = append(testCases, testCase{ |
| 6672 | testType: serverTest, |
| 6673 | name: "TokenBinding-Server-OldVersion-" + ver.name, |
| 6674 |
| 6675 | config: Config{ |
| 6676 | MinVersion: ver.version, |
| 6677 | MaxVersion: ver.version, |
| 6678 | TokenBindingParams: []byte{0, 1, 2}, |
| 6679 | TokenBindingVersion: minTokenBindingVersion - 1, |
| 6680 | }, |
| 6681 | flags: []string{ |
| 6682 | "-token-binding-params", |
| 6683 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 6684 | }, |
| 6685 | }) |
| 6686 | testCases = append(testCases, testCase{ |
| 6687 | testType: serverTest, |
| 6688 | name: "TokenBinding-Server-NewVersion-" + ver.name, |
| 6689 |
| 6690 | config: Config{ |
| 6691 | MinVersion: ver.version, |
| 6692 | MaxVersion: ver.version, |
| 6693 | TokenBindingParams: []byte{0, 1, 2}, |
| 6694 | TokenBindingVersion: maxTokenBindingVersion + 1, |
| 6695 | }, |
| 6696 | expectTokenBinding: true, |
| 6697 | expectedTokenBindingParam: 2, |
| 6698 | flags: []string{ |
| 6699 | "-token-binding-params", |
| 6700 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 6701 | "-expect-token-binding-param", |
| 6702 | "2", |
| 6703 | }, |
| 6704 | }) |
| 6705 | testCases = append(testCases, testCase{ |
| 6706 | testType: serverTest, |
| 6707 | name: "TokenBinding-Server-NoParams-" + ver.name, |
| 6708 |
| 6709 | config: Config{ |
| 6710 | MinVersion: ver.version, |
| 6711 | MaxVersion: ver.version, |
| 6712 | TokenBindingParams: []byte{}, |
| 6713 | TokenBindingVersion: maxTokenBindingVersion, |
| 6714 | }, |
| 6715 | flags: []string{ |
| 6716 | "-token-binding-params", |
| 6717 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 6718 | }, |
| 6719 | shouldFail: true, |
| 6720 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 6721 | }) |
| 6722 | testCases = append(testCases, testCase{ |
| 6723 | testType: serverTest, |
| 6724 | name: "TokenBinding-Server-RepeatedParam" + ver.name, |
| 6725 |
| 6726 | config: Config{ |
| 6727 | MinVersion: ver.version, |
| 6728 | MaxVersion: ver.version, |
| 6729 | TokenBindingParams: []byte{0, 1, 2, 2}, |
| 6730 | TokenBindingVersion: maxTokenBindingVersion, |
| 6731 | }, |
| 6732 | expectTokenBinding: true, |
| 6733 | expectedTokenBindingParam: 2, |
| 6734 | flags: []string{ |
| 6735 | "-token-binding-params", |
| 6736 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 6737 | "-expect-token-binding-param", |
| 6738 | "2", |
| 6739 | }, |
| 6740 | }) |
| 6741 | testCases = append(testCases, testCase{ |
| 6742 | testType: clientTest, |
| 6743 | name: "TokenBinding-Client-" + ver.name, |
| 6744 |
| 6745 | config: Config{ |
| 6746 | MinVersion: ver.version, |
| 6747 | MaxVersion: ver.version, |
| 6748 | TokenBindingParams: []byte{2}, |
| 6749 | TokenBindingVersion: maxTokenBindingVersion, |
| 6750 | ExpectTokenBindingParams: []byte{0, 1, 2}, |
| 6751 | }, |
| 6752 | flags: []string{ |
| 6753 | "-token-binding-params", |
| 6754 | base64.StdEncoding.EncodeToString([]byte{0, 1, 2}), |
| 6755 | "-expect-token-binding-param", |
| 6756 | "2", |
| 6757 | }, |
| 6758 | }) |
| 6759 | testCases = append(testCases, testCase{ |
| 6760 | testType: clientTest, |
| 6761 | name: "TokenBinding-Client-Unexpected-" + ver.name, |
| 6762 |
| 6763 | config: Config{ |
| 6764 | MinVersion: ver.version, |
| 6765 | MaxVersion: ver.version, |
| 6766 | TokenBindingParams: []byte{2}, |
| 6767 | TokenBindingVersion: maxTokenBindingVersion, |
| 6768 | }, |
| 6769 | shouldFail: true, |
| 6770 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 6771 | }) |
| 6772 | testCases = append(testCases, testCase{ |
| 6773 | testType: clientTest, |
| 6774 | name: "TokenBinding-Client-ExtraParams-" + ver.name, |
| 6775 |
| 6776 | config: Config{ |
| 6777 | MinVersion: ver.version, |
| 6778 | MaxVersion: ver.version, |
| 6779 | TokenBindingParams: []byte{2, 1}, |
| 6780 | TokenBindingVersion: maxTokenBindingVersion, |
| 6781 | ExpectTokenBindingParams: []byte{0, 1, 2}, |
| 6782 | }, |
| 6783 | flags: []string{ |
| 6784 | "-token-binding-params", |
| 6785 | base64.StdEncoding.EncodeToString([]byte{0, 1, 2}), |
| 6786 | "-expect-token-binding-param", |
| 6787 | "2", |
| 6788 | }, |
| 6789 | shouldFail: true, |
| 6790 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 6791 | }) |
| 6792 | testCases = append(testCases, testCase{ |
| 6793 | testType: clientTest, |
| 6794 | name: "TokenBinding-Client-NoParams-" + ver.name, |
| 6795 |
| 6796 | config: Config{ |
| 6797 | MinVersion: ver.version, |
| 6798 | MaxVersion: ver.version, |
| 6799 | TokenBindingParams: []byte{}, |
| 6800 | TokenBindingVersion: maxTokenBindingVersion, |
| 6801 | ExpectTokenBindingParams: []byte{0, 1, 2}, |
| 6802 | }, |
| 6803 | flags: []string{ |
| 6804 | "-token-binding-params", |
| 6805 | base64.StdEncoding.EncodeToString([]byte{0, 1, 2}), |
| 6806 | "-expect-token-binding-param", |
| 6807 | "2", |
| 6808 | }, |
| 6809 | shouldFail: true, |
| 6810 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 6811 | }) |
| 6812 | testCases = append(testCases, testCase{ |
| 6813 | testType: clientTest, |
| 6814 | name: "TokenBinding-Client-WrongParam-" + ver.name, |
| 6815 |
| 6816 | config: Config{ |
| 6817 | MinVersion: ver.version, |
| 6818 | MaxVersion: ver.version, |
| 6819 | TokenBindingParams: []byte{3}, |
| 6820 | TokenBindingVersion: maxTokenBindingVersion, |
| 6821 | ExpectTokenBindingParams: []byte{0, 1, 2}, |
| 6822 | }, |
| 6823 | flags: []string{ |
| 6824 | "-token-binding-params", |
| 6825 | base64.StdEncoding.EncodeToString([]byte{0, 1, 2}), |
| 6826 | "-expect-token-binding-param", |
| 6827 | "2", |
| 6828 | }, |
| 6829 | shouldFail: true, |
| 6830 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 6831 | }) |
| 6832 | testCases = append(testCases, testCase{ |
| 6833 | testType: clientTest, |
| 6834 | name: "TokenBinding-Client-OldVersion-" + ver.name, |
| 6835 |
| 6836 | config: Config{ |
| 6837 | MinVersion: ver.version, |
| 6838 | MaxVersion: ver.version, |
| 6839 | TokenBindingParams: []byte{2}, |
| 6840 | TokenBindingVersion: minTokenBindingVersion - 1, |
| 6841 | ExpectTokenBindingParams: []byte{0, 1, 2}, |
| 6842 | }, |
| 6843 | flags: []string{ |
| 6844 | "-token-binding-params", |
| 6845 | base64.StdEncoding.EncodeToString([]byte{0, 1, 2}), |
| 6846 | }, |
| 6847 | }) |
| 6848 | testCases = append(testCases, testCase{ |
| 6849 | testType: clientTest, |
| 6850 | name: "TokenBinding-Client-MinVersion-" + ver.name, |
| 6851 |
| 6852 | config: Config{ |
| 6853 | MinVersion: ver.version, |
| 6854 | MaxVersion: ver.version, |
| 6855 | TokenBindingParams: []byte{2}, |
| 6856 | TokenBindingVersion: minTokenBindingVersion, |
| 6857 | ExpectTokenBindingParams: []byte{0, 1, 2}, |
| 6858 | }, |
| 6859 | flags: []string{ |
| 6860 | "-token-binding-params", |
| 6861 | base64.StdEncoding.EncodeToString([]byte{0, 1, 2}), |
| 6862 | "-expect-token-binding-param", |
| 6863 | "2", |
| 6864 | }, |
| 6865 | }) |
| 6866 | testCases = append(testCases, testCase{ |
| 6867 | testType: clientTest, |
| 6868 | name: "TokenBinding-Client-VersionTooNew-" + ver.name, |
| 6869 |
| 6870 | config: Config{ |
| 6871 | MinVersion: ver.version, |
| 6872 | MaxVersion: ver.version, |
| 6873 | TokenBindingParams: []byte{2}, |
| 6874 | TokenBindingVersion: maxTokenBindingVersion + 1, |
| 6875 | ExpectTokenBindingParams: []byte{0, 1, 2}, |
| 6876 | }, |
| 6877 | flags: []string{ |
| 6878 | "-token-binding-params", |
| 6879 | base64.StdEncoding.EncodeToString([]byte{0, 1, 2}), |
| 6880 | }, |
| 6881 | shouldFail: true, |
| 6882 | expectedError: "ERROR_PARSING_EXTENSION", |
| 6883 | }) |
| 6884 | if ver.version < VersionTLS13 { |
| 6885 | testCases = append(testCases, testCase{ |
| 6886 | testType: clientTest, |
| 6887 | name: "TokenBinding-Client-NoEMS-" + ver.name, |
| 6888 |
| 6889 | config: Config{ |
| 6890 | MinVersion: ver.version, |
| 6891 | MaxVersion: ver.version, |
| 6892 | TokenBindingParams: []byte{2}, |
| 6893 | TokenBindingVersion: maxTokenBindingVersion, |
| 6894 | ExpectTokenBindingParams: []byte{2, 1, 0}, |
| 6895 | Bugs: ProtocolBugs{ |
| 6896 | NoExtendedMasterSecret: true, |
| 6897 | }, |
| 6898 | }, |
| 6899 | flags: []string{ |
| 6900 | "-token-binding-params", |
| 6901 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 6902 | }, |
| 6903 | shouldFail: true, |
| 6904 | expectedError: ":NEGOTIATED_TB_WITHOUT_EMS_OR_RI:", |
| 6905 | }) |
| 6906 | testCases = append(testCases, testCase{ |
| 6907 | testType: serverTest, |
| 6908 | name: "TokenBinding-Server-NoEMS-" + ver.name, |
| 6909 |
| 6910 | config: Config{ |
| 6911 | MinVersion: ver.version, |
| 6912 | MaxVersion: ver.version, |
| 6913 | TokenBindingParams: []byte{0, 1, 2}, |
| 6914 | TokenBindingVersion: maxTokenBindingVersion, |
| 6915 | Bugs: ProtocolBugs{ |
| 6916 | NoExtendedMasterSecret: true, |
| 6917 | }, |
| 6918 | }, |
| 6919 | flags: []string{ |
| 6920 | "-token-binding-params", |
| 6921 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 6922 | }, |
| 6923 | shouldFail: true, |
| 6924 | expectedError: ":NEGOTIATED_TB_WITHOUT_EMS_OR_RI:", |
| 6925 | }) |
| 6926 | testCases = append(testCases, testCase{ |
| 6927 | testType: clientTest, |
| 6928 | name: "TokenBinding-Client-NoRI-" + ver.name, |
| 6929 |
| 6930 | config: Config{ |
| 6931 | MinVersion: ver.version, |
| 6932 | MaxVersion: ver.version, |
| 6933 | TokenBindingParams: []byte{2}, |
| 6934 | TokenBindingVersion: maxTokenBindingVersion, |
| 6935 | ExpectTokenBindingParams: []byte{2, 1, 0}, |
| 6936 | Bugs: ProtocolBugs{ |
| 6937 | NoRenegotiationInfo: true, |
| 6938 | }, |
| 6939 | }, |
| 6940 | flags: []string{ |
| 6941 | "-token-binding-params", |
| 6942 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 6943 | }, |
| 6944 | shouldFail: true, |
| 6945 | expectedError: ":NEGOTIATED_TB_WITHOUT_EMS_OR_RI:", |
| 6946 | }) |
| 6947 | testCases = append(testCases, testCase{ |
| 6948 | testType: serverTest, |
| 6949 | name: "TokenBinding-Server-NoRI-" + ver.name, |
| 6950 |
| 6951 | config: Config{ |
| 6952 | MinVersion: ver.version, |
| 6953 | MaxVersion: ver.version, |
| 6954 | TokenBindingParams: []byte{0, 1, 2}, |
| 6955 | TokenBindingVersion: maxTokenBindingVersion, |
| 6956 | Bugs: ProtocolBugs{ |
| 6957 | NoRenegotiationInfo: true, |
| 6958 | }, |
| 6959 | }, |
| 6960 | flags: []string{ |
| 6961 | "-token-binding-params", |
| 6962 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 6963 | }, |
| 6964 | shouldFail: true, |
| 6965 | expectedError: ":NEGOTIATED_TB_WITHOUT_EMS_OR_RI:", |
| 6966 | }) |
| 6967 | } else { |
| 6968 | testCases = append(testCases, testCase{ |
| 6969 | testType: clientTest, |
| 6970 | name: "TokenBinding-WithEarlyDataFails-" + ver.name, |
| 6971 | config: Config{ |
| 6972 | MinVersion: ver.version, |
| 6973 | MaxVersion: ver.version, |
| 6974 | TokenBindingParams: []byte{2}, |
| 6975 | TokenBindingVersion: maxTokenBindingVersion, |
| 6976 | ExpectTokenBindingParams: []byte{2, 1, 0}, |
| 6977 | MaxEarlyDataSize: 16384, |
| 6978 | }, |
| 6979 | resumeSession: true, |
| 6980 | flags: []string{ |
| 6981 | "-enable-early-data", |
| 6982 | "-expect-ticket-supports-early-data", |
| 6983 | "-token-binding-params", |
| 6984 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 6985 | }, |
| 6986 | shouldFail: true, |
| 6987 | expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:", |
| 6988 | }) |
| 6989 | testCases = append(testCases, testCase{ |
| 6990 | testType: serverTest, |
| 6991 | name: "TokenBinding-EarlyDataRejected-" + ver.name, |
| 6992 | config: Config{ |
| 6993 | MinVersion: ver.version, |
| 6994 | MaxVersion: ver.version, |
| 6995 | TokenBindingParams: []byte{0, 1, 2}, |
| 6996 | TokenBindingVersion: maxTokenBindingVersion, |
| 6997 | MaxEarlyDataSize: 16384, |
| 6998 | }, |
| 6999 | resumeSession: true, |
| 7000 | expectTokenBinding: true, |
| 7001 | expectedTokenBindingParam: 2, |
| 7002 | flags: []string{ |
| 7003 | "-enable-early-data", |
| 7004 | "-expect-ticket-supports-early-data", |
| 7005 | "-token-binding-params", |
| 7006 | base64.StdEncoding.EncodeToString([]byte{2, 1, 0}), |
| 7007 | "-expect-reject-early-data", |
| 7008 | "-on-retry-expect-early-data-reason", "token_binding", |
| 7009 | }, |
| 7010 | }) |
| 7011 | } |
| 7012 |
| 7013 | // Test QUIC transport params |
| 7014 | if ver.version >= VersionTLS13 { |
| 7015 | // Client sends params |
| 7016 | testCases = append(testCases, testCase{ |
| 7017 | testType: clientTest, |
| 7018 | name: "QUICTransportParams-Client-" + ver.name, |
| 7019 | config: Config{ |
| 7020 | MinVersion: ver.version, |
| 7021 | MaxVersion: ver.version, |
| 7022 | QUICTransportParams: []byte{1, 2}, |
| 7023 | }, |
| 7024 | flags: []string{ |
| 7025 | "-quic-transport-params", |
| 7026 | base64.StdEncoding.EncodeToString([]byte{3, 4}), |
| 7027 | "-expect-quic-transport-params", |
| 7028 | base64.StdEncoding.EncodeToString([]byte{1, 2}), |
| 7029 | }, |
| 7030 | expectedQUICTransportParams: []byte{3, 4}, |
| 7031 | }) |
| 7032 | // Server sends params |
| 7033 | testCases = append(testCases, testCase{ |
| 7034 | testType: serverTest, |
| 7035 | name: "QUICTransportParams-Server-" + ver.name, |
| 7036 | config: Config{ |
| 7037 | MinVersion: ver.version, |
| 7038 | MaxVersion: ver.version, |
| 7039 | QUICTransportParams: []byte{1, 2}, |
| 7040 | }, |
| 7041 | flags: []string{ |
| 7042 | "-quic-transport-params", |
| 7043 | base64.StdEncoding.EncodeToString([]byte{3, 4}), |
| 7044 | "-expect-quic-transport-params", |
| 7045 | base64.StdEncoding.EncodeToString([]byte{1, 2}), |
| 7046 | }, |
| 7047 | expectedQUICTransportParams: []byte{3, 4}, |
| 7048 | }) |
| 7049 | } else { |
| 7050 | testCases = append(testCases, testCase{ |
| 7051 | testType: clientTest, |
| 7052 | name: "QUICTransportParams-Client-NotSent-" + ver.name, |
| 7053 | config: Config{ |
| 7054 | MinVersion: ver.version, |
| 7055 | MaxVersion: ver.version, |
| 7056 | }, |
| 7057 | flags: []string{ |
| 7058 | "-max-version", |
| 7059 | strconv.Itoa(int(ver.version)), |
| 7060 | "-quic-transport-params", |
| 7061 | base64.StdEncoding.EncodeToString([]byte{3, 4}), |
| 7062 | }, |
| 7063 | }) |
| 7064 | testCases = append(testCases, testCase{ |
| 7065 | testType: clientTest, |
| 7066 | name: "QUICTransportParams-Client-Rejected-" + ver.name, |
| 7067 | config: Config{ |
| 7068 | MinVersion: ver.version, |
| 7069 | MaxVersion: ver.version, |
| 7070 | QUICTransportParams: []byte{1, 2}, |
| 7071 | }, |
| 7072 | flags: []string{ |
| 7073 | "-quic-transport-params", |
| 7074 | base64.StdEncoding.EncodeToString([]byte{3, 4}), |
| 7075 | }, |
| 7076 | shouldFail: true, |
| 7077 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 7078 | }) |
| 7079 | testCases = append(testCases, testCase{ |
| 7080 | testType: serverTest, |
| 7081 | name: "QUICTransportParams-Server-Rejected-" + ver.name, |
| 7082 | config: Config{ |
| 7083 | MinVersion: ver.version, |
| 7084 | MaxVersion: ver.version, |
| 7085 | QUICTransportParams: []byte{1, 2}, |
| 7086 | }, |
| 7087 | flags: []string{ |
| 7088 | "-expect-quic-transport-params", |
| 7089 | base64.StdEncoding.EncodeToString([]byte{1, 2}), |
| 7090 | }, |
| 7091 | shouldFail: true, |
| 7092 | expectedError: "QUIC transport params mismatch", |
| 7093 | }) |
| 7094 | testCases = append(testCases, testCase{ |
| 7095 | testType: serverTest, |
| 7096 | name: "QUICTransportParams-OldServerIgnores-" + ver.name, |
| 7097 | config: Config{ |
| 7098 | MaxVersion: VersionTLS13, |
| 7099 | QUICTransportParams: []byte{1, 2}, |
| 7100 | }, |
| 7101 | flags: []string{ |
| 7102 | "-min-version", ver.shimFlag(tls), |
| 7103 | "-max-version", ver.shimFlag(tls), |
| 7104 | }, |
| 7105 | }) |
| 7106 | } |
| 7107 |
| 7108 | // Test ticket behavior. |
| 7109 |
| 7110 | // Resume with a corrupt ticket. |
| 7111 | testCases = append(testCases, testCase{ |
| 7112 | testType: serverTest, |
| 7113 | name: "CorruptTicket-" + ver.name, |
| 7114 | config: Config{ |
| 7115 | MaxVersion: ver.version, |
| 7116 | Bugs: ProtocolBugs{ |
| 7117 | FilterTicket: func(in []byte) ([]byte, error) { |
| 7118 | in[len(in)-1] ^= 1 |
| 7119 | return in, nil |
| 7120 | }, |
| 7121 | }, |
| 7122 | }, |
| 7123 | resumeSession: true, |
| 7124 | expectResumeRejected: true, |
| 7125 | }) |
| 7126 | // Test the ticket callback, with and without renewal. |
| 7127 | testCases = append(testCases, testCase{ |
| 7128 | testType: serverTest, |
| 7129 | name: "TicketCallback-" + ver.name, |
| 7130 | config: Config{ |
| 7131 | MaxVersion: ver.version, |
| 7132 | }, |
| 7133 | resumeSession: true, |
| 7134 | flags: []string{"-use-ticket-callback"}, |
| 7135 | }) |
| 7136 | testCases = append(testCases, testCase{ |
| 7137 | testType: serverTest, |
| 7138 | name: "TicketCallback-Renew-" + ver.name, |
| 7139 | config: Config{ |
| 7140 | MaxVersion: ver.version, |
| 7141 | Bugs: ProtocolBugs{ |
| 7142 | ExpectNewTicket: true, |
| 7143 | }, |
| 7144 | }, |
| 7145 | flags: []string{"-use-ticket-callback", "-renew-ticket"}, |
| 7146 | resumeSession: true, |
| 7147 | }) |
| 7148 |
| 7149 | // Test that the ticket callback is only called once when everything before |
| 7150 | // it in the ClientHello is asynchronous. This corrupts the ticket so |
| 7151 | // certificate selection callbacks run. |
| 7152 | testCases = append(testCases, testCase{ |
| 7153 | testType: serverTest, |
| 7154 | name: "TicketCallback-SingleCall-" + ver.name, |
| 7155 | config: Config{ |
| 7156 | MaxVersion: ver.version, |
| 7157 | Bugs: ProtocolBugs{ |
| 7158 | FilterTicket: func(in []byte) ([]byte, error) { |
| 7159 | in[len(in)-1] ^= 1 |
| 7160 | return in, nil |
| 7161 | }, |
| 7162 | }, |
| 7163 | }, |
| 7164 | resumeSession: true, |
| 7165 | expectResumeRejected: true, |
| 7166 | flags: []string{ |
| 7167 | "-use-ticket-callback", |
| 7168 | "-async", |
| 7169 | }, |
| 7170 | }) |
| 7171 |
| 7172 | // Resume with various lengths of ticket session id. |
| 7173 | if ver.version < VersionTLS13 { |
| 7174 | testCases = append(testCases, testCase{ |
| 7175 | testType: serverTest, |
| 7176 | name: "TicketSessionIDLength-0-" + ver.name, |
| 7177 | config: Config{ |
| 7178 | MaxVersion: ver.version, |
| 7179 | Bugs: ProtocolBugs{ |
| 7180 | EmptyTicketSessionID: true, |
| 7181 | }, |
| 7182 | }, |
| 7183 | resumeSession: true, |
| 7184 | }) |
| 7185 | testCases = append(testCases, testCase{ |
| 7186 | testType: serverTest, |
| 7187 | name: "TicketSessionIDLength-16-" + ver.name, |
| 7188 | config: Config{ |
| 7189 | MaxVersion: ver.version, |
| 7190 | Bugs: ProtocolBugs{ |
| 7191 | TicketSessionIDLength: 16, |
| 7192 | }, |
| 7193 | }, |
| 7194 | resumeSession: true, |
| 7195 | }) |
| 7196 | testCases = append(testCases, testCase{ |
| 7197 | testType: serverTest, |
| 7198 | name: "TicketSessionIDLength-32-" + ver.name, |
| 7199 | config: Config{ |
| 7200 | MaxVersion: ver.version, |
| 7201 | Bugs: ProtocolBugs{ |
| 7202 | TicketSessionIDLength: 32, |
| 7203 | }, |
| 7204 | }, |
| 7205 | resumeSession: true, |
| 7206 | }) |
| 7207 | testCases = append(testCases, testCase{ |
| 7208 | testType: serverTest, |
| 7209 | name: "TicketSessionIDLength-33-" + ver.name, |
| 7210 | config: Config{ |
| 7211 | MaxVersion: ver.version, |
| 7212 | Bugs: ProtocolBugs{ |
| 7213 | TicketSessionIDLength: 33, |
| 7214 | }, |
| 7215 | }, |
| 7216 | resumeSession: true, |
| 7217 | shouldFail: true, |
| 7218 | // The maximum session ID length is 32. |
| 7219 | expectedError: ":DECODE_ERROR:", |
| 7220 | }) |
| 7221 | } |
| 7222 |
| 7223 | // Basic DTLS-SRTP tests. Include fake profiles to ensure they |
| 7224 | // are ignored. |
| 7225 | if ver.hasDTLS { |
| 7226 | testCases = append(testCases, testCase{ |
| 7227 | protocol: dtls, |
| 7228 | name: "SRTP-Client-" + ver.name, |
| 7229 | config: Config{ |
| 7230 | MaxVersion: ver.version, |
| 7231 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 7232 | }, |
| 7233 | flags: []string{ |
| 7234 | "-srtp-profiles", |
| 7235 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 7236 | }, |
| 7237 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 7238 | }) |
| 7239 | testCases = append(testCases, testCase{ |
| 7240 | protocol: dtls, |
| 7241 | testType: serverTest, |
| 7242 | name: "SRTP-Server-" + ver.name, |
| 7243 | config: Config{ |
| 7244 | MaxVersion: ver.version, |
| 7245 | SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42}, |
| 7246 | }, |
| 7247 | flags: []string{ |
| 7248 | "-srtp-profiles", |
| 7249 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 7250 | }, |
| 7251 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 7252 | }) |
| 7253 | // Test that the MKI is ignored. |
| 7254 | testCases = append(testCases, testCase{ |
| 7255 | protocol: dtls, |
| 7256 | testType: serverTest, |
| 7257 | name: "SRTP-Server-IgnoreMKI-" + ver.name, |
| 7258 | config: Config{ |
| 7259 | MaxVersion: ver.version, |
| 7260 | SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80}, |
| 7261 | Bugs: ProtocolBugs{ |
| 7262 | SRTPMasterKeyIdentifer: "bogus", |
| 7263 | }, |
| 7264 | }, |
| 7265 | flags: []string{ |
| 7266 | "-srtp-profiles", |
| 7267 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 7268 | }, |
| 7269 | expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80, |
| 7270 | }) |
| 7271 | // Test that SRTP isn't negotiated on the server if there were |
| 7272 | // no matching profiles. |
| 7273 | testCases = append(testCases, testCase{ |
| 7274 | protocol: dtls, |
| 7275 | testType: serverTest, |
| 7276 | name: "SRTP-Server-NoMatch-" + ver.name, |
| 7277 | config: Config{ |
| 7278 | MaxVersion: ver.version, |
| 7279 | SRTPProtectionProfiles: []uint16{100, 101, 102}, |
| 7280 | }, |
| 7281 | flags: []string{ |
| 7282 | "-srtp-profiles", |
| 7283 | "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32", |
| 7284 | }, |
| 7285 | expectedSRTPProtectionProfile: 0, |
| 7286 | }) |
| 7287 | // Test that the server returning an invalid SRTP profile is |
| 7288 | // flagged as an error by the client. |
| 7289 | testCases = append(testCases, testCase{ |
| 7290 | protocol: dtls, |
| 7291 | name: "SRTP-Client-NoMatch-" + ver.name, |
| 7292 | config: Config{ |
| 7293 | MaxVersion: ver.version, |
| 7294 | Bugs: ProtocolBugs{ |
| 7295 | SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32, |
| 7296 | }, |
| 7297 | }, |
| 7298 | flags: []string{ |
| 7299 | "-srtp-profiles", |
| 7300 | "SRTP_AES128_CM_SHA1_80", |
| 7301 | }, |
| 7302 | shouldFail: true, |
| 7303 | expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:", |
| 7304 | }) |
| 7305 | } |
| 7306 |
| 7307 | // Test SCT list. |
| 7308 | testCases = append(testCases, testCase{ |
| 7309 | name: "SignedCertificateTimestampList-Client-" + ver.name, |
| 7310 | testType: clientTest, |
| 7311 | config: Config{ |
| 7312 | MaxVersion: ver.version, |
| 7313 | }, |
| 7314 | flags: []string{ |
| 7315 | "-enable-signed-cert-timestamps", |
| 7316 | "-expect-signed-cert-timestamps", |
| 7317 | base64.StdEncoding.EncodeToString(testSCTList), |
| 7318 | }, |
| 7319 | resumeSession: true, |
| 7320 | }) |
| 7321 |
| 7322 | var differentSCTList []byte |
| 7323 | differentSCTList = append(differentSCTList, testSCTList...) |
| 7324 | differentSCTList[len(differentSCTList)-1] ^= 1 |
| 7325 |
| 7326 | // The SCT extension did not specify that it must only be sent on resumption as it |
| 7327 | // should have, so test that we tolerate but ignore it. |
| 7328 | testCases = append(testCases, testCase{ |
| 7329 | name: "SendSCTListOnResume-" + ver.name, |
| 7330 | config: Config{ |
| 7331 | MaxVersion: ver.version, |
| 7332 | Bugs: ProtocolBugs{ |
| 7333 | SendSCTListOnResume: differentSCTList, |
| 7334 | }, |
| 7335 | }, |
| 7336 | flags: []string{ |
| 7337 | "-enable-signed-cert-timestamps", |
| 7338 | "-expect-signed-cert-timestamps", |
| 7339 | base64.StdEncoding.EncodeToString(testSCTList), |
| 7340 | }, |
| 7341 | resumeSession: true, |
| 7342 | }) |
| 7343 |
| 7344 | testCases = append(testCases, testCase{ |
| 7345 | name: "SignedCertificateTimestampList-Server-" + ver.name, |
| 7346 | testType: serverTest, |
| 7347 | config: Config{ |
| 7348 | MaxVersion: ver.version, |
| 7349 | }, |
| 7350 | flags: []string{ |
| 7351 | "-signed-cert-timestamps", |
| 7352 | base64.StdEncoding.EncodeToString(testSCTList), |
| 7353 | }, |
| 7354 | expectedSCTList: testSCTList, |
| 7355 | resumeSession: true, |
| 7356 | }) |
| 7357 |
| 7358 | emptySCTListCert := *testCerts[0].cert |
| 7359 | emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0} |
| 7360 |
| 7361 | // Test empty SCT list. |
| 7362 | testCases = append(testCases, testCase{ |
| 7363 | name: "SignedCertificateTimestampListEmpty-Client-" + ver.name, |
| 7364 | testType: clientTest, |
| 7365 | config: Config{ |
| 7366 | MaxVersion: ver.version, |
| 7367 | Certificates: []Certificate{emptySCTListCert}, |
| 7368 | }, |
| 7369 | flags: []string{ |
| 7370 | "-enable-signed-cert-timestamps", |
| 7371 | }, |
| 7372 | shouldFail: true, |
| 7373 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 7374 | }) |
| 7375 |
| 7376 | emptySCTCert := *testCerts[0].cert |
| 7377 | emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0} |
| 7378 |
| 7379 | // Test empty SCT in non-empty list. |
| 7380 | testCases = append(testCases, testCase{ |
| 7381 | name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name, |
| 7382 | testType: clientTest, |
| 7383 | config: Config{ |
| 7384 | MaxVersion: ver.version, |
| 7385 | Certificates: []Certificate{emptySCTCert}, |
| 7386 | }, |
| 7387 | flags: []string{ |
| 7388 | "-enable-signed-cert-timestamps", |
| 7389 | }, |
| 7390 | shouldFail: true, |
| 7391 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 7392 | }) |
| 7393 |
| 7394 | // Test that certificate-related extensions are not sent unsolicited. |
| 7395 | testCases = append(testCases, testCase{ |
| 7396 | testType: serverTest, |
| 7397 | name: "UnsolicitedCertificateExtensions-" + ver.name, |
| 7398 | config: Config{ |
| 7399 | MaxVersion: ver.version, |
| 7400 | Bugs: ProtocolBugs{ |
| 7401 | NoOCSPStapling: true, |
| 7402 | NoSignedCertificateTimestamps: true, |
| 7403 | }, |
| 7404 | }, |
| 7405 | flags: []string{ |
| 7406 | "-ocsp-response", |
| 7407 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 7408 | "-signed-cert-timestamps", |
| 7409 | base64.StdEncoding.EncodeToString(testSCTList), |
| 7410 | }, |
| 7411 | }) |
| 7412 | } |
| 7413 |
| 7414 | testCases = append(testCases, testCase{ |
| 7415 | testType: clientTest, |
| 7416 | name: "ClientHelloPadding", |
| 7417 | config: Config{ |
| 7418 | Bugs: ProtocolBugs{ |
| 7419 | RequireClientHelloSize: 512, |
| 7420 | }, |
| 7421 | }, |
| 7422 | // This hostname just needs to be long enough to push the |
| 7423 | // ClientHello into F5's danger zone between 256 and 511 bytes |
| 7424 | // long. |
| 7425 | flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"}, |
| 7426 | }) |
| 7427 |
| 7428 | // Test that illegal extensions in TLS 1.3 are rejected by the client if |
| 7429 | // in ServerHello. |
| 7430 | testCases = append(testCases, testCase{ |
| 7431 | name: "NPN-Forbidden-TLS13", |
| 7432 | config: Config{ |
| 7433 | MaxVersion: VersionTLS13, |
| 7434 | NextProtos: []string{"foo"}, |
| 7435 | Bugs: ProtocolBugs{ |
| 7436 | NegotiateNPNAtAllVersions: true, |
| 7437 | }, |
| 7438 | }, |
| 7439 | flags: []string{"-select-next-proto", "foo"}, |
| 7440 | shouldFail: true, |
| 7441 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 7442 | }) |
| 7443 | testCases = append(testCases, testCase{ |
| 7444 | name: "EMS-Forbidden-TLS13", |
| 7445 | config: Config{ |
| 7446 | MaxVersion: VersionTLS13, |
| 7447 | Bugs: ProtocolBugs{ |
| 7448 | NegotiateEMSAtAllVersions: true, |
| 7449 | }, |
| 7450 | }, |
| 7451 | shouldFail: true, |
| 7452 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 7453 | }) |
| 7454 | testCases = append(testCases, testCase{ |
| 7455 | name: "RenegotiationInfo-Forbidden-TLS13", |
| 7456 | config: Config{ |
| 7457 | MaxVersion: VersionTLS13, |
| 7458 | Bugs: ProtocolBugs{ |
| 7459 | NegotiateRenegotiationInfoAtAllVersions: true, |
| 7460 | }, |
| 7461 | }, |
| 7462 | shouldFail: true, |
| 7463 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 7464 | }) |
| 7465 | testCases = append(testCases, testCase{ |
| 7466 | name: "Ticket-Forbidden-TLS13", |
| 7467 | config: Config{ |
| 7468 | MaxVersion: VersionTLS12, |
| 7469 | }, |
| 7470 | resumeConfig: &Config{ |
| 7471 | MaxVersion: VersionTLS13, |
| 7472 | Bugs: ProtocolBugs{ |
| 7473 | AdvertiseTicketExtension: true, |
| 7474 | }, |
| 7475 | }, |
| 7476 | resumeSession: true, |
| 7477 | shouldFail: true, |
| 7478 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 7479 | }) |
| 7480 |
| 7481 | // Test that illegal extensions in TLS 1.3 are declined by the server if |
| 7482 | // offered in ClientHello. The runner's server will fail if this occurs, |
| 7483 | // so we exercise the offering path. (EMS and Renegotiation Info are |
| 7484 | // implicit in every test.) |
| 7485 | testCases = append(testCases, testCase{ |
| 7486 | testType: serverTest, |
| 7487 | name: "NPN-Declined-TLS13", |
| 7488 | config: Config{ |
| 7489 | MaxVersion: VersionTLS13, |
| 7490 | NextProtos: []string{"bar"}, |
| 7491 | }, |
| 7492 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 7493 | }) |
| 7494 |
| 7495 | // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is |
| 7496 | // tolerated. |
| 7497 | testCases = append(testCases, testCase{ |
| 7498 | name: "SendOCSPResponseOnResume-TLS12", |
| 7499 | config: Config{ |
| 7500 | MaxVersion: VersionTLS12, |
| 7501 | Bugs: ProtocolBugs{ |
| 7502 | SendOCSPResponseOnResume: []byte("bogus"), |
| 7503 | }, |
| 7504 | }, |
| 7505 | flags: []string{ |
| 7506 | "-enable-ocsp-stapling", |
| 7507 | "-expect-ocsp-response", |
| 7508 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 7509 | }, |
| 7510 | resumeSession: true, |
| 7511 | }) |
| 7512 |
| 7513 | testCases = append(testCases, testCase{ |
| 7514 | name: "SendUnsolicitedOCSPOnCertificate-TLS13", |
| 7515 | config: Config{ |
| 7516 | MaxVersion: VersionTLS13, |
| 7517 | Bugs: ProtocolBugs{ |
| 7518 | SendExtensionOnCertificate: testOCSPExtension, |
| 7519 | }, |
| 7520 | }, |
| 7521 | shouldFail: true, |
| 7522 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7523 | }) |
| 7524 |
| 7525 | testCases = append(testCases, testCase{ |
| 7526 | name: "SendUnsolicitedSCTOnCertificate-TLS13", |
| 7527 | config: Config{ |
| 7528 | MaxVersion: VersionTLS13, |
| 7529 | Bugs: ProtocolBugs{ |
| 7530 | SendExtensionOnCertificate: testSCTExtension, |
| 7531 | }, |
| 7532 | }, |
| 7533 | shouldFail: true, |
| 7534 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7535 | }) |
| 7536 |
| 7537 | // Test that extensions on client certificates are never accepted. |
| 7538 | testCases = append(testCases, testCase{ |
| 7539 | name: "SendExtensionOnClientCertificate-TLS13", |
| 7540 | testType: serverTest, |
| 7541 | config: Config{ |
| 7542 | MaxVersion: VersionTLS13, |
| 7543 | Certificates: []Certificate{rsaCertificate}, |
| 7544 | Bugs: ProtocolBugs{ |
| 7545 | SendExtensionOnCertificate: testOCSPExtension, |
| 7546 | }, |
| 7547 | }, |
| 7548 | flags: []string{ |
| 7549 | "-enable-ocsp-stapling", |
| 7550 | "-require-any-client-certificate", |
| 7551 | }, |
| 7552 | shouldFail: true, |
| 7553 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7554 | }) |
| 7555 |
| 7556 | testCases = append(testCases, testCase{ |
| 7557 | name: "SendUnknownExtensionOnCertificate-TLS13", |
| 7558 | config: Config{ |
| 7559 | MaxVersion: VersionTLS13, |
| 7560 | Bugs: ProtocolBugs{ |
| 7561 | SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0}, |
| 7562 | }, |
| 7563 | }, |
| 7564 | shouldFail: true, |
| 7565 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 7566 | }) |
| 7567 |
| 7568 | // Test that extensions on intermediates are allowed but ignored. |
| 7569 | testCases = append(testCases, testCase{ |
| 7570 | name: "IgnoreExtensionsOnIntermediates-TLS13", |
| 7571 | config: Config{ |
| 7572 | MaxVersion: VersionTLS13, |
| 7573 | Certificates: []Certificate{rsaChainCertificate}, |
| 7574 | Bugs: ProtocolBugs{ |
| 7575 | // Send different values on the intermediate. This tests |
| 7576 | // the intermediate's extensions do not override the |
| 7577 | // leaf's. |
| 7578 | SendOCSPOnIntermediates: testOCSPResponse2, |
| 7579 | SendSCTOnIntermediates: testSCTList2, |
| 7580 | }, |
| 7581 | }, |
| 7582 | flags: []string{ |
| 7583 | "-enable-ocsp-stapling", |
| 7584 | "-expect-ocsp-response", |
| 7585 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 7586 | "-enable-signed-cert-timestamps", |
| 7587 | "-expect-signed-cert-timestamps", |
| 7588 | base64.StdEncoding.EncodeToString(testSCTList), |
| 7589 | }, |
| 7590 | resumeSession: true, |
| 7591 | }) |
| 7592 |
| 7593 | // Test that extensions are not sent on intermediates when configured |
| 7594 | // only for a leaf. |
| 7595 | testCases = append(testCases, testCase{ |
| 7596 | testType: serverTest, |
| 7597 | name: "SendNoExtensionsOnIntermediate-TLS13", |
| 7598 | config: Config{ |
| 7599 | MaxVersion: VersionTLS13, |
| 7600 | Bugs: ProtocolBugs{ |
| 7601 | ExpectNoExtensionsOnIntermediate: true, |
| 7602 | }, |
| 7603 | }, |
| 7604 | flags: []string{ |
| 7605 | "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile), |
| 7606 | "-key-file", path.Join(*resourceDir, rsaChainKeyFile), |
| 7607 | "-ocsp-response", |
| 7608 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 7609 | "-signed-cert-timestamps", |
| 7610 | base64.StdEncoding.EncodeToString(testSCTList), |
| 7611 | }, |
| 7612 | }) |
| 7613 |
| 7614 | // Test that extensions are not sent on client certificates. |
| 7615 | testCases = append(testCases, testCase{ |
| 7616 | name: "SendNoClientCertificateExtensions-TLS13", |
| 7617 | config: Config{ |
| 7618 | MaxVersion: VersionTLS13, |
| 7619 | ClientAuth: RequireAnyClientCert, |
| 7620 | }, |
| 7621 | flags: []string{ |
| 7622 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 7623 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 7624 | "-ocsp-response", |
| 7625 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 7626 | "-signed-cert-timestamps", |
| 7627 | base64.StdEncoding.EncodeToString(testSCTList), |
| 7628 | }, |
| 7629 | }) |
| 7630 |
| 7631 | testCases = append(testCases, testCase{ |
| 7632 | name: "SendDuplicateExtensionsOnCerts-TLS13", |
| 7633 | config: Config{ |
| 7634 | MaxVersion: VersionTLS13, |
| 7635 | Bugs: ProtocolBugs{ |
| 7636 | SendDuplicateCertExtensions: true, |
| 7637 | }, |
| 7638 | }, |
| 7639 | flags: []string{ |
| 7640 | "-enable-ocsp-stapling", |
| 7641 | "-enable-signed-cert-timestamps", |
| 7642 | }, |
| 7643 | resumeSession: true, |
| 7644 | shouldFail: true, |
| 7645 | expectedError: ":DUPLICATE_EXTENSION:", |
| 7646 | }) |
| 7647 |
| 7648 | testCases = append(testCases, testCase{ |
| 7649 | name: "SignedCertificateTimestampListInvalid-Server", |
| 7650 | testType: serverTest, |
| 7651 | flags: []string{ |
| 7652 | "-signed-cert-timestamps", |
| 7653 | base64.StdEncoding.EncodeToString([]byte{0, 0}), |
| 7654 | }, |
| 7655 | shouldFail: true, |
| 7656 | expectedError: ":INVALID_SCT_LIST:", |
| 7657 | }) |
| 7658 | } |
| 7659 |
| 7660 | func addResumptionVersionTests() { |
| 7661 | for _, sessionVers := range tlsVersions { |
| 7662 | for _, resumeVers := range tlsVersions { |
| 7663 | protocols := []protocol{tls} |
| 7664 | if sessionVers.hasDTLS && resumeVers.hasDTLS { |
| 7665 | protocols = append(protocols, dtls) |
| 7666 | } |
| 7667 | for _, protocol := range protocols { |
| 7668 | suffix := "-" + sessionVers.name + "-" + resumeVers.name |
| 7669 | if protocol == dtls { |
| 7670 | suffix += "-DTLS" |
| 7671 | } |
| 7672 |
| 7673 | if sessionVers.version == resumeVers.version { |
| 7674 | testCases = append(testCases, testCase{ |
| 7675 | protocol: protocol, |
| 7676 | name: "Resume-Client" + suffix, |
| 7677 | resumeSession: true, |
| 7678 | config: Config{ |
| 7679 | MaxVersion: sessionVers.version, |
| 7680 | Bugs: ProtocolBugs{ |
| 7681 | ExpectNoTLS13PSK: sessionVers.version < VersionTLS13, |
| 7682 | }, |
| 7683 | }, |
| 7684 | expectedVersion: sessionVers.version, |
| 7685 | expectedResumeVersion: resumeVers.version, |
| 7686 | }) |
| 7687 | } else { |
| 7688 | testCases = append(testCases, testCase{ |
| 7689 | protocol: protocol, |
| 7690 | name: "Resume-Client-Mismatch" + suffix, |
| 7691 | resumeSession: true, |
| 7692 | config: Config{ |
| 7693 | MaxVersion: sessionVers.version, |
| 7694 | }, |
| 7695 | expectedVersion: sessionVers.version, |
| 7696 | resumeConfig: &Config{ |
| 7697 | MaxVersion: resumeVers.version, |
| 7698 | Bugs: ProtocolBugs{ |
| 7699 | AcceptAnySession: true, |
| 7700 | }, |
| 7701 | }, |
| 7702 | expectedResumeVersion: resumeVers.version, |
| 7703 | shouldFail: true, |
| 7704 | expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:", |
| 7705 | }) |
| 7706 | } |
| 7707 |
| 7708 | testCases = append(testCases, testCase{ |
| 7709 | protocol: protocol, |
| 7710 | name: "Resume-Client-NoResume" + suffix, |
| 7711 | resumeSession: true, |
| 7712 | config: Config{ |
| 7713 | MaxVersion: sessionVers.version, |
| 7714 | }, |
| 7715 | expectedVersion: sessionVers.version, |
| 7716 | resumeConfig: &Config{ |
| 7717 | MaxVersion: resumeVers.version, |
| 7718 | }, |
| 7719 | newSessionsOnResume: true, |
| 7720 | expectResumeRejected: true, |
| 7721 | expectedResumeVersion: resumeVers.version, |
| 7722 | }) |
| 7723 |
| 7724 | testCases = append(testCases, testCase{ |
| 7725 | protocol: protocol, |
| 7726 | testType: serverTest, |
| 7727 | name: "Resume-Server" + suffix, |
| 7728 | resumeSession: true, |
| 7729 | config: Config{ |
| 7730 | MaxVersion: sessionVers.version, |
| 7731 | }, |
| 7732 | expectedVersion: sessionVers.version, |
| 7733 | expectResumeRejected: sessionVers != resumeVers, |
| 7734 | resumeConfig: &Config{ |
| 7735 | MaxVersion: resumeVers.version, |
| 7736 | Bugs: ProtocolBugs{ |
| 7737 | SendBothTickets: true, |
| 7738 | }, |
| 7739 | }, |
| 7740 | expectedResumeVersion: resumeVers.version, |
| 7741 | }) |
| 7742 |
| 7743 | // Repeat the test using session IDs, rather than tickets. |
| 7744 | if sessionVers.version < VersionTLS13 && resumeVers.version < VersionTLS13 { |
| 7745 | testCases = append(testCases, testCase{ |
| 7746 | protocol: protocol, |
| 7747 | testType: serverTest, |
| 7748 | name: "Resume-Server-NoTickets" + suffix, |
| 7749 | resumeSession: true, |
| 7750 | config: Config{ |
| 7751 | MaxVersion: sessionVers.version, |
| 7752 | SessionTicketsDisabled: true, |
| 7753 | }, |
| 7754 | expectedVersion: sessionVers.version, |
| 7755 | expectResumeRejected: sessionVers != resumeVers, |
| 7756 | resumeConfig: &Config{ |
| 7757 | MaxVersion: resumeVers.version, |
| 7758 | SessionTicketsDisabled: true, |
| 7759 | }, |
| 7760 | expectedResumeVersion: resumeVers.version, |
| 7761 | }) |
| 7762 | } |
| 7763 | } |
| 7764 | } |
| 7765 | } |
| 7766 |
| 7767 | // Make sure shim ticket mutations are functional. |
| 7768 | testCases = append(testCases, testCase{ |
| 7769 | testType: serverTest, |
| 7770 | name: "ShimTicketRewritable", |
| 7771 | resumeSession: true, |
| 7772 | config: Config{ |
| 7773 | MaxVersion: VersionTLS12, |
| 7774 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7775 | Bugs: ProtocolBugs{ |
| 7776 | FilterTicket: func(in []byte) ([]byte, error) { |
| 7777 | in, err := SetShimTicketVersion(in, VersionTLS12) |
| 7778 | if err != nil { |
| 7779 | return nil, err |
| 7780 | } |
| 7781 | return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) |
| 7782 | }, |
| 7783 | }, |
| 7784 | }, |
| 7785 | flags: []string{ |
| 7786 | "-ticket-key", |
| 7787 | base64.StdEncoding.EncodeToString(TestShimTicketKey), |
| 7788 | }, |
| 7789 | }) |
| 7790 |
| 7791 | // Resumptions are declined if the version does not match. |
| 7792 | testCases = append(testCases, testCase{ |
| 7793 | testType: serverTest, |
| 7794 | name: "Resume-Server-DeclineCrossVersion", |
| 7795 | resumeSession: true, |
| 7796 | config: Config{ |
| 7797 | MaxVersion: VersionTLS12, |
| 7798 | Bugs: ProtocolBugs{ |
| 7799 | ExpectNewTicket: true, |
| 7800 | FilterTicket: func(in []byte) ([]byte, error) { |
| 7801 | return SetShimTicketVersion(in, VersionTLS13) |
| 7802 | }, |
| 7803 | }, |
| 7804 | }, |
| 7805 | flags: []string{ |
| 7806 | "-ticket-key", |
| 7807 | base64.StdEncoding.EncodeToString(TestShimTicketKey), |
| 7808 | }, |
| 7809 | expectResumeRejected: true, |
| 7810 | }) |
| 7811 |
| 7812 | testCases = append(testCases, testCase{ |
| 7813 | testType: serverTest, |
| 7814 | name: "Resume-Server-DeclineCrossVersion-TLS13", |
| 7815 | resumeSession: true, |
| 7816 | config: Config{ |
| 7817 | MaxVersion: VersionTLS13, |
| 7818 | Bugs: ProtocolBugs{ |
| 7819 | FilterTicket: func(in []byte) ([]byte, error) { |
| 7820 | return SetShimTicketVersion(in, VersionTLS12) |
| 7821 | }, |
| 7822 | }, |
| 7823 | }, |
| 7824 | flags: []string{ |
| 7825 | "-ticket-key", |
| 7826 | base64.StdEncoding.EncodeToString(TestShimTicketKey), |
| 7827 | }, |
| 7828 | expectResumeRejected: true, |
| 7829 | }) |
| 7830 |
| 7831 | // Resumptions are declined if the cipher is invalid or disabled. |
| 7832 | testCases = append(testCases, testCase{ |
| 7833 | testType: serverTest, |
| 7834 | name: "Resume-Server-DeclineBadCipher", |
| 7835 | resumeSession: true, |
| 7836 | config: Config{ |
| 7837 | MaxVersion: VersionTLS12, |
| 7838 | Bugs: ProtocolBugs{ |
| 7839 | ExpectNewTicket: true, |
| 7840 | FilterTicket: func(in []byte) ([]byte, error) { |
| 7841 | return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256) |
| 7842 | }, |
| 7843 | }, |
| 7844 | }, |
| 7845 | flags: []string{ |
| 7846 | "-ticket-key", |
| 7847 | base64.StdEncoding.EncodeToString(TestShimTicketKey), |
| 7848 | }, |
| 7849 | expectResumeRejected: true, |
| 7850 | }) |
| 7851 |
| 7852 | testCases = append(testCases, testCase{ |
| 7853 | testType: serverTest, |
| 7854 | name: "Resume-Server-DeclineBadCipher-2", |
| 7855 | resumeSession: true, |
| 7856 | config: Config{ |
| 7857 | MaxVersion: VersionTLS12, |
| 7858 | Bugs: ProtocolBugs{ |
| 7859 | ExpectNewTicket: true, |
| 7860 | FilterTicket: func(in []byte) ([]byte, error) { |
| 7861 | return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) |
| 7862 | }, |
| 7863 | }, |
| 7864 | }, |
| 7865 | flags: []string{ |
| 7866 | "-cipher", "AES128", |
| 7867 | "-ticket-key", |
| 7868 | base64.StdEncoding.EncodeToString(TestShimTicketKey), |
| 7869 | }, |
| 7870 | expectResumeRejected: true, |
| 7871 | }) |
| 7872 |
| 7873 | // Sessions are not resumed if they do not use the preferred cipher. |
| 7874 | testCases = append(testCases, testCase{ |
| 7875 | testType: serverTest, |
| 7876 | name: "Resume-Server-CipherNotPreferred", |
| 7877 | resumeSession: true, |
| 7878 | config: Config{ |
| 7879 | MaxVersion: VersionTLS12, |
| 7880 | Bugs: ProtocolBugs{ |
| 7881 | ExpectNewTicket: true, |
| 7882 | FilterTicket: func(in []byte) ([]byte, error) { |
| 7883 | return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) |
| 7884 | }, |
| 7885 | }, |
| 7886 | }, |
| 7887 | flags: []string{ |
| 7888 | "-ticket-key", |
| 7889 | base64.StdEncoding.EncodeToString(TestShimTicketKey), |
| 7890 | }, |
| 7891 | shouldFail: false, |
| 7892 | expectResumeRejected: true, |
| 7893 | }) |
| 7894 |
| 7895 | // TLS 1.3 allows sessions to be resumed at a different cipher if their |
| 7896 | // PRF hashes match, but BoringSSL will always decline such resumptions. |
| 7897 | testCases = append(testCases, testCase{ |
| 7898 | testType: serverTest, |
| 7899 | name: "Resume-Server-CipherNotPreferred-TLS13", |
| 7900 | resumeSession: true, |
| 7901 | config: Config{ |
| 7902 | MaxVersion: VersionTLS13, |
| 7903 | CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256}, |
| 7904 | Bugs: ProtocolBugs{ |
| 7905 | FilterTicket: func(in []byte) ([]byte, error) { |
| 7906 | // If the client (runner) offers ChaCha20-Poly1305 first, the |
| 7907 | // server (shim) always prefers it. Switch it to AES-GCM. |
| 7908 | return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256) |
| 7909 | }, |
| 7910 | }, |
| 7911 | }, |
| 7912 | flags: []string{ |
| 7913 | "-ticket-key", |
| 7914 | base64.StdEncoding.EncodeToString(TestShimTicketKey), |
| 7915 | }, |
| 7916 | shouldFail: false, |
| 7917 | expectResumeRejected: true, |
| 7918 | }) |
| 7919 |
| 7920 | // Sessions may not be resumed if they contain another version's cipher. |
| 7921 | testCases = append(testCases, testCase{ |
| 7922 | testType: serverTest, |
| 7923 | name: "Resume-Server-DeclineBadCipher-TLS13", |
| 7924 | resumeSession: true, |
| 7925 | config: Config{ |
| 7926 | MaxVersion: VersionTLS13, |
| 7927 | Bugs: ProtocolBugs{ |
| 7928 | FilterTicket: func(in []byte) ([]byte, error) { |
| 7929 | return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) |
| 7930 | }, |
| 7931 | }, |
| 7932 | }, |
| 7933 | flags: []string{ |
| 7934 | "-ticket-key", |
| 7935 | base64.StdEncoding.EncodeToString(TestShimTicketKey), |
| 7936 | }, |
| 7937 | expectResumeRejected: true, |
| 7938 | }) |
| 7939 |
| 7940 | // If the client does not offer the cipher from the session, decline to |
| 7941 | // resume. Clients are forbidden from doing this, but BoringSSL selects |
| 7942 | // the cipher first, so we only decline. |
| 7943 | testCases = append(testCases, testCase{ |
| 7944 | testType: serverTest, |
| 7945 | name: "Resume-Server-UnofferedCipher", |
| 7946 | resumeSession: true, |
| 7947 | config: Config{ |
| 7948 | MaxVersion: VersionTLS12, |
| 7949 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 7950 | }, |
| 7951 | resumeConfig: &Config{ |
| 7952 | MaxVersion: VersionTLS12, |
| 7953 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 7954 | Bugs: ProtocolBugs{ |
| 7955 | SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 7956 | }, |
| 7957 | }, |
| 7958 | expectResumeRejected: true, |
| 7959 | }) |
| 7960 |
| 7961 | // In TLS 1.3, clients may advertise a cipher list which does not |
| 7962 | // include the selected cipher. Test that we tolerate this. Servers may |
| 7963 | // resume at another cipher if the PRF matches and are not doing 0-RTT, but |
| 7964 | // BoringSSL will always decline. |
| 7965 | testCases = append(testCases, testCase{ |
| 7966 | testType: serverTest, |
| 7967 | name: "Resume-Server-UnofferedCipher-TLS13", |
| 7968 | resumeSession: true, |
| 7969 | config: Config{ |
| 7970 | MaxVersion: VersionTLS13, |
| 7971 | CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256}, |
| 7972 | }, |
| 7973 | resumeConfig: &Config{ |
| 7974 | MaxVersion: VersionTLS13, |
| 7975 | CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256}, |
| 7976 | Bugs: ProtocolBugs{ |
| 7977 | SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256}, |
| 7978 | }, |
| 7979 | }, |
| 7980 | expectResumeRejected: true, |
| 7981 | }) |
| 7982 |
| 7983 | // Sessions may not be resumed at a different cipher. |
| 7984 | testCases = append(testCases, testCase{ |
| 7985 | name: "Resume-Client-CipherMismatch", |
| 7986 | resumeSession: true, |
| 7987 | config: Config{ |
| 7988 | MaxVersion: VersionTLS12, |
| 7989 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 7990 | }, |
| 7991 | resumeConfig: &Config{ |
| 7992 | MaxVersion: VersionTLS12, |
| 7993 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 7994 | Bugs: ProtocolBugs{ |
| 7995 | SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA, |
| 7996 | }, |
| 7997 | }, |
| 7998 | shouldFail: true, |
| 7999 | expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:", |
| 8000 | }) |
| 8001 |
| 8002 | // Session resumption in TLS 1.3 may change the cipher suite if the PRF |
| 8003 | // matches. |
| 8004 | testCases = append(testCases, testCase{ |
| 8005 | name: "Resume-Client-CipherMismatch-TLS13", |
| 8006 | resumeSession: true, |
| 8007 | config: Config{ |
| 8008 | MaxVersion: VersionTLS13, |
| 8009 | CipherSuites: []uint16{TLS_AES_128_GCM_SHA256}, |
| 8010 | }, |
| 8011 | resumeConfig: &Config{ |
| 8012 | MaxVersion: VersionTLS13, |
| 8013 | CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256}, |
| 8014 | }, |
| 8015 | }) |
| 8016 |
| 8017 | // Session resumption in TLS 1.3 is forbidden if the PRF does not match. |
| 8018 | testCases = append(testCases, testCase{ |
| 8019 | name: "Resume-Client-PRFMismatch-TLS13", |
| 8020 | resumeSession: true, |
| 8021 | config: Config{ |
| 8022 | MaxVersion: VersionTLS13, |
| 8023 | CipherSuites: []uint16{TLS_AES_128_GCM_SHA256}, |
| 8024 | }, |
| 8025 | resumeConfig: &Config{ |
| 8026 | MaxVersion: VersionTLS13, |
| 8027 | CipherSuites: []uint16{TLS_AES_128_GCM_SHA256}, |
| 8028 | Bugs: ProtocolBugs{ |
| 8029 | SendCipherSuite: TLS_AES_256_GCM_SHA384, |
| 8030 | }, |
| 8031 | }, |
| 8032 | shouldFail: true, |
| 8033 | expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:", |
| 8034 | }) |
| 8035 |
| 8036 | for _, secondBinder := range []bool{false, true} { |
| 8037 | var suffix string |
| 8038 | var defaultCurves []CurveID |
| 8039 | if secondBinder { |
| 8040 | suffix = "-SecondBinder" |
| 8041 | // Force a HelloRetryRequest by predicting an empty curve list. |
| 8042 | defaultCurves = []CurveID{} |
| 8043 | } |
| 8044 |
| 8045 | testCases = append(testCases, testCase{ |
| 8046 | testType: serverTest, |
| 8047 | name: "Resume-Server-BinderWrongLength" + suffix, |
| 8048 | resumeSession: true, |
| 8049 | config: Config{ |
| 8050 | MaxVersion: VersionTLS13, |
| 8051 | DefaultCurves: defaultCurves, |
| 8052 | Bugs: ProtocolBugs{ |
| 8053 | SendShortPSKBinder: true, |
| 8054 | OnlyCorruptSecondPSKBinder: secondBinder, |
| 8055 | }, |
| 8056 | }, |
| 8057 | shouldFail: true, |
| 8058 | expectedLocalError: "remote error: error decrypting message", |
| 8059 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 8060 | }) |
| 8061 |
| 8062 | testCases = append(testCases, testCase{ |
| 8063 | testType: serverTest, |
| 8064 | name: "Resume-Server-NoPSKBinder" + suffix, |
| 8065 | resumeSession: true, |
| 8066 | config: Config{ |
| 8067 | MaxVersion: VersionTLS13, |
| 8068 | DefaultCurves: defaultCurves, |
| 8069 | Bugs: ProtocolBugs{ |
| 8070 | SendNoPSKBinder: true, |
| 8071 | OnlyCorruptSecondPSKBinder: secondBinder, |
| 8072 | }, |
| 8073 | }, |
| 8074 | shouldFail: true, |
| 8075 | expectedLocalError: "remote error: error decoding message", |
| 8076 | expectedError: ":DECODE_ERROR:", |
| 8077 | }) |
| 8078 |
| 8079 | testCases = append(testCases, testCase{ |
| 8080 | testType: serverTest, |
| 8081 | name: "Resume-Server-ExtraPSKBinder" + suffix, |
| 8082 | resumeSession: true, |
| 8083 | config: Config{ |
| 8084 | MaxVersion: VersionTLS13, |
| 8085 | DefaultCurves: defaultCurves, |
| 8086 | Bugs: ProtocolBugs{ |
| 8087 | SendExtraPSKBinder: true, |
| 8088 | OnlyCorruptSecondPSKBinder: secondBinder, |
| 8089 | }, |
| 8090 | }, |
| 8091 | shouldFail: true, |
| 8092 | expectedLocalError: "remote error: illegal parameter", |
| 8093 | expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:", |
| 8094 | }) |
| 8095 |
| 8096 | testCases = append(testCases, testCase{ |
| 8097 | testType: serverTest, |
| 8098 | name: "Resume-Server-ExtraIdentityNoBinder" + suffix, |
| 8099 | resumeSession: true, |
| 8100 | config: Config{ |
| 8101 | MaxVersion: VersionTLS13, |
| 8102 | DefaultCurves: defaultCurves, |
| 8103 | Bugs: ProtocolBugs{ |
| 8104 | ExtraPSKIdentity: true, |
| 8105 | OnlyCorruptSecondPSKBinder: secondBinder, |
| 8106 | }, |
| 8107 | }, |
| 8108 | shouldFail: true, |
| 8109 | expectedLocalError: "remote error: illegal parameter", |
| 8110 | expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:", |
| 8111 | }) |
| 8112 |
| 8113 | testCases = append(testCases, testCase{ |
| 8114 | testType: serverTest, |
| 8115 | name: "Resume-Server-InvalidPSKBinder" + suffix, |
| 8116 | resumeSession: true, |
| 8117 | config: Config{ |
| 8118 | MaxVersion: VersionTLS13, |
| 8119 | DefaultCurves: defaultCurves, |
| 8120 | Bugs: ProtocolBugs{ |
| 8121 | SendInvalidPSKBinder: true, |
| 8122 | OnlyCorruptSecondPSKBinder: secondBinder, |
| 8123 | }, |
| 8124 | }, |
| 8125 | shouldFail: true, |
| 8126 | expectedLocalError: "remote error: error decrypting message", |
| 8127 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 8128 | }) |
| 8129 |
| 8130 | testCases = append(testCases, testCase{ |
| 8131 | testType: serverTest, |
| 8132 | name: "Resume-Server-PSKBinderFirstExtension" + suffix, |
| 8133 | resumeSession: true, |
| 8134 | config: Config{ |
| 8135 | MaxVersion: VersionTLS13, |
| 8136 | DefaultCurves: defaultCurves, |
| 8137 | Bugs: ProtocolBugs{ |
| 8138 | PSKBinderFirst: true, |
| 8139 | OnlyCorruptSecondPSKBinder: secondBinder, |
| 8140 | }, |
| 8141 | }, |
| 8142 | shouldFail: true, |
| 8143 | expectedLocalError: "remote error: illegal parameter", |
| 8144 | expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:", |
| 8145 | }) |
| 8146 | } |
| 8147 |
| 8148 | testCases = append(testCases, testCase{ |
| 8149 | testType: serverTest, |
| 8150 | name: "Resume-Server-OmitPSKsOnSecondClientHello", |
| 8151 | resumeSession: true, |
| 8152 | config: Config{ |
| 8153 | MaxVersion: VersionTLS13, |
| 8154 | DefaultCurves: []CurveID{}, |
| 8155 | Bugs: ProtocolBugs{ |
| 8156 | OmitPSKsOnSecondClientHello: true, |
| 8157 | }, |
| 8158 | }, |
| 8159 | shouldFail: true, |
| 8160 | expectedLocalError: "remote error: illegal parameter", |
| 8161 | expectedError: ":INCONSISTENT_CLIENT_HELLO:", |
| 8162 | }) |
| 8163 | } |
| 8164 |
| 8165 | func addRenegotiationTests() { |
| 8166 | // Servers cannot renegotiate. |
| 8167 | testCases = append(testCases, testCase{ |
| 8168 | testType: serverTest, |
| 8169 | name: "Renegotiate-Server-Forbidden", |
| 8170 | config: Config{ |
| 8171 | MaxVersion: VersionTLS12, |
| 8172 | }, |
| 8173 | renegotiate: 1, |
| 8174 | shouldFail: true, |
| 8175 | expectedError: ":NO_RENEGOTIATION:", |
| 8176 | expectedLocalError: "remote error: no renegotiation", |
| 8177 | }) |
| 8178 | // The server shouldn't echo the renegotiation extension unless |
| 8179 | // requested by the client. |
| 8180 | testCases = append(testCases, testCase{ |
| 8181 | testType: serverTest, |
| 8182 | name: "Renegotiate-Server-NoExt", |
| 8183 | config: Config{ |
| 8184 | MaxVersion: VersionTLS12, |
| 8185 | Bugs: ProtocolBugs{ |
| 8186 | NoRenegotiationInfo: true, |
| 8187 | RequireRenegotiationInfo: true, |
| 8188 | }, |
| 8189 | }, |
| 8190 | shouldFail: true, |
| 8191 | expectedLocalError: "renegotiation extension missing", |
| 8192 | }) |
| 8193 | // The renegotiation SCSV should be sufficient for the server to echo |
| 8194 | // the extension. |
| 8195 | testCases = append(testCases, testCase{ |
| 8196 | testType: serverTest, |
| 8197 | name: "Renegotiate-Server-NoExt-SCSV", |
| 8198 | config: Config{ |
| 8199 | MaxVersion: VersionTLS12, |
| 8200 | Bugs: ProtocolBugs{ |
| 8201 | NoRenegotiationInfo: true, |
| 8202 | SendRenegotiationSCSV: true, |
| 8203 | RequireRenegotiationInfo: true, |
| 8204 | }, |
| 8205 | }, |
| 8206 | }) |
| 8207 | testCases = append(testCases, testCase{ |
| 8208 | name: "Renegotiate-Client", |
| 8209 | config: Config{ |
| 8210 | MaxVersion: VersionTLS12, |
| 8211 | Bugs: ProtocolBugs{ |
| 8212 | FailIfResumeOnRenego: true, |
| 8213 | }, |
| 8214 | }, |
| 8215 | renegotiate: 1, |
| 8216 | // Test renegotiation after both an initial and resumption |
| 8217 | // handshake. |
| 8218 | resumeSession: true, |
| 8219 | flags: []string{ |
| 8220 | "-renegotiate-freely", |
| 8221 | "-expect-total-renegotiations", "1", |
| 8222 | "-expect-secure-renegotiation", |
| 8223 | }, |
| 8224 | }) |
| 8225 | testCases = append(testCases, testCase{ |
| 8226 | name: "Renegotiate-Client-TLS12", |
| 8227 | config: Config{ |
| 8228 | MaxVersion: VersionTLS12, |
| 8229 | Bugs: ProtocolBugs{ |
| 8230 | FailIfResumeOnRenego: true, |
| 8231 | }, |
| 8232 | }, |
| 8233 | renegotiate: 1, |
| 8234 | // Test renegotiation after both an initial and resumption |
| 8235 | // handshake. |
| 8236 | resumeSession: true, |
| 8237 | flags: []string{ |
| 8238 | "-renegotiate-freely", |
| 8239 | "-expect-total-renegotiations", "1", |
| 8240 | "-expect-secure-renegotiation", |
| 8241 | }, |
| 8242 | }) |
| 8243 | testCases = append(testCases, testCase{ |
| 8244 | name: "Renegotiate-Client-EmptyExt", |
| 8245 | renegotiate: 1, |
| 8246 | config: Config{ |
| 8247 | MaxVersion: VersionTLS12, |
| 8248 | Bugs: ProtocolBugs{ |
| 8249 | EmptyRenegotiationInfo: true, |
| 8250 | }, |
| 8251 | }, |
| 8252 | flags: []string{"-renegotiate-freely"}, |
| 8253 | shouldFail: true, |
| 8254 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 8255 | expectedLocalError: "handshake failure", |
| 8256 | }) |
| 8257 | testCases = append(testCases, testCase{ |
| 8258 | name: "Renegotiate-Client-BadExt", |
| 8259 | renegotiate: 1, |
| 8260 | config: Config{ |
| 8261 | MaxVersion: VersionTLS12, |
| 8262 | Bugs: ProtocolBugs{ |
| 8263 | BadRenegotiationInfo: true, |
| 8264 | }, |
| 8265 | }, |
| 8266 | flags: []string{"-renegotiate-freely"}, |
| 8267 | shouldFail: true, |
| 8268 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 8269 | expectedLocalError: "handshake failure", |
| 8270 | }) |
| 8271 | testCases = append(testCases, testCase{ |
| 8272 | name: "Renegotiate-Client-BadExt2", |
| 8273 | renegotiate: 1, |
| 8274 | config: Config{ |
| 8275 | MaxVersion: VersionTLS12, |
| 8276 | Bugs: ProtocolBugs{ |
| 8277 | BadRenegotiationInfoEnd: true, |
| 8278 | }, |
| 8279 | }, |
| 8280 | flags: []string{"-renegotiate-freely"}, |
| 8281 | shouldFail: true, |
| 8282 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 8283 | expectedLocalError: "handshake failure", |
| 8284 | }) |
| 8285 | testCases = append(testCases, testCase{ |
| 8286 | name: "Renegotiate-Client-Downgrade", |
| 8287 | renegotiate: 1, |
| 8288 | config: Config{ |
| 8289 | MaxVersion: VersionTLS12, |
| 8290 | Bugs: ProtocolBugs{ |
| 8291 | NoRenegotiationInfoAfterInitial: true, |
| 8292 | }, |
| 8293 | }, |
| 8294 | flags: []string{"-renegotiate-freely"}, |
| 8295 | shouldFail: true, |
| 8296 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 8297 | expectedLocalError: "handshake failure", |
| 8298 | }) |
| 8299 | testCases = append(testCases, testCase{ |
| 8300 | name: "Renegotiate-Client-Upgrade", |
| 8301 | renegotiate: 1, |
| 8302 | config: Config{ |
| 8303 | MaxVersion: VersionTLS12, |
| 8304 | Bugs: ProtocolBugs{ |
| 8305 | NoRenegotiationInfoInInitial: true, |
| 8306 | }, |
| 8307 | }, |
| 8308 | flags: []string{"-renegotiate-freely"}, |
| 8309 | shouldFail: true, |
| 8310 | expectedError: ":RENEGOTIATION_MISMATCH:", |
| 8311 | expectedLocalError: "handshake failure", |
| 8312 | }) |
| 8313 | testCases = append(testCases, testCase{ |
| 8314 | name: "Renegotiate-Client-NoExt-Allowed", |
| 8315 | renegotiate: 1, |
| 8316 | config: Config{ |
| 8317 | MaxVersion: VersionTLS12, |
| 8318 | Bugs: ProtocolBugs{ |
| 8319 | NoRenegotiationInfo: true, |
| 8320 | }, |
| 8321 | }, |
| 8322 | flags: []string{ |
| 8323 | "-renegotiate-freely", |
| 8324 | "-expect-total-renegotiations", "1", |
| 8325 | "-expect-no-secure-renegotiation", |
| 8326 | }, |
| 8327 | }) |
| 8328 |
| 8329 | // Test that the server may switch ciphers on renegotiation without |
| 8330 | // problems. |
| 8331 | testCases = append(testCases, testCase{ |
| 8332 | name: "Renegotiate-Client-SwitchCiphers", |
| 8333 | renegotiate: 1, |
| 8334 | config: Config{ |
| 8335 | MaxVersion: VersionTLS12, |
| 8336 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
| 8337 | }, |
| 8338 | renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 8339 | flags: []string{ |
| 8340 | "-renegotiate-freely", |
| 8341 | "-expect-total-renegotiations", "1", |
| 8342 | }, |
| 8343 | }) |
| 8344 | testCases = append(testCases, testCase{ |
| 8345 | name: "Renegotiate-Client-SwitchCiphers2", |
| 8346 | renegotiate: 1, |
| 8347 | config: Config{ |
| 8348 | MaxVersion: VersionTLS12, |
| 8349 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 8350 | }, |
| 8351 | renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
| 8352 | flags: []string{ |
| 8353 | "-renegotiate-freely", |
| 8354 | "-expect-total-renegotiations", "1", |
| 8355 | }, |
| 8356 | }) |
| 8357 |
| 8358 | // Test that the server may not switch versions on renegotiation. |
| 8359 | testCases = append(testCases, testCase{ |
| 8360 | name: "Renegotiate-Client-SwitchVersion", |
| 8361 | config: Config{ |
| 8362 | MaxVersion: VersionTLS12, |
| 8363 | // Pick a cipher which exists at both versions. |
| 8364 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 8365 | Bugs: ProtocolBugs{ |
| 8366 | NegotiateVersionOnRenego: VersionTLS11, |
| 8367 | // Avoid failing early at the record layer. |
| 8368 | SendRecordVersion: VersionTLS12, |
| 8369 | }, |
| 8370 | }, |
| 8371 | renegotiate: 1, |
| 8372 | flags: []string{ |
| 8373 | "-renegotiate-freely", |
| 8374 | "-expect-total-renegotiations", "1", |
| 8375 | }, |
| 8376 | shouldFail: true, |
| 8377 | expectedError: ":WRONG_SSL_VERSION:", |
| 8378 | }) |
| 8379 |
| 8380 | testCases = append(testCases, testCase{ |
| 8381 | name: "Renegotiate-SameClientVersion", |
| 8382 | renegotiate: 1, |
| 8383 | config: Config{ |
| 8384 | MaxVersion: VersionTLS10, |
| 8385 | Bugs: ProtocolBugs{ |
| 8386 | RequireSameRenegoClientVersion: true, |
| 8387 | }, |
| 8388 | }, |
| 8389 | flags: []string{ |
| 8390 | "-renegotiate-freely", |
| 8391 | "-expect-total-renegotiations", "1", |
| 8392 | }, |
| 8393 | }) |
| 8394 | testCases = append(testCases, testCase{ |
| 8395 | name: "Renegotiate-FalseStart", |
| 8396 | renegotiate: 1, |
| 8397 | config: Config{ |
| 8398 | MaxVersion: VersionTLS12, |
| 8399 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 8400 | NextProtos: []string{"foo"}, |
| 8401 | }, |
| 8402 | flags: []string{ |
| 8403 | "-false-start", |
| 8404 | "-select-next-proto", "foo", |
| 8405 | "-renegotiate-freely", |
| 8406 | "-expect-total-renegotiations", "1", |
| 8407 | }, |
| 8408 | shimWritesFirst: true, |
| 8409 | }) |
| 8410 |
| 8411 | // Client-side renegotiation controls. |
| 8412 | testCases = append(testCases, testCase{ |
| 8413 | name: "Renegotiate-Client-Forbidden-1", |
| 8414 | config: Config{ |
| 8415 | MaxVersion: VersionTLS12, |
| 8416 | }, |
| 8417 | renegotiate: 1, |
| 8418 | shouldFail: true, |
| 8419 | expectedError: ":NO_RENEGOTIATION:", |
| 8420 | expectedLocalError: "remote error: no renegotiation", |
| 8421 | }) |
| 8422 | testCases = append(testCases, testCase{ |
| 8423 | name: "Renegotiate-Client-Once-1", |
| 8424 | config: Config{ |
| 8425 | MaxVersion: VersionTLS12, |
| 8426 | }, |
| 8427 | renegotiate: 1, |
| 8428 | flags: []string{ |
| 8429 | "-renegotiate-once", |
| 8430 | "-expect-total-renegotiations", "1", |
| 8431 | }, |
| 8432 | }) |
| 8433 | testCases = append(testCases, testCase{ |
| 8434 | name: "Renegotiate-Client-Freely-1", |
| 8435 | config: Config{ |
| 8436 | MaxVersion: VersionTLS12, |
| 8437 | }, |
| 8438 | renegotiate: 1, |
| 8439 | flags: []string{ |
| 8440 | "-renegotiate-freely", |
| 8441 | "-expect-total-renegotiations", "1", |
| 8442 | }, |
| 8443 | }) |
| 8444 | testCases = append(testCases, testCase{ |
| 8445 | name: "Renegotiate-Client-Once-2", |
| 8446 | config: Config{ |
| 8447 | MaxVersion: VersionTLS12, |
| 8448 | }, |
| 8449 | renegotiate: 2, |
| 8450 | flags: []string{"-renegotiate-once"}, |
| 8451 | shouldFail: true, |
| 8452 | expectedError: ":NO_RENEGOTIATION:", |
| 8453 | expectedLocalError: "remote error: no renegotiation", |
| 8454 | }) |
| 8455 | testCases = append(testCases, testCase{ |
| 8456 | name: "Renegotiate-Client-Freely-2", |
| 8457 | config: Config{ |
| 8458 | MaxVersion: VersionTLS12, |
| 8459 | }, |
| 8460 | renegotiate: 2, |
| 8461 | flags: []string{ |
| 8462 | "-renegotiate-freely", |
| 8463 | "-expect-total-renegotiations", "2", |
| 8464 | }, |
| 8465 | }) |
| 8466 | testCases = append(testCases, testCase{ |
| 8467 | name: "Renegotiate-Client-NoIgnore", |
| 8468 | config: Config{ |
| 8469 | MaxVersion: VersionTLS12, |
| 8470 | Bugs: ProtocolBugs{ |
| 8471 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 8472 | }, |
| 8473 | }, |
| 8474 | shouldFail: true, |
| 8475 | expectedError: ":NO_RENEGOTIATION:", |
| 8476 | }) |
| 8477 | testCases = append(testCases, testCase{ |
| 8478 | name: "Renegotiate-Client-Ignore", |
| 8479 | config: Config{ |
| 8480 | MaxVersion: VersionTLS12, |
| 8481 | Bugs: ProtocolBugs{ |
| 8482 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 8483 | }, |
| 8484 | }, |
| 8485 | flags: []string{ |
| 8486 | "-renegotiate-ignore", |
| 8487 | "-expect-total-renegotiations", "0", |
| 8488 | }, |
| 8489 | }) |
| 8490 |
| 8491 | // Renegotiation may be enabled and then disabled immediately after the |
| 8492 | // handshake. |
| 8493 | testCases = append(testCases, testCase{ |
| 8494 | name: "Renegotiate-ForbidAfterHandshake", |
| 8495 | config: Config{ |
| 8496 | MaxVersion: VersionTLS12, |
| 8497 | }, |
| 8498 | renegotiate: 1, |
| 8499 | flags: []string{"-forbid-renegotiation-after-handshake"}, |
| 8500 | shouldFail: true, |
| 8501 | expectedError: ":NO_RENEGOTIATION:", |
| 8502 | expectedLocalError: "remote error: no renegotiation", |
| 8503 | }) |
| 8504 |
| 8505 | // Renegotiation is not allowed when there is an unfinished write. |
| 8506 | testCases = append(testCases, testCase{ |
| 8507 | name: "Renegotiate-Client-UnfinishedWrite", |
| 8508 | config: Config{ |
| 8509 | MaxVersion: VersionTLS12, |
| 8510 | }, |
| 8511 | renegotiate: 1, |
| 8512 | readWithUnfinishedWrite: true, |
| 8513 | flags: []string{ |
| 8514 | "-async", |
| 8515 | "-renegotiate-freely", |
| 8516 | }, |
| 8517 | shouldFail: true, |
| 8518 | expectedError: ":NO_RENEGOTIATION:", |
| 8519 | // We do not successfully send the no_renegotiation alert in |
| 8520 | // this case. https://crbug.com/boringssl/130 |
| 8521 | }) |
| 8522 |
| 8523 | // We reject stray HelloRequests during the handshake in TLS 1.2. |
| 8524 | testCases = append(testCases, testCase{ |
| 8525 | name: "StrayHelloRequest", |
| 8526 | config: Config{ |
| 8527 | MaxVersion: VersionTLS12, |
| 8528 | Bugs: ProtocolBugs{ |
| 8529 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 8530 | }, |
| 8531 | }, |
| 8532 | shouldFail: true, |
| 8533 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 8534 | }) |
| 8535 | testCases = append(testCases, testCase{ |
| 8536 | name: "StrayHelloRequest-Packed", |
| 8537 | config: Config{ |
| 8538 | MaxVersion: VersionTLS12, |
| 8539 | Bugs: ProtocolBugs{ |
| 8540 | PackHandshakeFlight: true, |
| 8541 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 8542 | }, |
| 8543 | }, |
| 8544 | shouldFail: true, |
| 8545 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 8546 | }) |
| 8547 |
| 8548 | // Test renegotiation works if HelloRequest and server Finished come in |
| 8549 | // the same record. |
| 8550 | testCases = append(testCases, testCase{ |
| 8551 | name: "Renegotiate-Client-Packed", |
| 8552 | config: Config{ |
| 8553 | MaxVersion: VersionTLS12, |
| 8554 | Bugs: ProtocolBugs{ |
| 8555 | PackHandshakeFlight: true, |
| 8556 | PackHelloRequestWithFinished: true, |
| 8557 | }, |
| 8558 | }, |
| 8559 | renegotiate: 1, |
| 8560 | flags: []string{ |
| 8561 | "-renegotiate-freely", |
| 8562 | "-expect-total-renegotiations", "1", |
| 8563 | }, |
| 8564 | }) |
| 8565 |
| 8566 | // Renegotiation is forbidden in TLS 1.3. |
| 8567 | testCases = append(testCases, testCase{ |
| 8568 | name: "Renegotiate-Client-TLS13", |
| 8569 | config: Config{ |
| 8570 | MaxVersion: VersionTLS13, |
| 8571 | Bugs: ProtocolBugs{ |
| 8572 | SendHelloRequestBeforeEveryAppDataRecord: true, |
| 8573 | }, |
| 8574 | }, |
| 8575 | flags: []string{ |
| 8576 | "-renegotiate-freely", |
| 8577 | }, |
| 8578 | shouldFail: true, |
| 8579 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 8580 | }) |
| 8581 |
| 8582 | // Stray HelloRequests during the handshake are forbidden in TLS 1.3. |
| 8583 | testCases = append(testCases, testCase{ |
| 8584 | name: "StrayHelloRequest-TLS13", |
| 8585 | config: Config{ |
| 8586 | MaxVersion: VersionTLS13, |
| 8587 | Bugs: ProtocolBugs{ |
| 8588 | SendHelloRequestBeforeEveryHandshakeMessage: true, |
| 8589 | }, |
| 8590 | }, |
| 8591 | shouldFail: true, |
| 8592 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 8593 | }) |
| 8594 |
| 8595 | // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3 |
| 8596 | // always reads as supporting it, regardless of whether it was |
| 8597 | // negotiated. |
| 8598 | testCases = append(testCases, testCase{ |
| 8599 | name: "AlwaysReportRenegotiationInfo-TLS13", |
| 8600 | config: Config{ |
| 8601 | MaxVersion: VersionTLS13, |
| 8602 | Bugs: ProtocolBugs{ |
| 8603 | NoRenegotiationInfo: true, |
| 8604 | }, |
| 8605 | }, |
| 8606 | flags: []string{ |
| 8607 | "-expect-secure-renegotiation", |
| 8608 | }, |
| 8609 | }) |
| 8610 |
| 8611 | // Certificates may not change on renegotiation. |
| 8612 | testCases = append(testCases, testCase{ |
| 8613 | name: "Renegotiation-CertificateChange", |
| 8614 | config: Config{ |
| 8615 | MaxVersion: VersionTLS12, |
| 8616 | Certificates: []Certificate{rsaCertificate}, |
| 8617 | Bugs: ProtocolBugs{ |
| 8618 | RenegotiationCertificate: &rsaChainCertificate, |
| 8619 | }, |
| 8620 | }, |
| 8621 | renegotiate: 1, |
| 8622 | flags: []string{"-renegotiate-freely"}, |
| 8623 | shouldFail: true, |
| 8624 | expectedError: ":SERVER_CERT_CHANGED:", |
| 8625 | }) |
| 8626 | testCases = append(testCases, testCase{ |
| 8627 | name: "Renegotiation-CertificateChange-2", |
| 8628 | config: Config{ |
| 8629 | MaxVersion: VersionTLS12, |
| 8630 | Certificates: []Certificate{rsaCertificate}, |
| 8631 | Bugs: ProtocolBugs{ |
| 8632 | RenegotiationCertificate: &rsa1024Certificate, |
| 8633 | }, |
| 8634 | }, |
| 8635 | renegotiate: 1, |
| 8636 | flags: []string{"-renegotiate-freely"}, |
| 8637 | shouldFail: true, |
| 8638 | expectedError: ":SERVER_CERT_CHANGED:", |
| 8639 | }) |
| 8640 |
| 8641 | // We do not negotiate ALPN after the initial handshake. This is |
| 8642 | // error-prone and only risks bugs in consumers. |
| 8643 | testCases = append(testCases, testCase{ |
| 8644 | testType: clientTest, |
| 8645 | name: "Renegotiation-ForbidALPN", |
| 8646 | config: Config{ |
| 8647 | MaxVersion: VersionTLS12, |
| 8648 | Bugs: ProtocolBugs{ |
| 8649 | // Forcibly negotiate ALPN on both initial and |
| 8650 | // renegotiation handshakes. The test stack will |
| 8651 | // internally check the client does not offer |
| 8652 | // it. |
| 8653 | SendALPN: "foo", |
| 8654 | }, |
| 8655 | }, |
| 8656 | flags: []string{ |
| 8657 | "-advertise-alpn", "\x03foo\x03bar\x03baz", |
| 8658 | "-expect-alpn", "foo", |
| 8659 | "-renegotiate-freely", |
| 8660 | }, |
| 8661 | renegotiate: 1, |
| 8662 | shouldFail: true, |
| 8663 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 8664 | }) |
| 8665 |
| 8666 | // The server may send different stapled OCSP responses or SCT lists on |
| 8667 | // renegotiation, but BoringSSL ignores this and reports the old values. |
| 8668 | // Also test that non-fatal verify results are preserved. |
| 8669 | testCases = append(testCases, testCase{ |
| 8670 | testType: clientTest, |
| 8671 | name: "Renegotiation-ChangeAuthProperties", |
| 8672 | config: Config{ |
| 8673 | MaxVersion: VersionTLS12, |
| 8674 | Bugs: ProtocolBugs{ |
| 8675 | SendOCSPResponseOnRenegotiation: testOCSPResponse2, |
| 8676 | SendSCTListOnRenegotiation: testSCTList2, |
| 8677 | }, |
| 8678 | }, |
| 8679 | renegotiate: 1, |
| 8680 | flags: []string{ |
| 8681 | "-renegotiate-freely", |
| 8682 | "-expect-total-renegotiations", "1", |
| 8683 | "-enable-ocsp-stapling", |
| 8684 | "-expect-ocsp-response", |
| 8685 | base64.StdEncoding.EncodeToString(testOCSPResponse), |
| 8686 | "-enable-signed-cert-timestamps", |
| 8687 | "-expect-signed-cert-timestamps", |
| 8688 | base64.StdEncoding.EncodeToString(testSCTList), |
| 8689 | "-verify-fail", |
| 8690 | "-expect-verify-result", |
| 8691 | }, |
| 8692 | }) |
| 8693 | } |
| 8694 |
| 8695 | func addDTLSReplayTests() { |
| 8696 | // Test that sequence number replays are detected. |
| 8697 | testCases = append(testCases, testCase{ |
| 8698 | protocol: dtls, |
| 8699 | name: "DTLS-Replay", |
| 8700 | messageCount: 200, |
| 8701 | replayWrites: true, |
| 8702 | }) |
| 8703 |
| 8704 | // Test the incoming sequence number skipping by values larger |
| 8705 | // than the retransmit window. |
| 8706 | testCases = append(testCases, testCase{ |
| 8707 | protocol: dtls, |
| 8708 | name: "DTLS-Replay-LargeGaps", |
| 8709 | config: Config{ |
| 8710 | Bugs: ProtocolBugs{ |
| 8711 | SequenceNumberMapping: func(in uint64) uint64 { |
| 8712 | return in * 127 |
| 8713 | }, |
| 8714 | }, |
| 8715 | }, |
| 8716 | messageCount: 200, |
| 8717 | replayWrites: true, |
| 8718 | }) |
| 8719 |
| 8720 | // Test the incoming sequence number changing non-monotonically. |
| 8721 | testCases = append(testCases, testCase{ |
| 8722 | protocol: dtls, |
| 8723 | name: "DTLS-Replay-NonMonotonic", |
| 8724 | config: Config{ |
| 8725 | Bugs: ProtocolBugs{ |
| 8726 | SequenceNumberMapping: func(in uint64) uint64 { |
| 8727 | return in ^ 31 |
| 8728 | }, |
| 8729 | }, |
| 8730 | }, |
| 8731 | messageCount: 200, |
| 8732 | replayWrites: true, |
| 8733 | }) |
| 8734 | } |
| 8735 |
| 8736 | var testSignatureAlgorithms = []struct { |
| 8737 | name string |
| 8738 | id signatureAlgorithm |
| 8739 | cert testCert |
| 8740 | }{ |
| 8741 | {"RSA_PKCS1_SHA1", signatureRSAPKCS1WithSHA1, testCertRSA}, |
| 8742 | {"RSA_PKCS1_SHA256", signatureRSAPKCS1WithSHA256, testCertRSA}, |
| 8743 | {"RSA_PKCS1_SHA384", signatureRSAPKCS1WithSHA384, testCertRSA}, |
| 8744 | {"RSA_PKCS1_SHA512", signatureRSAPKCS1WithSHA512, testCertRSA}, |
| 8745 | {"ECDSA_SHA1", signatureECDSAWithSHA1, testCertECDSAP256}, |
| 8746 | // The “P256” in the following line is not a mistake. In TLS 1.2 the |
| 8747 | // hash function doesn't have to match the curve and so the same |
| 8748 | // signature algorithm works with P-224. |
| 8749 | {"ECDSA_P224_SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224}, |
| 8750 | {"ECDSA_P256_SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256}, |
| 8751 | {"ECDSA_P384_SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384}, |
| 8752 | {"ECDSA_P521_SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521}, |
| 8753 | {"RSA_PSS_SHA256", signatureRSAPSSWithSHA256, testCertRSA}, |
| 8754 | {"RSA_PSS_SHA384", signatureRSAPSSWithSHA384, testCertRSA}, |
| 8755 | {"RSA_PSS_SHA512", signatureRSAPSSWithSHA512, testCertRSA}, |
| 8756 | {"Ed25519", signatureEd25519, testCertEd25519}, |
| 8757 | // Tests for key types prior to TLS 1.2. |
| 8758 | {"RSA", 0, testCertRSA}, |
| 8759 | {"ECDSA", 0, testCertECDSAP256}, |
| 8760 | } |
| 8761 |
| 8762 | const fakeSigAlg1 signatureAlgorithm = 0x2a01 |
| 8763 | const fakeSigAlg2 signatureAlgorithm = 0xff01 |
| 8764 |
| 8765 | func addSignatureAlgorithmTests() { |
| 8766 | // Not all ciphers involve a signature. Advertise a list which gives all |
| 8767 | // versions a signing cipher. |
| 8768 | signingCiphers := []uint16{ |
| 8769 | TLS_AES_256_GCM_SHA384, |
| 8770 | TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 8771 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 8772 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 8773 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 8774 | } |
| 8775 |
| 8776 | var allAlgorithms []signatureAlgorithm |
| 8777 | for _, alg := range testSignatureAlgorithms { |
| 8778 | if alg.id != 0 { |
| 8779 | allAlgorithms = append(allAlgorithms, alg.id) |
| 8780 | } |
| 8781 | } |
| 8782 |
| 8783 | // Make sure each signature algorithm works. Include some fake values in |
| 8784 | // the list and ensure they're ignored. |
| 8785 | for _, alg := range testSignatureAlgorithms { |
| 8786 | for _, ver := range tlsVersions { |
| 8787 | if (ver.version < VersionTLS12) != (alg.id == 0) { |
| 8788 | continue |
| 8789 | } |
| 8790 |
| 8791 | var shouldSignFail, shouldVerifyFail bool |
| 8792 | // ecdsa_sha1 does not exist in TLS 1.3. |
| 8793 | if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 { |
| 8794 | shouldSignFail = true |
| 8795 | shouldVerifyFail = true |
| 8796 | } |
| 8797 | // RSA-PKCS1 does not exist in TLS 1.3. |
| 8798 | if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") { |
| 8799 | shouldSignFail = true |
| 8800 | shouldVerifyFail = true |
| 8801 | } |
| 8802 | // SHA-224 has been removed from TLS 1.3 and, in 1.3, |
| 8803 | // the curve has to match the hash size. |
| 8804 | if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 { |
| 8805 | shouldSignFail = true |
| 8806 | shouldVerifyFail = true |
| 8807 | } |
| 8808 |
| 8809 | // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them. |
| 8810 | if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 { |
| 8811 | shouldVerifyFail = true |
| 8812 | } |
| 8813 |
| 8814 | var signError, signLocalError, verifyError, verifyLocalError string |
| 8815 | if shouldSignFail { |
| 8816 | signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:" |
| 8817 | signLocalError = "remote error: handshake failure" |
| 8818 | } |
| 8819 | if shouldVerifyFail { |
| 8820 | verifyError = ":WRONG_SIGNATURE_TYPE:" |
| 8821 | verifyLocalError = "remote error" |
| 8822 | } |
| 8823 |
| 8824 | suffix := "-" + alg.name + "-" + ver.name |
| 8825 |
| 8826 | testCases = append(testCases, testCase{ |
| 8827 | name: "ClientAuth-Sign" + suffix, |
| 8828 | config: Config{ |
| 8829 | MaxVersion: ver.version, |
| 8830 | ClientAuth: RequireAnyClientCert, |
| 8831 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 8832 | fakeSigAlg1, |
| 8833 | alg.id, |
| 8834 | fakeSigAlg2, |
| 8835 | }, |
| 8836 | }, |
| 8837 | flags: []string{ |
| 8838 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 8839 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 8840 | "-enable-all-curves", |
| 8841 | "-enable-ed25519", |
| 8842 | }, |
| 8843 | shouldFail: shouldSignFail, |
| 8844 | expectedError: signError, |
| 8845 | expectedLocalError: signLocalError, |
| 8846 | expectedPeerSignatureAlgorithm: alg.id, |
| 8847 | }) |
| 8848 |
| 8849 | testCases = append(testCases, testCase{ |
| 8850 | testType: serverTest, |
| 8851 | name: "ClientAuth-Verify" + suffix, |
| 8852 | config: Config{ |
| 8853 | MaxVersion: ver.version, |
| 8854 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 8855 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 8856 | alg.id, |
| 8857 | }, |
| 8858 | Bugs: ProtocolBugs{ |
| 8859 | SkipECDSACurveCheck: shouldVerifyFail, |
| 8860 | IgnoreSignatureVersionChecks: shouldVerifyFail, |
| 8861 | // Some signature algorithms may not be advertised. |
| 8862 | IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail, |
| 8863 | }, |
| 8864 | }, |
| 8865 | flags: []string{ |
| 8866 | "-require-any-client-certificate", |
| 8867 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 8868 | "-enable-all-curves", |
| 8869 | "-enable-ed25519", |
| 8870 | }, |
| 8871 | // Resume the session to assert the peer signature |
| 8872 | // algorithm is reported on both handshakes. |
| 8873 | resumeSession: !shouldVerifyFail, |
| 8874 | shouldFail: shouldVerifyFail, |
| 8875 | expectedError: verifyError, |
| 8876 | expectedLocalError: verifyLocalError, |
| 8877 | }) |
| 8878 |
| 8879 | testCases = append(testCases, testCase{ |
| 8880 | testType: serverTest, |
| 8881 | name: "ServerAuth-Sign" + suffix, |
| 8882 | config: Config{ |
| 8883 | MaxVersion: ver.version, |
| 8884 | CipherSuites: signingCiphers, |
| 8885 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 8886 | fakeSigAlg1, |
| 8887 | alg.id, |
| 8888 | fakeSigAlg2, |
| 8889 | }, |
| 8890 | }, |
| 8891 | flags: []string{ |
| 8892 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 8893 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 8894 | "-enable-all-curves", |
| 8895 | "-enable-ed25519", |
| 8896 | }, |
| 8897 | shouldFail: shouldSignFail, |
| 8898 | expectedError: signError, |
| 8899 | expectedLocalError: signLocalError, |
| 8900 | expectedPeerSignatureAlgorithm: alg.id, |
| 8901 | }) |
| 8902 |
| 8903 | testCases = append(testCases, testCase{ |
| 8904 | name: "ServerAuth-Verify" + suffix, |
| 8905 | config: Config{ |
| 8906 | MaxVersion: ver.version, |
| 8907 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 8908 | CipherSuites: signingCiphers, |
| 8909 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 8910 | alg.id, |
| 8911 | }, |
| 8912 | Bugs: ProtocolBugs{ |
| 8913 | SkipECDSACurveCheck: shouldVerifyFail, |
| 8914 | IgnoreSignatureVersionChecks: shouldVerifyFail, |
| 8915 | // Some signature algorithms may not be advertised. |
| 8916 | IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail, |
| 8917 | }, |
| 8918 | }, |
| 8919 | flags: []string{ |
| 8920 | "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)), |
| 8921 | "-enable-all-curves", |
| 8922 | "-enable-ed25519", |
| 8923 | }, |
| 8924 | // Resume the session to assert the peer signature |
| 8925 | // algorithm is reported on both handshakes. |
| 8926 | resumeSession: !shouldVerifyFail, |
| 8927 | shouldFail: shouldVerifyFail, |
| 8928 | expectedError: verifyError, |
| 8929 | expectedLocalError: verifyLocalError, |
| 8930 | }) |
| 8931 |
| 8932 | if !shouldVerifyFail { |
| 8933 | testCases = append(testCases, testCase{ |
| 8934 | testType: serverTest, |
| 8935 | name: "ClientAuth-InvalidSignature" + suffix, |
| 8936 | config: Config{ |
| 8937 | MaxVersion: ver.version, |
| 8938 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 8939 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 8940 | alg.id, |
| 8941 | }, |
| 8942 | Bugs: ProtocolBugs{ |
| 8943 | InvalidSignature: true, |
| 8944 | }, |
| 8945 | }, |
| 8946 | flags: []string{ |
| 8947 | "-require-any-client-certificate", |
| 8948 | "-enable-all-curves", |
| 8949 | "-enable-ed25519", |
| 8950 | }, |
| 8951 | shouldFail: true, |
| 8952 | expectedError: ":BAD_SIGNATURE:", |
| 8953 | }) |
| 8954 |
| 8955 | testCases = append(testCases, testCase{ |
| 8956 | name: "ServerAuth-InvalidSignature" + suffix, |
| 8957 | config: Config{ |
| 8958 | MaxVersion: ver.version, |
| 8959 | Certificates: []Certificate{getRunnerCertificate(alg.cert)}, |
| 8960 | CipherSuites: signingCiphers, |
| 8961 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 8962 | alg.id, |
| 8963 | }, |
| 8964 | Bugs: ProtocolBugs{ |
| 8965 | InvalidSignature: true, |
| 8966 | }, |
| 8967 | }, |
| 8968 | flags: []string{ |
| 8969 | "-enable-all-curves", |
| 8970 | "-enable-ed25519", |
| 8971 | }, |
| 8972 | shouldFail: true, |
| 8973 | expectedError: ":BAD_SIGNATURE:", |
| 8974 | }) |
| 8975 | } |
| 8976 |
| 8977 | if ver.version >= VersionTLS12 && !shouldSignFail { |
| 8978 | testCases = append(testCases, testCase{ |
| 8979 | name: "ClientAuth-Sign-Negotiate" + suffix, |
| 8980 | config: Config{ |
| 8981 | MaxVersion: ver.version, |
| 8982 | ClientAuth: RequireAnyClientCert, |
| 8983 | VerifySignatureAlgorithms: allAlgorithms, |
| 8984 | }, |
| 8985 | flags: []string{ |
| 8986 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 8987 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 8988 | "-enable-all-curves", |
| 8989 | "-enable-ed25519", |
| 8990 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 8991 | }, |
| 8992 | expectedPeerSignatureAlgorithm: alg.id, |
| 8993 | }) |
| 8994 |
| 8995 | testCases = append(testCases, testCase{ |
| 8996 | testType: serverTest, |
| 8997 | name: "ServerAuth-Sign-Negotiate" + suffix, |
| 8998 | config: Config{ |
| 8999 | MaxVersion: ver.version, |
| 9000 | CipherSuites: signingCiphers, |
| 9001 | VerifySignatureAlgorithms: allAlgorithms, |
| 9002 | }, |
| 9003 | flags: []string{ |
| 9004 | "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)), |
| 9005 | "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)), |
| 9006 | "-enable-all-curves", |
| 9007 | "-enable-ed25519", |
| 9008 | "-signing-prefs", strconv.Itoa(int(alg.id)), |
| 9009 | }, |
| 9010 | expectedPeerSignatureAlgorithm: alg.id, |
| 9011 | }) |
| 9012 | } |
| 9013 | } |
| 9014 | } |
| 9015 |
| 9016 | // Test the peer's verify preferences are available. |
| 9017 | for _, ver := range tlsVersions { |
| 9018 | if ver.version < VersionTLS12 { |
| 9019 | continue |
| 9020 | } |
| 9021 | testCases = append(testCases, testCase{ |
| 9022 | name: "ClientAuth-PeerVerifyPrefs-" + ver.name, |
| 9023 | config: Config{ |
| 9024 | MaxVersion: ver.version, |
| 9025 | ClientAuth: RequireAnyClientCert, |
| 9026 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9027 | signatureRSAPSSWithSHA256, |
| 9028 | signatureEd25519, |
| 9029 | signatureECDSAWithP256AndSHA256, |
| 9030 | }, |
| 9031 | }, |
| 9032 | flags: []string{ |
| 9033 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9034 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9035 | "-expect-peer-verify-pref", strconv.Itoa(int(signatureRSAPSSWithSHA256)), |
| 9036 | "-expect-peer-verify-pref", strconv.Itoa(int(signatureEd25519)), |
| 9037 | "-expect-peer-verify-pref", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)), |
| 9038 | }, |
| 9039 | }) |
| 9040 |
| 9041 | testCases = append(testCases, testCase{ |
| 9042 | testType: serverTest, |
| 9043 | name: "ServerAuth-PeerVerifyPrefs-" + ver.name, |
| 9044 | config: Config{ |
| 9045 | MaxVersion: ver.version, |
| 9046 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9047 | signatureRSAPSSWithSHA256, |
| 9048 | signatureEd25519, |
| 9049 | signatureECDSAWithP256AndSHA256, |
| 9050 | }, |
| 9051 | }, |
| 9052 | flags: []string{ |
| 9053 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9054 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9055 | "-expect-peer-verify-pref", strconv.Itoa(int(signatureRSAPSSWithSHA256)), |
| 9056 | "-expect-peer-verify-pref", strconv.Itoa(int(signatureEd25519)), |
| 9057 | "-expect-peer-verify-pref", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)), |
| 9058 | }, |
| 9059 | }) |
| 9060 |
| 9061 | } |
| 9062 |
| 9063 | // Test that algorithm selection takes the key type into account. |
| 9064 | testCases = append(testCases, testCase{ |
| 9065 | name: "ClientAuth-SignatureType", |
| 9066 | config: Config{ |
| 9067 | ClientAuth: RequireAnyClientCert, |
| 9068 | MaxVersion: VersionTLS12, |
| 9069 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9070 | signatureECDSAWithP521AndSHA512, |
| 9071 | signatureRSAPKCS1WithSHA384, |
| 9072 | signatureECDSAWithSHA1, |
| 9073 | }, |
| 9074 | }, |
| 9075 | flags: []string{ |
| 9076 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9077 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9078 | }, |
| 9079 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
| 9080 | }) |
| 9081 |
| 9082 | testCases = append(testCases, testCase{ |
| 9083 | name: "ClientAuth-SignatureType-TLS13", |
| 9084 | config: Config{ |
| 9085 | ClientAuth: RequireAnyClientCert, |
| 9086 | MaxVersion: VersionTLS13, |
| 9087 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9088 | signatureECDSAWithP521AndSHA512, |
| 9089 | signatureRSAPKCS1WithSHA384, |
| 9090 | signatureRSAPSSWithSHA384, |
| 9091 | signatureECDSAWithSHA1, |
| 9092 | }, |
| 9093 | }, |
| 9094 | flags: []string{ |
| 9095 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9096 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9097 | }, |
| 9098 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 9099 | }) |
| 9100 |
| 9101 | testCases = append(testCases, testCase{ |
| 9102 | testType: serverTest, |
| 9103 | name: "ServerAuth-SignatureType", |
| 9104 | config: Config{ |
| 9105 | MaxVersion: VersionTLS12, |
| 9106 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 9107 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9108 | signatureECDSAWithP521AndSHA512, |
| 9109 | signatureRSAPKCS1WithSHA384, |
| 9110 | signatureECDSAWithSHA1, |
| 9111 | }, |
| 9112 | }, |
| 9113 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384, |
| 9114 | }) |
| 9115 |
| 9116 | testCases = append(testCases, testCase{ |
| 9117 | testType: serverTest, |
| 9118 | name: "ServerAuth-SignatureType-TLS13", |
| 9119 | config: Config{ |
| 9120 | MaxVersion: VersionTLS13, |
| 9121 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9122 | signatureECDSAWithP521AndSHA512, |
| 9123 | signatureRSAPKCS1WithSHA384, |
| 9124 | signatureRSAPSSWithSHA384, |
| 9125 | signatureECDSAWithSHA1, |
| 9126 | }, |
| 9127 | }, |
| 9128 | expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384, |
| 9129 | }) |
| 9130 |
| 9131 | // Test that signature verification takes the key type into account. |
| 9132 | testCases = append(testCases, testCase{ |
| 9133 | testType: serverTest, |
| 9134 | name: "Verify-ClientAuth-SignatureType", |
| 9135 | config: Config{ |
| 9136 | MaxVersion: VersionTLS12, |
| 9137 | Certificates: []Certificate{rsaCertificate}, |
| 9138 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9139 | signatureRSAPKCS1WithSHA256, |
| 9140 | }, |
| 9141 | Bugs: ProtocolBugs{ |
| 9142 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 9143 | }, |
| 9144 | }, |
| 9145 | flags: []string{ |
| 9146 | "-require-any-client-certificate", |
| 9147 | }, |
| 9148 | shouldFail: true, |
| 9149 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 9150 | }) |
| 9151 |
| 9152 | testCases = append(testCases, testCase{ |
| 9153 | testType: serverTest, |
| 9154 | name: "Verify-ClientAuth-SignatureType-TLS13", |
| 9155 | config: Config{ |
| 9156 | MaxVersion: VersionTLS13, |
| 9157 | Certificates: []Certificate{rsaCertificate}, |
| 9158 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9159 | signatureRSAPSSWithSHA256, |
| 9160 | }, |
| 9161 | Bugs: ProtocolBugs{ |
| 9162 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 9163 | }, |
| 9164 | }, |
| 9165 | flags: []string{ |
| 9166 | "-require-any-client-certificate", |
| 9167 | }, |
| 9168 | shouldFail: true, |
| 9169 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 9170 | }) |
| 9171 |
| 9172 | testCases = append(testCases, testCase{ |
| 9173 | name: "Verify-ServerAuth-SignatureType", |
| 9174 | config: Config{ |
| 9175 | MaxVersion: VersionTLS12, |
| 9176 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 9177 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9178 | signatureRSAPKCS1WithSHA256, |
| 9179 | }, |
| 9180 | Bugs: ProtocolBugs{ |
| 9181 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 9182 | }, |
| 9183 | }, |
| 9184 | shouldFail: true, |
| 9185 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 9186 | }) |
| 9187 |
| 9188 | testCases = append(testCases, testCase{ |
| 9189 | name: "Verify-ServerAuth-SignatureType-TLS13", |
| 9190 | config: Config{ |
| 9191 | MaxVersion: VersionTLS13, |
| 9192 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9193 | signatureRSAPSSWithSHA256, |
| 9194 | }, |
| 9195 | Bugs: ProtocolBugs{ |
| 9196 | SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 9197 | }, |
| 9198 | }, |
| 9199 | shouldFail: true, |
| 9200 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 9201 | }) |
| 9202 |
| 9203 | // Test that, if the ClientHello list is missing, the server falls back |
| 9204 | // to SHA-1 in TLS 1.2, but not TLS 1.3. |
| 9205 | testCases = append(testCases, testCase{ |
| 9206 | testType: serverTest, |
| 9207 | name: "ServerAuth-SHA1-Fallback-RSA", |
| 9208 | config: Config{ |
| 9209 | MaxVersion: VersionTLS12, |
| 9210 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9211 | signatureRSAPKCS1WithSHA1, |
| 9212 | }, |
| 9213 | Bugs: ProtocolBugs{ |
| 9214 | NoSignatureAlgorithms: true, |
| 9215 | }, |
| 9216 | }, |
| 9217 | flags: []string{ |
| 9218 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9219 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9220 | }, |
| 9221 | }) |
| 9222 |
| 9223 | testCases = append(testCases, testCase{ |
| 9224 | testType: serverTest, |
| 9225 | name: "ServerAuth-SHA1-Fallback-ECDSA", |
| 9226 | config: Config{ |
| 9227 | MaxVersion: VersionTLS12, |
| 9228 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9229 | signatureECDSAWithSHA1, |
| 9230 | }, |
| 9231 | Bugs: ProtocolBugs{ |
| 9232 | NoSignatureAlgorithms: true, |
| 9233 | }, |
| 9234 | }, |
| 9235 | flags: []string{ |
| 9236 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 9237 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 9238 | }, |
| 9239 | }) |
| 9240 |
| 9241 | testCases = append(testCases, testCase{ |
| 9242 | testType: serverTest, |
| 9243 | name: "ServerAuth-NoFallback-TLS13", |
| 9244 | config: Config{ |
| 9245 | MaxVersion: VersionTLS13, |
| 9246 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9247 | signatureRSAPKCS1WithSHA1, |
| 9248 | }, |
| 9249 | Bugs: ProtocolBugs{ |
| 9250 | NoSignatureAlgorithms: true, |
| 9251 | }, |
| 9252 | }, |
| 9253 | shouldFail: true, |
| 9254 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 9255 | }) |
| 9256 |
| 9257 | // The CertificateRequest list, however, may never be omitted. It is a |
| 9258 | // syntax error for it to be empty. |
| 9259 | testCases = append(testCases, testCase{ |
| 9260 | name: "ClientAuth-NoFallback-RSA", |
| 9261 | config: Config{ |
| 9262 | MaxVersion: VersionTLS12, |
| 9263 | ClientAuth: RequireAnyClientCert, |
| 9264 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9265 | signatureRSAPKCS1WithSHA1, |
| 9266 | }, |
| 9267 | Bugs: ProtocolBugs{ |
| 9268 | NoSignatureAlgorithms: true, |
| 9269 | }, |
| 9270 | }, |
| 9271 | flags: []string{ |
| 9272 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9273 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9274 | }, |
| 9275 | shouldFail: true, |
| 9276 | expectedError: ":DECODE_ERROR:", |
| 9277 | expectedLocalError: "remote error: error decoding message", |
| 9278 | }) |
| 9279 |
| 9280 | testCases = append(testCases, testCase{ |
| 9281 | name: "ClientAuth-NoFallback-ECDSA", |
| 9282 | config: Config{ |
| 9283 | MaxVersion: VersionTLS12, |
| 9284 | ClientAuth: RequireAnyClientCert, |
| 9285 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9286 | signatureECDSAWithSHA1, |
| 9287 | }, |
| 9288 | Bugs: ProtocolBugs{ |
| 9289 | NoSignatureAlgorithms: true, |
| 9290 | }, |
| 9291 | }, |
| 9292 | flags: []string{ |
| 9293 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 9294 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 9295 | }, |
| 9296 | shouldFail: true, |
| 9297 | expectedError: ":DECODE_ERROR:", |
| 9298 | expectedLocalError: "remote error: error decoding message", |
| 9299 | }) |
| 9300 |
| 9301 | testCases = append(testCases, testCase{ |
| 9302 | name: "ClientAuth-NoFallback-TLS13", |
| 9303 | config: Config{ |
| 9304 | MaxVersion: VersionTLS13, |
| 9305 | ClientAuth: RequireAnyClientCert, |
| 9306 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9307 | signatureRSAPKCS1WithSHA1, |
| 9308 | }, |
| 9309 | Bugs: ProtocolBugs{ |
| 9310 | NoSignatureAlgorithms: true, |
| 9311 | }, |
| 9312 | }, |
| 9313 | flags: []string{ |
| 9314 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9315 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9316 | }, |
| 9317 | shouldFail: true, |
| 9318 | expectedError: ":DECODE_ERROR:", |
| 9319 | expectedLocalError: "remote error: error decoding message", |
| 9320 | }) |
| 9321 |
| 9322 | // Test that signature preferences are enforced. BoringSSL does not |
| 9323 | // implement MD5 signatures. |
| 9324 | testCases = append(testCases, testCase{ |
| 9325 | testType: serverTest, |
| 9326 | name: "ClientAuth-Enforced", |
| 9327 | config: Config{ |
| 9328 | MaxVersion: VersionTLS12, |
| 9329 | Certificates: []Certificate{rsaCertificate}, |
| 9330 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9331 | signatureRSAPKCS1WithMD5, |
| 9332 | }, |
| 9333 | Bugs: ProtocolBugs{ |
| 9334 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 9335 | }, |
| 9336 | }, |
| 9337 | flags: []string{"-require-any-client-certificate"}, |
| 9338 | shouldFail: true, |
| 9339 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 9340 | }) |
| 9341 |
| 9342 | testCases = append(testCases, testCase{ |
| 9343 | name: "ServerAuth-Enforced", |
| 9344 | config: Config{ |
| 9345 | MaxVersion: VersionTLS12, |
| 9346 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 9347 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9348 | signatureRSAPKCS1WithMD5, |
| 9349 | }, |
| 9350 | Bugs: ProtocolBugs{ |
| 9351 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 9352 | }, |
| 9353 | }, |
| 9354 | shouldFail: true, |
| 9355 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 9356 | }) |
| 9357 | testCases = append(testCases, testCase{ |
| 9358 | testType: serverTest, |
| 9359 | name: "ClientAuth-Enforced-TLS13", |
| 9360 | config: Config{ |
| 9361 | MaxVersion: VersionTLS13, |
| 9362 | Certificates: []Certificate{rsaCertificate}, |
| 9363 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9364 | signatureRSAPKCS1WithMD5, |
| 9365 | }, |
| 9366 | Bugs: ProtocolBugs{ |
| 9367 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 9368 | IgnoreSignatureVersionChecks: true, |
| 9369 | }, |
| 9370 | }, |
| 9371 | flags: []string{"-require-any-client-certificate"}, |
| 9372 | shouldFail: true, |
| 9373 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 9374 | }) |
| 9375 |
| 9376 | testCases = append(testCases, testCase{ |
| 9377 | name: "ServerAuth-Enforced-TLS13", |
| 9378 | config: Config{ |
| 9379 | MaxVersion: VersionTLS13, |
| 9380 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9381 | signatureRSAPKCS1WithMD5, |
| 9382 | }, |
| 9383 | Bugs: ProtocolBugs{ |
| 9384 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 9385 | IgnoreSignatureVersionChecks: true, |
| 9386 | }, |
| 9387 | }, |
| 9388 | shouldFail: true, |
| 9389 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 9390 | }) |
| 9391 |
| 9392 | // Test that the negotiated signature algorithm respects the client and |
| 9393 | // server preferences. |
| 9394 | testCases = append(testCases, testCase{ |
| 9395 | name: "NoCommonAlgorithms", |
| 9396 | config: Config{ |
| 9397 | MaxVersion: VersionTLS12, |
| 9398 | ClientAuth: RequireAnyClientCert, |
| 9399 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9400 | signatureRSAPKCS1WithSHA512, |
| 9401 | signatureRSAPKCS1WithSHA1, |
| 9402 | }, |
| 9403 | }, |
| 9404 | flags: []string{ |
| 9405 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9406 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9407 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
| 9408 | }, |
| 9409 | shouldFail: true, |
| 9410 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 9411 | }) |
| 9412 | testCases = append(testCases, testCase{ |
| 9413 | name: "NoCommonAlgorithms-TLS13", |
| 9414 | config: Config{ |
| 9415 | MaxVersion: VersionTLS13, |
| 9416 | ClientAuth: RequireAnyClientCert, |
| 9417 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9418 | signatureRSAPSSWithSHA512, |
| 9419 | signatureRSAPSSWithSHA384, |
| 9420 | }, |
| 9421 | }, |
| 9422 | flags: []string{ |
| 9423 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9424 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9425 | "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)), |
| 9426 | }, |
| 9427 | shouldFail: true, |
| 9428 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 9429 | }) |
| 9430 | testCases = append(testCases, testCase{ |
| 9431 | name: "Agree-Digest-SHA256", |
| 9432 | config: Config{ |
| 9433 | MaxVersion: VersionTLS12, |
| 9434 | ClientAuth: RequireAnyClientCert, |
| 9435 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9436 | signatureRSAPKCS1WithSHA1, |
| 9437 | signatureRSAPKCS1WithSHA256, |
| 9438 | }, |
| 9439 | }, |
| 9440 | flags: []string{ |
| 9441 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9442 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9443 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
| 9444 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA1)), |
| 9445 | }, |
| 9446 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
| 9447 | }) |
| 9448 | testCases = append(testCases, testCase{ |
| 9449 | name: "Agree-Digest-SHA1", |
| 9450 | config: Config{ |
| 9451 | MaxVersion: VersionTLS12, |
| 9452 | ClientAuth: RequireAnyClientCert, |
| 9453 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9454 | signatureRSAPKCS1WithSHA1, |
| 9455 | }, |
| 9456 | }, |
| 9457 | flags: []string{ |
| 9458 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9459 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9460 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA512)), |
| 9461 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
| 9462 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA1)), |
| 9463 | }, |
| 9464 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1, |
| 9465 | }) |
| 9466 | testCases = append(testCases, testCase{ |
| 9467 | name: "Agree-Digest-Default", |
| 9468 | config: Config{ |
| 9469 | MaxVersion: VersionTLS12, |
| 9470 | ClientAuth: RequireAnyClientCert, |
| 9471 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9472 | signatureRSAPKCS1WithSHA256, |
| 9473 | signatureECDSAWithP256AndSHA256, |
| 9474 | signatureRSAPKCS1WithSHA1, |
| 9475 | signatureECDSAWithSHA1, |
| 9476 | }, |
| 9477 | }, |
| 9478 | flags: []string{ |
| 9479 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9480 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9481 | }, |
| 9482 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
| 9483 | }) |
| 9484 |
| 9485 | // Test that the signing preference list may include extra algorithms |
| 9486 | // without negotiation problems. |
| 9487 | testCases = append(testCases, testCase{ |
| 9488 | testType: serverTest, |
| 9489 | name: "FilterExtraAlgorithms", |
| 9490 | config: Config{ |
| 9491 | MaxVersion: VersionTLS12, |
| 9492 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9493 | signatureRSAPKCS1WithSHA256, |
| 9494 | }, |
| 9495 | }, |
| 9496 | flags: []string{ |
| 9497 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 9498 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 9499 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)), |
| 9500 | "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)), |
| 9501 | "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)), |
| 9502 | "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)), |
| 9503 | }, |
| 9504 | expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256, |
| 9505 | }) |
| 9506 |
| 9507 | // In TLS 1.2 and below, ECDSA uses the curve list rather than the |
| 9508 | // signature algorithms. |
| 9509 | testCases = append(testCases, testCase{ |
| 9510 | name: "CheckLeafCurve", |
| 9511 | config: Config{ |
| 9512 | MaxVersion: VersionTLS12, |
| 9513 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 9514 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 9515 | }, |
| 9516 | flags: []string{"-curves", strconv.Itoa(int(CurveP384))}, |
| 9517 | shouldFail: true, |
| 9518 | expectedError: ":BAD_ECC_CERT:", |
| 9519 | }) |
| 9520 |
| 9521 | // In TLS 1.3, ECDSA does not use the ECDHE curve list. |
| 9522 | testCases = append(testCases, testCase{ |
| 9523 | name: "CheckLeafCurve-TLS13", |
| 9524 | config: Config{ |
| 9525 | MaxVersion: VersionTLS13, |
| 9526 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 9527 | }, |
| 9528 | flags: []string{"-curves", strconv.Itoa(int(CurveP384))}, |
| 9529 | }) |
| 9530 |
| 9531 | // In TLS 1.2, the ECDSA curve is not in the signature algorithm. |
| 9532 | testCases = append(testCases, testCase{ |
| 9533 | name: "ECDSACurveMismatch-Verify-TLS12", |
| 9534 | config: Config{ |
| 9535 | MaxVersion: VersionTLS12, |
| 9536 | CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 9537 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 9538 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9539 | signatureECDSAWithP384AndSHA384, |
| 9540 | }, |
| 9541 | }, |
| 9542 | }) |
| 9543 |
| 9544 | // In TLS 1.3, the ECDSA curve comes from the signature algorithm. |
| 9545 | testCases = append(testCases, testCase{ |
| 9546 | name: "ECDSACurveMismatch-Verify-TLS13", |
| 9547 | config: Config{ |
| 9548 | MaxVersion: VersionTLS13, |
| 9549 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 9550 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9551 | signatureECDSAWithP384AndSHA384, |
| 9552 | }, |
| 9553 | Bugs: ProtocolBugs{ |
| 9554 | SkipECDSACurveCheck: true, |
| 9555 | }, |
| 9556 | }, |
| 9557 | shouldFail: true, |
| 9558 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 9559 | }) |
| 9560 |
| 9561 | // Signature algorithm selection in TLS 1.3 should take the curve into |
| 9562 | // account. |
| 9563 | testCases = append(testCases, testCase{ |
| 9564 | testType: serverTest, |
| 9565 | name: "ECDSACurveMismatch-Sign-TLS13", |
| 9566 | config: Config{ |
| 9567 | MaxVersion: VersionTLS13, |
| 9568 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9569 | signatureECDSAWithP384AndSHA384, |
| 9570 | signatureECDSAWithP256AndSHA256, |
| 9571 | }, |
| 9572 | }, |
| 9573 | flags: []string{ |
| 9574 | "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 9575 | "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile), |
| 9576 | }, |
| 9577 | expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256, |
| 9578 | }) |
| 9579 |
| 9580 | // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the |
| 9581 | // server does not attempt to sign in that case. |
| 9582 | testCases = append(testCases, testCase{ |
| 9583 | testType: serverTest, |
| 9584 | name: "RSA-PSS-Large", |
| 9585 | config: Config{ |
| 9586 | MaxVersion: VersionTLS13, |
| 9587 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9588 | signatureRSAPSSWithSHA512, |
| 9589 | }, |
| 9590 | }, |
| 9591 | flags: []string{ |
| 9592 | "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile), |
| 9593 | "-key-file", path.Join(*resourceDir, rsa1024KeyFile), |
| 9594 | }, |
| 9595 | shouldFail: true, |
| 9596 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 9597 | }) |
| 9598 |
| 9599 | // Test that RSA-PSS is enabled by default for TLS 1.2. |
| 9600 | testCases = append(testCases, testCase{ |
| 9601 | testType: clientTest, |
| 9602 | name: "RSA-PSS-Default-Verify", |
| 9603 | config: Config{ |
| 9604 | MaxVersion: VersionTLS12, |
| 9605 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9606 | signatureRSAPSSWithSHA256, |
| 9607 | }, |
| 9608 | }, |
| 9609 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 9610 | }) |
| 9611 |
| 9612 | testCases = append(testCases, testCase{ |
| 9613 | testType: serverTest, |
| 9614 | name: "RSA-PSS-Default-Sign", |
| 9615 | config: Config{ |
| 9616 | MaxVersion: VersionTLS12, |
| 9617 | VerifySignatureAlgorithms: []signatureAlgorithm{ |
| 9618 | signatureRSAPSSWithSHA256, |
| 9619 | }, |
| 9620 | }, |
| 9621 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 9622 | }) |
| 9623 |
| 9624 | // TLS 1.1 and below has no way to advertise support for or negotiate |
| 9625 | // Ed25519's signature algorithm. |
| 9626 | testCases = append(testCases, testCase{ |
| 9627 | testType: clientTest, |
| 9628 | name: "NoEd25519-TLS11-ServerAuth-Verify", |
| 9629 | config: Config{ |
| 9630 | MaxVersion: VersionTLS11, |
| 9631 | Certificates: []Certificate{ed25519Certificate}, |
| 9632 | Bugs: ProtocolBugs{ |
| 9633 | // Sign with Ed25519 even though it is TLS 1.1. |
| 9634 | UseLegacySigningAlgorithm: signatureEd25519, |
| 9635 | }, |
| 9636 | }, |
| 9637 | flags: []string{"-enable-ed25519"}, |
| 9638 | shouldFail: true, |
| 9639 | expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:", |
| 9640 | }) |
| 9641 | testCases = append(testCases, testCase{ |
| 9642 | testType: serverTest, |
| 9643 | name: "NoEd25519-TLS11-ServerAuth-Sign", |
| 9644 | config: Config{ |
| 9645 | MaxVersion: VersionTLS11, |
| 9646 | }, |
| 9647 | flags: []string{ |
| 9648 | "-cert-file", path.Join(*resourceDir, ed25519CertificateFile), |
| 9649 | "-key-file", path.Join(*resourceDir, ed25519KeyFile), |
| 9650 | }, |
| 9651 | shouldFail: true, |
| 9652 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 9653 | }) |
| 9654 | testCases = append(testCases, testCase{ |
| 9655 | testType: serverTest, |
| 9656 | name: "NoEd25519-TLS11-ClientAuth-Verify", |
| 9657 | config: Config{ |
| 9658 | MaxVersion: VersionTLS11, |
| 9659 | Certificates: []Certificate{ed25519Certificate}, |
| 9660 | Bugs: ProtocolBugs{ |
| 9661 | // Sign with Ed25519 even though it is TLS 1.1. |
| 9662 | UseLegacySigningAlgorithm: signatureEd25519, |
| 9663 | }, |
| 9664 | }, |
| 9665 | flags: []string{ |
| 9666 | "-enable-ed25519", |
| 9667 | "-require-any-client-certificate", |
| 9668 | }, |
| 9669 | shouldFail: true, |
| 9670 | expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:", |
| 9671 | }) |
| 9672 | testCases = append(testCases, testCase{ |
| 9673 | testType: clientTest, |
| 9674 | name: "NoEd25519-TLS11-ClientAuth-Sign", |
| 9675 | config: Config{ |
| 9676 | MaxVersion: VersionTLS11, |
| 9677 | ClientAuth: RequireAnyClientCert, |
| 9678 | }, |
| 9679 | flags: []string{ |
| 9680 | "-cert-file", path.Join(*resourceDir, ed25519CertificateFile), |
| 9681 | "-key-file", path.Join(*resourceDir, ed25519KeyFile), |
| 9682 | }, |
| 9683 | shouldFail: true, |
| 9684 | expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:", |
| 9685 | }) |
| 9686 |
| 9687 | // Test Ed25519 is not advertised by default. |
| 9688 | testCases = append(testCases, testCase{ |
| 9689 | testType: clientTest, |
| 9690 | name: "Ed25519DefaultDisable-NoAdvertise", |
| 9691 | config: Config{ |
| 9692 | Certificates: []Certificate{ed25519Certificate}, |
| 9693 | }, |
| 9694 | shouldFail: true, |
| 9695 | expectedLocalError: "tls: no common signature algorithms", |
| 9696 | }) |
| 9697 |
| 9698 | // Test Ed25519, when disabled, is not accepted if the peer ignores our |
| 9699 | // preferences. |
| 9700 | testCases = append(testCases, testCase{ |
| 9701 | testType: clientTest, |
| 9702 | name: "Ed25519DefaultDisable-NoAccept", |
| 9703 | config: Config{ |
| 9704 | Certificates: []Certificate{ed25519Certificate}, |
| 9705 | Bugs: ProtocolBugs{ |
| 9706 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 9707 | }, |
| 9708 | }, |
| 9709 | shouldFail: true, |
| 9710 | expectedLocalError: "remote error: illegal parameter", |
| 9711 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 9712 | }) |
| 9713 |
| 9714 | // Test that configuring verify preferences changes what the client |
| 9715 | // advertises. |
| 9716 | testCases = append(testCases, testCase{ |
| 9717 | name: "VerifyPreferences-Advertised", |
| 9718 | config: Config{ |
| 9719 | Certificates: []Certificate{rsaCertificate}, |
| 9720 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9721 | signatureRSAPSSWithSHA256, |
| 9722 | signatureRSAPSSWithSHA384, |
| 9723 | signatureRSAPSSWithSHA512, |
| 9724 | }, |
| 9725 | }, |
| 9726 | flags: []string{ |
| 9727 | "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)), |
| 9728 | "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)), |
| 9729 | }, |
| 9730 | }) |
| 9731 |
| 9732 | // Test that the client advertises a set which the runner can find |
| 9733 | // nothing in common with. |
| 9734 | testCases = append(testCases, testCase{ |
| 9735 | name: "VerifyPreferences-NoCommonAlgorithms", |
| 9736 | config: Config{ |
| 9737 | Certificates: []Certificate{rsaCertificate}, |
| 9738 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9739 | signatureRSAPSSWithSHA256, |
| 9740 | signatureRSAPSSWithSHA512, |
| 9741 | }, |
| 9742 | }, |
| 9743 | flags: []string{ |
| 9744 | "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)), |
| 9745 | }, |
| 9746 | shouldFail: true, |
| 9747 | expectedLocalError: "tls: no common signature algorithms", |
| 9748 | }) |
| 9749 |
| 9750 | // Test that the client enforces its preferences when configured. |
| 9751 | testCases = append(testCases, testCase{ |
| 9752 | name: "VerifyPreferences-Enforced", |
| 9753 | config: Config{ |
| 9754 | Certificates: []Certificate{rsaCertificate}, |
| 9755 | SignSignatureAlgorithms: []signatureAlgorithm{ |
| 9756 | signatureRSAPSSWithSHA256, |
| 9757 | signatureRSAPSSWithSHA512, |
| 9758 | }, |
| 9759 | Bugs: ProtocolBugs{ |
| 9760 | IgnorePeerSignatureAlgorithmPreferences: true, |
| 9761 | }, |
| 9762 | }, |
| 9763 | flags: []string{ |
| 9764 | "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)), |
| 9765 | }, |
| 9766 | shouldFail: true, |
| 9767 | expectedLocalError: "remote error: illegal parameter", |
| 9768 | expectedError: ":WRONG_SIGNATURE_TYPE:", |
| 9769 | }) |
| 9770 |
| 9771 | // Test that explicitly configuring Ed25519 is as good as changing the |
| 9772 | // boolean toggle. |
| 9773 | testCases = append(testCases, testCase{ |
| 9774 | name: "VerifyPreferences-Ed25519", |
| 9775 | config: Config{ |
| 9776 | Certificates: []Certificate{ed25519Certificate}, |
| 9777 | }, |
| 9778 | flags: []string{ |
| 9779 | "-verify-prefs", strconv.Itoa(int(signatureEd25519)), |
| 9780 | }, |
| 9781 | }) |
| 9782 |
| 9783 | rsaPSSSupportTests := []struct { |
| 9784 | name string |
| 9785 | expectRSAPSSSupport RSAPSSSupport |
| 9786 | verifyPrefs []signatureAlgorithm |
| 9787 | noCerts bool |
| 9788 | }{ |
| 9789 | // By default, RSA-PSS is fully advertised. |
| 9790 | { |
| 9791 | name: "Default", |
| 9792 | expectRSAPSSSupport: RSAPSSSupportBoth, |
| 9793 | }, |
| 9794 | // Disabling RSA-PSS certificates makes it online-signature-only. |
| 9795 | { |
| 9796 | name: "Default-NoCerts", |
| 9797 | expectRSAPSSSupport: RSAPSSSupportOnlineSignatureOnly, |
| 9798 | noCerts: true, |
| 9799 | }, |
| 9800 | // The above also apply if verify preferences were explicitly configured. |
| 9801 | { |
| 9802 | name: "ConfigPSS", |
| 9803 | expectRSAPSSSupport: RSAPSSSupportBoth, |
| 9804 | verifyPrefs: []signatureAlgorithm{signatureRSAPSSWithSHA256, signatureRSAPKCS1WithSHA256, signatureECDSAWithP256AndSHA256}, |
| 9805 | }, |
| 9806 | { |
| 9807 | name: "ConfigPSS-NoCerts", |
| 9808 | expectRSAPSSSupport: RSAPSSSupportOnlineSignatureOnly, |
| 9809 | verifyPrefs: []signatureAlgorithm{signatureRSAPSSWithSHA256, signatureRSAPKCS1WithSHA256, signatureECDSAWithP256AndSHA256}, |
| 9810 | noCerts: true, |
| 9811 | }, |
| 9812 | // If verify preferences were explicitly configured without RSA-PSS support, |
| 9813 | // NoCerts is a no-op and the shim correctly only sends one extension. |
| 9814 | // (This is checked internally in the runner.) |
| 9815 | { |
| 9816 | name: "ConfigNoPSS", |
| 9817 | expectRSAPSSSupport: RSAPSSSupportNone, |
| 9818 | verifyPrefs: []signatureAlgorithm{signatureRSAPKCS1WithSHA256, signatureECDSAWithP256AndSHA256}, |
| 9819 | }, |
| 9820 | { |
| 9821 | name: "ConfigNoPSS-NoCerts", |
| 9822 | expectRSAPSSSupport: RSAPSSSupportNone, |
| 9823 | verifyPrefs: []signatureAlgorithm{signatureRSAPKCS1WithSHA256, signatureECDSAWithP256AndSHA256}, |
| 9824 | noCerts: true, |
| 9825 | }, |
| 9826 | } |
| 9827 |
| 9828 | for _, test := range rsaPSSSupportTests { |
| 9829 | var pssFlags []string |
| 9830 | for _, pref := range test.verifyPrefs { |
| 9831 | pssFlags = append(pssFlags, "-verify-prefs", strconv.Itoa(int(pref))) |
| 9832 | } |
| 9833 | if test.noCerts { |
| 9834 | pssFlags = append(pssFlags, "-no-rsa-pss-rsae-certs") |
| 9835 | } |
| 9836 | for _, ver := range tlsVersions { |
| 9837 | if ver.version < VersionTLS12 { |
| 9838 | continue |
| 9839 | } |
| 9840 |
| 9841 | // TLS 1.2 cannot express different RSAPSSSupportOnlineSignatureOnly, |
| 9842 | // so it decays to RSAPSSSupportNone. |
| 9843 | expect := test.expectRSAPSSSupport |
| 9844 | if ver.version < VersionTLS13 && expect == RSAPSSSupportOnlineSignatureOnly { |
| 9845 | expect = RSAPSSSupportNone |
| 9846 | } |
| 9847 |
| 9848 | // If the configuration results in no RSA-PSS support, the handshake won't complete. |
| 9849 | // (The test, however, still covers the RSA-PSS assertion.) |
| 9850 | var localError string |
| 9851 | var shouldFail bool |
| 9852 | if ver.version >= VersionTLS13 && expect == RSAPSSSupportNone { |
| 9853 | shouldFail = true |
| 9854 | localError = "tls: no common signature algorithms" |
| 9855 | } |
| 9856 |
| 9857 | flags := []string{"-max-version", ver.shimFlag(tls)} |
| 9858 | flags = append(flags, pssFlags...) |
| 9859 | testCases = append(testCases, testCase{ |
| 9860 | name: fmt.Sprintf("RSAPSSSupport-%s-%s-Client", test.name, ver.name), |
| 9861 | config: Config{ |
| 9862 | MinVersion: ver.version, |
| 9863 | MaxVersion: ver.version, |
| 9864 | Certificates: []Certificate{rsaCertificate}, |
| 9865 | Bugs: ProtocolBugs{ |
| 9866 | ExpectRSAPSSSupport: expect, |
| 9867 | }, |
| 9868 | }, |
| 9869 | flags: flags, |
| 9870 | shouldFail: shouldFail, |
| 9871 | expectedLocalError: localError, |
| 9872 | }) |
| 9873 |
| 9874 | serverFlags := []string{"-require-any-client-certificate"} |
| 9875 | serverFlags = append(flags, serverFlags...) |
| 9876 | testCases = append(testCases, testCase{ |
| 9877 | testType: serverTest, |
| 9878 | name: fmt.Sprintf("RSAPSSSupport-%s-%s-Server", test.name, ver.name), |
| 9879 | config: Config{ |
| 9880 | MinVersion: ver.version, |
| 9881 | MaxVersion: ver.version, |
| 9882 | Certificates: []Certificate{rsaCertificate}, |
| 9883 | Bugs: ProtocolBugs{ |
| 9884 | ExpectRSAPSSSupport: expect, |
| 9885 | }, |
| 9886 | }, |
| 9887 | flags: serverFlags, |
| 9888 | shouldFail: shouldFail, |
| 9889 | expectedLocalError: localError, |
| 9890 | }) |
| 9891 | } |
| 9892 | } |
| 9893 | } |
| 9894 |
| 9895 | // timeouts is the retransmit schedule for BoringSSL. It doubles and |
| 9896 | // caps at 60 seconds. On the 13th timeout, it gives up. |
| 9897 | var timeouts = []time.Duration{ |
| 9898 | 1 * time.Second, |
| 9899 | 2 * time.Second, |
| 9900 | 4 * time.Second, |
| 9901 | 8 * time.Second, |
| 9902 | 16 * time.Second, |
| 9903 | 32 * time.Second, |
| 9904 | 60 * time.Second, |
| 9905 | 60 * time.Second, |
| 9906 | 60 * time.Second, |
| 9907 | 60 * time.Second, |
| 9908 | 60 * time.Second, |
| 9909 | 60 * time.Second, |
| 9910 | 60 * time.Second, |
| 9911 | } |
| 9912 |
| 9913 | // shortTimeouts is an alternate set of timeouts which would occur if the |
| 9914 | // initial timeout duration was set to 250ms. |
| 9915 | var shortTimeouts = []time.Duration{ |
| 9916 | 250 * time.Millisecond, |
| 9917 | 500 * time.Millisecond, |
| 9918 | 1 * time.Second, |
| 9919 | 2 * time.Second, |
| 9920 | 4 * time.Second, |
| 9921 | 8 * time.Second, |
| 9922 | 16 * time.Second, |
| 9923 | 32 * time.Second, |
| 9924 | 60 * time.Second, |
| 9925 | 60 * time.Second, |
| 9926 | 60 * time.Second, |
| 9927 | 60 * time.Second, |
| 9928 | 60 * time.Second, |
| 9929 | } |
| 9930 |
| 9931 | func addDTLSRetransmitTests() { |
| 9932 | // These tests work by coordinating some behavior on both the shim and |
| 9933 | // the runner. |
| 9934 | // |
| 9935 | // TimeoutSchedule configures the runner to send a series of timeout |
| 9936 | // opcodes to the shim (see packetAdaptor) immediately before reading |
| 9937 | // each peer handshake flight N. The timeout opcode both simulates a |
| 9938 | // timeout in the shim and acts as a synchronization point to help the |
| 9939 | // runner bracket each handshake flight. |
| 9940 | // |
| 9941 | // We assume the shim does not read from the channel eagerly. It must |
| 9942 | // first wait until it has sent flight N and is ready to receive |
| 9943 | // handshake flight N+1. At this point, it will process the timeout |
| 9944 | // opcode. It must then immediately respond with a timeout ACK and act |
| 9945 | // as if the shim was idle for the specified amount of time. |
| 9946 | // |
| 9947 | // The runner then drops all packets received before the ACK and |
| 9948 | // continues waiting for flight N. This ordering results in one attempt |
| 9949 | // at sending flight N to be dropped. For the test to complete, the |
| 9950 | // shim must send flight N again, testing that the shim implements DTLS |
| 9951 | // retransmit on a timeout. |
| 9952 |
| 9953 | // TODO(davidben): Add DTLS 1.3 versions of these tests. There will |
| 9954 | // likely be more epochs to cross and the final message's retransmit may |
| 9955 | // be more complex. |
| 9956 |
| 9957 | // Test that this is indeed the timeout schedule. Stress all |
| 9958 | // four patterns of handshake. |
| 9959 | for i := 1; i < len(timeouts); i++ { |
| 9960 | number := strconv.Itoa(i) |
| 9961 | testCases = append(testCases, testCase{ |
| 9962 | protocol: dtls, |
| 9963 | name: "DTLS-Retransmit-Client-" + number, |
| 9964 | config: Config{ |
| 9965 | MaxVersion: VersionTLS12, |
| 9966 | Bugs: ProtocolBugs{ |
| 9967 | TimeoutSchedule: timeouts[:i], |
| 9968 | }, |
| 9969 | }, |
| 9970 | resumeSession: true, |
| 9971 | flags: []string{"-async"}, |
| 9972 | }) |
| 9973 | testCases = append(testCases, testCase{ |
| 9974 | protocol: dtls, |
| 9975 | testType: serverTest, |
| 9976 | name: "DTLS-Retransmit-Server-" + number, |
| 9977 | config: Config{ |
| 9978 | MaxVersion: VersionTLS12, |
| 9979 | Bugs: ProtocolBugs{ |
| 9980 | TimeoutSchedule: timeouts[:i], |
| 9981 | }, |
| 9982 | }, |
| 9983 | resumeSession: true, |
| 9984 | flags: []string{"-async"}, |
| 9985 | }) |
| 9986 | } |
| 9987 |
| 9988 | // Test that exceeding the timeout schedule hits a read |
| 9989 | // timeout. |
| 9990 | testCases = append(testCases, testCase{ |
| 9991 | protocol: dtls, |
| 9992 | name: "DTLS-Retransmit-Timeout", |
| 9993 | config: Config{ |
| 9994 | MaxVersion: VersionTLS12, |
| 9995 | Bugs: ProtocolBugs{ |
| 9996 | TimeoutSchedule: timeouts, |
| 9997 | }, |
| 9998 | }, |
| 9999 | resumeSession: true, |
| 10000 | flags: []string{"-async"}, |
| 10001 | shouldFail: true, |
| 10002 | expectedError: ":READ_TIMEOUT_EXPIRED:", |
| 10003 | }) |
| 10004 |
| 10005 | // Test that timeout handling has a fudge factor, due to API |
| 10006 | // problems. |
| 10007 | testCases = append(testCases, testCase{ |
| 10008 | protocol: dtls, |
| 10009 | name: "DTLS-Retransmit-Fudge", |
| 10010 | config: Config{ |
| 10011 | MaxVersion: VersionTLS12, |
| 10012 | Bugs: ProtocolBugs{ |
| 10013 | TimeoutSchedule: []time.Duration{ |
| 10014 | timeouts[0] - 10*time.Millisecond, |
| 10015 | }, |
| 10016 | }, |
| 10017 | }, |
| 10018 | resumeSession: true, |
| 10019 | flags: []string{"-async"}, |
| 10020 | }) |
| 10021 |
| 10022 | // Test that the final Finished retransmitting isn't |
| 10023 | // duplicated if the peer badly fragments everything. |
| 10024 | testCases = append(testCases, testCase{ |
| 10025 | testType: serverTest, |
| 10026 | protocol: dtls, |
| 10027 | name: "DTLS-Retransmit-Fragmented", |
| 10028 | config: Config{ |
| 10029 | MaxVersion: VersionTLS12, |
| 10030 | Bugs: ProtocolBugs{ |
| 10031 | TimeoutSchedule: []time.Duration{timeouts[0]}, |
| 10032 | MaxHandshakeRecordLength: 2, |
| 10033 | }, |
| 10034 | }, |
| 10035 | flags: []string{"-async"}, |
| 10036 | }) |
| 10037 |
| 10038 | // Test the timeout schedule when a shorter initial timeout duration is set. |
| 10039 | testCases = append(testCases, testCase{ |
| 10040 | protocol: dtls, |
| 10041 | name: "DTLS-Retransmit-Short-Client", |
| 10042 | config: Config{ |
| 10043 | MaxVersion: VersionTLS12, |
| 10044 | Bugs: ProtocolBugs{ |
| 10045 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
| 10046 | }, |
| 10047 | }, |
| 10048 | resumeSession: true, |
| 10049 | flags: []string{ |
| 10050 | "-async", |
| 10051 | "-initial-timeout-duration-ms", "250", |
| 10052 | }, |
| 10053 | }) |
| 10054 | testCases = append(testCases, testCase{ |
| 10055 | protocol: dtls, |
| 10056 | testType: serverTest, |
| 10057 | name: "DTLS-Retransmit-Short-Server", |
| 10058 | config: Config{ |
| 10059 | MaxVersion: VersionTLS12, |
| 10060 | Bugs: ProtocolBugs{ |
| 10061 | TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1], |
| 10062 | }, |
| 10063 | }, |
| 10064 | resumeSession: true, |
| 10065 | flags: []string{ |
| 10066 | "-async", |
| 10067 | "-initial-timeout-duration-ms", "250", |
| 10068 | }, |
| 10069 | }) |
| 10070 |
| 10071 | // If the shim sends the last Finished (server full or client resume |
| 10072 | // handshakes), it must retransmit that Finished when it sees a |
| 10073 | // post-handshake penultimate Finished from the runner. The above tests |
| 10074 | // cover this. Conversely, if the shim sends the penultimate Finished |
| 10075 | // (client full or server resume), test that it does not retransmit. |
| 10076 | testCases = append(testCases, testCase{ |
| 10077 | protocol: dtls, |
| 10078 | testType: clientTest, |
| 10079 | name: "DTLS-StrayRetransmitFinished-ClientFull", |
| 10080 | config: Config{ |
| 10081 | MaxVersion: VersionTLS12, |
| 10082 | Bugs: ProtocolBugs{ |
| 10083 | RetransmitFinished: true, |
| 10084 | }, |
| 10085 | }, |
| 10086 | }) |
| 10087 | testCases = append(testCases, testCase{ |
| 10088 | protocol: dtls, |
| 10089 | testType: serverTest, |
| 10090 | name: "DTLS-StrayRetransmitFinished-ServerResume", |
| 10091 | config: Config{ |
| 10092 | MaxVersion: VersionTLS12, |
| 10093 | }, |
| 10094 | resumeConfig: &Config{ |
| 10095 | MaxVersion: VersionTLS12, |
| 10096 | Bugs: ProtocolBugs{ |
| 10097 | RetransmitFinished: true, |
| 10098 | }, |
| 10099 | }, |
| 10100 | resumeSession: true, |
| 10101 | }) |
| 10102 | } |
| 10103 |
| 10104 | func addExportKeyingMaterialTests() { |
| 10105 | for _, vers := range tlsVersions { |
| 10106 | testCases = append(testCases, testCase{ |
| 10107 | name: "ExportKeyingMaterial-" + vers.name, |
| 10108 | config: Config{ |
| 10109 | MaxVersion: vers.version, |
| 10110 | }, |
| 10111 | // Test the exporter in both initial and resumption |
| 10112 | // handshakes. |
| 10113 | resumeSession: true, |
| 10114 | exportKeyingMaterial: 1024, |
| 10115 | exportLabel: "label", |
| 10116 | exportContext: "context", |
| 10117 | useExportContext: true, |
| 10118 | }) |
| 10119 | testCases = append(testCases, testCase{ |
| 10120 | name: "ExportKeyingMaterial-NoContext-" + vers.name, |
| 10121 | config: Config{ |
| 10122 | MaxVersion: vers.version, |
| 10123 | }, |
| 10124 | exportKeyingMaterial: 1024, |
| 10125 | }) |
| 10126 | testCases = append(testCases, testCase{ |
| 10127 | name: "ExportKeyingMaterial-EmptyContext-" + vers.name, |
| 10128 | config: Config{ |
| 10129 | MaxVersion: vers.version, |
| 10130 | }, |
| 10131 | exportKeyingMaterial: 1024, |
| 10132 | useExportContext: true, |
| 10133 | }) |
| 10134 | testCases = append(testCases, testCase{ |
| 10135 | name: "ExportKeyingMaterial-Small-" + vers.name, |
| 10136 | config: Config{ |
| 10137 | MaxVersion: vers.version, |
| 10138 | }, |
| 10139 | exportKeyingMaterial: 1, |
| 10140 | exportLabel: "label", |
| 10141 | exportContext: "context", |
| 10142 | useExportContext: true, |
| 10143 | }) |
| 10144 |
| 10145 | if vers.version >= VersionTLS13 { |
| 10146 | // Test the exporters do not work while the client is |
| 10147 | // sending 0-RTT data. |
| 10148 | testCases = append(testCases, testCase{ |
| 10149 | name: "NoEarlyKeyingMaterial-Client-InEarlyData-" + vers.name, |
| 10150 | config: Config{ |
| 10151 | MaxVersion: vers.version, |
| 10152 | MaxEarlyDataSize: 16384, |
| 10153 | }, |
| 10154 | resumeSession: true, |
| 10155 | flags: []string{ |
| 10156 | "-enable-early-data", |
| 10157 | "-expect-ticket-supports-early-data", |
| 10158 | "-on-resume-expect-accept-early-data", |
| 10159 | "-on-resume-export-keying-material", "1024", |
| 10160 | "-on-resume-export-label", "label", |
| 10161 | "-on-resume-export-context", "context", |
| 10162 | }, |
| 10163 | shouldFail: true, |
| 10164 | expectedError: ":HANDSHAKE_NOT_COMPLETE:", |
| 10165 | }) |
| 10166 |
| 10167 | // Test the normal exporter on the server in half-RTT. |
| 10168 | testCases = append(testCases, testCase{ |
| 10169 | testType: serverTest, |
| 10170 | name: "ExportKeyingMaterial-Server-HalfRTT-" + vers.name, |
| 10171 | config: Config{ |
| 10172 | MaxVersion: vers.version, |
| 10173 | Bugs: ProtocolBugs{ |
| 10174 | SendEarlyData: [][]byte{}, |
| 10175 | ExpectEarlyDataAccepted: true, |
| 10176 | }, |
| 10177 | }, |
| 10178 | resumeSession: true, |
| 10179 | exportKeyingMaterial: 1024, |
| 10180 | exportLabel: "label", |
| 10181 | exportContext: "context", |
| 10182 | useExportContext: true, |
| 10183 | flags: []string{"-enable-early-data"}, |
| 10184 | }) |
| 10185 | } |
| 10186 | } |
| 10187 |
| 10188 | // Exporters work during a False Start. |
| 10189 | testCases = append(testCases, testCase{ |
| 10190 | name: "ExportKeyingMaterial-FalseStart", |
| 10191 | config: Config{ |
| 10192 | MaxVersion: VersionTLS12, |
| 10193 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 10194 | NextProtos: []string{"foo"}, |
| 10195 | Bugs: ProtocolBugs{ |
| 10196 | ExpectFalseStart: true, |
| 10197 | }, |
| 10198 | }, |
| 10199 | flags: []string{ |
| 10200 | "-false-start", |
| 10201 | "-advertise-alpn", "\x03foo", |
| 10202 | "-expect-alpn", "foo", |
| 10203 | }, |
| 10204 | shimWritesFirst: true, |
| 10205 | exportKeyingMaterial: 1024, |
| 10206 | exportLabel: "label", |
| 10207 | exportContext: "context", |
| 10208 | useExportContext: true, |
| 10209 | }) |
| 10210 |
| 10211 | // Exporters do not work in the middle of a renegotiation. Test this by |
| 10212 | // triggering the exporter after every SSL_read call and configuring the |
| 10213 | // shim to run asynchronously. |
| 10214 | testCases = append(testCases, testCase{ |
| 10215 | name: "ExportKeyingMaterial-Renegotiate", |
| 10216 | config: Config{ |
| 10217 | MaxVersion: VersionTLS12, |
| 10218 | }, |
| 10219 | renegotiate: 1, |
| 10220 | flags: []string{ |
| 10221 | "-async", |
| 10222 | "-use-exporter-between-reads", |
| 10223 | "-renegotiate-freely", |
| 10224 | "-expect-total-renegotiations", "1", |
| 10225 | }, |
| 10226 | shouldFail: true, |
| 10227 | expectedError: "failed to export keying material", |
| 10228 | }) |
| 10229 | } |
| 10230 |
| 10231 | func addExportTrafficSecretsTests() { |
| 10232 | for _, cipherSuite := range []testCipherSuite{ |
| 10233 | // Test a SHA-256 and SHA-384 based cipher suite. |
| 10234 | {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256}, |
| 10235 | {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384}, |
| 10236 | } { |
| 10237 |
| 10238 | testCases = append(testCases, testCase{ |
| 10239 | name: "ExportTrafficSecrets-" + cipherSuite.name, |
| 10240 | config: Config{ |
| 10241 | MinVersion: VersionTLS13, |
| 10242 | CipherSuites: []uint16{cipherSuite.id}, |
| 10243 | }, |
| 10244 | exportTrafficSecrets: true, |
| 10245 | }) |
| 10246 | } |
| 10247 | } |
| 10248 |
| 10249 | func addTLSUniqueTests() { |
| 10250 | for _, isClient := range []bool{false, true} { |
| 10251 | for _, isResumption := range []bool{false, true} { |
| 10252 | for _, hasEMS := range []bool{false, true} { |
| 10253 | var suffix string |
| 10254 | if isResumption { |
| 10255 | suffix = "Resume-" |
| 10256 | } else { |
| 10257 | suffix = "Full-" |
| 10258 | } |
| 10259 |
| 10260 | if hasEMS { |
| 10261 | suffix += "EMS-" |
| 10262 | } else { |
| 10263 | suffix += "NoEMS-" |
| 10264 | } |
| 10265 |
| 10266 | if isClient { |
| 10267 | suffix += "Client" |
| 10268 | } else { |
| 10269 | suffix += "Server" |
| 10270 | } |
| 10271 |
| 10272 | test := testCase{ |
| 10273 | name: "TLSUnique-" + suffix, |
| 10274 | testTLSUnique: true, |
| 10275 | config: Config{ |
| 10276 | MaxVersion: VersionTLS12, |
| 10277 | Bugs: ProtocolBugs{ |
| 10278 | NoExtendedMasterSecret: !hasEMS, |
| 10279 | }, |
| 10280 | }, |
| 10281 | } |
| 10282 |
| 10283 | if isResumption { |
| 10284 | test.resumeSession = true |
| 10285 | test.resumeConfig = &Config{ |
| 10286 | MaxVersion: VersionTLS12, |
| 10287 | Bugs: ProtocolBugs{ |
| 10288 | NoExtendedMasterSecret: !hasEMS, |
| 10289 | }, |
| 10290 | } |
| 10291 | } |
| 10292 |
| 10293 | if isResumption && !hasEMS { |
| 10294 | test.shouldFail = true |
| 10295 | test.expectedError = "failed to get tls-unique" |
| 10296 | } |
| 10297 |
| 10298 | testCases = append(testCases, test) |
| 10299 | } |
| 10300 | } |
| 10301 | } |
| 10302 | } |
| 10303 |
| 10304 | func addCustomExtensionTests() { |
| 10305 | // Test an unknown extension from the server. |
| 10306 | testCases = append(testCases, testCase{ |
| 10307 | testType: clientTest, |
| 10308 | name: "UnknownExtension-Client", |
| 10309 | config: Config{ |
| 10310 | MaxVersion: VersionTLS12, |
| 10311 | Bugs: ProtocolBugs{ |
| 10312 | CustomExtension: "custom extension", |
| 10313 | }, |
| 10314 | }, |
| 10315 | shouldFail: true, |
| 10316 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 10317 | expectedLocalError: "remote error: unsupported extension", |
| 10318 | }) |
| 10319 | testCases = append(testCases, testCase{ |
| 10320 | testType: clientTest, |
| 10321 | name: "UnknownExtension-Client-TLS13", |
| 10322 | config: Config{ |
| 10323 | MaxVersion: VersionTLS13, |
| 10324 | Bugs: ProtocolBugs{ |
| 10325 | CustomExtension: "custom extension", |
| 10326 | }, |
| 10327 | }, |
| 10328 | shouldFail: true, |
| 10329 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 10330 | expectedLocalError: "remote error: unsupported extension", |
| 10331 | }) |
| 10332 | testCases = append(testCases, testCase{ |
| 10333 | testType: clientTest, |
| 10334 | name: "UnknownUnencryptedExtension-Client-TLS13", |
| 10335 | config: Config{ |
| 10336 | MaxVersion: VersionTLS13, |
| 10337 | Bugs: ProtocolBugs{ |
| 10338 | CustomUnencryptedExtension: "custom extension", |
| 10339 | }, |
| 10340 | }, |
| 10341 | shouldFail: true, |
| 10342 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 10343 | // The shim must send an alert, but alerts at this point do not |
| 10344 | // get successfully decrypted by the runner. |
| 10345 | expectedLocalError: "local error: bad record MAC", |
| 10346 | }) |
| 10347 | testCases = append(testCases, testCase{ |
| 10348 | testType: clientTest, |
| 10349 | name: "UnexpectedUnencryptedExtension-Client-TLS13", |
| 10350 | config: Config{ |
| 10351 | MaxVersion: VersionTLS13, |
| 10352 | Bugs: ProtocolBugs{ |
| 10353 | SendUnencryptedALPN: "foo", |
| 10354 | }, |
| 10355 | }, |
| 10356 | flags: []string{ |
| 10357 | "-advertise-alpn", "\x03foo\x03bar", |
| 10358 | }, |
| 10359 | shouldFail: true, |
| 10360 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 10361 | // The shim must send an alert, but alerts at this point do not |
| 10362 | // get successfully decrypted by the runner. |
| 10363 | expectedLocalError: "local error: bad record MAC", |
| 10364 | }) |
| 10365 |
| 10366 | // Test a known but unoffered extension from the server. |
| 10367 | testCases = append(testCases, testCase{ |
| 10368 | testType: clientTest, |
| 10369 | name: "UnofferedExtension-Client", |
| 10370 | config: Config{ |
| 10371 | MaxVersion: VersionTLS12, |
| 10372 | Bugs: ProtocolBugs{ |
| 10373 | SendALPN: "alpn", |
| 10374 | }, |
| 10375 | }, |
| 10376 | shouldFail: true, |
| 10377 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 10378 | expectedLocalError: "remote error: unsupported extension", |
| 10379 | }) |
| 10380 | testCases = append(testCases, testCase{ |
| 10381 | testType: clientTest, |
| 10382 | name: "UnofferedExtension-Client-TLS13", |
| 10383 | config: Config{ |
| 10384 | MaxVersion: VersionTLS13, |
| 10385 | Bugs: ProtocolBugs{ |
| 10386 | SendALPN: "alpn", |
| 10387 | }, |
| 10388 | }, |
| 10389 | shouldFail: true, |
| 10390 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 10391 | expectedLocalError: "remote error: unsupported extension", |
| 10392 | }) |
| 10393 | } |
| 10394 |
| 10395 | func addRSAClientKeyExchangeTests() { |
| 10396 | for bad := RSABadValue(1); bad < NumRSABadValues; bad++ { |
| 10397 | testCases = append(testCases, testCase{ |
| 10398 | testType: serverTest, |
| 10399 | name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad), |
| 10400 | config: Config{ |
| 10401 | // Ensure the ClientHello version and final |
| 10402 | // version are different, to detect if the |
| 10403 | // server uses the wrong one. |
| 10404 | MaxVersion: VersionTLS11, |
| 10405 | CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA}, |
| 10406 | Bugs: ProtocolBugs{ |
| 10407 | BadRSAClientKeyExchange: bad, |
| 10408 | }, |
| 10409 | }, |
| 10410 | shouldFail: true, |
| 10411 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 10412 | }) |
| 10413 | } |
| 10414 |
| 10415 | // The server must compare whatever was in ClientHello.version for the |
| 10416 | // RSA premaster. |
| 10417 | testCases = append(testCases, testCase{ |
| 10418 | testType: serverTest, |
| 10419 | name: "SendClientVersion-RSA", |
| 10420 | config: Config{ |
| 10421 | CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256}, |
| 10422 | Bugs: ProtocolBugs{ |
| 10423 | SendClientVersion: 0x1234, |
| 10424 | }, |
| 10425 | }, |
| 10426 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 10427 | }) |
| 10428 | } |
| 10429 |
| 10430 | var testCurves = []struct { |
| 10431 | name string |
| 10432 | id CurveID |
| 10433 | }{ |
| 10434 | {"P-224", CurveP224}, |
| 10435 | {"P-256", CurveP256}, |
| 10436 | {"P-384", CurveP384}, |
| 10437 | {"P-521", CurveP521}, |
| 10438 | {"X25519", CurveX25519}, |
| 10439 | {"CECPQ2", CurveCECPQ2}, |
| 10440 | {"CECPQ2b", CurveCECPQ2b}, |
| 10441 | } |
| 10442 |
| 10443 | const bogusCurve = 0x1234 |
| 10444 |
| 10445 | func isPqGroup(r CurveID) bool { |
| 10446 | return r == CurveCECPQ2 || r == CurveCECPQ2b |
| 10447 | } |
| 10448 |
| 10449 | func addCurveTests() { |
| 10450 | for _, curve := range testCurves { |
| 10451 | for _, ver := range tlsVersions { |
| 10452 | if isPqGroup(curve.id) && ver.version < VersionTLS13 { |
| 10453 | continue |
| 10454 | } |
| 10455 |
| 10456 | suffix := curve.name + "-" + ver.name |
| 10457 |
| 10458 | testCases = append(testCases, testCase{ |
| 10459 | name: "CurveTest-Client-" + suffix, |
| 10460 | config: Config{ |
| 10461 | MaxVersion: ver.version, |
| 10462 | CipherSuites: []uint16{ |
| 10463 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 10464 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 10465 | TLS_AES_256_GCM_SHA384, |
| 10466 | }, |
| 10467 | CurvePreferences: []CurveID{curve.id}, |
| 10468 | }, |
| 10469 | flags: []string{ |
| 10470 | "-enable-all-curves", |
| 10471 | "-expect-curve-id", strconv.Itoa(int(curve.id)), |
| 10472 | }, |
| 10473 | expectedCurveID: curve.id, |
| 10474 | }) |
| 10475 | testCases = append(testCases, testCase{ |
| 10476 | testType: serverTest, |
| 10477 | name: "CurveTest-Server-" + suffix, |
| 10478 | config: Config{ |
| 10479 | MaxVersion: ver.version, |
| 10480 | CipherSuites: []uint16{ |
| 10481 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 10482 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 10483 | TLS_AES_256_GCM_SHA384, |
| 10484 | }, |
| 10485 | CurvePreferences: []CurveID{curve.id}, |
| 10486 | }, |
| 10487 | flags: []string{ |
| 10488 | "-enable-all-curves", |
| 10489 | "-expect-curve-id", strconv.Itoa(int(curve.id)), |
| 10490 | }, |
| 10491 | expectedCurveID: curve.id, |
| 10492 | }) |
| 10493 |
| 10494 | if curve.id != CurveX25519 && !isPqGroup(curve.id) { |
| 10495 | testCases = append(testCases, testCase{ |
| 10496 | name: "CurveTest-Client-Compressed-" + suffix, |
| 10497 | config: Config{ |
| 10498 | MaxVersion: ver.version, |
| 10499 | CipherSuites: []uint16{ |
| 10500 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 10501 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 10502 | TLS_AES_256_GCM_SHA384, |
| 10503 | }, |
| 10504 | CurvePreferences: []CurveID{curve.id}, |
| 10505 | Bugs: ProtocolBugs{ |
| 10506 | SendCompressedCoordinates: true, |
| 10507 | }, |
| 10508 | }, |
| 10509 | flags: []string{"-enable-all-curves"}, |
| 10510 | shouldFail: true, |
| 10511 | expectedError: ":BAD_ECPOINT:", |
| 10512 | }) |
| 10513 | testCases = append(testCases, testCase{ |
| 10514 | testType: serverTest, |
| 10515 | name: "CurveTest-Server-Compressed-" + suffix, |
| 10516 | config: Config{ |
| 10517 | MaxVersion: ver.version, |
| 10518 | CipherSuites: []uint16{ |
| 10519 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 10520 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 10521 | TLS_AES_256_GCM_SHA384, |
| 10522 | }, |
| 10523 | CurvePreferences: []CurveID{curve.id}, |
| 10524 | Bugs: ProtocolBugs{ |
| 10525 | SendCompressedCoordinates: true, |
| 10526 | }, |
| 10527 | }, |
| 10528 | flags: []string{"-enable-all-curves"}, |
| 10529 | shouldFail: true, |
| 10530 | expectedError: ":BAD_ECPOINT:", |
| 10531 | }) |
| 10532 | } |
| 10533 | } |
| 10534 | } |
| 10535 |
| 10536 | // The server must be tolerant to bogus curves. |
| 10537 | testCases = append(testCases, testCase{ |
| 10538 | testType: serverTest, |
| 10539 | name: "UnknownCurve", |
| 10540 | config: Config{ |
| 10541 | MaxVersion: VersionTLS12, |
| 10542 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 10543 | CurvePreferences: []CurveID{bogusCurve, CurveP256}, |
| 10544 | }, |
| 10545 | }) |
| 10546 |
| 10547 | // The server must be tolerant to bogus curves. |
| 10548 | testCases = append(testCases, testCase{ |
| 10549 | testType: serverTest, |
| 10550 | name: "UnknownCurve-TLS13", |
| 10551 | config: Config{ |
| 10552 | MaxVersion: VersionTLS13, |
| 10553 | CurvePreferences: []CurveID{bogusCurve, CurveP256}, |
| 10554 | }, |
| 10555 | }) |
| 10556 |
| 10557 | // The server must not consider ECDHE ciphers when there are no |
| 10558 | // supported curves. |
| 10559 | testCases = append(testCases, testCase{ |
| 10560 | testType: serverTest, |
| 10561 | name: "NoSupportedCurves", |
| 10562 | config: Config{ |
| 10563 | MaxVersion: VersionTLS12, |
| 10564 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 10565 | Bugs: ProtocolBugs{ |
| 10566 | NoSupportedCurves: true, |
| 10567 | }, |
| 10568 | }, |
| 10569 | shouldFail: true, |
| 10570 | expectedError: ":NO_SHARED_CIPHER:", |
| 10571 | }) |
| 10572 | testCases = append(testCases, testCase{ |
| 10573 | testType: serverTest, |
| 10574 | name: "NoSupportedCurves-TLS13", |
| 10575 | config: Config{ |
| 10576 | MaxVersion: VersionTLS13, |
| 10577 | Bugs: ProtocolBugs{ |
| 10578 | NoSupportedCurves: true, |
| 10579 | }, |
| 10580 | }, |
| 10581 | shouldFail: true, |
| 10582 | expectedError: ":NO_SHARED_GROUP:", |
| 10583 | }) |
| 10584 |
| 10585 | // The server must fall back to another cipher when there are no |
| 10586 | // supported curves. |
| 10587 | testCases = append(testCases, testCase{ |
| 10588 | testType: serverTest, |
| 10589 | name: "NoCommonCurves", |
| 10590 | config: Config{ |
| 10591 | MaxVersion: VersionTLS12, |
| 10592 | CipherSuites: []uint16{ |
| 10593 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 10594 | TLS_RSA_WITH_AES_128_GCM_SHA256, |
| 10595 | }, |
| 10596 | CurvePreferences: []CurveID{CurveP224}, |
| 10597 | }, |
| 10598 | expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256, |
| 10599 | }) |
| 10600 |
| 10601 | // The client must reject bogus curves and disabled curves. |
| 10602 | testCases = append(testCases, testCase{ |
| 10603 | name: "BadECDHECurve", |
| 10604 | config: Config{ |
| 10605 | MaxVersion: VersionTLS12, |
| 10606 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 10607 | Bugs: ProtocolBugs{ |
| 10608 | SendCurve: bogusCurve, |
| 10609 | }, |
| 10610 | }, |
| 10611 | shouldFail: true, |
| 10612 | expectedError: ":WRONG_CURVE:", |
| 10613 | }) |
| 10614 | testCases = append(testCases, testCase{ |
| 10615 | name: "BadECDHECurve-TLS13", |
| 10616 | config: Config{ |
| 10617 | MaxVersion: VersionTLS13, |
| 10618 | Bugs: ProtocolBugs{ |
| 10619 | SendCurve: bogusCurve, |
| 10620 | }, |
| 10621 | }, |
| 10622 | shouldFail: true, |
| 10623 | expectedError: ":WRONG_CURVE:", |
| 10624 | }) |
| 10625 |
| 10626 | testCases = append(testCases, testCase{ |
| 10627 | name: "UnsupportedCurve", |
| 10628 | config: Config{ |
| 10629 | MaxVersion: VersionTLS12, |
| 10630 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 10631 | CurvePreferences: []CurveID{CurveP256}, |
| 10632 | Bugs: ProtocolBugs{ |
| 10633 | IgnorePeerCurvePreferences: true, |
| 10634 | }, |
| 10635 | }, |
| 10636 | flags: []string{"-curves", strconv.Itoa(int(CurveP384))}, |
| 10637 | shouldFail: true, |
| 10638 | expectedError: ":WRONG_CURVE:", |
| 10639 | }) |
| 10640 |
| 10641 | testCases = append(testCases, testCase{ |
| 10642 | // TODO(davidben): Add a TLS 1.3 version where |
| 10643 | // HelloRetryRequest requests an unsupported curve. |
| 10644 | name: "UnsupportedCurve-ServerHello-TLS13", |
| 10645 | config: Config{ |
| 10646 | MaxVersion: VersionTLS13, |
| 10647 | CurvePreferences: []CurveID{CurveP384}, |
| 10648 | Bugs: ProtocolBugs{ |
| 10649 | SendCurve: CurveP256, |
| 10650 | }, |
| 10651 | }, |
| 10652 | flags: []string{"-curves", strconv.Itoa(int(CurveP384))}, |
| 10653 | shouldFail: true, |
| 10654 | expectedError: ":WRONG_CURVE:", |
| 10655 | }) |
| 10656 |
| 10657 | // Test invalid curve points. |
| 10658 | testCases = append(testCases, testCase{ |
| 10659 | name: "InvalidECDHPoint-Client", |
| 10660 | config: Config{ |
| 10661 | MaxVersion: VersionTLS12, |
| 10662 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 10663 | CurvePreferences: []CurveID{CurveP256}, |
| 10664 | Bugs: ProtocolBugs{ |
| 10665 | InvalidECDHPoint: true, |
| 10666 | }, |
| 10667 | }, |
| 10668 | shouldFail: true, |
| 10669 | expectedError: ":BAD_ECPOINT:", |
| 10670 | }) |
| 10671 | testCases = append(testCases, testCase{ |
| 10672 | name: "InvalidECDHPoint-Client-TLS13", |
| 10673 | config: Config{ |
| 10674 | MaxVersion: VersionTLS13, |
| 10675 | CurvePreferences: []CurveID{CurveP256}, |
| 10676 | Bugs: ProtocolBugs{ |
| 10677 | InvalidECDHPoint: true, |
| 10678 | }, |
| 10679 | }, |
| 10680 | shouldFail: true, |
| 10681 | expectedError: ":BAD_ECPOINT:", |
| 10682 | }) |
| 10683 | testCases = append(testCases, testCase{ |
| 10684 | testType: serverTest, |
| 10685 | name: "InvalidECDHPoint-Server", |
| 10686 | config: Config{ |
| 10687 | MaxVersion: VersionTLS12, |
| 10688 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 10689 | CurvePreferences: []CurveID{CurveP256}, |
| 10690 | Bugs: ProtocolBugs{ |
| 10691 | InvalidECDHPoint: true, |
| 10692 | }, |
| 10693 | }, |
| 10694 | shouldFail: true, |
| 10695 | expectedError: ":BAD_ECPOINT:", |
| 10696 | }) |
| 10697 | testCases = append(testCases, testCase{ |
| 10698 | testType: serverTest, |
| 10699 | name: "InvalidECDHPoint-Server-TLS13", |
| 10700 | config: Config{ |
| 10701 | MaxVersion: VersionTLS13, |
| 10702 | CurvePreferences: []CurveID{CurveP256}, |
| 10703 | Bugs: ProtocolBugs{ |
| 10704 | InvalidECDHPoint: true, |
| 10705 | }, |
| 10706 | }, |
| 10707 | shouldFail: true, |
| 10708 | expectedError: ":BAD_ECPOINT:", |
| 10709 | }) |
| 10710 |
| 10711 | // The previous curve ID should be reported on TLS 1.2 resumption. |
| 10712 | testCases = append(testCases, testCase{ |
| 10713 | name: "CurveID-Resume-Client", |
| 10714 | config: Config{ |
| 10715 | MaxVersion: VersionTLS12, |
| 10716 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 10717 | CurvePreferences: []CurveID{CurveX25519}, |
| 10718 | }, |
| 10719 | flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))}, |
| 10720 | resumeSession: true, |
| 10721 | }) |
| 10722 | testCases = append(testCases, testCase{ |
| 10723 | testType: serverTest, |
| 10724 | name: "CurveID-Resume-Server", |
| 10725 | config: Config{ |
| 10726 | MaxVersion: VersionTLS12, |
| 10727 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 10728 | CurvePreferences: []CurveID{CurveX25519}, |
| 10729 | }, |
| 10730 | flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))}, |
| 10731 | resumeSession: true, |
| 10732 | }) |
| 10733 |
| 10734 | // TLS 1.3 allows resuming at a differet curve. If this happens, the new |
| 10735 | // one should be reported. |
| 10736 | testCases = append(testCases, testCase{ |
| 10737 | name: "CurveID-Resume-Client-TLS13", |
| 10738 | config: Config{ |
| 10739 | MaxVersion: VersionTLS13, |
| 10740 | CurvePreferences: []CurveID{CurveX25519}, |
| 10741 | }, |
| 10742 | resumeConfig: &Config{ |
| 10743 | MaxVersion: VersionTLS13, |
| 10744 | CurvePreferences: []CurveID{CurveP256}, |
| 10745 | }, |
| 10746 | flags: []string{ |
| 10747 | "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)), |
| 10748 | "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)), |
| 10749 | }, |
| 10750 | resumeSession: true, |
| 10751 | }) |
| 10752 | testCases = append(testCases, testCase{ |
| 10753 | testType: serverTest, |
| 10754 | name: "CurveID-Resume-Server-TLS13", |
| 10755 | config: Config{ |
| 10756 | MaxVersion: VersionTLS13, |
| 10757 | CurvePreferences: []CurveID{CurveX25519}, |
| 10758 | }, |
| 10759 | resumeConfig: &Config{ |
| 10760 | MaxVersion: VersionTLS13, |
| 10761 | CurvePreferences: []CurveID{CurveP256}, |
| 10762 | }, |
| 10763 | flags: []string{ |
| 10764 | "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)), |
| 10765 | "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)), |
| 10766 | }, |
| 10767 | resumeSession: true, |
| 10768 | }) |
| 10769 |
| 10770 | // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3. |
| 10771 | testCases = append(testCases, testCase{ |
| 10772 | name: "PointFormat-ServerHello-TLS12", |
| 10773 | config: Config{ |
| 10774 | MaxVersion: VersionTLS12, |
| 10775 | Bugs: ProtocolBugs{ |
| 10776 | SendSupportedPointFormats: []byte{pointFormatUncompressed}, |
| 10777 | }, |
| 10778 | }, |
| 10779 | }) |
| 10780 | testCases = append(testCases, testCase{ |
| 10781 | name: "PointFormat-EncryptedExtensions-TLS13", |
| 10782 | config: Config{ |
| 10783 | MaxVersion: VersionTLS13, |
| 10784 | Bugs: ProtocolBugs{ |
| 10785 | SendSupportedPointFormats: []byte{pointFormatUncompressed}, |
| 10786 | }, |
| 10787 | }, |
| 10788 | shouldFail: true, |
| 10789 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 10790 | }) |
| 10791 |
| 10792 | // Server-sent supported groups/curves are legal in TLS 1.3. They are |
| 10793 | // illegal in TLS 1.2, but some servers send them anyway, so we must |
| 10794 | // tolerate them. |
| 10795 | testCases = append(testCases, testCase{ |
| 10796 | name: "SupportedCurves-ServerHello-TLS12", |
| 10797 | config: Config{ |
| 10798 | MaxVersion: VersionTLS12, |
| 10799 | Bugs: ProtocolBugs{ |
| 10800 | SendServerSupportedCurves: true, |
| 10801 | }, |
| 10802 | }, |
| 10803 | }) |
| 10804 | testCases = append(testCases, testCase{ |
| 10805 | name: "SupportedCurves-EncryptedExtensions-TLS13", |
| 10806 | config: Config{ |
| 10807 | MaxVersion: VersionTLS13, |
| 10808 | Bugs: ProtocolBugs{ |
| 10809 | SendServerSupportedCurves: true, |
| 10810 | }, |
| 10811 | }, |
| 10812 | }) |
| 10813 |
| 10814 | // Test that we tolerate unknown point formats, as long as |
| 10815 | // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to |
| 10816 | // check they are still functional. |
| 10817 | testCases = append(testCases, testCase{ |
| 10818 | name: "PointFormat-Client-Tolerance", |
| 10819 | config: Config{ |
| 10820 | MaxVersion: VersionTLS12, |
| 10821 | Bugs: ProtocolBugs{ |
| 10822 | SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime}, |
| 10823 | }, |
| 10824 | }, |
| 10825 | }) |
| 10826 | testCases = append(testCases, testCase{ |
| 10827 | testType: serverTest, |
| 10828 | name: "PointFormat-Server-Tolerance", |
| 10829 | config: Config{ |
| 10830 | MaxVersion: VersionTLS12, |
| 10831 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 10832 | Bugs: ProtocolBugs{ |
| 10833 | SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime}, |
| 10834 | }, |
| 10835 | }, |
| 10836 | }) |
| 10837 |
| 10838 | // Test TLS 1.2 does not require the point format extension to be |
| 10839 | // present. |
| 10840 | testCases = append(testCases, testCase{ |
| 10841 | name: "PointFormat-Client-Missing", |
| 10842 | config: Config{ |
| 10843 | MaxVersion: VersionTLS12, |
| 10844 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 10845 | Bugs: ProtocolBugs{ |
| 10846 | SendSupportedPointFormats: []byte{}, |
| 10847 | }, |
| 10848 | }, |
| 10849 | }) |
| 10850 | testCases = append(testCases, testCase{ |
| 10851 | testType: serverTest, |
| 10852 | name: "PointFormat-Server-Missing", |
| 10853 | config: Config{ |
| 10854 | MaxVersion: VersionTLS12, |
| 10855 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256}, |
| 10856 | Bugs: ProtocolBugs{ |
| 10857 | SendSupportedPointFormats: []byte{}, |
| 10858 | }, |
| 10859 | }, |
| 10860 | }) |
| 10861 |
| 10862 | // If the point format extension is present, uncompressed points must be |
| 10863 | // offered. BoringSSL requires this whether or not ECDHE is used. |
| 10864 | testCases = append(testCases, testCase{ |
| 10865 | name: "PointFormat-Client-MissingUncompressed", |
| 10866 | config: Config{ |
| 10867 | MaxVersion: VersionTLS12, |
| 10868 | Bugs: ProtocolBugs{ |
| 10869 | SendSupportedPointFormats: []byte{pointFormatCompressedPrime}, |
| 10870 | }, |
| 10871 | }, |
| 10872 | shouldFail: true, |
| 10873 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 10874 | }) |
| 10875 | testCases = append(testCases, testCase{ |
| 10876 | testType: serverTest, |
| 10877 | name: "PointFormat-Server-MissingUncompressed", |
| 10878 | config: Config{ |
| 10879 | MaxVersion: VersionTLS12, |
| 10880 | Bugs: ProtocolBugs{ |
| 10881 | SendSupportedPointFormats: []byte{pointFormatCompressedPrime}, |
| 10882 | }, |
| 10883 | }, |
| 10884 | shouldFail: true, |
| 10885 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 10886 | }) |
| 10887 |
| 10888 | // Implementations should mask off the high order bit in X25519. |
| 10889 | testCases = append(testCases, testCase{ |
| 10890 | name: "SetX25519HighBit", |
| 10891 | config: Config{ |
| 10892 | CipherSuites: []uint16{ |
| 10893 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 10894 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 10895 | TLS_AES_128_GCM_SHA256, |
| 10896 | }, |
| 10897 | CurvePreferences: []CurveID{CurveX25519}, |
| 10898 | Bugs: ProtocolBugs{ |
| 10899 | SetX25519HighBit: true, |
| 10900 | }, |
| 10901 | }, |
| 10902 | }) |
| 10903 |
| 10904 | // CECPQ2 should not be offered by a TLS < 1.3 client. |
| 10905 | testCases = append(testCases, testCase{ |
| 10906 | name: "CECPQ2NotInTLS12", |
| 10907 | config: Config{ |
| 10908 | Bugs: ProtocolBugs{ |
| 10909 | FailIfCECPQ2Offered: true, |
| 10910 | }, |
| 10911 | }, |
| 10912 | flags: []string{ |
| 10913 | "-max-version", strconv.Itoa(VersionTLS12), |
| 10914 | "-curves", strconv.Itoa(int(CurveCECPQ2)), |
| 10915 | "-curves", strconv.Itoa(int(CurveX25519)), |
| 10916 | }, |
| 10917 | }) |
| 10918 |
| 10919 | // CECPQ2b should not be offered by a TLS < 1.3 client. |
| 10920 | testCases = append(testCases, testCase{ |
| 10921 | name: "CECPQ2bNotInTLS12", |
| 10922 | config: Config{ |
| 10923 | Bugs: ProtocolBugs{ |
| 10924 | FailIfCECPQ2Offered: true, |
| 10925 | }, |
| 10926 | }, |
| 10927 | flags: []string{ |
| 10928 | "-max-version", strconv.Itoa(VersionTLS12), |
| 10929 | "-curves", strconv.Itoa(int(CurveCECPQ2b)), |
| 10930 | "-curves", strconv.Itoa(int(CurveX25519)), |
| 10931 | }, |
| 10932 | }) |
| 10933 |
| 10934 | // CECPQ2 should not crash a TLS < 1.3 client if the server mistakenly |
| 10935 | // selects it. |
| 10936 | testCases = append(testCases, testCase{ |
| 10937 | name: "CECPQ2NotAcceptedByTLS12Client", |
| 10938 | config: Config{ |
| 10939 | Bugs: ProtocolBugs{ |
| 10940 | SendCurve: CurveCECPQ2, |
| 10941 | }, |
| 10942 | }, |
| 10943 | flags: []string{ |
| 10944 | "-max-version", strconv.Itoa(VersionTLS12), |
| 10945 | "-curves", strconv.Itoa(int(CurveCECPQ2)), |
| 10946 | "-curves", strconv.Itoa(int(CurveX25519)), |
| 10947 | }, |
| 10948 | shouldFail: true, |
| 10949 | expectedError: ":WRONG_CURVE:", |
| 10950 | }) |
| 10951 |
| 10952 | // CECPQ2b should not crash a TLS < 1.3 client if the server mistakenly |
| 10953 | // selects it. |
| 10954 | testCases = append(testCases, testCase{ |
| 10955 | name: "CECPQ2bNotAcceptedByTLS12Client", |
| 10956 | config: Config{ |
| 10957 | Bugs: ProtocolBugs{ |
| 10958 | SendCurve: CurveCECPQ2b, |
| 10959 | }, |
| 10960 | }, |
| 10961 | flags: []string{ |
| 10962 | "-max-version", strconv.Itoa(VersionTLS12), |
| 10963 | "-curves", strconv.Itoa(int(CurveCECPQ2b)), |
| 10964 | "-curves", strconv.Itoa(int(CurveX25519)), |
| 10965 | }, |
| 10966 | shouldFail: true, |
| 10967 | expectedError: ":WRONG_CURVE:", |
| 10968 | }) |
| 10969 |
| 10970 | // CECPQ2 should not be offered by default as a client. |
| 10971 | testCases = append(testCases, testCase{ |
| 10972 | name: "CECPQ2NotEnabledByDefaultInClients", |
| 10973 | config: Config{ |
| 10974 | MinVersion: VersionTLS13, |
| 10975 | Bugs: ProtocolBugs{ |
| 10976 | FailIfCECPQ2Offered: true, |
| 10977 | }, |
| 10978 | }, |
| 10979 | }) |
| 10980 |
| 10981 | // CECPQ2b should not be offered by default as a client. |
| 10982 | testCases = append(testCases, testCase{ |
| 10983 | name: "CECPQ2bNotEnabledByDefaultInClients", |
| 10984 | config: Config{ |
| 10985 | MinVersion: VersionTLS13, |
| 10986 | Bugs: ProtocolBugs{ |
| 10987 | FailIfCECPQ2Offered: true, |
| 10988 | }, |
| 10989 | }, |
| 10990 | }) |
| 10991 |
| 10992 | // If CECPQ2 is offered, both X25519 and CECPQ2 should have a key-share. |
| 10993 | testCases = append(testCases, testCase{ |
| 10994 | name: "NotJustCECPQ2KeyShare", |
| 10995 | config: Config{ |
| 10996 | MinVersion: VersionTLS13, |
| 10997 | Bugs: ProtocolBugs{ |
| 10998 | ExpectedKeyShares: []CurveID{CurveCECPQ2, CurveX25519}, |
| 10999 | }, |
| 11000 | }, |
| 11001 | flags: []string{ |
| 11002 | "-curves", strconv.Itoa(int(CurveCECPQ2)), |
| 11003 | "-curves", strconv.Itoa(int(CurveX25519)), |
| 11004 | "-expect-curve-id", strconv.Itoa(int(CurveCECPQ2)), |
| 11005 | }, |
| 11006 | }) |
| 11007 |
| 11008 | // ... but only if CECPQ2 is listed first. |
| 11009 | testCases = append(testCases, testCase{ |
| 11010 | name: "CECPQ2KeyShareNotIncludedSecond", |
| 11011 | config: Config{ |
| 11012 | MinVersion: VersionTLS13, |
| 11013 | Bugs: ProtocolBugs{ |
| 11014 | ExpectedKeyShares: []CurveID{CurveX25519}, |
| 11015 | }, |
| 11016 | }, |
| 11017 | flags: []string{ |
| 11018 | "-curves", strconv.Itoa(int(CurveX25519)), |
| 11019 | "-curves", strconv.Itoa(int(CurveCECPQ2)), |
| 11020 | "-expect-curve-id", strconv.Itoa(int(CurveX25519)), |
| 11021 | }, |
| 11022 | }) |
| 11023 |
| 11024 | // If CECPQ2b is offered, both X25519 and CECPQ2b should have a key-share. |
| 11025 | testCases = append(testCases, testCase{ |
| 11026 | name: "NotJustCECPQ2bKeyShare", |
| 11027 | config: Config{ |
| 11028 | MinVersion: VersionTLS13, |
| 11029 | Bugs: ProtocolBugs{ |
| 11030 | ExpectedKeyShares: []CurveID{CurveCECPQ2b, CurveX25519}, |
| 11031 | }, |
| 11032 | }, |
| 11033 | flags: []string{ |
| 11034 | "-curves", strconv.Itoa(int(CurveCECPQ2b)), |
| 11035 | "-curves", strconv.Itoa(int(CurveX25519)), |
| 11036 | "-expect-curve-id", strconv.Itoa(int(CurveCECPQ2b)), |
| 11037 | }, |
| 11038 | }) |
| 11039 |
| 11040 | // ... but only if CECPQ2b is listed first. |
| 11041 | testCases = append(testCases, testCase{ |
| 11042 | name: "CECPQ2bKeyShareNotIncludedSecond", |
| 11043 | config: Config{ |
| 11044 | MinVersion: VersionTLS13, |
| 11045 | Bugs: ProtocolBugs{ |
| 11046 | ExpectedKeyShares: []CurveID{CurveX25519}, |
| 11047 | }, |
| 11048 | }, |
| 11049 | flags: []string{ |
| 11050 | "-curves", strconv.Itoa(int(CurveX25519)), |
| 11051 | "-curves", strconv.Itoa(int(CurveCECPQ2b)), |
| 11052 | "-expect-curve-id", strconv.Itoa(int(CurveX25519)), |
| 11053 | }, |
| 11054 | }) |
| 11055 |
| 11056 | // If CECPQ2 is the only configured curve, the key share is sent. |
| 11057 | testCases = append(testCases, testCase{ |
| 11058 | name: "JustConfiguringCECPQ2Works", |
| 11059 | config: Config{ |
| 11060 | MinVersion: VersionTLS13, |
| 11061 | Bugs: ProtocolBugs{ |
| 11062 | ExpectedKeyShares: []CurveID{CurveCECPQ2}, |
| 11063 | }, |
| 11064 | }, |
| 11065 | flags: []string{ |
| 11066 | "-curves", strconv.Itoa(int(CurveCECPQ2)), |
| 11067 | "-expect-curve-id", strconv.Itoa(int(CurveCECPQ2)), |
| 11068 | }, |
| 11069 | }) |
| 11070 |
| 11071 | // If CECPQ2b is the only configured curve, the key share is sent. |
| 11072 | testCases = append(testCases, testCase{ |
| 11073 | name: "JustConfiguringCECPQ2bWorks", |
| 11074 | config: Config{ |
| 11075 | MinVersion: VersionTLS13, |
| 11076 | Bugs: ProtocolBugs{ |
| 11077 | ExpectedKeyShares: []CurveID{CurveCECPQ2b}, |
| 11078 | }, |
| 11079 | }, |
| 11080 | flags: []string{ |
| 11081 | "-curves", strconv.Itoa(int(CurveCECPQ2b)), |
| 11082 | "-expect-curve-id", strconv.Itoa(int(CurveCECPQ2b)), |
| 11083 | }, |
| 11084 | }) |
| 11085 |
| 11086 | // As a server, CECPQ2 is not yet supported by default. |
| 11087 | testCases = append(testCases, testCase{ |
| 11088 | testType: serverTest, |
| 11089 | name: "CECPQ2NotEnabledByDefaultForAServer", |
| 11090 | config: Config{ |
| 11091 | MinVersion: VersionTLS13, |
| 11092 | CurvePreferences: []CurveID{CurveCECPQ2, CurveX25519}, |
| 11093 | DefaultCurves: []CurveID{CurveCECPQ2}, |
| 11094 | }, |
| 11095 | flags: []string{ |
| 11096 | "-server-preference", |
| 11097 | "-expect-curve-id", strconv.Itoa(int(CurveX25519)), |
| 11098 | }, |
| 11099 | }) |
| 11100 |
| 11101 | // As a server, CECPQ2b is not yet supported by default. |
| 11102 | testCases = append(testCases, testCase{ |
| 11103 | testType: serverTest, |
| 11104 | name: "CECPQ2bNotEnabledByDefaultForAServer", |
| 11105 | config: Config{ |
| 11106 | MinVersion: VersionTLS13, |
| 11107 | CurvePreferences: []CurveID{CurveCECPQ2b, CurveX25519}, |
| 11108 | DefaultCurves: []CurveID{CurveCECPQ2b}, |
| 11109 | }, |
| 11110 | flags: []string{ |
| 11111 | "-server-preference", |
| 11112 | "-expect-curve-id", strconv.Itoa(int(CurveX25519)), |
| 11113 | }, |
| 11114 | }) |
| 11115 | } |
| 11116 |
| 11117 | func addTLS13RecordTests() { |
| 11118 | testCases = append(testCases, testCase{ |
| 11119 | name: "TLS13-RecordPadding", |
| 11120 | config: Config{ |
| 11121 | MaxVersion: VersionTLS13, |
| 11122 | MinVersion: VersionTLS13, |
| 11123 | Bugs: ProtocolBugs{ |
| 11124 | RecordPadding: 10, |
| 11125 | }, |
| 11126 | }, |
| 11127 | }) |
| 11128 |
| 11129 | testCases = append(testCases, testCase{ |
| 11130 | name: "TLS13-EmptyRecords", |
| 11131 | config: Config{ |
| 11132 | MaxVersion: VersionTLS13, |
| 11133 | MinVersion: VersionTLS13, |
| 11134 | Bugs: ProtocolBugs{ |
| 11135 | OmitRecordContents: true, |
| 11136 | }, |
| 11137 | }, |
| 11138 | shouldFail: true, |
| 11139 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 11140 | }) |
| 11141 |
| 11142 | testCases = append(testCases, testCase{ |
| 11143 | name: "TLS13-OnlyPadding", |
| 11144 | config: Config{ |
| 11145 | MaxVersion: VersionTLS13, |
| 11146 | MinVersion: VersionTLS13, |
| 11147 | Bugs: ProtocolBugs{ |
| 11148 | OmitRecordContents: true, |
| 11149 | RecordPadding: 10, |
| 11150 | }, |
| 11151 | }, |
| 11152 | shouldFail: true, |
| 11153 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 11154 | }) |
| 11155 |
| 11156 | testCases = append(testCases, testCase{ |
| 11157 | name: "TLS13-WrongOuterRecord", |
| 11158 | config: Config{ |
| 11159 | MaxVersion: VersionTLS13, |
| 11160 | MinVersion: VersionTLS13, |
| 11161 | Bugs: ProtocolBugs{ |
| 11162 | OuterRecordType: recordTypeHandshake, |
| 11163 | }, |
| 11164 | }, |
| 11165 | shouldFail: true, |
| 11166 | expectedError: ":INVALID_OUTER_RECORD_TYPE:", |
| 11167 | }) |
| 11168 | } |
| 11169 |
| 11170 | func addSessionTicketTests() { |
| 11171 | testCases = append(testCases, testCase{ |
| 11172 | // In TLS 1.2 and below, empty NewSessionTicket messages |
| 11173 | // mean the server changed its mind on sending a ticket. |
| 11174 | name: "SendEmptySessionTicket", |
| 11175 | config: Config{ |
| 11176 | MaxVersion: VersionTLS12, |
| 11177 | Bugs: ProtocolBugs{ |
| 11178 | SendEmptySessionTicket: true, |
| 11179 | }, |
| 11180 | }, |
| 11181 | flags: []string{"-expect-no-session"}, |
| 11182 | }) |
| 11183 |
| 11184 | // Test that the server ignores unknown PSK modes. |
| 11185 | testCases = append(testCases, testCase{ |
| 11186 | testType: serverTest, |
| 11187 | name: "TLS13-SendUnknownModeSessionTicket-Server", |
| 11188 | config: Config{ |
| 11189 | MaxVersion: VersionTLS13, |
| 11190 | Bugs: ProtocolBugs{ |
| 11191 | SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a}, |
| 11192 | }, |
| 11193 | }, |
| 11194 | resumeSession: true, |
| 11195 | expectedResumeVersion: VersionTLS13, |
| 11196 | }) |
| 11197 |
| 11198 | // Test that the server does not send session tickets with no matching key exchange mode. |
| 11199 | testCases = append(testCases, testCase{ |
| 11200 | testType: serverTest, |
| 11201 | name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server", |
| 11202 | config: Config{ |
| 11203 | MaxVersion: VersionTLS13, |
| 11204 | Bugs: ProtocolBugs{ |
| 11205 | SendPSKKeyExchangeModes: []byte{0x1a}, |
| 11206 | ExpectNoNewSessionTicket: true, |
| 11207 | }, |
| 11208 | }, |
| 11209 | }) |
| 11210 |
| 11211 | // Test that the server does not accept a session with no matching key exchange mode. |
| 11212 | testCases = append(testCases, testCase{ |
| 11213 | testType: serverTest, |
| 11214 | name: "TLS13-SendBadKEModeSessionTicket-Server", |
| 11215 | config: Config{ |
| 11216 | MaxVersion: VersionTLS13, |
| 11217 | }, |
| 11218 | resumeConfig: &Config{ |
| 11219 | MaxVersion: VersionTLS13, |
| 11220 | Bugs: ProtocolBugs{ |
| 11221 | SendPSKKeyExchangeModes: []byte{0x1a}, |
| 11222 | }, |
| 11223 | }, |
| 11224 | resumeSession: true, |
| 11225 | expectResumeRejected: true, |
| 11226 | }) |
| 11227 |
| 11228 | // Test that the client ticket age is sent correctly. |
| 11229 | testCases = append(testCases, testCase{ |
| 11230 | testType: clientTest, |
| 11231 | name: "TLS13-TestValidTicketAge-Client", |
| 11232 | config: Config{ |
| 11233 | MaxVersion: VersionTLS13, |
| 11234 | Bugs: ProtocolBugs{ |
| 11235 | ExpectTicketAge: 10 * time.Second, |
| 11236 | }, |
| 11237 | }, |
| 11238 | resumeSession: true, |
| 11239 | flags: []string{ |
| 11240 | "-resumption-delay", "10", |
| 11241 | }, |
| 11242 | }) |
| 11243 |
| 11244 | // Test that the client ticket age is enforced. |
| 11245 | testCases = append(testCases, testCase{ |
| 11246 | testType: clientTest, |
| 11247 | name: "TLS13-TestBadTicketAge-Client", |
| 11248 | config: Config{ |
| 11249 | MaxVersion: VersionTLS13, |
| 11250 | Bugs: ProtocolBugs{ |
| 11251 | ExpectTicketAge: 1000 * time.Second, |
| 11252 | }, |
| 11253 | }, |
| 11254 | resumeSession: true, |
| 11255 | shouldFail: true, |
| 11256 | expectedLocalError: "tls: invalid ticket age", |
| 11257 | }) |
| 11258 |
| 11259 | // Test that the server's ticket age skew reporting works. |
| 11260 | testCases = append(testCases, testCase{ |
| 11261 | testType: serverTest, |
| 11262 | name: "TLS13-TicketAgeSkew-Forward", |
| 11263 | config: Config{ |
| 11264 | MaxVersion: VersionTLS13, |
| 11265 | Bugs: ProtocolBugs{ |
| 11266 | SendTicketAge: 15 * time.Second, |
| 11267 | }, |
| 11268 | }, |
| 11269 | resumeSession: true, |
| 11270 | resumeRenewedSession: true, |
| 11271 | flags: []string{ |
| 11272 | "-resumption-delay", "10", |
| 11273 | "-expect-ticket-age-skew", "5", |
| 11274 | }, |
| 11275 | }) |
| 11276 | testCases = append(testCases, testCase{ |
| 11277 | testType: serverTest, |
| 11278 | name: "TLS13-TicketAgeSkew-Backward", |
| 11279 | config: Config{ |
| 11280 | MaxVersion: VersionTLS13, |
| 11281 | Bugs: ProtocolBugs{ |
| 11282 | SendTicketAge: 5 * time.Second, |
| 11283 | }, |
| 11284 | }, |
| 11285 | resumeSession: true, |
| 11286 | resumeRenewedSession: true, |
| 11287 | flags: []string{ |
| 11288 | "-resumption-delay", "10", |
| 11289 | "-expect-ticket-age-skew", "-5", |
| 11290 | }, |
| 11291 | }) |
| 11292 |
| 11293 | // Test that ticket age skew up to 60 seconds in either direction is accepted. |
| 11294 | testCases = append(testCases, testCase{ |
| 11295 | testType: serverTest, |
| 11296 | name: "TLS13-TicketAgeSkew-Forward-60-Accept", |
| 11297 | config: Config{ |
| 11298 | MaxVersion: VersionTLS13, |
| 11299 | Bugs: ProtocolBugs{ |
| 11300 | SendTicketAge: 70 * time.Second, |
| 11301 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 11302 | ExpectEarlyDataAccepted: true, |
| 11303 | ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}}, |
| 11304 | }, |
| 11305 | }, |
| 11306 | resumeSession: true, |
| 11307 | flags: []string{ |
| 11308 | "-resumption-delay", "10", |
| 11309 | "-expect-ticket-age-skew", "60", |
| 11310 | // 0-RTT is accepted. |
| 11311 | "-enable-early-data", |
| 11312 | "-on-resume-expect-accept-early-data", |
| 11313 | "-on-resume-expect-early-data-reason", "accept", |
| 11314 | }, |
| 11315 | }) |
| 11316 | testCases = append(testCases, testCase{ |
| 11317 | testType: serverTest, |
| 11318 | name: "TLS13-TicketAgeSkew-Backward-60-Accept", |
| 11319 | config: Config{ |
| 11320 | MaxVersion: VersionTLS13, |
| 11321 | Bugs: ProtocolBugs{ |
| 11322 | SendTicketAge: 10 * time.Second, |
| 11323 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 11324 | ExpectEarlyDataAccepted: true, |
| 11325 | ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}}, |
| 11326 | }, |
| 11327 | }, |
| 11328 | resumeSession: true, |
| 11329 | flags: []string{ |
| 11330 | "-resumption-delay", "70", |
| 11331 | "-expect-ticket-age-skew", "-60", |
| 11332 | // 0-RTT is accepted. |
| 11333 | "-enable-early-data", |
| 11334 | "-on-resume-expect-accept-early-data", |
| 11335 | "-on-resume-expect-early-data-reason", "accept", |
| 11336 | }, |
| 11337 | }) |
| 11338 |
| 11339 | // Test that ticket age skew beyond 60 seconds in either direction is rejected. |
| 11340 | testCases = append(testCases, testCase{ |
| 11341 | testType: serverTest, |
| 11342 | name: "TLS13-TicketAgeSkew-Forward-61-Reject", |
| 11343 | config: Config{ |
| 11344 | MaxVersion: VersionTLS13, |
| 11345 | Bugs: ProtocolBugs{ |
| 11346 | SendTicketAge: 71 * time.Second, |
| 11347 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 11348 | ExpectEarlyDataAccepted: false, |
| 11349 | }, |
| 11350 | }, |
| 11351 | resumeSession: true, |
| 11352 | flags: []string{ |
| 11353 | "-resumption-delay", "10", |
| 11354 | "-expect-ticket-age-skew", "61", |
| 11355 | // 0-RTT is rejected. |
| 11356 | "-enable-early-data", |
| 11357 | "-expect-reject-early-data", |
| 11358 | "-on-resume-expect-early-data-reason", "ticket_age_skew", |
| 11359 | }, |
| 11360 | }) |
| 11361 | testCases = append(testCases, testCase{ |
| 11362 | testType: serverTest, |
| 11363 | name: "TLS13-TicketAgeSkew-Backward-61-Reject", |
| 11364 | config: Config{ |
| 11365 | MaxVersion: VersionTLS13, |
| 11366 | Bugs: ProtocolBugs{ |
| 11367 | SendTicketAge: 10 * time.Second, |
| 11368 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 11369 | ExpectEarlyDataAccepted: false, |
| 11370 | }, |
| 11371 | }, |
| 11372 | resumeSession: true, |
| 11373 | flags: []string{ |
| 11374 | "-resumption-delay", "71", |
| 11375 | "-expect-ticket-age-skew", "-61", |
| 11376 | // 0-RTT is rejected. |
| 11377 | "-enable-early-data", |
| 11378 | "-expect-reject-early-data", |
| 11379 | "-on-resume-expect-early-data-reason", "ticket_age_skew", |
| 11380 | }, |
| 11381 | }) |
| 11382 |
| 11383 | testCases = append(testCases, testCase{ |
| 11384 | testType: clientTest, |
| 11385 | name: "TLS13-SendTicketEarlyDataSupport", |
| 11386 | config: Config{ |
| 11387 | MaxVersion: VersionTLS13, |
| 11388 | MaxEarlyDataSize: 16384, |
| 11389 | }, |
| 11390 | flags: []string{ |
| 11391 | "-enable-early-data", |
| 11392 | "-expect-ticket-supports-early-data", |
| 11393 | }, |
| 11394 | }) |
| 11395 |
| 11396 | // Test that 0-RTT tickets are still recorded as such when early data is disabled overall. |
| 11397 | testCases = append(testCases, testCase{ |
| 11398 | testType: clientTest, |
| 11399 | name: "TLS13-SendTicketEarlyDataSupport-Disabled", |
| 11400 | config: Config{ |
| 11401 | MaxVersion: VersionTLS13, |
| 11402 | MaxEarlyDataSize: 16384, |
| 11403 | }, |
| 11404 | flags: []string{ |
| 11405 | "-expect-ticket-supports-early-data", |
| 11406 | }, |
| 11407 | }) |
| 11408 |
| 11409 | testCases = append(testCases, testCase{ |
| 11410 | testType: clientTest, |
| 11411 | name: "TLS13-DuplicateTicketEarlyDataSupport", |
| 11412 | config: Config{ |
| 11413 | MaxVersion: VersionTLS13, |
| 11414 | MaxEarlyDataSize: 16384, |
| 11415 | Bugs: ProtocolBugs{ |
| 11416 | DuplicateTicketEarlyData: true, |
| 11417 | }, |
| 11418 | }, |
| 11419 | shouldFail: true, |
| 11420 | expectedError: ":DUPLICATE_EXTENSION:", |
| 11421 | expectedLocalError: "remote error: illegal parameter", |
| 11422 | }) |
| 11423 |
| 11424 | testCases = append(testCases, testCase{ |
| 11425 | testType: serverTest, |
| 11426 | name: "TLS13-ExpectTicketEarlyDataSupport", |
| 11427 | config: Config{ |
| 11428 | MaxVersion: VersionTLS13, |
| 11429 | Bugs: ProtocolBugs{ |
| 11430 | ExpectTicketEarlyData: true, |
| 11431 | }, |
| 11432 | }, |
| 11433 | flags: []string{ |
| 11434 | "-enable-early-data", |
| 11435 | }, |
| 11436 | }) |
| 11437 |
| 11438 | // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime |
| 11439 | // is honored. |
| 11440 | testCases = append(testCases, testCase{ |
| 11441 | testType: clientTest, |
| 11442 | name: "TLS13-HonorServerSessionTicketLifetime", |
| 11443 | config: Config{ |
| 11444 | MaxVersion: VersionTLS13, |
| 11445 | Bugs: ProtocolBugs{ |
| 11446 | SendTicketLifetime: 20 * time.Second, |
| 11447 | }, |
| 11448 | }, |
| 11449 | flags: []string{ |
| 11450 | "-resumption-delay", "19", |
| 11451 | }, |
| 11452 | resumeSession: true, |
| 11453 | }) |
| 11454 | testCases = append(testCases, testCase{ |
| 11455 | testType: clientTest, |
| 11456 | name: "TLS13-HonorServerSessionTicketLifetime-2", |
| 11457 | config: Config{ |
| 11458 | MaxVersion: VersionTLS13, |
| 11459 | Bugs: ProtocolBugs{ |
| 11460 | SendTicketLifetime: 20 * time.Second, |
| 11461 | // The client should not offer the expired session. |
| 11462 | ExpectNoTLS13PSK: true, |
| 11463 | }, |
| 11464 | }, |
| 11465 | flags: []string{ |
| 11466 | "-resumption-delay", "21", |
| 11467 | }, |
| 11468 | resumeSession: true, |
| 11469 | expectResumeRejected: true, |
| 11470 | }) |
| 11471 |
| 11472 | for _, ver := range tlsVersions { |
| 11473 | // Prior to TLS 1.3, disabling session tickets enables session IDs. |
| 11474 | useStatefulResumption := ver.version < VersionTLS13 |
| 11475 |
| 11476 | // SSL_OP_NO_TICKET implies the server must not mint any tickets. |
| 11477 | testCases = append(testCases, testCase{ |
| 11478 | testType: serverTest, |
| 11479 | name: ver.name + "-NoTicket-NoMint", |
| 11480 | config: Config{ |
| 11481 | MinVersion: ver.version, |
| 11482 | MaxVersion: ver.version, |
| 11483 | Bugs: ProtocolBugs{ |
| 11484 | ExpectNoNewSessionTicket: true, |
| 11485 | RequireSessionIDs: useStatefulResumption, |
| 11486 | }, |
| 11487 | }, |
| 11488 | resumeSession: useStatefulResumption, |
| 11489 | flags: []string{"-no-ticket"}, |
| 11490 | }) |
| 11491 |
| 11492 | // SSL_OP_NO_TICKET implies the server must not accept any tickets. |
| 11493 | testCases = append(testCases, testCase{ |
| 11494 | testType: serverTest, |
| 11495 | name: ver.name + "-NoTicket-NoAccept", |
| 11496 | config: Config{ |
| 11497 | MinVersion: ver.version, |
| 11498 | MaxVersion: ver.version, |
| 11499 | }, |
| 11500 | resumeSession: true, |
| 11501 | expectResumeRejected: true, |
| 11502 | // Set SSL_OP_NO_TICKET on the second connection, after the first |
| 11503 | // has established tickets. |
| 11504 | flags: []string{"-on-resume-no-ticket"}, |
| 11505 | }) |
| 11506 | } |
| 11507 | } |
| 11508 |
| 11509 | func addChangeCipherSpecTests() { |
| 11510 | // Test missing ChangeCipherSpecs. |
| 11511 | testCases = append(testCases, testCase{ |
| 11512 | name: "SkipChangeCipherSpec-Client", |
| 11513 | config: Config{ |
| 11514 | MaxVersion: VersionTLS12, |
| 11515 | Bugs: ProtocolBugs{ |
| 11516 | SkipChangeCipherSpec: true, |
| 11517 | }, |
| 11518 | }, |
| 11519 | shouldFail: true, |
| 11520 | expectedError: ":UNEXPECTED_RECORD:", |
| 11521 | }) |
| 11522 | testCases = append(testCases, testCase{ |
| 11523 | testType: serverTest, |
| 11524 | name: "SkipChangeCipherSpec-Server", |
| 11525 | config: Config{ |
| 11526 | MaxVersion: VersionTLS12, |
| 11527 | Bugs: ProtocolBugs{ |
| 11528 | SkipChangeCipherSpec: true, |
| 11529 | }, |
| 11530 | }, |
| 11531 | shouldFail: true, |
| 11532 | expectedError: ":UNEXPECTED_RECORD:", |
| 11533 | }) |
| 11534 | testCases = append(testCases, testCase{ |
| 11535 | testType: serverTest, |
| 11536 | name: "SkipChangeCipherSpec-Server-NPN", |
| 11537 | config: Config{ |
| 11538 | MaxVersion: VersionTLS12, |
| 11539 | NextProtos: []string{"bar"}, |
| 11540 | Bugs: ProtocolBugs{ |
| 11541 | SkipChangeCipherSpec: true, |
| 11542 | }, |
| 11543 | }, |
| 11544 | flags: []string{ |
| 11545 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 11546 | }, |
| 11547 | shouldFail: true, |
| 11548 | expectedError: ":UNEXPECTED_RECORD:", |
| 11549 | }) |
| 11550 |
| 11551 | // Test synchronization between the handshake and ChangeCipherSpec. |
| 11552 | // Partial post-CCS handshake messages before ChangeCipherSpec should be |
| 11553 | // rejected. Test both with and without handshake packing to handle both |
| 11554 | // when the partial post-CCS message is in its own record and when it is |
| 11555 | // attached to the pre-CCS message. |
| 11556 | for _, packed := range []bool{false, true} { |
| 11557 | var suffix string |
| 11558 | if packed { |
| 11559 | suffix = "-Packed" |
| 11560 | } |
| 11561 |
| 11562 | testCases = append(testCases, testCase{ |
| 11563 | name: "FragmentAcrossChangeCipherSpec-Client" + suffix, |
| 11564 | config: Config{ |
| 11565 | MaxVersion: VersionTLS12, |
| 11566 | Bugs: ProtocolBugs{ |
| 11567 | FragmentAcrossChangeCipherSpec: true, |
| 11568 | PackHandshakeFlight: packed, |
| 11569 | }, |
| 11570 | }, |
| 11571 | shouldFail: true, |
| 11572 | expectedError: ":UNEXPECTED_RECORD:", |
| 11573 | }) |
| 11574 | testCases = append(testCases, testCase{ |
| 11575 | name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix, |
| 11576 | config: Config{ |
| 11577 | MaxVersion: VersionTLS12, |
| 11578 | }, |
| 11579 | resumeSession: true, |
| 11580 | resumeConfig: &Config{ |
| 11581 | MaxVersion: VersionTLS12, |
| 11582 | Bugs: ProtocolBugs{ |
| 11583 | FragmentAcrossChangeCipherSpec: true, |
| 11584 | PackHandshakeFlight: packed, |
| 11585 | }, |
| 11586 | }, |
| 11587 | shouldFail: true, |
| 11588 | expectedError: ":UNEXPECTED_RECORD:", |
| 11589 | }) |
| 11590 | testCases = append(testCases, testCase{ |
| 11591 | testType: serverTest, |
| 11592 | name: "FragmentAcrossChangeCipherSpec-Server" + suffix, |
| 11593 | config: Config{ |
| 11594 | MaxVersion: VersionTLS12, |
| 11595 | Bugs: ProtocolBugs{ |
| 11596 | FragmentAcrossChangeCipherSpec: true, |
| 11597 | PackHandshakeFlight: packed, |
| 11598 | }, |
| 11599 | }, |
| 11600 | shouldFail: true, |
| 11601 | expectedError: ":UNEXPECTED_RECORD:", |
| 11602 | }) |
| 11603 | testCases = append(testCases, testCase{ |
| 11604 | testType: serverTest, |
| 11605 | name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix, |
| 11606 | config: Config{ |
| 11607 | MaxVersion: VersionTLS12, |
| 11608 | }, |
| 11609 | resumeSession: true, |
| 11610 | resumeConfig: &Config{ |
| 11611 | MaxVersion: VersionTLS12, |
| 11612 | Bugs: ProtocolBugs{ |
| 11613 | FragmentAcrossChangeCipherSpec: true, |
| 11614 | PackHandshakeFlight: packed, |
| 11615 | }, |
| 11616 | }, |
| 11617 | shouldFail: true, |
| 11618 | expectedError: ":UNEXPECTED_RECORD:", |
| 11619 | }) |
| 11620 | testCases = append(testCases, testCase{ |
| 11621 | testType: serverTest, |
| 11622 | name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix, |
| 11623 | config: Config{ |
| 11624 | MaxVersion: VersionTLS12, |
| 11625 | NextProtos: []string{"bar"}, |
| 11626 | Bugs: ProtocolBugs{ |
| 11627 | FragmentAcrossChangeCipherSpec: true, |
| 11628 | PackHandshakeFlight: packed, |
| 11629 | }, |
| 11630 | }, |
| 11631 | flags: []string{ |
| 11632 | "-advertise-npn", "\x03foo\x03bar\x03baz", |
| 11633 | }, |
| 11634 | shouldFail: true, |
| 11635 | expectedError: ":UNEXPECTED_RECORD:", |
| 11636 | }) |
| 11637 | } |
| 11638 |
| 11639 | // Test that, in DTLS, ChangeCipherSpec is not allowed when there are |
| 11640 | // messages in the handshake queue. Do this by testing the server |
| 11641 | // reading the client Finished, reversing the flight so Finished comes |
| 11642 | // first. |
| 11643 | testCases = append(testCases, testCase{ |
| 11644 | protocol: dtls, |
| 11645 | testType: serverTest, |
| 11646 | name: "SendUnencryptedFinished-DTLS", |
| 11647 | config: Config{ |
| 11648 | MaxVersion: VersionTLS12, |
| 11649 | Bugs: ProtocolBugs{ |
| 11650 | SendUnencryptedFinished: true, |
| 11651 | ReverseHandshakeFragments: true, |
| 11652 | }, |
| 11653 | }, |
| 11654 | shouldFail: true, |
| 11655 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 11656 | }) |
| 11657 |
| 11658 | // Test synchronization between encryption changes and the handshake in |
| 11659 | // TLS 1.3, where ChangeCipherSpec is implicit. |
| 11660 | testCases = append(testCases, testCase{ |
| 11661 | name: "PartialEncryptedExtensionsWithServerHello", |
| 11662 | config: Config{ |
| 11663 | MaxVersion: VersionTLS13, |
| 11664 | Bugs: ProtocolBugs{ |
| 11665 | PartialEncryptedExtensionsWithServerHello: true, |
| 11666 | }, |
| 11667 | }, |
| 11668 | shouldFail: true, |
| 11669 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 11670 | }) |
| 11671 | testCases = append(testCases, testCase{ |
| 11672 | testType: serverTest, |
| 11673 | name: "PartialClientFinishedWithClientHello", |
| 11674 | config: Config{ |
| 11675 | MaxVersion: VersionTLS13, |
| 11676 | Bugs: ProtocolBugs{ |
| 11677 | PartialClientFinishedWithClientHello: true, |
| 11678 | }, |
| 11679 | }, |
| 11680 | shouldFail: true, |
| 11681 | expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:", |
| 11682 | }) |
| 11683 |
| 11684 | // Test that early ChangeCipherSpecs are handled correctly. |
| 11685 | testCases = append(testCases, testCase{ |
| 11686 | testType: serverTest, |
| 11687 | name: "EarlyChangeCipherSpec-server-1", |
| 11688 | config: Config{ |
| 11689 | MaxVersion: VersionTLS12, |
| 11690 | Bugs: ProtocolBugs{ |
| 11691 | EarlyChangeCipherSpec: 1, |
| 11692 | }, |
| 11693 | }, |
| 11694 | shouldFail: true, |
| 11695 | expectedError: ":UNEXPECTED_RECORD:", |
| 11696 | }) |
| 11697 | testCases = append(testCases, testCase{ |
| 11698 | testType: serverTest, |
| 11699 | name: "EarlyChangeCipherSpec-server-2", |
| 11700 | config: Config{ |
| 11701 | MaxVersion: VersionTLS12, |
| 11702 | Bugs: ProtocolBugs{ |
| 11703 | EarlyChangeCipherSpec: 2, |
| 11704 | }, |
| 11705 | }, |
| 11706 | shouldFail: true, |
| 11707 | expectedError: ":UNEXPECTED_RECORD:", |
| 11708 | }) |
| 11709 | testCases = append(testCases, testCase{ |
| 11710 | protocol: dtls, |
| 11711 | name: "StrayChangeCipherSpec", |
| 11712 | config: Config{ |
| 11713 | // TODO(davidben): Once DTLS 1.3 exists, test |
| 11714 | // that stray ChangeCipherSpec messages are |
| 11715 | // rejected. |
| 11716 | MaxVersion: VersionTLS12, |
| 11717 | Bugs: ProtocolBugs{ |
| 11718 | StrayChangeCipherSpec: true, |
| 11719 | }, |
| 11720 | }, |
| 11721 | }) |
| 11722 |
| 11723 | // Test that reordered ChangeCipherSpecs are tolerated. |
| 11724 | testCases = append(testCases, testCase{ |
| 11725 | protocol: dtls, |
| 11726 | name: "ReorderChangeCipherSpec-DTLS-Client", |
| 11727 | config: Config{ |
| 11728 | MaxVersion: VersionTLS12, |
| 11729 | Bugs: ProtocolBugs{ |
| 11730 | ReorderChangeCipherSpec: true, |
| 11731 | }, |
| 11732 | }, |
| 11733 | resumeSession: true, |
| 11734 | }) |
| 11735 | testCases = append(testCases, testCase{ |
| 11736 | testType: serverTest, |
| 11737 | protocol: dtls, |
| 11738 | name: "ReorderChangeCipherSpec-DTLS-Server", |
| 11739 | config: Config{ |
| 11740 | MaxVersion: VersionTLS12, |
| 11741 | Bugs: ProtocolBugs{ |
| 11742 | ReorderChangeCipherSpec: true, |
| 11743 | }, |
| 11744 | }, |
| 11745 | resumeSession: true, |
| 11746 | }) |
| 11747 |
| 11748 | // Test that the contents of ChangeCipherSpec are checked. |
| 11749 | testCases = append(testCases, testCase{ |
| 11750 | name: "BadChangeCipherSpec-1", |
| 11751 | config: Config{ |
| 11752 | MaxVersion: VersionTLS12, |
| 11753 | Bugs: ProtocolBugs{ |
| 11754 | BadChangeCipherSpec: []byte{2}, |
| 11755 | }, |
| 11756 | }, |
| 11757 | shouldFail: true, |
| 11758 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 11759 | }) |
| 11760 | testCases = append(testCases, testCase{ |
| 11761 | name: "BadChangeCipherSpec-2", |
| 11762 | config: Config{ |
| 11763 | MaxVersion: VersionTLS12, |
| 11764 | Bugs: ProtocolBugs{ |
| 11765 | BadChangeCipherSpec: []byte{1, 1}, |
| 11766 | }, |
| 11767 | }, |
| 11768 | shouldFail: true, |
| 11769 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 11770 | }) |
| 11771 | testCases = append(testCases, testCase{ |
| 11772 | protocol: dtls, |
| 11773 | name: "BadChangeCipherSpec-DTLS-1", |
| 11774 | config: Config{ |
| 11775 | MaxVersion: VersionTLS12, |
| 11776 | Bugs: ProtocolBugs{ |
| 11777 | BadChangeCipherSpec: []byte{2}, |
| 11778 | }, |
| 11779 | }, |
| 11780 | shouldFail: true, |
| 11781 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 11782 | }) |
| 11783 | testCases = append(testCases, testCase{ |
| 11784 | protocol: dtls, |
| 11785 | name: "BadChangeCipherSpec-DTLS-2", |
| 11786 | config: Config{ |
| 11787 | MaxVersion: VersionTLS12, |
| 11788 | Bugs: ProtocolBugs{ |
| 11789 | BadChangeCipherSpec: []byte{1, 1}, |
| 11790 | }, |
| 11791 | }, |
| 11792 | shouldFail: true, |
| 11793 | expectedError: ":BAD_CHANGE_CIPHER_SPEC:", |
| 11794 | }) |
| 11795 | } |
| 11796 |
| 11797 | type perMessageTest struct { |
| 11798 | messageType uint8 |
| 11799 | test testCase |
| 11800 | } |
| 11801 |
| 11802 | // makePerMessageTests returns a series of test templates which cover each |
| 11803 | // message in the TLS handshake. These may be used with bugs like |
| 11804 | // WrongMessageType to fully test a per-message bug. |
| 11805 | func makePerMessageTests() []perMessageTest { |
| 11806 | var ret []perMessageTest |
| 11807 | for _, protocol := range []protocol{tls, dtls} { |
| 11808 | var suffix string |
| 11809 | if protocol == dtls { |
| 11810 | suffix = "-DTLS" |
| 11811 | } |
| 11812 |
| 11813 | ret = append(ret, perMessageTest{ |
| 11814 | messageType: typeClientHello, |
| 11815 | test: testCase{ |
| 11816 | protocol: protocol, |
| 11817 | testType: serverTest, |
| 11818 | name: "ClientHello" + suffix, |
| 11819 | config: Config{ |
| 11820 | MaxVersion: VersionTLS12, |
| 11821 | }, |
| 11822 | }, |
| 11823 | }) |
| 11824 |
| 11825 | if protocol == dtls { |
| 11826 | ret = append(ret, perMessageTest{ |
| 11827 | messageType: typeHelloVerifyRequest, |
| 11828 | test: testCase{ |
| 11829 | protocol: protocol, |
| 11830 | name: "HelloVerifyRequest" + suffix, |
| 11831 | config: Config{ |
| 11832 | MaxVersion: VersionTLS12, |
| 11833 | }, |
| 11834 | }, |
| 11835 | }) |
| 11836 | } |
| 11837 |
| 11838 | ret = append(ret, perMessageTest{ |
| 11839 | messageType: typeServerHello, |
| 11840 | test: testCase{ |
| 11841 | protocol: protocol, |
| 11842 | name: "ServerHello" + suffix, |
| 11843 | config: Config{ |
| 11844 | MaxVersion: VersionTLS12, |
| 11845 | }, |
| 11846 | }, |
| 11847 | }) |
| 11848 |
| 11849 | ret = append(ret, perMessageTest{ |
| 11850 | messageType: typeCertificate, |
| 11851 | test: testCase{ |
| 11852 | protocol: protocol, |
| 11853 | name: "ServerCertificate" + suffix, |
| 11854 | config: Config{ |
| 11855 | MaxVersion: VersionTLS12, |
| 11856 | }, |
| 11857 | }, |
| 11858 | }) |
| 11859 |
| 11860 | ret = append(ret, perMessageTest{ |
| 11861 | messageType: typeCertificateStatus, |
| 11862 | test: testCase{ |
| 11863 | protocol: protocol, |
| 11864 | name: "CertificateStatus" + suffix, |
| 11865 | config: Config{ |
| 11866 | MaxVersion: VersionTLS12, |
| 11867 | }, |
| 11868 | flags: []string{"-enable-ocsp-stapling"}, |
| 11869 | }, |
| 11870 | }) |
| 11871 |
| 11872 | ret = append(ret, perMessageTest{ |
| 11873 | messageType: typeServerKeyExchange, |
| 11874 | test: testCase{ |
| 11875 | protocol: protocol, |
| 11876 | name: "ServerKeyExchange" + suffix, |
| 11877 | config: Config{ |
| 11878 | MaxVersion: VersionTLS12, |
| 11879 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 11880 | }, |
| 11881 | }, |
| 11882 | }) |
| 11883 |
| 11884 | ret = append(ret, perMessageTest{ |
| 11885 | messageType: typeCertificateRequest, |
| 11886 | test: testCase{ |
| 11887 | protocol: protocol, |
| 11888 | name: "CertificateRequest" + suffix, |
| 11889 | config: Config{ |
| 11890 | MaxVersion: VersionTLS12, |
| 11891 | ClientAuth: RequireAnyClientCert, |
| 11892 | }, |
| 11893 | }, |
| 11894 | }) |
| 11895 |
| 11896 | ret = append(ret, perMessageTest{ |
| 11897 | messageType: typeServerHelloDone, |
| 11898 | test: testCase{ |
| 11899 | protocol: protocol, |
| 11900 | name: "ServerHelloDone" + suffix, |
| 11901 | config: Config{ |
| 11902 | MaxVersion: VersionTLS12, |
| 11903 | }, |
| 11904 | }, |
| 11905 | }) |
| 11906 |
| 11907 | ret = append(ret, perMessageTest{ |
| 11908 | messageType: typeCertificate, |
| 11909 | test: testCase{ |
| 11910 | testType: serverTest, |
| 11911 | protocol: protocol, |
| 11912 | name: "ClientCertificate" + suffix, |
| 11913 | config: Config{ |
| 11914 | Certificates: []Certificate{rsaCertificate}, |
| 11915 | MaxVersion: VersionTLS12, |
| 11916 | }, |
| 11917 | flags: []string{"-require-any-client-certificate"}, |
| 11918 | }, |
| 11919 | }) |
| 11920 |
| 11921 | ret = append(ret, perMessageTest{ |
| 11922 | messageType: typeCertificateVerify, |
| 11923 | test: testCase{ |
| 11924 | testType: serverTest, |
| 11925 | protocol: protocol, |
| 11926 | name: "CertificateVerify" + suffix, |
| 11927 | config: Config{ |
| 11928 | Certificates: []Certificate{rsaCertificate}, |
| 11929 | MaxVersion: VersionTLS12, |
| 11930 | }, |
| 11931 | flags: []string{"-require-any-client-certificate"}, |
| 11932 | }, |
| 11933 | }) |
| 11934 |
| 11935 | ret = append(ret, perMessageTest{ |
| 11936 | messageType: typeClientKeyExchange, |
| 11937 | test: testCase{ |
| 11938 | testType: serverTest, |
| 11939 | protocol: protocol, |
| 11940 | name: "ClientKeyExchange" + suffix, |
| 11941 | config: Config{ |
| 11942 | MaxVersion: VersionTLS12, |
| 11943 | }, |
| 11944 | }, |
| 11945 | }) |
| 11946 |
| 11947 | if protocol != dtls { |
| 11948 | ret = append(ret, perMessageTest{ |
| 11949 | messageType: typeNextProtocol, |
| 11950 | test: testCase{ |
| 11951 | testType: serverTest, |
| 11952 | protocol: protocol, |
| 11953 | name: "NextProtocol" + suffix, |
| 11954 | config: Config{ |
| 11955 | MaxVersion: VersionTLS12, |
| 11956 | NextProtos: []string{"bar"}, |
| 11957 | }, |
| 11958 | flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"}, |
| 11959 | }, |
| 11960 | }) |
| 11961 |
| 11962 | ret = append(ret, perMessageTest{ |
| 11963 | messageType: typeChannelID, |
| 11964 | test: testCase{ |
| 11965 | testType: serverTest, |
| 11966 | protocol: protocol, |
| 11967 | name: "ChannelID" + suffix, |
| 11968 | config: Config{ |
| 11969 | MaxVersion: VersionTLS12, |
| 11970 | ChannelID: channelIDKey, |
| 11971 | }, |
| 11972 | flags: []string{ |
| 11973 | "-expect-channel-id", |
| 11974 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 11975 | }, |
| 11976 | }, |
| 11977 | }) |
| 11978 | } |
| 11979 |
| 11980 | ret = append(ret, perMessageTest{ |
| 11981 | messageType: typeFinished, |
| 11982 | test: testCase{ |
| 11983 | testType: serverTest, |
| 11984 | protocol: protocol, |
| 11985 | name: "ClientFinished" + suffix, |
| 11986 | config: Config{ |
| 11987 | MaxVersion: VersionTLS12, |
| 11988 | }, |
| 11989 | }, |
| 11990 | }) |
| 11991 |
| 11992 | ret = append(ret, perMessageTest{ |
| 11993 | messageType: typeNewSessionTicket, |
| 11994 | test: testCase{ |
| 11995 | protocol: protocol, |
| 11996 | name: "NewSessionTicket" + suffix, |
| 11997 | config: Config{ |
| 11998 | MaxVersion: VersionTLS12, |
| 11999 | }, |
| 12000 | }, |
| 12001 | }) |
| 12002 |
| 12003 | ret = append(ret, perMessageTest{ |
| 12004 | messageType: typeFinished, |
| 12005 | test: testCase{ |
| 12006 | protocol: protocol, |
| 12007 | name: "ServerFinished" + suffix, |
| 12008 | config: Config{ |
| 12009 | MaxVersion: VersionTLS12, |
| 12010 | }, |
| 12011 | }, |
| 12012 | }) |
| 12013 |
| 12014 | } |
| 12015 |
| 12016 | ret = append(ret, perMessageTest{ |
| 12017 | messageType: typeClientHello, |
| 12018 | test: testCase{ |
| 12019 | testType: serverTest, |
| 12020 | name: "TLS13-ClientHello", |
| 12021 | config: Config{ |
| 12022 | MaxVersion: VersionTLS13, |
| 12023 | }, |
| 12024 | }, |
| 12025 | }) |
| 12026 |
| 12027 | ret = append(ret, perMessageTest{ |
| 12028 | messageType: typeServerHello, |
| 12029 | test: testCase{ |
| 12030 | name: "TLS13-ServerHello", |
| 12031 | config: Config{ |
| 12032 | MaxVersion: VersionTLS13, |
| 12033 | }, |
| 12034 | }, |
| 12035 | }) |
| 12036 |
| 12037 | ret = append(ret, perMessageTest{ |
| 12038 | messageType: typeEncryptedExtensions, |
| 12039 | test: testCase{ |
| 12040 | name: "TLS13-EncryptedExtensions", |
| 12041 | config: Config{ |
| 12042 | MaxVersion: VersionTLS13, |
| 12043 | }, |
| 12044 | }, |
| 12045 | }) |
| 12046 |
| 12047 | ret = append(ret, perMessageTest{ |
| 12048 | messageType: typeCertificateRequest, |
| 12049 | test: testCase{ |
| 12050 | name: "TLS13-CertificateRequest", |
| 12051 | config: Config{ |
| 12052 | MaxVersion: VersionTLS13, |
| 12053 | ClientAuth: RequireAnyClientCert, |
| 12054 | }, |
| 12055 | }, |
| 12056 | }) |
| 12057 |
| 12058 | ret = append(ret, perMessageTest{ |
| 12059 | messageType: typeCertificate, |
| 12060 | test: testCase{ |
| 12061 | name: "TLS13-ServerCertificate", |
| 12062 | config: Config{ |
| 12063 | MaxVersion: VersionTLS13, |
| 12064 | }, |
| 12065 | }, |
| 12066 | }) |
| 12067 |
| 12068 | ret = append(ret, perMessageTest{ |
| 12069 | messageType: typeCertificateVerify, |
| 12070 | test: testCase{ |
| 12071 | name: "TLS13-ServerCertificateVerify", |
| 12072 | config: Config{ |
| 12073 | MaxVersion: VersionTLS13, |
| 12074 | }, |
| 12075 | }, |
| 12076 | }) |
| 12077 |
| 12078 | ret = append(ret, perMessageTest{ |
| 12079 | messageType: typeFinished, |
| 12080 | test: testCase{ |
| 12081 | name: "TLS13-ServerFinished", |
| 12082 | config: Config{ |
| 12083 | MaxVersion: VersionTLS13, |
| 12084 | }, |
| 12085 | }, |
| 12086 | }) |
| 12087 |
| 12088 | ret = append(ret, perMessageTest{ |
| 12089 | messageType: typeCertificate, |
| 12090 | test: testCase{ |
| 12091 | testType: serverTest, |
| 12092 | name: "TLS13-ClientCertificate", |
| 12093 | config: Config{ |
| 12094 | Certificates: []Certificate{rsaCertificate}, |
| 12095 | MaxVersion: VersionTLS13, |
| 12096 | }, |
| 12097 | flags: []string{"-require-any-client-certificate"}, |
| 12098 | }, |
| 12099 | }) |
| 12100 |
| 12101 | ret = append(ret, perMessageTest{ |
| 12102 | messageType: typeCertificateVerify, |
| 12103 | test: testCase{ |
| 12104 | testType: serverTest, |
| 12105 | name: "TLS13-ClientCertificateVerify", |
| 12106 | config: Config{ |
| 12107 | Certificates: []Certificate{rsaCertificate}, |
| 12108 | MaxVersion: VersionTLS13, |
| 12109 | }, |
| 12110 | flags: []string{"-require-any-client-certificate"}, |
| 12111 | }, |
| 12112 | }) |
| 12113 |
| 12114 | ret = append(ret, perMessageTest{ |
| 12115 | messageType: typeFinished, |
| 12116 | test: testCase{ |
| 12117 | testType: serverTest, |
| 12118 | name: "TLS13-ClientFinished", |
| 12119 | config: Config{ |
| 12120 | MaxVersion: VersionTLS13, |
| 12121 | }, |
| 12122 | }, |
| 12123 | }) |
| 12124 |
| 12125 | ret = append(ret, perMessageTest{ |
| 12126 | messageType: typeEndOfEarlyData, |
| 12127 | test: testCase{ |
| 12128 | testType: serverTest, |
| 12129 | name: "TLS13-EndOfEarlyData", |
| 12130 | config: Config{ |
| 12131 | MaxVersion: VersionTLS13, |
| 12132 | }, |
| 12133 | resumeConfig: &Config{ |
| 12134 | MaxVersion: VersionTLS13, |
| 12135 | Bugs: ProtocolBugs{ |
| 12136 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 12137 | ExpectEarlyDataAccepted: true, |
| 12138 | }, |
| 12139 | }, |
| 12140 | resumeSession: true, |
| 12141 | flags: []string{"-enable-early-data"}, |
| 12142 | }, |
| 12143 | }) |
| 12144 |
| 12145 | return ret |
| 12146 | } |
| 12147 |
| 12148 | func addWrongMessageTypeTests() { |
| 12149 | for _, t := range makePerMessageTests() { |
| 12150 | t.test.name = "WrongMessageType-" + t.test.name |
| 12151 | if t.test.resumeConfig != nil { |
| 12152 | t.test.resumeConfig.Bugs.SendWrongMessageType = t.messageType |
| 12153 | } else { |
| 12154 | t.test.config.Bugs.SendWrongMessageType = t.messageType |
| 12155 | } |
| 12156 | t.test.shouldFail = true |
| 12157 | t.test.expectedError = ":UNEXPECTED_MESSAGE:" |
| 12158 | t.test.expectedLocalError = "remote error: unexpected message" |
| 12159 |
| 12160 | if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello { |
| 12161 | // In TLS 1.3, a bad ServerHello means the client sends |
| 12162 | // an unencrypted alert while the server expects |
| 12163 | // encryption, so the alert is not readable by runner. |
| 12164 | t.test.expectedLocalError = "local error: bad record MAC" |
| 12165 | } |
| 12166 |
| 12167 | testCases = append(testCases, t.test) |
| 12168 | } |
| 12169 |
| 12170 | // The processing order for TLS 1.3 version negotiation is such that one |
| 12171 | // may accidentally accept a HelloRetryRequest in lieu of ServerHello in |
| 12172 | // TLS 1.2. Test that we do not do this. |
| 12173 | testCases = append(testCases, testCase{ |
| 12174 | name: "SendServerHelloAsHelloRetryRequest", |
| 12175 | config: Config{ |
| 12176 | MaxVersion: VersionTLS12, |
| 12177 | Bugs: ProtocolBugs{ |
| 12178 | SendServerHelloAsHelloRetryRequest: true, |
| 12179 | }, |
| 12180 | }, |
| 12181 | shouldFail: true, |
| 12182 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 12183 | expectedLocalError: "remote error: unexpected message", |
| 12184 | }) |
| 12185 | } |
| 12186 |
| 12187 | func addTrailingMessageDataTests() { |
| 12188 | for _, t := range makePerMessageTests() { |
| 12189 | t.test.name = "TrailingMessageData-" + t.test.name |
| 12190 | if t.test.resumeConfig != nil { |
| 12191 | t.test.resumeConfig.Bugs.SendTrailingMessageData = t.messageType |
| 12192 | } else { |
| 12193 | t.test.config.Bugs.SendTrailingMessageData = t.messageType |
| 12194 | } |
| 12195 | t.test.shouldFail = true |
| 12196 | t.test.expectedError = ":DECODE_ERROR:" |
| 12197 | t.test.expectedLocalError = "remote error: error decoding message" |
| 12198 |
| 12199 | if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello { |
| 12200 | // In TLS 1.3, a bad ServerHello means the client sends |
| 12201 | // an unencrypted alert while the server expects |
| 12202 | // encryption, so the alert is not readable by runner. |
| 12203 | t.test.expectedLocalError = "local error: bad record MAC" |
| 12204 | } |
| 12205 |
| 12206 | if t.messageType == typeFinished { |
| 12207 | // Bad Finished messages read as the verify data having |
| 12208 | // the wrong length. |
| 12209 | t.test.expectedError = ":DIGEST_CHECK_FAILED:" |
| 12210 | t.test.expectedLocalError = "remote error: error decrypting message" |
| 12211 | } |
| 12212 |
| 12213 | testCases = append(testCases, t.test) |
| 12214 | } |
| 12215 | } |
| 12216 |
| 12217 | func addTLS13HandshakeTests() { |
| 12218 | testCases = append(testCases, testCase{ |
| 12219 | testType: clientTest, |
| 12220 | name: "NegotiatePSKResumption-TLS13", |
| 12221 | config: Config{ |
| 12222 | MaxVersion: VersionTLS13, |
| 12223 | Bugs: ProtocolBugs{ |
| 12224 | NegotiatePSKResumption: true, |
| 12225 | }, |
| 12226 | }, |
| 12227 | resumeSession: true, |
| 12228 | shouldFail: true, |
| 12229 | expectedError: ":MISSING_KEY_SHARE:", |
| 12230 | }) |
| 12231 |
| 12232 | testCases = append(testCases, testCase{ |
| 12233 | testType: clientTest, |
| 12234 | name: "MissingKeyShare-Client-TLS13", |
| 12235 | config: Config{ |
| 12236 | MaxVersion: VersionTLS13, |
| 12237 | Bugs: ProtocolBugs{ |
| 12238 | MissingKeyShare: true, |
| 12239 | }, |
| 12240 | }, |
| 12241 | shouldFail: true, |
| 12242 | expectedError: ":MISSING_KEY_SHARE:", |
| 12243 | }) |
| 12244 |
| 12245 | testCases = append(testCases, testCase{ |
| 12246 | testType: serverTest, |
| 12247 | name: "MissingKeyShare-Server-TLS13", |
| 12248 | config: Config{ |
| 12249 | MaxVersion: VersionTLS13, |
| 12250 | Bugs: ProtocolBugs{ |
| 12251 | MissingKeyShare: true, |
| 12252 | }, |
| 12253 | }, |
| 12254 | shouldFail: true, |
| 12255 | expectedError: ":MISSING_KEY_SHARE:", |
| 12256 | }) |
| 12257 |
| 12258 | testCases = append(testCases, testCase{ |
| 12259 | testType: serverTest, |
| 12260 | name: "DuplicateKeyShares-TLS13", |
| 12261 | config: Config{ |
| 12262 | MaxVersion: VersionTLS13, |
| 12263 | Bugs: ProtocolBugs{ |
| 12264 | DuplicateKeyShares: true, |
| 12265 | }, |
| 12266 | }, |
| 12267 | shouldFail: true, |
| 12268 | expectedError: ":DUPLICATE_KEY_SHARE:", |
| 12269 | }) |
| 12270 |
| 12271 | testCases = append(testCases, testCase{ |
| 12272 | testType: serverTest, |
| 12273 | name: "SkipEarlyData-TLS13", |
| 12274 | config: Config{ |
| 12275 | MaxVersion: VersionTLS13, |
| 12276 | Bugs: ProtocolBugs{ |
| 12277 | SendFakeEarlyDataLength: 4, |
| 12278 | }, |
| 12279 | }, |
| 12280 | }) |
| 12281 |
| 12282 | // Test that enabling TLS 1.3 does not interfere with TLS 1.2 session ID |
| 12283 | // resumption. |
| 12284 | testCases = append(testCases, testCase{ |
| 12285 | testType: clientTest, |
| 12286 | name: "ResumeTLS12SessionID-TLS13", |
| 12287 | config: Config{ |
| 12288 | MaxVersion: VersionTLS12, |
| 12289 | SessionTicketsDisabled: true, |
| 12290 | }, |
| 12291 | resumeSession: true, |
| 12292 | }) |
| 12293 |
| 12294 | // Test that the client correctly handles a TLS 1.3 ServerHello which echoes |
| 12295 | // a TLS 1.2 session ID. |
| 12296 | testCases = append(testCases, testCase{ |
| 12297 | testType: clientTest, |
| 12298 | name: "TLS12SessionID-TLS13", |
| 12299 | config: Config{ |
| 12300 | MaxVersion: VersionTLS12, |
| 12301 | SessionTicketsDisabled: true, |
| 12302 | }, |
| 12303 | resumeConfig: &Config{ |
| 12304 | MaxVersion: VersionTLS13, |
| 12305 | }, |
| 12306 | resumeSession: true, |
| 12307 | expectResumeRejected: true, |
| 12308 | }) |
| 12309 |
| 12310 | // Test that the server correctly echoes back session IDs of |
| 12311 | // various lengths. The first test additionally asserts that |
| 12312 | // BoringSSL always sends the ChangeCipherSpec messages for |
| 12313 | // compatibility mode, rather than negotiating it based on the |
| 12314 | // ClientHello. |
| 12315 | testCases = append(testCases, testCase{ |
| 12316 | testType: serverTest, |
| 12317 | name: "EmptySessionID-TLS13", |
| 12318 | config: Config{ |
| 12319 | MaxVersion: VersionTLS13, |
| 12320 | Bugs: ProtocolBugs{ |
| 12321 | SendClientHelloSessionID: []byte{}, |
| 12322 | }, |
| 12323 | }, |
| 12324 | }) |
| 12325 |
| 12326 | testCases = append(testCases, testCase{ |
| 12327 | testType: serverTest, |
| 12328 | name: "ShortSessionID-TLS13", |
| 12329 | config: Config{ |
| 12330 | MaxVersion: VersionTLS13, |
| 12331 | Bugs: ProtocolBugs{ |
| 12332 | SendClientHelloSessionID: make([]byte, 16), |
| 12333 | }, |
| 12334 | }, |
| 12335 | }) |
| 12336 |
| 12337 | testCases = append(testCases, testCase{ |
| 12338 | testType: serverTest, |
| 12339 | name: "FullSessionID-TLS13", |
| 12340 | config: Config{ |
| 12341 | MaxVersion: VersionTLS13, |
| 12342 | Bugs: ProtocolBugs{ |
| 12343 | SendClientHelloSessionID: make([]byte, 32), |
| 12344 | }, |
| 12345 | }, |
| 12346 | }) |
| 12347 |
| 12348 | // Test that the client sends a fake session ID in TLS 1.3. |
| 12349 | testCases = append(testCases, testCase{ |
| 12350 | testType: clientTest, |
| 12351 | name: "TLS13SessionID-TLS13", |
| 12352 | config: Config{ |
| 12353 | MaxVersion: VersionTLS13, |
| 12354 | Bugs: ProtocolBugs{ |
| 12355 | ExpectClientHelloSessionID: true, |
| 12356 | }, |
| 12357 | }, |
| 12358 | }) |
| 12359 |
| 12360 | // Test that the client omits the fake session ID when the max version is TLS 1.2 and below. |
| 12361 | testCases = append(testCases, testCase{ |
| 12362 | testType: clientTest, |
| 12363 | name: "TLS12NoSessionID-TLS13", |
| 12364 | config: Config{ |
| 12365 | MaxVersion: VersionTLS13, |
| 12366 | Bugs: ProtocolBugs{ |
| 12367 | ExpectNoTLS12Session: true, |
| 12368 | }, |
| 12369 | }, |
| 12370 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 12371 | }) |
| 12372 |
| 12373 | testCases = append(testCases, testCase{ |
| 12374 | testType: clientTest, |
| 12375 | name: "EarlyData-Client-TLS13", |
| 12376 | config: Config{ |
| 12377 | MaxVersion: VersionTLS13, |
| 12378 | MinVersion: VersionTLS13, |
| 12379 | MaxEarlyDataSize: 16384, |
| 12380 | }, |
| 12381 | resumeConfig: &Config{ |
| 12382 | MaxVersion: VersionTLS13, |
| 12383 | MinVersion: VersionTLS13, |
| 12384 | MaxEarlyDataSize: 16384, |
| 12385 | Bugs: ProtocolBugs{ |
| 12386 | ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}}, |
| 12387 | }, |
| 12388 | }, |
| 12389 | resumeSession: true, |
| 12390 | flags: []string{ |
| 12391 | "-enable-early-data", |
| 12392 | "-expect-ticket-supports-early-data", |
| 12393 | "-on-initial-expect-early-data-reason", "no_session_offered", |
| 12394 | "-on-resume-expect-accept-early-data", |
| 12395 | "-on-resume-expect-early-data-reason", "accept", |
| 12396 | "-on-resume-shim-writes-first", |
| 12397 | }, |
| 12398 | }) |
| 12399 |
| 12400 | testCases = append(testCases, testCase{ |
| 12401 | testType: clientTest, |
| 12402 | name: "EarlyData-Reject-Client-TLS13", |
| 12403 | config: Config{ |
| 12404 | MaxVersion: VersionTLS13, |
| 12405 | MaxEarlyDataSize: 16384, |
| 12406 | }, |
| 12407 | resumeConfig: &Config{ |
| 12408 | MaxVersion: VersionTLS13, |
| 12409 | MaxEarlyDataSize: 16384, |
| 12410 | Bugs: ProtocolBugs{ |
| 12411 | AlwaysRejectEarlyData: true, |
| 12412 | }, |
| 12413 | }, |
| 12414 | resumeSession: true, |
| 12415 | flags: []string{ |
| 12416 | "-enable-early-data", |
| 12417 | "-expect-ticket-supports-early-data", |
| 12418 | "-expect-reject-early-data", |
| 12419 | "-on-resume-shim-writes-first", |
| 12420 | "-on-retry-expect-early-data-reason", "peer_declined", |
| 12421 | }, |
| 12422 | }) |
| 12423 |
| 12424 | testCases = append(testCases, testCase{ |
| 12425 | testType: serverTest, |
| 12426 | name: "EarlyData-Server-TLS13", |
| 12427 | config: Config{ |
| 12428 | MaxVersion: VersionTLS13, |
| 12429 | MinVersion: VersionTLS13, |
| 12430 | Bugs: ProtocolBugs{ |
| 12431 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 12432 | ExpectEarlyDataAccepted: true, |
| 12433 | ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}}, |
| 12434 | }, |
| 12435 | }, |
| 12436 | messageCount: 2, |
| 12437 | resumeSession: true, |
| 12438 | flags: []string{ |
| 12439 | "-enable-early-data", |
| 12440 | "-on-initial-expect-early-data-reason", "no_session_offered", |
| 12441 | "-on-resume-expect-accept-early-data", |
| 12442 | "-on-resume-expect-early-data-reason", "accept", |
| 12443 | }, |
| 12444 | }) |
| 12445 |
| 12446 | // The above tests the most recent ticket. Additionally test that 0-RTT |
| 12447 | // works on the first ticket issued by the server. |
| 12448 | testCases = append(testCases, testCase{ |
| 12449 | testType: serverTest, |
| 12450 | name: "EarlyData-FirstTicket-Server-TLS13", |
| 12451 | config: Config{ |
| 12452 | MaxVersion: VersionTLS13, |
| 12453 | MinVersion: VersionTLS13, |
| 12454 | Bugs: ProtocolBugs{ |
| 12455 | UseFirstSessionTicket: true, |
| 12456 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 12457 | ExpectEarlyDataAccepted: true, |
| 12458 | ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}}, |
| 12459 | }, |
| 12460 | }, |
| 12461 | messageCount: 2, |
| 12462 | resumeSession: true, |
| 12463 | flags: []string{ |
| 12464 | "-enable-early-data", |
| 12465 | "-on-resume-expect-accept-early-data", |
| 12466 | "-on-resume-expect-early-data-reason", "accept", |
| 12467 | }, |
| 12468 | }) |
| 12469 |
| 12470 | testCases = append(testCases, testCase{ |
| 12471 | testType: serverTest, |
| 12472 | name: "SkipEarlyData-OmitEarlyDataExtension-TLS13", |
| 12473 | config: Config{ |
| 12474 | MaxVersion: VersionTLS13, |
| 12475 | Bugs: ProtocolBugs{ |
| 12476 | SendFakeEarlyDataLength: 4, |
| 12477 | OmitEarlyDataExtension: true, |
| 12478 | }, |
| 12479 | }, |
| 12480 | shouldFail: true, |
| 12481 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 12482 | }) |
| 12483 |
| 12484 | testCases = append(testCases, testCase{ |
| 12485 | testType: serverTest, |
| 12486 | name: "SkipEarlyData-TooMuchData-TLS13", |
| 12487 | config: Config{ |
| 12488 | MaxVersion: VersionTLS13, |
| 12489 | Bugs: ProtocolBugs{ |
| 12490 | SendFakeEarlyDataLength: 16384 + 1, |
| 12491 | }, |
| 12492 | }, |
| 12493 | shouldFail: true, |
| 12494 | expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:", |
| 12495 | }) |
| 12496 |
| 12497 | testCases = append(testCases, testCase{ |
| 12498 | testType: serverTest, |
| 12499 | name: "SkipEarlyData-Interleaved-TLS13", |
| 12500 | config: Config{ |
| 12501 | MaxVersion: VersionTLS13, |
| 12502 | Bugs: ProtocolBugs{ |
| 12503 | SendFakeEarlyDataLength: 4, |
| 12504 | InterleaveEarlyData: true, |
| 12505 | }, |
| 12506 | }, |
| 12507 | shouldFail: true, |
| 12508 | expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:", |
| 12509 | }) |
| 12510 |
| 12511 | testCases = append(testCases, testCase{ |
| 12512 | testType: serverTest, |
| 12513 | name: "SkipEarlyData-EarlyDataInTLS12-TLS13", |
| 12514 | config: Config{ |
| 12515 | MaxVersion: VersionTLS13, |
| 12516 | Bugs: ProtocolBugs{ |
| 12517 | SendFakeEarlyDataLength: 4, |
| 12518 | }, |
| 12519 | }, |
| 12520 | shouldFail: true, |
| 12521 | expectedError: ":UNEXPECTED_RECORD:", |
| 12522 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 12523 | }) |
| 12524 |
| 12525 | testCases = append(testCases, testCase{ |
| 12526 | testType: serverTest, |
| 12527 | name: "SkipEarlyData-HRR-TLS13", |
| 12528 | config: Config{ |
| 12529 | MaxVersion: VersionTLS13, |
| 12530 | Bugs: ProtocolBugs{ |
| 12531 | SendFakeEarlyDataLength: 4, |
| 12532 | }, |
| 12533 | DefaultCurves: []CurveID{}, |
| 12534 | }, |
| 12535 | // Though the session is not resumed and we send HelloRetryRequest, |
| 12536 | // early data being disabled takes priority as the reject reason. |
| 12537 | flags: []string{"-expect-early-data-reason", "disabled"}, |
| 12538 | }) |
| 12539 |
| 12540 | testCases = append(testCases, testCase{ |
| 12541 | testType: serverTest, |
| 12542 | name: "SkipEarlyData-HRR-Interleaved-TLS13", |
| 12543 | config: Config{ |
| 12544 | MaxVersion: VersionTLS13, |
| 12545 | Bugs: ProtocolBugs{ |
| 12546 | SendFakeEarlyDataLength: 4, |
| 12547 | InterleaveEarlyData: true, |
| 12548 | }, |
| 12549 | DefaultCurves: []CurveID{}, |
| 12550 | }, |
| 12551 | shouldFail: true, |
| 12552 | expectedError: ":UNEXPECTED_RECORD:", |
| 12553 | }) |
| 12554 |
| 12555 | testCases = append(testCases, testCase{ |
| 12556 | testType: serverTest, |
| 12557 | name: "SkipEarlyData-HRR-TooMuchData-TLS13", |
| 12558 | config: Config{ |
| 12559 | MaxVersion: VersionTLS13, |
| 12560 | Bugs: ProtocolBugs{ |
| 12561 | SendFakeEarlyDataLength: 16384 + 1, |
| 12562 | }, |
| 12563 | DefaultCurves: []CurveID{}, |
| 12564 | }, |
| 12565 | shouldFail: true, |
| 12566 | expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:", |
| 12567 | }) |
| 12568 |
| 12569 | // Test that skipping early data looking for cleartext correctly |
| 12570 | // processes an alert record. |
| 12571 | testCases = append(testCases, testCase{ |
| 12572 | testType: serverTest, |
| 12573 | name: "SkipEarlyData-HRR-FatalAlert-TLS13", |
| 12574 | config: Config{ |
| 12575 | MaxVersion: VersionTLS13, |
| 12576 | Bugs: ProtocolBugs{ |
| 12577 | SendEarlyAlert: true, |
| 12578 | SendFakeEarlyDataLength: 4, |
| 12579 | }, |
| 12580 | DefaultCurves: []CurveID{}, |
| 12581 | }, |
| 12582 | shouldFail: true, |
| 12583 | expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:", |
| 12584 | }) |
| 12585 |
| 12586 | testCases = append(testCases, testCase{ |
| 12587 | testType: serverTest, |
| 12588 | name: "SkipEarlyData-SecondClientHelloEarlyData-TLS13", |
| 12589 | config: Config{ |
| 12590 | MaxVersion: VersionTLS13, |
| 12591 | Bugs: ProtocolBugs{ |
| 12592 | SendEarlyDataOnSecondClientHello: true, |
| 12593 | }, |
| 12594 | DefaultCurves: []CurveID{}, |
| 12595 | }, |
| 12596 | shouldFail: true, |
| 12597 | expectedLocalError: "remote error: bad record MAC", |
| 12598 | }) |
| 12599 |
| 12600 | testCases = append(testCases, testCase{ |
| 12601 | testType: clientTest, |
| 12602 | name: "EmptyEncryptedExtensions-TLS13", |
| 12603 | config: Config{ |
| 12604 | MaxVersion: VersionTLS13, |
| 12605 | Bugs: ProtocolBugs{ |
| 12606 | EmptyEncryptedExtensions: true, |
| 12607 | }, |
| 12608 | }, |
| 12609 | shouldFail: true, |
| 12610 | expectedLocalError: "remote error: error decoding message", |
| 12611 | }) |
| 12612 |
| 12613 | testCases = append(testCases, testCase{ |
| 12614 | testType: clientTest, |
| 12615 | name: "EncryptedExtensionsWithKeyShare-TLS13", |
| 12616 | config: Config{ |
| 12617 | MaxVersion: VersionTLS13, |
| 12618 | Bugs: ProtocolBugs{ |
| 12619 | EncryptedExtensionsWithKeyShare: true, |
| 12620 | }, |
| 12621 | }, |
| 12622 | shouldFail: true, |
| 12623 | expectedLocalError: "remote error: unsupported extension", |
| 12624 | }) |
| 12625 |
| 12626 | testCases = append(testCases, testCase{ |
| 12627 | testType: serverTest, |
| 12628 | name: "SendHelloRetryRequest-TLS13", |
| 12629 | config: Config{ |
| 12630 | MaxVersion: VersionTLS13, |
| 12631 | // Require a HelloRetryRequest for every curve. |
| 12632 | DefaultCurves: []CurveID{}, |
| 12633 | CurvePreferences: []CurveID{CurveX25519}, |
| 12634 | }, |
| 12635 | expectedCurveID: CurveX25519, |
| 12636 | }) |
| 12637 |
| 12638 | testCases = append(testCases, testCase{ |
| 12639 | testType: serverTest, |
| 12640 | name: "SendHelloRetryRequest-2-TLS13", |
| 12641 | config: Config{ |
| 12642 | MaxVersion: VersionTLS13, |
| 12643 | DefaultCurves: []CurveID{CurveP384}, |
| 12644 | CurvePreferences: []CurveID{CurveX25519, CurveP384}, |
| 12645 | }, |
| 12646 | // Although the ClientHello did not predict our preferred curve, |
| 12647 | // we always select it whether it is predicted or not. |
| 12648 | expectedCurveID: CurveX25519, |
| 12649 | }) |
| 12650 |
| 12651 | testCases = append(testCases, testCase{ |
| 12652 | name: "UnknownCurve-HelloRetryRequest-TLS13", |
| 12653 | config: Config{ |
| 12654 | MaxVersion: VersionTLS13, |
| 12655 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 12656 | CurvePreferences: []CurveID{CurveP384}, |
| 12657 | Bugs: ProtocolBugs{ |
| 12658 | SendHelloRetryRequestCurve: bogusCurve, |
| 12659 | }, |
| 12660 | }, |
| 12661 | shouldFail: true, |
| 12662 | expectedError: ":WRONG_CURVE:", |
| 12663 | }) |
| 12664 |
| 12665 | testCases = append(testCases, testCase{ |
| 12666 | name: "HelloRetryRequest-CipherChange-TLS13", |
| 12667 | config: Config{ |
| 12668 | MaxVersion: VersionTLS13, |
| 12669 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 12670 | CurvePreferences: []CurveID{CurveP384}, |
| 12671 | Bugs: ProtocolBugs{ |
| 12672 | SendCipherSuite: TLS_AES_128_GCM_SHA256, |
| 12673 | SendHelloRetryRequestCipherSuite: TLS_CHACHA20_POLY1305_SHA256, |
| 12674 | }, |
| 12675 | }, |
| 12676 | shouldFail: true, |
| 12677 | expectedError: ":WRONG_CIPHER_RETURNED:", |
| 12678 | }) |
| 12679 |
| 12680 | // Test that the client does not offer a PSK in the second ClientHello if the |
| 12681 | // HelloRetryRequest is incompatible with it. |
| 12682 | testCases = append(testCases, testCase{ |
| 12683 | testType: clientTest, |
| 12684 | name: "HelloRetryRequest-NonResumableCipher-TLS13", |
| 12685 | config: Config{ |
| 12686 | MaxVersion: VersionTLS13, |
| 12687 | CipherSuites: []uint16{ |
| 12688 | TLS_AES_128_GCM_SHA256, |
| 12689 | }, |
| 12690 | }, |
| 12691 | resumeConfig: &Config{ |
| 12692 | MaxVersion: VersionTLS13, |
| 12693 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 12694 | CurvePreferences: []CurveID{CurveP384}, |
| 12695 | Bugs: ProtocolBugs{ |
| 12696 | ExpectNoTLS13PSKAfterHRR: true, |
| 12697 | }, |
| 12698 | CipherSuites: []uint16{ |
| 12699 | TLS_AES_256_GCM_SHA384, |
| 12700 | }, |
| 12701 | }, |
| 12702 | resumeSession: true, |
| 12703 | expectResumeRejected: true, |
| 12704 | }) |
| 12705 |
| 12706 | testCases = append(testCases, testCase{ |
| 12707 | name: "DisabledCurve-HelloRetryRequest-TLS13", |
| 12708 | config: Config{ |
| 12709 | MaxVersion: VersionTLS13, |
| 12710 | CurvePreferences: []CurveID{CurveP256}, |
| 12711 | Bugs: ProtocolBugs{ |
| 12712 | IgnorePeerCurvePreferences: true, |
| 12713 | }, |
| 12714 | }, |
| 12715 | flags: []string{"-curves", strconv.Itoa(int(CurveP384))}, |
| 12716 | shouldFail: true, |
| 12717 | expectedError: ":WRONG_CURVE:", |
| 12718 | }) |
| 12719 |
| 12720 | testCases = append(testCases, testCase{ |
| 12721 | name: "UnnecessaryHelloRetryRequest-TLS13", |
| 12722 | config: Config{ |
| 12723 | MaxVersion: VersionTLS13, |
| 12724 | CurvePreferences: []CurveID{CurveX25519}, |
| 12725 | Bugs: ProtocolBugs{ |
| 12726 | SendHelloRetryRequestCurve: CurveX25519, |
| 12727 | }, |
| 12728 | }, |
| 12729 | shouldFail: true, |
| 12730 | expectedError: ":WRONG_CURVE:", |
| 12731 | }) |
| 12732 |
| 12733 | testCases = append(testCases, testCase{ |
| 12734 | name: "SecondHelloRetryRequest-TLS13", |
| 12735 | config: Config{ |
| 12736 | MaxVersion: VersionTLS13, |
| 12737 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 12738 | CurvePreferences: []CurveID{CurveP384}, |
| 12739 | Bugs: ProtocolBugs{ |
| 12740 | SecondHelloRetryRequest: true, |
| 12741 | }, |
| 12742 | }, |
| 12743 | shouldFail: true, |
| 12744 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 12745 | }) |
| 12746 |
| 12747 | testCases = append(testCases, testCase{ |
| 12748 | name: "HelloRetryRequest-Empty-TLS13", |
| 12749 | config: Config{ |
| 12750 | MaxVersion: VersionTLS13, |
| 12751 | Bugs: ProtocolBugs{ |
| 12752 | AlwaysSendHelloRetryRequest: true, |
| 12753 | }, |
| 12754 | }, |
| 12755 | shouldFail: true, |
| 12756 | expectedError: ":EMPTY_HELLO_RETRY_REQUEST:", |
| 12757 | expectedLocalError: "remote error: illegal parameter", |
| 12758 | }) |
| 12759 |
| 12760 | testCases = append(testCases, testCase{ |
| 12761 | name: "HelloRetryRequest-DuplicateCurve-TLS13", |
| 12762 | config: Config{ |
| 12763 | MaxVersion: VersionTLS13, |
| 12764 | // P-384 requires a HelloRetryRequest against BoringSSL's default |
| 12765 | // configuration. Assert this ExpectMissingKeyShare. |
| 12766 | CurvePreferences: []CurveID{CurveP384}, |
| 12767 | Bugs: ProtocolBugs{ |
| 12768 | ExpectMissingKeyShare: true, |
| 12769 | DuplicateHelloRetryRequestExtensions: true, |
| 12770 | }, |
| 12771 | }, |
| 12772 | shouldFail: true, |
| 12773 | expectedError: ":DUPLICATE_EXTENSION:", |
| 12774 | expectedLocalError: "remote error: illegal parameter", |
| 12775 | }) |
| 12776 |
| 12777 | testCases = append(testCases, testCase{ |
| 12778 | name: "HelloRetryRequest-Cookie-TLS13", |
| 12779 | config: Config{ |
| 12780 | MaxVersion: VersionTLS13, |
| 12781 | Bugs: ProtocolBugs{ |
| 12782 | SendHelloRetryRequestCookie: []byte("cookie"), |
| 12783 | }, |
| 12784 | }, |
| 12785 | }) |
| 12786 |
| 12787 | testCases = append(testCases, testCase{ |
| 12788 | name: "HelloRetryRequest-DuplicateCookie-TLS13", |
| 12789 | config: Config{ |
| 12790 | MaxVersion: VersionTLS13, |
| 12791 | Bugs: ProtocolBugs{ |
| 12792 | SendHelloRetryRequestCookie: []byte("cookie"), |
| 12793 | DuplicateHelloRetryRequestExtensions: true, |
| 12794 | }, |
| 12795 | }, |
| 12796 | shouldFail: true, |
| 12797 | expectedError: ":DUPLICATE_EXTENSION:", |
| 12798 | expectedLocalError: "remote error: illegal parameter", |
| 12799 | }) |
| 12800 |
| 12801 | testCases = append(testCases, testCase{ |
| 12802 | name: "HelloRetryRequest-EmptyCookie-TLS13", |
| 12803 | config: Config{ |
| 12804 | MaxVersion: VersionTLS13, |
| 12805 | Bugs: ProtocolBugs{ |
| 12806 | SendHelloRetryRequestCookie: []byte{}, |
| 12807 | }, |
| 12808 | }, |
| 12809 | shouldFail: true, |
| 12810 | expectedError: ":DECODE_ERROR:", |
| 12811 | }) |
| 12812 |
| 12813 | testCases = append(testCases, testCase{ |
| 12814 | name: "HelloRetryRequest-Cookie-Curve-TLS13", |
| 12815 | config: Config{ |
| 12816 | MaxVersion: VersionTLS13, |
| 12817 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 12818 | CurvePreferences: []CurveID{CurveP384}, |
| 12819 | Bugs: ProtocolBugs{ |
| 12820 | SendHelloRetryRequestCookie: []byte("cookie"), |
| 12821 | ExpectMissingKeyShare: true, |
| 12822 | }, |
| 12823 | }, |
| 12824 | }) |
| 12825 |
| 12826 | testCases = append(testCases, testCase{ |
| 12827 | name: "HelloRetryRequest-Unknown-TLS13", |
| 12828 | config: Config{ |
| 12829 | MaxVersion: VersionTLS13, |
| 12830 | Bugs: ProtocolBugs{ |
| 12831 | CustomHelloRetryRequestExtension: "extension", |
| 12832 | }, |
| 12833 | }, |
| 12834 | shouldFail: true, |
| 12835 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 12836 | expectedLocalError: "remote error: unsupported extension", |
| 12837 | }) |
| 12838 |
| 12839 | testCases = append(testCases, testCase{ |
| 12840 | testType: serverTest, |
| 12841 | name: "SecondClientHelloMissingKeyShare-TLS13", |
| 12842 | config: Config{ |
| 12843 | MaxVersion: VersionTLS13, |
| 12844 | DefaultCurves: []CurveID{}, |
| 12845 | Bugs: ProtocolBugs{ |
| 12846 | SecondClientHelloMissingKeyShare: true, |
| 12847 | }, |
| 12848 | }, |
| 12849 | shouldFail: true, |
| 12850 | expectedError: ":MISSING_KEY_SHARE:", |
| 12851 | }) |
| 12852 |
| 12853 | testCases = append(testCases, testCase{ |
| 12854 | testType: serverTest, |
| 12855 | name: "SecondClientHelloWrongCurve-TLS13", |
| 12856 | config: Config{ |
| 12857 | MaxVersion: VersionTLS13, |
| 12858 | DefaultCurves: []CurveID{}, |
| 12859 | Bugs: ProtocolBugs{ |
| 12860 | MisinterpretHelloRetryRequestCurve: CurveP521, |
| 12861 | }, |
| 12862 | }, |
| 12863 | shouldFail: true, |
| 12864 | expectedError: ":WRONG_CURVE:", |
| 12865 | }) |
| 12866 |
| 12867 | testCases = append(testCases, testCase{ |
| 12868 | name: "HelloRetryRequestVersionMismatch-TLS13", |
| 12869 | config: Config{ |
| 12870 | MaxVersion: VersionTLS13, |
| 12871 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 12872 | CurvePreferences: []CurveID{CurveP384}, |
| 12873 | Bugs: ProtocolBugs{ |
| 12874 | SendServerHelloVersion: 0x0305, |
| 12875 | }, |
| 12876 | }, |
| 12877 | shouldFail: true, |
| 12878 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 12879 | }) |
| 12880 |
| 12881 | testCases = append(testCases, testCase{ |
| 12882 | name: "HelloRetryRequestCurveMismatch-TLS13", |
| 12883 | config: Config{ |
| 12884 | MaxVersion: VersionTLS13, |
| 12885 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 12886 | CurvePreferences: []CurveID{CurveP384}, |
| 12887 | Bugs: ProtocolBugs{ |
| 12888 | // Send P-384 (correct) in the HelloRetryRequest. |
| 12889 | SendHelloRetryRequestCurve: CurveP384, |
| 12890 | // But send P-256 in the ServerHello. |
| 12891 | SendCurve: CurveP256, |
| 12892 | }, |
| 12893 | }, |
| 12894 | shouldFail: true, |
| 12895 | expectedError: ":WRONG_CURVE:", |
| 12896 | }) |
| 12897 |
| 12898 | // Test the server selecting a curve that requires a HelloRetryRequest |
| 12899 | // without sending it. |
| 12900 | testCases = append(testCases, testCase{ |
| 12901 | name: "SkipHelloRetryRequest-TLS13", |
| 12902 | config: Config{ |
| 12903 | MaxVersion: VersionTLS13, |
| 12904 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 12905 | CurvePreferences: []CurveID{CurveP384}, |
| 12906 | Bugs: ProtocolBugs{ |
| 12907 | SkipHelloRetryRequest: true, |
| 12908 | }, |
| 12909 | }, |
| 12910 | shouldFail: true, |
| 12911 | expectedError: ":WRONG_CURVE:", |
| 12912 | }) |
| 12913 |
| 12914 | testCases = append(testCases, testCase{ |
| 12915 | name: "SecondServerHelloNoVersion-TLS13", |
| 12916 | config: Config{ |
| 12917 | MaxVersion: VersionTLS13, |
| 12918 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 12919 | CurvePreferences: []CurveID{CurveP384}, |
| 12920 | Bugs: ProtocolBugs{ |
| 12921 | OmitServerSupportedVersionExtension: true, |
| 12922 | }, |
| 12923 | }, |
| 12924 | shouldFail: true, |
| 12925 | expectedError: ":SECOND_SERVERHELLO_VERSION_MISMATCH:", |
| 12926 | }) |
| 12927 | testCases = append(testCases, testCase{ |
| 12928 | name: "SecondServerHelloWrongVersion-TLS13", |
| 12929 | config: Config{ |
| 12930 | MaxVersion: VersionTLS13, |
| 12931 | // P-384 requires HelloRetryRequest in BoringSSL. |
| 12932 | CurvePreferences: []CurveID{CurveP384}, |
| 12933 | Bugs: ProtocolBugs{ |
| 12934 | SendServerSupportedVersionExtension: 0x1234, |
| 12935 | }, |
| 12936 | }, |
| 12937 | shouldFail: true, |
| 12938 | expectedError: ":SECOND_SERVERHELLO_VERSION_MISMATCH:", |
| 12939 | }) |
| 12940 |
| 12941 | testCases = append(testCases, testCase{ |
| 12942 | name: "RequestContextInHandshake-TLS13", |
| 12943 | config: Config{ |
| 12944 | MaxVersion: VersionTLS13, |
| 12945 | MinVersion: VersionTLS13, |
| 12946 | ClientAuth: RequireAnyClientCert, |
| 12947 | Bugs: ProtocolBugs{ |
| 12948 | SendRequestContext: []byte("request context"), |
| 12949 | }, |
| 12950 | }, |
| 12951 | flags: []string{ |
| 12952 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 12953 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 12954 | }, |
| 12955 | shouldFail: true, |
| 12956 | expectedError: ":DECODE_ERROR:", |
| 12957 | }) |
| 12958 |
| 12959 | testCases = append(testCases, testCase{ |
| 12960 | name: "UnknownExtensionInCertificateRequest-TLS13", |
| 12961 | config: Config{ |
| 12962 | MaxVersion: VersionTLS13, |
| 12963 | MinVersion: VersionTLS13, |
| 12964 | ClientAuth: RequireAnyClientCert, |
| 12965 | Bugs: ProtocolBugs{ |
| 12966 | SendCustomCertificateRequest: 0x1212, |
| 12967 | }, |
| 12968 | }, |
| 12969 | flags: []string{ |
| 12970 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 12971 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 12972 | }, |
| 12973 | }) |
| 12974 |
| 12975 | testCases = append(testCases, testCase{ |
| 12976 | name: "MissingSignatureAlgorithmsInCertificateRequest-TLS13", |
| 12977 | config: Config{ |
| 12978 | MaxVersion: VersionTLS13, |
| 12979 | MinVersion: VersionTLS13, |
| 12980 | ClientAuth: RequireAnyClientCert, |
| 12981 | Bugs: ProtocolBugs{ |
| 12982 | OmitCertificateRequestAlgorithms: true, |
| 12983 | }, |
| 12984 | }, |
| 12985 | flags: []string{ |
| 12986 | "-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 12987 | "-key-file", path.Join(*resourceDir, rsaKeyFile), |
| 12988 | }, |
| 12989 | shouldFail: true, |
| 12990 | expectedError: ":DECODE_ERROR:", |
| 12991 | }) |
| 12992 |
| 12993 | testCases = append(testCases, testCase{ |
| 12994 | testType: serverTest, |
| 12995 | name: "TrailingKeyShareData-TLS13", |
| 12996 | config: Config{ |
| 12997 | MaxVersion: VersionTLS13, |
| 12998 | Bugs: ProtocolBugs{ |
| 12999 | TrailingKeyShareData: true, |
| 13000 | }, |
| 13001 | }, |
| 13002 | shouldFail: true, |
| 13003 | expectedError: ":DECODE_ERROR:", |
| 13004 | }) |
| 13005 |
| 13006 | testCases = append(testCases, testCase{ |
| 13007 | name: "AlwaysSelectPSKIdentity-TLS13", |
| 13008 | config: Config{ |
| 13009 | MaxVersion: VersionTLS13, |
| 13010 | Bugs: ProtocolBugs{ |
| 13011 | AlwaysSelectPSKIdentity: true, |
| 13012 | }, |
| 13013 | }, |
| 13014 | shouldFail: true, |
| 13015 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 13016 | }) |
| 13017 |
| 13018 | testCases = append(testCases, testCase{ |
| 13019 | name: "InvalidPSKIdentity-TLS13", |
| 13020 | config: Config{ |
| 13021 | MaxVersion: VersionTLS13, |
| 13022 | Bugs: ProtocolBugs{ |
| 13023 | SelectPSKIdentityOnResume: 1, |
| 13024 | }, |
| 13025 | }, |
| 13026 | resumeSession: true, |
| 13027 | shouldFail: true, |
| 13028 | expectedError: ":PSK_IDENTITY_NOT_FOUND:", |
| 13029 | }) |
| 13030 |
| 13031 | testCases = append(testCases, testCase{ |
| 13032 | testType: serverTest, |
| 13033 | name: "ExtraPSKIdentity-TLS13", |
| 13034 | config: Config{ |
| 13035 | MaxVersion: VersionTLS13, |
| 13036 | Bugs: ProtocolBugs{ |
| 13037 | ExtraPSKIdentity: true, |
| 13038 | SendExtraPSKBinder: true, |
| 13039 | }, |
| 13040 | }, |
| 13041 | resumeSession: true, |
| 13042 | }) |
| 13043 |
| 13044 | // Test that unknown NewSessionTicket extensions are tolerated. |
| 13045 | testCases = append(testCases, testCase{ |
| 13046 | name: "CustomTicketExtension-TLS13", |
| 13047 | config: Config{ |
| 13048 | MaxVersion: VersionTLS13, |
| 13049 | Bugs: ProtocolBugs{ |
| 13050 | CustomTicketExtension: "1234", |
| 13051 | }, |
| 13052 | }, |
| 13053 | }) |
| 13054 |
| 13055 | // Test the client handles 0-RTT being rejected by a full handshake. |
| 13056 | testCases = append(testCases, testCase{ |
| 13057 | testType: clientTest, |
| 13058 | name: "EarlyData-RejectTicket-Client-TLS13", |
| 13059 | config: Config{ |
| 13060 | MaxVersion: VersionTLS13, |
| 13061 | MaxEarlyDataSize: 16384, |
| 13062 | Certificates: []Certificate{rsaCertificate}, |
| 13063 | }, |
| 13064 | resumeConfig: &Config{ |
| 13065 | MaxVersion: VersionTLS13, |
| 13066 | MaxEarlyDataSize: 16384, |
| 13067 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 13068 | SessionTicketsDisabled: true, |
| 13069 | }, |
| 13070 | resumeSession: true, |
| 13071 | expectResumeRejected: true, |
| 13072 | flags: []string{ |
| 13073 | "-enable-early-data", |
| 13074 | "-expect-ticket-supports-early-data", |
| 13075 | "-expect-reject-early-data", |
| 13076 | "-on-resume-shim-writes-first", |
| 13077 | "-on-retry-expect-early-data-reason", "session_not_resumed", |
| 13078 | // Test the peer certificate is reported correctly in each of the |
| 13079 | // three logical connections. |
| 13080 | "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 13081 | "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 13082 | "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 13083 | // Session tickets are disabled, so the runner will not send a ticket. |
| 13084 | "-on-retry-expect-no-session", |
| 13085 | }, |
| 13086 | }) |
| 13087 |
| 13088 | // Test the server rejects 0-RTT if it does not recognize the ticket. |
| 13089 | testCases = append(testCases, testCase{ |
| 13090 | testType: serverTest, |
| 13091 | name: "EarlyData-RejectTicket-Server-TLS13", |
| 13092 | config: Config{ |
| 13093 | MaxVersion: VersionTLS13, |
| 13094 | MinVersion: VersionTLS13, |
| 13095 | Bugs: ProtocolBugs{ |
| 13096 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13097 | ExpectEarlyDataAccepted: false, |
| 13098 | // Corrupt the ticket. |
| 13099 | FilterTicket: func(in []byte) ([]byte, error) { |
| 13100 | in[len(in)-1] ^= 1 |
| 13101 | return in, nil |
| 13102 | }, |
| 13103 | }, |
| 13104 | }, |
| 13105 | messageCount: 2, |
| 13106 | resumeSession: true, |
| 13107 | expectResumeRejected: true, |
| 13108 | flags: []string{ |
| 13109 | "-enable-early-data", |
| 13110 | "-on-resume-expect-reject-early-data", |
| 13111 | "-on-resume-expect-early-data-reason", "session_not_resumed", |
| 13112 | }, |
| 13113 | }) |
| 13114 |
| 13115 | // Test the client handles 0-RTT being rejected via a HelloRetryRequest. |
| 13116 | testCases = append(testCases, testCase{ |
| 13117 | testType: clientTest, |
| 13118 | name: "EarlyData-HRR-Client-TLS13", |
| 13119 | config: Config{ |
| 13120 | MaxVersion: VersionTLS13, |
| 13121 | MaxEarlyDataSize: 16384, |
| 13122 | }, |
| 13123 | resumeConfig: &Config{ |
| 13124 | MaxVersion: VersionTLS13, |
| 13125 | MaxEarlyDataSize: 16384, |
| 13126 | Bugs: ProtocolBugs{ |
| 13127 | SendHelloRetryRequestCookie: []byte{1, 2, 3, 4}, |
| 13128 | }, |
| 13129 | }, |
| 13130 | resumeSession: true, |
| 13131 | flags: []string{ |
| 13132 | "-enable-early-data", |
| 13133 | "-expect-ticket-supports-early-data", |
| 13134 | "-expect-reject-early-data", |
| 13135 | "-on-retry-expect-early-data-reason", "hello_retry_request", |
| 13136 | }, |
| 13137 | }) |
| 13138 |
| 13139 | // Test the server rejects 0-RTT if it needs to send a HelloRetryRequest. |
| 13140 | testCases = append(testCases, testCase{ |
| 13141 | testType: serverTest, |
| 13142 | name: "EarlyData-HRR-Server-TLS13", |
| 13143 | config: Config{ |
| 13144 | MaxVersion: VersionTLS13, |
| 13145 | MinVersion: VersionTLS13, |
| 13146 | // Require a HelloRetryRequest for every curve. |
| 13147 | DefaultCurves: []CurveID{}, |
| 13148 | Bugs: ProtocolBugs{ |
| 13149 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13150 | ExpectEarlyDataAccepted: false, |
| 13151 | }, |
| 13152 | }, |
| 13153 | messageCount: 2, |
| 13154 | resumeSession: true, |
| 13155 | flags: []string{ |
| 13156 | "-enable-early-data", |
| 13157 | "-on-resume-expect-reject-early-data", |
| 13158 | "-on-resume-expect-early-data-reason", "hello_retry_request", |
| 13159 | }, |
| 13160 | }) |
| 13161 |
| 13162 | // Test the client handles a 0-RTT reject from both ticket rejection and |
| 13163 | // HelloRetryRequest. |
| 13164 | testCases = append(testCases, testCase{ |
| 13165 | testType: clientTest, |
| 13166 | name: "EarlyData-HRR-RejectTicket-Client-TLS13", |
| 13167 | config: Config{ |
| 13168 | MaxVersion: VersionTLS13, |
| 13169 | MaxEarlyDataSize: 16384, |
| 13170 | Certificates: []Certificate{rsaCertificate}, |
| 13171 | }, |
| 13172 | resumeConfig: &Config{ |
| 13173 | MaxVersion: VersionTLS13, |
| 13174 | MaxEarlyDataSize: 16384, |
| 13175 | Certificates: []Certificate{ecdsaP256Certificate}, |
| 13176 | SessionTicketsDisabled: true, |
| 13177 | Bugs: ProtocolBugs{ |
| 13178 | SendHelloRetryRequestCookie: []byte{1, 2, 3, 4}, |
| 13179 | }, |
| 13180 | }, |
| 13181 | resumeSession: true, |
| 13182 | expectResumeRejected: true, |
| 13183 | flags: []string{ |
| 13184 | "-enable-early-data", |
| 13185 | "-expect-ticket-supports-early-data", |
| 13186 | "-expect-reject-early-data", |
| 13187 | // The client sees HelloRetryRequest before the resumption result, |
| 13188 | // though neither value is inherently preferable. |
| 13189 | "-on-retry-expect-early-data-reason", "hello_retry_request", |
| 13190 | // Test the peer certificate is reported correctly in each of the |
| 13191 | // three logical connections. |
| 13192 | "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 13193 | "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile), |
| 13194 | "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile), |
| 13195 | // Session tickets are disabled, so the runner will not send a ticket. |
| 13196 | "-on-retry-expect-no-session", |
| 13197 | }, |
| 13198 | }) |
| 13199 |
| 13200 | // Test the server rejects 0-RTT if it needs to send a HelloRetryRequest. |
| 13201 | testCases = append(testCases, testCase{ |
| 13202 | testType: serverTest, |
| 13203 | name: "EarlyData-HRR-RejectTicket-Server-TLS13", |
| 13204 | config: Config{ |
| 13205 | MaxVersion: VersionTLS13, |
| 13206 | MinVersion: VersionTLS13, |
| 13207 | // Require a HelloRetryRequest for every curve. |
| 13208 | DefaultCurves: []CurveID{}, |
| 13209 | Bugs: ProtocolBugs{ |
| 13210 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13211 | ExpectEarlyDataAccepted: false, |
| 13212 | // Corrupt the ticket. |
| 13213 | FilterTicket: func(in []byte) ([]byte, error) { |
| 13214 | in[len(in)-1] ^= 1 |
| 13215 | return in, nil |
| 13216 | }, |
| 13217 | }, |
| 13218 | }, |
| 13219 | messageCount: 2, |
| 13220 | resumeSession: true, |
| 13221 | expectResumeRejected: true, |
| 13222 | flags: []string{ |
| 13223 | "-enable-early-data", |
| 13224 | "-on-resume-expect-reject-early-data", |
| 13225 | // The server sees the missed resumption before HelloRetryRequest, |
| 13226 | // though neither value is inherently preferable. |
| 13227 | "-on-resume-expect-early-data-reason", "session_not_resumed", |
| 13228 | }, |
| 13229 | }) |
| 13230 |
| 13231 | // The client must check the server does not send the early_data |
| 13232 | // extension while rejecting the session. |
| 13233 | testCases = append(testCases, testCase{ |
| 13234 | testType: clientTest, |
| 13235 | name: "EarlyDataWithoutResume-Client-TLS13", |
| 13236 | config: Config{ |
| 13237 | MaxVersion: VersionTLS13, |
| 13238 | MaxEarlyDataSize: 16384, |
| 13239 | }, |
| 13240 | resumeConfig: &Config{ |
| 13241 | MaxVersion: VersionTLS13, |
| 13242 | SessionTicketsDisabled: true, |
| 13243 | Bugs: ProtocolBugs{ |
| 13244 | SendEarlyDataExtension: true, |
| 13245 | }, |
| 13246 | }, |
| 13247 | resumeSession: true, |
| 13248 | flags: []string{ |
| 13249 | "-enable-early-data", |
| 13250 | "-expect-ticket-supports-early-data", |
| 13251 | }, |
| 13252 | shouldFail: true, |
| 13253 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 13254 | }) |
| 13255 |
| 13256 | // The client must fail with a dedicated error code if the server |
| 13257 | // responds with TLS 1.2 when offering 0-RTT. |
| 13258 | testCases = append(testCases, testCase{ |
| 13259 | testType: clientTest, |
| 13260 | name: "EarlyDataVersionDowngrade-Client-TLS13", |
| 13261 | config: Config{ |
| 13262 | MaxVersion: VersionTLS13, |
| 13263 | MaxEarlyDataSize: 16384, |
| 13264 | }, |
| 13265 | resumeConfig: &Config{ |
| 13266 | MaxVersion: VersionTLS12, |
| 13267 | }, |
| 13268 | resumeSession: true, |
| 13269 | flags: []string{ |
| 13270 | "-enable-early-data", |
| 13271 | "-expect-ticket-supports-early-data", |
| 13272 | }, |
| 13273 | shouldFail: true, |
| 13274 | expectedError: ":WRONG_VERSION_ON_EARLY_DATA:", |
| 13275 | }) |
| 13276 |
| 13277 | // Test that the client rejects an (unsolicited) early_data extension if |
| 13278 | // the server sent an HRR. |
| 13279 | testCases = append(testCases, testCase{ |
| 13280 | testType: clientTest, |
| 13281 | name: "ServerAcceptsEarlyDataOnHRR-Client-TLS13", |
| 13282 | config: Config{ |
| 13283 | MaxVersion: VersionTLS13, |
| 13284 | MaxEarlyDataSize: 16384, |
| 13285 | }, |
| 13286 | resumeConfig: &Config{ |
| 13287 | MaxVersion: VersionTLS13, |
| 13288 | MaxEarlyDataSize: 16384, |
| 13289 | Bugs: ProtocolBugs{ |
| 13290 | SendHelloRetryRequestCookie: []byte{1, 2, 3, 4}, |
| 13291 | SendEarlyDataExtension: true, |
| 13292 | }, |
| 13293 | }, |
| 13294 | resumeSession: true, |
| 13295 | flags: []string{ |
| 13296 | "-enable-early-data", |
| 13297 | "-expect-ticket-supports-early-data", |
| 13298 | "-expect-reject-early-data", |
| 13299 | }, |
| 13300 | shouldFail: true, |
| 13301 | expectedError: ":UNEXPECTED_EXTENSION:", |
| 13302 | }) |
| 13303 |
| 13304 | testCases = append(testCases, testCase{ |
| 13305 | testType: clientTest, |
| 13306 | name: "SkipChangeCipherSpec-Client-TLS13", |
| 13307 | config: Config{ |
| 13308 | MaxVersion: VersionTLS13, |
| 13309 | Bugs: ProtocolBugs{ |
| 13310 | SkipChangeCipherSpec: true, |
| 13311 | }, |
| 13312 | }, |
| 13313 | }) |
| 13314 |
| 13315 | testCases = append(testCases, testCase{ |
| 13316 | testType: serverTest, |
| 13317 | name: "SkipChangeCipherSpec-Server-TLS13", |
| 13318 | config: Config{ |
| 13319 | MaxVersion: VersionTLS13, |
| 13320 | Bugs: ProtocolBugs{ |
| 13321 | SkipChangeCipherSpec: true, |
| 13322 | }, |
| 13323 | }, |
| 13324 | }) |
| 13325 |
| 13326 | testCases = append(testCases, testCase{ |
| 13327 | testType: clientTest, |
| 13328 | name: "TooManyChangeCipherSpec-Client-TLS13", |
| 13329 | config: Config{ |
| 13330 | MaxVersion: VersionTLS13, |
| 13331 | Bugs: ProtocolBugs{ |
| 13332 | SendExtraChangeCipherSpec: 33, |
| 13333 | }, |
| 13334 | }, |
| 13335 | shouldFail: true, |
| 13336 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 13337 | }) |
| 13338 |
| 13339 | testCases = append(testCases, testCase{ |
| 13340 | testType: serverTest, |
| 13341 | name: "TooManyChangeCipherSpec-Server-TLS13", |
| 13342 | config: Config{ |
| 13343 | MaxVersion: VersionTLS13, |
| 13344 | Bugs: ProtocolBugs{ |
| 13345 | SendExtraChangeCipherSpec: 33, |
| 13346 | }, |
| 13347 | }, |
| 13348 | shouldFail: true, |
| 13349 | expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:", |
| 13350 | }) |
| 13351 |
| 13352 | testCases = append(testCases, testCase{ |
| 13353 | name: "SendPostHandshakeChangeCipherSpec-TLS13", |
| 13354 | config: Config{ |
| 13355 | MaxVersion: VersionTLS13, |
| 13356 | Bugs: ProtocolBugs{ |
| 13357 | SendPostHandshakeChangeCipherSpec: true, |
| 13358 | }, |
| 13359 | }, |
| 13360 | shouldFail: true, |
| 13361 | expectedError: ":UNEXPECTED_RECORD:", |
| 13362 | expectedLocalError: "remote error: unexpected message", |
| 13363 | }) |
| 13364 |
| 13365 | fooString := "foo" |
| 13366 | barString := "bar" |
| 13367 |
| 13368 | // Test that the client reports the correct ALPN after a 0-RTT reject |
| 13369 | // that changed it. |
| 13370 | testCases = append(testCases, testCase{ |
| 13371 | testType: clientTest, |
| 13372 | name: "EarlyData-ALPNMismatch-Client-TLS13", |
| 13373 | config: Config{ |
| 13374 | MaxVersion: VersionTLS13, |
| 13375 | MaxEarlyDataSize: 16384, |
| 13376 | Bugs: ProtocolBugs{ |
| 13377 | ALPNProtocol: &fooString, |
| 13378 | }, |
| 13379 | }, |
| 13380 | resumeConfig: &Config{ |
| 13381 | MaxVersion: VersionTLS13, |
| 13382 | MaxEarlyDataSize: 16384, |
| 13383 | Bugs: ProtocolBugs{ |
| 13384 | ALPNProtocol: &barString, |
| 13385 | }, |
| 13386 | }, |
| 13387 | resumeSession: true, |
| 13388 | flags: []string{ |
| 13389 | "-advertise-alpn", "\x03foo\x03bar", |
| 13390 | "-enable-early-data", |
| 13391 | "-expect-ticket-supports-early-data", |
| 13392 | "-expect-reject-early-data", |
| 13393 | // The client does not learn ALPN was the cause. |
| 13394 | "-on-retry-expect-early-data-reason", "peer_declined", |
| 13395 | // In the 0-RTT state, we surface the predicted ALPN. After |
| 13396 | // processing the reject, we surface the real one. |
| 13397 | "-on-initial-expect-alpn", "foo", |
| 13398 | "-on-resume-expect-alpn", "foo", |
| 13399 | "-on-retry-expect-alpn", "bar", |
| 13400 | }, |
| 13401 | }) |
| 13402 |
| 13403 | // Test that the client reports the correct ALPN after a 0-RTT reject if |
| 13404 | // ALPN was omitted from the first connection. |
| 13405 | testCases = append(testCases, testCase{ |
| 13406 | testType: clientTest, |
| 13407 | name: "EarlyData-ALPNOmitted1-Client-TLS13", |
| 13408 | config: Config{ |
| 13409 | MaxVersion: VersionTLS13, |
| 13410 | MaxEarlyDataSize: 16384, |
| 13411 | }, |
| 13412 | resumeConfig: &Config{ |
| 13413 | MaxVersion: VersionTLS13, |
| 13414 | MaxEarlyDataSize: 16384, |
| 13415 | NextProtos: []string{"foo"}, |
| 13416 | }, |
| 13417 | resumeSession: true, |
| 13418 | flags: []string{ |
| 13419 | "-advertise-alpn", "\x03foo\x03bar", |
| 13420 | "-enable-early-data", |
| 13421 | "-expect-ticket-supports-early-data", |
| 13422 | "-expect-reject-early-data", |
| 13423 | // The client does not learn ALPN was the cause. |
| 13424 | "-on-retry-expect-early-data-reason", "peer_declined", |
| 13425 | // In the 0-RTT state, we surface the predicted ALPN. After |
| 13426 | // processing the reject, we surface the real one. |
| 13427 | "-on-initial-expect-alpn", "", |
| 13428 | "-on-resume-expect-alpn", "", |
| 13429 | "-on-retry-expect-alpn", "foo", |
| 13430 | "-on-resume-shim-writes-first", |
| 13431 | }, |
| 13432 | }) |
| 13433 |
| 13434 | // Test that the client reports the correct ALPN after a 0-RTT reject if |
| 13435 | // ALPN was omitted from the second connection. |
| 13436 | testCases = append(testCases, testCase{ |
| 13437 | testType: clientTest, |
| 13438 | name: "EarlyData-ALPNOmitted2-Client-TLS13", |
| 13439 | config: Config{ |
| 13440 | MaxVersion: VersionTLS13, |
| 13441 | MaxEarlyDataSize: 16384, |
| 13442 | NextProtos: []string{"foo"}, |
| 13443 | }, |
| 13444 | resumeConfig: &Config{ |
| 13445 | MaxVersion: VersionTLS13, |
| 13446 | MaxEarlyDataSize: 16384, |
| 13447 | }, |
| 13448 | resumeSession: true, |
| 13449 | flags: []string{ |
| 13450 | "-advertise-alpn", "\x03foo\x03bar", |
| 13451 | "-enable-early-data", |
| 13452 | "-expect-ticket-supports-early-data", |
| 13453 | "-expect-reject-early-data", |
| 13454 | // The client does not learn ALPN was the cause. |
| 13455 | "-on-retry-expect-early-data-reason", "peer_declined", |
| 13456 | // In the 0-RTT state, we surface the predicted ALPN. After |
| 13457 | // processing the reject, we surface the real one. |
| 13458 | "-on-initial-expect-alpn", "foo", |
| 13459 | "-on-resume-expect-alpn", "foo", |
| 13460 | "-on-retry-expect-alpn", "", |
| 13461 | "-on-resume-shim-writes-first", |
| 13462 | }, |
| 13463 | }) |
| 13464 |
| 13465 | // Test that the client enforces ALPN match on 0-RTT accept. |
| 13466 | testCases = append(testCases, testCase{ |
| 13467 | testType: clientTest, |
| 13468 | name: "EarlyData-BadALPNMismatch-Client-TLS13", |
| 13469 | config: Config{ |
| 13470 | MaxVersion: VersionTLS13, |
| 13471 | MaxEarlyDataSize: 16384, |
| 13472 | Bugs: ProtocolBugs{ |
| 13473 | ALPNProtocol: &fooString, |
| 13474 | }, |
| 13475 | }, |
| 13476 | resumeConfig: &Config{ |
| 13477 | MaxVersion: VersionTLS13, |
| 13478 | MaxEarlyDataSize: 16384, |
| 13479 | Bugs: ProtocolBugs{ |
| 13480 | AlwaysAcceptEarlyData: true, |
| 13481 | ALPNProtocol: &barString, |
| 13482 | }, |
| 13483 | }, |
| 13484 | resumeSession: true, |
| 13485 | flags: []string{ |
| 13486 | "-advertise-alpn", "\x03foo\x03bar", |
| 13487 | "-enable-early-data", |
| 13488 | "-expect-ticket-supports-early-data", |
| 13489 | "-on-initial-expect-alpn", "foo", |
| 13490 | "-on-resume-expect-alpn", "foo", |
| 13491 | "-on-retry-expect-alpn", "bar", |
| 13492 | }, |
| 13493 | shouldFail: true, |
| 13494 | expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:", |
| 13495 | }) |
| 13496 |
| 13497 | // Test that the client does not offer early data if it is incompatible |
| 13498 | // with ALPN preferences. |
| 13499 | testCases = append(testCases, testCase{ |
| 13500 | testType: clientTest, |
| 13501 | name: "EarlyData-ALPNPreferenceChanged-TLS13", |
| 13502 | config: Config{ |
| 13503 | MaxVersion: VersionTLS13, |
| 13504 | MaxEarlyDataSize: 16384, |
| 13505 | NextProtos: []string{"foo", "bar"}, |
| 13506 | }, |
| 13507 | resumeSession: true, |
| 13508 | flags: []string{ |
| 13509 | "-enable-early-data", |
| 13510 | "-expect-ticket-supports-early-data", |
| 13511 | "-expect-no-offer-early-data", |
| 13512 | // Offer different ALPN values in the initial and resumption. |
| 13513 | "-on-initial-advertise-alpn", "\x03foo", |
| 13514 | "-on-initial-expect-alpn", "foo", |
| 13515 | "-on-resume-advertise-alpn", "\x03bar", |
| 13516 | "-on-resume-expect-alpn", "bar", |
| 13517 | // The ALPN mismatch comes from the client, so it reports it as the |
| 13518 | // reason. |
| 13519 | "-on-resume-expect-early-data-reason", "alpn_mismatch", |
| 13520 | }, |
| 13521 | }) |
| 13522 |
| 13523 | // Test that the client does not offer 0-RTT to servers which never |
| 13524 | // advertise it. |
| 13525 | testCases = append(testCases, testCase{ |
| 13526 | testType: clientTest, |
| 13527 | name: "EarlyData-NonZeroRTTSession-Client-TLS13", |
| 13528 | config: Config{ |
| 13529 | MaxVersion: VersionTLS13, |
| 13530 | }, |
| 13531 | resumeSession: true, |
| 13532 | flags: []string{ |
| 13533 | "-enable-early-data", |
| 13534 | "-on-resume-expect-no-offer-early-data", |
| 13535 | // The client declines to offer 0-RTT because of the session. |
| 13536 | "-on-resume-expect-early-data-reason", "unsupported_for_session", |
| 13537 | }, |
| 13538 | }) |
| 13539 |
| 13540 | // Test that the server correctly rejects 0-RTT when the previous |
| 13541 | // session did not allow early data on resumption. |
| 13542 | testCases = append(testCases, testCase{ |
| 13543 | testType: serverTest, |
| 13544 | name: "EarlyData-NonZeroRTTSession-Server-TLS13", |
| 13545 | config: Config{ |
| 13546 | MaxVersion: VersionTLS13, |
| 13547 | }, |
| 13548 | resumeConfig: &Config{ |
| 13549 | MaxVersion: VersionTLS13, |
| 13550 | Bugs: ProtocolBugs{ |
| 13551 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13552 | ExpectEarlyDataAccepted: false, |
| 13553 | }, |
| 13554 | }, |
| 13555 | resumeSession: true, |
| 13556 | flags: []string{ |
| 13557 | "-on-resume-enable-early-data", |
| 13558 | "-expect-reject-early-data", |
| 13559 | // The server rejects 0-RTT because of the session. |
| 13560 | "-on-resume-expect-early-data-reason", "unsupported_for_session", |
| 13561 | }, |
| 13562 | }) |
| 13563 |
| 13564 | // Test that we reject early data where ALPN is omitted from the first |
| 13565 | // connection. |
| 13566 | testCases = append(testCases, testCase{ |
| 13567 | testType: serverTest, |
| 13568 | name: "EarlyData-ALPNOmitted1-Server-TLS13", |
| 13569 | config: Config{ |
| 13570 | MaxVersion: VersionTLS13, |
| 13571 | NextProtos: []string{}, |
| 13572 | }, |
| 13573 | resumeConfig: &Config{ |
| 13574 | MaxVersion: VersionTLS13, |
| 13575 | NextProtos: []string{"foo"}, |
| 13576 | Bugs: ProtocolBugs{ |
| 13577 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13578 | ExpectEarlyDataAccepted: false, |
| 13579 | }, |
| 13580 | }, |
| 13581 | resumeSession: true, |
| 13582 | flags: []string{ |
| 13583 | "-enable-early-data", |
| 13584 | "-on-initial-select-alpn", "", |
| 13585 | "-on-resume-select-alpn", "foo", |
| 13586 | "-on-resume-expect-early-data-reason", "alpn_mismatch", |
| 13587 | }, |
| 13588 | }) |
| 13589 |
| 13590 | // Test that we reject early data where ALPN is omitted from the second |
| 13591 | // connection. |
| 13592 | testCases = append(testCases, testCase{ |
| 13593 | testType: serverTest, |
| 13594 | name: "EarlyData-ALPNOmitted2-Server-TLS13", |
| 13595 | config: Config{ |
| 13596 | MaxVersion: VersionTLS13, |
| 13597 | NextProtos: []string{"foo"}, |
| 13598 | }, |
| 13599 | resumeConfig: &Config{ |
| 13600 | MaxVersion: VersionTLS13, |
| 13601 | NextProtos: []string{}, |
| 13602 | Bugs: ProtocolBugs{ |
| 13603 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13604 | ExpectEarlyDataAccepted: false, |
| 13605 | }, |
| 13606 | }, |
| 13607 | resumeSession: true, |
| 13608 | flags: []string{ |
| 13609 | "-enable-early-data", |
| 13610 | "-on-initial-select-alpn", "foo", |
| 13611 | "-on-resume-select-alpn", "", |
| 13612 | "-on-resume-expect-early-data-reason", "alpn_mismatch", |
| 13613 | }, |
| 13614 | }) |
| 13615 |
| 13616 | // Test that we reject early data with mismatched ALPN. |
| 13617 | testCases = append(testCases, testCase{ |
| 13618 | testType: serverTest, |
| 13619 | name: "EarlyData-ALPNMismatch-Server-TLS13", |
| 13620 | config: Config{ |
| 13621 | MaxVersion: VersionTLS13, |
| 13622 | NextProtos: []string{"foo"}, |
| 13623 | }, |
| 13624 | resumeConfig: &Config{ |
| 13625 | MaxVersion: VersionTLS13, |
| 13626 | NextProtos: []string{"bar"}, |
| 13627 | Bugs: ProtocolBugs{ |
| 13628 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13629 | ExpectEarlyDataAccepted: false, |
| 13630 | }, |
| 13631 | }, |
| 13632 | resumeSession: true, |
| 13633 | flags: []string{ |
| 13634 | "-enable-early-data", |
| 13635 | "-on-initial-select-alpn", "foo", |
| 13636 | "-on-resume-select-alpn", "bar", |
| 13637 | "-on-resume-expect-early-data-reason", "alpn_mismatch", |
| 13638 | }, |
| 13639 | }) |
| 13640 |
| 13641 | // Test that the client offering 0-RTT and Channel ID forbids the server |
| 13642 | // from accepting both. |
| 13643 | testCases = append(testCases, testCase{ |
| 13644 | testType: clientTest, |
| 13645 | name: "EarlyDataChannelID-AcceptBoth-Client-TLS13", |
| 13646 | config: Config{ |
| 13647 | MaxVersion: VersionTLS13, |
| 13648 | MaxEarlyDataSize: 16384, |
| 13649 | RequestChannelID: true, |
| 13650 | }, |
| 13651 | resumeSession: true, |
| 13652 | expectChannelID: true, |
| 13653 | shouldFail: true, |
| 13654 | expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:", |
| 13655 | flags: []string{ |
| 13656 | "-enable-early-data", |
| 13657 | "-expect-ticket-supports-early-data", |
| 13658 | "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile), |
| 13659 | }, |
| 13660 | }) |
| 13661 |
| 13662 | // Test that the client offering Channel ID and 0-RTT allows the server |
| 13663 | // to decline 0-RTT. |
| 13664 | testCases = append(testCases, testCase{ |
| 13665 | testType: clientTest, |
| 13666 | name: "EarlyDataChannelID-AcceptChannelID-Client-TLS13", |
| 13667 | config: Config{ |
| 13668 | MaxVersion: VersionTLS13, |
| 13669 | MaxEarlyDataSize: 16384, |
| 13670 | RequestChannelID: true, |
| 13671 | Bugs: ProtocolBugs{ |
| 13672 | AlwaysRejectEarlyData: true, |
| 13673 | }, |
| 13674 | }, |
| 13675 | resumeSession: true, |
| 13676 | expectChannelID: true, |
| 13677 | flags: []string{ |
| 13678 | "-enable-early-data", |
| 13679 | "-expect-ticket-supports-early-data", |
| 13680 | "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile), |
| 13681 | "-expect-reject-early-data", |
| 13682 | // The client never learns the reason was Channel ID. |
| 13683 | "-on-retry-expect-early-data-reason", "peer_declined", |
| 13684 | }, |
| 13685 | }) |
| 13686 |
| 13687 | // Test that the client offering Channel ID and 0-RTT allows the server |
| 13688 | // to decline Channel ID. |
| 13689 | testCases = append(testCases, testCase{ |
| 13690 | testType: clientTest, |
| 13691 | name: "EarlyDataChannelID-AcceptEarlyData-Client-TLS13", |
| 13692 | config: Config{ |
| 13693 | MaxVersion: VersionTLS13, |
| 13694 | MaxEarlyDataSize: 16384, |
| 13695 | }, |
| 13696 | resumeSession: true, |
| 13697 | flags: []string{ |
| 13698 | "-enable-early-data", |
| 13699 | "-expect-ticket-supports-early-data", |
| 13700 | "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile), |
| 13701 | "-on-resume-expect-accept-early-data", |
| 13702 | "-on-resume-expect-early-data-reason", "accept", |
| 13703 | }, |
| 13704 | }) |
| 13705 |
| 13706 | // Test that the server supporting Channel ID and 0-RTT declines 0-RTT |
| 13707 | // if it would negotiate Channel ID. |
| 13708 | testCases = append(testCases, testCase{ |
| 13709 | testType: serverTest, |
| 13710 | name: "EarlyDataChannelID-OfferBoth-Server-TLS13", |
| 13711 | config: Config{ |
| 13712 | MaxVersion: VersionTLS13, |
| 13713 | ChannelID: channelIDKey, |
| 13714 | Bugs: ProtocolBugs{ |
| 13715 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13716 | ExpectEarlyDataAccepted: false, |
| 13717 | }, |
| 13718 | }, |
| 13719 | resumeSession: true, |
| 13720 | expectChannelID: true, |
| 13721 | flags: []string{ |
| 13722 | "-enable-early-data", |
| 13723 | "-expect-reject-early-data", |
| 13724 | "-expect-channel-id", |
| 13725 | base64.StdEncoding.EncodeToString(channelIDBytes), |
| 13726 | "-on-resume-expect-early-data-reason", "channel_id", |
| 13727 | }, |
| 13728 | }) |
| 13729 |
| 13730 | // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT |
| 13731 | // if not offered Channel ID. |
| 13732 | testCases = append(testCases, testCase{ |
| 13733 | testType: serverTest, |
| 13734 | name: "EarlyDataChannelID-OfferEarlyData-Server-TLS13", |
| 13735 | config: Config{ |
| 13736 | MaxVersion: VersionTLS13, |
| 13737 | Bugs: ProtocolBugs{ |
| 13738 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13739 | ExpectEarlyDataAccepted: true, |
| 13740 | ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}}, |
| 13741 | }, |
| 13742 | }, |
| 13743 | resumeSession: true, |
| 13744 | expectChannelID: false, |
| 13745 | flags: []string{ |
| 13746 | "-enable-early-data", |
| 13747 | "-on-resume-expect-accept-early-data", |
| 13748 | "-enable-channel-id", |
| 13749 | "-on-resume-expect-early-data-reason", "accept", |
| 13750 | }, |
| 13751 | }) |
| 13752 |
| 13753 | // Test that the server rejects 0-RTT streams without end_of_early_data. |
| 13754 | // The subsequent records should fail to decrypt. |
| 13755 | testCases = append(testCases, testCase{ |
| 13756 | testType: serverTest, |
| 13757 | name: "EarlyData-SkipEndOfEarlyData-TLS13", |
| 13758 | config: Config{ |
| 13759 | MaxVersion: VersionTLS13, |
| 13760 | Bugs: ProtocolBugs{ |
| 13761 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13762 | ExpectEarlyDataAccepted: true, |
| 13763 | SkipEndOfEarlyData: true, |
| 13764 | }, |
| 13765 | }, |
| 13766 | resumeSession: true, |
| 13767 | flags: []string{"-enable-early-data"}, |
| 13768 | shouldFail: true, |
| 13769 | expectedLocalError: "remote error: bad record MAC", |
| 13770 | expectedError: ":BAD_DECRYPT:", |
| 13771 | }) |
| 13772 |
| 13773 | testCases = append(testCases, testCase{ |
| 13774 | testType: serverTest, |
| 13775 | name: "EarlyData-UnexpectedHandshake-Server-TLS13", |
| 13776 | config: Config{ |
| 13777 | MaxVersion: VersionTLS13, |
| 13778 | }, |
| 13779 | resumeConfig: &Config{ |
| 13780 | MaxVersion: VersionTLS13, |
| 13781 | Bugs: ProtocolBugs{ |
| 13782 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13783 | SendStrayEarlyHandshake: true, |
| 13784 | ExpectEarlyDataAccepted: true, |
| 13785 | }, |
| 13786 | }, |
| 13787 | resumeSession: true, |
| 13788 | shouldFail: true, |
| 13789 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 13790 | expectedLocalError: "remote error: unexpected message", |
| 13791 | flags: []string{ |
| 13792 | "-enable-early-data", |
| 13793 | }, |
| 13794 | }) |
| 13795 |
| 13796 | // Test that the client reports TLS 1.3 as the version while sending |
| 13797 | // early data. |
| 13798 | testCases = append(testCases, testCase{ |
| 13799 | testType: clientTest, |
| 13800 | name: "EarlyData-Client-VersionAPI-TLS13", |
| 13801 | config: Config{ |
| 13802 | MaxVersion: VersionTLS13, |
| 13803 | MaxEarlyDataSize: 16384, |
| 13804 | }, |
| 13805 | resumeSession: true, |
| 13806 | flags: []string{ |
| 13807 | "-enable-early-data", |
| 13808 | "-expect-ticket-supports-early-data", |
| 13809 | "-on-resume-expect-accept-early-data", |
| 13810 | "-expect-version", strconv.Itoa(VersionTLS13), |
| 13811 | }, |
| 13812 | }) |
| 13813 |
| 13814 | // Test that client and server both notice handshake errors after data |
| 13815 | // has started flowing. |
| 13816 | testCases = append(testCases, testCase{ |
| 13817 | testType: clientTest, |
| 13818 | name: "EarlyData-Client-BadFinished-TLS13", |
| 13819 | config: Config{ |
| 13820 | MaxVersion: VersionTLS13, |
| 13821 | MaxEarlyDataSize: 16384, |
| 13822 | }, |
| 13823 | resumeConfig: &Config{ |
| 13824 | MaxVersion: VersionTLS13, |
| 13825 | MaxEarlyDataSize: 16384, |
| 13826 | Bugs: ProtocolBugs{ |
| 13827 | BadFinished: true, |
| 13828 | }, |
| 13829 | }, |
| 13830 | resumeSession: true, |
| 13831 | flags: []string{ |
| 13832 | "-enable-early-data", |
| 13833 | "-expect-ticket-supports-early-data", |
| 13834 | "-on-resume-expect-accept-early-data", |
| 13835 | }, |
| 13836 | shouldFail: true, |
| 13837 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 13838 | expectedLocalError: "remote error: error decrypting message", |
| 13839 | }) |
| 13840 | testCases = append(testCases, testCase{ |
| 13841 | testType: serverTest, |
| 13842 | name: "EarlyData-Server-BadFinished-TLS13", |
| 13843 | config: Config{ |
| 13844 | MaxVersion: VersionTLS13, |
| 13845 | }, |
| 13846 | resumeConfig: &Config{ |
| 13847 | MaxVersion: VersionTLS13, |
| 13848 | Bugs: ProtocolBugs{ |
| 13849 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13850 | ExpectEarlyDataAccepted: true, |
| 13851 | ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}}, |
| 13852 | BadFinished: true, |
| 13853 | }, |
| 13854 | }, |
| 13855 | resumeSession: true, |
| 13856 | flags: []string{ |
| 13857 | "-enable-early-data", |
| 13858 | "-on-resume-expect-accept-early-data", |
| 13859 | }, |
| 13860 | shouldFail: true, |
| 13861 | expectedError: ":DIGEST_CHECK_FAILED:", |
| 13862 | expectedLocalError: "remote error: error decrypting message", |
| 13863 | }) |
| 13864 |
| 13865 | testCases = append(testCases, testCase{ |
| 13866 | testType: serverTest, |
| 13867 | name: "Server-NonEmptyEndOfEarlyData-TLS13", |
| 13868 | config: Config{ |
| 13869 | MaxVersion: VersionTLS13, |
| 13870 | }, |
| 13871 | resumeConfig: &Config{ |
| 13872 | MaxVersion: VersionTLS13, |
| 13873 | Bugs: ProtocolBugs{ |
| 13874 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 13875 | ExpectEarlyDataAccepted: true, |
| 13876 | NonEmptyEndOfEarlyData: true, |
| 13877 | }, |
| 13878 | }, |
| 13879 | resumeSession: true, |
| 13880 | flags: []string{ |
| 13881 | "-enable-early-data", |
| 13882 | "-expect-ticket-supports-early-data", |
| 13883 | "-on-resume-expect-accept-early-data", |
| 13884 | }, |
| 13885 | shouldFail: true, |
| 13886 | expectedError: ":DECODE_ERROR:", |
| 13887 | }) |
| 13888 |
| 13889 | testCases = append(testCases, testCase{ |
| 13890 | testType: serverTest, |
| 13891 | name: "ServerSkipCertificateVerify-TLS13", |
| 13892 | config: Config{ |
| 13893 | MinVersion: VersionTLS13, |
| 13894 | MaxVersion: VersionTLS13, |
| 13895 | Certificates: []Certificate{rsaChainCertificate}, |
| 13896 | Bugs: ProtocolBugs{ |
| 13897 | SkipCertificateVerify: true, |
| 13898 | }, |
| 13899 | }, |
| 13900 | expectPeerCertificate: &rsaChainCertificate, |
| 13901 | flags: []string{ |
| 13902 | "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile), |
| 13903 | "-key-file", path.Join(*resourceDir, rsaChainKeyFile), |
| 13904 | "-require-any-client-certificate", |
| 13905 | }, |
| 13906 | shouldFail: true, |
| 13907 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 13908 | expectedLocalError: "remote error: unexpected message", |
| 13909 | }) |
| 13910 | testCases = append(testCases, testCase{ |
| 13911 | testType: clientTest, |
| 13912 | name: "ClientSkipCertificateVerify-TLS13", |
| 13913 | config: Config{ |
| 13914 | MinVersion: VersionTLS13, |
| 13915 | MaxVersion: VersionTLS13, |
| 13916 | Certificates: []Certificate{rsaChainCertificate}, |
| 13917 | Bugs: ProtocolBugs{ |
| 13918 | SkipCertificateVerify: true, |
| 13919 | }, |
| 13920 | }, |
| 13921 | expectPeerCertificate: &rsaChainCertificate, |
| 13922 | flags: []string{ |
| 13923 | "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile), |
| 13924 | "-key-file", path.Join(*resourceDir, rsaChainKeyFile), |
| 13925 | }, |
| 13926 | shouldFail: true, |
| 13927 | expectedError: ":UNEXPECTED_MESSAGE:", |
| 13928 | expectedLocalError: "remote error: unexpected message", |
| 13929 | }) |
| 13930 |
| 13931 | // If the client or server has 0-RTT enabled but disabled TLS 1.3, it should |
| 13932 | // report a reason of protocol_version. |
| 13933 | testCases = append(testCases, testCase{ |
| 13934 | testType: clientTest, |
| 13935 | name: "EarlyDataEnabled-Client-MaxTLS12", |
| 13936 | expectedVersion: VersionTLS12, |
| 13937 | flags: []string{ |
| 13938 | "-enable-early-data", |
| 13939 | "-max-version", strconv.Itoa(VersionTLS12), |
| 13940 | "-expect-early-data-reason", "protocol_version", |
| 13941 | }, |
| 13942 | }) |
| 13943 | testCases = append(testCases, testCase{ |
| 13944 | testType: serverTest, |
| 13945 | name: "EarlyDataEnabled-Server-MaxTLS12", |
| 13946 | expectedVersion: VersionTLS12, |
| 13947 | flags: []string{ |
| 13948 | "-enable-early-data", |
| 13949 | "-max-version", strconv.Itoa(VersionTLS12), |
| 13950 | "-expect-early-data-reason", "protocol_version", |
| 13951 | }, |
| 13952 | }) |
| 13953 |
| 13954 | // The server additionally reports protocol_version if it enabled TLS 1.3, |
| 13955 | // but the peer negotiated TLS 1.2. (The corresponding situation does not |
| 13956 | // exist on the client because negotiating TLS 1.2 with a 0-RTT ClientHello |
| 13957 | // is a fatal error.) |
| 13958 | testCases = append(testCases, testCase{ |
| 13959 | testType: serverTest, |
| 13960 | name: "EarlyDataEnabled-Server-NegotiateTLS12", |
| 13961 | config: Config{ |
| 13962 | MaxVersion: VersionTLS12, |
| 13963 | }, |
| 13964 | expectedVersion: VersionTLS12, |
| 13965 | flags: []string{ |
| 13966 | "-enable-early-data", |
| 13967 | "-expect-early-data-reason", "protocol_version", |
| 13968 | }, |
| 13969 | }) |
| 13970 | } |
| 13971 |
| 13972 | func addTLS13CipherPreferenceTests() { |
| 13973 | // Test that client preference is honored if the shim has AES hardware |
| 13974 | // and ChaCha20-Poly1305 is preferred otherwise. |
| 13975 | testCases = append(testCases, testCase{ |
| 13976 | testType: serverTest, |
| 13977 | name: "TLS13-CipherPreference-Server-ChaCha20-AES", |
| 13978 | config: Config{ |
| 13979 | MaxVersion: VersionTLS13, |
| 13980 | CipherSuites: []uint16{ |
| 13981 | TLS_CHACHA20_POLY1305_SHA256, |
| 13982 | TLS_AES_128_GCM_SHA256, |
| 13983 | }, |
| 13984 | CurvePreferences: []CurveID{CurveX25519}, |
| 13985 | }, |
| 13986 | flags: []string{ |
| 13987 | "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)), |
| 13988 | "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)), |
| 13989 | }, |
| 13990 | }) |
| 13991 |
| 13992 | testCases = append(testCases, testCase{ |
| 13993 | testType: serverTest, |
| 13994 | name: "TLS13-CipherPreference-Server-AES-ChaCha20", |
| 13995 | config: Config{ |
| 13996 | MaxVersion: VersionTLS13, |
| 13997 | CipherSuites: []uint16{ |
| 13998 | TLS_AES_128_GCM_SHA256, |
| 13999 | TLS_CHACHA20_POLY1305_SHA256, |
| 14000 | }, |
| 14001 | CurvePreferences: []CurveID{CurveX25519}, |
| 14002 | }, |
| 14003 | flags: []string{ |
| 14004 | "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)), |
| 14005 | "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)), |
| 14006 | }, |
| 14007 | }) |
| 14008 |
| 14009 | // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on |
| 14010 | // whether it has AES hardware. |
| 14011 | testCases = append(testCases, testCase{ |
| 14012 | name: "TLS13-CipherPreference-Client", |
| 14013 | config: Config{ |
| 14014 | MaxVersion: VersionTLS13, |
| 14015 | // Use the client cipher order. (This is the default but |
| 14016 | // is listed to be explicit.) |
| 14017 | PreferServerCipherSuites: false, |
| 14018 | }, |
| 14019 | flags: []string{ |
| 14020 | "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)), |
| 14021 | "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)), |
| 14022 | }, |
| 14023 | }) |
| 14024 |
| 14025 | // CECPQ2 prefers 256-bit ciphers but will use AES-128 if there's nothing else. |
| 14026 | testCases = append(testCases, testCase{ |
| 14027 | testType: serverTest, |
| 14028 | name: "TLS13-CipherPreference-CECPQ2-AES128Only", |
| 14029 | config: Config{ |
| 14030 | MaxVersion: VersionTLS13, |
| 14031 | CipherSuites: []uint16{ |
| 14032 | TLS_AES_128_GCM_SHA256, |
| 14033 | }, |
| 14034 | }, |
| 14035 | flags: []string{ |
| 14036 | "-curves", strconv.Itoa(int(CurveCECPQ2)), |
| 14037 | }, |
| 14038 | }) |
| 14039 |
| 14040 | // CECPQ2b prefers 256-bit ciphers but will use AES-128 if there's nothing else. |
| 14041 | testCases = append(testCases, testCase{ |
| 14042 | testType: serverTest, |
| 14043 | name: "TLS13-CipherPreference-CECPQ2b-AES128Only", |
| 14044 | config: Config{ |
| 14045 | MaxVersion: VersionTLS13, |
| 14046 | CipherSuites: []uint16{ |
| 14047 | TLS_AES_128_GCM_SHA256, |
| 14048 | }, |
| 14049 | }, |
| 14050 | flags: []string{ |
| 14051 | "-curves", strconv.Itoa(int(CurveCECPQ2b)), |
| 14052 | }, |
| 14053 | }) |
| 14054 |
| 14055 | // When a 256-bit cipher is offered, even if not in first place, it should be |
| 14056 | // picked. |
| 14057 | testCases = append(testCases, testCase{ |
| 14058 | testType: serverTest, |
| 14059 | name: "TLS13-CipherPreference-CECPQ2-AES256Preferred", |
| 14060 | config: Config{ |
| 14061 | MaxVersion: VersionTLS13, |
| 14062 | CipherSuites: []uint16{ |
| 14063 | TLS_AES_128_GCM_SHA256, |
| 14064 | TLS_AES_256_GCM_SHA384, |
| 14065 | }, |
| 14066 | }, |
| 14067 | flags: []string{ |
| 14068 | "-curves", strconv.Itoa(int(CurveCECPQ2)), |
| 14069 | }, |
| 14070 | expectedCipher: TLS_AES_256_GCM_SHA384, |
| 14071 | }) |
| 14072 | // ... but when CECPQ2 isn't being used, the client's preference controls. |
| 14073 | testCases = append(testCases, testCase{ |
| 14074 | testType: serverTest, |
| 14075 | name: "TLS13-CipherPreference-CECPQ2-AES128PreferredOtherwise", |
| 14076 | config: Config{ |
| 14077 | MaxVersion: VersionTLS13, |
| 14078 | CipherSuites: []uint16{ |
| 14079 | TLS_AES_128_GCM_SHA256, |
| 14080 | TLS_AES_256_GCM_SHA384, |
| 14081 | }, |
| 14082 | }, |
| 14083 | flags: []string{ |
| 14084 | "-curves", strconv.Itoa(int(CurveX25519)), |
| 14085 | }, |
| 14086 | expectedCipher: TLS_AES_128_GCM_SHA256, |
| 14087 | }) |
| 14088 |
| 14089 | // When a 256-bit cipher is offered, even if not in first place, it should be |
| 14090 | // picked. |
| 14091 | testCases = append(testCases, testCase{ |
| 14092 | testType: serverTest, |
| 14093 | name: "TLS13-CipherPreference-CECPQ2b-AES256Preferred", |
| 14094 | config: Config{ |
| 14095 | MaxVersion: VersionTLS13, |
| 14096 | CipherSuites: []uint16{ |
| 14097 | TLS_AES_128_GCM_SHA256, |
| 14098 | TLS_AES_256_GCM_SHA384, |
| 14099 | }, |
| 14100 | }, |
| 14101 | flags: []string{ |
| 14102 | "-curves", strconv.Itoa(int(CurveCECPQ2b)), |
| 14103 | }, |
| 14104 | expectedCipher: TLS_AES_256_GCM_SHA384, |
| 14105 | }) |
| 14106 | // ... but when CECPQ2b isn't being used, the client's preference controls. |
| 14107 | testCases = append(testCases, testCase{ |
| 14108 | testType: serverTest, |
| 14109 | name: "TLS13-CipherPreference-CECPQ2b-AES128PreferredOtherwise", |
| 14110 | config: Config{ |
| 14111 | MaxVersion: VersionTLS13, |
| 14112 | CipherSuites: []uint16{ |
| 14113 | TLS_AES_128_GCM_SHA256, |
| 14114 | TLS_AES_256_GCM_SHA384, |
| 14115 | }, |
| 14116 | }, |
| 14117 | flags: []string{ |
| 14118 | "-curves", strconv.Itoa(int(CurveX25519)), |
| 14119 | }, |
| 14120 | expectedCipher: TLS_AES_128_GCM_SHA256, |
| 14121 | }) |
| 14122 |
| 14123 | // Test that CECPQ2 continues to honor AES vs ChaCha20 logic. |
| 14124 | testCases = append(testCases, testCase{ |
| 14125 | testType: serverTest, |
| 14126 | name: "TLS13-CipherPreference-CECPQ2-AES128-ChaCha20-AES256", |
| 14127 | config: Config{ |
| 14128 | MaxVersion: VersionTLS13, |
| 14129 | CipherSuites: []uint16{ |
| 14130 | TLS_AES_128_GCM_SHA256, |
| 14131 | TLS_CHACHA20_POLY1305_SHA256, |
| 14132 | TLS_AES_256_GCM_SHA384, |
| 14133 | }, |
| 14134 | }, |
| 14135 | flags: []string{ |
| 14136 | "-curves", strconv.Itoa(int(CurveCECPQ2)), |
| 14137 | "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)), |
| 14138 | "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)), |
| 14139 | }, |
| 14140 | }) |
| 14141 | testCases = append(testCases, testCase{ |
| 14142 | testType: serverTest, |
| 14143 | name: "TLS13-CipherPreference-CECPQ2-AES128-AES256-ChaCha20", |
| 14144 | config: Config{ |
| 14145 | MaxVersion: VersionTLS13, |
| 14146 | CipherSuites: []uint16{ |
| 14147 | TLS_AES_128_GCM_SHA256, |
| 14148 | TLS_AES_256_GCM_SHA384, |
| 14149 | TLS_CHACHA20_POLY1305_SHA256, |
| 14150 | }, |
| 14151 | }, |
| 14152 | flags: []string{ |
| 14153 | "-curves", strconv.Itoa(int(CurveCECPQ2)), |
| 14154 | "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_256_GCM_SHA384)), |
| 14155 | "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)), |
| 14156 | }, |
| 14157 | }) |
| 14158 |
| 14159 | // Test that CECPQ2b continues to honor AES vs ChaCha20 logic. |
| 14160 | testCases = append(testCases, testCase{ |
| 14161 | testType: serverTest, |
| 14162 | name: "TLS13-CipherPreference-CECPQ2b-AES128-ChaCha20-AES256", |
| 14163 | config: Config{ |
| 14164 | MaxVersion: VersionTLS13, |
| 14165 | CipherSuites: []uint16{ |
| 14166 | TLS_AES_128_GCM_SHA256, |
| 14167 | TLS_CHACHA20_POLY1305_SHA256, |
| 14168 | TLS_AES_256_GCM_SHA384, |
| 14169 | }, |
| 14170 | }, |
| 14171 | flags: []string{ |
| 14172 | "-curves", strconv.Itoa(int(CurveCECPQ2b)), |
| 14173 | "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)), |
| 14174 | "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)), |
| 14175 | }, |
| 14176 | }) |
| 14177 | testCases = append(testCases, testCase{ |
| 14178 | testType: serverTest, |
| 14179 | name: "TLS13-CipherPreference-CECPQ2b-AES128-AES256-ChaCha20", |
| 14180 | config: Config{ |
| 14181 | MaxVersion: VersionTLS13, |
| 14182 | CipherSuites: []uint16{ |
| 14183 | TLS_AES_128_GCM_SHA256, |
| 14184 | TLS_AES_256_GCM_SHA384, |
| 14185 | TLS_CHACHA20_POLY1305_SHA256, |
| 14186 | }, |
| 14187 | }, |
| 14188 | flags: []string{ |
| 14189 | "-curves", strconv.Itoa(int(CurveCECPQ2b)), |
| 14190 | "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_256_GCM_SHA384)), |
| 14191 | "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)), |
| 14192 | }, |
| 14193 | }) |
| 14194 | } |
| 14195 |
| 14196 | func addPeekTests() { |
| 14197 | // Test SSL_peek works, including on empty records. |
| 14198 | testCases = append(testCases, testCase{ |
| 14199 | name: "Peek-Basic", |
| 14200 | sendEmptyRecords: 1, |
| 14201 | flags: []string{"-peek-then-read"}, |
| 14202 | }) |
| 14203 |
| 14204 | // Test SSL_peek can drive the initial handshake. |
| 14205 | testCases = append(testCases, testCase{ |
| 14206 | name: "Peek-ImplicitHandshake", |
| 14207 | flags: []string{ |
| 14208 | "-peek-then-read", |
| 14209 | "-implicit-handshake", |
| 14210 | }, |
| 14211 | }) |
| 14212 |
| 14213 | // Test SSL_peek can discover and drive a renegotiation. |
| 14214 | testCases = append(testCases, testCase{ |
| 14215 | name: "Peek-Renegotiate", |
| 14216 | config: Config{ |
| 14217 | MaxVersion: VersionTLS12, |
| 14218 | }, |
| 14219 | renegotiate: 1, |
| 14220 | flags: []string{ |
| 14221 | "-peek-then-read", |
| 14222 | "-renegotiate-freely", |
| 14223 | "-expect-total-renegotiations", "1", |
| 14224 | }, |
| 14225 | }) |
| 14226 |
| 14227 | // Test SSL_peek can discover a close_notify. |
| 14228 | testCases = append(testCases, testCase{ |
| 14229 | name: "Peek-Shutdown", |
| 14230 | config: Config{ |
| 14231 | Bugs: ProtocolBugs{ |
| 14232 | ExpectCloseNotify: true, |
| 14233 | }, |
| 14234 | }, |
| 14235 | flags: []string{ |
| 14236 | "-peek-then-read", |
| 14237 | "-check-close-notify", |
| 14238 | }, |
| 14239 | }) |
| 14240 |
| 14241 | // Test SSL_peek can discover an alert. |
| 14242 | testCases = append(testCases, testCase{ |
| 14243 | name: "Peek-Alert", |
| 14244 | config: Config{ |
| 14245 | Bugs: ProtocolBugs{ |
| 14246 | SendSpuriousAlert: alertRecordOverflow, |
| 14247 | }, |
| 14248 | }, |
| 14249 | flags: []string{"-peek-then-read"}, |
| 14250 | shouldFail: true, |
| 14251 | expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:", |
| 14252 | }) |
| 14253 |
| 14254 | // Test SSL_peek can handle KeyUpdate. |
| 14255 | testCases = append(testCases, testCase{ |
| 14256 | name: "Peek-KeyUpdate", |
| 14257 | config: Config{ |
| 14258 | MaxVersion: VersionTLS13, |
| 14259 | }, |
| 14260 | sendKeyUpdates: 1, |
| 14261 | keyUpdateRequest: keyUpdateNotRequested, |
| 14262 | flags: []string{"-peek-then-read"}, |
| 14263 | }) |
| 14264 | } |
| 14265 |
| 14266 | func addRecordVersionTests() { |
| 14267 | for _, ver := range tlsVersions { |
| 14268 | // Test that the record version is enforced. |
| 14269 | testCases = append(testCases, testCase{ |
| 14270 | name: "CheckRecordVersion-" + ver.name, |
| 14271 | config: Config{ |
| 14272 | MinVersion: ver.version, |
| 14273 | MaxVersion: ver.version, |
| 14274 | Bugs: ProtocolBugs{ |
| 14275 | SendRecordVersion: 0x03ff, |
| 14276 | }, |
| 14277 | }, |
| 14278 | shouldFail: true, |
| 14279 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 14280 | }) |
| 14281 |
| 14282 | // Test that the ClientHello may use any record version, for |
| 14283 | // compatibility reasons. |
| 14284 | testCases = append(testCases, testCase{ |
| 14285 | testType: serverTest, |
| 14286 | name: "LooseInitialRecordVersion-" + ver.name, |
| 14287 | config: Config{ |
| 14288 | MinVersion: ver.version, |
| 14289 | MaxVersion: ver.version, |
| 14290 | Bugs: ProtocolBugs{ |
| 14291 | SendInitialRecordVersion: 0x03ff, |
| 14292 | }, |
| 14293 | }, |
| 14294 | }) |
| 14295 |
| 14296 | // Test that garbage ClientHello record versions are rejected. |
| 14297 | testCases = append(testCases, testCase{ |
| 14298 | testType: serverTest, |
| 14299 | name: "GarbageInitialRecordVersion-" + ver.name, |
| 14300 | config: Config{ |
| 14301 | MinVersion: ver.version, |
| 14302 | MaxVersion: ver.version, |
| 14303 | Bugs: ProtocolBugs{ |
| 14304 | SendInitialRecordVersion: 0xffff, |
| 14305 | }, |
| 14306 | }, |
| 14307 | shouldFail: true, |
| 14308 | expectedError: ":WRONG_VERSION_NUMBER:", |
| 14309 | }) |
| 14310 | } |
| 14311 | } |
| 14312 |
| 14313 | func addCertificateTests() { |
| 14314 | for _, ver := range tlsVersions { |
| 14315 | // Test that a certificate chain with intermediate may be sent |
| 14316 | // and received as both client and server. |
| 14317 | testCases = append(testCases, testCase{ |
| 14318 | testType: clientTest, |
| 14319 | name: "SendReceiveIntermediate-Client-" + ver.name, |
| 14320 | config: Config{ |
| 14321 | MinVersion: ver.version, |
| 14322 | MaxVersion: ver.version, |
| 14323 | Certificates: []Certificate{rsaChainCertificate}, |
| 14324 | ClientAuth: RequireAnyClientCert, |
| 14325 | }, |
| 14326 | expectPeerCertificate: &rsaChainCertificate, |
| 14327 | flags: []string{ |
| 14328 | "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile), |
| 14329 | "-key-file", path.Join(*resourceDir, rsaChainKeyFile), |
| 14330 | "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile), |
| 14331 | }, |
| 14332 | }) |
| 14333 |
| 14334 | testCases = append(testCases, testCase{ |
| 14335 | testType: serverTest, |
| 14336 | name: "SendReceiveIntermediate-Server-" + ver.name, |
| 14337 | config: Config{ |
| 14338 | MinVersion: ver.version, |
| 14339 | MaxVersion: ver.version, |
| 14340 | Certificates: []Certificate{rsaChainCertificate}, |
| 14341 | }, |
| 14342 | expectPeerCertificate: &rsaChainCertificate, |
| 14343 | flags: []string{ |
| 14344 | "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile), |
| 14345 | "-key-file", path.Join(*resourceDir, rsaChainKeyFile), |
| 14346 | "-require-any-client-certificate", |
| 14347 | "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile), |
| 14348 | }, |
| 14349 | }) |
| 14350 |
| 14351 | // Test that garbage leaf certificates are properly rejected. |
| 14352 | testCases = append(testCases, testCase{ |
| 14353 | testType: clientTest, |
| 14354 | name: "GarbageCertificate-Client-" + ver.name, |
| 14355 | config: Config{ |
| 14356 | MinVersion: ver.version, |
| 14357 | MaxVersion: ver.version, |
| 14358 | Certificates: []Certificate{garbageCertificate}, |
| 14359 | }, |
| 14360 | shouldFail: true, |
| 14361 | expectedError: ":CANNOT_PARSE_LEAF_CERT:", |
| 14362 | expectedLocalError: "remote error: error decoding message", |
| 14363 | }) |
| 14364 |
| 14365 | testCases = append(testCases, testCase{ |
| 14366 | testType: serverTest, |
| 14367 | name: "GarbageCertificate-Server-" + ver.name, |
| 14368 | config: Config{ |
| 14369 | MinVersion: ver.version, |
| 14370 | MaxVersion: ver.version, |
| 14371 | Certificates: []Certificate{garbageCertificate}, |
| 14372 | }, |
| 14373 | flags: []string{"-require-any-client-certificate"}, |
| 14374 | shouldFail: true, |
| 14375 | expectedError: ":CANNOT_PARSE_LEAF_CERT:", |
| 14376 | expectedLocalError: "remote error: error decoding message", |
| 14377 | }) |
| 14378 | } |
| 14379 | } |
| 14380 |
| 14381 | func addRetainOnlySHA256ClientCertTests() { |
| 14382 | for _, ver := range tlsVersions { |
| 14383 | // Test that enabling |
| 14384 | // SSL_CTX_set_retain_only_sha256_of_client_certs without |
| 14385 | // actually requesting a client certificate is a no-op. |
| 14386 | testCases = append(testCases, testCase{ |
| 14387 | testType: serverTest, |
| 14388 | name: "RetainOnlySHA256-NoCert-" + ver.name, |
| 14389 | config: Config{ |
| 14390 | MinVersion: ver.version, |
| 14391 | MaxVersion: ver.version, |
| 14392 | }, |
| 14393 | flags: []string{ |
| 14394 | "-on-initial-retain-only-sha256-client-cert", |
| 14395 | "-on-resume-retain-only-sha256-client-cert", |
| 14396 | }, |
| 14397 | resumeSession: true, |
| 14398 | }) |
| 14399 |
| 14400 | // Test that when retaining only a SHA-256 certificate is |
| 14401 | // enabled, the hash appears as expected. |
| 14402 | testCases = append(testCases, testCase{ |
| 14403 | testType: serverTest, |
| 14404 | name: "RetainOnlySHA256-Cert-" + ver.name, |
| 14405 | config: Config{ |
| 14406 | MinVersion: ver.version, |
| 14407 | MaxVersion: ver.version, |
| 14408 | Certificates: []Certificate{rsaCertificate}, |
| 14409 | }, |
| 14410 | flags: []string{ |
| 14411 | "-verify-peer", |
| 14412 | "-on-initial-retain-only-sha256-client-cert", |
| 14413 | "-on-resume-retain-only-sha256-client-cert", |
| 14414 | "-on-initial-expect-sha256-client-cert", |
| 14415 | "-on-resume-expect-sha256-client-cert", |
| 14416 | }, |
| 14417 | resumeSession: true, |
| 14418 | }) |
| 14419 |
| 14420 | // Test that when the config changes from on to off, a |
| 14421 | // resumption is rejected because the server now wants the full |
| 14422 | // certificate chain. |
| 14423 | testCases = append(testCases, testCase{ |
| 14424 | testType: serverTest, |
| 14425 | name: "RetainOnlySHA256-OnOff-" + ver.name, |
| 14426 | config: Config{ |
| 14427 | MinVersion: ver.version, |
| 14428 | MaxVersion: ver.version, |
| 14429 | Certificates: []Certificate{rsaCertificate}, |
| 14430 | }, |
| 14431 | flags: []string{ |
| 14432 | "-verify-peer", |
| 14433 | "-on-initial-retain-only-sha256-client-cert", |
| 14434 | "-on-initial-expect-sha256-client-cert", |
| 14435 | }, |
| 14436 | resumeSession: true, |
| 14437 | expectResumeRejected: true, |
| 14438 | }) |
| 14439 |
| 14440 | // Test that when the config changes from off to on, a |
| 14441 | // resumption is rejected because the server now wants just the |
| 14442 | // hash. |
| 14443 | testCases = append(testCases, testCase{ |
| 14444 | testType: serverTest, |
| 14445 | name: "RetainOnlySHA256-OffOn-" + ver.name, |
| 14446 | config: Config{ |
| 14447 | MinVersion: ver.version, |
| 14448 | MaxVersion: ver.version, |
| 14449 | Certificates: []Certificate{rsaCertificate}, |
| 14450 | }, |
| 14451 | flags: []string{ |
| 14452 | "-verify-peer", |
| 14453 | "-on-resume-retain-only-sha256-client-cert", |
| 14454 | "-on-resume-expect-sha256-client-cert", |
| 14455 | }, |
| 14456 | resumeSession: true, |
| 14457 | expectResumeRejected: true, |
| 14458 | }) |
| 14459 | } |
| 14460 | } |
| 14461 |
| 14462 | func addECDSAKeyUsageTests() { |
| 14463 | p256 := elliptic.P256() |
| 14464 | priv, err := ecdsa.GenerateKey(p256, rand.Reader) |
| 14465 | if err != nil { |
| 14466 | panic(err) |
| 14467 | } |
| 14468 |
| 14469 | serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) |
| 14470 | serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) |
| 14471 | if err != nil { |
| 14472 | panic(err) |
| 14473 | } |
| 14474 |
| 14475 | template := x509.Certificate{ |
| 14476 | SerialNumber: serialNumber, |
| 14477 | Subject: pkix.Name{ |
| 14478 | Organization: []string{"Acme Co"}, |
| 14479 | }, |
| 14480 | NotBefore: time.Now(), |
| 14481 | NotAfter: time.Now(), |
| 14482 |
| 14483 | // An ECC certificate with only the keyAgreement key usgae may |
| 14484 | // be used with ECDH, but not ECDSA. |
| 14485 | KeyUsage: x509.KeyUsageKeyAgreement, |
| 14486 | ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, |
| 14487 | BasicConstraintsValid: true, |
| 14488 | } |
| 14489 |
| 14490 | derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv) |
| 14491 | if err != nil { |
| 14492 | panic(err) |
| 14493 | } |
| 14494 |
| 14495 | cert := Certificate{ |
| 14496 | Certificate: [][]byte{derBytes}, |
| 14497 | PrivateKey: priv, |
| 14498 | } |
| 14499 |
| 14500 | for _, ver := range tlsVersions { |
| 14501 | if ver.version < VersionTLS12 { |
| 14502 | continue |
| 14503 | } |
| 14504 |
| 14505 | testCases = append(testCases, testCase{ |
| 14506 | testType: clientTest, |
| 14507 | name: "ECDSAKeyUsage-" + ver.name, |
| 14508 | config: Config{ |
| 14509 | MinVersion: ver.version, |
| 14510 | MaxVersion: ver.version, |
| 14511 | Certificates: []Certificate{cert}, |
| 14512 | }, |
| 14513 | shouldFail: true, |
| 14514 | expectedError: ":KEY_USAGE_BIT_INCORRECT:", |
| 14515 | }) |
| 14516 | } |
| 14517 | } |
| 14518 |
| 14519 | func addRSAKeyUsageTests() { |
| 14520 | priv := rsaCertificate.PrivateKey.(*rsa.PrivateKey) |
| 14521 |
| 14522 | serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) |
| 14523 | serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) |
| 14524 | if err != nil { |
| 14525 | panic(err) |
| 14526 | } |
| 14527 |
| 14528 | dsTemplate := x509.Certificate{ |
| 14529 | SerialNumber: serialNumber, |
| 14530 | Subject: pkix.Name{ |
| 14531 | Organization: []string{"Acme Co"}, |
| 14532 | }, |
| 14533 | NotBefore: time.Now(), |
| 14534 | NotAfter: time.Now(), |
| 14535 |
| 14536 | KeyUsage: x509.KeyUsageDigitalSignature, |
| 14537 | BasicConstraintsValid: true, |
| 14538 | } |
| 14539 |
| 14540 | encTemplate := x509.Certificate{ |
| 14541 | SerialNumber: serialNumber, |
| 14542 | Subject: pkix.Name{ |
| 14543 | Organization: []string{"Acme Co"}, |
| 14544 | }, |
| 14545 | NotBefore: time.Now(), |
| 14546 | NotAfter: time.Now(), |
| 14547 |
| 14548 | KeyUsage: x509.KeyUsageKeyEncipherment, |
| 14549 | BasicConstraintsValid: true, |
| 14550 | } |
| 14551 |
| 14552 | dsDerBytes, err := x509.CreateCertificate(rand.Reader, &dsTemplate, &dsTemplate, &priv.PublicKey, priv) |
| 14553 | if err != nil { |
| 14554 | panic(err) |
| 14555 | } |
| 14556 |
| 14557 | encDerBytes, err := x509.CreateCertificate(rand.Reader, &encTemplate, &encTemplate, &priv.PublicKey, priv) |
| 14558 | if err != nil { |
| 14559 | panic(err) |
| 14560 | } |
| 14561 |
| 14562 | dsCert := Certificate{ |
| 14563 | Certificate: [][]byte{dsDerBytes}, |
| 14564 | PrivateKey: priv, |
| 14565 | } |
| 14566 |
| 14567 | encCert := Certificate{ |
| 14568 | Certificate: [][]byte{encDerBytes}, |
| 14569 | PrivateKey: priv, |
| 14570 | } |
| 14571 |
| 14572 | dsSuites := []uint16{ |
| 14573 | TLS_AES_128_GCM_SHA256, |
| 14574 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 14575 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 14576 | } |
| 14577 | encSuites := []uint16{ |
| 14578 | TLS_RSA_WITH_AES_128_GCM_SHA256, |
| 14579 | TLS_RSA_WITH_AES_128_CBC_SHA, |
| 14580 | } |
| 14581 |
| 14582 | for _, ver := range tlsVersions { |
| 14583 | testCases = append(testCases, testCase{ |
| 14584 | testType: clientTest, |
| 14585 | name: "RSAKeyUsage-WantSignature-GotEncipherment-" + ver.name, |
| 14586 | config: Config{ |
| 14587 | MinVersion: ver.version, |
| 14588 | MaxVersion: ver.version, |
| 14589 | Certificates: []Certificate{encCert}, |
| 14590 | CipherSuites: dsSuites, |
| 14591 | }, |
| 14592 | shouldFail: true, |
| 14593 | expectedError: ":KEY_USAGE_BIT_INCORRECT:", |
| 14594 | flags: []string{ |
| 14595 | "-enforce-rsa-key-usage", |
| 14596 | }, |
| 14597 | }) |
| 14598 |
| 14599 | testCases = append(testCases, testCase{ |
| 14600 | testType: clientTest, |
| 14601 | name: "RSAKeyUsage-WantSignature-GotSignature-" + ver.name, |
| 14602 | config: Config{ |
| 14603 | MinVersion: ver.version, |
| 14604 | MaxVersion: ver.version, |
| 14605 | Certificates: []Certificate{dsCert}, |
| 14606 | CipherSuites: dsSuites, |
| 14607 | }, |
| 14608 | flags: []string{ |
| 14609 | "-enforce-rsa-key-usage", |
| 14610 | }, |
| 14611 | }) |
| 14612 |
| 14613 | // TLS 1.3 removes the encipherment suites. |
| 14614 | if ver.version < VersionTLS13 { |
| 14615 | testCases = append(testCases, testCase{ |
| 14616 | testType: clientTest, |
| 14617 | name: "RSAKeyUsage-WantEncipherment-GotEncipherment" + ver.name, |
| 14618 | config: Config{ |
| 14619 | MinVersion: ver.version, |
| 14620 | MaxVersion: ver.version, |
| 14621 | Certificates: []Certificate{encCert}, |
| 14622 | CipherSuites: encSuites, |
| 14623 | }, |
| 14624 | flags: []string{ |
| 14625 | "-enforce-rsa-key-usage", |
| 14626 | }, |
| 14627 | }) |
| 14628 |
| 14629 | testCases = append(testCases, testCase{ |
| 14630 | testType: clientTest, |
| 14631 | name: "RSAKeyUsage-WantEncipherment-GotSignature-" + ver.name, |
| 14632 | config: Config{ |
| 14633 | MinVersion: ver.version, |
| 14634 | MaxVersion: ver.version, |
| 14635 | Certificates: []Certificate{dsCert}, |
| 14636 | CipherSuites: encSuites, |
| 14637 | }, |
| 14638 | shouldFail: true, |
| 14639 | expectedError: ":KEY_USAGE_BIT_INCORRECT:", |
| 14640 | flags: []string{ |
| 14641 | "-enforce-rsa-key-usage", |
| 14642 | }, |
| 14643 | }) |
| 14644 |
| 14645 | // In 1.2 and below, we should not enforce without the enforce-rsa-key-usage flag. |
| 14646 | testCases = append(testCases, testCase{ |
| 14647 | testType: clientTest, |
| 14648 | name: "RSAKeyUsage-WantSignature-GotEncipherment-Unenforced" + ver.name, |
| 14649 | config: Config{ |
| 14650 | MinVersion: ver.version, |
| 14651 | MaxVersion: ver.version, |
| 14652 | Certificates: []Certificate{dsCert}, |
| 14653 | CipherSuites: encSuites, |
| 14654 | }, |
| 14655 | }) |
| 14656 |
| 14657 | testCases = append(testCases, testCase{ |
| 14658 | testType: clientTest, |
| 14659 | name: "RSAKeyUsage-WantEncipherment-GotSignature-Unenforced" + ver.name, |
| 14660 | config: Config{ |
| 14661 | MinVersion: ver.version, |
| 14662 | MaxVersion: ver.version, |
| 14663 | Certificates: []Certificate{encCert}, |
| 14664 | CipherSuites: dsSuites, |
| 14665 | }, |
| 14666 | }) |
| 14667 |
| 14668 | } |
| 14669 |
| 14670 | if ver.version >= VersionTLS13 { |
| 14671 | // In 1.3 and above, we enforce keyUsage even without the flag. |
| 14672 | testCases = append(testCases, testCase{ |
| 14673 | testType: clientTest, |
| 14674 | name: "RSAKeyUsage-WantSignature-GotEncipherment-Enforced" + ver.name, |
| 14675 | config: Config{ |
| 14676 | MinVersion: ver.version, |
| 14677 | MaxVersion: ver.version, |
| 14678 | Certificates: []Certificate{encCert}, |
| 14679 | CipherSuites: dsSuites, |
| 14680 | }, |
| 14681 | shouldFail: true, |
| 14682 | expectedError: ":KEY_USAGE_BIT_INCORRECT:", |
| 14683 | }) |
| 14684 |
| 14685 | } |
| 14686 | } |
| 14687 | } |
| 14688 |
| 14689 | func addExtraHandshakeTests() { |
| 14690 | // An extra SSL_do_handshake is normally a no-op. These tests use -async |
| 14691 | // to ensure there is no transport I/O. |
| 14692 | testCases = append(testCases, testCase{ |
| 14693 | testType: clientTest, |
| 14694 | name: "ExtraHandshake-Client-TLS12", |
| 14695 | config: Config{ |
| 14696 | MinVersion: VersionTLS12, |
| 14697 | MaxVersion: VersionTLS12, |
| 14698 | }, |
| 14699 | flags: []string{ |
| 14700 | "-async", |
| 14701 | "-no-op-extra-handshake", |
| 14702 | }, |
| 14703 | }) |
| 14704 | testCases = append(testCases, testCase{ |
| 14705 | testType: serverTest, |
| 14706 | name: "ExtraHandshake-Server-TLS12", |
| 14707 | config: Config{ |
| 14708 | MinVersion: VersionTLS12, |
| 14709 | MaxVersion: VersionTLS12, |
| 14710 | }, |
| 14711 | flags: []string{ |
| 14712 | "-async", |
| 14713 | "-no-op-extra-handshake", |
| 14714 | }, |
| 14715 | }) |
| 14716 | testCases = append(testCases, testCase{ |
| 14717 | testType: clientTest, |
| 14718 | name: "ExtraHandshake-Client-TLS13", |
| 14719 | config: Config{ |
| 14720 | MinVersion: VersionTLS13, |
| 14721 | MaxVersion: VersionTLS13, |
| 14722 | }, |
| 14723 | flags: []string{ |
| 14724 | "-async", |
| 14725 | "-no-op-extra-handshake", |
| 14726 | }, |
| 14727 | }) |
| 14728 | testCases = append(testCases, testCase{ |
| 14729 | testType: serverTest, |
| 14730 | name: "ExtraHandshake-Server-TLS13", |
| 14731 | config: Config{ |
| 14732 | MinVersion: VersionTLS13, |
| 14733 | MaxVersion: VersionTLS13, |
| 14734 | }, |
| 14735 | flags: []string{ |
| 14736 | "-async", |
| 14737 | "-no-op-extra-handshake", |
| 14738 | }, |
| 14739 | }) |
| 14740 |
| 14741 | // An extra SSL_do_handshake is a no-op in server 0-RTT. |
| 14742 | testCases = append(testCases, testCase{ |
| 14743 | testType: serverTest, |
| 14744 | name: "ExtraHandshake-Server-EarlyData-TLS13", |
| 14745 | config: Config{ |
| 14746 | MaxVersion: VersionTLS13, |
| 14747 | MinVersion: VersionTLS13, |
| 14748 | Bugs: ProtocolBugs{ |
| 14749 | SendEarlyData: [][]byte{{1, 2, 3, 4}}, |
| 14750 | ExpectEarlyDataAccepted: true, |
| 14751 | ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}}, |
| 14752 | }, |
| 14753 | }, |
| 14754 | messageCount: 2, |
| 14755 | resumeSession: true, |
| 14756 | flags: []string{ |
| 14757 | "-async", |
| 14758 | "-enable-early-data", |
| 14759 | "-on-resume-expect-accept-early-data", |
| 14760 | "-no-op-extra-handshake", |
| 14761 | }, |
| 14762 | }) |
| 14763 |
| 14764 | // An extra SSL_do_handshake drives the handshake to completion in False |
| 14765 | // Start. We test this by handshaking twice and asserting the False |
| 14766 | // Start does not appear to happen. See AlertBeforeFalseStartTest for |
| 14767 | // how the test works. |
| 14768 | testCases = append(testCases, testCase{ |
| 14769 | testType: clientTest, |
| 14770 | name: "ExtraHandshake-FalseStart", |
| 14771 | config: Config{ |
| 14772 | MaxVersion: VersionTLS12, |
| 14773 | CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}, |
| 14774 | NextProtos: []string{"foo"}, |
| 14775 | Bugs: ProtocolBugs{ |
| 14776 | ExpectFalseStart: true, |
| 14777 | AlertBeforeFalseStartTest: alertAccessDenied, |
| 14778 | }, |
| 14779 | }, |
| 14780 | flags: []string{ |
| 14781 | "-handshake-twice", |
| 14782 | "-false-start", |
| 14783 | "-advertise-alpn", "\x03foo", |
| 14784 | "-expect-alpn", "foo", |
| 14785 | }, |
| 14786 | shimWritesFirst: true, |
| 14787 | shouldFail: true, |
| 14788 | expectedError: ":TLSV1_ALERT_ACCESS_DENIED:", |
| 14789 | expectedLocalError: "tls: peer did not false start: EOF", |
| 14790 | }) |
| 14791 | } |
| 14792 |
| 14793 | // Test that omitted and empty extensions blocks are tolerated. |
| 14794 | func addOmitExtensionsTests() { |
| 14795 | // Check the ExpectOmitExtensions setting works. |
| 14796 | testCases = append(testCases, testCase{ |
| 14797 | testType: serverTest, |
| 14798 | name: "ExpectOmitExtensions", |
| 14799 | config: Config{ |
| 14800 | MinVersion: VersionTLS12, |
| 14801 | MaxVersion: VersionTLS12, |
| 14802 | Bugs: ProtocolBugs{ |
| 14803 | ExpectOmitExtensions: true, |
| 14804 | }, |
| 14805 | }, |
| 14806 | shouldFail: true, |
| 14807 | expectedLocalError: "tls: ServerHello did not omit extensions", |
| 14808 | }) |
| 14809 |
| 14810 | for _, ver := range tlsVersions { |
| 14811 | if ver.version > VersionTLS12 { |
| 14812 | continue |
| 14813 | } |
| 14814 |
| 14815 | testCases = append(testCases, testCase{ |
| 14816 | testType: serverTest, |
| 14817 | name: "OmitExtensions-ClientHello-" + ver.name, |
| 14818 | config: Config{ |
| 14819 | MinVersion: ver.version, |
| 14820 | MaxVersion: ver.version, |
| 14821 | SessionTicketsDisabled: true, |
| 14822 | Bugs: ProtocolBugs{ |
| 14823 | OmitExtensions: true, |
| 14824 | // With no client extensions, the ServerHello must not have |
| 14825 | // extensions. It should then omit the extensions field. |
| 14826 | ExpectOmitExtensions: true, |
| 14827 | }, |
| 14828 | }, |
| 14829 | }) |
| 14830 |
| 14831 | testCases = append(testCases, testCase{ |
| 14832 | testType: serverTest, |
| 14833 | name: "EmptyExtensions-ClientHello-" + ver.name, |
| 14834 | config: Config{ |
| 14835 | MinVersion: ver.version, |
| 14836 | MaxVersion: ver.version, |
| 14837 | SessionTicketsDisabled: true, |
| 14838 | Bugs: ProtocolBugs{ |
| 14839 | EmptyExtensions: true, |
| 14840 | // With no client extensions, the ServerHello must not have |
| 14841 | // extensions. It should then omit the extensions field. |
| 14842 | ExpectOmitExtensions: true, |
| 14843 | }, |
| 14844 | }, |
| 14845 | }) |
| 14846 |
| 14847 | testCases = append(testCases, testCase{ |
| 14848 | testType: clientTest, |
| 14849 | name: "OmitExtensions-ServerHello-" + ver.name, |
| 14850 | config: Config{ |
| 14851 | MinVersion: ver.version, |
| 14852 | MaxVersion: ver.version, |
| 14853 | SessionTicketsDisabled: true, |
| 14854 | Bugs: ProtocolBugs{ |
| 14855 | OmitExtensions: true, |
| 14856 | // Disable all ServerHello extensions so |
| 14857 | // OmitExtensions works. |
| 14858 | NoExtendedMasterSecret: true, |
| 14859 | NoRenegotiationInfo: true, |
| 14860 | NoOCSPStapling: true, |
| 14861 | NoSignedCertificateTimestamps: true, |
| 14862 | }, |
| 14863 | }, |
| 14864 | }) |
| 14865 |
| 14866 | testCases = append(testCases, testCase{ |
| 14867 | testType: clientTest, |
| 14868 | name: "EmptyExtensions-ServerHello-" + ver.name, |
| 14869 | config: Config{ |
| 14870 | MinVersion: ver.version, |
| 14871 | MaxVersion: ver.version, |
| 14872 | SessionTicketsDisabled: true, |
| 14873 | Bugs: ProtocolBugs{ |
| 14874 | EmptyExtensions: true, |
| 14875 | // Disable all ServerHello extensions so |
| 14876 | // EmptyExtensions works. |
| 14877 | NoExtendedMasterSecret: true, |
| 14878 | NoRenegotiationInfo: true, |
| 14879 | NoOCSPStapling: true, |
| 14880 | NoSignedCertificateTimestamps: true, |
| 14881 | }, |
| 14882 | }, |
| 14883 | }) |
| 14884 | } |
| 14885 | } |
| 14886 |
| 14887 | func addCertCompressionTests() { |
| 14888 | // shrinkingPrefix is the first two bytes of a Certificate message. |
| 14889 | shrinkingPrefix := []byte{0, 0} |
| 14890 | // expandingPrefix is just some arbitrary byte string. This has to match the |
| 14891 | // value in the shim. |
| 14892 | expandingPrefix := []byte{1, 2, 3, 4} |
| 14893 |
| 14894 | shrinking := CertCompressionAlg{ |
| 14895 | Compress: func(uncompressed []byte) []byte { |
| 14896 | if !bytes.HasPrefix(uncompressed, shrinkingPrefix) { |
| 14897 | panic(fmt.Sprintf("cannot compress certificate message %x", uncompressed)) |
| 14898 | } |
| 14899 | return uncompressed[len(shrinkingPrefix):] |
| 14900 | }, |
| 14901 | Decompress: func(out []byte, compressed []byte) bool { |
| 14902 | if len(out) != len(shrinkingPrefix)+len(compressed) { |
| 14903 | return false |
| 14904 | } |
| 14905 |
| 14906 | copy(out, shrinkingPrefix) |
| 14907 | copy(out[len(shrinkingPrefix):], compressed) |
| 14908 | return true |
| 14909 | }, |
| 14910 | } |
| 14911 |
| 14912 | expanding := CertCompressionAlg{ |
| 14913 | Compress: func(uncompressed []byte) []byte { |
| 14914 | ret := make([]byte, 0, len(expandingPrefix)+len(uncompressed)) |
| 14915 | ret = append(ret, expandingPrefix...) |
| 14916 | return append(ret, uncompressed...) |
| 14917 | }, |
| 14918 | Decompress: func(out []byte, compressed []byte) bool { |
| 14919 | if !bytes.HasPrefix(compressed, expandingPrefix) { |
| 14920 | return false |
| 14921 | } |
| 14922 | copy(out, compressed[len(expandingPrefix):]) |
| 14923 | return true |
| 14924 | }, |
| 14925 | } |
| 14926 |
| 14927 | const ( |
| 14928 | shrinkingAlgId = 0xff01 |
| 14929 | expandingAlgId = 0xff02 |
| 14930 | ) |
| 14931 |
| 14932 | for _, ver := range tlsVersions { |
| 14933 | if ver.version < VersionTLS12 { |
| 14934 | continue |
| 14935 | } |
| 14936 |
| 14937 | // Duplicate compression algorithms is an error, even if nothing is |
| 14938 | // configured. |
| 14939 | testCases = append(testCases, testCase{ |
| 14940 | testType: serverTest, |
| 14941 | name: "DuplicateCertCompressionExt-" + ver.name, |
| 14942 | config: Config{ |
| 14943 | MinVersion: ver.version, |
| 14944 | MaxVersion: ver.version, |
| 14945 | Bugs: ProtocolBugs{ |
| 14946 | DuplicateCompressedCertAlgs: true, |
| 14947 | }, |
| 14948 | }, |
| 14949 | shouldFail: true, |
| 14950 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 14951 | }) |
| 14952 |
| 14953 | // With compression algorithms configured, an duplicate values should still |
| 14954 | // be an error. |
| 14955 | testCases = append(testCases, testCase{ |
| 14956 | testType: serverTest, |
| 14957 | name: "DuplicateCertCompressionExt2-" + ver.name, |
| 14958 | flags: []string{"-install-cert-compression-algs"}, |
| 14959 | config: Config{ |
| 14960 | MinVersion: ver.version, |
| 14961 | MaxVersion: ver.version, |
| 14962 | Bugs: ProtocolBugs{ |
| 14963 | DuplicateCompressedCertAlgs: true, |
| 14964 | }, |
| 14965 | }, |
| 14966 | shouldFail: true, |
| 14967 | expectedError: ":ERROR_PARSING_EXTENSION:", |
| 14968 | }) |
| 14969 |
| 14970 | if ver.version < VersionTLS13 { |
| 14971 | testCases = append(testCases, testCase{ |
| 14972 | testType: serverTest, |
| 14973 | name: "CertCompressionIgnoredBefore13-" + ver.name, |
| 14974 | flags: []string{"-install-cert-compression-algs"}, |
| 14975 | config: Config{ |
| 14976 | MinVersion: ver.version, |
| 14977 | MaxVersion: ver.version, |
| 14978 | CertCompressionAlgs: map[uint16]CertCompressionAlg{expandingAlgId: expanding}, |
| 14979 | }, |
| 14980 | }) |
| 14981 |
| 14982 | continue |
| 14983 | } |
| 14984 |
| 14985 | testCases = append(testCases, testCase{ |
| 14986 | testType: serverTest, |
| 14987 | name: "CertCompressionExpands-" + ver.name, |
| 14988 | flags: []string{"-install-cert-compression-algs"}, |
| 14989 | config: Config{ |
| 14990 | MinVersion: ver.version, |
| 14991 | MaxVersion: ver.version, |
| 14992 | CertCompressionAlgs: map[uint16]CertCompressionAlg{expandingAlgId: expanding}, |
| 14993 | Bugs: ProtocolBugs{ |
| 14994 | ExpectedCompressedCert: expandingAlgId, |
| 14995 | }, |
| 14996 | }, |
| 14997 | }) |
| 14998 |
| 14999 | testCases = append(testCases, testCase{ |
| 15000 | testType: serverTest, |
| 15001 | name: "CertCompressionShrinks-" + ver.name, |
| 15002 | flags: []string{"-install-cert-compression-algs"}, |
| 15003 | config: Config{ |
| 15004 | MinVersion: ver.version, |
| 15005 | MaxVersion: ver.version, |
| 15006 | CertCompressionAlgs: map[uint16]CertCompressionAlg{shrinkingAlgId: shrinking}, |
| 15007 | Bugs: ProtocolBugs{ |
| 15008 | ExpectedCompressedCert: shrinkingAlgId, |
| 15009 | }, |
| 15010 | }, |
| 15011 | }) |
| 15012 |
| 15013 | // With both algorithms configured, the server should pick its most |
| 15014 | // preferable. (Which is expandingAlgId.) |
| 15015 | testCases = append(testCases, testCase{ |
| 15016 | testType: serverTest, |
| 15017 | name: "CertCompressionPriority-" + ver.name, |
| 15018 | flags: []string{"-install-cert-compression-algs"}, |
| 15019 | config: Config{ |
| 15020 | MinVersion: ver.version, |
| 15021 | MaxVersion: ver.version, |
| 15022 | CertCompressionAlgs: map[uint16]CertCompressionAlg{ |
| 15023 | shrinkingAlgId: shrinking, |
| 15024 | expandingAlgId: expanding, |
| 15025 | }, |
| 15026 | Bugs: ProtocolBugs{ |
| 15027 | ExpectedCompressedCert: expandingAlgId, |
| 15028 | }, |
| 15029 | }, |
| 15030 | }) |
| 15031 |
| 15032 | testCases = append(testCases, testCase{ |
| 15033 | testType: clientTest, |
| 15034 | name: "CertCompressionExpandsClient-" + ver.name, |
| 15035 | flags: []string{"-install-cert-compression-algs"}, |
| 15036 | config: Config{ |
| 15037 | MinVersion: ver.version, |
| 15038 | MaxVersion: ver.version, |
| 15039 | CertCompressionAlgs: map[uint16]CertCompressionAlg{ |
| 15040 | expandingAlgId: expanding, |
| 15041 | }, |
| 15042 | Bugs: ProtocolBugs{ |
| 15043 | ExpectedCompressedCert: expandingAlgId, |
| 15044 | }, |
| 15045 | }, |
| 15046 | }) |
| 15047 |
| 15048 | testCases = append(testCases, testCase{ |
| 15049 | testType: clientTest, |
| 15050 | name: "CertCompressionShrinksClient-" + ver.name, |
| 15051 | flags: []string{"-install-cert-compression-algs"}, |
| 15052 | config: Config{ |
| 15053 | MinVersion: ver.version, |
| 15054 | MaxVersion: ver.version, |
| 15055 | CertCompressionAlgs: map[uint16]CertCompressionAlg{ |
| 15056 | shrinkingAlgId: shrinking, |
| 15057 | }, |
| 15058 | Bugs: ProtocolBugs{ |
| 15059 | ExpectedCompressedCert: shrinkingAlgId, |
| 15060 | }, |
| 15061 | }, |
| 15062 | }) |
| 15063 |
| 15064 | testCases = append(testCases, testCase{ |
| 15065 | testType: clientTest, |
| 15066 | name: "CertCompressionBadAlgIdClient-" + ver.name, |
| 15067 | flags: []string{"-install-cert-compression-algs"}, |
| 15068 | config: Config{ |
| 15069 | MinVersion: ver.version, |
| 15070 | MaxVersion: ver.version, |
| 15071 | CertCompressionAlgs: map[uint16]CertCompressionAlg{ |
| 15072 | shrinkingAlgId: shrinking, |
| 15073 | }, |
| 15074 | Bugs: ProtocolBugs{ |
| 15075 | ExpectedCompressedCert: shrinkingAlgId, |
| 15076 | SendCertCompressionAlgId: 1234, |
| 15077 | }, |
| 15078 | }, |
| 15079 | shouldFail: true, |
| 15080 | expectedError: ":UNKNOWN_CERT_COMPRESSION_ALG:", |
| 15081 | }) |
| 15082 |
| 15083 | testCases = append(testCases, testCase{ |
| 15084 | testType: clientTest, |
| 15085 | name: "CertCompressionTooSmallClient-" + ver.name, |
| 15086 | flags: []string{"-install-cert-compression-algs"}, |
| 15087 | config: Config{ |
| 15088 | MinVersion: ver.version, |
| 15089 | MaxVersion: ver.version, |
| 15090 | CertCompressionAlgs: map[uint16]CertCompressionAlg{ |
| 15091 | shrinkingAlgId: shrinking, |
| 15092 | }, |
| 15093 | Bugs: ProtocolBugs{ |
| 15094 | ExpectedCompressedCert: shrinkingAlgId, |
| 15095 | SendCertUncompressedLength: 12, |
| 15096 | }, |
| 15097 | }, |
| 15098 | shouldFail: true, |
| 15099 | expectedError: ":CERT_DECOMPRESSION_FAILED:", |
| 15100 | }) |
| 15101 |
| 15102 | testCases = append(testCases, testCase{ |
| 15103 | testType: clientTest, |
| 15104 | name: "CertCompressionTooLargeClient-" + ver.name, |
| 15105 | flags: []string{"-install-cert-compression-algs"}, |
| 15106 | config: Config{ |
| 15107 | MinVersion: ver.version, |
| 15108 | MaxVersion: ver.version, |
| 15109 | CertCompressionAlgs: map[uint16]CertCompressionAlg{ |
| 15110 | shrinkingAlgId: shrinking, |
| 15111 | }, |
| 15112 | Bugs: ProtocolBugs{ |
| 15113 | ExpectedCompressedCert: shrinkingAlgId, |
| 15114 | SendCertUncompressedLength: 1 << 20, |
| 15115 | }, |
| 15116 | }, |
| 15117 | shouldFail: true, |
| 15118 | expectedError: ":UNCOMPRESSED_CERT_TOO_LARGE:", |
| 15119 | }) |
| 15120 | } |
| 15121 | } |
| 15122 |
| 15123 | func addJDK11WorkaroundTests() { |
| 15124 | // Test the client treats the JDK 11 downgrade random like the usual one. |
| 15125 | testCases = append(testCases, testCase{ |
| 15126 | testType: clientTest, |
| 15127 | name: "Client-RejectJDK11DowngradeRandom", |
| 15128 | config: Config{ |
| 15129 | MaxVersion: VersionTLS12, |
| 15130 | Bugs: ProtocolBugs{ |
| 15131 | SendJDK11DowngradeRandom: true, |
| 15132 | }, |
| 15133 | }, |
| 15134 | shouldFail: true, |
| 15135 | expectedError: ":TLS13_DOWNGRADE:", |
| 15136 | expectedLocalError: "remote error: illegal parameter", |
| 15137 | }) |
| 15138 | testCases = append(testCases, testCase{ |
| 15139 | testType: clientTest, |
| 15140 | name: "Client-AcceptJDK11DowngradeRandom", |
| 15141 | config: Config{ |
| 15142 | MaxVersion: VersionTLS12, |
| 15143 | Bugs: ProtocolBugs{ |
| 15144 | SendJDK11DowngradeRandom: true, |
| 15145 | }, |
| 15146 | }, |
| 15147 | flags: []string{"-max-version", strconv.Itoa(VersionTLS12)}, |
| 15148 | }) |
| 15149 |
| 15150 | var clientHelloTests = []struct { |
| 15151 | clientHello []byte |
| 15152 | isJDK11 bool |
| 15153 | }{ |
| 15154 | { |
| 15155 | // A default JDK 11 ClientHello. |
| 15156 | decodeHexOrPanic("010001a9030336a379aa355a22a064b4402760efae1c73977b0b4c975efc7654c35677723dde201fe3f8a2bca60418a68f72463ea19f3c241e7cbfceb347e451a62bd2417d8981005a13011302c02cc02bc030009dc02ec032009f00a3c02f009cc02dc031009e00a2c024c028003dc026c02a006b006ac00ac0140035c005c00f00390038c023c027003cc025c02900670040c009c013002fc004c00e0033003200ff01000106000000080006000003736e69000500050100000000000a0020001e0017001800190009000a000b000c000d000e001601000101010201030104000b00020100000d002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020032002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020011000900070200040000000000170000002b0009080304030303020301002d000201010033004700450017004104721f007464cb08a0f36e093ad178eb78d6968df20077b2dd882694a85dc4c9884caf5092db41f16cc3f8d41f59426992fa5e32cfb9ad08deee752cdd95b1a6b5"), |
| 15157 | true, |
| 15158 | }, |
| 15159 | { |
| 15160 | // The above with supported_versions and |
| 15161 | // psk_key_exchange_modes in the wrong order. |
| 15162 | decodeHexOrPanic("010001a9030336a379aa355a22a064b4402760efae1c73977b0b4c975efc7654c35677723dde201fe3f8a2bca60418a68f72463ea19f3c241e7cbfceb347e451a62bd2417d8981005a13011302c02cc02bc030009dc02ec032009f00a3c02f009cc02dc031009e00a2c024c028003dc026c02a006b006ac00ac0140035c005c00f00390038c023c027003cc025c02900670040c009c013002fc004c00e0033003200ff01000106000000080006000003736e69000500050100000000000a0020001e0017001800190009000a000b000c000d000e001601000101010201030104000b00020100000d002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020032002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020011000900070200040000000000170000002d00020101002b00090803040303030203010033004700450017004104721f007464cb08a0f36e093ad178eb78d6968df20077b2dd882694a85dc4c9884caf5092db41f16cc3f8d41f59426992fa5e32cfb9ad08deee752cdd95b1a6b5"), |
| 15163 | false, |
| 15164 | }, |
| 15165 | { |
| 15166 | // The above with a padding extension added at the end. |
| 15167 | decodeHexOrPanic("010001b4030336a379aa355a22a064b4402760efae1c73977b0b4c975efc7654c35677723dde201fe3f8a2bca60418a68f72463ea19f3c241e7cbfceb347e451a62bd2417d8981005a13011302c02cc02bc030009dc02ec032009f00a3c02f009cc02dc031009e00a2c024c028003dc026c02a006b006ac00ac0140035c005c00f00390038c023c027003cc025c02900670040c009c013002fc004c00e0033003200ff01000111000000080006000003736e69000500050100000000000a0020001e0017001800190009000a000b000c000d000e001601000101010201030104000b00020100000d002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020032002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020011000900070200040000000000170000002b0009080304030303020301002d000201010033004700450017004104721f007464cb08a0f36e093ad178eb78d6968df20077b2dd882694a85dc4c9884caf5092db41f16cc3f8d41f59426992fa5e32cfb9ad08deee752cdd95b1a6b50015000700000000000000"), |
| 15168 | false, |
| 15169 | }, |
| 15170 | { |
| 15171 | // A JDK 11 ClientHello offering a TLS 1.3 PSK. |
| 15172 | decodeHexOrPanic("0100024c0303a8d71b20f060545a398226e807d21371a7a02b7ca2f96f476c2dea7e5860c5a400005a13011302c02cc02bc030009dc02ec032009f00a3c02f009cc02dc031009e00a2c024c028003dc026c02a006b006ac00ac0140035c005c00f00390038c023c027003cc025c02900670040c009c013002fc004c00e0033003200ff010001c9000500050100000000000a0020001e0017001800190009000a000b000c000d000e001601000101010201030104000b00020100000d002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020032002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020011000900070200040000000000170000002b0009080304030303020301002d000201010033004700450017004104aaec585ea9e121b24710a23560571322b2cf8ab8cd14e5762ef0486d8a6d0ecd721d8f2abda2eb8ed5ab7195505660450f49bba94bbf0c3f0070a531d9a1be4f002900cb00a600a0e6f7586d9a2bf64a54c1adf55a2f76657047e8e88e26629e2e7b9d630941e06fd87792770f6834e159a70b252157a9b4b082183f24629c8ff5049088b07ce37c49de8cf752a2ed7a545aff63bdc7a1b18e1bc201f23f159ee75d4987a04e00f840824f764691ab83a20e3032646e793065874cdb46138a52f50ed71406f399f96f9309eba4e5b1966148c22a63dc4aa1364269dd41dd5cc0e848d07af0095622c52cfcfc00212009cc315259e2328d65ad17a3de7c182c7874140a9356fecdd4614657806cd659"), |
| 15173 | true, |
| 15174 | }, |
| 15175 | { |
| 15176 | // A JDK 11 ClientHello offering a TLS 1.2 session. |
| 15177 | decodeHexOrPanic("010001a903038cdec49f4836d064a75046c93f22d0b9c2cf4900917332e6f0e1f41d692d3146201a3e99047492285ec65ab4e0eeee59f8f9d1eb7687398887bcd7b81353e93923005a13011302c02cc02bc030009dc02ec032009f00a3c02f009cc02dc031009e00a2c024c028003dc026c02a006b006ac00ac0140035c005c00f00390038c023c027003cc025c02900670040c009c013002fc004c00e0033003200ff01000106000000080006000003736e69000500050100000000000a0020001e0017001800190009000a000b000c000d000e001601000101010201030104000b00020100000d002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020032002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020011000900070200040000000000170000002b0009080304030303020301002d0002010100330047004500170041041c83c42fcd8fc06265b9f6e4f076f7e7ee17ace915c587845c0e1bc8cd177f904befeb611b682cae4702509a5f5d0c7162a282b8152d843169b91136e7c6f3e7"), |
| 15178 | true, |
| 15179 | }, |
| 15180 | { |
| 15181 | // A JDK 11 ClientHello with EMS disabled. |
| 15182 | decodeHexOrPanic("010001a50303323a857c324a9ef57d6e2544d129073830385cb1dc75ea79f6a2ec8ae09d2e7320f85fdd081678874c67ebab235e6d6a81d947f690bc0af9be4d39854ed67d9ef9005a13011302c02cc02bc030009dc02ec032009f00a3c02f009cc02dc031009e00a2c024c028003dc026c02a006b006ac00ac0140035c005c00f00390038c023c027003cc025c02900670040c009c013002fc004c00e0033003200ff01000102000000080006000003736e69000500050100000000000a0020001e0017001800190009000a000b000c000d000e001601000101010201030104000b00020100000d002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020032002800260403050306030804080508060809080a080b040105010601040203030301030202030201020200110009000702000400000000002b0009080304030303020301002d0002010100330047004500170041049c904c4850b495d75522f955d79e9cabea065c90279d6037a101a4c4ee712afc93ad0df5d12d287d53e458c7075d9a3ce3969c939bb62222bda779cecf54a603"), |
| 15183 | true, |
| 15184 | }, |
| 15185 | { |
| 15186 | // A JDK 11 ClientHello with OCSP stapling disabled. |
| 15187 | decodeHexOrPanic("0100019303038a50481dc85ee4f6581670821c50f2b3d34ac3251dc6e9b751bfd2521ab47ab02069a963c5486034c37ae0577ddb4c2db28cab592380ef8e4599d1305148712112005a13011302c02cc02bc030009dc02ec032009f00a3c02f009cc02dc031009e00a2c024c028003dc026c02a006b006ac00ac0140035c005c00f00390038c023c027003cc025c02900670040c009c013002fc004c00e0033003200ff010000f0000000080006000003736e69000a0020001e0017001800190009000a000b000c000d000e001601000101010201030104000b00020100000d002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020032002800260403050306030804080508060809080a080b040105010601040203030301030202030201020200170000002b0009080304030303020301002d00020101003300470045001700410438a97824f842c549e3c339322d8b2dbaa85d10bd7bca9c969376cb0c60b1e929eb4d13db38dcb0082ad8c637b24f55466a9acbb0b63634c1f431ec8342cf720d"), |
| 15188 | true, |
| 15189 | }, |
| 15190 | { |
| 15191 | // A JDK 11 ClientHello configured with a smaller set of |
| 15192 | // ciphers. |
| 15193 | decodeHexOrPanic("0100015603036f5706bbdf1dcae671cd9be043603f5ed20f8fc195b426504cafb4f353edb0012007aabd35e588bc2504a72eda42cbbf89d69cfc0a6a1d77db0d757606f1f4811800061301c02bc02f01000107000000080006000003736e69000500050100000000000a0020001e0017001800190009000a000b000c000d000e001601000101010201030104000b00020100000d002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020032002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020011000900070200040000000000170000002b00050403040303002d000201010033004700450017004104d283f3d5a90259b61d43ea1511211f568ce5d18457326b717e1f9d6b7d1476f2b51cdc3c798d3bdfba5095edff0ffd0540f6bc0c324bd9744f3b3f24317496e3ff01000100"), |
| 15194 | true, |
| 15195 | }, |
| 15196 | { |
| 15197 | // The above with TLS_CHACHA20_POLY1305_SHA256 added, |
| 15198 | // which JDK 11 does not support. |
| 15199 | decodeHexOrPanic("0100015803036f5706bbdf1dcae671cd9be043603f5ed20f8fc195b426504cafb4f353edb0012007aabd35e588bc2504a72eda42cbbf89d69cfc0a6a1d77db0d757606f1f48118000813011303c02bc02f01000107000000080006000003736e69000500050100000000000a0020001e0017001800190009000a000b000c000d000e001601000101010201030104000b00020100000d002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020032002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020011000900070200040000000000170000002b00050403040303002d000201010033004700450017004104d283f3d5a90259b61d43ea1511211f568ce5d18457326b717e1f9d6b7d1476f2b51cdc3c798d3bdfba5095edff0ffd0540f6bc0c324bd9744f3b3f24317496e3ff01000100"), |
| 15200 | false, |
| 15201 | }, |
| 15202 | { |
| 15203 | // The above with X25519 added, which JDK 11 does not |
| 15204 | // support. |
| 15205 | decodeHexOrPanic("0100015803036f5706bbdf1dcae671cd9be043603f5ed20f8fc195b426504cafb4f353edb0012007aabd35e588bc2504a72eda42cbbf89d69cfc0a6a1d77db0d757606f1f4811800061301c02bc02f01000109000000080006000003736e69000500050100000000000a00220020001d0017001800190009000a000b000c000d000e001601000101010201030104000b00020100000d002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020032002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020011000900070200040000000000170000002b00050403040303002d000201010033004700450017004104d283f3d5a90259b61d43ea1511211f568ce5d18457326b717e1f9d6b7d1476f2b51cdc3c798d3bdfba5095edff0ffd0540f6bc0c324bd9744f3b3f24317496e3ff01000100"), |
| 15206 | false, |
| 15207 | }, |
| 15208 | { |
| 15209 | // A JDK 11 ClientHello with ALPN protocols configured. |
| 15210 | decodeHexOrPanic("010001bb0303c0e0ea707b00c5311eb09cabd58626692cebfaefaef7265637e4550811dae16220da86d6eea04e214e873675223f08a6926bcf79f16d866280bdbab85e9e09c3ff005a13011302c02cc02bc030009dc02ec032009f00a3c02f009cc02dc031009e00a2c024c028003dc026c02a006b006ac00ac0140035c005c00f00390038c023c027003cc025c02900670040c009c013002fc004c00e0033003200ff01000118000000080006000003736e69000500050100000000000a0020001e0017001800190009000a000b000c000d000e001601000101010201030104000b00020100000d002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020032002800260403050306030804080508060809080a080b04010501060104020303030103020203020102020010000e000c02683208687474702f312e310011000900070200040000000000170000002b0009080304030303020301002d00020101003300470045001700410416def07c1d66ddde5fc9dcc328c8e77022d321c590c0d30cb41d515b38dca34540819a216c6c053bd47b9068f4f6b960f03647de4e36e8b7ffeea78f7252e3d9"), |
| 15211 | true, |
| 15212 | }, |
| 15213 | } |
| 15214 | for i, t := range clientHelloTests { |
| 15215 | expectedVersion := uint16(VersionTLS13) |
| 15216 | if t.isJDK11 { |
| 15217 | expectedVersion = VersionTLS12 |
| 15218 | } |
| 15219 |
| 15220 | // In each of these tests, we set DefaultCurves to P-256 to |
| 15221 | // match the test inputs. SendClientHelloWithFixes requires the |
| 15222 | // key_shares extension to match in type. |
| 15223 |
| 15224 | // With the workaround enabled, we should negotiate TLS 1.2 on |
| 15225 | // JDK 11 ClientHellos. |
| 15226 | testCases = append(testCases, testCase{ |
| 15227 | testType: serverTest, |
| 15228 | name: fmt.Sprintf("Server-JDK11-%d", i), |
| 15229 | config: Config{ |
| 15230 | MaxVersion: VersionTLS13, |
| 15231 | DefaultCurves: []CurveID{CurveP256}, |
| 15232 | Bugs: ProtocolBugs{ |
| 15233 | SendClientHelloWithFixes: t.clientHello, |
| 15234 | ExpectJDK11DowngradeRandom: t.isJDK11, |
| 15235 | }, |
| 15236 | }, |
| 15237 | expectedVersion: expectedVersion, |
| 15238 | flags: []string{"-jdk11-workaround"}, |
| 15239 | }) |
| 15240 |
| 15241 | // With the workaround disabled, we always negotiate TLS 1.3. |
| 15242 | testCases = append(testCases, testCase{ |
| 15243 | testType: serverTest, |
| 15244 | name: fmt.Sprintf("Server-JDK11-NoWorkaround-%d", i), |
| 15245 | config: Config{ |
| 15246 | MaxVersion: VersionTLS13, |
| 15247 | DefaultCurves: []CurveID{CurveP256}, |
| 15248 | Bugs: ProtocolBugs{ |
| 15249 | SendClientHelloWithFixes: t.clientHello, |
| 15250 | ExpectJDK11DowngradeRandom: false, |
| 15251 | }, |
| 15252 | }, |
| 15253 | expectedVersion: VersionTLS13, |
| 15254 | }) |
| 15255 |
| 15256 | // If the server does not support TLS 1.3, the workaround should |
| 15257 | // be a no-op. In particular, it should not send the downgrade |
| 15258 | // signal. |
| 15259 | testCases = append(testCases, testCase{ |
| 15260 | testType: serverTest, |
| 15261 | name: fmt.Sprintf("Server-JDK11-TLS12-%d", i), |
| 15262 | config: Config{ |
| 15263 | MaxVersion: VersionTLS13, |
| 15264 | DefaultCurves: []CurveID{CurveP256}, |
| 15265 | Bugs: ProtocolBugs{ |
| 15266 | SendClientHelloWithFixes: t.clientHello, |
| 15267 | ExpectJDK11DowngradeRandom: false, |
| 15268 | }, |
| 15269 | }, |
| 15270 | expectedVersion: VersionTLS12, |
| 15271 | flags: []string{ |
| 15272 | "-jdk11-workaround", |
| 15273 | "-max-version", strconv.Itoa(VersionTLS12), |
| 15274 | }, |
| 15275 | }) |
| 15276 | } |
| 15277 | } |
| 15278 |
| 15279 | func addDelegatedCredentialTests() { |
| 15280 | certPath := path.Join(*resourceDir, rsaCertificateFile) |
| 15281 | pemBytes, err := ioutil.ReadFile(certPath) |
| 15282 | if err != nil { |
| 15283 | panic(err) |
| 15284 | } |
| 15285 |
| 15286 | block, _ := pem.Decode(pemBytes) |
| 15287 | if block == nil { |
| 15288 | panic(fmt.Sprintf("no PEM block found in %q", certPath)) |
| 15289 | } |
| 15290 | parentDER := block.Bytes |
| 15291 |
| 15292 | rsaPriv, _, err := loadRSAPrivateKey(rsaKeyFile) |
| 15293 | if err != nil { |
| 15294 | panic(err) |
| 15295 | } |
| 15296 |
| 15297 | ecdsaDC, ecdsaPKCS8, err := createDelegatedCredential(delegatedCredentialConfig{ |
| 15298 | algo: signatureRSAPSSWithSHA256, |
| 15299 | }, parentDER, rsaPriv) |
| 15300 | if err != nil { |
| 15301 | panic(err) |
| 15302 | } |
| 15303 | ecdsaFlagValue := fmt.Sprintf("%x,%x", ecdsaDC, ecdsaPKCS8) |
| 15304 |
| 15305 | testCases = append(testCases, testCase{ |
| 15306 | testType: serverTest, |
| 15307 | name: "DelegatedCredentials-NoClientSupport", |
| 15308 | config: Config{ |
| 15309 | MinVersion: VersionTLS13, |
| 15310 | MaxVersion: VersionTLS13, |
| 15311 | Bugs: ProtocolBugs{ |
| 15312 | DisableDelegatedCredentials: true, |
| 15313 | }, |
| 15314 | }, |
| 15315 | flags: []string{ |
| 15316 | "-delegated-credential", ecdsaFlagValue, |
| 15317 | }, |
| 15318 | }) |
| 15319 |
| 15320 | testCases = append(testCases, testCase{ |
| 15321 | testType: serverTest, |
| 15322 | name: "DelegatedCredentials-Basic", |
| 15323 | config: Config{ |
| 15324 | MinVersion: VersionTLS13, |
| 15325 | MaxVersion: VersionTLS13, |
| 15326 | Bugs: ProtocolBugs{ |
| 15327 | ExpectDelegatedCredentials: true, |
| 15328 | }, |
| 15329 | }, |
| 15330 | flags: []string{ |
| 15331 | "-delegated-credential", ecdsaFlagValue, |
| 15332 | "-expect-delegated-credential-used", |
| 15333 | }, |
| 15334 | }) |
| 15335 |
| 15336 | testCases = append(testCases, testCase{ |
| 15337 | testType: serverTest, |
| 15338 | name: "DelegatedCredentials-SigAlgoMissing", |
| 15339 | config: Config{ |
| 15340 | MinVersion: VersionTLS13, |
| 15341 | MaxVersion: VersionTLS13, |
| 15342 | Bugs: ProtocolBugs{ |
| 15343 | FailIfDelegatedCredentials: true, |
| 15344 | }, |
| 15345 | // If the client doesn't support the delegated credential signature |
| 15346 | // algorithm then the handshake should complete without using delegated |
| 15347 | // credentials. |
| 15348 | VerifySignatureAlgorithms: []signatureAlgorithm{signatureRSAPSSWithSHA256}, |
| 15349 | }, |
| 15350 | flags: []string{ |
| 15351 | "-delegated-credential", ecdsaFlagValue, |
| 15352 | }, |
| 15353 | }) |
| 15354 |
| 15355 | // This flag value has mismatched public and private keys which should cause a |
| 15356 | // configuration error in the shim. |
| 15357 | _, badTLSVersionPKCS8, err := createDelegatedCredential(delegatedCredentialConfig{ |
| 15358 | algo: signatureRSAPSSWithSHA256, |
| 15359 | tlsVersion: 0x1234, |
| 15360 | }, parentDER, rsaPriv) |
| 15361 | if err != nil { |
| 15362 | panic(err) |
| 15363 | } |
| 15364 | mismatchFlagValue := fmt.Sprintf("%x,%x", ecdsaDC, badTLSVersionPKCS8) |
| 15365 | testCases = append(testCases, testCase{ |
| 15366 | testType: serverTest, |
| 15367 | name: "DelegatedCredentials-KeyMismatch", |
| 15368 | config: Config{ |
| 15369 | MinVersion: VersionTLS13, |
| 15370 | MaxVersion: VersionTLS13, |
| 15371 | Bugs: ProtocolBugs{ |
| 15372 | FailIfDelegatedCredentials: true, |
| 15373 | }, |
| 15374 | }, |
| 15375 | flags: []string{ |
| 15376 | "-delegated-credential", mismatchFlagValue, |
| 15377 | }, |
| 15378 | shouldFail: true, |
| 15379 | expectedError: ":KEY_VALUES_MISMATCH:", |
| 15380 | }) |
| 15381 | } |
| 15382 |
| 15383 | func addPQExperimentSignalTests() { |
| 15384 | testCases = append(testCases, testCase{ |
| 15385 | testType: serverTest, |
| 15386 | name: "PQExperimentSignal-Server-NoEchoIfNotConfigured", |
| 15387 | config: Config{ |
| 15388 | MinVersion: VersionTLS13, |
| 15389 | MaxVersion: VersionTLS13, |
| 15390 | Bugs: ProtocolBugs{ |
| 15391 | ExpectPQExperimentSignal: false, |
| 15392 | }, |
| 15393 | PQExperimentSignal: true, |
| 15394 | }, |
| 15395 | }) |
| 15396 |
| 15397 | testCases = append(testCases, testCase{ |
| 15398 | testType: serverTest, |
| 15399 | name: "PQExperimentSignal-Server-Echo", |
| 15400 | config: Config{ |
| 15401 | MinVersion: VersionTLS13, |
| 15402 | MaxVersion: VersionTLS13, |
| 15403 | Bugs: ProtocolBugs{ |
| 15404 | ExpectPQExperimentSignal: true, |
| 15405 | }, |
| 15406 | PQExperimentSignal: true, |
| 15407 | }, |
| 15408 | flags: []string{ |
| 15409 | "-enable-pq-experiment-signal", |
| 15410 | "-expect-pq-experiment-signal", |
| 15411 | }, |
| 15412 | }) |
| 15413 |
| 15414 | testCases = append(testCases, testCase{ |
| 15415 | testType: clientTest, |
| 15416 | name: "PQExperimentSignal-Client-NotDefault", |
| 15417 | config: Config{ |
| 15418 | MinVersion: VersionTLS13, |
| 15419 | MaxVersion: VersionTLS13, |
| 15420 | Bugs: ProtocolBugs{ |
| 15421 | ExpectPQExperimentSignal: false, |
| 15422 | }, |
| 15423 | PQExperimentSignal: true, |
| 15424 | }, |
| 15425 | }) |
| 15426 |
| 15427 | testCases = append(testCases, testCase{ |
| 15428 | testType: clientTest, |
| 15429 | name: "PQExperimentSignal-Client", |
| 15430 | config: Config{ |
| 15431 | MinVersion: VersionTLS13, |
| 15432 | MaxVersion: VersionTLS13, |
| 15433 | Bugs: ProtocolBugs{ |
| 15434 | ExpectPQExperimentSignal: true, |
| 15435 | }, |
| 15436 | }, |
| 15437 | flags: []string{ |
| 15438 | "-enable-pq-experiment-signal", |
| 15439 | "-expect-pq-experiment-signal", |
| 15440 | }, |
| 15441 | }) |
| 15442 | } |
| 15443 |
| 15444 | func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) { |
| 15445 | defer wg.Done() |
| 15446 |
| 15447 | for test := range c { |
| 15448 | var err error |
| 15449 |
| 15450 | if *mallocTest >= 0 { |
| 15451 | for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ { |
| 15452 | statusChan <- statusMsg{test: test, started: true} |
| 15453 | if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs { |
| 15454 | if err != nil { |
| 15455 | fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err) |
| 15456 | } |
| 15457 | break |
| 15458 | } |
| 15459 | } |
| 15460 | } else if *repeatUntilFailure { |
| 15461 | for err == nil { |
| 15462 | statusChan <- statusMsg{test: test, started: true} |
| 15463 | err = runTest(test, shimPath, -1) |
| 15464 | } |
| 15465 | } else { |
| 15466 | statusChan <- statusMsg{test: test, started: true} |
| 15467 | err = runTest(test, shimPath, -1) |
| 15468 | } |
| 15469 | statusChan <- statusMsg{test: test, err: err} |
| 15470 | } |
| 15471 | } |
| 15472 |
| 15473 | type statusMsg struct { |
| 15474 | test *testCase |
| 15475 | started bool |
| 15476 | err error |
| 15477 | } |
| 15478 |
| 15479 | func statusPrinter(doneChan chan *testresult.Results, statusChan chan statusMsg, total int) { |
| 15480 | var started, done, failed, unimplemented, lineLen int |
| 15481 |
| 15482 | testOutput := testresult.NewResults() |
| 15483 | for msg := range statusChan { |
| 15484 | if !*pipe { |
| 15485 | // Erase the previous status line. |
| 15486 | var erase string |
| 15487 | for i := 0; i < lineLen; i++ { |
| 15488 | erase += "\b \b" |
| 15489 | } |
| 15490 | fmt.Print(erase) |
| 15491 | } |
| 15492 |
| 15493 | if msg.started { |
| 15494 | started++ |
| 15495 | } else { |
| 15496 | done++ |
| 15497 |
| 15498 | if msg.err != nil { |
| 15499 | if msg.err == errUnimplemented { |
| 15500 | if *pipe { |
| 15501 | // Print each test instead of a status line. |
| 15502 | fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name) |
| 15503 | } |
| 15504 | unimplemented++ |
| 15505 | if *allowUnimplemented { |
| 15506 | testOutput.AddSkip(msg.test.name) |
| 15507 | } else { |
| 15508 | testOutput.AddResult(msg.test.name, "SKIP") |
| 15509 | } |
| 15510 | } else { |
| 15511 | fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err) |
| 15512 | failed++ |
| 15513 | testOutput.AddResult(msg.test.name, "FAIL") |
| 15514 | } |
| 15515 | } else { |
| 15516 | if *pipe { |
| 15517 | // Print each test instead of a status line. |
| 15518 | fmt.Printf("PASSED (%s)\n", msg.test.name) |
| 15519 | } |
| 15520 | testOutput.AddResult(msg.test.name, "PASS") |
| 15521 | } |
| 15522 | } |
| 15523 |
| 15524 | if !*pipe { |
| 15525 | // Print a new status line. |
| 15526 | line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total) |
| 15527 | lineLen = len(line) |
| 15528 | os.Stdout.WriteString(line) |
| 15529 | } |
| 15530 | } |
| 15531 |
| 15532 | doneChan <- testOutput |
| 15533 | } |
| 15534 |
| 15535 | func main() { |
| 15536 | flag.Parse() |
| 15537 | *resourceDir = path.Clean(*resourceDir) |
| 15538 | initCertificates() |
| 15539 |
| 15540 | addBasicTests() |
| 15541 | addCipherSuiteTests() |
| 15542 | addBadECDSASignatureTests() |
| 15543 | addCBCPaddingTests() |
| 15544 | addCBCSplittingTests() |
| 15545 | addClientAuthTests() |
| 15546 | addDDoSCallbackTests() |
| 15547 | addVersionNegotiationTests() |
| 15548 | addMinimumVersionTests() |
| 15549 | addExtensionTests() |
| 15550 | addResumptionVersionTests() |
| 15551 | addExtendedMasterSecretTests() |
| 15552 | addRenegotiationTests() |
| 15553 | addDTLSReplayTests() |
| 15554 | addSignatureAlgorithmTests() |
| 15555 | addDTLSRetransmitTests() |
| 15556 | addExportKeyingMaterialTests() |
| 15557 | addExportTrafficSecretsTests() |
| 15558 | addTLSUniqueTests() |
| 15559 | addCustomExtensionTests() |
| 15560 | addRSAClientKeyExchangeTests() |
| 15561 | addCurveTests() |
| 15562 | addSessionTicketTests() |
| 15563 | addTLS13RecordTests() |
| 15564 | addAllStateMachineCoverageTests() |
| 15565 | addChangeCipherSpecTests() |
| 15566 | addWrongMessageTypeTests() |
| 15567 | addTrailingMessageDataTests() |
| 15568 | addTLS13HandshakeTests() |
| 15569 | addTLS13CipherPreferenceTests() |
| 15570 | addPeekTests() |
| 15571 | addRecordVersionTests() |
| 15572 | addCertificateTests() |
| 15573 | addRetainOnlySHA256ClientCertTests() |
| 15574 | addECDSAKeyUsageTests() |
| 15575 | addRSAKeyUsageTests() |
| 15576 | addExtraHandshakeTests() |
| 15577 | addOmitExtensionsTests() |
| 15578 | addCertCompressionTests() |
| 15579 | addJDK11WorkaroundTests() |
| 15580 | addDelegatedCredentialTests() |
| 15581 | addPQExperimentSignalTests() |
| 15582 |
| 15583 | testCases = append(testCases, convertToSplitHandshakeTests(testCases)...) |
| 15584 |
| 15585 | var wg sync.WaitGroup |
| 15586 |
| 15587 | statusChan := make(chan statusMsg, *numWorkers) |
| 15588 | testChan := make(chan *testCase, *numWorkers) |
| 15589 | doneChan := make(chan *testresult.Results) |
| 15590 |
| 15591 | if len(*shimConfigFile) != 0 { |
| 15592 | encoded, err := ioutil.ReadFile(*shimConfigFile) |
| 15593 | if err != nil { |
| 15594 | fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err) |
| 15595 | os.Exit(1) |
| 15596 | } |
| 15597 |
| 15598 | if err := json.Unmarshal(encoded, &shimConfig); err != nil { |
| 15599 | fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err) |
| 15600 | os.Exit(1) |
| 15601 | } |
| 15602 | } |
| 15603 |
| 15604 | go statusPrinter(doneChan, statusChan, len(testCases)) |
| 15605 |
| 15606 | for i := 0; i < *numWorkers; i++ { |
| 15607 | wg.Add(1) |
| 15608 | go worker(statusChan, testChan, *shimPath, &wg) |
| 15609 | } |
| 15610 |
| 15611 | var foundTest bool |
| 15612 | for i := range testCases { |
| 15613 | matched := true |
| 15614 | if len(*testToRun) != 0 { |
| 15615 | var err error |
| 15616 | matched, err = filepath.Match(*testToRun, testCases[i].name) |
| 15617 | if err != nil { |
| 15618 | fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err) |
| 15619 | os.Exit(1) |
| 15620 | } |
| 15621 | } |
| 15622 |
| 15623 | if !*includeDisabled { |
| 15624 | for pattern := range shimConfig.DisabledTests { |
| 15625 | isDisabled, err := filepath.Match(pattern, testCases[i].name) |
| 15626 | if err != nil { |
| 15627 | fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err) |
| 15628 | os.Exit(1) |
| 15629 | } |
| 15630 |
| 15631 | if isDisabled { |
| 15632 | matched = false |
| 15633 | break |
| 15634 | } |
| 15635 | } |
| 15636 | } |
| 15637 |
| 15638 | if matched { |
| 15639 | foundTest = true |
| 15640 | testChan <- &testCases[i] |
| 15641 |
| 15642 | // Only run one test if repeating until failure. |
| 15643 | if *repeatUntilFailure { |
| 15644 | break |
| 15645 | } |
| 15646 | } |
| 15647 | } |
| 15648 |
| 15649 | if !foundTest { |
| 15650 | fmt.Fprintf(os.Stderr, "No tests run\n") |
| 15651 | os.Exit(1) |
| 15652 | } |
| 15653 |
| 15654 | close(testChan) |
| 15655 | wg.Wait() |
| 15656 | close(statusChan) |
| 15657 | testOutput := <-doneChan |
| 15658 |
| 15659 | fmt.Printf("\n") |
| 15660 |
| 15661 | if *jsonOutput != "" { |
| 15662 | if err := testOutput.WriteToFile(*jsonOutput); err != nil { |
| 15663 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 15664 | } |
| 15665 | } |
| 15666 |
| 15667 | if !testOutput.HasUnexpectedResults() { |
| 15668 | os.Exit(1) |
| 15669 | } |
| 15670 | } |
| 15671 |