Commit 3401f00b authored by Matthew Webb's avatar Matthew Webb Committed by Commit Bot

fido/bio: use OnceCallback for enrollment

Clean up the enrollment handler, refactor sequence_checker, and use
BindOnce for EnrollTemplate.

Bug: 974046
Change-Id: I06ddd3caba96f335012cc6cd1c6aa250045b6ed0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1678787
Auto-Submit: Matthew Webb <noviv@google.com>
Reviewed-by: default avatarKim Paulhamus <kpaulhamus@chromium.org>
Reviewed-by: default avatarMartin Kreichgauer <martinkr@google.com>
Commit-Queue: Matthew Webb <noviv@google.com>
Cr-Commit-Position: refs/heads/master@{#672615}
parent abd54457
...@@ -27,43 +27,38 @@ BioEnrollmentHandler::BioEnrollmentHandler( ...@@ -27,43 +27,38 @@ BioEnrollmentHandler::BioEnrollmentHandler(
} }
BioEnrollmentHandler::~BioEnrollmentHandler() { BioEnrollmentHandler::~BioEnrollmentHandler() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
} }
void BioEnrollmentHandler::GetModality(ResponseCallback callback) { void BioEnrollmentHandler::GetModality(ResponseCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(authenticator_); DCHECK(authenticator_);
authenticator_->GetModality(std::move(callback)); authenticator_->GetModality(std::move(callback));
} }
void BioEnrollmentHandler::GetSensorInfo(ResponseCallback callback) { void BioEnrollmentHandler::GetSensorInfo(ResponseCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(authenticator_); DCHECK(authenticator_);
authenticator_->GetSensorInfo(std::move(callback)); authenticator_->GetSensorInfo(std::move(callback));
} }
void BioEnrollmentHandler::EnrollTemplate(ResponseCallback callback) { void BioEnrollmentHandler::EnrollTemplate(ResponseCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!enroll_callback_);
enroll_callback_ = std::move(callback);
authenticator_->BioEnrollFingerprint( authenticator_->BioEnrollFingerprint(
*pin_token_response_, *pin_token_response_,
base::BindRepeating(&BioEnrollmentHandler::OnEnrollTemplate, base::BindOnce(&BioEnrollmentHandler::OnEnrollTemplate,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr(), std::move(callback)));
} }
void BioEnrollmentHandler::Cancel(StatusCallback callback) { void BioEnrollmentHandler::Cancel(StatusCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
authenticator_->BioEnrollCancel( authenticator_->BioEnrollCancel(
base::BindOnce(&BioEnrollmentHandler::OnCancel, base::BindOnce(&BioEnrollmentHandler::OnCancel,
weak_factory_.GetWeakPtr(), std::move(callback))); weak_factory_.GetWeakPtr(), std::move(callback)));
} }
void BioEnrollmentHandler::EnumerateTemplates(ResponseCallback callback) { void BioEnrollmentHandler::EnumerateTemplates(ResponseCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
authenticator_->BioEnrollEnumerate( authenticator_->BioEnrollEnumerate(
*pin_token_response_, *pin_token_response_,
base::BindOnce(&BioEnrollmentHandler::OnEnumerateTemplates, base::BindOnce(&BioEnrollmentHandler::OnEnumerateTemplates,
...@@ -73,8 +68,7 @@ void BioEnrollmentHandler::EnumerateTemplates(ResponseCallback callback) { ...@@ -73,8 +68,7 @@ void BioEnrollmentHandler::EnumerateTemplates(ResponseCallback callback) {
void BioEnrollmentHandler::RenameTemplate(std::vector<uint8_t> id, void BioEnrollmentHandler::RenameTemplate(std::vector<uint8_t> id,
std::string name, std::string name,
StatusCallback callback) { StatusCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
authenticator_->BioEnrollRename( authenticator_->BioEnrollRename(
*pin_token_response_, std::move(id), std::move(name), *pin_token_response_, std::move(id), std::move(name),
base::BindOnce(&BioEnrollmentHandler::OnRenameTemplate, base::BindOnce(&BioEnrollmentHandler::OnRenameTemplate,
...@@ -83,8 +77,7 @@ void BioEnrollmentHandler::RenameTemplate(std::vector<uint8_t> id, ...@@ -83,8 +77,7 @@ void BioEnrollmentHandler::RenameTemplate(std::vector<uint8_t> id,
void BioEnrollmentHandler::DeleteTemplate(std::vector<uint8_t> id, void BioEnrollmentHandler::DeleteTemplate(std::vector<uint8_t> id,
StatusCallback callback) { StatusCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
authenticator_->BioEnrollDelete( authenticator_->BioEnrollDelete(
*pin_token_response_, std::move(id), *pin_token_response_, std::move(id),
base::BindOnce(&BioEnrollmentHandler::OnDeleteTemplate, base::BindOnce(&BioEnrollmentHandler::OnDeleteTemplate,
...@@ -92,7 +85,7 @@ void BioEnrollmentHandler::DeleteTemplate(std::vector<uint8_t> id, ...@@ -92,7 +85,7 @@ void BioEnrollmentHandler::DeleteTemplate(std::vector<uint8_t> id,
} }
void BioEnrollmentHandler::DispatchRequest(FidoAuthenticator* authenticator) { void BioEnrollmentHandler::DispatchRequest(FidoAuthenticator* authenticator) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
authenticator->GetTouch(base::BindOnce(&BioEnrollmentHandler::OnTouch, authenticator->GetTouch(base::BindOnce(&BioEnrollmentHandler::OnTouch,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(),
authenticator)); authenticator));
...@@ -101,7 +94,7 @@ void BioEnrollmentHandler::DispatchRequest(FidoAuthenticator* authenticator) { ...@@ -101,7 +94,7 @@ void BioEnrollmentHandler::DispatchRequest(FidoAuthenticator* authenticator) {
void BioEnrollmentHandler::AuthenticatorRemoved( void BioEnrollmentHandler::AuthenticatorRemoved(
FidoDiscoveryBase* discovery, FidoDiscoveryBase* discovery,
FidoAuthenticator* authenticator) { FidoAuthenticator* authenticator) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
FidoRequestHandlerBase::AuthenticatorRemoved(discovery, authenticator); FidoRequestHandlerBase::AuthenticatorRemoved(discovery, authenticator);
if (authenticator_ != authenticator) { if (authenticator_ != authenticator) {
return; return;
...@@ -138,7 +131,7 @@ void BioEnrollmentHandler::OnTouch(FidoAuthenticator* authenticator) { ...@@ -138,7 +131,7 @@ void BioEnrollmentHandler::OnTouch(FidoAuthenticator* authenticator) {
void BioEnrollmentHandler::OnRetriesResponse( void BioEnrollmentHandler::OnRetriesResponse(
CtapDeviceResponseCode code, CtapDeviceResponseCode code,
base::Optional<pin::RetriesResponse> response) { base::Optional<pin::RetriesResponse> response) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!response || code != CtapDeviceResponseCode::kSuccess) { if (!response || code != CtapDeviceResponseCode::kSuccess) {
FIDO_LOG(DEBUG) << "OnRetriesResponse failed: " << static_cast<int>(code); FIDO_LOG(DEBUG) << "OnRetriesResponse failed: " << static_cast<int>(code);
std::move(error_callback_) std::move(error_callback_)
...@@ -157,8 +150,7 @@ void BioEnrollmentHandler::OnRetriesResponse( ...@@ -157,8 +150,7 @@ void BioEnrollmentHandler::OnRetriesResponse(
} }
void BioEnrollmentHandler::OnHavePIN(std::string pin) { void BioEnrollmentHandler::OnHavePIN(std::string pin) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
authenticator_->GetEphemeralKey( authenticator_->GetEphemeralKey(
base::BindOnce(&BioEnrollmentHandler::OnHaveEphemeralKey, base::BindOnce(&BioEnrollmentHandler::OnHaveEphemeralKey,
weak_factory_.GetWeakPtr(), std::move(pin))); weak_factory_.GetWeakPtr(), std::move(pin)));
...@@ -211,22 +203,22 @@ void BioEnrollmentHandler::OnHavePINToken( ...@@ -211,22 +203,22 @@ void BioEnrollmentHandler::OnHavePINToken(
} }
void BioEnrollmentHandler::OnEnrollTemplate( void BioEnrollmentHandler::OnEnrollTemplate(
ResponseCallback callback,
CtapDeviceResponseCode code, CtapDeviceResponseCode code,
base::Optional<BioEnrollmentResponse> response) { base::Optional<BioEnrollmentResponse> response) {
if (code != CtapDeviceResponseCode::kSuccess) { if (code != CtapDeviceResponseCode::kSuccess) {
// Response is not valid if operation was not successful. // Response is not valid if operation was not successful.
std::move(enroll_callback_).Run(code, base::nullopt); std::move(callback).Run(code, base::nullopt);
return; return;
} }
if (!response || !response->last_status || !response->remaining_samples) { if (!response || !response->last_status || !response->remaining_samples) {
std::move(enroll_callback_) std::move(callback).Run(CtapDeviceResponseCode::kCtap2ErrOther,
.Run(CtapDeviceResponseCode::kCtap2ErrOther, base::nullopt); base::nullopt);
return; return;
} }
FIDO_LOG(DEBUG) << "Finished bio enrollment with code " FIDO_LOG(DEBUG) << "Finished bio enrollment with code "
<< static_cast<int>(code); << static_cast<int>(code);
std::move(enroll_callback_).Run(code, std::move(response)); std::move(callback).Run(code, std::move(response));
// TODO(noviv): Test calling OnEnrollTemplate multiple times.
} }
void BioEnrollmentHandler::OnCancel(StatusCallback callback, void BioEnrollmentHandler::OnCancel(StatusCallback callback,
......
...@@ -65,7 +65,8 @@ class COMPONENT_EXPORT(DEVICE_FIDO) BioEnrollmentHandler ...@@ -65,7 +65,8 @@ class COMPONENT_EXPORT(DEVICE_FIDO) BioEnrollmentHandler
base::Optional<pin::KeyAgreementResponse>); base::Optional<pin::KeyAgreementResponse>);
void OnHavePINToken(CtapDeviceResponseCode, void OnHavePINToken(CtapDeviceResponseCode,
base::Optional<pin::TokenResponse>); base::Optional<pin::TokenResponse>);
void OnEnrollTemplate(CtapDeviceResponseCode, void OnEnrollTemplate(ResponseCallback,
CtapDeviceResponseCode,
base::Optional<BioEnrollmentResponse>); base::Optional<BioEnrollmentResponse>);
void OnCancel(StatusCallback, void OnCancel(StatusCallback,
CtapDeviceResponseCode, CtapDeviceResponseCode,
...@@ -80,13 +81,12 @@ class COMPONENT_EXPORT(DEVICE_FIDO) BioEnrollmentHandler ...@@ -80,13 +81,12 @@ class COMPONENT_EXPORT(DEVICE_FIDO) BioEnrollmentHandler
CtapDeviceResponseCode, CtapDeviceResponseCode,
base::Optional<BioEnrollmentResponse>); base::Optional<BioEnrollmentResponse>);
SEQUENCE_CHECKER(sequence_checker); SEQUENCE_CHECKER(sequence_checker_);
FidoAuthenticator* authenticator_ = nullptr; FidoAuthenticator* authenticator_ = nullptr;
base::OnceClosure ready_callback_; base::OnceClosure ready_callback_;
ErrorCallback error_callback_; ErrorCallback error_callback_;
GetPINCallback get_pin_callback_; GetPINCallback get_pin_callback_;
ResponseCallback enroll_callback_;
base::Optional<pin::TokenResponse> pin_token_response_; base::Optional<pin::TokenResponse> pin_token_response_;
base::WeakPtrFactory<BioEnrollmentHandler> weak_factory_; base::WeakPtrFactory<BioEnrollmentHandler> weak_factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment