| 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 CHROME_BROWSER_CERTIFICATE_MANAGER_MODEL_H_ | 5 #ifndef CHROME_BROWSER_CERTIFICATE_MANAGER_MODEL_H_ |
| 6 #define CHROME_BROWSER_CERTIFICATE_MANAGER_MODEL_H_ | 6 #define CHROME_BROWSER_CERTIFICATE_MANAGER_MODEL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "net/base/cert_database.h" | 13 #include "net/base/nss_cert_database.h" |
| 14 | 14 |
| 15 // CertificateManagerModel provides the data to be displayed in the certificate | 15 // CertificateManagerModel provides the data to be displayed in the certificate |
| 16 // manager dialog, and processes changes from the view. | 16 // manager dialog, and processes changes from the view. |
| 17 class CertificateManagerModel { | 17 class CertificateManagerModel { |
| 18 public: | 18 public: |
| 19 // Map from the subject organization name to the list of certs from that | 19 // Map from the subject organization name to the list of certs from that |
| 20 // organization. If a cert does not have an organization name, the | 20 // organization. If a cert does not have an organization name, the |
| 21 // subject's CertPrincipal::GetDisplayName() value is used instead. | 21 // subject's CertPrincipal::GetDisplayName() value is used instead. |
| 22 typedef std::map<std::string, net::CertificateList> OrgGroupingMap; | 22 typedef std::map<std::string, net::CertificateList> OrgGroupingMap; |
| 23 | 23 |
| 24 // Enumeration of the possible columns in the certificate manager tree view. | 24 // Enumeration of the possible columns in the certificate manager tree view. |
| 25 enum Column { | 25 enum Column { |
| 26 COL_SUBJECT_NAME, | 26 COL_SUBJECT_NAME, |
| 27 COL_CERTIFICATE_STORE, | 27 COL_CERTIFICATE_STORE, |
| 28 COL_SERIAL_NUMBER, | 28 COL_SERIAL_NUMBER, |
| 29 COL_EXPIRES_ON, | 29 COL_EXPIRES_ON, |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 class Observer { | 32 class Observer { |
| 33 public: | 33 public: |
| 34 // Called to notify the view that the certificate list has been refreshed. | 34 // Called to notify the view that the certificate list has been refreshed. |
| 35 // TODO(mattm): do a more granular updating strategy? Maybe retrieve new | 35 // TODO(mattm): do a more granular updating strategy? Maybe retrieve new |
| 36 // list of certs, diff against past list, and then notify of the changes? | 36 // list of certs, diff against past list, and then notify of the changes? |
| 37 virtual void CertificatesRefreshed() = 0; | 37 virtual void CertificatesRefreshed() = 0; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 explicit CertificateManagerModel(Observer* observer); | 40 explicit CertificateManagerModel(Observer* observer); |
| 41 ~CertificateManagerModel(); | 41 ~CertificateManagerModel(); |
| 42 | 42 |
| 43 // Accessor for read-only access to the underlying CertDatabase. | 43 // Accessor for read-only access to the underlying NSSCertDatabase. |
| 44 const net::CertDatabase& cert_db() const { return cert_db_; } | 44 const net::NSSCertDatabase& cert_db() const { return cert_db_; } |
| 45 | 45 |
| 46 // Trigger a refresh of the list of certs, unlock any slots if necessary. | 46 // Trigger a refresh of the list of certs, unlock any slots if necessary. |
| 47 // Following this call, the observer CertificatesRefreshed method will be | 47 // Following this call, the observer CertificatesRefreshed method will be |
| 48 // called so the view can call FilterAndBuildOrgGroupingMap as necessary to | 48 // called so the view can call FilterAndBuildOrgGroupingMap as necessary to |
| 49 // refresh its tree views. | 49 // refresh its tree views. |
| 50 void Refresh(); | 50 void Refresh(); |
| 51 | 51 |
| 52 // Fill |map| with the certificates matching |filter_type|. | 52 // Fill |map| with the certificates matching |filter_type|. |
| 53 void FilterAndBuildOrgGroupingMap(net::CertType filter_type, | 53 void FilterAndBuildOrgGroupingMap(net::CertType filter_type, |
| 54 OrgGroupingMap* map) const; | 54 OrgGroupingMap* map) const; |
| 55 | 55 |
| 56 // Get the data to be displayed in |column| for the given |cert|. | 56 // Get the data to be displayed in |column| for the given |cert|. |
| 57 string16 GetColumnText(const net::X509Certificate& cert, Column column) const; | 57 string16 GetColumnText(const net::X509Certificate& cert, Column column) const; |
| 58 | 58 |
| 59 // Import private keys and certificates from PKCS #12 encoded | 59 // Import private keys and certificates from PKCS #12 encoded |
| 60 // |data|, using the given |password|. If |is_extractable| is false, | 60 // |data|, using the given |password|. If |is_extractable| is false, |
| 61 // mark the private key as unextractable from the module. | 61 // mark the private key as unextractable from the module. |
| 62 // Returns a net error code on failure. | 62 // Returns a net error code on failure. |
| 63 int ImportFromPKCS12(net::CryptoModule* module, const std::string& data, | 63 int ImportFromPKCS12(net::CryptoModule* module, const std::string& data, |
| 64 const string16& password, bool is_extractable); | 64 const string16& password, bool is_extractable); |
| 65 | 65 |
| 66 // Import CA certificates. | 66 // Import CA certificates. |
| 67 // Tries to import all the certificates given. The root will be trusted | 67 // Tries to import all the certificates given. The root will be trusted |
| 68 // according to |trust_bits|. Any certificates that could not be imported | 68 // according to |trust_bits|. Any certificates that could not be imported |
| 69 // will be listed in |not_imported|. | 69 // will be listed in |not_imported|. |
| 70 // |trust_bits| should be a bit field of TRUST* values from CertDatabase. | 70 // |trust_bits| should be a bit field of TRUST* values from NSSCertDatabase. |
| 71 // Returns false if there is an internal error, otherwise true is returned and | 71 // Returns false if there is an internal error, otherwise true is returned and |
| 72 // |not_imported| should be checked for any certificates that were not | 72 // |not_imported| should be checked for any certificates that were not |
| 73 // imported. | 73 // imported. |
| 74 bool ImportCACerts(const net::CertificateList& certificates, | 74 bool ImportCACerts(const net::CertificateList& certificates, |
| 75 net::CertDatabase::TrustBits trust_bits, | 75 net::NSSCertDatabase::TrustBits trust_bits, |
| 76 net::CertDatabase::ImportCertFailureList* not_imported); | 76 net::NSSCertDatabase::ImportCertFailureList* not_imported); |
| 77 | 77 |
| 78 // Import server certificate. The first cert should be the server cert. Any | 78 // Import server certificate. The first cert should be the server cert. Any |
| 79 // additional certs should be intermediate/CA certs and will be imported but | 79 // additional certs should be intermediate/CA certs and will be imported but |
| 80 // not given any trust. | 80 // not given any trust. |
| 81 // Any certificates that could not be imported will be listed in | 81 // Any certificates that could not be imported will be listed in |
| 82 // |not_imported|. | 82 // |not_imported|. |
| 83 // |trust_bits| can be set to explicitly trust or distrust the certificate, or | 83 // |trust_bits| can be set to explicitly trust or distrust the certificate, or |
| 84 // use TRUST_DEFAULT to inherit trust as normal. | 84 // use TRUST_DEFAULT to inherit trust as normal. |
| 85 // Returns false if there is an internal error, otherwise true is returned and | 85 // Returns false if there is an internal error, otherwise true is returned and |
| 86 // |not_imported| should be checked for any certificates that were not | 86 // |not_imported| should be checked for any certificates that were not |
| 87 // imported. | 87 // imported. |
| 88 bool ImportServerCert( | 88 bool ImportServerCert( |
| 89 const net::CertificateList& certificates, | 89 const net::CertificateList& certificates, |
| 90 net::CertDatabase::TrustBits trust_bits, | 90 net::NSSCertDatabase::TrustBits trust_bits, |
| 91 net::CertDatabase::ImportCertFailureList* not_imported); | 91 net::NSSCertDatabase::ImportCertFailureList* not_imported); |
| 92 | 92 |
| 93 // Set trust values for certificate. | 93 // Set trust values for certificate. |
| 94 // |trust_bits| should be a bit field of TRUST* values from CertDatabase. | 94 // |trust_bits| should be a bit field of TRUST* values from NSSCertDatabase. |
| 95 // Returns true on success or false on failure. | 95 // Returns true on success or false on failure. |
| 96 bool SetCertTrust(const net::X509Certificate* cert, | 96 bool SetCertTrust(const net::X509Certificate* cert, |
| 97 net::CertType type, | 97 net::CertType type, |
| 98 net::CertDatabase::TrustBits trust_bits); | 98 net::NSSCertDatabase::TrustBits trust_bits); |
| 99 | 99 |
| 100 // Delete the cert. Returns true on success. |cert| is still valid when this | 100 // Delete the cert. Returns true on success. |cert| is still valid when this |
| 101 // function returns. | 101 // function returns. |
| 102 bool Delete(net::X509Certificate* cert); | 102 bool Delete(net::X509Certificate* cert); |
| 103 | 103 |
| 104 // IsHardwareBacked returns true if |cert| is hardware backed. | 104 // IsHardwareBacked returns true if |cert| is hardware backed. |
| 105 // This function is only implemented for Chrome OS and always returns false | 105 // This function is only implemented for Chrome OS and always returns false |
| 106 // for other platforms. | 106 // for other platforms. |
| 107 bool IsHardwareBacked(const net::X509Certificate* cert) const; | 107 bool IsHardwareBacked(const net::X509Certificate* cert) const; |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 // Callback used by Refresh() for when the cert slots have been unlocked. | 110 // Callback used by Refresh() for when the cert slots have been unlocked. |
| 111 // This method does the actual refreshing. | 111 // This method does the actual refreshing. |
| 112 void RefreshSlotsUnlocked(); | 112 void RefreshSlotsUnlocked(); |
| 113 | 113 |
| 114 net::CertDatabase cert_db_; | 114 net::NSSCertDatabase cert_db_; |
| 115 net::CertificateList cert_list_; | 115 net::CertificateList cert_list_; |
| 116 | 116 |
| 117 // The observer to notify when certificate list is refreshed. | 117 // The observer to notify when certificate list is refreshed. |
| 118 Observer* observer_; | 118 Observer* observer_; |
| 119 | 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(CertificateManagerModel); | 120 DISALLOW_COPY_AND_ASSIGN(CertificateManagerModel); |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 #endif // CHROME_BROWSER_CERTIFICATE_MANAGER_MODEL_H_ | 123 #endif // CHROME_BROWSER_CERTIFICATE_MANAGER_MODEL_H_ |
| OLD | NEW |