diff options
author | altimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-20 12:01:11 +0000 |
---|---|---|
committer | altimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-20 12:01:11 +0000 |
commit | d55864e9e69f5fd4fd98b9482ed5fc461fbfb584 (patch) | |
tree | cdd280a627b08ebd5473168424730ca6acb6ad2e | |
parent | 21766d7536424c43a8d677bedeb8c81e6cce41c7 (diff) | |
download | chromium_src-d55864e9e69f5fd4fd98b9482ed5fc461fbfb584.zip chromium_src-d55864e9e69f5fd4fd98b9482ed5fc461fbfb584.tar.gz chromium_src-d55864e9e69f5fd4fd98b9482ed5fc461fbfb584.tar.bz2 |
Adds spinner to the Tpm-password screen password.
Spinner is added to the Tpm-password screen. Also some stubs for working
with Cryptohome was implemented.
BUG=chromium-os:7134
TEST=On EULA screen click on "System security settings", notice spinner
is rotating until TPM password is ready.
Review URL: http://codereview.chromium.org/3832011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63203 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 2 | ||||
-rw-r--r-- | chrome/app/resources/locale_settings.grd | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/cryptohome_library.cc | 55 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/cryptohome_library.h | 26 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/mock_cryptohome_library.h | 8 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/eula_view.cc | 134 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/eula_view.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_utils.cc | 14 |
8 files changed, 202 insertions, 43 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 10cd03d..110bdf7 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -9292,7 +9292,7 @@ Keep your key file in a safe place. You will need it to create new versions of y The TPM is being set up. Please be patient; this may take a few minutes. </message> <message name="IDS_EULA_TPM_BUSY" desc="Message bubble text"> - TPM is not ready yet, try later. + TPM is being prepared, please wait (this may take a few minutes)... </message> <message name="IDS_EULA_TPM_DISABLED" desc="Tooltip text describing why 'System security setting' link is disabled."> Trusted Platform Module (TPM) chip is disabled or absent. diff --git a/chrome/app/resources/locale_settings.grd b/chrome/app/resources/locale_settings.grd index bbe300f..ed25b39 100644 --- a/chrome/app/resources/locale_settings.grd +++ b/chrome/app/resources/locale_settings.grd @@ -728,10 +728,10 @@ <!-- The width and height of the TPM setting dialog box in --> <!-- characters and lines (See above). --> <message name="IDS_TPM_INFO_DIALOG_WIDTH_CHARS" use_name_for_id="true"> - 60 + 80 </message> <message name="IDS_TPM_INFO_DIALOG_HEIGHT_LINES" use_name_for_id="true"> - 12 + 10 </message> <!-- The width and height of the password changed dialog box in --> diff --git a/chrome/browser/chromeos/cros/cryptohome_library.cc b/chrome/browser/chromeos/cros/cryptohome_library.cc index e0a4709..52ce85c 100644 --- a/chrome/browser/chromeos/cros/cryptohome_library.cc +++ b/chrome/browser/chromeos/cros/cryptohome_library.cc @@ -108,6 +108,34 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary { return chromeos::CryptohomeGetSystemSalt(); } + bool TpmIsReady() { + return chromeos::CryptohomeTpmIsReady(); + } + + bool TpmIsEnabled() { + return chromeos::CryptohomeTpmIsEnabled(); + } + + bool TpmIsOwned() { + return chromeos::CryptohomeTpmIsOwned(); + } + + bool TpmIsBeingOwned() { + return chromeos::CryptohomeTpmIsBeingOwned(); + } + + bool TpmGetPassword(std::string* password) { + return chromeos::CryptohomeTpmGetPassword(password); + } + + void TpmCanAttemptOwnership() { + chromeos::CryptohomeTpmCanAttemptOwnership(); + } + + void TpmClearStoredPassword() { + chromeos::CryptohomeTpmClearStoredPassword(); + } + private: static void Handler(const chromeos::CryptohomeAsyncCallStatus& event, void* cryptohome_library) { @@ -235,6 +263,33 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary { return salt; } + // Tpm begin ready after 20-th call. + bool TpmIsReady() { + static int counter = 0; + return ++counter > 20; + } + + bool TpmIsEnabled() { + return true; + } + + bool TpmIsOwned() { + return true; + } + + bool TpmIsBeingOwned() { + return true; + } + + bool TpmGetPassword(std::string* password) { + *password = "Stub-TPM-password"; + return true; + } + + void TpmCanAttemptOwnership() {} + + void TpmClearStoredPassword() {} + private: static void DoStubCallback(Delegate* callback) { callback->OnComplete(true, kCryptohomeMountErrorNone); diff --git a/chrome/browser/chromeos/cros/cryptohome_library.h b/chrome/browser/chromeos/cros/cryptohome_library.h index 5687c5c..0daa2b5 100644 --- a/chrome/browser/chromeos/cros/cryptohome_library.h +++ b/chrome/browser/chromeos/cros/cryptohome_library.h @@ -103,6 +103,32 @@ class CryptohomeLibrary { // Asks cryptohomed for the system salt. virtual CryptohomeBlob GetSystemSalt() = 0; + + // Wrappers of the functions for working with Tpm. + + // Returns whether Tpm is ready. + virtual bool TpmIsReady() = 0; + + // Returns whether Tpm is presented and enabled. + virtual bool TpmIsEnabled() = 0; + + // Returns whether device has already been owned. + virtual bool TpmIsOwned() = 0; + + // Returns whether device is being owned (Tpm password is generating). + virtual bool TpmIsBeingOwned() = 0; + + // Returns Tpm password (if password was cleared empty one is returned). + // Return value is true if password was successfully acquired. + virtual bool TpmGetPassword(std::string* password) = 0; + + // Attempts to start owning (if device isn't owned and isn't being owned). + virtual void TpmCanAttemptOwnership() = 0; + + // Clears Tpm password. Password should be cleared after it was generated and + // shown to user. + virtual void TpmClearStoredPassword() = 0; + // Factory function, creates a new instance and returns ownership. // For normal usage, access the singleton via CrosLibrary::Get(). static CryptohomeLibrary* GetImpl(bool stub); diff --git a/chrome/browser/chromeos/cros/mock_cryptohome_library.h b/chrome/browser/chromeos/cros/mock_cryptohome_library.h index c109b91..a35d6a0 100644 --- a/chrome/browser/chromeos/cros/mock_cryptohome_library.h +++ b/chrome/browser/chromeos/cros/mock_cryptohome_library.h @@ -68,6 +68,14 @@ class MockCryptohomeLibrary : public CryptohomeLibrary { MOCK_METHOD0(IsMounted, bool(void)); MOCK_METHOD0(GetSystemSalt, CryptohomeBlob(void)); + MOCK_METHOD0(TpmIsReady, bool(void)); + MOCK_METHOD0(TpmIsEnabled, bool(void)); + MOCK_METHOD0(TpmIsOwned, bool(void)); + MOCK_METHOD0(TpmIsBeingOwned, bool(void)); + MOCK_METHOD1(TpmGetPassword, bool(std::string* password)); + MOCK_METHOD0(TpmCanAttemptOwnership, void(void)); + MOCK_METHOD0(TpmClearStoredPassword, void(void)); + void SetAsyncBehavior(bool outcome, int code) { outcome_ = outcome; code_ = code; diff --git a/chrome/browser/chromeos/login/eula_view.cc b/chrome/browser/chromeos/login/eula_view.cc index c928334..cbd3080 100644 --- a/chrome/browser/chromeos/login/eula_view.cc +++ b/chrome/browser/chromeos/login/eula_view.cc @@ -11,13 +11,17 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/basictypes.h" +#include "base/message_loop.h" +#include "base/task.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/cryptohome_library.h" #include "chrome/browser/chromeos/cros_settings_provider_stats.h" #include "chrome/browser/chromeos/customization_document.h" #include "chrome/browser/chromeos/login/help_app_launcher.h" +#include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/chromeos/login/network_screen_delegate.h" #include "chrome/browser/chromeos/login/rounded_rect_painter.h" #include "chrome/browser/chromeos/login/wizard_controller.h" @@ -28,7 +32,6 @@ #include "chrome/browser/views/window.h" #include "chrome/common/native_web_keyboard_event.h" #include "chrome/common/url_constants.h" -#include "cros/chromeos_cryptohome.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" @@ -36,6 +39,7 @@ #include "views/controls/button/checkbox.h" #include "views/controls/button/native_button.h" #include "views/controls/label.h" +#include "views/controls/throbber.h" #include "views/grid_layout.h" #include "views/layout_manager.h" #include "views/standard_layout.h" @@ -48,10 +52,11 @@ using views::WidgetGtk; namespace { const int kBorderSize = 10; -const int kMargin = 20; -const int kLastButtonHorizontalMargin = 10; const int kCheckBowWidth = 22; +const int kLastButtonHorizontalMargin = 10; +const int kMargin = 20; const int kTextMargin = 10; +const int kTpmCheckIntervalMs = 500; // TODO(glotov): this URL should be changed to actual Google ChromeOS EULA. // See crbug.com/4647 @@ -81,7 +86,12 @@ struct FillLayoutWithBorder : public views::LayoutManager { class TpmInfoView : public views::View, public views::DialogDelegate { public: - explicit TpmInfoView(std::wstring password) : password_(password) { } + explicit TpmInfoView(std::string* password) + : ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)), + password_(password) { + DCHECK(password_); + } + void Init(); protected: @@ -105,7 +115,17 @@ class TpmInfoView : public views::View, } private: - std::wstring password_; + void PullPassword(); + + ScopedRunnableMethodFactory<TpmInfoView> runnable_method_factory_; + + // Holds pointer to the password storage. + std::string* password_; + + views::Label* busy_label_; + views::Label* password_label_; + views::Throbber* throbber_; + DISALLOW_COPY_AND_ASSIGN(TpmInfoView); }; @@ -119,6 +139,7 @@ void TpmInfoView::Init() { views::Label* label = new views::Label( l10n_util::GetString(IDS_EULA_SYSTEM_SECURITY_SETTING_DESCRIPTION)); label->SetMultiLine(true); + label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); layout->AddView(label); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); @@ -126,6 +147,7 @@ void TpmInfoView::Init() { label = new views::Label( l10n_util::GetString(IDS_EULA_SYSTEM_SECURITY_SETTING_DESCRIPTION_KEY)); label->SetMultiLine(true); + label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); layout->AddView(label); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); @@ -136,9 +158,68 @@ void TpmInfoView::Init() { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); gfx::Font password_font = rb.GetFont(ResourceBundle::MediumFont).DeriveFont(0, gfx::Font::BOLD); - label = new views::Label(password_, password_font); - layout->AddView(label); + // Password will be set later. + password_label_ = new views::Label(L"", password_font); + password_label_->SetVisible(false); + layout->AddView(password_label_); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + + column_set = layout->AddColumnSet(2); + column_set->AddPaddingColumn(1, 0); + // Resize of the throbber and label is not allowed, since we want they to be + // placed in the center. + column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, + views::GridLayout::USE_PREF, 0, 0); + column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, + views::GridLayout::USE_PREF, 0, 0); + column_set->AddPaddingColumn(1, 0); + // Border padding columns should have the same width. It guaranties that + // throbber and label will be placed in the center. + column_set->LinkColumnSizes(0, 4, -1); + + layout->StartRow(0, 2); + throbber_ = chromeos::CreateDefaultThrobber(); + throbber_->Start(); + layout->AddView(throbber_); + busy_label_ = new views::Label(l10n_util::GetString(IDS_EULA_TPM_BUSY)); + layout->AddView(busy_label_); + layout->AddPaddingRow(0, kRelatedControlHorizontalSpacing); + + PullPassword(); +} + +void TpmInfoView::PullPassword() { + // Since this method is also called directly. + runnable_method_factory_.RevokeAll(); + + chromeos::CryptohomeLibrary* cryptohome = + chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); + + bool password_was_cleared = false; + if (password_->empty() && cryptohome->TpmIsReady()) { + bool password_acquired = cryptohome->TpmGetPassword(password_); + if (password_acquired) { + cryptohome->TpmClearStoredPassword(); + if (password_->empty()) + password_was_cleared = true; + } else { + password_->clear(); + } + } + if (password_->empty() && !password_was_cleared) { + // Password hasn't been acquired, reschedule pulling. + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + runnable_method_factory_.NewRunnableMethod(&TpmInfoView::PullPassword), + kTpmCheckIntervalMs); + } else { + password_label_->SetText(ASCIIToWide(*password_)); + password_label_->SetVisible(true); + busy_label_->SetVisible(false); + throbber_->Stop(); + throbber_->SetVisible(false); + } } } // namespace @@ -230,7 +311,8 @@ static GURL GetOemEulaPagePath() { void EulaView::Init() { // First, command to own the TPM. if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { - chromeos::CryptohomeTpmCanAttemptOwnership(); + chromeos::CrosLibrary::Get()-> + GetCryptohomeLibrary()->TpmCanAttemptOwnership(); } else { LOG(ERROR) << "Cros library not loaded. " << "We must have disabled the link that led here."; @@ -302,10 +384,13 @@ void EulaView::Init() { layout->StartRow(0, LAST_ROW); system_security_settings_link_ = new views::Link(); system_security_settings_link_->SetController(this); + if (!chromeos::CrosLibrary::Get()->EnsureLoaded() || - !chromeos::CryptohomeTpmIsEnabled()) { + !chromeos::CrosLibrary::Get()->GetCryptohomeLibrary()-> + TpmIsEnabled()) { system_security_settings_link_->SetEnabled(false); } + layout->AddView(system_security_settings_link_); back_button_ = new views::NativeButton(this, std::wstring()); @@ -383,31 +468,12 @@ void EulaView::LinkActivated(views::Link* source, int event_flags) { help_app_.reset(new HelpAppLauncher(GetNativeWindow())); help_app_->ShowHelpTopic(HelpAppLauncher::HELP_STATS_USAGE); } else if (source == system_security_settings_link_) { - // Pull the password from TPM. - bool password_acquired = false; - if (tpm_password_.empty() && chromeos::CryptohomeTpmIsReady()) { - // TODO(glotov): Sanitize memory used to store password when - // it's destroyed. - password_acquired = chromeos::CryptohomeTpmGetPassword(&tpm_password_); - chromeos::CryptohomeTpmClearStoredPassword(); - } - if (!tpm_password_.empty() || password_acquired) { - TpmInfoView* view = new TpmInfoView(ASCIIToWide(tpm_password_)); - view->Init(); - views::Window* window = browser::CreateViewsWindow( - GetNativeWindow(), gfx::Rect(), view); - window->SetIsAlwaysOnTop(true); - window->Show(); - } else { - if (!bubble_) - bubble_ = MessageBubble::Show( - system_security_settings_link_->GetWidget(), - system_security_settings_link_->GetScreenBounds(), - BubbleBorder::LEFT_TOP, - ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), - l10n_util::GetString(IDS_EULA_TPM_BUSY), - std::wstring(), this); - } + TpmInfoView* view = new TpmInfoView(&tpm_password_); + view->Init(); + views::Window* window = browser::CreateViewsWindow( + GetNativeWindow(), gfx::Rect(), view); + window->SetIsAlwaysOnTop(true); + window->Show(); } } diff --git a/chrome/browser/chromeos/login/eula_view.h b/chrome/browser/chromeos/login/eula_view.h index e7fc027..642186a 100644 --- a/chrome/browser/chromeos/login/eula_view.h +++ b/chrome/browser/chromeos/login/eula_view.h @@ -152,6 +152,8 @@ class EulaView // TPM password local storage. By convention, we clear the password // from TPM as soon as we read it. We store it here locally until // EULA screen is closed. + // TODO(glotov): Sanitize memory used to store password when + // it's destroyed. std::string tpm_password_; DISALLOW_COPY_AND_ASSIGN(EulaView); diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index a818438..87ee171 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -170,12 +170,14 @@ void LoginUtilsImpl::CompleteLogin(const std::string& username, // Own TPM device if, for any reason, it has not been done in EULA // wizard screen. - if (chromeos::CryptohomeTpmIsEnabled() && - !chromeos::CryptohomeTpmIsBeingOwned()) { - if (chromeos::CryptohomeTpmIsOwned()) { - chromeos::CryptohomeTpmClearStoredPassword(); - } else { - chromeos::CryptohomeTpmCanAttemptOwnership(); + if (CrosLibrary::Get()->EnsureLoaded()) { + CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); + if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { + if (cryptohome->TpmIsOwned()) { + cryptohome->TpmClearStoredPassword(); + } else { + cryptohome->TpmCanAttemptOwnership(); + } } } |