Skip to content

Commit

Permalink
Handle key credential manager (Windows Hello) failure
Browse files Browse the repository at this point in the history
The KeyCredentialManager::RequestCreateAsync call can fail because we
can end up in a situation where Windows Hello is initially available but
then becomes unavailable, such as during a remote desktop session. This
commit prevents a crash by moving the call into the try-catch.

Fixes keepassxreboot#7890, but does not improve the experience yet.
  • Loading branch information
Gibstick committed Jan 19, 2023
1 parent 3e3e87d commit c429f8f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/winhello/WindowsHello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,18 @@ namespace
array_view<uint8_t>(reinterpret_cast<uint8_t*>(challenge.data()), challenge.size()));

return AsyncTask::runAndWaitForFuture([&] {
// The first time this is used a key-pair will be generated using the common name
auto result =
KeyCredentialManager::RequestCreateAsync(s_winHelloKeyName, KeyCredentialCreationOption::FailIfExists)
.get();

if (result.Status() == KeyCredentialStatus::CredentialAlreadyExists) {
result = KeyCredentialManager::OpenAsync(s_winHelloKeyName).get();
} else if (result.Status() != KeyCredentialStatus::Success) {
error = QObject::tr("Failed to create Windows Hello credential.");
return false;
}

try {
// The first time this is used a key-pair will be generated using the common name
auto result =
KeyCredentialManager::RequestCreateAsync(s_winHelloKeyName, KeyCredentialCreationOption::FailIfExists)
.get();

if (result.Status() == KeyCredentialStatus::CredentialAlreadyExists) {
result = KeyCredentialManager::OpenAsync(s_winHelloKeyName).get();
} else if (result.Status() != KeyCredentialStatus::Success) {
error = QObject::tr("Failed to create Windows Hello credential.");
return false;
}
const auto signature = result.Credential().RequestSignAsync(challengeBuffer).get();
if (signature.Status() != KeyCredentialStatus::Success) {
error = QObject::tr("Failed to sign challenge using Windows Hello.");
Expand Down

0 comments on commit c429f8f

Please sign in to comment.