OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "base/trace_event/memory_allocator_dump.h" | |
22 #include "base/trace_event/process_memory_dump.h" | |
23 #include "base/trace_event/trace_event_argument.h" | |
24 #include "base/values.h" | 21 #include "base/values.h" |
25 #include "net/base/address_list.h" | 22 #include "net/base/address_list.h" |
26 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
27 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
28 #include "net/base/test_completion_callback.h" | 25 #include "net/base/test_completion_callback.h" |
29 #include "net/cert/asn1_util.h" | 26 #include "net/cert/asn1_util.h" |
30 #include "net/cert/ct_policy_enforcer.h" | 27 #include "net/cert/ct_policy_enforcer.h" |
31 #include "net/cert/ct_policy_status.h" | 28 #include "net/cert/ct_policy_status.h" |
32 #include "net/cert/ct_verifier.h" | 29 #include "net/cert/ct_verifier.h" |
33 #include "net/cert/do_nothing_ct_verifier.h" | 30 #include "net/cert/do_nothing_ct_verifier.h" |
34 #include "net/cert/mock_cert_verifier.h" | 31 #include "net/cert/mock_cert_verifier.h" |
35 #include "net/cert/signed_certificate_timestamp_and_status.h" | 32 #include "net/cert/signed_certificate_timestamp_and_status.h" |
36 #include "net/cert/test_root_certs.h" | 33 #include "net/cert/test_root_certs.h" |
37 #include "net/der/input.h" | 34 #include "net/der/input.h" |
38 #include "net/der/parser.h" | 35 #include "net/der/parser.h" |
39 #include "net/der/tag.h" | 36 #include "net/der/tag.h" |
40 #include "net/dns/host_resolver.h" | 37 #include "net/dns/host_resolver.h" |
41 #include "net/http/transport_security_state.h" | 38 #include "net/http/transport_security_state.h" |
42 #include "net/log/net_log_event_type.h" | 39 #include "net/log/net_log_event_type.h" |
43 #include "net/log/net_log_source.h" | 40 #include "net/log/net_log_source.h" |
44 #include "net/log/test_net_log.h" | 41 #include "net/log/test_net_log.h" |
45 #include "net/log/test_net_log_entry.h" | 42 #include "net/log/test_net_log_entry.h" |
46 #include "net/log/test_net_log_util.h" | 43 #include "net/log/test_net_log_util.h" |
47 #include "net/socket/client_socket_factory.h" | 44 #include "net/socket/client_socket_factory.h" |
48 #include "net/socket/client_socket_handle.h" | 45 #include "net/socket/client_socket_handle.h" |
49 #include "net/socket/socket_test_util.h" | 46 #include "net/socket/socket_test_util.h" |
| 47 #include "net/socket/stream_socket.h" |
50 #include "net/socket/tcp_client_socket.h" | 48 #include "net/socket/tcp_client_socket.h" |
51 #include "net/ssl/channel_id_service.h" | 49 #include "net/ssl/channel_id_service.h" |
52 #include "net/ssl/default_channel_id_store.h" | 50 #include "net/ssl/default_channel_id_store.h" |
53 #include "net/ssl/ssl_cert_request_info.h" | 51 #include "net/ssl/ssl_cert_request_info.h" |
54 #include "net/ssl/ssl_config_service.h" | 52 #include "net/ssl/ssl_config_service.h" |
55 #include "net/ssl/ssl_connection_status_flags.h" | 53 #include "net/ssl/ssl_connection_status_flags.h" |
56 #include "net/ssl/ssl_info.h" | 54 #include "net/ssl/ssl_info.h" |
57 #include "net/ssl/test_ssl_private_key.h" | 55 #include "net/ssl/test_ssl_private_key.h" |
58 #include "net/test/cert_test_util.h" | 56 #include "net/test/cert_test_util.h" |
59 #include "net/test/gtest_util.h" | 57 #include "net/test/gtest_util.h" |
(...skipping 3560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3620 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); | 3618 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); |
3621 } | 3619 } |
3622 | 3620 |
3623 // Basic test for dumping memory stats. | 3621 // Basic test for dumping memory stats. |
3624 TEST_F(SSLClientSocketTest, DumpMemoryStats) { | 3622 TEST_F(SSLClientSocketTest, DumpMemoryStats) { |
3625 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 3623 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
3626 | 3624 |
3627 int rv; | 3625 int rv; |
3628 ASSERT_TRUE(CreateAndConnectSSLClientSocket(SSLConfig(), &rv)); | 3626 ASSERT_TRUE(CreateAndConnectSSLClientSocket(SSLConfig(), &rv)); |
3629 EXPECT_THAT(rv, IsOk()); | 3627 EXPECT_THAT(rv, IsOk()); |
3630 | 3628 StreamSocket::SocketMemoryStats stats; |
3631 base::trace_event::MemoryDumpArgs dump_args = { | 3629 sock_->DumpMemoryStats(&stats); |
3632 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; | 3630 EXPECT_EQ(0u, stats.buffer_size); |
3633 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( | 3631 EXPECT_EQ(1u, stats.cert_count); |
3634 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); | 3632 EXPECT_LT(0u, stats.serialized_cert_size); |
3635 base::trace_event::MemoryAllocatorDump* parent_dump1 = | 3633 EXPECT_EQ(stats.serialized_cert_size, stats.total_size); |
3636 process_memory_dump->CreateAllocatorDump("parent1"); | |
3637 sock_->DumpMemoryStats(process_memory_dump.get(), | |
3638 parent_dump1->absolute_name()); | |
3639 | 3634 |
3640 // Read the response without writing a request, so the read will be pending. | 3635 // Read the response without writing a request, so the read will be pending. |
3641 TestCompletionCallback read_callback; | 3636 TestCompletionCallback read_callback; |
3642 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); | 3637 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); |
3643 rv = sock_->Read(buf.get(), 4096, read_callback.callback()); | 3638 rv = sock_->Read(buf.get(), 4096, read_callback.callback()); |
3644 EXPECT_EQ(ERR_IO_PENDING, rv); | 3639 EXPECT_EQ(ERR_IO_PENDING, rv); |
3645 | 3640 |
3646 // Dump memory again and check that |buffer_size| contain the read buffer. | 3641 // Dump memory again and check that |buffer_size| contain the read buffer. |
3647 base::trace_event::MemoryAllocatorDump* parent_dump2 = | 3642 StreamSocket::SocketMemoryStats stats2; |
3648 process_memory_dump->CreateAllocatorDump("parent2"); | 3643 sock_->DumpMemoryStats(&stats2); |
3649 sock_->DumpMemoryStats(process_memory_dump.get(), | 3644 EXPECT_EQ(17 * 1024u, stats2.buffer_size); |
3650 parent_dump2->absolute_name()); | 3645 EXPECT_EQ(1u, stats2.cert_count); |
3651 | 3646 EXPECT_LT(0u, stats2.serialized_cert_size); |
3652 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap& | 3647 EXPECT_LT(17 * 1024u, stats2.total_size); |
3653 allocator_dumps = process_memory_dump->allocator_dumps(); | |
3654 bool did_dump[] = {false, false}; | |
3655 // Checks that there are two dumps because DumpMemoryStats() is invoked twice. | |
3656 for (const auto& pair : allocator_dumps) { | |
3657 const std::string& dump_name = pair.first; | |
3658 if (dump_name.find("ssl_socket") == std::string::npos) | |
3659 continue; | |
3660 std::unique_ptr<base::Value> raw_attrs = | |
3661 pair.second->attributes_for_testing()->ToBaseValue(); | |
3662 base::DictionaryValue* attrs; | |
3663 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); | |
3664 base::DictionaryValue* buffer_size_attrs; | |
3665 ASSERT_TRUE(attrs->GetDictionary("buffer_size", &buffer_size_attrs)); | |
3666 std::string buffer_size; | |
3667 ASSERT_TRUE(buffer_size_attrs->GetString("value", &buffer_size)); | |
3668 ASSERT_TRUE(attrs->HasKey("serialized_cert_size")); | |
3669 ASSERT_TRUE(attrs->HasKey("cert_count")); | |
3670 if (dump_name.find("parent1/ssl_socket") != std::string::npos) { | |
3671 did_dump[0] = true; | |
3672 ASSERT_EQ("0", buffer_size); | |
3673 } | |
3674 if (dump_name.find("parent2/ssl_socket") != std::string::npos) { | |
3675 did_dump[1] = true; | |
3676 // The read buffer is not released, so |buffer_size| can't be 0. | |
3677 ASSERT_NE("0", buffer_size); | |
3678 } | |
3679 } | |
3680 EXPECT_THAT(did_dump, testing::ElementsAre(true, true)); | |
3681 } | 3648 } |
3682 | 3649 |
3683 } // namespace net | 3650 } // namespace net |
OLD | NEW |