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 <openssl/bio.h> | 8 #include <openssl/bio.h> |
9 #include <openssl/bytestring.h> | 9 #include <openssl/bytestring.h> |
10 #include <openssl/err.h> | 10 #include <openssl/err.h> |
11 #include <openssl/evp.h> | 11 #include <openssl/evp.h> |
12 #include <openssl/mem.h> | 12 #include <openssl/mem.h> |
13 #include <openssl/ssl.h> | 13 #include <openssl/ssl.h> |
14 #include <string.h> | 14 #include <string.h> |
15 | 15 |
16 #include <utility> | 16 #include <utility> |
17 | 17 |
18 #include "base/bind.h" | 18 #include "base/bind.h" |
19 #include "base/callback_helpers.h" | 19 #include "base/callback_helpers.h" |
20 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
21 #include "base/macros.h" | 21 #include "base/macros.h" |
22 #include "base/memory/singleton.h" | 22 #include "base/memory/singleton.h" |
23 #include "base/metrics/field_trial.h" | |
23 #include "base/metrics/histogram_macros.h" | 24 #include "base/metrics/histogram_macros.h" |
24 #include "base/metrics/sparse_histogram.h" | 25 #include "base/metrics/sparse_histogram.h" |
25 #include "base/profiler/scoped_tracker.h" | 26 #include "base/profiler/scoped_tracker.h" |
26 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
27 #include "base/strings/string_piece.h" | 28 #include "base/strings/string_piece.h" |
28 #include "base/synchronization/lock.h" | 29 #include "base/synchronization/lock.h" |
29 #include "base/threading/thread_local.h" | 30 #include "base/threading/thread_local.h" |
30 #include "base/trace_event/trace_event.h" | 31 #include "base/trace_event/trace_event.h" |
31 #include "base/values.h" | 32 #include "base/values.h" |
32 #include "crypto/auto_cbb.h" | 33 #include "crypto/auto_cbb.h" |
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
922 if (!unused.AssignFromIPLiteral(host_and_port_.host()) && | 923 if (!unused.AssignFromIPLiteral(host_and_port_.host()) && |
923 !SSL_set_tlsext_host_name(ssl_, host_and_port_.host().c_str())) { | 924 !SSL_set_tlsext_host_name(ssl_, host_and_port_.host().c_str())) { |
924 return ERR_UNEXPECTED; | 925 return ERR_UNEXPECTED; |
925 } | 926 } |
926 | 927 |
927 ScopedSSL_SESSION session = | 928 ScopedSSL_SESSION session = |
928 context->session_cache()->Lookup(GetSessionCacheKey()); | 929 context->session_cache()->Lookup(GetSessionCacheKey()); |
929 if (session) | 930 if (session) |
930 SSL_set_session(ssl_, session.get()); | 931 SSL_set_session(ssl_, session.get()); |
931 | 932 |
933 // Get read and write buffer sizes from field trials, if possible. If values | |
934 // not present, use default. Also make sure values are in reasonable range. | |
935 int send_buffer_size; | |
936 if (!base::StringToInt( | |
937 base::FieldTrialList::FindFullName("SSLBufferSizeSend"), | |
938 &send_buffer_size)) { | |
939 send_buffer_size = KDefaultOpenSSLBufferSize; | |
davidben
2016/06/27 18:31:48
(Haha. While you're here, do you mind fixing KDefa
mmenke
2016/06/27 20:01:06
I completely missed that! Done.
| |
940 } | |
941 send_buffer_size = std::max(send_buffer_size, 1000); | |
942 send_buffer_size = std::min(send_buffer_size, 2 * KDefaultOpenSSLBufferSize); | |
932 send_buffer_ = new GrowableIOBuffer(); | 943 send_buffer_ = new GrowableIOBuffer(); |
933 send_buffer_->SetCapacity(KDefaultOpenSSLBufferSize); | 944 send_buffer_->SetCapacity(send_buffer_size); |
945 | |
946 int recv_buffer_size; | |
947 if (!base::StringToInt( | |
948 base::FieldTrialList::FindFullName("SSLBufferSizeRecv"), | |
949 &recv_buffer_size)) { | |
950 recv_buffer_size = KDefaultOpenSSLBufferSize; | |
951 } | |
952 recv_buffer_size = std::max(recv_buffer_size, 1000); | |
953 recv_buffer_size = std::min(recv_buffer_size, 2 * KDefaultOpenSSLBufferSize); | |
934 recv_buffer_ = new GrowableIOBuffer(); | 954 recv_buffer_ = new GrowableIOBuffer(); |
935 recv_buffer_->SetCapacity(KDefaultOpenSSLBufferSize); | 955 recv_buffer_->SetCapacity(recv_buffer_size); |
936 | 956 |
937 BIO* ssl_bio = NULL; | 957 BIO* ssl_bio = NULL; |
938 | 958 |
939 // SSLClientSocketImpl retains ownership of the BIO buffers. | 959 // SSLClientSocketImpl retains ownership of the BIO buffers. |
940 if (!BIO_new_bio_pair_external_buf( | 960 if (!BIO_new_bio_pair_external_buf( |
941 &ssl_bio, send_buffer_->capacity(), | 961 &ssl_bio, send_buffer_->capacity(), |
942 reinterpret_cast<uint8_t*>(send_buffer_->data()), &transport_bio_, | 962 reinterpret_cast<uint8_t*>(send_buffer_->data()), &transport_bio_, |
943 recv_buffer_->capacity(), | 963 recv_buffer_->capacity(), |
944 reinterpret_cast<uint8_t*>(recv_buffer_->data()))) | 964 reinterpret_cast<uint8_t*>(recv_buffer_->data()))) |
945 return ERR_UNEXPECTED; | 965 return ERR_UNEXPECTED; |
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2336 if (rv != OK) { | 2356 if (rv != OK) { |
2337 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 2357 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
2338 return; | 2358 return; |
2339 } | 2359 } |
2340 | 2360 |
2341 net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT, | 2361 net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT, |
2342 base::Bind(&NetLogSSLInfoCallback, base::Unretained(this))); | 2362 base::Bind(&NetLogSSLInfoCallback, base::Unretained(this))); |
2343 } | 2363 } |
2344 | 2364 |
2345 } // namespace net | 2365 } // namespace net |
OLD | NEW |