OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "blimp/net/ssl_client_transport.h" | |
6 | |
7 #include "base/callback.h" | |
8 #include "base/callback_helpers.h" | |
9 #include "blimp/net/exact_match_cert_verifier.h" | |
10 #include "blimp/net/stream_socket_connection.h" | |
11 #include "net/base/host_port_pair.h" | |
12 #include "net/cert/x509_certificate.h" | |
13 #include "net/socket/client_socket_factory.h" | |
14 #include "net/socket/client_socket_handle.h" | |
15 #include "net/socket/ssl_client_socket.h" | |
16 #include "net/socket/stream_socket.h" | |
17 #include "net/socket/tcp_client_socket.h" | |
18 #include "net/ssl/ssl_config.h" | |
19 | |
20 namespace blimp { | |
21 | |
22 SSLClientTransport::SSLClientTransport(const net::IPEndPoint& ip_endpoint, | |
23 scoped_refptr<net::X509Certificate> cert, | |
24 net::NetLog* net_log) | |
25 : TCPClientTransport(ip_endpoint, net_log), | |
26 ip_endpoint_(ip_endpoint), | |
27 cert_verifier_(std::move(cert)) {} | |
28 | |
29 SSLClientTransport::~SSLClientTransport() {} | |
30 | |
31 const std::string SSLClientTransport::GetName() const { | |
Ryan Sleevi
2016/02/23 21:01:32
random API nit:
1) Any reason this is returning st
Kevin M
2016/02/24 00:31:42
No reason, returning a const char* is fine. (Done;
| |
32 return "SSL"; | |
33 } | |
34 | |
35 void SSLClientTransport::OnTCPConnectComplete(int result) { | |
36 DCHECK_NE(net::ERR_IO_PENDING, result); | |
37 | |
38 scoped_ptr<net::StreamSocket> tcp_socket = TCPClientTransport::TakeSocket(); | |
Ryan Sleevi
2016/02/23 21:01:32
Acknowledged that you're going to investigate re-d
Kevin M
2016/02/24 00:31:42
Acknowledged.
| |
39 | |
40 DVLOG(1) << "TCP connection result=" << result; | |
41 if (result != net::OK) { | |
42 OnConnectComplete(result); | |
43 return; | |
44 } | |
45 | |
46 // Construct arguments to use for the SSL socket factory. | |
47 scoped_ptr<net::ClientSocketHandle> socket_handle( | |
48 new net::ClientSocketHandle); | |
49 socket_handle->SetSocket(std::move(tcp_socket)); | |
50 | |
51 net::HostPortPair host_port_pair = | |
52 net::HostPortPair::FromIPEndPoint(ip_endpoint_); | |
53 | |
54 net::SSLClientSocketContext create_context; | |
55 create_context.cert_verifier = &cert_verifier_; | |
56 create_context.transport_security_state = &transport_security_state_; | |
57 | |
58 scoped_ptr<net::StreamSocket> ssl_socket( | |
59 socket_factory()->CreateSSLClientSocket(std::move(socket_handle), | |
60 host_port_pair, net::SSLConfig(), | |
61 create_context)); | |
62 | |
63 if (!ssl_socket) { | |
64 OnConnectComplete(net::ERR_SSL_PROTOCOL_ERROR); | |
65 return; | |
66 } | |
67 | |
68 result = ssl_socket->Connect(base::Bind( | |
69 &SSLClientTransport::OnSSLConnectComplete, base::Unretained(this))); | |
70 SetSocket(std::move(ssl_socket)); | |
71 | |
72 if (result == net::ERR_IO_PENDING) { | |
73 // SSL connection will complete asynchronously. | |
74 return; | |
75 } | |
76 | |
77 OnSSLConnectComplete(result); | |
78 } | |
79 | |
80 void SSLClientTransport::OnSSLConnectComplete(int result) { | |
81 DCHECK_NE(net::ERR_IO_PENDING, result); | |
82 DVLOG(1) << "SSL connection result=" << result; | |
83 | |
84 OnConnectComplete(result); | |
85 } | |
86 | |
87 } // namespace blimp | |
OLD | NEW |