Commit 6cae032c authored by Erik Chen's avatar Erik Chen Committed by Chromium LUCI CQ

lacros: Switch to mojom generated constants.

This CL is a refactor with no intended behavior change.

Bug: 1164523
Change-Id: Ifcb9d931ec1322496553bf551015cbe75abd841c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2630287Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843770}
parent 7ed88f67
......@@ -24,6 +24,7 @@ namespace {
namespace api_epk = api::enterprise_platform_keys;
namespace api_epki = api::enterprise_platform_keys_internal;
using KeystoreService = crosapi::mojom::KeystoreService;
std::vector<uint8_t> VectorFromString(const std::string& s) {
return std::vector<uint8_t>(s.begin(), s.end());
......@@ -57,7 +58,7 @@ const char kInvalidKeystoreType[] = "Invalid keystore type.";
// extension. |context| is the browser context in which the extension is hosted.
std::string ValidateCrosapi(int min_version, content::BrowserContext* context) {
int version = chromeos::LacrosChromeServiceImpl::Get()->GetInterfaceVersion(
crosapi::mojom::KeystoreService::Uuid_);
KeystoreService::Uuid_);
if (version < min_version)
return kUnsupportedByAsh;
......@@ -140,7 +141,8 @@ EnterprisePlatformKeysInternalGenerateKeyFunction::Run() {
api_epki::GenerateKey::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
std::string error = ValidateCrosapi(/*min_version=*/2, browser_context());
std::string error = ValidateCrosapi(KeystoreService::kGenerateKeyMinVersion,
browser_context());
if (!error.empty()) {
return RespondNow(Error(error));
}
......@@ -179,7 +181,8 @@ EnterprisePlatformKeysGetCertificatesFunction::Run() {
api_epk::GetCertificates::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
std::string error = ValidateCrosapi(/*min_version=*/2, browser_context());
std::string error = ValidateCrosapi(
KeystoreService::kGetCertificatesMinVersion, browser_context());
if (!error.empty()) {
return RespondNow(Error(error));
}
......@@ -222,7 +225,8 @@ EnterprisePlatformKeysImportCertificateFunction::Run() {
api_epk::ImportCertificate::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
std::string error = ValidateCrosapi(/*min_version=*/2, browser_context());
std::string error = ValidateCrosapi(
KeystoreService::kAddCertificateMinVersion, browser_context());
if (!error.empty()) {
return RespondNow(Error(error));
}
......@@ -254,7 +258,8 @@ EnterprisePlatformKeysRemoveCertificateFunction::Run() {
api_epk::RemoveCertificate::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
std::string error = ValidateCrosapi(/*min_version=*/2, browser_context());
std::string error = ValidateCrosapi(
KeystoreService::kRemoveCertificateMinVersion, browser_context());
if (!error.empty()) {
return RespondNow(Error(error));
}
......@@ -285,7 +290,8 @@ ExtensionFunction::ResponseAction
EnterprisePlatformKeysInternalGetTokensFunction::Run() {
EXTENSION_FUNCTION_VALIDATE(args_->empty());
std::string error = ValidateCrosapi(/*min_version=*/1, browser_context());
std::string error = ValidateCrosapi(KeystoreService::kGetKeyStoresMinVersion,
browser_context());
if (!error.empty()) {
return RespondNow(Error(error));
}
......@@ -366,7 +372,9 @@ EnterprisePlatformKeysChallengeUserKeyFunction::Run() {
api_epk::ChallengeUserKey::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
std::string error = ValidateCrosapi(/*min_version=*/0, browser_context());
std::string error = ValidateCrosapi(
KeystoreService::kChallengeAttestationOnlyKeystoreMinVersion,
browser_context());
if (!error.empty()) {
return RespondNow(Error(error));
}
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/platform_keys_internal.h"
#include "chromeos/crosapi/cpp/keystore_service_util.h"
#include "chromeos/crosapi/mojom/keystore_service.mojom.h"
#include "chromeos/lacros/lacros_chrome_service_impl.h"
namespace extensions {
......@@ -18,6 +19,7 @@ namespace extensions {
namespace api_pki = api::platform_keys_internal;
using SigningScheme = crosapi::mojom::KeystoreSigningScheme;
using SigningAlgorithmName = crosapi::mojom::KeystoreSigningAlgorithmName;
using KeystoreService = crosapi::mojom::KeystoreService;
namespace {
const char kUnsupportedByAsh[] = "Not implemented.";
......@@ -103,7 +105,8 @@ PlatformKeysInternalGetPublicKeyFunction::Run() {
EXTENSION_FUNCTION_VALIDATE(params);
if (chromeos::LacrosChromeServiceImpl::Get()->GetInterfaceVersion(
crosapi::mojom::KeystoreService::Uuid_) < 3) {
KeystoreService::Uuid_) <
static_cast<int>(KeystoreService::kGetPublicKeyMinVersion)) {
return RespondNow(Error(kUnsupportedByAsh));
}
......@@ -168,7 +171,8 @@ ExtensionFunction::ResponseAction PlatformKeysInternalSignFunction::Run() {
EXTENSION_FUNCTION_VALIDATE(params);
if (chromeos::LacrosChromeServiceImpl::Get()->GetInterfaceVersion(
crosapi::mojom::KeystoreService::Uuid_) < 4) {
KeystoreService::Uuid_) <
static_cast<int>(KeystoreService::kSignMinVersion)) {
return RespondNow(Error(kUnsupportedByAsh));
}
......
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