OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "remoting/protocol/v1_client_channel_authenticator.h" | 5 #include "remoting/protocol/v1_client_channel_authenticator.h" |
6 | 6 |
7 #include "net/base/cert_verifier.h" | 7 #include "net/base/cert_verifier.h" |
8 #include "net/base/host_port_pair.h" | 8 #include "net/base/host_port_pair.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 #include "net/base/ssl_config_service.h" | 11 #include "net/base/ssl_config_service.h" |
12 #include "net/socket/client_socket_factory.h" | 12 #include "net/socket/client_socket_factory.h" |
13 #include "net/socket/ssl_client_socket.h" | 13 #include "net/socket/ssl_client_socket.h" |
14 #include "remoting/protocol/auth_util.h" | 14 #include "remoting/protocol/auth_util.h" |
15 | 15 |
16 namespace remoting { | 16 namespace remoting { |
17 namespace protocol { | 17 namespace protocol { |
18 | 18 |
19 V1ClientChannelAuthenticator::V1ClientChannelAuthenticator( | 19 V1ClientChannelAuthenticator::V1ClientChannelAuthenticator( |
20 const std::string& host_cert, | 20 const std::string& host_cert, |
21 const std::string& shared_secret) | 21 const std::string& shared_secret) |
22 : host_cert_(host_cert), | 22 : host_cert_(host_cert), |
23 shared_secret_(shared_secret), | 23 shared_secret_(shared_secret), |
24 socket_(NULL), | 24 socket_(NULL) { |
25 ALLOW_THIS_IN_INITIALIZER_LIST(connect_callback_( | |
26 this, &V1ClientChannelAuthenticator::OnConnected)), | |
27 ALLOW_THIS_IN_INITIALIZER_LIST(auth_write_callback_( | |
28 this, &V1ClientChannelAuthenticator::OnAuthBytesWritten)) { | |
29 } | 25 } |
30 | 26 |
31 V1ClientChannelAuthenticator::~V1ClientChannelAuthenticator() { | 27 V1ClientChannelAuthenticator::~V1ClientChannelAuthenticator() { |
32 } | 28 } |
33 | 29 |
34 void V1ClientChannelAuthenticator::SecureAndAuthenticate( | 30 void V1ClientChannelAuthenticator::SecureAndAuthenticate( |
35 net::StreamSocket* socket, const DoneCallback& done_callback) { | 31 net::StreamSocket* socket, const DoneCallback& done_callback) { |
36 DCHECK(CalledOnValidThread()); | 32 DCHECK(CalledOnValidThread()); |
37 DCHECK(socket->IsConnected()); | 33 DCHECK(socket->IsConnected()); |
38 | 34 |
(...skipping 13 matching lines...) Expand all Loading... |
52 ssl_config.allowed_bad_certs.push_back(cert_and_status); | 48 ssl_config.allowed_bad_certs.push_back(cert_and_status); |
53 ssl_config.rev_checking_enabled = false; | 49 ssl_config.rev_checking_enabled = false; |
54 | 50 |
55 net::HostPortPair host_and_port(kSslFakeHostName, 0); | 51 net::HostPortPair host_and_port(kSslFakeHostName, 0); |
56 net::SSLClientSocketContext context; | 52 net::SSLClientSocketContext context; |
57 context.cert_verifier = cert_verifier_.get(); | 53 context.cert_verifier = cert_verifier_.get(); |
58 socket_.reset( | 54 socket_.reset( |
59 net::ClientSocketFactory::GetDefaultFactory()->CreateSSLClientSocket( | 55 net::ClientSocketFactory::GetDefaultFactory()->CreateSSLClientSocket( |
60 socket, host_and_port, ssl_config, NULL, context)); | 56 socket, host_and_port, ssl_config, NULL, context)); |
61 | 57 |
62 int result = socket_->Connect(&connect_callback_); | 58 int result = socket_->Connect( |
| 59 base::Bind(&V1ClientChannelAuthenticator::OnConnected, |
| 60 base::Unretained(this))); |
63 if (result == net::ERR_IO_PENDING) | 61 if (result == net::ERR_IO_PENDING) |
64 return; | 62 return; |
65 OnConnected(result); | 63 OnConnected(result); |
66 } | 64 } |
67 | 65 |
68 void V1ClientChannelAuthenticator::OnConnected(int result) { | 66 void V1ClientChannelAuthenticator::OnConnected(int result) { |
69 if (result != net::OK) { | 67 if (result != net::OK) { |
70 LOG(ERROR) << "Failed to establish SSL connection"; | 68 LOG(ERROR) << "Failed to establish SSL connection"; |
71 done_callback_.Run(static_cast<net::Error>(result), NULL); | 69 done_callback_.Run(static_cast<net::Error>(result), NULL); |
72 } | 70 } |
(...skipping 19 matching lines...) Expand all Loading... |
92 } | 90 } |
93 | 91 |
94 // Allocate a buffer to write the digest. | 92 // Allocate a buffer to write the digest. |
95 auth_write_buf_ = new net::DrainableIOBuffer( | 93 auth_write_buf_ = new net::DrainableIOBuffer( |
96 new net::StringIOBuffer(auth_bytes), auth_bytes.size()); | 94 new net::StringIOBuffer(auth_bytes), auth_bytes.size()); |
97 WriteAuthenticationBytes(); | 95 WriteAuthenticationBytes(); |
98 } | 96 } |
99 | 97 |
100 void V1ClientChannelAuthenticator::WriteAuthenticationBytes() { | 98 void V1ClientChannelAuthenticator::WriteAuthenticationBytes() { |
101 while (true) { | 99 while (true) { |
102 int result = socket_->Write(auth_write_buf_, | 100 int result = socket_->Write( |
103 auth_write_buf_->BytesRemaining(), | 101 auth_write_buf_, auth_write_buf_->BytesRemaining(), |
104 &auth_write_callback_); | 102 base::Bind(&V1ClientChannelAuthenticator::OnAuthBytesWritten, |
| 103 base::Unretained(this))); |
105 if (result == net::ERR_IO_PENDING) | 104 if (result == net::ERR_IO_PENDING) |
106 break; | 105 break; |
107 if (!HandleAuthBytesWritten(result)) | 106 if (!HandleAuthBytesWritten(result)) |
108 break; | 107 break; |
109 } | 108 } |
110 } | 109 } |
111 | 110 |
112 void V1ClientChannelAuthenticator::OnAuthBytesWritten(int result) { | 111 void V1ClientChannelAuthenticator::OnAuthBytesWritten(int result) { |
113 DCHECK(CalledOnValidThread()); | 112 DCHECK(CalledOnValidThread()); |
114 | 113 |
(...skipping 11 matching lines...) Expand all Loading... |
126 auth_write_buf_->DidConsume(result); | 125 auth_write_buf_->DidConsume(result); |
127 if (auth_write_buf_->BytesRemaining() > 0) | 126 if (auth_write_buf_->BytesRemaining() > 0) |
128 return true; | 127 return true; |
129 | 128 |
130 done_callback_.Run(net::OK, socket_.release()); | 129 done_callback_.Run(net::OK, socket_.release()); |
131 return false; | 130 return false; |
132 } | 131 } |
133 | 132 |
134 } // namespace protocol | 133 } // namespace protocol |
135 } // namespace remoting | 134 } // namespace remoting |
OLD | NEW |