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

Side by Side Diff: net/third_party/mozilla_security_manager/nsNSSCertificateDB.cpp

Issue 8566056: This applies GUIDs to certificate and key nicknames when (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More review changes Created 9 years 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 /* ***** BEGIN LICENSE BLOCK ***** 1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 * 3 *
4 * The contents of this file are subject to the Mozilla Public License Version 4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with 5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at 6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/ 7 * http://www.mozilla.org/MPL/
8 * 8 *
9 * Software distributed under the License is distributed on an "AS IS" basis, 9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
(...skipping 29 matching lines...) Expand all
40 40
41 #include <cert.h> 41 #include <cert.h>
42 #include <pk11pub.h> 42 #include <pk11pub.h>
43 #include <secerr.h> 43 #include <secerr.h>
44 44
45 #include "base/logging.h" 45 #include "base/logging.h"
46 #include "crypto/nss_util_internal.h" 46 #include "crypto/nss_util_internal.h"
47 #include "crypto/scoped_nss_types.h" 47 #include "crypto/scoped_nss_types.h"
48 #include "net/base/net_errors.h" 48 #include "net/base/net_errors.h"
49 #include "net/base/x509_certificate.h" 49 #include "net/base/x509_certificate.h"
50 #include "net/base/x509_util_nss.h"
50 #include "net/third_party/mozilla_security_manager/nsNSSCertTrust.h" 51 #include "net/third_party/mozilla_security_manager/nsNSSCertTrust.h"
51 52
52 namespace mozilla_security_manager { 53 namespace mozilla_security_manager {
53 54
54 // Based on nsNSSCertificateDB::handleCACertDownload, minus the UI bits. 55 // Based on nsNSSCertificateDB::handleCACertDownload, minus the UI bits.
55 bool ImportCACerts(const net::CertificateList& certificates, 56 bool ImportCACerts(const net::CertificateList& certificates,
56 net::X509Certificate* root, 57 net::X509Certificate* root,
57 net::CertDatabase::TrustBits trustBits, 58 net::CertDatabase::TrustBits trustBits,
58 net::CertDatabase::ImportCertFailureList* not_imported) { 59 net::CertDatabase::ImportCertFailureList* not_imported) {
59 crypto::ScopedPK11Slot slot(crypto::GetPublicNSSKeySlot()); 60 crypto::ScopedPK11Slot slot(crypto::GetPublicNSSKeySlot());
(...skipping 13 matching lines...) Expand all
73 // Mozilla just returns here, but we continue in case there are other certs 74 // Mozilla just returns here, but we continue in case there are other certs
74 // in the list which aren't already imported. 75 // in the list which aren't already imported.
75 // TODO(mattm): should we set/add trust if it differs from the present 76 // TODO(mattm): should we set/add trust if it differs from the present
76 // settings? 77 // settings?
77 not_imported->push_back(net::CertDatabase::ImportCertFailure( 78 not_imported->push_back(net::CertDatabase::ImportCertFailure(
78 root, net::ERR_IMPORT_CERT_ALREADY_EXISTS)); 79 root, net::ERR_IMPORT_CERT_ALREADY_EXISTS));
79 } else { 80 } else {
80 // Mozilla uses CERT_AddTempCertToPerm, however it is privately exported, 81 // Mozilla uses CERT_AddTempCertToPerm, however it is privately exported,
81 // and it doesn't take the slot as an argument either. Instead, we use 82 // and it doesn't take the slot as an argument either. Instead, we use
82 // PK11_ImportCert and CERT_ChangeCertTrust. 83 // PK11_ImportCert and CERT_ChangeCertTrust.
83 char* nickname = CERT_MakeCANickname(root->os_cert_handle()); 84 SECStatus srv = PK11_ImportCert(
wtc 2011/12/08 00:07:43 Please add a CHECK (non-debug assertion) here to a
Greg Spencer (Chromium) 2011/12/09 18:51:38 Now that we're passing the certificate type instea
84 if (!nickname) 85 slot.get(),
85 return false; 86 root->os_cert_handle(),
86 SECStatus srv = PK11_ImportCert(slot.get(), root->os_cert_handle(), 87 CK_INVALID_HANDLE,
87 CK_INVALID_HANDLE, 88 net::x509_util::GetDefaultCertificateLabel(root).c_str(),
88 nickname, 89 PR_FALSE /* includeTrust (unused) */);
89 PR_FALSE /* includeTrust (unused) */);
90 PORT_Free(nickname);
91 if (srv != SECSuccess) { 90 if (srv != SECSuccess) {
92 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError(); 91 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError();
93 return false; 92 return false;
94 } 93 }
95 if (!SetCertTrust(root, net::CA_CERT, trustBits)) 94 if (!SetCertTrust(root, net::CA_CERT, trustBits))
96 return false; 95 return false;
97 } 96 }
98 97
99 PRTime now = PR_Now(); 98 PRTime now = PR_Now();
100 // Import additional delivered certificates that can be verified. 99 // Import additional delivered certificates that can be verified.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // error value). (maybe make MapSecurityError or MapCertErrorToCertStatus 131 // error value). (maybe make MapSecurityError or MapCertErrorToCertStatus
133 // public.) 132 // public.)
134 not_imported->push_back(net::CertDatabase::ImportCertFailure( 133 not_imported->push_back(net::CertDatabase::ImportCertFailure(
135 cert, net::ERR_FAILED)); 134 cert, net::ERR_FAILED));
136 VLOG(1) << "skipping cert (verify) " << PORT_GetError(); 135 VLOG(1) << "skipping cert (verify) " << PORT_GetError();
137 continue; 136 continue;
138 } 137 }
139 138
140 // Mozilla uses CERT_ImportCerts, which doesn't take a slot arg. We use 139 // Mozilla uses CERT_ImportCerts, which doesn't take a slot arg. We use
141 // PK11_ImportCert instead. 140 // PK11_ImportCert instead.
142 char* nickname = CERT_MakeCANickname(cert->os_cert_handle()); 141 SECStatus srv = PK11_ImportCert(
wtc 2011/12/08 00:07:43 Please add a CHECK (non-debug assertion) here to a
Greg Spencer (Chromium) 2011/12/09 18:51:38 Now that we pass the certificate type, this is not
143 if (!nickname) 142 slot.get(),
144 return false; 143 cert->os_cert_handle(),
145 SECStatus srv = PK11_ImportCert(slot.get(), cert->os_cert_handle(), 144 CK_INVALID_HANDLE,
146 CK_INVALID_HANDLE, 145 net::x509_util::GetDefaultCertificateLabel(cert).c_str(),
147 nickname, 146 PR_FALSE /* includeTrust (unused) */);
148 PR_FALSE /* includeTrust (unused) */);
149 PORT_Free(nickname);
150 if (srv != SECSuccess) { 147 if (srv != SECSuccess) {
151 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError(); 148 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError();
152 // TODO(mattm): Should we bail or continue on error here? Mozilla doesn't 149 // TODO(mattm): Should we bail or continue on error here? Mozilla doesn't
153 // check error code at all. 150 // check error code at all.
154 not_imported->push_back(net::CertDatabase::ImportCertFailure( 151 not_imported->push_back(net::CertDatabase::ImportCertFailure(
155 cert, net::ERR_IMPORT_CA_CERT_FAILED)); 152 cert, net::ERR_IMPORT_CA_CERT_FAILED));
156 } 153 }
157 } 154 }
158 155
159 // Any errors importing individual certs will be in listed in |not_imported|. 156 // Any errors importing individual certs will be in listed in |not_imported|.
160 return true; 157 return true;
161 } 158 }
162 159
163 // Based on nsNSSCertificateDB::ImportServerCertificate. 160 // Based on nsNSSCertificateDB::ImportServerCertificate.
164 bool ImportServerCert(const net::CertificateList& certificates, 161 bool ImportServerCert(const net::CertificateList& certificates,
165 net::CertDatabase::ImportCertFailureList* not_imported) { 162 net::CertDatabase::ImportCertFailureList* not_imported) {
166 crypto::ScopedPK11Slot slot(crypto::GetPublicNSSKeySlot()); 163 crypto::ScopedPK11Slot slot(crypto::GetPublicNSSKeySlot());
167 if (!slot.get()) { 164 if (!slot.get()) {
168 LOG(ERROR) << "Couldn't get internal key slot!"; 165 LOG(ERROR) << "Couldn't get internal key slot!";
169 return false; 166 return false;
170 } 167 }
171 168
172 for (size_t i = 0; i < certificates.size(); ++i) { 169 for (size_t i = 0; i < certificates.size(); ++i) {
173 const scoped_refptr<net::X509Certificate>& cert = certificates[i]; 170 const scoped_refptr<net::X509Certificate>& cert = certificates[i];
174 171
175 // Mozilla uses CERT_ImportCerts, which doesn't take a slot arg. We use 172 // Mozilla uses CERT_ImportCerts, which doesn't take a slot arg. We use
176 // PK11_ImportCert instead. 173 // PK11_ImportCert instead.
177 SECStatus srv = PK11_ImportCert(slot.get(), cert->os_cert_handle(), 174 SECStatus srv = PK11_ImportCert(
wtc 2011/12/08 00:07:43 Please add a CHECK (non-debug assertion) here to a
Greg Spencer (Chromium) 2011/12/09 18:51:38 Now that we pass the certificate type, this is not
178 CK_INVALID_HANDLE, 175 slot.get(),
179 cert->subject().GetDisplayName().c_str(), 176 cert->os_cert_handle(),
180 PR_FALSE /* includeTrust (unused) */); 177 CK_INVALID_HANDLE,
178 net::x509_util::GetDefaultCertificateLabel(cert).c_str(),
179 PR_FALSE /* includeTrust (unused) */);
181 if (srv != SECSuccess) { 180 if (srv != SECSuccess) {
182 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError(); 181 LOG(ERROR) << "PK11_ImportCert failed with error " << PORT_GetError();
183 not_imported->push_back(net::CertDatabase::ImportCertFailure( 182 not_imported->push_back(net::CertDatabase::ImportCertFailure(
184 cert, net::ERR_IMPORT_SERVER_CERT_FAILED)); 183 cert, net::ERR_IMPORT_SERVER_CERT_FAILED));
185 continue; 184 continue;
186 } 185 }
187 } 186 }
188 187
189 // Set as valid peer, but without any extra trust. 188 // Set as valid peer, but without any extra trust.
190 SetCertTrust(certificates[0].get(), net::SERVER_CERT, 189 SetCertTrust(certificates[0].get(), net::SERVER_CERT,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } else { 223 } else {
225 // ignore user and email/unknown certs 224 // ignore user and email/unknown certs
226 return true; 225 return true;
227 } 226 }
228 if (srv != SECSuccess) 227 if (srv != SECSuccess)
229 LOG(ERROR) << "SetCertTrust failed with error " << PORT_GetError(); 228 LOG(ERROR) << "SetCertTrust failed with error " << PORT_GetError();
230 return srv == SECSuccess; 229 return srv == SECSuccess;
231 } 230 }
232 231
233 } // namespace mozilla_security_manager 232 } // namespace mozilla_security_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698