summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/login/login_browsertest.cc2
-rw-r--r--chrome/browser/chromeos/login/login_utils.cc5
-rw-r--r--chrome/browser/chromeos/login/login_utils_browsertest.cc44
-rw-r--r--chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc5
-rw-r--r--chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos_unittest.cc12
-rw-r--r--chrome/browser/chromeos/policy/enterprise_install_attributes.cc43
-rw-r--r--chrome/browser/chromeos/policy/enterprise_install_attributes.h8
-rw-r--r--chrome/browser/chromeos/policy/enterprise_install_attributes_unittest.cc28
-rw-r--r--chrome/browser/chromeos/policy/stub_enterprise_install_attributes.cc2
-rw-r--r--chrome/browser/policy/browser_policy_connector.cc7
-rw-r--r--chromeos/cryptohome/cryptohome_library.cc177
-rw-r--r--chromeos/cryptohome/cryptohome_library.h40
-rw-r--r--chromeos/cryptohome/mock_cryptohome_library.h13
13 files changed, 147 insertions, 239 deletions
diff --git a/chrome/browser/chromeos/login/login_browsertest.cc b/chrome/browser/chromeos/login/login_browsertest.cc
index 4db9cb0..d82929e 100644
--- a/chrome/browser/chromeos/login/login_browsertest.cc
+++ b/chrome/browser/chromeos/login/login_browsertest.cc
@@ -44,8 +44,6 @@ class LoginTestBase : public InProcessBrowserTest {
mock_cryptohome_library_.reset(new chromeos::MockCryptohomeLibrary());
EXPECT_CALL(*(mock_cryptohome_library_.get()), GetSystemSalt())
.WillRepeatedly(Return(std::string("stub_system_salt")));
- EXPECT_CALL(*(mock_cryptohome_library_.get()), InstallAttributesIsReady())
- .WillRepeatedly(Return(false));
}
scoped_ptr<chromeos::MockCryptohomeLibrary> mock_cryptohome_library_;
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index 0e3dd68..cef9342 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -507,11 +507,10 @@ void LoginUtilsImpl::FinalizePrepareProfile(Profile* user_profile) {
BootTimesLoader* btl = BootTimesLoader::Get();
// Own TPM device if, for any reason, it has not been done in EULA
// wizard screen.
- CryptohomeLibrary* cryptohome = CryptohomeLibrary::Get();
CryptohomeClient* client = DBusThreadManager::Get()->GetCryptohomeClient();
btl->AddLoginTimeMarker("TPMOwn-Start", false);
- if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) {
- if (cryptohome->TpmIsOwned()) {
+ if (cryptohome_util::TpmIsEnabled() && !cryptohome_util::TpmIsBeingOwned()) {
+ if (cryptohome_util::TpmIsOwned()) {
client->CallTpmClearStoredPasswordAndBlock();
} else {
client->TpmCanAttemptOwnership(EmptyVoidDBusMethodCallback());
diff --git a/chrome/browser/chromeos/login/login_utils_browsertest.cc b/chrome/browser/chromeos/login/login_utils_browsertest.cc
index 843be727..b00ff99 100644
--- a/chrome/browser/chromeos/login/login_utils_browsertest.cc
+++ b/chrome/browser/chromeos/login/login_utils_browsertest.cc
@@ -226,46 +226,6 @@ class LoginUtilsTest : public testing::Test,
mock_async_method_caller_);
cryptohome_.reset(new MockCryptohomeLibrary());
- EXPECT_CALL(*cryptohome_, InstallAttributesIsInvalid())
- .WillRepeatedly(Return(false));
- EXPECT_CALL(*cryptohome_, InstallAttributesIsFirstInstall())
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*cryptohome_, TpmIsEnabled())
- .WillRepeatedly(Return(false));
- EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwned, kTrue))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwner,
- kUsername))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttrEnterpriseDomain,
- kDomain))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttrEnterpriseMode,
- kMode))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttrEnterpriseDeviceId,
- kDeviceId))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*cryptohome_, InstallAttributesFinalize())
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttributeOwned, _))
- .WillRepeatedly(DoAll(SetArgPointee<1>(kTrue),
- Return(true)));
- EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttributeConsumerKiosk, _))
- .WillRepeatedly(DoAll(SetArgPointee<1>(kFalse),
- Return(true)));
- EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttributeOwner, _))
- .WillRepeatedly(DoAll(SetArgPointee<1>(kUsername),
- Return(true)));
- EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDomain, _))
- .WillRepeatedly(DoAll(SetArgPointee<1>(kDomain),
- Return(true)));
- EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseMode, _))
- .WillRepeatedly(DoAll(SetArgPointee<1>(kMode),
- Return(true)));
- EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDeviceId, _))
- .WillRepeatedly(DoAll(SetArgPointee<1>(kDeviceId),
- Return(true)));
CryptohomeLibrary::SetForTest(cryptohome_.get());
test_device_settings_service_.reset(new ScopedTestDeviceSettingsService);
@@ -401,10 +361,6 @@ class LoginUtilsTest : public testing::Test,
}
void EnrollDevice(const std::string& username) {
- EXPECT_CALL(*cryptohome_, InstallAttributesIsFirstInstall())
- .WillOnce(Return(true))
- .WillRepeatedly(Return(false));
-
base::RunLoop loop;
policy::EnterpriseInstallAttributes::LockResult result;
connector_->GetInstallAttributes()->LockDevice(
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc
index c509c4e..96904ae 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc
@@ -60,8 +60,7 @@ class DeviceCloudPolicyManagerChromeOSTest
DeviceCloudPolicyManagerChromeOSTest()
: cryptohome_library_(chromeos::CryptohomeLibrary::GetTestImpl()),
fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()),
- install_attributes_(cryptohome_library_.get(),
- fake_cryptohome_client_.get()),
+ install_attributes_(fake_cryptohome_client_.get()),
store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_,
&install_attributes_)),
manager_(make_scoped_ptr(store_),
@@ -84,6 +83,8 @@ class DeviceCloudPolicyManagerChromeOSTest
request_context_getter_.get());
TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
chromeos::DeviceOAuth2TokenServiceFactory::Initialize();
+ // TODO(satorux): Remove CryptohomeLibrary::SetForTest() when it's ready.
+ // (removing it now breaks the unit test). crbug.com/141016.
chromeos::CryptohomeLibrary::SetForTest(cryptohome_library_.get());
url_fetcher_response_code_ = 200;
url_fetcher_response_string_ = "{\"access_token\":\"accessToken4Test\","
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos_unittest.cc b/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos_unittest.cc
index c5f0460..82dbd9c 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos_unittest.cc
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos_unittest.cc
@@ -35,10 +35,9 @@ class DeviceCloudPolicyStoreChromeOSTest
: public chromeos::DeviceSettingsTestBase {
protected:
DeviceCloudPolicyStoreChromeOSTest()
- : cryptohome_library_(chromeos::CryptohomeLibrary::GetTestImpl()),
- fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()),
+ : fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()),
install_attributes_(new EnterpriseInstallAttributes(
- cryptohome_library_.get(), fake_cryptohome_client_.get())),
+ fake_cryptohome_client_.get())),
store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_,
install_attributes_.get())) {
fake_cryptohome_client_->Init(NULL /* no dbus::Bus */);
@@ -96,15 +95,14 @@ class DeviceCloudPolicyStoreChromeOSTest
void ResetToNonEnterprise() {
store_.reset();
- cryptohome_library_->InstallAttributesSet("enterprise.owned",
- std::string());
+ chromeos::cryptohome_util::InstallAttributesSet("enterprise.owned",
+ std::string());
install_attributes_.reset(new EnterpriseInstallAttributes(
- cryptohome_library_.get(), fake_cryptohome_client_.get()));
+ fake_cryptohome_client_.get()));
store_.reset(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_,
install_attributes_.get()));
}
- scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_library_;
scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_;
scoped_ptr<EnterpriseInstallAttributes> install_attributes_;
diff --git a/chrome/browser/chromeos/policy/enterprise_install_attributes.cc b/chrome/browser/chromeos/policy/enterprise_install_attributes.cc
index 72318d3..429d60f 100644
--- a/chrome/browser/chromeos/policy/enterprise_install_attributes.cc
+++ b/chrome/browser/chromeos/policy/enterprise_install_attributes.cc
@@ -18,6 +18,8 @@
namespace policy {
+namespace cryptohome_util = chromeos::cryptohome_util;
+
namespace {
// Translates DeviceMode constants to strings used in the lockbox.
@@ -88,11 +90,9 @@ const char EnterpriseInstallAttributes::kAttrConsumerKioskEnabled[] =
"consumer.app_kiosk_enabled";
EnterpriseInstallAttributes::EnterpriseInstallAttributes(
- chromeos::CryptohomeLibrary* cryptohome,
chromeos::CryptohomeClient* cryptohome_client)
: device_locked_(false),
registration_mode_(DEVICE_MODE_PENDING),
- cryptohome_(cryptohome),
cryptohome_client_(cryptohome_client),
weak_ptr_factory_(this) {}
@@ -152,8 +152,8 @@ void EnterpriseInstallAttributes::ReadAttributesIfReady(
bool result) {
if (call_status == chromeos::DBUS_METHOD_CALL_SUCCESS && result) {
registration_mode_ = DEVICE_MODE_NOT_SET;
- if (!cryptohome_->InstallAttributesIsInvalid() &&
- !cryptohome_->InstallAttributesIsFirstInstall()) {
+ if (!cryptohome_util::InstallAttributesIsInvalid() &&
+ !cryptohome_util::InstallAttributesIsFirstInstall()) {
device_locked_ = true;
static const char* kEnterpriseAttributes[] = {
@@ -167,7 +167,8 @@ void EnterpriseInstallAttributes::ReadAttributesIfReady(
std::map<std::string, std::string> attr_map;
for (size_t i = 0; i < arraysize(kEnterpriseAttributes); ++i) {
std::string value;
- if (cryptohome_->InstallAttributesGet(kEnterpriseAttributes[i], &value))
+ if (cryptohome_util::InstallAttributesGet(kEnterpriseAttributes[i],
+ &value))
attr_map[kEnterpriseAttributes[i]] = value;
}
@@ -222,20 +223,20 @@ void EnterpriseInstallAttributes::LockDeviceIfAttributesIsReady(
}
// Clearing the TPM password seems to be always a good deal.
- if (cryptohome_->TpmIsEnabled() &&
- !cryptohome_->TpmIsBeingOwned() &&
- cryptohome_->TpmIsOwned()) {
+ if (cryptohome_util::TpmIsEnabled() &&
+ !cryptohome_util::TpmIsBeingOwned() &&
+ cryptohome_util::TpmIsOwned()) {
cryptohome_client_->CallTpmClearStoredPasswordAndBlock();
}
// Make sure we really have a working InstallAttrs.
- if (cryptohome_->InstallAttributesIsInvalid()) {
+ if (cryptohome_util::InstallAttributesIsInvalid()) {
LOG(ERROR) << "Install attributes invalid.";
callback.Run(LOCK_BACKEND_ERROR);
return;
}
- if (!cryptohome_->InstallAttributesIsFirstInstall()) {
+ if (!cryptohome_util::InstallAttributesIsFirstInstall()) {
callback.Run(LOCK_WRONG_USER);
return;
}
@@ -247,7 +248,8 @@ void EnterpriseInstallAttributes::LockDeviceIfAttributesIsReady(
if (device_mode == DEVICE_MODE_CONSUMER_KIOSK) {
// Set values in the InstallAttrs and lock it.
- if (!cryptohome_->InstallAttributesSet(kAttrConsumerKioskEnabled, "true")) {
+ if (!cryptohome_util::InstallAttributesSet(kAttrConsumerKioskEnabled,
+ "true")) {
LOG(ERROR) << "Failed writing attributes";
callback.Run(LOCK_BACKEND_ERROR);
return;
@@ -255,21 +257,22 @@ void EnterpriseInstallAttributes::LockDeviceIfAttributesIsReady(
} else {
std::string domain = gaia::ExtractDomainName(registration_user);
// Set values in the InstallAttrs and lock it.
- if (!cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true") ||
- !cryptohome_->InstallAttributesSet(kAttrEnterpriseUser,
- registration_user) ||
- !cryptohome_->InstallAttributesSet(kAttrEnterpriseDomain, domain) ||
- !cryptohome_->InstallAttributesSet(kAttrEnterpriseMode, mode) ||
- !cryptohome_->InstallAttributesSet(kAttrEnterpriseDeviceId,
- device_id)) {
+ if (!cryptohome_util::InstallAttributesSet(kAttrEnterpriseOwned, "true") ||
+ !cryptohome_util::InstallAttributesSet(kAttrEnterpriseUser,
+ registration_user) ||
+ !cryptohome_util::InstallAttributesSet(kAttrEnterpriseDomain,
+ domain) ||
+ !cryptohome_util::InstallAttributesSet(kAttrEnterpriseMode, mode) ||
+ !cryptohome_util::InstallAttributesSet(kAttrEnterpriseDeviceId,
+ device_id)) {
LOG(ERROR) << "Failed writing attributes";
callback.Run(LOCK_BACKEND_ERROR);
return;
}
}
- if (!cryptohome_->InstallAttributesFinalize() ||
- cryptohome_->InstallAttributesIsFirstInstall()) {
+ if (!cryptohome_util::InstallAttributesFinalize() ||
+ cryptohome_util::InstallAttributesIsFirstInstall()) {
LOG(ERROR) << "Failed locking.";
callback.Run(LOCK_BACKEND_ERROR);
return;
diff --git a/chrome/browser/chromeos/policy/enterprise_install_attributes.h b/chrome/browser/chromeos/policy/enterprise_install_attributes.h
index fdb80a0..b4fb2c0 100644
--- a/chrome/browser/chromeos/policy/enterprise_install_attributes.h
+++ b/chrome/browser/chromeos/policy/enterprise_install_attributes.h
@@ -17,10 +17,6 @@
#include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_method_call_status.h"
-namespace chromeos {
-class CryptohomeLibrary;
-}
-
namespace policy {
// Brokers access to the enterprise-related installation-time attributes on
@@ -54,8 +50,7 @@ class EnterpriseInstallAttributes {
static const char kAttrEnterpriseUser[];
static const char kAttrConsumerKioskEnabled[];
- EnterpriseInstallAttributes(
- chromeos::CryptohomeLibrary* cryptohome,
+ explicit EnterpriseInstallAttributes(
chromeos::CryptohomeClient* cryptohome_client);
~EnterpriseInstallAttributes();
@@ -134,7 +129,6 @@ class EnterpriseInstallAttributes {
void OnReadImmutableAttributes(const std::string& user,
const LockResultCallback& callback);
- chromeos::CryptohomeLibrary* cryptohome_;
chromeos::CryptohomeClient* cryptohome_client_;
base::WeakPtrFactory<EnterpriseInstallAttributes> weak_ptr_factory_;
diff --git a/chrome/browser/chromeos/policy/enterprise_install_attributes_unittest.cc b/chrome/browser/chromeos/policy/enterprise_install_attributes_unittest.cc
index c85940b..dd1e63a 100644
--- a/chrome/browser/chromeos/policy/enterprise_install_attributes_unittest.cc
+++ b/chrome/browser/chromeos/policy/enterprise_install_attributes_unittest.cc
@@ -11,12 +11,15 @@
#include "base/run_loop.h"
#include "chrome/browser/policy/proto/chromeos/install_attributes.pb.h"
#include "chromeos/cryptohome/cryptohome_library.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_cryptohome_client.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace policy {
+namespace cryptohome_util = chromeos::cryptohome_util;
+
namespace {
void CopyLockResult(base::RunLoop* loop,
@@ -36,14 +39,18 @@ static const char kTestDeviceId[] = "133750519";
class EnterpriseInstallAttributesTest : public testing::Test {
protected:
EnterpriseInstallAttributesTest()
- : cryptohome_(chromeos::CryptohomeLibrary::GetTestImpl()),
- fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()),
- install_attributes_(cryptohome_.get(), fake_cryptohome_client_.get()) {
+ : fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()),
+ install_attributes_(fake_cryptohome_client_.get()) {
fake_cryptohome_client_->Init(NULL /* no dbus::Bus */);
}
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ chromeos::DBusThreadManager::InitializeWithStub();
+ }
+
+ virtual void TearDown() OVERRIDE {
+ chromeos::DBusThreadManager::Shutdown();
}
base::FilePath GetTempPath() const {
@@ -62,7 +69,6 @@ class EnterpriseInstallAttributesTest : public testing::Test {
base::MessageLoopForUI message_loop_;
base::ScopedTempDir temp_dir_;
- scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_;
scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_;
EnterpriseInstallAttributes install_attributes_;
@@ -175,12 +181,12 @@ TEST_F(EnterpriseInstallAttributesTest, ConsumerDevice) {
install_attributes_.ReadCacheFile(GetTempPath());
EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode());
// Lock the attributes empty.
- ASSERT_TRUE(cryptohome_->InstallAttributesFinalize());
+ ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize());
base::RunLoop loop;
install_attributes_.ReadImmutableAttributes(base::Bind(loop.QuitClosure()));
loop.Run();
- ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall());
+ ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall());
EXPECT_EQ(DEVICE_MODE_CONSUMER, install_attributes_.GetMode());
}
@@ -194,7 +200,7 @@ TEST_F(EnterpriseInstallAttributesTest, ConsumerKioskDevice) {
DEVICE_MODE_CONSUMER_KIOSK,
std::string()));
- ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall());
+ ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall());
EXPECT_EQ(DEVICE_MODE_CONSUMER_KIOSK, install_attributes_.GetMode());
ASSERT_TRUE(install_attributes_.IsConsumerKioskDevice());
}
@@ -203,16 +209,16 @@ TEST_F(EnterpriseInstallAttributesTest, DeviceLockedFromOlderVersion) {
install_attributes_.ReadCacheFile(GetTempPath());
EXPECT_EQ(DEVICE_MODE_PENDING, install_attributes_.GetMode());
// Lock the attributes as if it was done from older Chrome version.
- ASSERT_TRUE(cryptohome_->InstallAttributesSet(
+ ASSERT_TRUE(cryptohome_util::InstallAttributesSet(
EnterpriseInstallAttributes::kAttrEnterpriseOwned, "true"));
- ASSERT_TRUE(cryptohome_->InstallAttributesSet(
+ ASSERT_TRUE(cryptohome_util::InstallAttributesSet(
EnterpriseInstallAttributes::kAttrEnterpriseUser, kTestUser));
- ASSERT_TRUE(cryptohome_->InstallAttributesFinalize());
+ ASSERT_TRUE(cryptohome_util::InstallAttributesFinalize());
base::RunLoop loop;
install_attributes_.ReadImmutableAttributes(base::Bind(loop.QuitClosure()));
loop.Run();
- ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall());
+ ASSERT_FALSE(cryptohome_util::InstallAttributesIsFirstInstall());
EXPECT_EQ(DEVICE_MODE_ENTERPRISE, install_attributes_.GetMode());
EXPECT_EQ(kTestDomain, install_attributes_.GetDomain());
EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser());
diff --git a/chrome/browser/chromeos/policy/stub_enterprise_install_attributes.cc b/chrome/browser/chromeos/policy/stub_enterprise_install_attributes.cc
index 5e4c649..39516a1 100644
--- a/chrome/browser/chromeos/policy/stub_enterprise_install_attributes.cc
+++ b/chrome/browser/chromeos/policy/stub_enterprise_install_attributes.cc
@@ -11,7 +11,7 @@
namespace policy {
StubEnterpriseInstallAttributes::StubEnterpriseInstallAttributes()
- : EnterpriseInstallAttributes(NULL, NULL) {
+ : EnterpriseInstallAttributes(NULL) {
device_locked_ = true;
}
diff --git a/chrome/browser/policy/browser_policy_connector.cc b/chrome/browser/policy/browser_policy_connector.cc
index 76bdac2..24a21c0 100644
--- a/chrome/browser/policy/browser_policy_connector.cc
+++ b/chrome/browser/policy/browser_policy_connector.cc
@@ -188,14 +188,15 @@ BrowserPolicyConnector::BrowserPolicyConnector()
#if defined(OS_CHROMEOS)
// CryptohomeLibrary or DBusThreadManager may be uninitialized on unit tests.
+
+ // TODO(satorux): Remove CryptohomeLibrary::IsInitialized() when it's ready
+ // (removing it now breaks tests). crbug.com/141016.
if (chromeos::CryptohomeLibrary::IsInitialized() &&
chromeos::DBusThreadManager::IsInitialized()) {
- chromeos::CryptohomeLibrary* cryptohome =
- chromeos::CryptohomeLibrary::Get();
chromeos::CryptohomeClient* cryptohome_client =
chromeos::DBusThreadManager::Get()->GetCryptohomeClient();
install_attributes_.reset(
- new EnterpriseInstallAttributes(cryptohome, cryptohome_client));
+ new EnterpriseInstallAttributes(cryptohome_client));
base::FilePath install_attrs_file;
CHECK(PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES,
&install_attrs_file));
diff --git a/chromeos/cryptohome/cryptohome_library.cc b/chromeos/cryptohome/cryptohome_library.cc
index 9222ac5..2fd6a86 100644
--- a/chromeos/cryptohome/cryptohome_library.cc
+++ b/chromeos/cryptohome/cryptohome_library.cc
@@ -37,72 +37,6 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary {
virtual ~CryptohomeLibraryImpl() {
}
- virtual bool TpmIsEnabled() OVERRIDE {
- bool result = false;
- DBusThreadManager::Get()->GetCryptohomeClient()->CallTpmIsEnabledAndBlock(
- &result);
- return result;
- }
-
- virtual bool TpmIsOwned() OVERRIDE {
- bool result = false;
- DBusThreadManager::Get()->GetCryptohomeClient()->CallTpmIsOwnedAndBlock(
- &result);
- return result;
- }
-
- virtual bool TpmIsBeingOwned() OVERRIDE {
- bool result = false;
- DBusThreadManager::Get()->GetCryptohomeClient()->
- CallTpmIsBeingOwnedAndBlock(&result);
- return result;
- }
-
- virtual bool InstallAttributesGet(
- const std::string& name, std::string* value) OVERRIDE {
- std::vector<uint8> buf;
- bool success = false;
- DBusThreadManager::Get()->GetCryptohomeClient()->
- InstallAttributesGet(name, &buf, &success);
- if (success) {
- // Cryptohome returns 'buf' with a terminating '\0' character.
- DCHECK(!buf.empty());
- DCHECK_EQ(buf.back(), 0);
- value->assign(reinterpret_cast<char*>(buf.data()), buf.size() - 1);
- }
- return success;
- }
-
- virtual bool InstallAttributesSet(
- const std::string& name, const std::string& value) OVERRIDE {
- std::vector<uint8> buf(value.c_str(), value.c_str() + value.size() + 1);
- bool success = false;
- DBusThreadManager::Get()->GetCryptohomeClient()->
- InstallAttributesSet(name, buf, &success);
- return success;
- }
-
- virtual bool InstallAttributesFinalize() OVERRIDE {
- bool success = false;
- DBusThreadManager::Get()->GetCryptohomeClient()->
- InstallAttributesFinalize(&success);
- return success;
- }
-
- virtual bool InstallAttributesIsInvalid() OVERRIDE {
- bool result = false;
- DBusThreadManager::Get()->GetCryptohomeClient()->
- InstallAttributesIsInvalid(&result);
- return result;
- }
-
- virtual bool InstallAttributesIsFirstInstall() OVERRIDE {
- bool result = false;
- DBusThreadManager::Get()->GetCryptohomeClient()->
- InstallAttributesIsFirstInstall(&result);
- return result;
- }
-
virtual std::string GetSystemSalt() OVERRIDE {
LoadSystemSalt(); // no-op if it's already loaded.
return system_salt_;
@@ -233,46 +167,6 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary {
: locked_(false) {}
virtual ~CryptohomeLibraryStubImpl() {}
- virtual bool TpmIsEnabled() OVERRIDE {
- return true;
- }
-
- virtual bool TpmIsOwned() OVERRIDE {
- return true;
- }
-
- virtual bool TpmIsBeingOwned() OVERRIDE {
- return true;
- }
-
- virtual bool InstallAttributesGet(
- const std::string& name, std::string* value) OVERRIDE {
- if (install_attrs_.find(name) != install_attrs_.end()) {
- *value = install_attrs_[name];
- return true;
- }
- return false;
- }
-
- virtual bool InstallAttributesSet(
- const std::string& name, const std::string& value) OVERRIDE {
- install_attrs_[name] = value;
- return true;
- }
-
- virtual bool InstallAttributesFinalize() OVERRIDE {
- locked_ = true;
- return true;
- }
-
- virtual bool InstallAttributesIsInvalid() OVERRIDE {
- return false;
- }
-
- virtual bool InstallAttributesIsFirstInstall() OVERRIDE {
- return !locked_;
- }
-
virtual std::string GetSystemSalt() OVERRIDE {
return kStubSystemSalt;
}
@@ -339,4 +233,73 @@ CryptohomeLibrary* CryptohomeLibrary::GetTestImpl() {
return new CryptohomeLibraryStubImpl();
}
-} // namespace chromeos
+namespace cryptohome_util {
+
+bool TpmIsEnabled() {
+ bool result = false;
+ DBusThreadManager::Get()->GetCryptohomeClient()->CallTpmIsEnabledAndBlock(
+ &result);
+ return result;
+}
+
+bool TpmIsOwned() {
+ bool result = false;
+ DBusThreadManager::Get()->GetCryptohomeClient()->CallTpmIsOwnedAndBlock(
+ &result);
+ return result;
+}
+
+bool TpmIsBeingOwned() {
+ bool result = false;
+ DBusThreadManager::Get()->GetCryptohomeClient()->
+ CallTpmIsBeingOwnedAndBlock(&result);
+ return result;
+}
+
+bool InstallAttributesGet(
+ const std::string& name, std::string* value) {
+ std::vector<uint8> buf;
+ bool success = false;
+ DBusThreadManager::Get()->GetCryptohomeClient()->
+ InstallAttributesGet(name, &buf, &success);
+ if (success) {
+ // Cryptohome returns 'buf' with a terminating '\0' character.
+ DCHECK(!buf.empty());
+ DCHECK_EQ(buf.back(), 0);
+ value->assign(reinterpret_cast<char*>(buf.data()), buf.size() - 1);
+ }
+ return success;
+}
+
+bool InstallAttributesSet(
+ const std::string& name, const std::string& value) {
+ std::vector<uint8> buf(value.c_str(), value.c_str() + value.size() + 1);
+ bool success = false;
+ DBusThreadManager::Get()->GetCryptohomeClient()->
+ InstallAttributesSet(name, buf, &success);
+ return success;
+}
+
+bool InstallAttributesFinalize() {
+ bool success = false;
+ DBusThreadManager::Get()->GetCryptohomeClient()->
+ InstallAttributesFinalize(&success);
+ return success;
+}
+
+bool InstallAttributesIsInvalid() {
+ bool result = false;
+ DBusThreadManager::Get()->GetCryptohomeClient()->
+ InstallAttributesIsInvalid(&result);
+ return result;
+}
+
+bool InstallAttributesIsFirstInstall() {
+ bool result = false;
+ DBusThreadManager::Get()->GetCryptohomeClient()->
+ InstallAttributesIsFirstInstall(&result);
+ return result;
+}
+
+} // namespace cryptohome_util
+} // namespace chromeos
diff --git a/chromeos/cryptohome/cryptohome_library.h b/chromeos/cryptohome/cryptohome_library.h
index 6d187ed..3d9afc2 100644
--- a/chromeos/cryptohome/cryptohome_library.h
+++ b/chromeos/cryptohome/cryptohome_library.h
@@ -33,25 +33,6 @@ class CHROMEOS_EXPORT CryptohomeLibrary {
// Public so that result of GetTestImpl can be destroyed.
virtual ~CryptohomeLibrary();
- // Wrappers of the functions for working with Tpm.
-
- // Returns whether Tpm is presented and enabled.
- virtual bool TpmIsEnabled() = 0;
-
- // Returns whether device has already been owned.
- virtual bool TpmIsOwned() = 0;
-
- // Returns whether device is being owned (Tpm password is generating).
- virtual bool TpmIsBeingOwned() = 0;
-
- virtual bool InstallAttributesGet(const std::string& name,
- std::string* value) = 0;
- virtual bool InstallAttributesSet(const std::string& name,
- const std::string& value) = 0;
- virtual bool InstallAttributesFinalize() = 0;
- virtual bool InstallAttributesIsInvalid() = 0;
- virtual bool InstallAttributesIsFirstInstall() = 0;
-
// Returns system hash in hex encoded ascii format. Note: this may return
// an empty string (e.g. if cryptohome is not running). It is up to the
// calling function to try again after a delay if desired.
@@ -74,6 +55,27 @@ class CHROMEOS_EXPORT CryptohomeLibrary {
DISALLOW_COPY_AND_ASSIGN(CryptohomeLibrary);
};
+// Wrappers of the D-Bus method calls for working with Tpm.
+namespace cryptohome_util {
+
+// Returns whether Tpm is presented and enabled.
+CHROMEOS_EXPORT bool TpmIsEnabled();
+
+// Returns whether device has already been owned.
+CHROMEOS_EXPORT bool TpmIsOwned();
+
+// Returns whether device is being owned (Tpm password is generating).
+CHROMEOS_EXPORT bool TpmIsBeingOwned();
+
+CHROMEOS_EXPORT bool InstallAttributesGet(const std::string& name,
+ std::string* value);
+CHROMEOS_EXPORT bool InstallAttributesSet(const std::string& name,
+ const std::string& value);
+CHROMEOS_EXPORT bool InstallAttributesFinalize();
+CHROMEOS_EXPORT bool InstallAttributesIsInvalid();
+CHROMEOS_EXPORT bool InstallAttributesIsFirstInstall();
+
+} // namespace cryptohome_util
} // namespace chromeos
#endif // CHROMEOS_CRYPTOHOME_CRYPTOHOME_LIBRARY_H_
diff --git a/chromeos/cryptohome/mock_cryptohome_library.h b/chromeos/cryptohome/mock_cryptohome_library.h
index 69c177e..5a08ac0 100644
--- a/chromeos/cryptohome/mock_cryptohome_library.h
+++ b/chromeos/cryptohome/mock_cryptohome_library.h
@@ -23,19 +23,6 @@ class MockCryptohomeLibrary : public CryptohomeLibrary {
virtual ~MockCryptohomeLibrary();
MOCK_METHOD0(GetSystemSalt, std::string(void));
- MOCK_METHOD0(TpmIsReady, bool(void));
- MOCK_METHOD0(TpmIsEnabled, bool(void));
- MOCK_METHOD0(TpmIsOwned, bool(void));
- MOCK_METHOD0(TpmIsBeingOwned, bool(void));
-
- MOCK_METHOD2(InstallAttributesGet, bool(const std::string&, std::string*));
- MOCK_METHOD2(InstallAttributesSet, bool(const std::string&,
- const std::string&));
- MOCK_METHOD0(InstallAttributesFinalize, bool(void));
- MOCK_METHOD0(InstallAttributesIsReady, bool(void));
- MOCK_METHOD0(InstallAttributesIsInvalid, bool(void));
- MOCK_METHOD0(InstallAttributesIsFirstInstall, bool(void));
-
MOCK_METHOD1(EncryptWithSystemSalt, std::string(const std::string&));
MOCK_METHOD1(DecryptWithSystemSalt, std::string(const std::string&));