OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/enrollment_dialog_view.h" | 5 #include "chrome/browser/chromeos/enrollment_dialog_view.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
12 #include "chrome/browser/ui/browser_navigator.h" | 13 #include "chrome/browser/ui/browser_navigator.h" |
| 14 #include "chromeos/network/client_cert_util.h" |
| 15 #include "chromeos/network/managed_network_configuration_handler.h" |
13 #include "chromeos/network/network_event_log.h" | 16 #include "chromeos/network/network_event_log.h" |
14 #include "chromeos/network/network_state.h" | 17 #include "chromeos/network/network_state.h" |
15 #include "chromeos/network/network_state_handler.h" | 18 #include "chromeos/network/network_state_handler.h" |
16 #include "content/public/common/page_transition_types.h" | 19 #include "content/public/common/page_transition_types.h" |
17 #include "extensions/browser/extension_host.h" | 20 #include "extensions/browser/extension_host.h" |
18 #include "extensions/common/constants.h" | 21 #include "extensions/common/constants.h" |
19 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
20 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
22 #include "ui/views/layout/grid_layout.h" | 25 #include "ui/views/layout/grid_layout.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 gfx::NativeWindow owning_window, | 212 gfx::NativeWindow owning_window, |
210 const std::string& network_name, | 213 const std::string& network_name, |
211 Profile* profile) : owning_window_(owning_window), | 214 Profile* profile) : owning_window_(owning_window), |
212 network_name_(network_name), | 215 network_name_(network_name), |
213 profile_(profile) {} | 216 profile_(profile) {} |
214 | 217 |
215 DialogEnrollmentDelegate::~DialogEnrollmentDelegate() {} | 218 DialogEnrollmentDelegate::~DialogEnrollmentDelegate() {} |
216 | 219 |
217 bool DialogEnrollmentDelegate::Enroll(const std::vector<std::string>& uri_list, | 220 bool DialogEnrollmentDelegate::Enroll(const std::vector<std::string>& uri_list, |
218 const base::Closure& post_action) { | 221 const base::Closure& post_action) { |
219 if (uri_list.empty()) { | |
220 NET_LOG_EVENT("No enrollment URIs", network_name_); | |
221 return false; | |
222 } | |
223 | |
224 // Keep the closure for later activation if we notice that | 222 // Keep the closure for later activation if we notice that |
225 // a certificate has been added. | 223 // a certificate has been added. |
226 | 224 |
227 // TODO(gspencer): Do something smart with the closure. At the moment it is | 225 // TODO(gspencer): Do something smart with the closure. At the moment it is |
228 // being ignored because we don't know when the enrollment tab is closed. | 226 // being ignored because we don't know when the enrollment tab is closed. |
229 // http://crosbug.com/30422 | 227 // http://crosbug.com/30422 |
230 for (std::vector<std::string>::const_iterator iter = uri_list.begin(); | 228 for (std::vector<std::string>::const_iterator iter = uri_list.begin(); |
231 iter != uri_list.end(); ++iter) { | 229 iter != uri_list.end(); ++iter) { |
232 GURL uri(*iter); | 230 GURL uri(*iter); |
233 if (uri.IsStandard() || uri.scheme() == extensions::kExtensionScheme) { | 231 if (uri.IsStandard() || uri.scheme() == extensions::kExtensionScheme) { |
(...skipping 26 matching lines...) Expand all Loading... |
260 namespace enrollment { | 258 namespace enrollment { |
261 | 259 |
262 bool CreateDialog(const std::string& service_path, | 260 bool CreateDialog(const std::string& service_path, |
263 gfx::NativeWindow owning_window) { | 261 gfx::NativeWindow owning_window) { |
264 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> | 262 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
265 GetNetworkState(service_path); | 263 GetNetworkState(service_path); |
266 if (!network) { | 264 if (!network) { |
267 NET_LOG_ERROR("Enrolling Unknown network", service_path); | 265 NET_LOG_ERROR("Enrolling Unknown network", service_path); |
268 return false; | 266 return false; |
269 } | 267 } |
| 268 Browser* browser = chrome::FindBrowserWithWindow(owning_window); |
| 269 Profile* profile = |
| 270 browser ? browser->profile() : ProfileManager::GetPrimaryUserProfile(); |
| 271 std::string username_hash = ProfileHelper::GetUserIdHashFromProfile(profile); |
| 272 |
| 273 onc::ONCSource onc_source = onc::ONC_SOURCE_NONE; |
| 274 const base::DictionaryValue* policy = |
| 275 NetworkHandler::Get() |
| 276 ->managed_network_configuration_handler() |
| 277 ->FindPolicyByGUID(username_hash, network->guid(), &onc_source); |
| 278 |
270 // We skip certificate patterns for device policy ONC so that an unmanaged | 279 // We skip certificate patterns for device policy ONC so that an unmanaged |
271 // user can't get to the place where a cert is presented for them | 280 // user can't get to the place where a cert is presented for them |
272 // involuntarily. | 281 // involuntarily. |
273 if (network->ui_data().onc_source() == onc::ONC_SOURCE_DEVICE_POLICY) | 282 if (!policy || onc_source == onc::ONC_SOURCE_DEVICE_POLICY) |
274 return false; | 283 return false; |
275 | 284 |
276 const CertificatePattern& certificate_pattern = | 285 client_cert::ClientCertConfig cert_config; |
277 network->ui_data().certificate_pattern(); | 286 OncToClientCertConfig(*policy, &cert_config); |
278 if (certificate_pattern.Empty()) { | 287 |
279 NET_LOG_EVENT("No certificate pattern found", service_path); | 288 if (cert_config.client_cert_type != onc::client_cert::kPattern) |
| 289 return false; |
| 290 |
| 291 if (cert_config.pattern.Empty()) |
| 292 NET_LOG_ERROR("Certificate pattern is empty", service_path); |
| 293 |
| 294 if (cert_config.pattern.enrollment_uri_list().empty()) { |
| 295 NET_LOG_EVENT("No enrollment URIs", service_path); |
280 return false; | 296 return false; |
281 } | 297 } |
282 | 298 |
283 NET_LOG_USER("Enrolling", service_path); | 299 NET_LOG_USER("Enrolling", service_path); |
284 | 300 |
285 Browser* browser = chrome::FindBrowserWithWindow(owning_window); | |
286 Profile* profile = browser ? browser->profile() : | |
287 ProfileManager::GetPrimaryUserProfile(); | |
288 DialogEnrollmentDelegate* enrollment = | 301 DialogEnrollmentDelegate* enrollment = |
289 new DialogEnrollmentDelegate(owning_window, network->name(), profile); | 302 new DialogEnrollmentDelegate(owning_window, network->name(), profile); |
290 return enrollment->Enroll(certificate_pattern.enrollment_uri_list(), | 303 return enrollment->Enroll(cert_config.pattern.enrollment_uri_list(), |
291 base::Bind(&EnrollmentComplete, service_path)); | 304 base::Bind(&EnrollmentComplete, service_path)); |
292 } | 305 } |
293 | 306 |
294 } // namespace enrollment | 307 } // namespace enrollment |
295 | 308 |
296 } // namespace chromeos | 309 } // namespace chromeos |
OLD | NEW |