OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_IMPL_H_ | 5 #ifndef CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_IMPL_H_ |
6 #define CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_IMPL_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_certificate_importer.h" |
17 #include "components/onc/onc_constants.h" | 17 #include "components/onc/onc_constants.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class DictionaryValue; | 20 class DictionaryValue; |
21 class ListValue; | 21 class ListValue; |
22 } | 22 } |
23 | 23 |
24 namespace net { | 24 namespace net { |
| 25 class NSSCertDatabase; |
25 class X509Certificate; | 26 class X509Certificate; |
26 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; | 27 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; |
27 } | 28 } |
28 | 29 |
29 namespace chromeos { | 30 namespace chromeos { |
30 namespace onc { | 31 namespace onc { |
31 | 32 |
32 // This class handles certificate imports from ONC (both policy and user | 33 // This class handles certificate imports from ONC (both policy and user |
33 // imports) into the certificate store. The GUID of Client certificates is | 34 // imports) into the certificate store. The GUID of Client certificates is |
34 // stored together with the certificate as Nickname. In contrast, Server and CA | 35 // stored together with the certificate as Nickname. In contrast, Server and CA |
35 // certificates are identified by their PEM and not by GUID. | 36 // certificates are identified by their PEM and not by GUID. |
36 // TODO(pneubeck): Replace Nickname by PEM for Client | 37 // TODO(pneubeck): Replace Nickname by PEM for Client |
37 // certificates. http://crbug.com/252119 | 38 // certificates. http://crbug.com/252119 |
38 class CHROMEOS_EXPORT CertificateImporterImpl : public CertificateImporter { | 39 class CHROMEOS_EXPORT CertificateImporterImpl : public CertificateImporter { |
39 public: | 40 public: |
40 typedef std::map<std::string, scoped_refptr<net::X509Certificate> > | 41 typedef std::map<std::string, scoped_refptr<net::X509Certificate> > |
41 CertsByGUID; | 42 CertsByGUID; |
42 | 43 |
43 CertificateImporterImpl(); | 44 explicit CertificateImporterImpl(net::NSSCertDatabase* target_nssdb_); |
44 | 45 |
45 // CertificateImporter overrides | 46 // CertificateImporter overrides |
46 virtual bool ImportCertificates( | 47 virtual bool ImportCertificates( |
47 const base::ListValue& certificates, | 48 const base::ListValue& certificates, |
48 ::onc::ONCSource source, | 49 ::onc::ONCSource source, |
49 net::CertificateList* onc_trusted_certificates) OVERRIDE; | 50 net::CertificateList* onc_trusted_certificates) OVERRIDE; |
50 | 51 |
51 // This implements ImportCertificates. Additionally, if | 52 // This implements ImportCertificates. Additionally, if |
52 // |imported_server_and_ca_certs| is not NULL, it will be filled with the | 53 // |imported_server_and_ca_certs| is not NULL, it will be filled with the |
53 // (GUID, Certificate) pairs of all succesfully imported Server and CA | 54 // (GUID, Certificate) pairs of all succesfully imported Server and CA |
54 // certificates. | 55 // certificates. |
55 bool ParseAndStoreCertificates(bool allow_trust_imports, | 56 bool ParseAndStoreCertificates(bool allow_trust_imports, |
56 const base::ListValue& onc_certificates, | 57 const base::ListValue& onc_certificates, |
57 net::CertificateList* onc_trusted_certificates, | 58 net::CertificateList* onc_trusted_certificates, |
58 CertsByGUID* imported_server_and_ca_certs); | 59 CertsByGUID* imported_server_and_ca_certs); |
59 | 60 |
| 61 private: |
60 // Lists the certificates that have the string |label| as their certificate | 62 // Lists the certificates that have the string |label| as their certificate |
61 // nickname (exact match). | 63 // nickname (exact match). |
62 static void ListCertsWithNickname(const std::string& label, | 64 static void ListCertsWithNickname(const std::string& label, |
63 net::CertificateList* result); | 65 net::CertificateList* result, |
| 66 net::NSSCertDatabase* target_nssdb); |
64 | 67 |
65 private: | |
66 // Deletes any certificate that has the string |label| as its nickname (exact | 68 // Deletes any certificate that has the string |label| as its nickname (exact |
67 // match). | 69 // match). |
68 static bool DeleteCertAndKeyByNickname(const std::string& label); | 70 static bool DeleteCertAndKeyByNickname(const std::string& label, |
| 71 net::NSSCertDatabase* target_nssdb); |
69 | 72 |
70 // Parses and stores/removes |certificate| in/from the certificate | 73 // Parses and stores/removes |certificate| in/from the certificate |
71 // store. Returns true if the operation succeeded. | 74 // store. Returns true if the operation succeeded. |
72 bool ParseAndStoreCertificate( | 75 bool ParseAndStoreCertificate( |
73 bool allow_trust_imports, | 76 bool allow_trust_imports, |
74 const base::DictionaryValue& certificate, | 77 const base::DictionaryValue& certificate, |
75 net::CertificateList* onc_trusted_certificates, | 78 net::CertificateList* onc_trusted_certificates, |
76 CertsByGUID* imported_server_and_ca_certs); | 79 CertsByGUID* imported_server_and_ca_certs); |
77 | 80 |
78 // Imports the Server or CA certificate |certificate|. Web trust is only | 81 // Imports the Server or CA certificate |certificate|. Web trust is only |
79 // applied if the certificate requests the TrustBits attribute "Web" and if | 82 // applied if the certificate requests the TrustBits attribute "Web" and if |
80 // the |allow_trust_imports| permission is granted, otherwise the attribute is | 83 // the |allow_trust_imports| permission is granted, otherwise the attribute is |
81 // ignored. | 84 // ignored. |
82 bool ParseServerOrCaCertificate( | 85 bool ParseServerOrCaCertificate( |
83 bool allow_trust_imports, | 86 bool allow_trust_imports, |
84 const std::string& cert_type, | 87 const std::string& cert_type, |
85 const std::string& guid, | 88 const std::string& guid, |
86 const base::DictionaryValue& certificate, | 89 const base::DictionaryValue& certificate, |
87 net::CertificateList* onc_trusted_certificates, | 90 net::CertificateList* onc_trusted_certificates, |
88 CertsByGUID* imported_server_and_ca_certs); | 91 CertsByGUID* imported_server_and_ca_certs); |
89 | 92 |
90 bool ParseClientCertificate(const std::string& guid, | 93 bool ParseClientCertificate(const std::string& guid, |
91 const base::DictionaryValue& certificate); | 94 const base::DictionaryValue& certificate); |
92 | 95 |
| 96 // The certificate database to which certificates are imported. |
| 97 net::NSSCertDatabase* target_nssdb_; |
| 98 |
93 DISALLOW_COPY_AND_ASSIGN(CertificateImporterImpl); | 99 DISALLOW_COPY_AND_ASSIGN(CertificateImporterImpl); |
94 }; | 100 }; |
95 | 101 |
96 } // namespace onc | 102 } // namespace onc |
97 } // namespace chromeos | 103 } // namespace chromeos |
98 | 104 |
99 #endif // CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_IMPL_H_ | 105 #endif // CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_IMPL_H_ |
OLD | NEW |