Commit 0f7c1aa2 authored by Jasmine Chen's avatar Jasmine Chen Committed by Commit Bot

VCD: Generate token for cros_camera_test

Generates the token for cros_camera_test for it to be used for
RegisterClientWithToken.

Bug: b/170075468
Test: Build, deploy simplechrome, and verify the client token is
generated.

Change-Id: I4dade5863868aa0d1af003a6d81067b338cb6780
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536653
Commit-Queue: Jasmine Chen <lnishan@google.com>
Reviewed-by: default avatarWei Lee <wtlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828546}
parent c5bff005
...@@ -68,6 +68,14 @@ bool WaitForSocketReadable(int raw_socket_fd, int raw_cancel_fd) { ...@@ -68,6 +68,14 @@ bool WaitForSocketReadable(int raw_socket_fd, int raw_cancel_fd) {
return true; return true;
} }
bool HasCrosCameraTest() {
static constexpr char kCrosCameraTestPath[] =
"/usr/local/bin/cros_camera_test";
base::FilePath path(kCrosCameraTestPath);
return base::PathExists(path);
}
class MojoCameraClientObserver : public CameraClientObserver { class MojoCameraClientObserver : public CameraClientObserver {
public: public:
explicit MojoCameraClientObserver( explicit MojoCameraClientObserver(
...@@ -134,6 +142,10 @@ bool CameraHalDispatcherImpl::Start( ...@@ -134,6 +142,10 @@ bool CameraHalDispatcherImpl::Start(
LOG(ERROR) << "Failed to generate authentication token for server"; LOG(ERROR) << "Failed to generate authentication token for server";
return false; return false;
} }
if (HasCrosCameraTest() && !token_manager_.GenerateTestClientToken()) {
LOG(ERROR) << "Failed to generate token for test client";
return false;
}
blocking_io_task_runner_->PostTask( blocking_io_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&CameraHalDispatcherImpl::CreateSocket, base::BindOnce(&CameraHalDispatcherImpl::CreateSocket,
......
...@@ -43,6 +43,24 @@ bool EnsureTokenDirectoryExists(const base::FilePath& token_path) { ...@@ -43,6 +43,24 @@ bool EnsureTokenDirectoryExists(const base::FilePath& token_path) {
return true; return true;
} }
bool WriteTokenToFile(const base::FilePath& token_path,
const base::UnguessableToken& token) {
if (!EnsureTokenDirectoryExists(token_path)) {
LOG(ERROR) << "Failed to ensure token directory exists";
return false;
}
base::File token_file(
token_path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
if (!token_file.IsValid()) {
LOG(ERROR) << "Failed to create token file at "
<< token_path.AsUTF8Unsafe();
return false;
}
std::string token_string = token.ToString();
token_file.WriteAtCurrentPos(token_string.c_str(), token_string.length());
return true;
}
} // namespace } // namespace
namespace media { namespace media {
...@@ -52,22 +70,18 @@ TokenManager::~TokenManager() = default; ...@@ -52,22 +70,18 @@ TokenManager::~TokenManager() = default;
bool TokenManager::GenerateServerToken() { bool TokenManager::GenerateServerToken() {
static constexpr char kServerTokenPath[] = "/run/camera_tokens/server/token"; static constexpr char kServerTokenPath[] = "/run/camera_tokens/server/token";
base::FilePath token_path(kServerTokenPath);
if (!EnsureTokenDirectoryExists(token_path)) {
LOG(ERROR) << "Failed to ensure server token directory exists";
return false;
}
base::File token_file(
token_path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
if (!token_file.IsValid()) {
LOG(ERROR) << "Failed to create server token file";
return false;
}
server_token_ = base::UnguessableToken::Create(); server_token_ = base::UnguessableToken::Create();
std::string token_string = server_token_.ToString(); return WriteTokenToFile(base::FilePath(kServerTokenPath), server_token_);
token_file.WriteAtCurrentPos(token_string.c_str(), token_string.length()); }
return true;
bool TokenManager::GenerateTestClientToken() {
static constexpr char kTestClientTokenPath[] =
"/run/camera_tokens/testing/token";
return WriteTokenToFile(
base::FilePath(kTestClientTokenPath),
GetTokenForTrustedClient(cros::mojom::CameraClientType::TESTING));
} }
base::UnguessableToken TokenManager::GetTokenForTrustedClient( base::UnguessableToken TokenManager::GetTokenForTrustedClient(
......
...@@ -18,6 +18,8 @@ class TokenManager { ...@@ -18,6 +18,8 @@ class TokenManager {
bool GenerateServerToken(); bool GenerateServerToken();
bool GenerateTestClientToken();
base::UnguessableToken GetTokenForTrustedClient( base::UnguessableToken GetTokenForTrustedClient(
cros::mojom::CameraClientType type); cros::mojom::CameraClientType type);
......
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