| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
| 9 #include "base/string_tokenizer.h" | 9 #include "base/string_tokenizer.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 for (int i = 0; i < num_policies; i++) { | 370 for (int i = 0; i < num_policies; i++) { |
| 371 if (!strcmp(policies_info->rgPolicyInfo[i].pszPolicyIdentifier, policy)) | 371 if (!strcmp(policies_info->rgPolicyInfo[i].pszPolicyIdentifier, policy)) |
| 372 return true; | 372 return true; |
| 373 } | 373 } |
| 374 return false; | 374 return false; |
| 375 } | 375 } |
| 376 | 376 |
| 377 // Helper function to parse a principal from a WinInet description of that | 377 // Helper function to parse a principal from a WinInet description of that |
| 378 // principal. | 378 // principal. |
| 379 void ParsePrincipal(const std::string& description, | 379 void ParsePrincipal(const std::string& description, |
| 380 X509Certificate::Principal* principal) { | 380 CertPrincipal* principal) { |
| 381 // The description of the principal is a string with each LDAP value on | 381 // The description of the principal is a string with each LDAP value on |
| 382 // a separate line. | 382 // a separate line. |
| 383 const std::string kDelimiters("\r\n"); | 383 const std::string kDelimiters("\r\n"); |
| 384 | 384 |
| 385 std::vector<std::string> common_names, locality_names, state_names, | 385 std::vector<std::string> common_names, locality_names, state_names, |
| 386 country_names; | 386 country_names; |
| 387 | 387 |
| 388 // TODO(jcampan): add business_category and serial_number. | 388 // TODO(jcampan): add business_category and serial_number. |
| 389 const std::string kPrefixes[] = { std::string("CN="), | 389 const std::string kPrefixes[] = { std::string("CN="), |
| 390 std::string("L="), | 390 std::string("L="), |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 // Check the end certificate simple chain (chain_context->rgpChain[0]). | 715 // Check the end certificate simple chain (chain_context->rgpChain[0]). |
| 716 // If the end certificate's certificatePolicies extension contains the | 716 // If the end certificate's certificatePolicies extension contains the |
| 717 // EV policy OID of the root CA, return true. | 717 // EV policy OID of the root CA, return true. |
| 718 PCERT_CHAIN_ELEMENT* element = chain_context->rgpChain[0]->rgpElement; | 718 PCERT_CHAIN_ELEMENT* element = chain_context->rgpChain[0]->rgpElement; |
| 719 int num_elements = chain_context->rgpChain[0]->cElement; | 719 int num_elements = chain_context->rgpChain[0]->cElement; |
| 720 if (num_elements < 2) | 720 if (num_elements < 2) |
| 721 return false; | 721 return false; |
| 722 | 722 |
| 723 // Look up the EV policy OID of the root CA. | 723 // Look up the EV policy OID of the root CA. |
| 724 PCCERT_CONTEXT root_cert = element[num_elements - 1]->pCertContext; | 724 PCCERT_CONTEXT root_cert = element[num_elements - 1]->pCertContext; |
| 725 Fingerprint fingerprint = CalculateFingerprint(root_cert); | 725 SHA1Fingerprint fingerprint = CalculateFingerprint(root_cert); |
| 726 const char* ev_policy_oid = NULL; | 726 const char* ev_policy_oid = NULL; |
| 727 if (!metadata->GetPolicyOID(fingerprint, &ev_policy_oid)) | 727 if (!metadata->GetPolicyOID(fingerprint, &ev_policy_oid)) |
| 728 return false; | 728 return false; |
| 729 DCHECK(ev_policy_oid); | 729 DCHECK(ev_policy_oid); |
| 730 | 730 |
| 731 // Get the certificatePolicies extension of the end certificate. | 731 // Get the certificatePolicies extension of the end certificate. |
| 732 PCCERT_CONTEXT end_cert = element[0]->pCertContext; | 732 PCCERT_CONTEXT end_cert = element[0]->pCertContext; |
| 733 scoped_ptr_malloc<CERT_POLICIES_INFO> policies_info; | 733 scoped_ptr_malloc<CERT_POLICIES_INFO> policies_info; |
| 734 GetCertPoliciesInfo(end_cert, &policies_info); | 734 GetCertPoliciesInfo(end_cert, &policies_info); |
| 735 if (!policies_info.get()) | 735 if (!policies_info.get()) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 759 OSCertHandle cert_handle) { | 759 OSCertHandle cert_handle) { |
| 760 return CertDuplicateCertificateContext(cert_handle); | 760 return CertDuplicateCertificateContext(cert_handle); |
| 761 } | 761 } |
| 762 | 762 |
| 763 // static | 763 // static |
| 764 void X509Certificate::FreeOSCertHandle(OSCertHandle cert_handle) { | 764 void X509Certificate::FreeOSCertHandle(OSCertHandle cert_handle) { |
| 765 CertFreeCertificateContext(cert_handle); | 765 CertFreeCertificateContext(cert_handle); |
| 766 } | 766 } |
| 767 | 767 |
| 768 // static | 768 // static |
| 769 X509Certificate::Fingerprint X509Certificate::CalculateFingerprint( | 769 SHA1Fingerprint X509Certificate::CalculateFingerprint( |
| 770 OSCertHandle cert) { | 770 OSCertHandle cert) { |
| 771 DCHECK(NULL != cert->pbCertEncoded); | 771 DCHECK(NULL != cert->pbCertEncoded); |
| 772 DCHECK(0 != cert->cbCertEncoded); | 772 DCHECK(0 != cert->cbCertEncoded); |
| 773 | 773 |
| 774 BOOL rv; | 774 BOOL rv; |
| 775 Fingerprint sha1; | 775 SHA1Fingerprint sha1; |
| 776 DWORD sha1_size = sizeof(sha1.data); | 776 DWORD sha1_size = sizeof(sha1.data); |
| 777 rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded, | 777 rv = CryptHashCertificate(NULL, CALG_SHA1, 0, cert->pbCertEncoded, |
| 778 cert->cbCertEncoded, sha1.data, &sha1_size); | 778 cert->cbCertEncoded, sha1.data, &sha1_size); |
| 779 DCHECK(rv && sha1_size == sizeof(sha1.data)); | 779 DCHECK(rv && sha1_size == sizeof(sha1.data)); |
| 780 if (!rv) | 780 if (!rv) |
| 781 memset(sha1.data, 0, sizeof(sha1.data)); | 781 memset(sha1.data, 0, sizeof(sha1.data)); |
| 782 return sha1; | 782 return sha1; |
| 783 } | 783 } |
| 784 | 784 |
| 785 } // namespace net | 785 } // namespace net |
| OLD | NEW |