Commit d7c7af71 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Passwords] Remove kCredUIPromptForWindowsCredentialsFeature

This change removes the kCredUIPromptForWindowsCredentialsFeature flag,
which made it possible to fallback to the legacy authentication logic.
Using the new logic making use of CredUIPromptForWindowsCredentials is
confirmed to work correctly, which is why this removal is safe.

Bug: 574581, 1126051
Change-Id: Iee54bdbe845b7acb3a452309b94fe62aa5f61174
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2406213
Auto-Submit: Jan Wilken Dörrie <jdoerrie@chromium.org>
Commit-Queue: Vasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806169}
parent 6b3f36e8
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -62,13 +61,6 @@ enum OsPasswordStatus { ...@@ -62,13 +61,6 @@ enum OsPasswordStatus {
const unsigned kMaxPasswordRetries = 3; const unsigned kMaxPasswordRetries = 3;
const unsigned kCredUiDefaultFlags =
CREDUI_FLAGS_GENERIC_CREDENTIALS |
CREDUI_FLAGS_EXCLUDE_CERTIFICATES |
CREDUI_FLAGS_KEEP_USERNAME |
CREDUI_FLAGS_ALWAYS_SHOW_UI |
CREDUI_FLAGS_DO_NOT_PERSIST;
struct PasswordCheckPrefs { struct PasswordCheckPrefs {
PasswordCheckPrefs() : pref_last_changed_(0), blank_password_(false) {} PasswordCheckPrefs() : pref_last_changed_(0), blank_password_(false) {}
...@@ -190,11 +182,6 @@ std::unique_ptr<char[]> CredentialBufferValidator::GetTokenInformation( ...@@ -190,11 +182,6 @@ std::unique_ptr<char[]> CredentialBufferValidator::GetTokenInformation(
return token_info_buffer; return token_info_buffer;
} }
// TODO(crbug.com/574581) Remove this feature once this is confirmed to work
// as expected.
const base::Feature kCredUIPromptForWindowsCredentialsFeature{
"CredUIPromptForWindowsCredentials", base::FEATURE_ENABLED_BY_DEFAULT};
void PasswordCheckPrefs::Read(PrefService* local_state) { void PasswordCheckPrefs::Read(PrefService* local_state) {
blank_password_ = blank_password_ =
local_state->GetBoolean(password_manager::prefs::kOsPasswordBlank); local_state->GetBoolean(password_manager::prefs::kOsPasswordBlank);
...@@ -351,128 +338,10 @@ void GetOsPasswordStatus() { ...@@ -351,128 +338,10 @@ void GetOsPasswordStatus() {
base::Passed(&status))); base::Passed(&status)));
} }
// Authenticate the user using the old Windows credential prompt. } // namespace
// TODO(crbug.com/574581) Remove this feature once this is confirmed to work
// as expected.
bool AuthenticateUserOld(gfx::NativeWindow window,
password_manager::ReauthPurpose purpose) {
bool retval = false;
CREDUI_INFO cui = {};
WCHAR username[CREDUI_MAX_USERNAME_LENGTH+1] = {};
WCHAR displayname[CREDUI_MAX_USERNAME_LENGTH+1] = {};
WCHAR password[CREDUI_MAX_PASSWORD_LENGTH+1] = {};
DWORD username_length = CREDUI_MAX_USERNAME_LENGTH;
base::string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
base::string16 password_prompt;
switch (purpose) {
case password_manager::ReauthPurpose::VIEW_PASSWORD:
password_prompt =
l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_AUTHENTICATION_PROMPT);
break;
case password_manager::ReauthPurpose::COPY_PASSWORD:
password_prompt = l10n_util::GetStringUTF16(
IDS_PASSWORDS_PAGE_COPY_AUTHENTICATION_PROMPT);
break;
case password_manager::ReauthPurpose::EDIT_PASSWORD:
password_prompt = l10n_util::GetStringUTF16(
IDS_PASSWORDS_PAGE_EDIT_AUTHENTICATION_PROMPT);
break;
case password_manager::ReauthPurpose::EXPORT:
password_prompt = l10n_util::GetStringUTF16(
IDS_PASSWORDS_PAGE_EXPORT_AUTHENTICATION_PROMPT);
break;
}
HANDLE handle = INVALID_HANDLE_VALUE;
size_t tries = 0;
bool use_displayname = false;
bool use_principalname = false;
DWORD logon_result = 0;
// On a domain, we obtain the User Principal Name
// for domain authentication.
if (GetUserNameEx(NameUserPrincipal, username, &username_length)) {
use_principalname = true;
} else {
username_length = CREDUI_MAX_USERNAME_LENGTH;
// Otherwise, we're a workstation, use the plain local username.
if (!GetUserName(username, &username_length)) {
DLOG(ERROR) << "Unable to obtain username " << GetLastError();
return false;
} else {
// As we are on a workstation, it's possible the user
// has no password, so check here.
if (CheckBlankPassword(username))
return true;
}
}
// Try and obtain a friendly display name.
username_length = CREDUI_MAX_USERNAME_LENGTH;
if (GetUserNameEx(NameDisplay, displayname, &username_length))
use_displayname = true;
cui.cbSize = sizeof(CREDUI_INFO);
cui.hwndParent = NULL;
cui.hwndParent = window->GetHost()->GetAcceleratedWidget();
cui.pszMessageText = password_prompt.c_str();
cui.pszCaptionText = product_name.c_str();
cui.hbmBanner = NULL;
BOOL save_password = FALSE;
DWORD credErr = NO_ERROR;
do {
tries++;
// TODO(wfh) Make sure we support smart cards here.
credErr = CredUIPromptForCredentials(
&cui,
product_name.c_str(),
NULL,
0,
use_displayname ? displayname : username,
CREDUI_MAX_USERNAME_LENGTH+1,
password,
CREDUI_MAX_PASSWORD_LENGTH+1,
&save_password,
kCredUiDefaultFlags |
(tries > 1 ? CREDUI_FLAGS_INCORRECT_PASSWORD : 0));
if (credErr == NO_ERROR) {
logon_result = LogonUser(username,
use_principalname ? NULL : L".",
password,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
&handle);
if (logon_result) {
retval = true;
CloseHandle(handle);
} else {
if (GetLastError() == ERROR_ACCOUNT_RESTRICTION &&
wcslen(password) == 0) {
// Password is blank, so permit.
retval = true;
} else {
DLOG(WARNING) << "Unable to authenticate " << GetLastError();
}
}
SecureZeroMemory(password, sizeof(password));
}
} while (credErr == NO_ERROR &&
(retval == false && tries < kMaxPasswordRetries));
return retval;
}
// Authenticate the user using the new Windows credential prompt. The new bool AuthenticateUser(gfx::NativeWindow window,
// prompt allows the user to authenticate using additional credential providers, password_manager::ReauthPurpose purpose) {
// such as PINs, smartcards, fingerprint scanners, and so on. It also still
// allows the user to authenticate with their password. This old prompt only
// supported password authentication which is not enough for enterprise
// environments.
bool AuthenticateUserNew(gfx::NativeWindow window,
password_manager::ReauthPurpose purpose) {
bool retval = false; bool retval = false;
WCHAR cur_username[CREDUI_MAX_USERNAME_LENGTH + 1] = {}; WCHAR cur_username[CREDUI_MAX_USERNAME_LENGTH + 1] = {};
DWORD cur_username_length = base::size(cur_username); DWORD cur_username_length = base::size(cur_username);
...@@ -553,19 +422,10 @@ bool AuthenticateUserNew(gfx::NativeWindow window, ...@@ -553,19 +422,10 @@ bool AuthenticateUserNew(gfx::NativeWindow window,
return retval; return retval;
} }
} // namespace
void DelayReportOsPassword() { void DelayReportOsPassword() {
content::GetUIThreadTaskRunner({})->PostDelayedTask( content::GetUIThreadTaskRunner({})->PostDelayedTask(
FROM_HERE, base::BindOnce(&GetOsPasswordStatus), FROM_HERE, base::BindOnce(&GetOsPasswordStatus),
base::TimeDelta::FromSeconds(40)); base::TimeDelta::FromSeconds(40));
} }
bool AuthenticateUser(gfx::NativeWindow window,
password_manager::ReauthPurpose purpose) {
return base::FeatureList::IsEnabled(kCredUIPromptForWindowsCredentialsFeature)
? AuthenticateUserNew(window, purpose)
: AuthenticateUserOld(window, purpose);
}
} // namespace password_manager_util_win } // namespace password_manager_util_win
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