OLD | NEW |
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 Loading... |
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) { |
| 200 // NOTE: isRoot doesn't mean the certificate is a trust anchor. It |
| 201 // means the certificate is self-signed. Here we assume isRoot only |
| 202 // implies the certificate is self-issued. |
| 203 CERTCertListNode* next_node = CERT_LIST_NEXT(node); |
| 204 CERTCertificate* next_cert; |
| 205 if (!CERT_LIST_END(next_node, cert_list)) { |
| 206 next_cert = next_node->cert; |
| 207 } else { |
| 208 next_cert = root_cert; |
| 209 } |
| 210 // Test that |node->cert| is actually a self-signed certificate |
| 211 // whose key is equal to |next_cert|, and not a self-issued |
| 212 // certificate signed by another key of the same CA. |
| 213 if (next_cert && SECITEM_ItemsAreEqual(&node->cert->derPublicKey, |
| 214 &next_cert->derPublicKey)) { |
| 215 continue; |
| 216 } |
| 217 } |
195 verified_chain.push_back(node->cert); | 218 verified_chain.push_back(node->cert); |
196 } | 219 } |
| 220 |
197 SECAlgorithmID& signature = node->cert->signature; | 221 SECAlgorithmID& signature = node->cert->signature; |
198 SECOidTag oid_tag = SECOID_FindOIDTag(&signature.algorithm); | 222 SECOidTag oid_tag = SECOID_FindOIDTag(&signature.algorithm); |
199 switch (oid_tag) { | 223 switch (oid_tag) { |
200 case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION: | 224 case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION: |
201 verify_result->has_md5 = true; | 225 verify_result->has_md5 = true; |
202 if (i != 0) | 226 if (i != 0) |
203 verify_result->has_md5_ca = true; | 227 verify_result->has_md5_ca = true; |
204 break; | 228 break; |
205 case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION: | 229 case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION: |
206 verify_result->has_md2 = true; | 230 verify_result->has_md2 = true; |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 *type = kPublicKeyTypeECDSA; | 1193 *type = kPublicKeyTypeECDSA; |
1170 break; | 1194 break; |
1171 default: | 1195 default: |
1172 *type = kPublicKeyTypeUnknown; | 1196 *type = kPublicKeyTypeUnknown; |
1173 *size_bits = 0; | 1197 *size_bits = 0; |
1174 break; | 1198 break; |
1175 } | 1199 } |
1176 } | 1200 } |
1177 | 1201 |
1178 } // namespace net | 1202 } // namespace net |
OLD | NEW |