Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: mojo/edk/system/node_channel.cc

Issue 1685183004: Bootstrap Mojo IPC independent of Chrome IPC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: and fix posix Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 "mojo/edk/system/node_channel.h" 5 #include "mojo/edk/system/node_channel.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 #include <limits> 8 #include <limits>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 187 }
188 #endif 188 #endif
189 return ScopedPlatformHandle(); 189 return ScopedPlatformHandle();
190 } 190 }
191 191
192 void NodeChannel::SetRemoteNodeName(const ports::NodeName& name) { 192 void NodeChannel::SetRemoteNodeName(const ports::NodeName& name) {
193 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 193 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
194 remote_node_name_ = name; 194 remote_node_name_ = name;
195 } 195 }
196 196
197 void NodeChannel::SetExpectedSecret(const std::string& secret) {
198 #if !defined(OS_WIN)
199 // Ensure we aren't expecting a secret on non-Windows.
200 CHECK(secret.empty());
201 #endif
202 expected_secret_ = secret;
203 }
204
205 void NodeChannel::SendSecret(const std::string& secret) {
206 Channel::MessagePtr message(new Channel::Message(secret.size(), 0));
207 memcpy(message->mutable_payload(), secret.data(), secret.size());
208 WriteChannelMessage(std::move(message));
209 }
210
197 void NodeChannel::AcceptChild(const ports::NodeName& parent_name, 211 void NodeChannel::AcceptChild(const ports::NodeName& parent_name,
198 const ports::NodeName& token) { 212 const ports::NodeName& token) {
199 AcceptChildData* data; 213 AcceptChildData* data;
200 Channel::MessagePtr message = CreateMessage( 214 Channel::MessagePtr message = CreateMessage(
201 MessageType::ACCEPT_CHILD, sizeof(AcceptChildData), 0, &data); 215 MessageType::ACCEPT_CHILD, sizeof(AcceptChildData), 0, &data);
202 data->parent_name = parent_name; 216 data->parent_name = parent_name;
203 data->token = token; 217 data->token = token;
204 WriteChannelMessage(std::move(message)); 218 WriteChannelMessage(std::move(message));
205 } 219 }
206 220
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 344
331 NodeChannel::~NodeChannel() { 345 NodeChannel::~NodeChannel() {
332 ShutDown(); 346 ShutDown();
333 } 347 }
334 348
335 void NodeChannel::OnChannelMessage(const void* payload, 349 void NodeChannel::OnChannelMessage(const void* payload,
336 size_t payload_size, 350 size_t payload_size,
337 ScopedPlatformHandleVectorPtr handles) { 351 ScopedPlatformHandleVectorPtr handles) {
338 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 352 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
339 353
354 if (!expected_secret_.empty()) {
355 // If we're expecting a secret string, that takes precedence over everything
356 // else.
357 if (std::string(static_cast<const char*>(payload), payload_size) !=
358 expected_secret_) {
359 LOG(ERROR) << "Received invalid secret from peer. Dropping channel.";
360 delegate_->OnChannelError(remote_node_name_);
361 }
362 expected_secret_.clear();
363 return;
364 }
365
340 #if defined(OS_WIN) 366 #if defined(OS_WIN)
341 // If we receive handles from a known process, rewrite them to our own 367 // If we receive handles from a known process, rewrite them to our own
342 // process. This can occur when a privileged node receives handles directly 368 // process. This can occur when a privileged node receives handles directly
343 // from a privileged descendant. 369 // from a privileged descendant.
344 { 370 {
345 base::AutoLock lock(remote_process_handle_lock_); 371 base::AutoLock lock(remote_process_handle_lock_);
346 if (handles && remote_process_handle_ != base::kNullProcessHandle) { 372 if (handles && remote_process_handle_ != base::kNullProcessHandle) {
347 if (!Channel::Message::RewriteHandles(remote_process_handle_, 373 if (!Channel::Message::RewriteHandles(remote_process_handle_,
348 base::GetCurrentProcessHandle(), 374 base::GetCurrentProcessHandle(),
349 handles->data(), handles->size())) { 375 handles->data(), handles->size())) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 568
543 base::AutoLock lock(channel_lock_); 569 base::AutoLock lock(channel_lock_);
544 if (!channel_) 570 if (!channel_)
545 DLOG(ERROR) << "Dropping message on closed channel."; 571 DLOG(ERROR) << "Dropping message on closed channel.";
546 else 572 else
547 channel_->Write(std::move(message)); 573 channel_->Write(std::move(message));
548 } 574 }
549 575
550 } // namespace edk 576 } // namespace edk
551 } // namespace mojo 577 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698