Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Unified Diff: chromeos/dbus/fake_cryptohome_client.cc

Issue 2297193006: Do a better job at faking simple challenge signatures. (Closed)
Patch Set: Added missing attestation.proto file. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..30f0a61d6ec18876c9a49b6fbb381e2ace929a2e 100644
--- a/chromeos/dbus/fake_cryptohome_client.cc
+++ b/chromeos/dbus/fake_cryptohome_client.cc
@@ -15,6 +15,7 @@
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chromeos/chromeos_paths.h"
+#include "chromeos/cryptohome/attestation.pb.h"
#include "chromeos/dbus/cryptohome/key.pb.h"
#include "chromeos/dbus/cryptohome/rpc.pb.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
@@ -24,6 +25,13 @@
namespace chromeos {
+namespace {
+// Signature nonces are twenty bytes. This matches the attestation code.
+const char kTwentyBytesNonce[] = "+addtwentybytesnonce";
xiyuan 2016/09/06 22:32:32 nit: const -> constexpr
+// A symbolic signature.
+const char kSignature[] = "signed";
+}
xiyuan 2016/09/06 22:32:32 nit: append "// namespace" after the closing }
The one and only Dr. Crash 2016/09/07 02:43:47 Done.
+
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);
+ cryptohome::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_;
}

Powered by Google App Engine
This is Rietveld 408576698