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/cert/cert_verify_proc_mac.h" | 5 #include "net/cert/cert_verify_proc_mac.h" |
6 | 6 |
7 #include <CommonCrypto/CommonDigest.h> | 7 #include <CommonCrypto/CommonDigest.h> |
8 #include <CoreServices/CoreServices.h> | 8 #include <CoreServices/CoreServices.h> |
9 #include <Security/Security.h> | 9 #include <Security/Security.h> |
10 | 10 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 if ((chain_info[i].StatusBits & CSSM_CERT_STATUS_IS_IN_ANCHORS) || | 208 if ((chain_info[i].StatusBits & CSSM_CERT_STATUS_IS_IN_ANCHORS) || |
209 (chain_info[i].StatusBits & CSSM_CERT_STATUS_IS_ROOT)) { | 209 (chain_info[i].StatusBits & CSSM_CERT_STATUS_IS_ROOT)) { |
210 // The current certificate is either in the user's trusted store or is | 210 // The current certificate is either in the user's trusted store or is |
211 // a root (self-signed) certificate. Ignore the signature algorithm for | 211 // a root (self-signed) certificate. Ignore the signature algorithm for |
212 // these certificates, as it is meaningless for security. We allow | 212 // these certificates, as it is meaningless for security. We allow |
213 // self-signed certificates (i == 0 & IS_ROOT), since we accept that | 213 // self-signed certificates (i == 0 & IS_ROOT), since we accept that |
214 // any security assertions by such a cert are inherently meaningless. | 214 // any security assertions by such a cert are inherently meaningless. |
215 continue; | 215 continue; |
216 } | 216 } |
217 | 217 |
218 x509_util::CSSMCachedCertificate cached_cert; | 218 bool is_leaf = i == 0; |
219 OSStatus status = cached_cert.Init(chain_cert); | 219 X509Certificate::SignatureHashAlgorithm hash_algorithm = |
220 if (status) | 220 FillCertVerifyResultWeakSignature(chain_cert, is_leaf, verify_result); |
221 continue; | 221 if (is_leaf) { |
222 x509_util::CSSMFieldValue signature_field; | 222 switch (hash_algorithm) { |
223 status = cached_cert.GetField(&CSSMOID_X509V1SignatureAlgorithm, | 223 case X509Certificate::kSignatureHashAlgorithmMd2: |
224 &signature_field); | 224 case X509Certificate::kSignatureHashAlgorithmMd4: |
225 if (status || !signature_field.field()) | 225 case X509Certificate::kSignatureHashAlgorithmMd5: |
226 continue; | 226 case X509Certificate::kSignatureHashAlgorithmSha1: |
227 // Match the behaviour of OS X system tools and defensively check that | 227 *leaf_is_weak = true; |
228 // sizes are appropriate. This would indicate a critical failure of the | 228 break; |
229 // OS X certificate library, but based on history, it is best to play it | 229 case X509Certificate::kSignatureHashAlgorithmOther: |
230 // safe. | 230 break; |
231 const CSSM_X509_ALGORITHM_IDENTIFIER* sig_algorithm = | |
232 signature_field.GetAs<CSSM_X509_ALGORITHM_IDENTIFIER>(); | |
233 if (!sig_algorithm) | |
234 continue; | |
235 | |
236 const CSSM_OID* alg_oid = &sig_algorithm->algorithm; | |
237 if (CSSMOIDEqual(alg_oid, &CSSMOID_MD2WithRSA)) { | |
238 verify_result->has_md2 = true; | |
239 if (i == 0) | |
240 *leaf_is_weak = true; | |
241 } else if (CSSMOIDEqual(alg_oid, &CSSMOID_MD4WithRSA)) { | |
242 verify_result->has_md4 = true; | |
243 if (i == 0) | |
244 *leaf_is_weak = true; | |
245 } else if (CSSMOIDEqual(alg_oid, &CSSMOID_MD5WithRSA)) { | |
246 verify_result->has_md5 = true; | |
247 if (i == 0) | |
248 *leaf_is_weak = true; | |
249 } else if (CSSMOIDEqual(alg_oid, &CSSMOID_SHA1WithRSA) || | |
250 CSSMOIDEqual(alg_oid, &CSSMOID_SHA1WithRSA_OIW) || | |
251 CSSMOIDEqual(alg_oid, &CSSMOID_SHA1WithDSA) || | |
252 CSSMOIDEqual(alg_oid, &CSSMOID_SHA1WithDSA_CMS) || | |
253 CSSMOIDEqual(alg_oid, &CSSMOID_SHA1WithDSA_JDK) || | |
254 CSSMOIDEqual(alg_oid, &CSSMOID_ECDSA_WithSHA1)) { | |
255 verify_result->has_sha1 = true; | |
256 if (i == 0) { | |
257 verify_result->has_sha1_leaf = true; | |
258 *leaf_is_weak = true; | |
259 } | 231 } |
260 } | 232 } |
261 } | 233 } |
262 if (!verified_cert) { | 234 if (!verified_cert) { |
263 NOTREACHED(); | 235 NOTREACHED(); |
264 return; | 236 return; |
265 } | 237 } |
266 | 238 |
267 verify_result->verified_cert = | 239 verify_result->verified_cert = |
268 X509Certificate::CreateFromHandle(verified_cert, verified_chain); | 240 X509Certificate::CreateFromHandle(verified_cert, verified_chain); |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 // EV cert and it was covered by CRLSets or revocation checking passed. | 1074 // EV cert and it was covered by CRLSets or revocation checking passed. |
1103 verify_result->cert_status |= CERT_STATUS_IS_EV; | 1075 verify_result->cert_status |= CERT_STATUS_IS_EV; |
1104 } | 1076 } |
1105 | 1077 |
1106 return OK; | 1078 return OK; |
1107 } | 1079 } |
1108 | 1080 |
1109 } // namespace net | 1081 } // namespace net |
1110 | 1082 |
1111 #pragma clang diagnostic pop // "-Wdeprecated-declarations" | 1083 #pragma clang diagnostic pop // "-Wdeprecated-declarations" |
OLD | NEW |