blob: b111aa28336f11296410d05d01919e3dedbfac1f [file] [log] [blame]
[email protected]e0ad0892012-05-22 19:16:591// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]df8e899b2011-02-22 22:58:222// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]4f242962011-05-13 22:25:225#ifndef CHROME_BROWSER_CERTIFICATE_MANAGER_MODEL_H_
6#define CHROME_BROWSER_CERTIFICATE_MANAGER_MODEL_H_
[email protected]df8e899b2011-02-22 22:58:227
8#include <map>
9#include <string>
10
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/ref_counted.h"
[email protected]df8e899b2011-02-22 22:58:2212#include "base/string16.h"
13#include "net/base/cert_database.h"
14
15// CertificateManagerModel provides the data to be displayed in the certificate
16// manager dialog, and processes changes from the view.
17class CertificateManagerModel {
18 public:
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
21 // subject's CertPrincipal::GetDisplayName() value is used instead.
22 typedef std::map<std::string, net::CertificateList> OrgGroupingMap;
23
24 // Enumeration of the possible columns in the certificate manager tree view.
25 enum Column {
26 COL_SUBJECT_NAME,
27 COL_CERTIFICATE_STORE,
28 COL_SERIAL_NUMBER,
29 COL_EXPIRES_ON,
30 };
31
32 class Observer {
33 public:
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
36 // list of certs, diff against past list, and then notify of the changes?
37 virtual void CertificatesRefreshed() = 0;
38 };
39
40 explicit CertificateManagerModel(Observer* observer);
41 ~CertificateManagerModel();
42
43 // Accessor for read-only access to the underlying CertDatabase.
44 const net::CertDatabase& cert_db() const { return cert_db_; }
45
[email protected]4c4f7cd2011-03-05 02:20:4446 // Trigger a refresh of the list of certs, unlock any slots if necessary.
47 // Following this call, the observer CertificatesRefreshed method will be
48 // called so the view can call FilterAndBuildOrgGroupingMap as necessary to
49 // refresh its tree views.
[email protected]df8e899b2011-02-22 22:58:2250 void Refresh();
51
52 // Fill |map| with the certificates matching |filter_type|.
53 void FilterAndBuildOrgGroupingMap(net::CertType filter_type,
54 OrgGroupingMap* map) const;
55
56 // Get the data to be displayed in |column| for the given |cert|.
57 string16 GetColumnText(const net::X509Certificate& cert, Column column) const;
58
[email protected]6a18d072011-06-29 00:25:4059 // Import private keys and certificates from PKCS #12 encoded
60 // |data|, using the given |password|. If |is_extractable| is false,
61 // mark the private key as unextractable from the module.
62 // Returns a net error code on failure.
[email protected]df8e899b2011-02-22 22:58:2263 int ImportFromPKCS12(net::CryptoModule* module, const std::string& data,
[email protected]6a18d072011-06-29 00:25:4064 const string16& password, bool is_extractable);
[email protected]df8e899b2011-02-22 22:58:2265
66 // Import CA certificates.
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
69 // will be listed in |not_imported|.
[email protected]ad40b212012-06-01 05:59:5670 // |trust_bits| should be a bit field of TRUST* values from CertDatabase.
[email protected]df8e899b2011-02-22 22:58:2271 // 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
73 // imported.
74 bool ImportCACerts(const net::CertificateList& certificates,
[email protected]c79b784d12011-09-20 18:44:5475 net::CertDatabase::TrustBits trust_bits,
[email protected]df8e899b2011-02-22 22:58:2276 net::CertDatabase::ImportCertFailureList* not_imported);
77
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
80 // not given any trust.
81 // Any certificates that could not be imported will be listed in
82 // |not_imported|.
[email protected]ad40b212012-06-01 05:59:5683 // |trust_bits| can be set to explicitly trust or distrust the certificate, or
84 // use TRUST_DEFAULT to inherit trust as normal.
[email protected]df8e899b2011-02-22 22:58:2285 // 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
87 // imported.
88 bool ImportServerCert(
89 const net::CertificateList& certificates,
[email protected]ad40b212012-06-01 05:59:5690 net::CertDatabase::TrustBits trust_bits,
[email protected]df8e899b2011-02-22 22:58:2291 net::CertDatabase::ImportCertFailureList* not_imported);
92
93 // Set trust values for certificate.
[email protected]ad40b212012-06-01 05:59:5694 // |trust_bits| should be a bit field of TRUST* values from CertDatabase.
[email protected]df8e899b2011-02-22 22:58:2295 // Returns true on success or false on failure.
96 bool SetCertTrust(const net::X509Certificate* cert,
97 net::CertType type,
[email protected]c79b784d12011-09-20 18:44:5498 net::CertDatabase::TrustBits trust_bits);
[email protected]df8e899b2011-02-22 22:58:2299
100 // Delete the cert. Returns true on success. |cert| is still valid when this
101 // function returns.
102 bool Delete(net::X509Certificate* cert);
103
[email protected]e0ad0892012-05-22 19:16:59104 // IsHardwareBacked returns true if |cert| is hardware backed.
[email protected]e0c99f92012-05-23 20:44:55105 // This function is only implemented for Chrome OS and always returns false
106 // for other platforms.
[email protected]e0ad0892012-05-22 19:16:59107 bool IsHardwareBacked(const net::X509Certificate* cert) const;
108
[email protected]df8e899b2011-02-22 22:58:22109 private:
[email protected]4c4f7cd2011-03-05 02:20:44110 // Callback used by Refresh() for when the cert slots have been unlocked.
111 // This method does the actual refreshing.
112 void RefreshSlotsUnlocked();
113
[email protected]df8e899b2011-02-22 22:58:22114 net::CertDatabase cert_db_;
115 net::CertificateList cert_list_;
116
117 // The observer to notify when certificate list is refreshed.
118 Observer* observer_;
119
120 DISALLOW_COPY_AND_ASSIGN(CertificateManagerModel);
121};
122
[email protected]4f242962011-05-13 22:25:22123#endif // CHROME_BROWSER_CERTIFICATE_MANAGER_MODEL_H_