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

Side by Side Diff: chrome/browser/ui/webui/options/managed_user_passphrase_handler.cc

Issue 11783008: Add a lock to the managed user settings page and require authentication for unlocking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adressed comments regarding the set passphrase dialog. Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/options/managed_user_passphrase_handler.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/values.h"
10 #include "chrome/browser/managed_mode/managed_user_passphrase.h"
11 #include "chrome/browser/managed_mode/managed_user_service.h"
12 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/webui/managed_user_passphrase_dialog.h"
16 #include "chrome/common/pref_names.h"
17 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_ui.h"
19 #include "grit/generated_resources.h"
20
21 namespace options {
22
23 ManagedUserPassphraseHandler::ManagedUserPassphraseHandler()
24 : weak_ptr_factory_(this) {
25 }
26
27 ManagedUserPassphraseHandler::~ManagedUserPassphraseHandler() {
28 }
29
30 void ManagedUserPassphraseHandler::InitializeHandler() {
31 }
32
33 void ManagedUserPassphraseHandler::RegisterMessages() {
34 web_ui()->RegisterMessageCallback("setPassphrase",
35 base::Bind(&ManagedUserPassphraseHandler::SetLocalPassphrase,
36 weak_ptr_factory_.GetWeakPtr()));
37 web_ui()->RegisterMessageCallback("displayPassphraseDialog",
38 base::Bind(&ManagedUserPassphraseHandler::DisplayPassphraseDialog,
39 weak_ptr_factory_.GetWeakPtr()));
40 web_ui()->RegisterMessageCallback("endAuthentication",
41 base::Bind(&ManagedUserPassphraseHandler::EndAuthentication,
42 weak_ptr_factory_.GetWeakPtr()));
43 web_ui()->RegisterMessageCallback("isPassphraseSet",
44 base::Bind(&ManagedUserPassphraseHandler::IsPassphraseSet,
45 weak_ptr_factory_.GetWeakPtr()));
46 web_ui()->RegisterMessageCallback("resetPassphrase",
47 base::Bind(&ManagedUserPassphraseHandler::ResetPassphrase,
48 weak_ptr_factory_.GetWeakPtr()));
49 }
50
51 void ManagedUserPassphraseHandler::GetLocalizedValues(
52 base::DictionaryValue* localized_strings) {
53 DCHECK(localized_strings);
54
55 static OptionsStringResource resources[] = {
56 { "confirmPassphrase", IDS_CONFIRM_PASSPHRASE_LABEL },
57 { "enterPassphrase", IDS_ENTER_PASSPHRASE_LABEL },
58 { "savePassphrase", IDS_SAVE_PASSPHRASE_BUTTON },
59 { "setPassphraseInstructions", IDS_SET_PASSPHRASE_INSTRUCTIONS },
60 { "passphraseMismatch", IDS_PASSPHRASE_MISMATCH },
61 };
62 RegisterStrings(localized_strings, resources, arraysize(resources));
63
64 RegisterTitle(localized_strings,
65 "setPassphraseTitle",
66 IDS_SET_PASSPHRASE_TITLE);
67 }
68
69 void ManagedUserPassphraseHandler::PassphraseDialogCallback(bool success) {
70 base::FundamentalValue unlock_success(success);
71 web_ui()->CallJavascriptFunction(callback_function_name_, unlock_success);
72 }
73
74 void ManagedUserPassphraseHandler::DisplayPassphraseDialog(
75 const base::ListValue* args) {
76 // Store the name of the callback function.
77 args->GetString(0, &callback_function_name_);
78 Profile* profile = Profile::FromWebUI(web_ui());
79 ManagedUserService* managed_user_service =
80 ManagedUserServiceFactory::GetForProfile(profile);
81 if (managed_user_service->IsElevated()) {
82 // If the custodian is already authenticated, skip the passphrase dialog.
83 PassphraseDialogCallback(true);
84 return;
85 }
86 // This is deleted automatically when the dialog is closed.
87 new ManagedUserPassphraseDialog(web_ui()->GetWebContents(),
88 base::Bind(&ManagedUserPassphraseHandler::PassphraseDialogCallback,
89 weak_ptr_factory_.GetWeakPtr()));
90 }
91
92 void ManagedUserPassphraseHandler::EndAuthentication(
93 const base::ListValue* args) {
94 Profile* profile = Profile::FromWebUI(web_ui());
95 ManagedUserService* managed_user_service =
96 ManagedUserServiceFactory::GetForProfile(profile);
97 managed_user_service->SetElevated(false);
98 }
99
100 void ManagedUserPassphraseHandler::IsPassphraseSet(
101 const base::ListValue* args) {
102 // Get the name of the callback function.
103 std::string callback_function_name;
104 args->GetString(0, &callback_function_name);
105 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
106 base::FundamentalValue is_passphrase_set(!pref_service->GetString(
107 prefs::kManagedModeLocalPassphrase).empty());
108 web_ui()->CallJavascriptFunction(callback_function_name,
109 is_passphrase_set);
110 }
111
112 void ManagedUserPassphraseHandler::ResetPassphrase(
113 const base::ListValue* args) {
114 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
115 pref_service->SetString(prefs::kManagedModeLocalPassphrase, "");
116 }
117
118 void ManagedUserPassphraseHandler::SetLocalPassphrase(
119 const base::ListValue* args) {
120 // Only change the passphrase if the custodian is authenticated.
121 Profile* profile = Profile::FromWebUI(web_ui());
122 ManagedUserService* managed_user_service =
123 ManagedUserServiceFactory::GetForProfile(profile);
124 if (!managed_user_service->IsElevated())
125 return;
126
127 std::string passphrase;
128 args->GetString(0, &passphrase);
129 ManagedUserPassphrase passphrase_key_generator((std::string()));
130 std::string encoded_passphrase_hash;
131 passphrase_key_generator.GenerateHashFromPassphrase(passphrase,
132 &encoded_passphrase_hash);
133 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
134 pref_service->SetString(prefs::kManagedModeLocalPassphrase,
135 encoded_passphrase_hash);
136 pref_service->SetString(prefs::kManagedModeLocalSalt,
137 passphrase_key_generator.GetSalt());
138 }
139
140 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698