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/cert_verify_proc_mac.h" | 5 #include "net/base/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 |
| 11 #include <string> |
| 12 #include <vector> |
| 13 |
11 #include "base/logging.h" | 14 #include "base/logging.h" |
12 #include "base/mac/mac_logging.h" | 15 #include "base/mac/mac_logging.h" |
13 #include "base/mac/scoped_cftyperef.h" | 16 #include "base/mac/scoped_cftyperef.h" |
14 #include "base/sha1.h" | 17 #include "base/sha1.h" |
15 #include "base/string_piece.h" | 18 #include "base/string_piece.h" |
16 #include "crypto/nss_util.h" | 19 #include "crypto/nss_util.h" |
17 #include "crypto/sha2.h" | 20 #include "crypto/sha2.h" |
18 #include "net/base/asn1_util.h" | 21 #include "net/base/asn1_util.h" |
19 #include "net/base/cert_status_flags.h" | 22 #include "net/base/cert_status_flags.h" |
20 #include "net/base/cert_verify_result.h" | 23 #include "net/base/cert_verify_result.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 227 } |
225 } | 228 } |
226 if (!verified_cert) | 229 if (!verified_cert) |
227 return; | 230 return; |
228 | 231 |
229 verify_result->verified_cert = | 232 verify_result->verified_cert = |
230 X509Certificate::CreateFromHandle(verified_cert, verified_chain); | 233 X509Certificate::CreateFromHandle(verified_cert, verified_chain); |
231 } | 234 } |
232 | 235 |
233 void AppendPublicKeyHashes(CFArrayRef chain, | 236 void AppendPublicKeyHashes(CFArrayRef chain, |
234 std::vector<SHA1Fingerprint>* hashes) { | 237 std::vector<HashValueVector>* hashes) { |
235 const CFIndex n = CFArrayGetCount(chain); | 238 const CFIndex n = CFArrayGetCount(chain); |
236 for (CFIndex i = 0; i < n; i++) { | 239 for (CFIndex i = 0; i < n; i++) { |
237 SecCertificateRef cert = reinterpret_cast<SecCertificateRef>( | 240 SecCertificateRef cert = reinterpret_cast<SecCertificateRef>( |
238 const_cast<void*>(CFArrayGetValueAtIndex(chain, i))); | 241 const_cast<void*>(CFArrayGetValueAtIndex(chain, i))); |
239 | 242 |
240 CSSM_DATA cert_data; | 243 CSSM_DATA cert_data; |
241 OSStatus err = SecCertificateGetData(cert, &cert_data); | 244 OSStatus err = SecCertificateGetData(cert, &cert_data); |
242 DCHECK_EQ(err, noErr); | 245 DCHECK_EQ(err, noErr); |
243 base::StringPiece der_bytes(reinterpret_cast<const char*>(cert_data.Data), | 246 base::StringPiece der_bytes(reinterpret_cast<const char*>(cert_data.Data), |
244 cert_data.Length); | 247 cert_data.Length); |
245 base::StringPiece spki_bytes; | 248 base::StringPiece spki_bytes; |
246 if (!asn1::ExtractSPKIFromDERCert(der_bytes, &spki_bytes)) | 249 if (!asn1::ExtractSPKIFromDERCert(der_bytes, &spki_bytes)) |
247 continue; | 250 continue; |
248 | 251 |
249 SHA1Fingerprint hash; | 252 HashValue sha1; |
250 CC_SHA1(spki_bytes.data(), spki_bytes.size(), hash.data); | 253 sha1.tag = HASH_VALUE_SHA1; |
251 hashes->push_back(hash); | 254 CC_SHA1(spki_bytes.data(), spki_bytes.size(), sha1.data()); |
| 255 (*hashes)[HASH_VALUE_SHA1].push_back(sha1); |
| 256 |
| 257 HashValue sha256; |
| 258 sha256.tag = HASH_VALUE_SHA256; |
| 259 CC_SHA256(spki_bytes.data(), spki_bytes.size(), sha256.data()); |
| 260 (*hashes)[HASH_VALUE_SHA256].push_back(sha256); |
252 } | 261 } |
253 } | 262 } |
254 | 263 |
255 bool CheckRevocationWithCRLSet(CFArrayRef chain, CRLSet* crl_set) { | 264 bool CheckRevocationWithCRLSet(CFArrayRef chain, CRLSet* crl_set) { |
256 if (CFArrayGetCount(chain) == 0) | 265 if (CFArrayGetCount(chain) == 0) |
257 return true; | 266 return true; |
258 | 267 |
259 // We iterate from the root certificate down to the leaf, keeping track of | 268 // We iterate from the root certificate down to the leaf, keeping track of |
260 // the issuer's SPKI at each step. | 269 // the issuer's SPKI at each step. |
261 std::string issuer_spki_hash; | 270 std::string issuer_spki_hash; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 327 |
319 // IsIssuedByKnownRoot returns true if the given chain is rooted at a root CA | 328 // IsIssuedByKnownRoot returns true if the given chain is rooted at a root CA |
320 // that we recognise as a standard root. | 329 // that we recognise as a standard root. |
321 // static | 330 // static |
322 bool IsIssuedByKnownRoot(CFArrayRef chain) { | 331 bool IsIssuedByKnownRoot(CFArrayRef chain) { |
323 int n = CFArrayGetCount(chain); | 332 int n = CFArrayGetCount(chain); |
324 if (n < 1) | 333 if (n < 1) |
325 return false; | 334 return false; |
326 SecCertificateRef root_ref = reinterpret_cast<SecCertificateRef>( | 335 SecCertificateRef root_ref = reinterpret_cast<SecCertificateRef>( |
327 const_cast<void*>(CFArrayGetValueAtIndex(chain, n - 1))); | 336 const_cast<void*>(CFArrayGetValueAtIndex(chain, n - 1))); |
328 SHA1Fingerprint hash = X509Certificate::CalculateFingerprint(root_ref); | 337 SHA1HashValue hash = X509Certificate::CalculateFingerprint(root_ref); |
329 return IsSHA1HashInSortedArray( | 338 return IsSHA1HashInSortedArray( |
330 hash, &kKnownRootCertSHA1Hashes[0][0], sizeof(kKnownRootCertSHA1Hashes)); | 339 hash, &kKnownRootCertSHA1Hashes[0][0], sizeof(kKnownRootCertSHA1Hashes)); |
331 } | 340 } |
332 | 341 |
333 } // namespace | 342 } // namespace |
334 | 343 |
335 CertVerifyProcMac::CertVerifyProcMac() {} | 344 CertVerifyProcMac::CertVerifyProcMac() {} |
336 | 345 |
337 CertVerifyProcMac::~CertVerifyProcMac() {} | 346 CertVerifyProcMac::~CertVerifyProcMac() {} |
338 | 347 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 } | 579 } |
571 } | 580 } |
572 | 581 |
573 AppendPublicKeyHashes(completed_chain, &verify_result->public_key_hashes); | 582 AppendPublicKeyHashes(completed_chain, &verify_result->public_key_hashes); |
574 verify_result->is_issued_by_known_root = IsIssuedByKnownRoot(completed_chain); | 583 verify_result->is_issued_by_known_root = IsIssuedByKnownRoot(completed_chain); |
575 | 584 |
576 return OK; | 585 return OK; |
577 } | 586 } |
578 | 587 |
579 } // namespace net | 588 } // namespace net |
OLD | NEW |