Skip to content

Commit

Permalink
This moves the ONC parsing code into chromeos/network/onc
Browse files Browse the repository at this point in the history
so that it can be used there without violating dependency
rules.

(Using the "refactoring" OWNERS TBR rule...)

BUG=none
TEST=ran unit tests
TBR=jhawkins@chromium.org


Review URL: https://chromiumcodereview.appspot.com/11299236

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172446 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
gspencer@chromium.org committed Dec 11, 2012
1 parent 6ba4d65 commit 01c988d
Show file tree
Hide file tree
Showing 95 changed files with 877 additions and 840 deletions.
60 changes: 0 additions & 60 deletions chrome/app/chromeos_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,6 @@ Press any key to continue exploring.
<message name="IDS_OFFERS_CONSENT_INFOBAR_DISABLE_BUTTON" desc="Disable button label.">
Deny
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_NETWORK_NOT_A_JSON_DICTIONARY" desc="Error for network configuration: Configuration is not a valid JSON dictionary.">
The configuration is not a valid JSON dictionary.
</message>
<message name="IDS_NETWORK_CONFIG_LOADING_ERROR" desc="Error message for loading network configuration file.">
Error loading network configuration file: <ph name="error">$1<ex>Unknown error</ex></ph>
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_UNKNOWN" desc="Error for network configuration: Unknown error.">
Unknown error
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_INCORRECT_PASSWORD" desc="Error for network configuration: Incorrect password.">
Incorrect password
</message>
Expand All @@ -162,57 +153,6 @@ Press any key to continue exploring.
<message name="IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED" desc="Error for network configuration: Network property dictionary malformed.">
Network property dictionary malformed
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_NETWORK_EAP_DICT_MALFORMED" desc="Error for network configuration: Network EAP dictionary malformed.">
Network EAP dictionary malformed
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_NETWORK_DELETE" desc="Error for network configuration: Network delete error.">
Network delete error
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_NETWORK_IMPORT" desc="Error for network configuration: Network import error.">
Network import error
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_CERT_GUID_MISSING" desc="Error for network configuration: Certificateg GUID missing.">
Certificate GUID missing
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_CERT_GUID_COLLISION" desc="Error for network configuration: GUID is taken by a different certificate.">
Certificate GUID collision
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_CERT_TYPE_MISSING" desc="Error for network configuration: Certificate type missing.">
Certificate type missing
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_CERT_TRUST_INVALID" desc="Error for network configuration: Certificate trust invalid.">
Certificate trust invalid
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_CERT_TRUST_UNKNOWN" desc="Error for network configuration: Certificate trust unknown.">
Certificate trust unknown
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MISSING" desc="Error for network configuration: Certificate data missing.">
Certificate data missing
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MALFORMED" desc="Error for network configuration: Certificate data malformed.">
Certificate data malformed
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_CERT_DELETE" desc="Error for network configuration: Certificate delete error.">
Certificate delete error
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_CERT_IMPORT" desc="Error for network configuration: Certificate import error.">
Certificate import error
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_MALFORMED" desc="Displayed when importing an encrypted ONC file and the ONC file is malformed.">
Encrypted ONC file is malformed.
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNSUPPORTED_ENCRYPTION" desc="Displayed when importing an encrypted ONC file and the ONC file uses an encryption protocol that is not supported.">
Encrypted ONC file uses an unsupported encryption scheme.
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNABLE_TO_DECODE" desc="Displayed when importing an encrypted ONC file and the encryption parameters are not able to be parsed.">
Unable to parse some parameters in the encrypted ONC file.
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNABLE_TO_DECRYPT" desc="Displayed when importing an encrypted ONC file and it is not able to be decrypted.">
Unable to decrypt the encrypted ONC file.
</message>
<message name="IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_TOO_MANY_ITERATIONS" desc="Displayed when importing an encrypted ONC file and the iteration count is too large.">
Passphrase iteration count is too large.
</message>
<message name="IDS_NETWORK_ENROLLMENT_HANDLER_TITLE" desc="Title of the window for generating a new network certificate.">
Obtain network certificate
</message>
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/chromeos/cros/mock_network_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>

#include "chrome/browser/chromeos/cros/network_library.h"
#include "chromeos/network/onc/onc_constants.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace chromeos {
Expand Down Expand Up @@ -187,11 +188,10 @@ class MockNetworkLibrary : public NetworkLibrary {
const std::string&,
int));
MOCK_METHOD0(SwitchToPreferredNetwork, void(void));
MOCK_METHOD5(LoadOncNetworks, bool(const std::string&,
MOCK_METHOD4(LoadOncNetworks, bool(const std::string&,
const std::string&,
NetworkUIData::ONCSource,
bool,
std::string*));
onc::ONCSource,
bool));
MOCK_METHOD2(SetActiveNetwork, bool(ConnectionType, const std::string&));
};

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/cros/network_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ void VirtualNetwork::MatchCertificatePattern(bool allow_enroll,
// user can't get to the place where a cert is presented for them
// involuntarily.
if (client_cert_pattern().Empty() ||
ui_data().onc_source() == NetworkUIData::ONC_SOURCE_DEVICE_POLICY) {
ui_data().onc_source() == onc::ONC_SOURCE_DEVICE_POLICY) {
connect.Run();
return;
}
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/chromeos/cros/network_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "chrome/browser/chromeos/cros/cros_network_functions.h"
#include "chrome/browser/chromeos/cros/network_constants.h"
#include "chrome/browser/chromeos/cros/network_ui_data.h"
#include "chromeos/network/onc/onc_constants.h"
#include "googleurl/src/gurl.h"

namespace base {
Expand Down Expand Up @@ -1689,9 +1690,8 @@ class NetworkLibrary {
// the error message.
virtual bool LoadOncNetworks(const std::string& onc_blob,
const std::string& passcode,
NetworkUIData::ONCSource source,
bool allow_web_trust_from_policy,
std::string* error) = 0;
onc::ONCSource source,
bool allow_web_trust_from_policy) = 0;

// This sets the active network for the network type. Note: priority order
// is unchanged (i.e. if a wifi network is set to active, but an ethernet
Expand Down
82 changes: 36 additions & 46 deletions chrome/browser/chromeos/cros/network_library_impl_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include "base/memory/scoped_vector.h"
#include "base/stl_util.h"
#include "chrome/browser/chromeos/cros/native_network_parser.h"
#include "chrome/browser/chromeos/cros/onc_constants.h"
#include "chrome/browser/chromeos/cros/onc_network_parser.h"
#include "chrome/browser/chromeos/network_login_observer.h"
#include "chrome/browser/chromeos/network_settings/onc_certificate_importer.h"
#include "chrome/browser/chromeos/network_settings/onc_signature.h"
#include "chrome/browser/chromeos/network_settings/onc_utils.h"
#include "chrome/browser/chromeos/network_settings/onc_validator.h"
#include "chromeos/network/onc/onc_certificate_importer.h"
#include "chromeos/network/onc/onc_constants.h"
#include "chromeos/network/onc/onc_signature.h"
#include "chromeos/network/onc/onc_utils.h"
#include "chromeos/network/onc/onc_validator.h"
#include "content/public/browser/browser_thread.h"
#include "crypto/nss_util.h" // crypto::GetTPMTokenInfo() for 802.1X and VPN.
#include "grit/generated_resources.h"
Expand All @@ -34,14 +34,14 @@ const int kNetworkNotifyDelayMs = 50;
// How long we should remember that cellular plan payment was received.
const int kRecentPlanPaymentHours = 6;

NetworkProfileType GetProfileTypeForSource(NetworkUIData::ONCSource source) {
NetworkProfileType GetProfileTypeForSource(onc::ONCSource source) {
switch (source) {
case NetworkUIData::ONC_SOURCE_DEVICE_POLICY:
case onc::ONC_SOURCE_DEVICE_POLICY:
return PROFILE_SHARED;
case NetworkUIData::ONC_SOURCE_USER_POLICY:
case onc::ONC_SOURCE_USER_POLICY:
return PROFILE_USER;
case NetworkUIData::ONC_SOURCE_NONE:
case NetworkUIData::ONC_SOURCE_USER_IMPORT:
case onc::ONC_SOURCE_NONE:
case onc::ONC_SOURCE_USER_IMPORT:
return PROFILE_NONE;
}
NOTREACHED() << "Unknown ONC source " << source;
Expand Down Expand Up @@ -364,7 +364,7 @@ const Network* NetworkLibraryImplBase::connected_network() const {
return result;
}

// Connecting order in logical prefernce.
// Connecting order in logical preference.
const Network* NetworkLibraryImplBase::connecting_network() const {
if (ethernet_connecting())
return ethernet_network();
Expand Down Expand Up @@ -1023,12 +1023,11 @@ void NetworkLibraryImplBase::SwitchToPreferredNetwork() {

bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
const std::string& passphrase,
NetworkUIData::ONCSource source,
bool allow_web_trust_from_policy,
std::string* error) {
onc::ONCSource source,
bool allow_web_trust_from_policy) {
NetworkProfile* profile = NULL;
bool from_policy = (source == NetworkUIData::ONC_SOURCE_USER_POLICY ||
source == NetworkUIData::ONC_SOURCE_DEVICE_POLICY);
bool from_policy = (source == onc::ONC_SOURCE_USER_POLICY ||
source == onc::ONC_SOURCE_DEVICE_POLICY);

// Policies are applied to a specific Shill profile. User ONC import however
// is applied to whatever profile Shill chooses. This should be the profile
Expand All @@ -1037,34 +1036,30 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
if (from_policy) {
profile = GetProfileForType(GetProfileTypeForSource(source));
if (profile == NULL) {
DLOG(WARNING) << "Profile for ONC source " << source << " doesn't exist.";
DLOG(WARNING) << "Profile for ONC source "
<< onc::GetSourceAsString(source)
<< " doesn't exist.";
return false;
}
}

VLOG(2) << __func__ << ": called on " << onc_blob;
std::string json_error;
scoped_ptr<base::DictionaryValue> root_dict =
onc::ReadDictionaryFromJson(onc_blob, &json_error);
onc::ReadDictionaryFromJson(onc_blob);
if (root_dict.get() == NULL) {
if (error != NULL)
*error = json_error;
LOG(WARNING) << "ONC loaded from ONC source " << source
<< " is not a valid json dictionary: " << json_error;
LOG(WARNING) << "ONC loaded from " << onc::GetSourceAsString(source)
<< " is not a valid JSON dictionary.";
return false;
}

// Check and see if this is an encrypted ONC file. If so, decrypt it.
std::string onc_type;
root_dict->GetStringWithoutPathExpansion(onc::kType, &onc_type);
if (onc_type == onc::kEncryptedConfiguration) {
std::string decrypt_error;
root_dict = onc::Decrypt(passphrase, *root_dict, &decrypt_error);
root_dict = onc::Decrypt(passphrase, *root_dict);
if (root_dict.get() == NULL) {
if (error != NULL)
*error = decrypt_error;
LOG(WARNING) << "Couldn't decrypt the ONC from source " << source
<< " with error: " << decrypt_error;
LOG(WARNING) << "Couldn't decrypt the ONC from "
<< onc::GetSourceAsString(source);
return false;
}
}
Expand Down Expand Up @@ -1105,12 +1100,10 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
VLOG(2) << "ONC file has " << certificates->GetSize() << " certificates";

onc::CertificateImporter cert_importer(source, allow_web_trust_from_policy);
std::string cert_error;
if (!cert_importer.ParseAndStoreCertificates(*certificates, &cert_error)) {
if (error != NULL)
*error = cert_error;
if (cert_importer.ParseAndStoreCertificates(*certificates) !=
onc::CertificateImporter::IMPORT_OK) {
LOG(WARNING) << "Cannot parse some of the certificates in the ONC from "
<< "source " << source << " with error: " << cert_error;
<< onc::GetSourceAsString(source);
return false;
}
}
Expand All @@ -1130,17 +1123,14 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
bool marked_for_removal = false;
Network* network = parser.ParseNetwork(i, &marked_for_removal);
if (!network) {
if (error != NULL)
*error = parser.parse_error();
LOG(WARNING) << "Error during parsing network at index " << i
<< " from ONC source " << source
<< ": " << parser.parse_error();
<< " from ONC source " << onc::GetSourceAsString(source);
return false;
}

// Disallow anything but WiFi and Ethernet for device-level policy (which
// corresponds to shared networks). See also http://crosbug.com/28741.
if (source == NetworkUIData::ONC_SOURCE_DEVICE_POLICY &&
if (source == onc::ONC_SOURCE_DEVICE_POLICY &&
network->type() != TYPE_WIFI &&
network->type() != TYPE_ETHERNET) {
LOG(WARNING) << "Ignoring device-level policy-pushed network of type "
Expand All @@ -1150,7 +1140,7 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
}

networks.push_back(network);
if (!(source == NetworkUIData::ONC_SOURCE_USER_IMPORT &&
if (!(source == onc::ONC_SOURCE_USER_IMPORT &&
marked_for_removal)) {
added_onc_map[network->unique_id()] = parser.GetNetworkConfig(i);
}
Expand Down Expand Up @@ -1178,7 +1168,7 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,

// Don't configure a network that is supposed to be removed. For
// policy-managed networks, the "remove" functionality of ONC is ignored.
if (source == NetworkUIData::ONC_SOURCE_USER_IMPORT &&
if (source == onc::ONC_SOURCE_USER_IMPORT &&
removal_ids.find(network->unique_id()) != removal_ids.end()) {
continue;
}
Expand Down Expand Up @@ -1222,7 +1212,7 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
// ONC blob. We first collect the networks and do the actual deletion later
// because ForgetNetwork() changes the remembered network vectors.
ForgetNetworksById(source, network_ids, false);
} else if (source == NetworkUIData::ONC_SOURCE_USER_IMPORT) {
} else if (source == onc::ONC_SOURCE_USER_IMPORT) {
if (removal_ids.empty())
return true;

Expand Down Expand Up @@ -1368,7 +1358,7 @@ void NetworkLibraryImplBase::DeleteNetwork(Network* network) {
}

void NetworkLibraryImplBase::ForgetNetworksById(
NetworkUIData::ONCSource source,
onc::ONCSource source,
std::set<std::string> ids,
bool if_found) {
std::vector<std::string> to_be_forgotten;
Expand Down Expand Up @@ -1405,9 +1395,9 @@ bool NetworkLibraryImplBase::ValidateRememberedNetwork(Network* network) {
// available to LoadOncNetworks(), which can happen due to the asynchronous
// communication between shill and NetworkLibrary. Just tell shill to
// delete the network now.
const NetworkUIData::ONCSource source = network->ui_data().onc_source();
if (source == NetworkUIData::ONC_SOURCE_USER_POLICY ||
source == NetworkUIData::ONC_SOURCE_DEVICE_POLICY) {
const onc::ONCSource source = network->ui_data().onc_source();
if (source == onc::ONC_SOURCE_USER_POLICY ||
source == onc::ONC_SOURCE_DEVICE_POLICY) {
NetworkSourceMap::const_iterator network_id_set(
network_source_map_.find(source));
if (network_id_set != network_source_map_.end() &&
Expand Down
12 changes: 6 additions & 6 deletions chrome/browser/chromeos/cros/network_library_impl_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <set>

#include "chrome/browser/chromeos/cros/network_library.h"
#include "chromeos/network/onc/onc_constants.h"

namespace chromeos {

Expand Down Expand Up @@ -43,7 +44,7 @@ class NetworkLibraryImplBase : public NetworkLibrary {
virtual void CallConfigureService(const std::string& identifier,
const DictionaryValue* info) = 0;
// Called from NetworkConnectStart.
// Calls NetworkConnectCompleted when the connection attept completes.
// Calls NetworkConnectCompleted when the connection attempt completes.
virtual void CallConnectToNetwork(Network* network) = 0;
// Called from DeleteRememberedNetwork.
virtual void CallDeleteRememberedNetwork(
Expand Down Expand Up @@ -233,9 +234,8 @@ class NetworkLibraryImplBase : public NetworkLibrary {
virtual void SwitchToPreferredNetwork() OVERRIDE;
virtual bool LoadOncNetworks(const std::string& onc_blob,
const std::string& passphrase,
NetworkUIData::ONCSource source,
bool allow_web_trust_from_policy,
std::string* error) OVERRIDE;
onc::ONCSource source,
bool allow_web_trust_from_policy) OVERRIDE;
virtual bool SetActiveNetwork(ConnectionType type,
const std::string& service_path) OVERRIDE;

Expand All @@ -251,7 +251,7 @@ class NetworkLibraryImplBase : public NetworkLibrary {
typedef std::map<std::string, int> PriorityMap;
typedef std::map<std::string, NetworkDevice*> NetworkDeviceMap;
typedef std::map<std::string, const base::DictionaryValue*> NetworkOncMap;
typedef std::map<NetworkUIData::ONCSource,
typedef std::map<onc::ONCSource,
std::set<std::string> > NetworkSourceMap;

struct NetworkProfile {
Expand Down Expand Up @@ -317,7 +317,7 @@ class NetworkLibraryImplBase : public NetworkLibrary {
// When |if_found| is true, then it forgets networks that appear in |ids|.
// When |if_found| is false, it removes networks that do NOT appear in |ids|.
// |source| is the import source of the data.
void ForgetNetworksById(NetworkUIData::ONCSource source,
void ForgetNetworksById(onc::ONCSource source,
std::set<std::string> ids,
bool if_found);

Expand Down
Loading

0 comments on commit 01c988d

Please sign in to comment.