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 <algorithm> | 10 #include <algorithm> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
15 #include "base/feature_list.h" | 15 #include "base/feature_list.h" |
16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/singleton.h" | 18 #include "base/memory/singleton.h" |
19 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" |
20 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
21 #include "base/metrics/sparse_histogram.h" | 21 #include "base/metrics/sparse_histogram.h" |
22 #include "base/profiler/scoped_tracker.h" | 22 #include "base/profiler/scoped_tracker.h" |
23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_piece.h" | 24 #include "base/strings/string_piece.h" |
25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
26 #include "base/synchronization/lock.h" | 26 #include "base/synchronization/lock.h" |
27 #include "base/threading/thread_local.h" | 27 #include "base/threading/thread_local.h" |
28 #include "base/trace_event/memory_allocator_dump.h" | |
29 #include "base/trace_event/process_memory_dump.h" | 28 #include "base/trace_event/process_memory_dump.h" |
30 #include "base/trace_event/trace_event.h" | 29 #include "base/trace_event/trace_event.h" |
31 #include "base/values.h" | 30 #include "base/values.h" |
32 #include "crypto/ec_private_key.h" | 31 #include "crypto/ec_private_key.h" |
33 #include "crypto/openssl_util.h" | 32 #include "crypto/openssl_util.h" |
34 #include "net/base/ip_address.h" | 33 #include "net/base/ip_address.h" |
35 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
36 #include "net/base/trace_constants.h" | 35 #include "net/base/trace_constants.h" |
37 #include "net/cert/cert_verifier.h" | 36 #include "net/cert/cert_verifier.h" |
38 #include "net/cert/ct_ev_whitelist.h" | 37 #include "net/cert/ct_ev_whitelist.h" |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 } | 803 } |
805 | 804 |
806 void SSLClientSocketImpl::GetConnectionAttempts(ConnectionAttempts* out) const { | 805 void SSLClientSocketImpl::GetConnectionAttempts(ConnectionAttempts* out) const { |
807 out->clear(); | 806 out->clear(); |
808 } | 807 } |
809 | 808 |
810 int64_t SSLClientSocketImpl::GetTotalReceivedBytes() const { | 809 int64_t SSLClientSocketImpl::GetTotalReceivedBytes() const { |
811 return transport_->socket()->GetTotalReceivedBytes(); | 810 return transport_->socket()->GetTotalReceivedBytes(); |
812 } | 811 } |
813 | 812 |
814 void SSLClientSocketImpl::DumpMemoryStats( | 813 void SSLClientSocketImpl::DumpMemoryStats(SocketMemoryStats* stats) const { |
815 base::trace_event::ProcessMemoryDump* pmd, | 814 size_t serialized_cert_size = 0; |
eroman
2017/01/11 22:15:14
This change shouldn't matter since the contract is
xunjieli
2017/01/11 23:19:24
Done. Got it, thanks!
| |
816 const std::string& parent_dump_absolute_name) const { | 815 if (transport_adapter_) |
817 size_t total_size = 0; | 816 stats->buffer_size = transport_adapter_->GetAllocationSize(); |
818 base::trace_event::MemoryAllocatorDump* socket_dump = | 817 if (server_cert_chain_) { |
819 pmd->CreateAllocatorDump(base::StringPrintf( | 818 for (size_t i = 0; i < server_cert_chain_->size(); ++i) { |
820 "%s/ssl_socket_%p", parent_dump_absolute_name.c_str(), this)); | 819 X509* cert = server_cert_chain_->Get(i); |
821 if (transport_adapter_) { | 820 // This measures the lower bound of the serialized certificate. It doesn't |
822 size_t bio_buffers_size = transport_adapter_->GetAllocationSize(); | 821 // measure the actual memory used, which is 4x this amount (see |
823 socket_dump->AddScalar("buffer_size", | 822 // crbug.com/671420 for more details). |
824 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 823 serialized_cert_size += i2d_X509(cert, nullptr); |
825 bio_buffers_size); | 824 } |
826 total_size += bio_buffers_size; | 825 stats->cert_count = server_cert_chain_->size(); |
827 } | 826 } |
828 size_t total_cert_size = 0; | 827 stats->serialized_cert_size = serialized_cert_size; |
829 size_t certs_count = 0; | 828 stats->total_size = stats->buffer_size + stats->serialized_cert_size; |
830 if (server_cert_chain_) { | |
831 certs_count = server_cert_chain_->size(); | |
832 for (size_t i = 0; i < certs_count; ++i) { | |
833 X509* cert = server_cert_chain_->Get(i); | |
834 total_cert_size += i2d_X509(cert, nullptr); | |
835 } | |
836 } | |
837 total_size += total_cert_size; | |
838 // This measures the lower bound of the serialized certificate. It doesn't | |
839 // measure the actual memory used, which is 4x this amount (see | |
840 // crbug.com/671420 for more details). | |
841 socket_dump->AddScalar("serialized_cert_size", | |
842 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
843 total_cert_size); | |
844 socket_dump->AddScalar("cert_count", | |
845 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | |
846 certs_count); | |
847 socket_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
848 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
849 total_size); | |
850 } | 829 } |
851 | 830 |
852 // static | 831 // static |
853 void SSLClientSocketImpl::DumpSSLClientSessionMemoryStats( | 832 void SSLClientSocketImpl::DumpSSLClientSessionMemoryStats( |
854 base::trace_event::ProcessMemoryDump* pmd) { | 833 base::trace_event::ProcessMemoryDump* pmd) { |
855 SSLContext::GetInstance()->session_cache()->DumpMemoryStats(pmd); | 834 SSLContext::GetInstance()->session_cache()->DumpMemoryStats(pmd); |
856 } | 835 } |
857 | 836 |
858 int SSLClientSocketImpl::Read(IOBuffer* buf, | 837 int SSLClientSocketImpl::Read(IOBuffer* buf, |
859 int buf_len, | 838 int buf_len, |
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2065 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED && | 2044 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED && |
2066 !certificate_requested_) { | 2045 !certificate_requested_) { |
2067 net_error = ERR_SSL_PROTOCOL_ERROR; | 2046 net_error = ERR_SSL_PROTOCOL_ERROR; |
2068 } | 2047 } |
2069 } | 2048 } |
2070 | 2049 |
2071 return net_error; | 2050 return net_error; |
2072 } | 2051 } |
2073 | 2052 |
2074 } // namespace net | 2053 } // namespace net |
OLD | NEW |