| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_proxy_client_socket.h" | 5 #include "net/http/http_proxy_client_socket.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "net/base/address_list.h" | 15 #include "net/base/address_list.h" |
| 16 #include "net/base/auth.h" | 16 #include "net/base/auth.h" |
| 17 #include "net/base/fuzzed_data_provider.h" |
| 17 #include "net/base/host_port_pair.h" | 18 #include "net/base/host_port_pair.h" |
| 18 #include "net/base/test_completion_callback.h" | 19 #include "net/base/test_completion_callback.h" |
| 19 #include "net/http/http_auth_cache.h" | 20 #include "net/http/http_auth_cache.h" |
| 20 #include "net/http/http_auth_handler_basic.h" | 21 #include "net/http/http_auth_handler_basic.h" |
| 21 #include "net/http/http_auth_handler_digest.h" | 22 #include "net/http/http_auth_handler_digest.h" |
| 22 #include "net/http/http_auth_handler_factory.h" | 23 #include "net/http/http_auth_handler_factory.h" |
| 23 #include "net/http/http_auth_scheme.h" | 24 #include "net/http/http_auth_scheme.h" |
| 24 #include "net/log/test_net_log.h" | 25 #include "net/log/test_net_log.h" |
| 25 #include "net/socket/client_socket_handle.h" | 26 #include "net/socket/client_socket_handle.h" |
| 26 #include "net/socket/fuzzed_socket.h" | 27 #include "net/socket/fuzzed_socket.h" |
| 27 #include "net/socket/next_proto.h" | 28 #include "net/socket/next_proto.h" |
| 28 | 29 |
| 29 // Fuzzer for HttpProxyClientSocket only tests establishing a connection when | 30 // Fuzzer for HttpProxyClientSocket only tests establishing a connection when |
| 30 // using the proxy as a tunnel. | 31 // using the proxy as a tunnel. |
| 31 // | 32 // |
| 32 // |data| is used to create a FuzzedSocket to fuzz reads and writes, see that | 33 // |data| is used to create a FuzzedSocket to fuzz reads and writes, see that |
| 33 // class for details. | 34 // class for details. |
| 34 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 35 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 35 // Use a test NetLog, to exercise logging code. | 36 // Use a test NetLog, to exercise logging code. |
| 36 net::BoundTestNetLog bound_test_net_log; | 37 net::TestNetLog test_net_log; |
| 37 | 38 |
| 38 // Use last byte to determine if the HttpProxyClientSocket should be told the | 39 net::FuzzedDataProvider data_provider(data, size); |
| 39 // underlying socket is HTTPS. | |
| 40 bool is_https_proxy = 0; | |
| 41 if (size > 0) { | |
| 42 is_https_proxy = !(data[size - 1] & 1); | |
| 43 size--; | |
| 44 } | |
| 45 | 40 |
| 46 net::TestCompletionCallback callback; | 41 net::TestCompletionCallback callback; |
| 47 std::unique_ptr<net::FuzzedSocket> fuzzed_socket( | 42 std::unique_ptr<net::FuzzedSocket> fuzzed_socket( |
| 48 new net::FuzzedSocket(data, size, bound_test_net_log.bound())); | 43 new net::FuzzedSocket(&data_provider, &test_net_log)); |
| 49 CHECK_EQ(net::OK, fuzzed_socket->Connect(callback.callback())); | 44 CHECK_EQ(net::OK, fuzzed_socket->Connect(callback.callback())); |
| 50 | 45 |
| 51 std::unique_ptr<net::ClientSocketHandle> socket_handle( | 46 std::unique_ptr<net::ClientSocketHandle> socket_handle( |
| 52 new net::ClientSocketHandle()); | 47 new net::ClientSocketHandle()); |
| 53 socket_handle->SetSocket(std::move(fuzzed_socket)); | 48 socket_handle->SetSocket(std::move(fuzzed_socket)); |
| 54 | 49 |
| 55 // Create auth handler supporting basic and digest schemes. Other schemes can | 50 // Create auth handler supporting basic and digest schemes. Other schemes can |
| 56 // make system calls, which doesn't seem like a great idea. | 51 // make system calls, which doesn't seem like a great idea. |
| 57 net::HttpAuthCache auth_cache; | 52 net::HttpAuthCache auth_cache; |
| 58 net::HttpAuthHandlerRegistryFactory auth_handler_factory; | 53 net::HttpAuthHandlerRegistryFactory auth_handler_factory; |
| 59 auth_handler_factory.RegisterSchemeFactory( | 54 auth_handler_factory.RegisterSchemeFactory( |
| 60 net::kBasicAuthScheme, new net::HttpAuthHandlerBasic::Factory()); | 55 net::kBasicAuthScheme, new net::HttpAuthHandlerBasic::Factory()); |
| 61 auth_handler_factory.RegisterSchemeFactory( | 56 auth_handler_factory.RegisterSchemeFactory( |
| 62 net::kDigestAuthScheme, new net::HttpAuthHandlerDigest::Factory()); | 57 net::kDigestAuthScheme, new net::HttpAuthHandlerDigest::Factory()); |
| 63 | 58 |
| 64 scoped_refptr<net::HttpAuthController> auth_controller( | 59 scoped_refptr<net::HttpAuthController> auth_controller( |
| 65 new net::HttpAuthController(net::HttpAuth::AUTH_PROXY, | 60 new net::HttpAuthController(net::HttpAuth::AUTH_PROXY, |
| 66 GURL("http://proxy:42/"), &auth_cache, | 61 GURL("http://proxy:42/"), &auth_cache, |
| 67 &auth_handler_factory)); | 62 &auth_handler_factory)); |
| 63 // Determine if the HttpProxyClientSocket should be told the underlying socket |
| 64 // is HTTPS. |
| 65 bool is_https_proxy = data_provider.ConsumeBool(); |
| 68 net::HttpProxyClientSocket socket( | 66 net::HttpProxyClientSocket socket( |
| 69 socket_handle.release(), "Bond/007", net::HostPortPair("foo", 80), | 67 socket_handle.release(), "Bond/007", net::HostPortPair("foo", 80), |
| 70 net::HostPortPair("proxy", 42), auth_controller.get(), true /* tunnel */, | 68 net::HostPortPair("proxy", 42), auth_controller.get(), true /* tunnel */, |
| 71 false /* using_spdy */, net::kProtoUnknown, nullptr /* proxy_delegate */, | 69 false /* using_spdy */, net::kProtoUnknown, nullptr /* proxy_delegate */, |
| 72 is_https_proxy); | 70 is_https_proxy); |
| 73 int result = socket.Connect(callback.callback()); | 71 int result = socket.Connect(callback.callback()); |
| 74 result = callback.GetResult(result); | 72 result = callback.GetResult(result); |
| 75 | 73 |
| 76 // Repeatedly try to log in with the same credentials. | 74 // Repeatedly try to log in with the same credentials. |
| 77 while (result == net::ERR_PROXY_AUTH_REQUESTED) { | 75 while (result == net::ERR_PROXY_AUTH_REQUESTED) { |
| 78 auth_controller->ResetAuth(net::AuthCredentials( | 76 auth_controller->ResetAuth(net::AuthCredentials( |
| 79 base::ASCIIToUTF16("user"), base::ASCIIToUTF16("pass"))); | 77 base::ASCIIToUTF16("user"), base::ASCIIToUTF16("pass"))); |
| 80 result = socket.RestartWithAuth(callback.callback()); | 78 result = socket.RestartWithAuth(callback.callback()); |
| 81 result = callback.GetResult(result); | 79 result = callback.GetResult(result); |
| 82 } | 80 } |
| 83 | 81 |
| 84 return 0; | 82 return 0; |
| 85 } | 83 } |
| OLD | NEW |