| 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 <cert.h> | 7 #include <cert.h> |
| 8 #include <nss.h> | 8 #include <nss.h> |
| 9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
| 10 #include <prerror.h> | 10 #include <prerror.h> |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 break; | 212 break; |
| 213 default: | 213 default: |
| 214 break; | 214 break; |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 typedef char* (*CERTGetNameFunc)(CERTName* name); | 219 typedef char* (*CERTGetNameFunc)(CERTName* name); |
| 220 | 220 |
| 221 void ParsePrincipal(CERTName* name, | 221 void ParsePrincipal(CERTName* name, |
| 222 X509Certificate::Principal* principal) { | 222 CertPrincipal* principal) { |
| 223 // TODO(jcampan): add business_category and serial_number. | 223 // TODO(jcampan): add business_category and serial_number. |
| 224 // TODO(wtc): NSS has the CERT_GetOrgName, CERT_GetOrgUnitName, and | 224 // TODO(wtc): NSS has the CERT_GetOrgName, CERT_GetOrgUnitName, and |
| 225 // CERT_GetDomainComponentName functions, but they return only the most | 225 // CERT_GetDomainComponentName functions, but they return only the most |
| 226 // general (the first) RDN. NSS doesn't have a function for the street | 226 // general (the first) RDN. NSS doesn't have a function for the street |
| 227 // address. | 227 // address. |
| 228 static const SECOidTag kOIDs[] = { | 228 static const SECOidTag kOIDs[] = { |
| 229 SEC_OID_AVA_STREET_ADDRESS, | 229 SEC_OID_AVA_STREET_ADDRESS, |
| 230 SEC_OID_AVA_ORGANIZATION_NAME, | 230 SEC_OID_AVA_ORGANIZATION_NAME, |
| 231 SEC_OID_AVA_ORGANIZATIONAL_UNIT_NAME, | 231 SEC_OID_AVA_ORGANIZATIONAL_UNIT_NAME, |
| 232 SEC_OID_AVA_DC }; | 232 SEC_OID_AVA_DC }; |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 metadata->GetPolicyOIDs(), | 699 metadata->GetPolicyOIDs(), |
| 700 metadata->NumPolicyOIDs(), | 700 metadata->NumPolicyOIDs(), |
| 701 cvout); | 701 cvout); |
| 702 if (status != SECSuccess) | 702 if (status != SECSuccess) |
| 703 return false; | 703 return false; |
| 704 | 704 |
| 705 CERTCertificate* root_ca = | 705 CERTCertificate* root_ca = |
| 706 cvout[cvout_trust_anchor_index].value.pointer.cert; | 706 cvout[cvout_trust_anchor_index].value.pointer.cert; |
| 707 if (root_ca == NULL) | 707 if (root_ca == NULL) |
| 708 return false; | 708 return false; |
| 709 X509Certificate::Fingerprint fingerprint = | 709 SHA1Fingerprint fingerprint = |
| 710 X509Certificate::CalculateFingerprint(root_ca); | 710 X509Certificate::CalculateFingerprint(root_ca); |
| 711 SECOidTag ev_policy_tag = SEC_OID_UNKNOWN; | 711 SECOidTag ev_policy_tag = SEC_OID_UNKNOWN; |
| 712 if (!metadata->GetPolicyOID(fingerprint, &ev_policy_tag)) | 712 if (!metadata->GetPolicyOID(fingerprint, &ev_policy_tag)) |
| 713 return false; | 713 return false; |
| 714 | 714 |
| 715 if (!CheckCertPolicies(cert_handle_, ev_policy_tag)) | 715 if (!CheckCertPolicies(cert_handle_, ev_policy_tag)) |
| 716 return false; | 716 return false; |
| 717 | 717 |
| 718 return true; | 718 return true; |
| 719 } | 719 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 743 OSCertHandle cert_handle) { | 743 OSCertHandle cert_handle) { |
| 744 return CERT_DupCertificate(cert_handle); | 744 return CERT_DupCertificate(cert_handle); |
| 745 } | 745 } |
| 746 | 746 |
| 747 // static | 747 // static |
| 748 void X509Certificate::FreeOSCertHandle(OSCertHandle cert_handle) { | 748 void X509Certificate::FreeOSCertHandle(OSCertHandle cert_handle) { |
| 749 CERT_DestroyCertificate(cert_handle); | 749 CERT_DestroyCertificate(cert_handle); |
| 750 } | 750 } |
| 751 | 751 |
| 752 // static | 752 // static |
| 753 X509Certificate::Fingerprint X509Certificate::CalculateFingerprint( | 753 SHA1Fingerprint X509Certificate::CalculateFingerprint( |
| 754 OSCertHandle cert) { | 754 OSCertHandle cert) { |
| 755 Fingerprint sha1; | 755 SHA1Fingerprint sha1; |
| 756 memset(sha1.data, 0, sizeof(sha1.data)); | 756 memset(sha1.data, 0, sizeof(sha1.data)); |
| 757 | 757 |
| 758 DCHECK(NULL != cert->derCert.data); | 758 DCHECK(NULL != cert->derCert.data); |
| 759 DCHECK(0 != cert->derCert.len); | 759 DCHECK(0 != cert->derCert.len); |
| 760 | 760 |
| 761 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, sha1.data, | 761 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, sha1.data, |
| 762 cert->derCert.data, cert->derCert.len); | 762 cert->derCert.data, cert->derCert.len); |
| 763 DCHECK(rv == SECSuccess); | 763 DCHECK(rv == SECSuccess); |
| 764 | 764 |
| 765 return sha1; | 765 return sha1; |
| 766 } | 766 } |
| 767 | 767 |
| 768 } // namespace net | 768 } // namespace net |
| OLD | NEW |