Index: remoting/host/security_key/remote_security_key_ipc_server_impl.cc |
diff --git a/remoting/host/security_key/remote_security_key_ipc_server_impl.cc b/remoting/host/security_key/remote_security_key_ipc_server_impl.cc |
index a2d75f005bb0ae1de62979787dd616908e04827d..0c0f7d1904a754fc0d4b1886a0d252c2e3fc430f 100644 |
--- a/remoting/host/security_key/remote_security_key_ipc_server_impl.cc |
+++ b/remoting/host/security_key/remote_security_key_ipc_server_impl.cc |
@@ -4,12 +4,15 @@ |
#include "remoting/host/security_key/remote_security_key_ipc_server_impl.h" |
+#include <cstdint> |
#include <memory> |
#include <string> |
#include "base/callback.h" |
#include "base/callback_helpers.h" |
+#include "base/location.h" |
#include "base/threading/thread_checker.h" |
+#include "base/threading/thread_task_runner_handle.h" |
#include "base/timer/timer.h" |
#include "ipc/ipc_channel.h" |
#include "ipc/ipc_message.h" |
@@ -38,13 +41,16 @@ namespace remoting { |
RemoteSecurityKeyIpcServerImpl::RemoteSecurityKeyIpcServerImpl( |
int connection_id, |
+ uint32_t peer_session_id, |
base::TimeDelta initial_connect_timeout, |
const GnubbyAuthHandler::SendMessageCallback& message_callback, |
const base::Closure& done_callback) |
: connection_id_(connection_id), |
+ peer_session_id_(peer_session_id), |
initial_connect_timeout_(initial_connect_timeout), |
done_callback_(done_callback), |
- message_callback_(message_callback) { |
+ message_callback_(message_callback), |
+ weak_factory_(this) { |
DCHECK_GT(connection_id_, 0); |
DCHECK(!done_callback_.is_null()); |
DCHECK(!message_callback_.is_null()); |
@@ -128,6 +134,27 @@ bool RemoteSecurityKeyIpcServerImpl::OnMessageReceived( |
void RemoteSecurityKeyIpcServerImpl::OnChannelConnected(int32_t peer_pid) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
+ |
+#if defined(OS_WIN) |
+ DWORD peer_session_id; |
+ if (!ProcessIdToSessionId(peer_pid, &peer_session_id)) { |
+ PLOG(ERROR) << "ProcessIdToSessionId() failed"; |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, base::Bind(&RemoteSecurityKeyIpcServerImpl::OnChannelError, |
+ weak_factory_.GetWeakPtr())); |
+ return; |
+ } |
+ if (peer_session_id != peer_session_id_) { |
+ LOG(ERROR) << "Ignoring connection attempt from outside remoted session."; |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
Sergey Ulanov
2016/06/29 22:36:46
This duplicates the PostTask() call above. Structu
Sergey Ulanov
2016/06/29 22:36:46
Should we also close the channel here? Otherwise t
joedow
2016/06/30 00:10:08
I think that is a good idea, I'll add a member boo
joedow
2016/06/30 00:10:08
Done.
|
+ FROM_HERE, base::Bind(&RemoteSecurityKeyIpcServerImpl::OnChannelError, |
+ weak_factory_.GetWeakPtr())); |
+ return; |
+ } |
+#else // !defined(OS_WIN) |
+ CHECK_EQ(peer_session_id_, UINT32_MAX); |
+#endif // !defined(OS_WIN) |
+ |
// Reset the timer to give the client a chance to send the request. |
timer_.Start(FROM_HERE, initial_connect_timeout_, |
base::Bind(&RemoteSecurityKeyIpcServerImpl::OnChannelError, |
@@ -136,6 +163,9 @@ void RemoteSecurityKeyIpcServerImpl::OnChannelConnected(int32_t peer_pid) { |
void RemoteSecurityKeyIpcServerImpl::OnChannelError() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
+ if (ipc_channel_) { |
+ ipc_channel_->Close(); |
+ } |
if (!done_callback_.is_null()) { |
// Note: This callback may result in this object being torn down. |