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

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

Issue 20041002: Make CertificateHandler a proper interface of CertificateImporter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 7 years, 5 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 | 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 CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_H_ 5 #ifndef CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_IMPL_H_
6 #define CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_H_ 6 #define CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "chromeos/chromeos_export.h" 15 #include "chromeos/chromeos_export.h"
16 #include "chromeos/network/onc/onc_certificate_importer.h"
16 #include "chromeos/network/onc/onc_constants.h" 17 #include "chromeos/network/onc/onc_constants.h"
17 18
18 namespace base { 19 namespace base {
19 class DictionaryValue; 20 class DictionaryValue;
20 class ListValue; 21 class ListValue;
21 } 22 }
22 23
23 namespace net { 24 namespace net {
24 class X509Certificate; 25 class X509Certificate;
25 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; 26 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList;
26 } 27 }
27 28
28 namespace chromeos { 29 namespace chromeos {
29 namespace onc { 30 namespace onc {
30 31
31 // This class handles certificate imports from ONC (both policy and user 32 // This class handles certificate imports from ONC (both policy and user
32 // imports) into the certificate store. The GUID of Client certificates is 33 // imports) into the certificate store. The GUID of Client certificates is
33 // stored together with the certificate as Nickname. In contrast, Server and CA 34 // stored together with the certificate as Nickname. In contrast, Server and CA
34 // certificates are identified by their PEM and not by GUID. 35 // certificates are identified by their PEM and not by GUID.
35 // TODO(pneubeck): Replace Nickname by PEM for Client 36 // TODO(pneubeck): Replace Nickname by PEM for Client
36 // certificates. http://crbug.com/252119 37 // certificates. http://crbug.com/252119
37 class CHROMEOS_EXPORT CertificateImporter { 38 class CHROMEOS_EXPORT CertificateImporterImpl : public CertificateImporter {
38 public: 39 public:
39 typedef std::map<std::string, scoped_refptr<net::X509Certificate> > 40 typedef std::map<std::string, scoped_refptr<net::X509Certificate> >
40 CertsByGUID; 41 CertsByGUID;
41 enum ParseResult {
42 IMPORT_OK,
43 IMPORT_INCOMPLETE,
44 IMPORT_FAILED,
45 };
46 42
47 // During import with ParseCertificate(), Web trust is only applied to Server 43 CertificateImporterImpl();
48 // and Authority certificates with the TrustBits attribute "Web" if the
49 // |allow_trust_imports| permission is granted, otherwise the attribute is
50 // ignored.
51 explicit CertificateImporter(bool allow_trust_imports);
52 44
53 // Parses and stores the certificates in |onc_certificates| into the 45 // CertificateImporter overrides
54 // certificate store. If the "Remove" field of a certificate is enabled, then 46 virtual bool ImportCertificates(
55 // removes the certificate from the store instead of importing. Returns the 47 const base::ListValue& certificates,
56 // result of the parse operation. In case of IMPORT_INCOMPLETE, some of the 48 onc::ONCSource source,
57 // certificates may be stored/removed successfully while others had errors. 49 net::CertificateList* onc_trusted_certificates) OVERRIDE;
58 // If no error occurred, returns IMPORT_OK. If |onc_trusted_certificates| is 50
59 // not NULL, it will be filled with the list of certificates that requested 51 // This implements ImportCertificates. Additionally, if
60 // the Web trust flag. If |imported_server_and_ca_certs| is not null, it will 52 // |imported_server_and_ca_certs| is not NULL, it will be filled with the
61 // be filled with the (GUID, Certificate) pairs of all successfully imported 53 // (GUID, Certificate) pairs of all succesfully imported Server and CA
62 // Server and CA certificates. 54 // certificates.
63 ParseResult ParseAndStoreCertificates( 55 bool ParseAndStoreCertificates(bool allow_trust_imports,
64 const base::ListValue& onc_certificates, 56 const base::ListValue& onc_certificates,
65 net::CertificateList* onc_trusted_certificates, 57 net::CertificateList* onc_trusted_certificates,
66 CertsByGUID* imported_server_and_ca_certs); 58 CertsByGUID* imported_server_and_ca_certs);
67 59
68 // Lists the certificates that have the string |label| as their certificate 60 // Lists the certificates that have the string |label| as their certificate
69 // nickname (exact match). 61 // nickname (exact match).
70 static void ListCertsWithNickname(const std::string& label, 62 static void ListCertsWithNickname(const std::string& label,
71 net::CertificateList* result); 63 net::CertificateList* result);
72 64
73 protected: 65 private:
74 // 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
75 // match). 67 // match).
76 static bool DeleteCertAndKeyByNickname(const std::string& label); 68 static bool DeleteCertAndKeyByNickname(const std::string& label);
77 69
78 private:
79 // Parses and stores/removes |certificate| in/from the certificate 70 // Parses and stores/removes |certificate| in/from the certificate
80 // store. Returns true if the operation succeeded. 71 // store. Returns true if the operation succeeded.
81 bool ParseAndStoreCertificate( 72 bool ParseAndStoreCertificate(
73 bool allow_trust_imports,
82 const base::DictionaryValue& certificate, 74 const base::DictionaryValue& certificate,
83 net::CertificateList* onc_trusted_certificates, 75 net::CertificateList* onc_trusted_certificates,
84 CertsByGUID* imported_server_and_ca_certs); 76 CertsByGUID* imported_server_and_ca_certs);
85 77
78 // Imports the Server or CA certificate |certificate|. Web trust is only
79 // applied if the certificate requests the TrustBits attribute "Web" and if
80 // the |allow_trust_imports| permission is granted, otherwise the attribute is
81 // ignored.
86 bool ParseServerOrCaCertificate( 82 bool ParseServerOrCaCertificate(
83 bool allow_trust_imports,
87 const std::string& cert_type, 84 const std::string& cert_type,
88 const std::string& guid, 85 const std::string& guid,
89 const base::DictionaryValue& certificate, 86 const base::DictionaryValue& certificate,
90 net::CertificateList* onc_trusted_certificates, 87 net::CertificateList* onc_trusted_certificates,
91 CertsByGUID* imported_server_and_ca_certs); 88 CertsByGUID* imported_server_and_ca_certs);
92 89
93 bool ParseClientCertificate(const std::string& guid, 90 bool ParseClientCertificate(const std::string& guid,
94 const base::DictionaryValue& certificate); 91 const base::DictionaryValue& certificate);
95 92
96 // Whether certificates with TrustBits attribute "Web" should be stored with 93 DISALLOW_COPY_AND_ASSIGN(CertificateImporterImpl);
97 // web trust.
98 bool allow_trust_imports_;
99
100 DISALLOW_COPY_AND_ASSIGN(CertificateImporter);
101 }; 94 };
102 95
103 } // namespace onc 96 } // namespace onc
104 } // namespace chromeos 97 } // namespace chromeos
105 98
106 #endif // CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_H_ 99 #endif // CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_IMPL_H_
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_certificate_importer.cc ('k') | chromeos/network/onc/onc_certificate_importer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698