Commit f7f7c2e1 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Mojo: Delete GenerateRandomToken()

There's no reason for Mojo to provide this API.

Bug: 844763
Change-Id: I32e9e92f82e55564273961f3f59dd15677125e81
Reviewed-on: https://chromium-review.googlesource.com/1086035Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Reviewed-by: default avatarRicky Liang <jcliang@chromium.org>
Reviewed-by: default avatarJay Civelli <jcivelli@chromium.org>
Commit-Queue: Ken Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565088}
parent 1da06444
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "components/arc/arc_bridge_host_impl.h" #include "components/arc/arc_bridge_host_impl.h"
#include "components/arc/arc_features.h" #include "components/arc/arc_features.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/platform_channel_utils_posix.h" #include "mojo/edk/embedder/platform_channel_utils_posix.h"
#include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
...@@ -49,6 +48,12 @@ chromeos::SessionManagerClient* GetSessionManagerClient() { ...@@ -49,6 +48,12 @@ chromeos::SessionManagerClient* GetSessionManagerClient() {
return chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); return chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
} }
std::string GenerateRandomToken() {
char random_bytes[16];
base::RandBytes(random_bytes, 16);
return base::HexEncode(random_bytes, 16);
}
// Creates a pipe. Returns true on success, otherwise false. // Creates a pipe. Returns true on success, otherwise false.
// On success, |read_fd| will be set to the fd of the read side, and // On success, |read_fd| will be set to the fd of the read side, and
// |write_fd| will be set to the one of write side. // |write_fd| will be set to the one of write side.
...@@ -182,7 +187,7 @@ mojo::ScopedMessagePipeHandle ArcSessionDelegateImpl::ConnectMojoInternal( ...@@ -182,7 +187,7 @@ mojo::ScopedMessagePipeHandle ArcSessionDelegateImpl::ConnectMojoInternal(
mojo::OutgoingInvitation invitation; mojo::OutgoingInvitation invitation;
// Generate an arbitrary 32-byte string. ARC uses this length as a protocol // Generate an arbitrary 32-byte string. ARC uses this length as a protocol
// version identifier. // version identifier.
std::string token = mojo::edk::GenerateRandomToken(); std::string token = GenerateRandomToken();
mojo::ScopedMessagePipeHandle pipe = invitation.AttachMessagePipe(token); mojo::ScopedMessagePipeHandle pipe = invitation.AttachMessagePipe(token);
mojo::OutgoingInvitation::Send(std::move(invitation), mojo::OutgoingInvitation::Send(std::move(invitation),
base::kNullProcessHandle, base::kNullProcessHandle,
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/platform_channel_utils_posix.h" #include "mojo/edk/embedder/platform_channel_utils_posix.h"
#include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/platform/named_platform_channel.h" #include "mojo/public/cpp/platform/named_platform_channel.h"
...@@ -33,6 +32,12 @@ const base::FilePath::CharType kArcCamera3SocketPath[] = ...@@ -33,6 +32,12 @@ const base::FilePath::CharType kArcCamera3SocketPath[] =
"/var/run/camera/camera3.sock"; "/var/run/camera/camera3.sock";
const char kArcCameraGroup[] = "arc-camera"; const char kArcCameraGroup[] = "arc-camera";
std::string GenerateRandomToken() {
char random_bytes[16];
base::RandBytes(random_bytes, 16);
return base::HexEncode(random_bytes, 16);
}
// Creates a pipe. Returns true on success, otherwise false. // Creates a pipe. Returns true on success, otherwise false.
// On success, |read_fd| will be set to the fd of the read side, and // On success, |read_fd| will be set to the fd of the read side, and
// |write_fd| will be set to the one of write side. // |write_fd| will be set to the one of write side.
...@@ -293,7 +298,7 @@ void CameraHalDispatcherImpl::StartServiceLoop(base::ScopedFD socket_fd, ...@@ -293,7 +298,7 @@ void CameraHalDispatcherImpl::StartServiceLoop(base::ScopedFD socket_fd,
// Generate an arbitrary 32-byte string, as we use this length as a // Generate an arbitrary 32-byte string, as we use this length as a
// protocol version identifier. // protocol version identifier.
std::string token = mojo::edk::GenerateRandomToken(); std::string token = GenerateRandomToken();
mojo::ScopedMessagePipeHandle pipe = invitation.AttachMessagePipe(token); mojo::ScopedMessagePipeHandle pipe = invitation.AttachMessagePipe(token);
mojo::OutgoingInvitation::Send(std::move(invitation), mojo::OutgoingInvitation::Send(std::move(invitation),
kUnusedChildProcessHandle, kUnusedChildProcessHandle,
......
...@@ -22,11 +22,6 @@ component("edk") { ...@@ -22,11 +22,6 @@ component("edk") {
defines = [ "MOJO_SYSTEM_IMPL_IMPLEMENTATION" ] defines = [ "MOJO_SYSTEM_IMPL_IMPLEMENTATION" ]
deps = []
if (!is_nacl) {
deps += [ "//crypto" ]
}
public_deps = [ public_deps = [
":impl_for_edk", ":impl_for_edk",
"//mojo/public/cpp/platform", "//mojo/public/cpp/platform",
......
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/task_runner.h" #include "base/task_runner.h"
#include "mojo/edk/embedder/entrypoints.h" #include "mojo/edk/embedder/entrypoints.h"
#include "mojo/edk/system/configuration.h" #include "mojo/edk/system/configuration.h"
...@@ -19,10 +17,6 @@ ...@@ -19,10 +17,6 @@
#include "mojo/edk/system/node_controller.h" #include "mojo/edk/system/node_controller.h"
#include "mojo/public/c/system/thunks.h" #include "mojo/public/c/system/thunks.h"
#if !defined(OS_NACL)
#include "crypto/random.h"
#endif
namespace mojo { namespace mojo {
namespace edk { namespace edk {
...@@ -40,17 +34,6 @@ void SetDefaultProcessErrorCallback(const ProcessErrorCallback& callback) { ...@@ -40,17 +34,6 @@ void SetDefaultProcessErrorCallback(const ProcessErrorCallback& callback) {
Core::Get()->SetDefaultProcessErrorCallback(callback); Core::Get()->SetDefaultProcessErrorCallback(callback);
} }
std::string GenerateRandomToken() {
char random_bytes[16];
#if defined(OS_NACL)
// Not secure. For NaCl only!
base::RandBytes(random_bytes, 16);
#else
crypto::RandBytes(random_bytes, 16);
#endif
return base::HexEncode(random_bytes, 16);
}
MojoResult CreateInternalPlatformHandleWrapper( MojoResult CreateInternalPlatformHandleWrapper(
ScopedInternalPlatformHandle platform_handle, ScopedInternalPlatformHandle platform_handle,
MojoHandle* platform_handle_wrapper_handle) { MojoHandle* platform_handle_wrapper_handle) {
......
...@@ -44,10 +44,6 @@ MOJO_SYSTEM_IMPL_EXPORT void Init(); ...@@ -44,10 +44,6 @@ MOJO_SYSTEM_IMPL_EXPORT void Init();
MOJO_SYSTEM_IMPL_EXPORT void SetDefaultProcessErrorCallback( MOJO_SYSTEM_IMPL_EXPORT void SetDefaultProcessErrorCallback(
const ProcessErrorCallback& callback); const ProcessErrorCallback& callback);
// Generates a random ASCII token string for use with various APIs that expect
// a globally unique token string. May be called at any time on any thread.
MOJO_SYSTEM_IMPL_EXPORT std::string GenerateRandomToken();
// Basic functions ------------------------------------------------------------- // Basic functions -------------------------------------------------------------
// //
// The functions in this section are available once |Init()| has been called and // The functions in this section are available once |Init()| has been called and
......
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
#include "base/memory/writable_shared_memory_region.h" #include "base/memory/writable_shared_memory_region.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/rand_util.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/test/test_timeouts.h" #include "base/test/test_timeouts.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -446,13 +448,13 @@ DEFINE_TEST_CLIENT_TEST_WITH_PIPE(MultiprocessMixMachAndFdsClient, ...@@ -446,13 +448,13 @@ DEFINE_TEST_CLIENT_TEST_WITH_PIPE(MultiprocessMixMachAndFdsClient,
// TODO(fuchsia): Implement NamedPlatformHandles (crbug.com/754038). // TODO(fuchsia): Implement NamedPlatformHandles (crbug.com/754038).
NamedPlatformHandle GenerateChannelName() { NamedPlatformHandle GenerateChannelName() {
std::string token = base::NumberToString(base::RandUint64());
#if defined(OS_POSIX) #if defined(OS_POSIX)
base::FilePath temp_dir; base::FilePath temp_dir;
CHECK(base::PathService::Get(base::DIR_TEMP, &temp_dir)); CHECK(base::PathService::Get(base::DIR_TEMP, &temp_dir));
return NamedPlatformHandle( return NamedPlatformHandle(temp_dir.AppendASCII(token).value());
temp_dir.AppendASCII(GenerateRandomToken()).value());
#else #else
return NamedPlatformHandle(GenerateRandomToken()); return NamedPlatformHandle(token);
#endif #endif
} }
...@@ -463,7 +465,7 @@ void CreateClientHandleOnIoThread(const NamedPlatformHandle& named_handle, ...@@ -463,7 +465,7 @@ void CreateClientHandleOnIoThread(const NamedPlatformHandle& named_handle,
TEST_F(EmbedderTest, ClosePendingPeerConnection) { TEST_F(EmbedderTest, ClosePendingPeerConnection) {
NamedPlatformHandle named_handle = GenerateChannelName(); NamedPlatformHandle named_handle = GenerateChannelName();
std::string peer_token = GenerateRandomToken(); std::string peer_token = base::NumberToString(base::RandUint64());
auto peer_connection = std::make_unique<PeerConnection>(); auto peer_connection = std::make_unique<PeerConnection>();
ScopedMessagePipeHandle server_pipe = ScopedMessagePipeHandle server_pipe =
......
...@@ -148,7 +148,8 @@ ScopedMessagePipeHandle MultiprocessTestHelper::StartChildWithExtraSwitch( ...@@ -148,7 +148,8 @@ ScopedMessagePipeHandle MultiprocessTestHelper::StartChildWithExtraSwitch(
#elif defined(OS_POSIX) #elif defined(OS_POSIX)
base::FilePath temp_dir; base::FilePath temp_dir;
CHECK(base::PathService::Get(base::DIR_TEMP, &temp_dir)); CHECK(base::PathService::Get(base::DIR_TEMP, &temp_dir));
server_name = temp_dir.AppendASCII(GenerateRandomToken()).value(); server_name =
temp_dir.AppendASCII(base::NumberToString(base::RandUint64())).value();
#elif defined(OS_WIN) #elif defined(OS_WIN)
server_name = base::NumberToString16(base::RandUint64()); server_name = base::NumberToString16(base::RandUint64());
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment