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 <fuzzer/FuzzedDataProvider.h>
6
7 #include <memory>
8 #include <string>
9
10 #include "net/base/network_anonymization_key.h"
11 #include "net/dns/mock_host_resolver.h"
12 #include "net/http/http_auth_challenge_tokenizer.h"
13 #include "net/http/http_auth_handler.h"
14 #include "net/http/http_auth_handler_digest.h"
15 #include "net/log/net_log_with_source.h"
16 #include "net/ssl/ssl_info.h"
17 #include "url/gurl.h"
18 #include "url/scheme_host_port.h"
19
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)20 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
21 FuzzedDataProvider data_provider{data, size};
22
23 std::string challenge =
24 "Digest " + data_provider.ConsumeRandomLengthString(500);
25
26 // Dummies
27 net::SSLInfo null_ssl_info;
28 url::SchemeHostPort scheme_host_port(GURL("https://foo.test/"));
29 auto host_resolver = std::make_unique<net::MockHostResolver>();
30 std::unique_ptr<net::HttpAuthHandler> handler;
31
32 net::HttpAuthHandlerDigest::Factory factory;
33 factory.CreateAuthHandlerFromString(
34 challenge, net::HttpAuth::AUTH_SERVER, null_ssl_info,
35 net::NetworkAnonymizationKey(), scheme_host_port, net::NetLogWithSource(),
36 host_resolver.get(), &handler);
37
38 if (handler) {
39 auto followup = "Digest " + data_provider.ConsumeRemainingBytesAsString();
40 net::HttpAuthChallengeTokenizer tokenizer{followup.begin(), followup.end()};
41 handler->HandleAnotherChallenge(&tokenizer);
42 }
43 return 0;
44 }
45