http_auth_handler_digest_fuzzer.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2019 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_digest.h"
  12. #include "net/log/net_log_with_source.h"
  13. #include "net/ssl/ssl_info.h"
  14. #include "url/gurl.h"
  15. #include "url/scheme_host_port.h"
  16. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  17. FuzzedDataProvider data_provider{data, size};
  18. std::string challenge =
  19. "Digest " + data_provider.ConsumeRandomLengthString(500);
  20. // Dummies
  21. net::SSLInfo null_ssl_info;
  22. url::SchemeHostPort scheme_host_port(GURL("https://foo.test/"));
  23. auto host_resolver = std::make_unique<net::MockHostResolver>();
  24. std::unique_ptr<net::HttpAuthHandler> handler;
  25. net::HttpAuthHandlerDigest::Factory factory;
  26. factory.CreateAuthHandlerFromString(challenge, net::HttpAuth::AUTH_SERVER,
  27. null_ssl_info, net::NetworkIsolationKey(),
  28. scheme_host_port, net::NetLogWithSource(),
  29. host_resolver.get(), &handler);
  30. if (handler) {
  31. auto followup = "Digest " + data_provider.ConsumeRemainingBytesAsString();
  32. net::HttpAuthChallengeTokenizer tokenizer{followup.begin(), followup.end()};
  33. handler->HandleAnotherChallenge(&tokenizer);
  34. }
  35. return 0;
  36. }