summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus
diff options
context:
space:
mode:
authordkrahn@google.com <dkrahn@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-30 18:00:48 +0000
committerdkrahn@google.com <dkrahn@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-30 18:00:48 +0000
commit43156477fa536cb65ff52bd5ba3ea52c73fd333f (patch)
tree2d2c3f8cc198585f7d8697c13c1f848927f78611 /chromeos/dbus
parentbc5fe91e1393dffd8da5be7254e3929269517a97 (diff)
downloadchromium_src-43156477fa536cb65ff52bd5ba3ea52c73fd333f.zip
chromium_src-43156477fa536cb65ff52bd5ba3ea52c73fd333f.tar.gz
chromium_src-43156477fa536cb65ff52bd5ba3ea52c73fd333f.tar.bz2
Added support in CryptohomeClient for new attestation dbus calls.
Support for the asynchronous calls has also been added to the cryptohome AsyncMethodCaller. BUG=chromium:221929 TEST=chromeos_unittests Review URL: https://chromiumcodereview.appspot.com/13160005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191534 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/dbus')
-rw-r--r--chromeos/dbus/cryptohome_client.cc192
-rw-r--r--chromeos/dbus/cryptohome_client.h63
-rw-r--r--chromeos/dbus/mock_cryptohome_client.h28
3 files changed, 283 insertions, 0 deletions
diff --git a/chromeos/dbus/cryptohome_client.cc b/chromeos/dbus/cryptohome_client.cc
index 39c5383..63e16f9 100644
--- a/chromeos/dbus/cryptohome_client.cc
+++ b/chromeos/dbus/cryptohome_client.cc
@@ -443,6 +443,119 @@ class CryptohomeClientImpl : public CryptohomeClient {
callback));
}
+ // CryptohomeClient override.
+ virtual void TpmAttestationDoesKeyExist(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const BoolDBusMethodCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(
+ cryptohome::kCryptohomeInterface,
+ cryptohome::kCryptohomeTpmAttestationDoesKeyExist);
+ dbus::MessageWriter writer(&method_call);
+ bool is_user_specific = (key_type == USER_KEY);
+ writer.AppendBool(is_user_specific);
+ writer.AppendString(key_name);
+ CallBoolMethod(&method_call, callback);
+ }
+
+ // CryptohomeClient override.
+ virtual void TpmAttestationGetCertificate(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const DataMethodCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(
+ cryptohome::kCryptohomeInterface,
+ cryptohome::kCryptohomeTpmAttestationGetCertificate);
+ dbus::MessageWriter writer(&method_call);
+ bool is_user_specific = (key_type == USER_KEY);
+ writer.AppendBool(is_user_specific);
+ writer.AppendString(key_name);
+ proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&CryptohomeClientImpl::OnDataMethod,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
+ }
+
+ // CryptohomeClient override.
+ virtual void TpmAttestationGetPublicKey(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const DataMethodCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(
+ cryptohome::kCryptohomeInterface,
+ cryptohome::kCryptohomeTpmAttestationGetPublicKey);
+ dbus::MessageWriter writer(&method_call);
+ bool is_user_specific = (key_type == USER_KEY);
+ writer.AppendBool(is_user_specific);
+ writer.AppendString(key_name);
+ proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&CryptohomeClientImpl::OnDataMethod,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
+ }
+
+ // CryptohomeClient override.
+ virtual void TpmAttestationRegisterKey(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const AsyncMethodCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(
+ cryptohome::kCryptohomeInterface,
+ cryptohome::kCryptohomeTpmAttestationRegisterKey);
+ dbus::MessageWriter writer(&method_call);
+ bool is_user_specific = (key_type == USER_KEY);
+ writer.AppendBool(is_user_specific);
+ writer.AppendString(key_name);
+ proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
+ }
+
+ // CryptohomeClient override.
+ virtual void TpmAttestationSignEnterpriseChallenge(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const std::string& domain,
+ const std::string& device_id,
+ const std::string& challenge,
+ const AsyncMethodCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(
+ cryptohome::kCryptohomeInterface,
+ cryptohome::kCryptohomeTpmAttestationSignEnterpriseChallenge);
+ dbus::MessageWriter writer(&method_call);
+ bool is_user_specific = (key_type == USER_KEY);
+ writer.AppendBool(is_user_specific);
+ writer.AppendString(key_name);
+ writer.AppendString(domain);
+ writer.AppendString(device_id);
+ writer.AppendString(challenge);
+ proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
+ }
+
+ // CryptohomeClient override.
+ virtual void TpmAttestationSignSimpleChallenge(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const std::string& challenge,
+ const AsyncMethodCallback& callback) OVERRIDE {
+ dbus::MethodCall method_call(
+ cryptohome::kCryptohomeInterface,
+ cryptohome::kCryptohomeTpmAttestationSignEnterpriseChallenge);
+ dbus::MessageWriter writer(&method_call);
+ bool is_user_specific = (key_type == USER_KEY);
+ writer.AppendBool(is_user_specific);
+ writer.AppendString(key_name);
+ writer.AppendString(challenge);
+ proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&CryptohomeClientImpl::OnAsyncMethodCall,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
+ }
+
private:
// Handles the result of AsyncXXX methods.
void OnAsyncMethodCall(const AsyncMethodCallback& callback,
@@ -529,6 +642,27 @@ class CryptohomeClientImpl : public CryptohomeClient {
callback.Run(DBUS_METHOD_CALL_SUCCESS, result);
}
+ // Handles responses for methods with a bool result and data.
+ void OnDataMethod(const DataMethodCallback& callback,
+ dbus::Response* response) {
+ if (!response) {
+ callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string());
+ return;
+ }
+ dbus::MessageReader reader(response);
+ bool result = false;
+ if (!reader.PopBool(&result)) {
+ callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string());
+ return;
+ }
+ std::string data;
+ if (!reader.PopString(&data)) {
+ callback.Run(DBUS_METHOD_CALL_FAILURE, false, std::string());
+ return;
+ }
+ callback.Run(DBUS_METHOD_CALL_SUCCESS, result, data);
+ }
+
// Handles responses for Pkcs11GetTpmtTokenInfo.
void OnPkcs11GetTpmTokenInfo(const Pkcs11GetTpmTokenInfoCallback& callback,
dbus::Response* response) {
@@ -872,6 +1006,64 @@ class CryptohomeClientStubImpl : public CryptohomeClient {
ReturnAsyncMethodResult(callback, true);
}
+ // CryptohomeClient override.
+ virtual void TpmAttestationDoesKeyExist(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const BoolDBusMethodCallback& callback) OVERRIDE {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false));
+ }
+
+ // CryptohomeClient override.
+ virtual void TpmAttestationGetCertificate(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const DataMethodCallback& callback) OVERRIDE {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string()));
+ }
+
+ // CryptohomeClient override.
+ virtual void TpmAttestationGetPublicKey(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const DataMethodCallback& callback) OVERRIDE {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string()));
+ }
+
+ // CryptohomeClient override.
+ virtual void TpmAttestationRegisterKey(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const AsyncMethodCallback& callback) OVERRIDE {
+ ReturnAsyncMethodResult(callback, true);
+ }
+
+ // CryptohomeClient override.
+ virtual void TpmAttestationSignEnterpriseChallenge(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const std::string& domain,
+ const std::string& device_id,
+ const std::string& challenge,
+ const AsyncMethodCallback& callback) OVERRIDE {
+ ReturnAsyncMethodResult(callback, true);
+ }
+
+ // CryptohomeClient override.
+ virtual void TpmAttestationSignSimpleChallenge(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const std::string& challenge,
+ const AsyncMethodCallback& callback) OVERRIDE {
+ ReturnAsyncMethodResult(callback, true);
+ }
+
private:
// Posts tasks which return fake results to the UI thread.
void ReturnAsyncMethodResult(const AsyncMethodCallback& callback,
diff --git a/chromeos/dbus/cryptohome_client.h b/chromeos/dbus/cryptohome_client.h
index 6b68066..1f5a314 100644
--- a/chromeos/dbus/cryptohome_client.h
+++ b/chromeos/dbus/cryptohome_client.h
@@ -42,6 +42,10 @@ class CHROMEOS_EXPORT CryptohomeClient {
DBusMethodCallStatus call_status,
const std::string& label,
const std::string& user_pin)> Pkcs11GetTpmTokenInfoCallback;
+ // A callback for methods which return both a bool result and data.
+ typedef base::Callback<void(DBusMethodCallStatus call_status,
+ bool result,
+ const std::string& data)> DataMethodCallback;
// Options available for customizing an attestation certificate.
enum AttestationCertificateOptions {
@@ -253,6 +257,65 @@ class CHROMEOS_EXPORT CryptohomeClient {
const std::string& key_name,
const AsyncMethodCallback& callback) = 0;
+ // Checks if an attestation key already exists. If the key specified by
+ // |key_type| and |key_name| exists, then the result sent to the callback will
+ // be true.
+ virtual void TpmAttestationDoesKeyExist(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const BoolDBusMethodCallback& callback) = 0;
+
+ // Gets the attestation certificate for the key specified by |key_type| and
+ // |key_name|. |callback| will be called when the operation completes. If
+ // the key does not exist the callback |result| parameter will be false.
+ virtual void TpmAttestationGetCertificate(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const DataMethodCallback& callback) = 0;
+
+ // Gets the public key for the key specified by |key_type| and |key_name|.
+ // |callback| will be called when the operation completes. If the key does
+ // not exist the callback |result| parameter will be false.
+ virtual void TpmAttestationGetPublicKey(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const DataMethodCallback& callback) = 0;
+
+ // Asynchronously registers an attestation key with the current user's
+ // PKCS #11 token. The |callback| will be called when the dbus call
+ // completes. When the operation completes, the AsyncCallStatusHandler signal
+ // handler is called. |key_type| and |key_name| specify the key to register.
+ virtual void TpmAttestationRegisterKey(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const AsyncMethodCallback& callback) = 0;
+
+ // Asynchronously signs an enterprise challenge with the key specified by
+ // |key_type| and |key_name|. |domain| and |device_id| will be included in
+ // the challenge response. |challenge| must be a valid enterprise attestation
+ // challenge. The |callback| will be called when the dbus call completes.
+ // When the operation completes, the AsyncCallStatusWithDataHandler signal
+ // handler is called.
+ virtual void TpmAttestationSignEnterpriseChallenge(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const std::string& domain,
+ const std::string& device_id,
+ const std::string& challenge,
+ const AsyncMethodCallback& callback) = 0;
+
+ // Asynchronously signs a simple challenge with the key specified by
+ // |key_type| and |key_name|. |challenge| can be any set of arbitrary bytes.
+ // A nonce will be appended to the challenge before signing; this method
+ // cannot be used to sign arbitrary data. The |callback| will be called when
+ // the dbus call completes. When the operation completes, the
+ // AsyncCallStatusWithDataHandler signal handler is called.
+ virtual void TpmAttestationSignSimpleChallenge(
+ AttestationKeyType key_type,
+ const std::string& key_name,
+ const std::string& challenge,
+ const AsyncMethodCallback& callback) = 0;
+
protected:
// Create() should be used instead.
CryptohomeClient();
diff --git a/chromeos/dbus/mock_cryptohome_client.h b/chromeos/dbus/mock_cryptohome_client.h
index eb9b3f3..f40fd1f2 100644
--- a/chromeos/dbus/mock_cryptohome_client.h
+++ b/chromeos/dbus/mock_cryptohome_client.h
@@ -90,6 +90,34 @@ class MockCryptohomeClient : public CryptohomeClient {
AttestationKeyType key_type,
const std::string& key_name,
const AsyncMethodCallback& callback));
+ MOCK_METHOD3(TpmAttestationDoesKeyExist,
+ void(AttestationKeyType key_type,
+ const std::string& key_name,
+ const BoolDBusMethodCallback& callback));
+ MOCK_METHOD3(TpmAttestationGetCertificate,
+ void(AttestationKeyType key_type,
+ const std::string& key_name,
+ const DataMethodCallback& callback));
+ MOCK_METHOD3(TpmAttestationGetPublicKey,
+ void(AttestationKeyType key_type,
+ const std::string& key_name,
+ const DataMethodCallback& callback));
+ MOCK_METHOD3(TpmAttestationRegisterKey,
+ void(AttestationKeyType key_type,
+ const std::string& key_name,
+ const AsyncMethodCallback& callback));
+ MOCK_METHOD6(TpmAttestationSignEnterpriseChallenge,
+ void(AttestationKeyType key_type,
+ const std::string& key_name,
+ const std::string& domain,
+ const std::string& device_id,
+ const std::string& challenge,
+ const AsyncMethodCallback& callback));
+ MOCK_METHOD4(TpmAttestationSignSimpleChallenge,
+ void(AttestationKeyType key_type,
+ const std::string& key_name,
+ const std::string& challenge,
+ const AsyncMethodCallback& callback));
};
} // namespace chromeos