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 // | |
200 // NOTE: isRoot doesn't mean the certificate is a trust anchor. It | |
201 // means the certificate is self-signed. | |
Ryan Sleevi
2012/01/27 21:45:37
nit: self-issued?
This is to match comments in li
wtc
2012/01/27 22:58:13
isRoot means self-signed as defined in PKIX (RFC 5
| |
202 if (node->cert->isRoot) { | |
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 // | |
214 // This SECITEM_ItemsAreEqual test should be unnecessary, implied | |
215 // by node->cert->isRoot and the fact that NSS has verified the | |
216 // signature of node->cert with the public key of next_cert. | |
217 if (next_cert && SECITEM_ItemsAreEqual(&node->cert->derPublicKey, | |
Ryan Sleevi
2012/01/27 21:45:37
This isn't for checking the signature of node->cer
| |
218 &next_cert->derPublicKey)) { | |
219 continue; | |
220 } | |
221 } | |
195 verified_chain.push_back(node->cert); | 222 verified_chain.push_back(node->cert); |
196 } | 223 } |
224 | |
197 SECAlgorithmID& signature = node->cert->signature; | 225 SECAlgorithmID& signature = node->cert->signature; |
198 SECOidTag oid_tag = SECOID_FindOIDTag(&signature.algorithm); | 226 SECOidTag oid_tag = SECOID_FindOIDTag(&signature.algorithm); |
199 switch (oid_tag) { | 227 switch (oid_tag) { |
200 case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION: | 228 case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION: |
201 verify_result->has_md5 = true; | 229 verify_result->has_md5 = true; |
202 if (i != 0) | 230 if (i != 0) |
203 verify_result->has_md5_ca = true; | 231 verify_result->has_md5_ca = true; |
204 break; | 232 break; |
205 case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION: | 233 case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION: |
206 verify_result->has_md2 = true; | 234 verify_result->has_md2 = true; |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1169 *type = kPublicKeyTypeECDSA; | 1197 *type = kPublicKeyTypeECDSA; |
1170 break; | 1198 break; |
1171 default: | 1199 default: |
1172 *type = kPublicKeyTypeUnknown; | 1200 *type = kPublicKeyTypeUnknown; |
1173 *size_bits = 0; | 1201 *size_bits = 0; |
1174 break; | 1202 break; |
1175 } | 1203 } |
1176 } | 1204 } |
1177 | 1205 |
1178 } // namespace net | 1206 } // namespace net |
OLD | NEW |