summaryrefslogtreecommitdiffstats
path: root/chromeos/cryptohome
diff options
context:
space:
mode:
authordkrahn@google.com <dkrahn@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-15 06:35:44 +0000
committerdkrahn@google.com <dkrahn@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-15 06:35:44 +0000
commitbccb3df10cb4ae5889f6ad203a96e0cafb673fd7 (patch)
tree089c843ecbc942f50194218c77ac6d666aa78625 /chromeos/cryptohome
parent2b67216b16aa4610b7b65835b0b2ae0b462c0eed (diff)
downloadchromium_src-bccb3df10cb4ae5889f6ad203a96e0cafb673fd7.zip
chromium_src-bccb3df10cb4ae5889f6ad203a96e0cafb673fd7.tar.gz
chromium_src-bccb3df10cb4ae5889f6ad203a96e0cafb673fd7.tar.bz2
Implemented plumbing for cryptohomed attestation calls.
BUG=chromium-os:36561 TEST=chromeos_unittests; manually tested login Review URL: https://chromiumcodereview.appspot.com/11647009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176807 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/cryptohome')
-rw-r--r--chromeos/cryptohome/async_method_caller.cc94
-rw-r--r--chromeos/cryptohome/async_method_caller.h29
-rw-r--r--chromeos/cryptohome/mock_async_method_caller.h9
3 files changed, 127 insertions, 5 deletions
diff --git a/chromeos/cryptohome/async_method_caller.cc b/chromeos/cryptohome/async_method_caller.cc
index c868868..aa25658 100644
--- a/chromeos/cryptohome/async_method_caller.cc
+++ b/chromeos/cryptohome/async_method_caller.cc
@@ -23,14 +23,16 @@ AsyncMethodCaller* g_async_method_caller = NULL;
class AsyncMethodCallerImpl : public AsyncMethodCaller {
public:
AsyncMethodCallerImpl() : weak_ptr_factory_(this) {
- DBusThreadManager::Get()->GetCryptohomeClient()->SetAsyncCallStatusHandler(
+ DBusThreadManager::Get()->GetCryptohomeClient()->SetAsyncCallStatusHandlers(
base::Bind(&AsyncMethodCallerImpl::HandleAsyncResponse,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&AsyncMethodCallerImpl::HandleAsyncDataResponse,
weak_ptr_factory_.GetWeakPtr()));
}
virtual ~AsyncMethodCallerImpl() {
DBusThreadManager::Get()->GetCryptohomeClient()->
- ResetAsyncCallStatusHandler();
+ ResetAsyncCallStatusHandlers();
}
virtual void AsyncCheckKey(const std::string& user_email,
@@ -87,11 +89,52 @@ class AsyncMethodCallerImpl : public AsyncMethodCaller {
"Couldn't initiate async removal of cryptohome."));
}
+ virtual void AsyncTpmAttestationCreateEnrollRequest(
+ const DataCallback& callback) OVERRIDE {
+ DBusThreadManager::Get()->GetCryptohomeClient()->
+ AsyncTpmAttestationCreateEnrollRequest(base::Bind(
+ &AsyncMethodCallerImpl::RegisterAsyncDataCallback,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ "Couldn't initiate async attestation enroll request."));
+ }
+
+ virtual void AsyncTpmAttestationEnroll(const std::string& pca_response,
+ const Callback& callback) OVERRIDE {
+ DBusThreadManager::Get()->GetCryptohomeClient()->
+ AsyncTpmAttestationEnroll(pca_response, base::Bind(
+ &AsyncMethodCallerImpl::RegisterAsyncCallback,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ "Couldn't initiate async attestation enroll."));
+ }
+
+ virtual void AsyncTpmAttestationCreateCertRequest(
+ bool is_cert_for_owner,
+ const DataCallback& callback) OVERRIDE {
+ DBusThreadManager::Get()->GetCryptohomeClient()->
+ AsyncTpmAttestationCreateCertRequest(is_cert_for_owner, base::Bind(
+ &AsyncMethodCallerImpl::RegisterAsyncDataCallback,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ "Couldn't initiate async attestation cert request."));
+ }
+
+ virtual void AsyncTpmAttestationFinishCertRequest(
+ const std::string& pca_response,
+ const DataCallback& callback) OVERRIDE {
+ DBusThreadManager::Get()->GetCryptohomeClient()->
+ AsyncTpmAttestationFinishCertRequest(pca_response, base::Bind(
+ &AsyncMethodCallerImpl::RegisterAsyncDataCallback,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ "Couldn't initiate async attestation finish cert request."));
+ }
+
private:
struct CallbackElement {
CallbackElement() {}
- explicit CallbackElement(
- const AsyncMethodCaller::Callback& callback)
+ explicit CallbackElement(const AsyncMethodCaller::Callback& callback)
: callback(callback),
proxy(base::MessageLoopProxy::current()) {
}
@@ -99,9 +142,21 @@ class AsyncMethodCallerImpl : public AsyncMethodCaller {
scoped_refptr<base::MessageLoopProxy> proxy;
};
+ struct DataCallbackElement {
+ DataCallbackElement() {}
+ explicit DataCallbackElement(
+ const AsyncMethodCaller::DataCallback& callback)
+ : data_callback(callback),
+ proxy(base::MessageLoopProxy::current()) {
+ }
+ AsyncMethodCaller::DataCallback data_callback;
+ scoped_refptr<base::MessageLoopProxy> proxy;
+ };
+
typedef base::hash_map<int, CallbackElement> CallbackMap;
+ typedef base::hash_map<int, DataCallbackElement> DataCallbackMap;
- // Hanldes the response for async calls.
+ // Handles the response for async calls.
// Below is described how async calls work.
// 1. CryptohomeClient::AsyncXXX returns "async ID".
// 2. RegisterAsyncCallback registers the "async ID" with the user-provided
@@ -123,6 +178,20 @@ class AsyncMethodCallerImpl : public AsyncMethodCaller {
callback_map_.erase(it);
}
+ // Similar to HandleAsyncResponse but for signals with a raw data payload.
+ void HandleAsyncDataResponse(int async_id,
+ bool return_status,
+ const std::string& return_data) {
+ const DataCallbackMap::iterator it = data_callback_map_.find(async_id);
+ if (it == data_callback_map_.end()) {
+ LOG(ERROR) << "Received signal for unknown async_id " << async_id;
+ return;
+ }
+ it->second.proxy->PostTask(FROM_HERE,
+ base::Bind(it->second.data_callback, return_status, return_data));
+ data_callback_map_.erase(it);
+ }
+
// Registers a callback which is called when the result for AsyncXXX is ready.
void RegisterAsyncCallback(
Callback callback, const char* error, int async_id) {
@@ -132,11 +201,26 @@ class AsyncMethodCallerImpl : public AsyncMethodCaller {
}
VLOG(1) << "Adding handler for " << async_id;
DCHECK_EQ(callback_map_.count(async_id), 0U);
+ DCHECK_EQ(data_callback_map_.count(async_id), 0U);
callback_map_[async_id] = CallbackElement(callback);
}
+ // Registers a callback which is called when the result for AsyncXXX is ready.
+ void RegisterAsyncDataCallback(
+ DataCallback callback, const char* error, int async_id) {
+ if (async_id == 0) {
+ LOG(ERROR) << error;
+ return;
+ }
+ VLOG(1) << "Adding handler for " << async_id;
+ DCHECK_EQ(callback_map_.count(async_id), 0U);
+ DCHECK_EQ(data_callback_map_.count(async_id), 0U);
+ data_callback_map_[async_id] = DataCallbackElement(callback);
+ }
+
base::WeakPtrFactory<AsyncMethodCallerImpl> weak_ptr_factory_;
CallbackMap callback_map_;
+ DataCallbackMap data_callback_map_;
DISALLOW_COPY_AND_ASSIGN(AsyncMethodCallerImpl);
};
diff --git a/chromeos/cryptohome/async_method_caller.h b/chromeos/cryptohome/async_method_caller.h
index b4ab3ab..c6956ff 100644
--- a/chromeos/cryptohome/async_method_caller.h
+++ b/chromeos/cryptohome/async_method_caller.h
@@ -33,6 +33,8 @@ class CHROMEOS_EXPORT AsyncMethodCaller {
// A callback type which is called back on the UI thread when the results of
// method calls are ready.
typedef base::Callback<void(bool success, MountError return_code)> Callback;
+ typedef base::Callback<void(bool success, const std::string& data)>
+ DataCallback;
virtual ~AsyncMethodCaller() {}
@@ -81,6 +83,33 @@ class CHROMEOS_EXPORT AsyncMethodCaller {
virtual void AsyncRemove(const std::string& user_email,
Callback callback) = 0;
+ // Asks cryptohomed to asynchronously create an attestation enrollment
+ // request. On success the data sent to |callback| is a request to be sent
+ // to the Privacy CA.
+ virtual void AsyncTpmAttestationCreateEnrollRequest(
+ const DataCallback& callback) = 0;
+
+ // Asks cryptohomed to asynchronously finish an attestation enrollment.
+ // |pca_response| is the response to the enrollment request emitted by the
+ // Privacy CA.
+ virtual void AsyncTpmAttestationEnroll(const std::string& pca_response,
+ const Callback& callback) = 0;
+
+ // Asks cryptohomed to asynchronously create an attestation certificate
+ // request. On success the data sent to |callback| is a request to be sent
+ // to the Privacy CA.
+ virtual void AsyncTpmAttestationCreateCertRequest(
+ bool is_cert_for_owner,
+ const DataCallback& callback) = 0;
+
+ // Asks cryptohomed to asynchronously finish an attestation certificate
+ // request. On success the data sent to |callback| is a certificate chain
+ // in PEM format. |pca_response| is the response to the certificate request
+ // emitted by the Privacy CA.
+ virtual void AsyncTpmAttestationFinishCertRequest(
+ const std::string& pca_response,
+ const DataCallback& callback) = 0;
+
// Creates the global AsyncMethodCaller instance.
static void Initialize();
diff --git a/chromeos/cryptohome/mock_async_method_caller.h b/chromeos/cryptohome/mock_async_method_caller.h
index 3d2fdeb..37bc0c44 100644
--- a/chromeos/cryptohome/mock_async_method_caller.h
+++ b/chromeos/cryptohome/mock_async_method_caller.h
@@ -35,6 +35,15 @@ class MockAsyncMethodCaller : public AsyncMethodCaller {
MOCK_METHOD1(AsyncMountGuest, void(Callback callback));
MOCK_METHOD2(AsyncRemove, void(const std::string& user_email,
Callback callback));
+ MOCK_METHOD1(AsyncTpmAttestationCreateEnrollRequest,
+ void(const DataCallback& callback));
+ MOCK_METHOD2(AsyncTpmAttestationEnroll,
+ void(const std::string& pca_response, const Callback& callback));
+ MOCK_METHOD2(AsyncTpmAttestationCreateCertRequest,
+ void(bool is_cert_for_owner, const DataCallback& callback));
+ MOCK_METHOD2(AsyncTpmAttestationFinishCertRequest,
+ void(const std::string& pca_response,
+ const DataCallback& callback));
private:
bool success_;