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

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

Issue 3565006: Decouples certificates viewers from NSS to prepare support for OpenSSL. (Closed)
Patch Set: Comments / ProcessIDN Created 10 years, 2 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
« no previous file with comments | « build/common.gypi ('k') | chrome/browser/gtk/certificate_dialogs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <cert.h>
8
9 #include "base/i18n/time_formatting.h" 7 #include "base/i18n/time_formatting.h"
10 #include "base/logging.h" 8 #include "base/logging.h"
11 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
12 #include "chrome/third_party/mozilla_security_manager/nsNSSCertHelper.h" 10 #include "chrome/common/net/x509_certificate_model.h"
13 #include "chrome/third_party/mozilla_security_manager/nsNSSCertificate.h"
14 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
15 #include "net/base/x509_certificate.h" 12 #include "net/base/x509_certificate.h"
16 13
17 // TODO(mattm): Try to make this use only X509Certificate stuff rather than NSS
18 // functions in some places. (Not very important at this time since this is only
19 // used w/NSS anyway.)
20
21 // PSM = Mozilla's Personal Security Manager.
22 namespace psm = mozilla_security_manager;
23
24 namespace {
25
26 // Convert a char* return value from NSS into a std::string and free the NSS
27 // memory. If the arg is NULL, an empty string will be returned instead.
28 std::string Stringize(char* nss_text) {
29 std::string s;
30 if (nss_text) {
31 s = nss_text;
32 PORT_Free(nss_text);
33 }
34 return s;
35 }
36
37 std::string GetCertNameOrNickname(CERTCertificate* os_cert) {
38 std::string name = psm::ProcessIDN(
39 Stringize(CERT_GetCommonName(&os_cert->subject)));
40 if (name.empty() && os_cert->nickname) {
41 name = os_cert->nickname;
42 // Hack copied from mozilla: Cut off text before first :, which seems to
43 // just be the token name.
44 size_t colon_pos = name.find(':');
45 if (colon_pos != std::string::npos)
46 name = name.substr(colon_pos + 1);
47 }
48 return name;
49 }
50
51 } // namespace
52
53 CertificateManagerModel::CertificateManagerModel(Observer* observer) 14 CertificateManagerModel::CertificateManagerModel(Observer* observer)
54 : observer_(observer) { 15 : observer_(observer) {
55 } 16 }
56 17
57 CertificateManagerModel::~CertificateManagerModel() { 18 CertificateManagerModel::~CertificateManagerModel() {
58 } 19 }
59 20
60 void CertificateManagerModel::Refresh() { 21 void CertificateManagerModel::Refresh() {
61 VLOG(1) << "refresh started"; 22 VLOG(1) << "refresh started";
62 cert_db_.ListCerts(&cert_list_); 23 cert_db_.ListCerts(&cert_list_);
63 observer_->CertificatesRefreshed(); 24 observer_->CertificatesRefreshed();
64 VLOG(1) << "refresh finished"; 25 VLOG(1) << "refresh finished";
65 } 26 }
66 27
67 void CertificateManagerModel::FilterAndBuildOrgGroupingMap( 28 void CertificateManagerModel::FilterAndBuildOrgGroupingMap(
68 net::CertType filter_type, 29 net::CertType filter_type,
69 CertificateManagerModel::OrgGroupingMap* map) const { 30 CertificateManagerModel::OrgGroupingMap* map) const {
70 for (net::CertificateList::const_iterator i = cert_list_.begin(); 31 for (net::CertificateList::const_iterator i = cert_list_.begin();
71 i != cert_list_.end(); ++i) { 32 i != cert_list_.end(); ++i) {
72 net::X509Certificate* cert = i->get(); 33 net::X509Certificate* cert = i->get();
73 net::CertType type = psm::GetCertType(cert->os_cert_handle()); 34 net::CertType type =
35 x509_certificate_model::GetType(cert->os_cert_handle());
74 if (type != filter_type) 36 if (type != filter_type)
75 continue; 37 continue;
76 38
77 std::string org; 39 std::string org;
78 if (!cert->subject().organization_names.empty()) 40 if (!cert->subject().organization_names.empty())
79 org = cert->subject().organization_names[0]; 41 org = cert->subject().organization_names[0];
80 if (org.empty()) 42 if (org.empty())
81 org = cert->subject().GetDisplayName(); 43 org = cert->subject().GetDisplayName();
82 44
83 (*map)[org].push_back(cert); 45 (*map)[org].push_back(cert);
84 } 46 }
85 } 47 }
86 48
87 string16 CertificateManagerModel::GetColumnText( 49 string16 CertificateManagerModel::GetColumnText(
88 const net::X509Certificate& cert, 50 const net::X509Certificate& cert,
89 Column column) const { 51 Column column) const {
90 string16 rv; 52 string16 rv;
91 switch (column) { 53 switch (column) {
92 case COL_SUBJECT_NAME: 54 case COL_SUBJECT_NAME:
93 rv = UTF8ToUTF16(GetCertNameOrNickname(cert.os_cert_handle())); 55 rv = UTF8ToUTF16(
56 x509_certificate_model::GetCertNameOrNickname(cert.os_cert_handle()));
94 break; 57 break;
95 case COL_CERTIFICATE_STORE: 58 case COL_CERTIFICATE_STORE:
96 rv = UTF8ToUTF16(psm::GetCertTokenName(cert.os_cert_handle())); 59 rv = UTF8ToUTF16(
60 x509_certificate_model::GetTokenName(cert.os_cert_handle()));
97 break; 61 break;
98 case COL_SERIAL_NUMBER: 62 case COL_SERIAL_NUMBER:
99 rv = ASCIIToUTF16(Stringize(CERT_Hexify( 63 rv = ASCIIToUTF16(
100 &cert.os_cert_handle()->serialNumber, PR_TRUE))); 64 x509_certificate_model::GetSerialNumberHexified(
65 cert.os_cert_handle(), ""));
101 break; 66 break;
102 case COL_EXPIRES_ON: 67 case COL_EXPIRES_ON:
103 if (!cert.valid_expiry().is_null()) { 68 if (!cert.valid_expiry().is_null()) {
104 rv = WideToUTF16Hack( 69 rv = WideToUTF16Hack(
105 base::TimeFormatShortDateNumeric(cert.valid_expiry())); 70 base::TimeFormatShortDateNumeric(cert.valid_expiry()));
106 } 71 }
107 break; 72 break;
108 case COL_EMAIL_ADDRESS: 73 case COL_EMAIL_ADDRESS:
109 if (cert.os_cert_handle()->emailAddr) 74 rv = UTF8ToUTF16(
110 rv = UTF8ToUTF16(cert.os_cert_handle()->emailAddr); 75 x509_certificate_model::GetEmailAddress(cert.os_cert_handle()));
111 break; 76 break;
112 default: 77 default:
113 NOTREACHED(); 78 NOTREACHED();
114 } 79 }
115 return rv; 80 return rv;
116 } 81 }
117 82
118 int CertificateManagerModel::ImportFromPKCS12(const std::string& data, 83 int CertificateManagerModel::ImportFromPKCS12(const std::string& data,
119 const string16& password) { 84 const string16& password) {
120 int result = cert_db_.ImportFromPKCS12(data, password); 85 int result = cert_db_.ImportFromPKCS12(data, password);
(...skipping 18 matching lines...) Expand all
139 unsigned int trust_bits) { 104 unsigned int trust_bits) {
140 return cert_db_.SetCertTrust(cert, type, trust_bits); 105 return cert_db_.SetCertTrust(cert, type, trust_bits);
141 } 106 }
142 107
143 bool CertificateManagerModel::Delete(net::X509Certificate* cert) { 108 bool CertificateManagerModel::Delete(net::X509Certificate* cert) {
144 bool result = cert_db_.DeleteCertAndKey(cert); 109 bool result = cert_db_.DeleteCertAndKey(cert);
145 if (result) 110 if (result)
146 Refresh(); 111 Refresh();
147 return result; 112 return result;
148 } 113 }
OLDNEW
« no previous file with comments | « build/common.gypi ('k') | chrome/browser/gtk/certificate_dialogs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698