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

Side by Side Diff: net/base/x509_certificate_nss.cc

Issue 9271060: Check cert->isRoot to skip extraneous root certificates in certificate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Implement rsleevi's suggestion Created 8 years, 11 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
« no previous file with comments | « no previous file | no next file » | 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) 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 "net/base/x509_certificate.h" 5 #include "net/base/x509_certificate.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 #include <cryptohi.h> 8 #include <cryptohi.h>
9 #include <keyhi.h> 9 #include <keyhi.h>
10 #include <nss.h> 10 #include <nss.h>
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 185
186 CERTCertificate* verified_cert = NULL; 186 CERTCertificate* verified_cert = NULL;
187 std::vector<CERTCertificate*> verified_chain; 187 std::vector<CERTCertificate*> verified_chain;
188 int i = 0; 188 int i = 0;
189 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); 189 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list);
190 !CERT_LIST_END(node, cert_list); 190 !CERT_LIST_END(node, cert_list);
191 node = CERT_LIST_NEXT(node), ++i) { 191 node = CERT_LIST_NEXT(node), ++i) {
192 if (i == 0) { 192 if (i == 0) {
193 verified_cert = node->cert; 193 verified_cert = node->cert;
194 } else { 194 } else {
195 // Because of an NSS bug, CERT_PKIXVerifyCert may chain a self-signed
196 // certificate of a root CA to another certificate of the same root CA
197 // key. Detect that error and ignore the root CA certificate.
198 // See https://bugzilla.mozilla.org/show_bug.cgi?id=721288.
199 if (node->cert->isRoot) {
Ryan Sleevi 2012/01/27 02:59:21 Might be worth adding a comment here that isRoot o
200 CERTCertListNode* next_node = CERT_LIST_NEXT(node);
201 CERTCertificate* next_cert;
202 if (!CERT_LIST_END(next_node, cert_list)) {
203 next_cert = next_node->cert;
204 } else {
205 next_cert = root_cert;
206 }
207 // This SECITEM_ItemsAreEqual test should be unnecessary, implied
208 // by node->cert->isRoot and the fact that NSS has verified the
209 // signature of node->cert with the public key of next_cert. But I
210 // added the test to make it easier to prove the code is correct.
Ryan Sleevi 2012/01/27 02:59:21 nit: Drop the last sentence? Would it be worth ex
211 if (next_cert && SECITEM_ItemsAreEqual(&node->cert->derPublicKey,
212 &next_cert->derPublicKey)) {
213 continue;
214 }
215 }
195 verified_chain.push_back(node->cert); 216 verified_chain.push_back(node->cert);
196 } 217 }
218
197 SECAlgorithmID& signature = node->cert->signature; 219 SECAlgorithmID& signature = node->cert->signature;
198 SECOidTag oid_tag = SECOID_FindOIDTag(&signature.algorithm); 220 SECOidTag oid_tag = SECOID_FindOIDTag(&signature.algorithm);
199 switch (oid_tag) { 221 switch (oid_tag) {
200 case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION: 222 case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION:
201 verify_result->has_md5 = true; 223 verify_result->has_md5 = true;
202 if (i != 0) 224 if (i != 0)
203 verify_result->has_md5_ca = true; 225 verify_result->has_md5_ca = true;
204 break; 226 break;
205 case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION: 227 case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION:
206 verify_result->has_md2 = true; 228 verify_result->has_md2 = true;
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 *type = kPublicKeyTypeECDSA; 1191 *type = kPublicKeyTypeECDSA;
1170 break; 1192 break;
1171 default: 1193 default:
1172 *type = kPublicKeyTypeUnknown; 1194 *type = kPublicKeyTypeUnknown;
1173 *size_bits = 0; 1195 *size_bits = 0;
1174 break; 1196 break;
1175 } 1197 }
1176 } 1198 }
1177 1199
1178 } // namespace net 1200 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698