http_auth_handler_fuzzer.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <fuzzer/FuzzedDataProvider.h>
  5. #include <memory>
  6. #include <string>
  7. #include "net/base/network_isolation_key.h"
  8. #include "net/dns/mock_host_resolver.h"
  9. #include "net/http/http_auth_challenge_tokenizer.h"
  10. #include "net/http/http_auth_handler.h"
  11. #include "net/http/http_auth_handler_factory.h"
  12. #include "net/http/http_auth_scheme.h"
  13. #include "net/log/net_log_with_source.h"
  14. #include "net/ssl/ssl_info.h"
  15. #include "url/gurl.h"
  16. #include "url/scheme_host_port.h"
  17. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  18. FuzzedDataProvider data_provider{data, size};
  19. std::string scheme;
  20. if (data_provider.ConsumeBool()) {
  21. scheme = std::string(data_provider.PickValueInArray(
  22. {net::kBasicAuthScheme, net::kDigestAuthScheme, net::kNtlmAuthScheme,
  23. net::kNegotiateAuthScheme}));
  24. } else {
  25. scheme = data_provider.ConsumeRandomLengthString(10);
  26. }
  27. std::unique_ptr<net::HttpAuthHandlerRegistryFactory> factory =
  28. net::HttpAuthHandlerFactory::CreateDefault();
  29. if (!factory->IsSchemeAllowedForTesting(scheme))
  30. return 0;
  31. std::string challenge = data_provider.ConsumeRandomLengthString(500);
  32. // Dummies
  33. net::SSLInfo null_ssl_info;
  34. url::SchemeHostPort scheme_host_port(GURL("https://foo.test/"));
  35. auto host_resolver = std::make_unique<net::MockHostResolver>();
  36. std::unique_ptr<net::HttpAuthHandler> handler;
  37. factory->CreateAuthHandlerFromString(
  38. challenge, net::HttpAuth::AUTH_SERVER, null_ssl_info,
  39. net::NetworkIsolationKey(), scheme_host_port, net::NetLogWithSource(),
  40. host_resolver.get(), &handler);
  41. if (handler) {
  42. auto followup = data_provider.ConsumeRemainingBytesAsString();
  43. net::HttpAuthChallengeTokenizer tokenizer{followup.begin(), followup.end()};
  44. handler->HandleAnotherChallenge(&tokenizer);
  45. }
  46. return 0;
  47. }