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

Side by Side Diff: chromeos/network/onc/onc_certificate_importer.h

Issue 11299236: This moves the ONC parsing code into chromeos/network/onc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit tests Created 8 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) 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 #ifndef CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_CERTIFICATE_IMPORTER_H_ 5 #ifndef CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_H_
6 #define CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_CERTIFICATE_IMPORTER_H_ 6 #define CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/chromeos/cros/network_ui_data.h" 14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/network/onc/onc_constants.h"
15 16
16 namespace base { 17 namespace base {
17 class DictionaryValue; 18 class DictionaryValue;
18 class ListValue; 19 class ListValue;
19 } 20 }
20 21
21 namespace net { 22 namespace net {
22 class X509Certificate; 23 class X509Certificate;
23 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; 24 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList;
24 } 25 }
25 26
26 namespace chromeos { 27 namespace chromeos {
27 namespace onc { 28 namespace onc {
28 29
29 // This class handles certificate imports from ONC (both policy and user 30 // This class handles certificate imports from ONC (both policy and user
30 // imports) into the certificate store. In particular, the GUID of certificates 31 // imports) into the certificate store. In particular, the GUID of certificates
31 // is stored together with the certificate as Nickname. 32 // is stored together with the certificate as Nickname.
32 class CertificateImporter { 33 class CHROMEOS_EXPORT CertificateImporter {
33 public: 34 public:
35 enum ParseResult {
36 IMPORT_OK,
37 IMPORT_INCOMPLETE,
38 IMPORT_FAILED,
39 };
40
34 // Certificates pushed from a policy source with Web trust are only imported 41 // Certificates pushed from a policy source with Web trust are only imported
35 // with ParseCertificate() if the |allow_web_trust_from_policy| permission is 42 // with ParseCertificate() if the |allow_web_trust_from_policy| permission is
36 // granted. 43 // granted.
37 CertificateImporter(NetworkUIData::ONCSource onc_source, 44 CertificateImporter(ONCSource onc_source,
38 bool allow_web_trust_from_policy); 45 bool allow_web_trust_from_policy);
39 46
40 // Parses and stores the certificates in |onc_certificates| into the 47 // Parses and stores the certificates in |onc_certificates| into the
41 // certificate store. If the "Remove" field of a certificate is enabled, then 48 // certificate store. If the "Remove" field of a certificate is enabled, then
42 // removes the certificate from the store instead of importing. Returns false 49 // removes the certificate from the store instead of importing. Returns the
43 // and sets |error| to a user readable message if an error occured. In that 50 // result of the parse operation. In case of IMPORT_INCOMPLETE, some of the
44 // case, some of the certificates may already be stored/removed. Otherwise, if 51 // certificates may be stored/removed successfully while others had errors.
45 // no error occured, returns true and doesn't modify |error|. 52 // If no error occurred, returns IMPORT_OK.
46 bool ParseAndStoreCertificates(const base::ListValue& onc_certificates, 53 ParseResult ParseAndStoreCertificates(
47 std::string* error); 54 const base::ListValue& onc_certificates);
48 55
49 // Parses and stores/removes |certificate| in/from the certificate 56 // Parses and stores/removes |certificate| in/from the certificate
50 // store. Returns false if an error occured. Returns true otherwise. 57 // store. Returns true if the operation succeeded.
51 bool ParseAndStoreCertificate(const base::DictionaryValue& certificate); 58 bool ParseAndStoreCertificate(const base::DictionaryValue& certificate);
52 59
53 // Lists the certificates that have the string |label| as their certificate 60 // Lists the certificates that have the string |label| as their certificate
54 // nickname (exact match). 61 // nickname (exact match).
55 static void ListCertsWithNickname(const std::string& label, 62 static void ListCertsWithNickname(const std::string& label,
56 net::CertificateList* result); 63 net::CertificateList* result);
57 64
58 protected: 65 protected:
59 // Deletes any certificate that has the string |label| as its nickname (exact 66 // Deletes any certificate that has the string |label| as its nickname (exact
60 // match). 67 // match).
61 static bool DeleteCertAndKeyByNickname(const std::string& label); 68 static bool DeleteCertAndKeyByNickname(const std::string& label);
62 69
63 private: 70 private:
64 bool ParseServerOrCaCertificate( 71 bool ParseServerOrCaCertificate(const std::string& cert_type,
65 const std::string& cert_type, 72 const std::string& guid,
66 const std::string& guid, 73 const base::DictionaryValue& certificate);
67 const base::DictionaryValue& certificate); 74
68 bool ParseClientCertificate( 75 bool ParseClientCertificate(const std::string& guid,
69 const std::string& guid, 76 const base::DictionaryValue& certificate);
70 const base::DictionaryValue& certificate);
71 77
72 // Where the ONC blob comes from. 78 // Where the ONC blob comes from.
73 NetworkUIData::ONCSource onc_source_; 79 ONCSource onc_source_;
74 80
75 // Whether certificates with Web trust should be stored when pushed from a 81 // Whether certificates with Web trust should be stored when pushed from a
76 // policy source. 82 // policy source.
77 bool allow_web_trust_from_policy_; 83 bool allow_web_trust_from_policy_;
78 84
79 std::string error_;
80
81 DISALLOW_COPY_AND_ASSIGN(CertificateImporter); 85 DISALLOW_COPY_AND_ASSIGN(CertificateImporter);
82 }; 86 };
83 87
84 } // chromeos 88 } // chromeos
85 } // onc 89 } // onc
86 90
87 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_CERTIFICATE_IMPORTER_H_ 91 #endif // CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_H_
OLDNEW
« no previous file with comments | « chromeos/network/network_event_log_unittest.cc ('k') | chromeos/network/onc/onc_certificate_importer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698