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