Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // If the "Remove" field of a certificate is enabled, then removes the |
| 55 // removes the certificate from the store instead of importing. Returns the | 47 // certificate from the store instead of importing. |
|
Mattias Nissler (ping if slow)
2013/07/24 11:25:40
Shouldn't this comment be on the interface.
pneubeck (no reviews)
2013/07/25 08:03:23
Done.
| |
| 56 // result of the parse operation. In case of IMPORT_INCOMPLETE, some of the | 48 virtual bool ImportCertificates( |
| 57 // certificates may be stored/removed successfully while others had errors. | 49 const base::ListValue& certificates, |
| 58 // If no error occurred, returns IMPORT_OK. If |onc_trusted_certificates| is | 50 onc::ONCSource source, |
| 59 // not NULL, it will be filled with the list of certificates that requested | 51 net::CertificateList* onc_trusted_certificates) OVERRIDE; |
| 60 // the Web trust flag. If |imported_server_and_ca_certs| is not null, it will | 52 |
| 61 // be filled with the (GUID, Certificate) pairs of all successfully imported | 53 // This implements ImportCertificates. Additionally, if |
| 62 // Server and CA certificates. | 54 // |imported_server_and_ca_certs| is not NULL, it will be filled with the |
| 63 ParseResult ParseAndStoreCertificates( | 55 // (GUID, Certificate) pairs of all succesfully imported Server and CA |
| 64 const base::ListValue& onc_certificates, | 56 // certificates. |
| 65 net::CertificateList* onc_trusted_certificates, | 57 bool ParseAndStoreCertificates(bool allow_trust_imports, |
| 66 CertsByGUID* imported_server_and_ca_certs); | 58 const base::ListValue& onc_certificates, |
| 59 net::CertificateList* onc_trusted_certificates, | |
| 60 CertsByGUID* imported_server_and_ca_certs); | |
| 67 | 61 |
| 68 // Lists the certificates that have the string |label| as their certificate | 62 // Lists the certificates that have the string |label| as their certificate |
| 69 // nickname (exact match). | 63 // nickname (exact match). |
| 70 static void ListCertsWithNickname(const std::string& label, | 64 static void ListCertsWithNickname(const std::string& label, |
| 71 net::CertificateList* result); | 65 net::CertificateList* result); |
| 72 | 66 |
| 73 protected: | 67 private: |
| 74 // 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 |
| 75 // match). | 69 // match). |
| 76 static bool DeleteCertAndKeyByNickname(const std::string& label); | 70 static bool DeleteCertAndKeyByNickname(const std::string& label); |
| 77 | 71 |
| 78 private: | |
| 79 // Parses and stores/removes |certificate| in/from the certificate | 72 // Parses and stores/removes |certificate| in/from the certificate |
| 80 // store. Returns true if the operation succeeded. | 73 // store. Returns true if the operation succeeded. |
| 81 bool ParseAndStoreCertificate( | 74 bool ParseAndStoreCertificate( |
| 75 bool allow_trust_imports, | |
| 82 const base::DictionaryValue& certificate, | 76 const base::DictionaryValue& certificate, |
| 83 net::CertificateList* onc_trusted_certificates, | 77 net::CertificateList* onc_trusted_certificates, |
| 84 CertsByGUID* imported_server_and_ca_certs); | 78 CertsByGUID* imported_server_and_ca_certs); |
| 85 | 79 |
| 80 // Imports the Server or CA certificate |certificate|. Web trust is only | |
| 81 // applied if the certificate requests the TrustBits attribute "Web" and if | |
| 82 // the |allow_trust_imports| permission is granted, otherwise the attribute is | |
| 83 // ignored. | |
| 86 bool ParseServerOrCaCertificate( | 84 bool ParseServerOrCaCertificate( |
| 85 bool allow_trust_imports, | |
| 87 const std::string& cert_type, | 86 const std::string& cert_type, |
| 88 const std::string& guid, | 87 const std::string& guid, |
| 89 const base::DictionaryValue& certificate, | 88 const base::DictionaryValue& certificate, |
| 90 net::CertificateList* onc_trusted_certificates, | 89 net::CertificateList* onc_trusted_certificates, |
| 91 CertsByGUID* imported_server_and_ca_certs); | 90 CertsByGUID* imported_server_and_ca_certs); |
| 92 | 91 |
| 93 bool ParseClientCertificate(const std::string& guid, | 92 bool ParseClientCertificate(const std::string& guid, |
| 94 const base::DictionaryValue& certificate); | 93 const base::DictionaryValue& certificate); |
| 95 | 94 |
| 96 // Whether certificates with TrustBits attribute "Web" should be stored with | 95 DISALLOW_COPY_AND_ASSIGN(CertificateImporterImpl); |
| 97 // web trust. | |
| 98 bool allow_trust_imports_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(CertificateImporter); | |
| 101 }; | 96 }; |
| 102 | 97 |
| 103 } // namespace onc | 98 } // namespace onc |
| 104 } // namespace chromeos | 99 } // namespace chromeos |
| 105 | 100 |
| 106 #endif // CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_H_ | 101 #endif // CHROMEOS_NETWORK_ONC_ONC_CERTIFICATE_IMPORTER_IMPL_H_ |
| OLD | NEW |