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/options/vpn_config_view.h" | 5 #include "chrome/browser/chromeos/options/vpn_config_view.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 if (service_path_.empty()) { | 306 if (service_path_.empty()) { |
307 NetworkLibrary::VPNConfigData config_data; | 307 NetworkLibrary::VPNConfigData config_data; |
308 switch (provider_type_) { | 308 switch (provider_type_) { |
309 case PROVIDER_TYPE_L2TP_IPSEC_PSK: | 309 case PROVIDER_TYPE_L2TP_IPSEC_PSK: |
310 config_data.psk = GetPSKPassphrase(); | 310 config_data.psk = GetPSKPassphrase(); |
311 config_data.username = GetUsername(); | 311 config_data.username = GetUsername(); |
312 config_data.user_passphrase = GetUserPassphrase(); | 312 config_data.user_passphrase = GetUserPassphrase(); |
313 config_data.group_name = GetGroupName(); | 313 config_data.group_name = GetGroupName(); |
314 break; | 314 break; |
315 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: { | 315 case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: { |
316 config_data.server_ca_cert_nss_nickname = GetServerCACertNssNickname(); | 316 config_data.server_ca_cert_pem = GetServerCACertPEM(); |
317 config_data.client_cert_pkcs11_id = GetUserCertID(); | 317 config_data.client_cert_pkcs11_id = GetUserCertID(); |
318 config_data.username = GetUsername(); | 318 config_data.username = GetUsername(); |
319 config_data.user_passphrase = GetUserPassphrase(); | 319 config_data.user_passphrase = GetUserPassphrase(); |
320 config_data.group_name = GetGroupName(); | 320 config_data.group_name = GetGroupName(); |
321 break; | 321 break; |
322 } | 322 } |
323 case PROVIDER_TYPE_OPEN_VPN: | 323 case PROVIDER_TYPE_OPEN_VPN: |
324 config_data.server_ca_cert_nss_nickname = GetServerCACertNssNickname(); | 324 config_data.server_ca_cert_pem = GetServerCACertPEM(); |
325 config_data.client_cert_pkcs11_id = GetUserCertID(); | 325 config_data.client_cert_pkcs11_id = GetUserCertID(); |
326 config_data.username = GetUsername(); | 326 config_data.username = GetUsername(); |
327 config_data.user_passphrase = GetUserPassphrase(); | 327 config_data.user_passphrase = GetUserPassphrase(); |
328 config_data.otp = GetOTP(); | 328 config_data.otp = GetOTP(); |
329 break; | 329 break; |
330 case PROVIDER_TYPE_MAX: | 330 case PROVIDER_TYPE_MAX: |
331 break; | 331 break; |
332 } | 332 } |
333 config_data.save_credentials = GetSaveCredentials(); | 333 config_data.save_credentials = GetSaveCredentials(); |
334 cros->ConnectToUnconfiguredVirtualNetwork( | 334 cros->ConnectToUnconfiguredVirtualNetwork( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 414 } |
415 | 415 |
416 const std::string VPNConfigView::GetGroupName() const { | 416 const std::string VPNConfigView::GetGroupName() const { |
417 return GetTextFromField(group_name_textfield_, false); | 417 return GetTextFromField(group_name_textfield_, false); |
418 } | 418 } |
419 | 419 |
420 const std::string VPNConfigView::GetOTP() const { | 420 const std::string VPNConfigView::GetOTP() const { |
421 return GetTextFromField(otp_textfield_, true); | 421 return GetTextFromField(otp_textfield_, true); |
422 } | 422 } |
423 | 423 |
424 const std::string VPNConfigView::GetServerCACertNssNickname() const { | 424 const std::string VPNConfigView::GetServerCACertPEM() const { |
425 int index = server_ca_cert_combobox_ ? | 425 int index = server_ca_cert_combobox_ ? |
426 server_ca_cert_combobox_->selected_index() : 0; | 426 server_ca_cert_combobox_->selected_index() : 0; |
427 if (index == 0) { | 427 if (index == 0) { |
428 // First item is "Default". | 428 // First item is "Default". |
429 return std::string(); | 429 return std::string(); |
430 } else { | 430 } else { |
431 int cert_index = index - 1; | 431 int cert_index = index - 1; |
432 return CertLibrary::Get()->GetCertNicknameAt( | 432 return CertLibrary::Get()->GetCertPEMAt( |
433 CertLibrary::CERT_TYPE_SERVER_CA, cert_index); | 433 CertLibrary::CERT_TYPE_SERVER_CA, cert_index); |
434 } | 434 } |
435 } | 435 } |
436 | 436 |
437 const std::string VPNConfigView::GetUserCertID() const { | 437 const std::string VPNConfigView::GetUserCertID() const { |
438 if (!HaveUserCerts()) { | 438 if (!HaveUserCerts()) { |
439 return std::string(); // "None installed" | 439 return std::string(); // "None installed" |
440 } else { | 440 } else { |
441 // Certificates are listed in the order they appear in the model. | 441 // Certificates are listed in the order they appear in the model. |
442 int index = user_cert_combobox_ ? user_cert_combobox_->selected_index() : 0; | 442 int index = user_cert_combobox_ ? user_cert_combobox_->selected_index() : 0; |
443 return CertLibrary::Get()->GetCertPkcs11IdAt( | 443 return CertLibrary::Get()->GetCertPkcs11IdAt( |
444 CertLibrary::CERT_TYPE_USER, index); | 444 CertLibrary::CERT_TYPE_USER, index); |
445 } | 445 } |
446 } | 446 } |
447 | 447 |
448 bool VPNConfigView::GetSaveCredentials() const { | 448 bool VPNConfigView::GetSaveCredentials() const { |
449 return save_credentials_checkbox_->checked(); | 449 return save_credentials_checkbox_->checked(); |
450 } | 450 } |
451 | 451 |
452 void VPNConfigView::Init(VirtualNetwork* vpn) { | 452 void VPNConfigView::Init(VirtualNetwork* vpn) { |
453 if (vpn) { | 453 if (vpn) { |
454 ProviderType type = vpn->provider_type(); | 454 ProviderType type = vpn->provider_type(); |
455 std::string type_dict_name = ProviderTypeToONCDictKey(type); | 455 std::string type_dict_name = ProviderTypeToONCDictKey(type); |
456 ParseVPNUIProperty(&ca_cert_ui_data_, vpn, type_dict_name, | 456 |
457 onc::vpn::kServerCARef); | 457 if (type == PROVIDER_TYPE_L2TP_IPSEC_PSK) { |
458 ParseVPNUIProperty(&psk_passphrase_ui_data_, vpn, type_dict_name, | 458 ParseVPNUIProperty(&ca_cert_ui_data_, vpn, type_dict_name, |
459 onc::vpn::kPSK); | 459 onc::ipsec::kServerCARef); |
| 460 ParseVPNUIProperty(&psk_passphrase_ui_data_, vpn, type_dict_name, |
| 461 onc::ipsec::kPSK); |
| 462 ParseVPNUIProperty(&group_name_ui_data_, vpn, type_dict_name, |
| 463 onc::ipsec::kGroup); |
| 464 } else { // OpenVPN |
| 465 ParseVPNUIProperty(&ca_cert_ui_data_, vpn, type_dict_name, |
| 466 onc::openvpn::kServerCARef); |
| 467 } |
460 ParseVPNUIProperty(&user_cert_ui_data_, vpn, type_dict_name, | 468 ParseVPNUIProperty(&user_cert_ui_data_, vpn, type_dict_name, |
461 onc::vpn::kClientCertRef); | 469 onc::vpn::kClientCertRef); |
462 ParseVPNUIProperty(&group_name_ui_data_, vpn, type_dict_name, | |
463 onc::vpn::kGroup); | |
464 | 470 |
465 const std::string credentials_dict_name( | 471 const std::string credentials_dict_name( |
466 type == PROVIDER_TYPE_L2TP_IPSEC_PSK ? | 472 type == PROVIDER_TYPE_L2TP_IPSEC_PSK ? |
467 onc::vpn::kL2TP : type_dict_name); | 473 onc::vpn::kL2TP : type_dict_name); |
468 ParseVPNUIProperty(&username_ui_data_, vpn, credentials_dict_name, | 474 ParseVPNUIProperty(&username_ui_data_, vpn, credentials_dict_name, |
469 onc::vpn::kUsername); | 475 onc::vpn::kUsername); |
470 ParseVPNUIProperty(&user_passphrase_ui_data_, vpn, credentials_dict_name, | 476 ParseVPNUIProperty(&user_passphrase_ui_data_, vpn, credentials_dict_name, |
471 onc::vpn::kPassword); | 477 onc::vpn::kPassword); |
472 ParseVPNUIProperty(&save_credentials_ui_data_, vpn, credentials_dict_name, | 478 ParseVPNUIProperty(&save_credentials_ui_data_, vpn, credentials_dict_name, |
473 onc::vpn::kSaveCredentials); | 479 onc::vpn::kSaveCredentials); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 void VPNConfigView::Refresh() { | 717 void VPNConfigView::Refresh() { |
712 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 718 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
713 | 719 |
714 UpdateControls(); | 720 UpdateControls(); |
715 | 721 |
716 // Set certificate combo boxes. | 722 // Set certificate combo boxes. |
717 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); | 723 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path_); |
718 if (server_ca_cert_combobox_) { | 724 if (server_ca_cert_combobox_) { |
719 server_ca_cert_combobox_->ModelChanged(); | 725 server_ca_cert_combobox_->ModelChanged(); |
720 if (enable_server_ca_cert_ && | 726 if (enable_server_ca_cert_ && |
721 (vpn && !vpn->ca_cert_nss().empty())) { | 727 (vpn && !vpn->ca_cert_pem().empty())) { |
722 // Select the current server CA certificate in the combobox. | 728 // Select the current server CA certificate in the combobox. |
723 int cert_index = CertLibrary::Get()->GetCertIndexByNickname( | 729 int cert_index = CertLibrary::Get()->GetCertIndexByPEM( |
724 CertLibrary::CERT_TYPE_SERVER_CA, vpn->ca_cert_nss()); | 730 CertLibrary::CERT_TYPE_SERVER_CA, vpn->ca_cert_pem()); |
725 if (cert_index >= 0) { | 731 if (cert_index >= 0) { |
726 // Skip item for "Default" | 732 // Skip item for "Default" |
727 server_ca_cert_combobox_->SetSelectedIndex(1 + cert_index); | 733 server_ca_cert_combobox_->SetSelectedIndex(1 + cert_index); |
728 } else { | 734 } else { |
729 server_ca_cert_combobox_->SetSelectedIndex(0); | 735 server_ca_cert_combobox_->SetSelectedIndex(0); |
730 } | 736 } |
731 } else { | 737 } else { |
732 server_ca_cert_combobox_->SetSelectedIndex(0); | 738 server_ca_cert_combobox_->SetSelectedIndex(0); |
733 } | 739 } |
734 } | 740 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 | 908 |
903 property_ui_data->ParseOncProperty( | 909 property_ui_data->ParseOncProperty( |
904 network->ui_data().onc_source(), onc, | 910 network->ui_data().onc_source(), onc, |
905 base::StringPrintf("%s.%s.%s", | 911 base::StringPrintf("%s.%s.%s", |
906 onc::network_config::kVPN, | 912 onc::network_config::kVPN, |
907 dict_key.c_str(), | 913 dict_key.c_str(), |
908 key.c_str())); | 914 key.c_str())); |
909 } | 915 } |
910 | 916 |
911 } // namespace chromeos | 917 } // namespace chromeos |
OLD | NEW |