summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-02 01:03:58 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-02 01:03:58 +0000
commit4386f075e874d5cebd8eb870599505f70aef328d (patch)
treec6ba825483e4646fa8b44f0999d960b21c7b75e5 /chromeos
parentbab8935b590fab092ee9dbb2549a9273bf8fcb03 (diff)
downloadchromium_src-4386f075e874d5cebd8eb870599505f70aef328d.zip
chromium_src-4386f075e874d5cebd8eb870599505f70aef328d.tar.gz
chromium_src-4386f075e874d5cebd8eb870599505f70aef328d.tar.bz2
cryptohome: Move stateless wrapper functions out of CryptohomeLibrary
These functions don't have to be in CryptohomeLibrary. If you need to avoid real D-Bus method calls (ex. in tests), you can use FakeCryptohomeClient. BUG=141016 TEST=none R=hashimoto@chromium.org, pneubeck@chromium.org Review URL: https://codereview.chromium.org/24869003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226373 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-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
3 files changed, 91 insertions, 139 deletions
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&));