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_impl.h" | 5 #include "net/socket/ssl_client_socket_impl.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/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
14 #include "base/feature_list.h" | 14 #include "base/feature_list.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
18 #include "base/metrics/field_trial.h" | 18 #include "base/metrics/field_trial.h" |
19 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
20 #include "base/metrics/sparse_histogram.h" | 20 #include "base/metrics/sparse_histogram.h" |
21 #include "base/profiler/scoped_tracker.h" | 21 #include "base/profiler/scoped_tracker.h" |
22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
23 #include "base/strings/string_piece.h" | 23 #include "base/strings/string_piece.h" |
| 24 #include "base/strings/stringprintf.h" |
24 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
25 #include "base/threading/thread_local.h" | 26 #include "base/threading/thread_local.h" |
| 27 #include "base/trace_event/memory_allocator_dump.h" |
| 28 #include "base/trace_event/process_memory_dump.h" |
26 #include "base/trace_event/trace_event.h" | 29 #include "base/trace_event/trace_event.h" |
27 #include "base/values.h" | 30 #include "base/values.h" |
28 #include "crypto/ec_private_key.h" | 31 #include "crypto/ec_private_key.h" |
29 #include "crypto/openssl_util.h" | 32 #include "crypto/openssl_util.h" |
30 #include "net/base/ip_address.h" | 33 #include "net/base/ip_address.h" |
31 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
32 #include "net/cert/cert_verifier.h" | 35 #include "net/cert/cert_verifier.h" |
33 #include "net/cert/ct_ev_whitelist.h" | 36 #include "net/cert/ct_ev_whitelist.h" |
34 #include "net/cert/ct_policy_enforcer.h" | 37 #include "net/cert/ct_policy_enforcer.h" |
35 #include "net/cert/ct_policy_status.h" | 38 #include "net/cert/ct_policy_status.h" |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 } | 798 } |
796 | 799 |
797 void SSLClientSocketImpl::GetConnectionAttempts(ConnectionAttempts* out) const { | 800 void SSLClientSocketImpl::GetConnectionAttempts(ConnectionAttempts* out) const { |
798 out->clear(); | 801 out->clear(); |
799 } | 802 } |
800 | 803 |
801 int64_t SSLClientSocketImpl::GetTotalReceivedBytes() const { | 804 int64_t SSLClientSocketImpl::GetTotalReceivedBytes() const { |
802 return transport_->socket()->GetTotalReceivedBytes(); | 805 return transport_->socket()->GetTotalReceivedBytes(); |
803 } | 806 } |
804 | 807 |
| 808 void SSLClientSocketImpl::DumpMemoryStats( |
| 809 base::trace_event::ProcessMemoryDump* pmd, |
| 810 const std::string& parent_dump_absolute_name) const { |
| 811 size_t total_size = 0; |
| 812 base::trace_event::MemoryAllocatorDump* socket_dump = |
| 813 pmd->CreateAllocatorDump(base::StringPrintf( |
| 814 "%s/ssl_socket_%p", parent_dump_absolute_name.c_str(), this)); |
| 815 if (transport_adapter_) { |
| 816 size_t bio_buffers_size = transport_adapter_->GetAllocationSize(); |
| 817 socket_dump->AddScalar("buffer_size", |
| 818 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 819 bio_buffers_size); |
| 820 total_size += bio_buffers_size; |
| 821 } |
| 822 size_t total_cert_size = 0; |
| 823 size_t certs_count = 0; |
| 824 if (server_cert_chain_) { |
| 825 certs_count = server_cert_chain_->size(); |
| 826 for (size_t i = 0; i < certs_count; ++i) { |
| 827 X509* cert = server_cert_chain_->Get(i); |
| 828 total_cert_size += i2d_X509(cert, nullptr); |
| 829 } |
| 830 } |
| 831 total_size += total_cert_size; |
| 832 // This measures the lower bound of the serialized certificate. It doesn't |
| 833 // measure the actual memory used, which is 4x this amount (see |
| 834 // crbug.com/671420 for more details). |
| 835 socket_dump->AddScalar("serialized_cert_size", |
| 836 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 837 total_cert_size); |
| 838 socket_dump->AddScalar("cert_count", |
| 839 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 840 certs_count); |
| 841 socket_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 842 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 843 total_size); |
| 844 } |
| 845 |
| 846 // static |
| 847 void SSLClientSocketImpl::DumpSSLClientSessionMemoryStats( |
| 848 base::trace_event::ProcessMemoryDump* pmd) { |
| 849 SSLContext::GetInstance()->session_cache()->DumpMemoryStats(pmd); |
| 850 } |
| 851 |
805 int SSLClientSocketImpl::Read(IOBuffer* buf, | 852 int SSLClientSocketImpl::Read(IOBuffer* buf, |
806 int buf_len, | 853 int buf_len, |
807 const CompletionCallback& callback) { | 854 const CompletionCallback& callback) { |
808 user_read_buf_ = buf; | 855 user_read_buf_ = buf; |
809 user_read_buf_len_ = buf_len; | 856 user_read_buf_len_ = buf_len; |
810 | 857 |
811 int rv = DoPayloadRead(); | 858 int rv = DoPayloadRead(); |
812 | 859 |
813 if (rv == ERR_IO_PENDING) { | 860 if (rv == ERR_IO_PENDING) { |
814 user_read_callback_ = callback; | 861 user_read_callback_ = callback; |
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2019 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED && | 2066 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED && |
2020 !certificate_requested_) { | 2067 !certificate_requested_) { |
2021 net_error = ERR_SSL_PROTOCOL_ERROR; | 2068 net_error = ERR_SSL_PROTOCOL_ERROR; |
2022 } | 2069 } |
2023 } | 2070 } |
2024 | 2071 |
2025 return net_error; | 2072 return net_error; |
2026 } | 2073 } |
2027 | 2074 |
2028 } // namespace net | 2075 } // namespace net |
OLD | NEW |