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_host_channel_authenticator.h" | 5 #include "remoting/protocol/v1_host_channel_authenticator.h" |
6 | 6 |
7 #include "crypto/rsa_private_key.h" | 7 #include "crypto/rsa_private_key.h" |
8 #include "crypto/secure_util.h" | 8 #include "crypto/secure_util.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/base/x509_certificate.h" | 12 #include "net/base/x509_certificate.h" |
13 #include "net/socket/ssl_server_socket.h" | 13 #include "net/socket/ssl_server_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 V1HostChannelAuthenticator::V1HostChannelAuthenticator( | 19 V1HostChannelAuthenticator::V1HostChannelAuthenticator( |
20 const std::string& local_cert, | 20 const std::string& local_cert, |
21 crypto::RSAPrivateKey* local_private_key, | 21 crypto::RSAPrivateKey* local_private_key, |
22 const std::string& shared_secret) | 22 const std::string& shared_secret) |
23 : local_cert_(local_cert), | 23 : local_cert_(local_cert), |
24 local_private_key_(local_private_key), | 24 local_private_key_(local_private_key), |
25 shared_secret_(shared_secret), | 25 shared_secret_(shared_secret), |
26 socket_(NULL), | 26 socket_(NULL), |
27 ALLOW_THIS_IN_INITIALIZER_LIST(connect_callback_( | 27 ALLOW_THIS_IN_INITIALIZER_LIST(connect_callback_( |
28 this, &V1HostChannelAuthenticator::OnConnected)), | 28 this, &V1HostChannelAuthenticator::OnConnected)) { |
29 ALLOW_THIS_IN_INITIALIZER_LIST(auth_read_callback_( | |
30 this, &V1HostChannelAuthenticator::OnAuthBytesRead)) { | |
31 } | 29 } |
32 | 30 |
33 V1HostChannelAuthenticator::~V1HostChannelAuthenticator() { | 31 V1HostChannelAuthenticator::~V1HostChannelAuthenticator() { |
34 } | 32 } |
35 | 33 |
36 void V1HostChannelAuthenticator::SecureAndAuthenticate( | 34 void V1HostChannelAuthenticator::SecureAndAuthenticate( |
37 net::StreamSocket* socket, const DoneCallback& done_callback) { | 35 net::StreamSocket* socket, const DoneCallback& done_callback) { |
38 DCHECK(CalledOnValidThread()); | 36 DCHECK(CalledOnValidThread()); |
39 | 37 |
40 scoped_ptr<net::StreamSocket> channel_socket(socket); | 38 scoped_ptr<net::StreamSocket> channel_socket(socket); |
(...skipping 26 matching lines...) Expand all Loading... |
67 } | 65 } |
68 | 66 |
69 // Read an authentication digest. | 67 // Read an authentication digest. |
70 auth_read_buf_ = new net::GrowableIOBuffer(); | 68 auth_read_buf_ = new net::GrowableIOBuffer(); |
71 auth_read_buf_->SetCapacity(kAuthDigestLength); | 69 auth_read_buf_->SetCapacity(kAuthDigestLength); |
72 DoAuthRead(); | 70 DoAuthRead(); |
73 } | 71 } |
74 | 72 |
75 void V1HostChannelAuthenticator::DoAuthRead(){ | 73 void V1HostChannelAuthenticator::DoAuthRead(){ |
76 while (true) { | 74 while (true) { |
77 int result = socket_->Read(auth_read_buf_, | 75 int result = socket_->Read( |
78 auth_read_buf_->RemainingCapacity(), | 76 auth_read_buf_, |
79 &auth_read_callback_); | 77 auth_read_buf_->RemainingCapacity(), |
| 78 base::Bind(&V1HostChannelAuthenticator::OnAuthBytesRead, |
| 79 base::Unretained(this))); |
80 if (result == net::ERR_IO_PENDING) | 80 if (result == net::ERR_IO_PENDING) |
81 break; | 81 break; |
82 if (!HandleAuthBytesRead(result)) | 82 if (!HandleAuthBytesRead(result)) |
83 break; | 83 break; |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 void V1HostChannelAuthenticator::OnAuthBytesRead(int result) { | 87 void V1HostChannelAuthenticator::OnAuthBytesRead(int result) { |
88 DCHECK(CalledOnValidThread()); | 88 DCHECK(CalledOnValidThread()); |
89 | 89 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 done_callback_.Run(net::ERR_FAILED, NULL); | 133 done_callback_.Run(net::ERR_FAILED, NULL); |
134 return false; | 134 return false; |
135 } | 135 } |
136 | 136 |
137 return crypto::SecureMemEqual(received_auth_bytes.data(), | 137 return crypto::SecureMemEqual(received_auth_bytes.data(), |
138 &(auth_bytes[0]), kAuthDigestLength); | 138 &(auth_bytes[0]), kAuthDigestLength); |
139 } | 139 } |
140 | 140 |
141 } // namespace protocol | 141 } // namespace protocol |
142 } // namespace remoting | 142 } // namespace remoting |
OLD | NEW |