Index: chromeos/dbus/fake_cryptohome_client.cc |
diff --git a/chromeos/dbus/fake_cryptohome_client.cc b/chromeos/dbus/fake_cryptohome_client.cc |
index 1ec74fdbe3fafc50a73d9552e6ff2d17c978ea9f..063582e78372703b08da9a4a666ed6419362f6eb 100644 |
--- a/chromeos/dbus/fake_cryptohome_client.cc |
+++ b/chromeos/dbus/fake_cryptohome_client.cc |
@@ -14,6 +14,7 @@ |
#include "base/single_thread_task_runner.h" |
#include "base/threading/thread_restrictions.h" |
#include "base/threading/thread_task_runner_handle.h" |
+#include "chromeos/attestation/attestation.pb.h" |
#include "chromeos/chromeos_paths.h" |
#include "chromeos/dbus/cryptohome/key.pb.h" |
#include "chromeos/dbus/cryptohome/rpc.pb.h" |
@@ -24,6 +25,13 @@ |
namespace chromeos { |
+namespace { |
+// Signature nonces are twenty bytes. This matches the attestation code. |
+constexpr char kTwentyBytesNonce[] = "+addtwentybytesnonce"; |
+// A symbolic signature. |
+constexpr char kSignature[] = "signed"; |
+} // namespace |
+ |
FakeCryptohomeClient::FakeCryptohomeClient() |
: service_is_available_(true), |
async_call_id_(1), |
@@ -80,7 +88,7 @@ void FakeCryptohomeClient::AsyncCheckKey( |
const cryptohome::Identification& cryptohome_id, |
const std::string& key, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, false); |
+ ReturnAsyncMethodResult(callback); |
} |
void FakeCryptohomeClient::AsyncMigrateKey( |
@@ -88,13 +96,13 @@ void FakeCryptohomeClient::AsyncMigrateKey( |
const std::string& from_key, |
const std::string& to_key, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, false); |
+ ReturnAsyncMethodResult(callback); |
} |
void FakeCryptohomeClient::AsyncRemove( |
const cryptohome::Identification& cryptohome_id, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, false); |
+ ReturnAsyncMethodResult(callback); |
} |
void FakeCryptohomeClient::RenameCryptohome( |
@@ -143,7 +151,7 @@ void FakeCryptohomeClient::AsyncMount( |
const std::string& key, |
int flags, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, false); |
+ ReturnAsyncMethodResult(callback); |
} |
void FakeCryptohomeClient::AsyncAddKey( |
@@ -151,19 +159,19 @@ void FakeCryptohomeClient::AsyncAddKey( |
const std::string& key, |
const std::string& new_key, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, false); |
+ ReturnAsyncMethodResult(callback); |
} |
void FakeCryptohomeClient::AsyncMountGuest( |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, false); |
+ ReturnAsyncMethodResult(callback); |
} |
void FakeCryptohomeClient::AsyncMountPublic( |
const cryptohome::Identification& public_mount_id, |
int flags, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, false); |
+ ReturnAsyncMethodResult(callback); |
} |
void FakeCryptohomeClient::TpmIsReady( |
@@ -366,14 +374,14 @@ void FakeCryptohomeClient::TpmAttestationIsEnrolled( |
void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest( |
chromeos::attestation::PrivacyCAType pca_type, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, true); |
+ ReturnAsyncMethodData(callback, std::string()); |
} |
void FakeCryptohomeClient::AsyncTpmAttestationEnroll( |
chromeos::attestation::PrivacyCAType pca_type, |
const std::string& pca_response, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, false); |
+ ReturnAsyncMethodResult(callback); |
} |
void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( |
@@ -382,7 +390,7 @@ void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( |
const cryptohome::Identification& cryptohome_id, |
const std::string& request_origin, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, true); |
+ ReturnAsyncMethodData(callback, std::string()); |
} |
void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest( |
@@ -391,7 +399,7 @@ void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest( |
const cryptohome::Identification& cryptohome_id, |
const std::string& key_name, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, true); |
+ ReturnAsyncMethodData(callback, std::string()); |
} |
void FakeCryptohomeClient::TpmAttestationDoesKeyExist( |
@@ -428,7 +436,7 @@ void FakeCryptohomeClient::TpmAttestationRegisterKey( |
const cryptohome::Identification& cryptohome_id, |
const std::string& key_name, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, true); |
+ ReturnAsyncMethodData(callback, std::string()); |
} |
void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge( |
@@ -440,7 +448,7 @@ void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge( |
attestation::AttestationChallengeOptions options, |
const std::string& challenge, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, true); |
+ ReturnAsyncMethodData(callback, std::string()); |
} |
void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( |
@@ -449,7 +457,10 @@ void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( |
const std::string& key_name, |
const std::string& challenge, |
const AsyncMethodCallback& callback) { |
- ReturnAsyncMethodResult(callback, true); |
+ chromeos::attestation::SignedData signed_data; |
+ signed_data.set_data(challenge + kTwentyBytesNonce); |
+ signed_data.set_signature(kSignature); |
+ ReturnAsyncMethodData(callback, signed_data.SerializeAsString()); |
} |
void FakeCryptohomeClient::TpmAttestationGetKeyPayload( |
@@ -588,26 +599,41 @@ void FakeCryptohomeClient::ReturnProtobufMethodCallback( |
} |
void FakeCryptohomeClient::ReturnAsyncMethodResult( |
- const AsyncMethodCallback& callback, |
- bool returns_data) { |
+ const AsyncMethodCallback& callback) { |
base::ThreadTaskRunnerHandle::Get()->PostTask( |
FROM_HERE, |
base::Bind(&FakeCryptohomeClient::ReturnAsyncMethodResultInternal, |
- weak_ptr_factory_.GetWeakPtr(), callback, returns_data)); |
+ weak_ptr_factory_.GetWeakPtr(), callback)); |
} |
-void FakeCryptohomeClient::ReturnAsyncMethodResultInternal( |
+void FakeCryptohomeClient::ReturnAsyncMethodData( |
const AsyncMethodCallback& callback, |
- bool returns_data) { |
+ const std::string& data) { |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&FakeCryptohomeClient::ReturnAsyncMethodDataInternal, |
+ weak_ptr_factory_.GetWeakPtr(), callback, data)); |
+} |
+ |
+void FakeCryptohomeClient::ReturnAsyncMethodResultInternal( |
+ const AsyncMethodCallback& callback) { |
callback.Run(async_call_id_); |
- if (!returns_data && !async_call_status_handler_.is_null()) { |
+ if (!async_call_status_handler_.is_null()) { |
base::ThreadTaskRunnerHandle::Get()->PostTask( |
FROM_HERE, base::Bind(async_call_status_handler_, async_call_id_, true, |
cryptohome::MOUNT_ERROR_NONE)); |
- } else if (returns_data && !async_call_status_data_handler_.is_null()) { |
+ } |
+ ++async_call_id_; |
+} |
+ |
+void FakeCryptohomeClient::ReturnAsyncMethodDataInternal( |
+ const AsyncMethodCallback& callback, |
+ const std::string& data) { |
+ callback.Run(async_call_id_); |
+ if (!async_call_status_data_handler_.is_null()) { |
base::ThreadTaskRunnerHandle::Get()->PostTask( |
FROM_HERE, base::Bind(async_call_status_data_handler_, async_call_id_, |
- true, std::string())); |
+ true, data)); |
} |
++async_call_id_; |
} |