summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_channel.cc
diff options
context:
space:
mode:
authorjschuh@chromium.org <jschuh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-17 02:20:46 +0000
committerjschuh@chromium.org <jschuh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-17 02:20:46 +0000
commit5c41e6e1cd446c3b2bc0ed17e66dffbc76f7c650 (patch)
tree81e2f1a63b2109464dde8efa38b32381e2001829 /ipc/ipc_channel.cc
parentab25e338556b9580c54b3f4025009eaaf6ac83d3 (diff)
downloadchromium_src-5c41e6e1cd446c3b2bc0ed17e66dffbc76f7c650.zip
chromium_src-5c41e6e1cd446c3b2bc0ed17e66dffbc76f7c650.tar.gz
chromium_src-5c41e6e1cd446c3b2bc0ed17e66dffbc76f7c650.tar.bz2
Verify the child process with a secret hello
BUG=117627 TEST=IPCSyncChannelTest.Verified Review URL: http://codereview.chromium.org/9692035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127327 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_channel.cc')
-rw-r--r--ipc/ipc_channel.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/ipc/ipc_channel.cc b/ipc/ipc_channel.cc
new file mode 100644
index 0000000..5973f72
--- /dev/null
+++ b/ipc/ipc_channel.cc
@@ -0,0 +1,40 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ipc/ipc_channel.h"
+
+#include <limits>
+
+#include "base/atomic_sequence_num.h"
+#include "base/process_util.h"
+#include "base/rand_util.h"
+#include "base/stringprintf.h"
+
+namespace {
+
+// Global atomic used to guarantee channel IDs are unique.
+base::StaticAtomicSequenceNumber g_last_id;
+
+} // namespace
+
+namespace IPC {
+
+// static
+std::string Channel::GenerateUniqueRandomChannelID() {
+ // Note: the string must start with the current process id, this is how
+ // some child processes determine the pid of the parent.
+ //
+ // This is composed of a unique incremental identifier, the process ID of
+ // the creator, an identifier for the child instance, and a strong random
+ // component. The strong random component prevents other processes from
+ // hijacking or squatting on predictable channel names.
+
+ return base::StringPrintf("%d.%u.%d",
+ base::GetCurrentProcId(),
+ g_last_id.GetNext(),
+ base::RandInt(0, std::numeric_limits<int32>::max()));
+}
+
+} // namespace IPC
+