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

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

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

Powered by Google App Engine
This is Rietveld 408576698