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

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

Issue 8759014: Add ONC VPN support for OpenVPN and L2TP/IPsec VPNs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ 6 #define CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/compiler_specific.h" // for OVERRIDE 11 #include "base/compiler_specific.h" // for OVERRIDE
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/values.h"
13 #include "chrome/browser/chromeos/cros/network_parser.h" 14 #include "chrome/browser/chromeos/cros/network_parser.h"
14 15
15 namespace base { 16 namespace base {
16 class DictionaryValue; 17 class DictionaryValue;
17 class ListValue; 18 class ListValue;
18 class Value; 19 class Value;
19 } 20 }
20 21
21 namespace chromeos { 22 namespace chromeos {
22 23
24 // This is a simple representation of the signature of an ONC typed
25 // field, used in validation and translation. It could be extended
26 // to include more complex rules of when the field is required/optional,
27 // as well as to handle "enum" types, which are strings with a small
28 // static set of possible values.
29 struct OncValueSignature {
30 const char* field;
31 PropertyIndex index;
32 base::Value::Type type;
33 };
34
23 // This is the network parser that parses the data from an Open Network 35 // This is the network parser that parses the data from an Open Network
24 // Configuration (ONC) file. ONC files are in JSON format that describes 36 // Configuration (ONC) file. ONC files are in JSON format that describes
25 // networks. We will use this parser to parse the ONC JSON blob. 37 // networks. We will use this parser to parse the ONC JSON blob.
26 // 38 //
27 // For ONC file format, see: http://dev.chromium.org/chromium-os/ 39 // For ONC file format, see: http://dev.chromium.org/chromium-os/
28 // chromiumos-design-docs/open-network-configuration 40 // chromiumos-design-docs/open-network-configuration
29 class OncNetworkParser : public NetworkParser { 41 class OncNetworkParser : public NetworkParser {
30 public: 42 public:
43 typedef bool (*ParserPointer)(OncNetworkParser*,
44 PropertyIndex,
45 const base::Value&,
46 Network*);
47
31 explicit OncNetworkParser(const std::string& onc_blob); 48 explicit OncNetworkParser(const std::string& onc_blob);
32 virtual ~OncNetworkParser(); 49 virtual ~OncNetworkParser();
33 static const EnumMapper<PropertyIndex>* property_mapper(); 50 static const EnumMapper<PropertyIndex>* property_mapper();
34 51
35 // Returns the number of networks in the "NetworkConfigs" list. 52 // Returns the number of networks in the "NetworkConfigs" list.
36 int GetNetworkConfigsSize() const; 53 int GetNetworkConfigsSize() const;
37 54
38 // Returns the number of certificates in the "Certificates" list. 55 // Returns the number of certificates in the "Certificates" list.
39 int GetCertificatesSize() const; 56 int GetCertificatesSize() const;
40 57
41 // Call to create the network by parsing network config in the nth position. 58 // Call to create the network by parsing network config in the nth position.
42 // (0-based). Returns NULL if there's a parse error or if n is out of range. 59 // (0-based). Returns NULL if there's a parse error or if n is out of range.
43 Network* ParseNetwork(int n); 60 Network* ParseNetwork(int n);
44 61
45 // Call to parse and import the nth certificate in the certificate 62 // Call to parse and import the nth certificate in the certificate
46 // list. Returns false on failure. 63 // list. Returns false on failure.
47 bool ParseCertificate(int n); 64 bool ParseCertificate(int n);
48 65
49 virtual Network* CreateNetworkFromInfo(const std::string& service_path, 66 virtual Network* CreateNetworkFromInfo(const std::string& service_path,
50 const base::DictionaryValue& info) OVERRIDE; 67 const base::DictionaryValue& info) OVERRIDE;
51 68
69 // Parses a nested ONC object with the given mapper and parser function.
70 // If Value is not the proper type or there is an error in parsing
71 // any individual field, VLOGs diagnostics, and returns false.
72 bool ParseNestedObject(Network* network,
73 const std::string& onc_type,
74 const base::Value& value,
75 OncValueSignature* signature,
76 ParserPointer parser);
77
52 const std::string& parse_error() const { return parse_error_; } 78 const std::string& parse_error() const { return parse_error_; }
53 79
54 protected: 80 protected:
55 OncNetworkParser(); 81 OncNetworkParser();
56 82
57 virtual Network* CreateNewNetwork(ConnectionType type, 83 virtual Network* CreateNewNetwork(ConnectionType type,
58 const std::string& service_path) OVERRIDE; 84 const std::string& service_path) OVERRIDE;
59 virtual ConnectionType ParseType(const std::string& type) OVERRIDE; 85 virtual ConnectionType ParseType(const std::string& type) OVERRIDE;
60 virtual ConnectionType ParseTypeFromDictionary( 86 virtual ConnectionType ParseTypeFromDictionary(
61 const base::DictionaryValue& info) OVERRIDE; 87 const base::DictionaryValue& info) OVERRIDE;
62 88
63 // Returns the type string from the dictionary of network values. 89 // Returns the type string from the dictionary of network values.
64 std::string GetTypeFromDictionary(const base::DictionaryValue& info); 90 std::string GetTypeFromDictionary(const base::DictionaryValue& info);
65 91
66 // Returns the GUID string from the dictionary of network values. 92 // Returns the GUID string from the dictionary of network values.
67 std::string GetGuidFromDictionary(const base::DictionaryValue& info); 93 std::string GetGuidFromDictionary(const base::DictionaryValue& info);
68 94
95 // Parse a field's value in the NetworkConfiguration object.
96 static bool ParseNetworkConfigurationValue(OncNetworkParser* parser,
97 PropertyIndex index,
98 const base::Value& value,
99 Network* network);
100
101 // Issue a diagnostic and return false if a type mismatch is found.
102 static bool CheckNetworkType(Network* network,
103 ConnectionType expected,
104 const std::string& onc_type);
105
106 // Return the string value of |value|. If not a string, returns empty
107 // string.
108 static std::string GetStringValue(const base::Value& value);
109
110 // Return the boolean value of |value|. If not a boolean, returns false.
111 static const bool GetBooleanValue(const base::Value& value);
112
113 // Convert the value of |value| to its string representation. Integers
114 // convert to base10 strings, bools convert to true/false. Strings
115 // remains as is.
116 static std::string ConvertValueToString(const base::Value& value);
stevenjb 2011/12/05 18:38:18 Do any of these need to be static members, or coul
kmixter1 2011/12/05 20:34:43 Done.
117
69 private: 118 private:
70 bool ParseServerOrCaCertificate( 119 bool ParseServerOrCaCertificate(
71 int cert_index, 120 int cert_index,
72 const std::string& cert_type, 121 const std::string& cert_type,
73 base::DictionaryValue* certificate); 122 base::DictionaryValue* certificate);
74 bool ParseClientCertificate( 123 bool ParseClientCertificate(
75 int cert_index, 124 int cert_index,
76 base::DictionaryValue* certificate); 125 base::DictionaryValue* certificate);
77 126
78 // Error message from the JSON parser, if applicable. 127 // Error message from the JSON parser, if applicable.
79 std::string parse_error_; 128 std::string parse_error_;
80 129
81 scoped_ptr<base::DictionaryValue> root_dict_; 130 scoped_ptr<base::DictionaryValue> root_dict_;
82 base::ListValue* network_configs_; 131 base::ListValue* network_configs_;
83 base::ListValue* certificates_; 132 base::ListValue* certificates_;
84 133
85 DISALLOW_COPY_AND_ASSIGN(OncNetworkParser); 134 DISALLOW_COPY_AND_ASSIGN(OncNetworkParser);
86 }; 135 };
87 136
88 // Base for wireless networks. 137 // Base for wireless networks.
89 class OncWirelessNetworkParser : public OncNetworkParser { 138 class OncWirelessNetworkParser : public OncNetworkParser {
90 public: 139 public:
91 OncWirelessNetworkParser(); 140 OncWirelessNetworkParser();
92 virtual ~OncWirelessNetworkParser(); 141 virtual ~OncWirelessNetworkParser();
93 virtual bool ParseValue(PropertyIndex index, 142
94 const base::Value& value,
95 Network* network) OVERRIDE;
96 private: 143 private:
97 DISALLOW_COPY_AND_ASSIGN(OncWirelessNetworkParser); 144 DISALLOW_COPY_AND_ASSIGN(OncWirelessNetworkParser);
98 }; 145 };
99 146
147 // Class for parsing Wi-Fi networks.
100 class OncWifiNetworkParser : public OncWirelessNetworkParser { 148 class OncWifiNetworkParser : public OncWirelessNetworkParser {
101 public: 149 public:
102 OncWifiNetworkParser(); 150 OncWifiNetworkParser();
103 virtual ~OncWifiNetworkParser(); 151 virtual ~OncWifiNetworkParser();
104 virtual bool ParseValue(PropertyIndex index, 152 static bool ParseWifiValue(OncNetworkParser* parser,
105 const base::Value& value, 153 PropertyIndex index,
106 Network* network) OVERRIDE; 154 const base::Value& value,
155 Network* wifi_network);
156
107 protected: 157 protected:
108 bool ParseEAPValue(PropertyIndex index, 158 static bool ParseEAPValue(OncNetworkParser* parser,
109 const base::Value& value, 159 PropertyIndex index,
110 WifiNetwork* wifi_network); 160 const base::Value& value,
111 ConnectionSecurity ParseSecurity(const std::string& security); 161 Network* wifi_network);
112 EAPMethod ParseEAPMethod(const std::string& method); 162 static ConnectionSecurity ParseSecurity(const std::string& security);
113 EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth); 163 static EAPMethod ParseEAPMethod(const std::string& method);
164 static EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth);
165
114 private: 166 private:
115 DISALLOW_COPY_AND_ASSIGN(OncWifiNetworkParser); 167 DISALLOW_COPY_AND_ASSIGN(OncWifiNetworkParser);
116 }; 168 };
117 169
170 // Class for parsing virtual private networks.
118 class OncVirtualNetworkParser : public OncNetworkParser { 171 class OncVirtualNetworkParser : public OncNetworkParser {
119 public: 172 public:
120 OncVirtualNetworkParser(); 173 OncVirtualNetworkParser();
121 virtual ~OncVirtualNetworkParser(); 174 virtual ~OncVirtualNetworkParser();
122 virtual bool ParseValue(PropertyIndex index,
123 const base::Value& value,
124 Network* network) OVERRIDE;
125 virtual bool UpdateNetworkFromInfo( 175 virtual bool UpdateNetworkFromInfo(
126 const base::DictionaryValue& info, Network* network) OVERRIDE; 176 const base::DictionaryValue& info, Network* network) OVERRIDE;
177 static bool ParseVPNValue(OncNetworkParser* parser,
178 PropertyIndex index,
179 const base::Value& value,
180 Network* network);
181
182 // network_library combines provider type and authentication type
183 // (L2TP-IPsec with PSK vs with Certificates). This function
184 // takes a provider type and adds an authentication type to return
185 // the updated provider type.
186 static ProviderType UpdateProviderTypeWithAuthType(
187 ProviderType provider,
188 const std::string& auth_type);
189
190 // This function takes a provider type (which includes authentication
191 // type) and returns the canonical provider type from it. For instance
192 // for L2TP-IPsec, the PSK provider type is the canonical one.
193 static ProviderType GetCanonicalProviderType(ProviderType provider_type);
194
195 static ProviderType ParseProviderType(const std::string& type);
196
127 protected: 197 protected:
128 bool ParseProviderValue(PropertyIndex index, 198 static bool ParseIPsecValue(OncNetworkParser* parser,
129 const base::Value& value, 199 PropertyIndex index,
130 VirtualNetwork* network); 200 const base::Value& value,
131 ProviderType ParseProviderType(const std::string& type); 201 Network* network);
202 static bool ParseL2TPValue(OncNetworkParser* parser,
203 PropertyIndex index,
204 const base::Value& value,
205 Network* network);
206 static bool ParseOpenVPNValue(OncNetworkParser* parser,
207 PropertyIndex index,
208 const base::Value& value,
209 Network* network);
210
132 private: 211 private:
133 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); 212 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser);
134 }; 213 };
135 214
136 } // namespace chromeos 215 } // namespace chromeos
137 216
138 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ 217 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.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