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

Side by Side Diff: chrome/browser/chromeos/cros/onc_network_parser.h

Issue 11578052: Replace OncNetworkParser by the new ONC translator. (Closed) Base URL: http://git.chromium.org/chromium/src.git@extend_onc_to_shill
Patch Set: Rebased. Created 7 years, 11 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
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 #ifndef CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/compiler_specific.h" // for OVERRIDE
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/values.h"
15 #include "chrome/browser/chromeos/cros/network_parser.h"
16 #include "chrome/browser/chromeos/cros/network_ui_data.h"
17 #include "chromeos/network/onc/onc_constants.h"
18
19 namespace base {
20 class DictionaryValue;
21 class ListValue;
22 class Value;
23 }
24
25 namespace net {
26 class ProxyServer;
27 }
28
29 namespace chromeos {
30
31 class IssuerSubjectPattern;
32
33 // This is a simple representation of the signature of an ONC typed
34 // field, used in validation and translation. It could be extended
35 // to include more complex rules of when the field is required/optional,
36 // as well as to handle "enum" types, which are strings with a small
37 // static set of possible values.
38 struct OncValueSignature {
39 const char* field;
40 PropertyIndex index;
41 base::Value::Type type;
42 };
43
44 // This is the network parser that parses the data from an Open Network
45 // Configuration (ONC) file. ONC files are in JSON format that describes
46 // networks. We will use this parser to parse the ONC JSON blob.
47 //
48 // For ONC file format, see: http://dev.chromium.org/chromium-os/
49 // chromiumos-design-docs/open-network-configuration
50 class OncNetworkParser : public NetworkParser {
51 public:
52 typedef bool (*ParserPointer)(OncNetworkParser*,
53 PropertyIndex,
54 const base::Value&,
55 Network*);
56
57 OncNetworkParser(const base::ListValue& network_configs,
58 onc::ONCSource onc_source);
59 virtual ~OncNetworkParser();
60 static const EnumMapper<PropertyIndex>* property_mapper();
61
62 // Returns the number of networks in the "NetworkConfigs" list.
63 int GetNetworkConfigsSize() const;
64
65 // Returns the network configuration dictionary for the nth network. CHECKs if
66 // |n| is out of range and returns NULL on parse errors.
67 const base::DictionaryValue* GetNetworkConfig(int n);
68
69 // Call to create the network by parsing network config in the nth position.
70 // (0-based). CHECKs if |n| is out of range and returns NULL on parse errors.
71 // |removed| is set to true if the network should be removed. |removed| may
72 // be NULL.
73 Network* ParseNetwork(int n, bool* marked_for_removal);
74
75 virtual Network* CreateNetworkFromInfo(const std::string& service_path,
76 const base::DictionaryValue& info) OVERRIDE;
77
78 // Parses a nested ONC object with the given mapper and parser function.
79 // If Value is not the proper type or there is an error in parsing
80 // any individual field, VLOGs diagnostics, and returns false.
81 bool ParseNestedObject(Network* network,
82 const std::string& onc_type,
83 const base::Value& value,
84 OncValueSignature* signature,
85 ParserPointer parser);
86
87 // Expands |value| with user account specific paramaters.
88 static std::string GetUserExpandedValue(const base::Value& value,
89 onc::ONCSource source);
90
91 const std::string& parse_error() const { return parse_error_; }
92
93 onc::ONCSource onc_source() const { return onc_source_; }
94
95 protected:
96 OncNetworkParser();
97
98 virtual Network* CreateNewNetwork(ConnectionType type,
99 const std::string& service_path) OVERRIDE;
100 virtual ConnectionType ParseType(const std::string& type) OVERRIDE;
101 virtual ConnectionType ParseTypeFromDictionary(
102 const base::DictionaryValue& info) OVERRIDE;
103
104 // Returns the type string from the dictionary of network values.
105 std::string GetTypeFromDictionary(const base::DictionaryValue& info);
106
107 // Returns the GUID string from the dictionary of network values.
108 std::string GetGuidFromDictionary(const base::DictionaryValue& info);
109
110 // Parse a field's value in the NetworkConfiguration object.
111 static bool ParseNetworkConfigurationValue(OncNetworkParser* parser,
112 PropertyIndex index,
113 const base::Value& value,
114 Network* network);
115
116 // Issue a diagnostic and return false if a type mismatch is found.
117 static bool CheckNetworkType(Network* network,
118 ConnectionType expected,
119 const std::string& onc_type);
120
121
122 // Find the PKCS#11 ID of the certificate with the given GUID. Returns
123 // an empty string on failure.
124 static std::string GetPkcs11IdFromCertGuid(const std::string& guid);
125
126 // Process ProxySettings dictionary into a format which is then updated into
127 // ProxyConfig property in shill.
128 static bool ProcessProxySettings(OncNetworkParser* parser,
129 const base::Value& value,
130 Network* network);
131
132 static ClientCertType ParseClientCertType(const std::string& type);
133
134 // Parse ClientCertPattern dictionary that specifies certificate pattern for
135 // VPN and WiFi EAP certificates.
136 static bool ParseClientCertPattern(OncNetworkParser* parser,
137 PropertyIndex index,
138 const base::Value& value,
139 Network* network);
140 private:
141 // Parse the ProxySettings dictionary.
142 static bool ParseProxySettingsValue(OncNetworkParser* parser,
143 PropertyIndex index,
144 const base::Value& value,
145 Network* network);
146
147 // Parse Type key of ProxySettings dictionary.
148 static ProxyOncType ParseProxyType(const std::string& type);
149
150 // Parse Manual dictionary that is child of ProxySettings dictionary.
151 static bool ParseProxyManualValue(OncNetworkParser* parser,
152 PropertyIndex index,
153 const base::Value& value,
154 Network* network);
155
156 // Parse proxy server for different schemes in Manual dictionary.
157 static bool ParseProxyServer(int property_index,
158 const base::Value& value,
159 const std::string& scheme,
160 Network* network);
161
162 // Parse ProxyLocation dictionary that specifies the manual proxy server.
163 static net::ProxyServer ParseProxyLocationValue(int property_index,
164 const base::Value& value);
165
166 // Parse IssuerSubjectPattern dictionary for certificate pattern fields.
167 static bool ParseIssuerPattern(OncNetworkParser* parser,
168 PropertyIndex index,
169 const base::Value& value,
170 Network* network);
171 static bool ParseSubjectPattern(OncNetworkParser* parser,
172 PropertyIndex index,
173 const base::Value& value,
174 Network* network);
175 static bool ParseIssuerSubjectPattern(IssuerSubjectPattern* pattern,
176 OncNetworkParser* parser,
177 PropertyIndex index,
178 const base::Value& value,
179 Network* network);
180
181 // Error message from the JSON parser, if applicable.
182 std::string parse_error_;
183
184 // Where the ONC blob comes from.
185 onc::ONCSource onc_source_;
186
187 scoped_ptr<base::ListValue> network_configs_;
188
189 DISALLOW_COPY_AND_ASSIGN(OncNetworkParser);
190 };
191
192 // Class for parsing Ethernet networks.
193 class OncEthernetNetworkParser : public OncNetworkParser {
194 public:
195 OncEthernetNetworkParser();
196 virtual ~OncEthernetNetworkParser();
197 static bool ParseEthernetValue(OncNetworkParser* parser,
198 PropertyIndex index,
199 const base::Value& value,
200 Network* ethernet_network);
201
202 private:
203 DISALLOW_COPY_AND_ASSIGN(OncEthernetNetworkParser);
204 };
205
206 // Base for wireless networks.
207 class OncWirelessNetworkParser : public OncNetworkParser {
208 public:
209 OncWirelessNetworkParser();
210 virtual ~OncWirelessNetworkParser();
211
212 private:
213 DISALLOW_COPY_AND_ASSIGN(OncWirelessNetworkParser);
214 };
215
216 // Class for parsing Wi-Fi networks.
217 class OncWifiNetworkParser : public OncWirelessNetworkParser {
218 public:
219 OncWifiNetworkParser();
220 virtual ~OncWifiNetworkParser();
221 static bool ParseWifiValue(OncNetworkParser* parser,
222 PropertyIndex index,
223 const base::Value& value,
224 Network* wifi_network);
225
226 protected:
227 static bool ParseEAPValue(OncNetworkParser* parser,
228 PropertyIndex index,
229 const base::Value& value,
230 Network* wifi_network);
231 static ConnectionSecurity ParseSecurity(const std::string& security);
232 static EAPMethod ParseEAPMethod(const std::string& method);
233 static EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth);
234
235 private:
236 DISALLOW_COPY_AND_ASSIGN(OncWifiNetworkParser);
237 };
238
239 // Class for parsing virtual private networks.
240 class OncVirtualNetworkParser : public OncNetworkParser {
241 public:
242 OncVirtualNetworkParser();
243 virtual ~OncVirtualNetworkParser();
244 virtual bool UpdateNetworkFromInfo(
245 const base::DictionaryValue& info, Network* network) OVERRIDE;
246 static bool ParseVPNValue(OncNetworkParser* parser,
247 PropertyIndex index,
248 const base::Value& value,
249 Network* network);
250
251 // network_library combines provider type and authentication type
252 // (L2TP-IPsec with PSK vs with Certificates). This function
253 // takes a provider type and adds an authentication type to return
254 // the updated provider type.
255 static ProviderType UpdateProviderTypeWithAuthType(
256 ProviderType provider,
257 const std::string& auth_type);
258
259 // This function takes a provider type (which includes authentication
260 // type) and returns the canonical provider type from it. For instance
261 // for L2TP-IPsec, the PSK provider type is the canonical one.
262 static ProviderType GetCanonicalProviderType(ProviderType provider_type);
263
264 static ProviderType ParseProviderType(const std::string& type);
265
266 protected:
267 static bool ParseIPsecValue(OncNetworkParser* parser,
268 PropertyIndex index,
269 const base::Value& value,
270 Network* network);
271 static bool ParseL2TPValue(OncNetworkParser* parser,
272 PropertyIndex index,
273 const base::Value& value,
274 Network* network);
275 static bool ParseOpenVPNValue(OncNetworkParser* parser,
276 PropertyIndex index,
277 const base::Value& value,
278 Network* network);
279
280 private:
281 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser);
282 };
283
284 } // namespace chromeos
285
286 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library_unittest.cc ('k') | chrome/browser/chromeos/cros/onc_network_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698