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

Side by Side Diff: chrome/browser/certificate_manager_model.cc

Issue 10916094: Move the NSS functions out of CertDatabase into a new NSSCertDatabase class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 3 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) 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 #include "chrome/browser/certificate_manager_model.h" 5 #include "chrome/browser/certificate_manager_model.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/i18n/time_formatting.h" 8 #include "base/i18n/time_formatting.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/ui/crypto_module_password_dialog.h" 11 #include "chrome/browser/ui/crypto_module_password_dialog.h"
12 #include "chrome/common/net/x509_certificate_model.h" 12 #include "chrome/common/net/x509_certificate_model.h"
13 #include "net/base/crypto_module.h" 13 #include "net/base/crypto_module.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/base/x509_certificate.h" 15 #include "net/base/x509_certificate.h"
16 16
17 #if defined(OS_CHROMEOS) 17 #if defined(OS_CHROMEOS)
18 #include <cert.h> 18 #include <cert.h>
19 19
20 #include "crypto/nss_util.h" 20 #include "crypto/nss_util.h"
21 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 #endif 23 #endif
24 24
25 CertificateManagerModel::CertificateManagerModel(Observer* observer) 25 CertificateManagerModel::CertificateManagerModel(Observer* observer)
26 : observer_(observer) { 26 : cert_db_(net::NSSCertDatabase::GetInstance()),
27 observer_(observer) {
27 } 28 }
28 29
29 CertificateManagerModel::~CertificateManagerModel() { 30 CertificateManagerModel::~CertificateManagerModel() {
30 } 31 }
31 32
32 void CertificateManagerModel::Refresh() { 33 void CertificateManagerModel::Refresh() {
33 VLOG(1) << "refresh started"; 34 VLOG(1) << "refresh started";
34 net::CryptoModuleList modules; 35 net::CryptoModuleList modules;
35 cert_db_.ListModules(&modules, false); 36 cert_db_->ListModules(&modules, false);
36 VLOG(1) << "refresh waiting for unlocking..."; 37 VLOG(1) << "refresh waiting for unlocking...";
37 browser::UnlockSlotsIfNecessary( 38 browser::UnlockSlotsIfNecessary(
38 modules, 39 modules,
39 browser::kCryptoModulePasswordListCerts, 40 browser::kCryptoModulePasswordListCerts,
40 "", // unused. 41 "", // unused.
41 base::Bind(&CertificateManagerModel::RefreshSlotsUnlocked, 42 base::Bind(&CertificateManagerModel::RefreshSlotsUnlocked,
42 base::Unretained(this))); 43 base::Unretained(this)));
43 } 44 }
44 45
45 void CertificateManagerModel::RefreshSlotsUnlocked() { 46 void CertificateManagerModel::RefreshSlotsUnlocked() {
46 VLOG(1) << "refresh listing certs..."; 47 VLOG(1) << "refresh listing certs...";
47 cert_db_.ListCerts(&cert_list_); 48 cert_db_->ListCerts(&cert_list_);
48 observer_->CertificatesRefreshed(); 49 observer_->CertificatesRefreshed();
49 VLOG(1) << "refresh finished"; 50 VLOG(1) << "refresh finished";
50 } 51 }
51 52
52 void CertificateManagerModel::FilterAndBuildOrgGroupingMap( 53 void CertificateManagerModel::FilterAndBuildOrgGroupingMap(
53 net::CertType filter_type, 54 net::CertType filter_type,
54 CertificateManagerModel::OrgGroupingMap* map) const { 55 CertificateManagerModel::OrgGroupingMap* map) const {
55 for (net::CertificateList::const_iterator i = cert_list_.begin(); 56 for (net::CertificateList::const_iterator i = cert_list_.begin();
56 i != cert_list_.end(); ++i) { 57 i != cert_list_.end(); ++i) {
57 net::X509Certificate* cert = i->get(); 58 net::X509Certificate* cert = i->get();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 default: 106 default:
106 NOTREACHED(); 107 NOTREACHED();
107 } 108 }
108 return rv; 109 return rv;
109 } 110 }
110 111
111 int CertificateManagerModel::ImportFromPKCS12(net::CryptoModule* module, 112 int CertificateManagerModel::ImportFromPKCS12(net::CryptoModule* module,
112 const std::string& data, 113 const std::string& data,
113 const string16& password, 114 const string16& password,
114 bool is_extractable) { 115 bool is_extractable) {
115 int result = cert_db_.ImportFromPKCS12(module, data, password, 116 int result = cert_db_->ImportFromPKCS12(module, data, password,
116 is_extractable, NULL); 117 is_extractable, NULL);
117 if (result == net::OK) 118 if (result == net::OK)
118 Refresh(); 119 Refresh();
119 return result; 120 return result;
120 } 121 }
121 122
122 bool CertificateManagerModel::ImportCACerts( 123 bool CertificateManagerModel::ImportCACerts(
123 const net::CertificateList& certificates, 124 const net::CertificateList& certificates,
124 net::CertDatabase::TrustBits trust_bits, 125 net::NSSCertDatabase::TrustBits trust_bits,
125 net::CertDatabase::ImportCertFailureList* not_imported) { 126 net::NSSCertDatabase::ImportCertFailureList* not_imported) {
126 bool result = cert_db_.ImportCACerts(certificates, trust_bits, not_imported); 127 bool result = cert_db_->ImportCACerts(certificates, trust_bits, not_imported);
127 if (result && not_imported->size() != certificates.size()) 128 if (result && not_imported->size() != certificates.size())
128 Refresh(); 129 Refresh();
129 return result; 130 return result;
130 } 131 }
131 132
132 bool CertificateManagerModel::ImportServerCert( 133 bool CertificateManagerModel::ImportServerCert(
133 const net::CertificateList& certificates, 134 const net::CertificateList& certificates,
134 net::CertDatabase::TrustBits trust_bits, 135 net::NSSCertDatabase::TrustBits trust_bits,
135 net::CertDatabase::ImportCertFailureList* not_imported) { 136 net::NSSCertDatabase::ImportCertFailureList* not_imported) {
136 bool result = cert_db_.ImportServerCert(certificates, trust_bits, 137 bool result = cert_db_->ImportServerCert(certificates, trust_bits,
137 not_imported); 138 not_imported);
138 if (result && not_imported->size() != certificates.size()) 139 if (result && not_imported->size() != certificates.size())
139 Refresh(); 140 Refresh();
140 return result; 141 return result;
141 } 142 }
142 143
143 bool CertificateManagerModel::SetCertTrust( 144 bool CertificateManagerModel::SetCertTrust(
144 const net::X509Certificate* cert, 145 const net::X509Certificate* cert,
145 net::CertType type, 146 net::CertType type,
146 net::CertDatabase::TrustBits trust_bits) { 147 net::NSSCertDatabase::TrustBits trust_bits) {
147 return cert_db_.SetCertTrust(cert, type, trust_bits); 148 return cert_db_->SetCertTrust(cert, type, trust_bits);
148 } 149 }
149 150
150 bool CertificateManagerModel::Delete(net::X509Certificate* cert) { 151 bool CertificateManagerModel::Delete(net::X509Certificate* cert) {
151 bool result = cert_db_.DeleteCertAndKey(cert); 152 bool result = cert_db_->DeleteCertAndKey(cert);
152 if (result) 153 if (result)
153 Refresh(); 154 Refresh();
154 return result; 155 return result;
155 } 156 }
156 157
157 bool CertificateManagerModel::IsHardwareBacked( 158 bool CertificateManagerModel::IsHardwareBacked(
158 const net::X509Certificate* cert) const { 159 const net::X509Certificate* cert) const {
159 #if defined(OS_CHROMEOS) 160 #if defined(OS_CHROMEOS)
160 return crypto::IsTPMTokenReady() && 161 return crypto::IsTPMTokenReady() &&
161 cert->os_cert_handle()->slot == 162 cert->os_cert_handle()->slot ==
162 cert_db().GetPrivateModule()->os_module_handle(); 163 cert_db_->GetPrivateModule()->os_module_handle();
163 #else 164 #else
164 return false; 165 return false;
165 #endif 166 #endif
166 } 167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698