OLD | NEW |
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/gtest_prod_util.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.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 |
| 22 namespace net { |
| 23 class X509Certificate; |
| 24 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; |
| 25 } |
| 26 |
21 namespace chromeos { | 27 namespace chromeos { |
22 | 28 |
23 // This is the network parser that parses the data from an Open Network | 29 // 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 | 30 // Configuration (ONC) file. ONC files are in JSON format that describes |
25 // networks. We will use this parser to parse the ONC JSON blob. | 31 // networks. We will use this parser to parse the ONC JSON blob. |
26 // | 32 // |
27 // For ONC file format, see: http://dev.chromium.org/chromium-os/ | 33 // For ONC file format, see: http://dev.chromium.org/chromium-os/ |
28 // chromiumos-design-docs/open-network-configuration | 34 // chromiumos-design-docs/open-network-configuration |
29 class OncNetworkParser : public NetworkParser { | 35 class OncNetworkParser : public NetworkParser { |
30 public: | 36 public: |
31 explicit OncNetworkParser(const std::string& onc_blob); | 37 explicit OncNetworkParser(const std::string& onc_blob); |
32 virtual ~OncNetworkParser(); | 38 virtual ~OncNetworkParser(); |
33 static const EnumMapper<PropertyIndex>* property_mapper(); | 39 static const EnumMapper<PropertyIndex>* property_mapper(); |
34 | 40 |
35 // Returns the number of networks in the "NetworkConfigs" list. | 41 // Returns the number of networks in the "NetworkConfigs" list. |
36 int GetNetworkConfigsSize() const; | 42 int GetNetworkConfigsSize() const; |
37 | 43 |
38 // Returns the number of certificates in the "Certificates" list. | |
39 int GetCertificatesSize() const; | |
40 | |
41 // Call to create the network by parsing network config in the nth position. | 44 // 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. | 45 // (0-based). Returns NULL if there's a parse error or if n is out of range. |
43 Network* ParseNetwork(int n); | 46 Network* ParseNetwork(int n); |
44 | 47 |
| 48 // Returns the number of certificates in the "Certificates" list. |
| 49 int GetCertificatesSize() const; |
| 50 |
45 // Call to parse and import the nth certificate in the certificate | 51 // Call to parse and import the nth certificate in the certificate |
46 // list. Returns false on failure. | 52 // list into the certificate store. Returns a NULL refptr if |
47 bool ParseCertificate(int n); | 53 // there's a parse error or if n is out of range. |
| 54 scoped_refptr<net::X509Certificate> ParseCertificate(int n); |
48 | 55 |
49 virtual Network* CreateNetworkFromInfo(const std::string& service_path, | 56 virtual Network* CreateNetworkFromInfo(const std::string& service_path, |
50 const base::DictionaryValue& info) OVERRIDE; | 57 const base::DictionaryValue& info) OVERRIDE; |
51 | 58 |
52 const std::string& parse_error() const { return parse_error_; } | 59 const std::string& parse_error() const { return parse_error_; } |
53 | 60 |
54 protected: | 61 protected: |
55 OncNetworkParser(); | 62 OncNetworkParser(); |
56 | 63 |
57 virtual Network* CreateNewNetwork(ConnectionType type, | 64 virtual Network* CreateNewNetwork(ConnectionType type, |
58 const std::string& service_path) OVERRIDE; | 65 const std::string& service_path) OVERRIDE; |
59 virtual ConnectionType ParseType(const std::string& type) OVERRIDE; | 66 virtual ConnectionType ParseType(const std::string& type) OVERRIDE; |
60 virtual ConnectionType ParseTypeFromDictionary( | 67 virtual ConnectionType ParseTypeFromDictionary( |
61 const base::DictionaryValue& info) OVERRIDE; | 68 const base::DictionaryValue& info) OVERRIDE; |
62 | 69 |
63 // Returns the type string from the dictionary of network values. | 70 // Returns the type string from the dictionary of network values. |
64 std::string GetTypeFromDictionary(const base::DictionaryValue& info); | 71 std::string GetTypeFromDictionary(const base::DictionaryValue& info); |
65 | 72 |
66 // Returns the GUID string from the dictionary of network values. | 73 // Returns the GUID string from the dictionary of network values. |
67 std::string GetGuidFromDictionary(const base::DictionaryValue& info); | 74 std::string GetGuidFromDictionary(const base::DictionaryValue& info); |
68 | 75 |
69 private: | 76 private: |
70 bool ParseServerOrCaCertificate( | 77 FRIEND_TEST_ALL_PREFIXES(OncNetworkParserTest, TestAddClientCertificate); |
| 78 FRIEND_TEST_ALL_PREFIXES(OncNetworkParserTest, TestAddServerCertificate); |
| 79 FRIEND_TEST_ALL_PREFIXES(OncNetworkParserTest, TestAddAuthorityCertificate); |
| 80 scoped_refptr<net::X509Certificate> ParseServerOrCaCertificate( |
71 int cert_index, | 81 int cert_index, |
72 const std::string& cert_type, | 82 const std::string& cert_type, |
| 83 const std::string& guid, |
73 base::DictionaryValue* certificate); | 84 base::DictionaryValue* certificate); |
74 bool ParseClientCertificate( | 85 scoped_refptr<net::X509Certificate> ParseClientCertificate( |
75 int cert_index, | 86 int cert_index, |
| 87 const std::string& guid, |
76 base::DictionaryValue* certificate); | 88 base::DictionaryValue* certificate); |
| 89 static void ListCertsWithLabel(const std::string& label, |
| 90 net::CertificateList* result); |
| 91 static bool DeleteCertAndKeyByLabel(const std::string& label); |
77 | 92 |
78 // Error message from the JSON parser, if applicable. | 93 // Error message from the JSON parser, if applicable. |
79 std::string parse_error_; | 94 std::string parse_error_; |
80 | 95 |
81 scoped_ptr<base::DictionaryValue> root_dict_; | 96 scoped_ptr<base::DictionaryValue> root_dict_; |
82 base::ListValue* network_configs_; | 97 base::ListValue* network_configs_; |
83 base::ListValue* certificates_; | 98 base::ListValue* certificates_; |
84 | 99 |
85 DISALLOW_COPY_AND_ASSIGN(OncNetworkParser); | 100 DISALLOW_COPY_AND_ASSIGN(OncNetworkParser); |
86 }; | 101 }; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 const base::Value& value, | 144 const base::Value& value, |
130 VirtualNetwork* network); | 145 VirtualNetwork* network); |
131 ProviderType ParseProviderType(const std::string& type); | 146 ProviderType ParseProviderType(const std::string& type); |
132 private: | 147 private: |
133 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); | 148 DISALLOW_COPY_AND_ASSIGN(OncVirtualNetworkParser); |
134 }; | 149 }; |
135 | 150 |
136 } // namespace chromeos | 151 } // namespace chromeos |
137 | 152 |
138 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ | 153 #endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_NETWORK_PARSER_H_ |
OLD | NEW |