• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/http/http_auth_handler_digest.h"
6 
7 #include <fuzzer/FuzzedDataProvider.h>
8 
9 #include <memory>
10 #include <string>
11 #include <string_view>
12 
13 #include "net/base/network_anonymization_key.h"
14 #include "net/dns/mock_host_resolver.h"
15 #include "net/http/http_auth_challenge_tokenizer.h"
16 #include "net/http/http_auth_handler.h"
17 #include "net/log/net_log_with_source.h"
18 #include "net/ssl/ssl_info.h"
19 #include "url/gurl.h"
20 #include "url/scheme_host_port.h"
21 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)22 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
23   FuzzedDataProvider data_provider{data, size};
24 
25   std::string challenge =
26       "Digest " + data_provider.ConsumeRandomLengthString(500);
27 
28   // Dummies
29   net::SSLInfo null_ssl_info;
30   url::SchemeHostPort scheme_host_port(GURL("https://foo.test/"));
31   auto host_resolver = std::make_unique<net::MockHostResolver>();
32   std::unique_ptr<net::HttpAuthHandler> handler;
33 
34   net::HttpAuthHandlerDigest::Factory factory;
35   factory.CreateAuthHandlerFromString(
36       challenge, net::HttpAuth::AUTH_SERVER, null_ssl_info,
37       net::NetworkAnonymizationKey(), scheme_host_port, net::NetLogWithSource(),
38       host_resolver.get(), &handler);
39 
40   if (handler) {
41     auto followup = "Digest " + data_provider.ConsumeRemainingBytesAsString();
42     net::HttpAuthChallengeTokenizer tokenizer{followup};
43     handler->HandleAnotherChallenge(&tokenizer);
44   }
45   return 0;
46 }
47