| 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_nss.h" | 5 #include "net/base/cert_verify_proc_nss.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 7 #include <cert.h> | 10 #include <cert.h> |
| 8 #include <nss.h> | 11 #include <nss.h> |
| 9 #include <prerror.h> | 12 #include <prerror.h> |
| 10 #include <secerr.h> | 13 #include <secerr.h> |
| 11 #include <sechash.h> | 14 #include <sechash.h> |
| 12 #include <sslerr.h> | 15 #include <sslerr.h> |
| 13 | 16 |
| 14 #include "base/logging.h" | 17 #include "base/logging.h" |
| 15 #include "crypto/nss_util.h" | 18 #include "crypto/nss_util.h" |
| 16 #include "crypto/scoped_nss_types.h" | 19 #include "crypto/scoped_nss_types.h" |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 od.offset = SEC_OID_UNKNOWN; | 563 od.offset = SEC_OID_UNKNOWN; |
| 561 // NSS doesn't allow us to pass an empty description, so I use a hardcoded, | 564 // NSS doesn't allow us to pass an empty description, so I use a hardcoded, |
| 562 // default description here. The description doesn't need to be unique for | 565 // default description here. The description doesn't need to be unique for |
| 563 // each OID. | 566 // each OID. |
| 564 od.desc = "a certificate policy"; | 567 od.desc = "a certificate policy"; |
| 565 od.mechanism = CKM_INVALID_MECHANISM; | 568 od.mechanism = CKM_INVALID_MECHANISM; |
| 566 od.supportedExtension = INVALID_CERT_EXTENSION; | 569 od.supportedExtension = INVALID_CERT_EXTENSION; |
| 567 return SECOID_AddEntry(&od); | 570 return SECOID_AddEntry(&od); |
| 568 } | 571 } |
| 569 | 572 |
| 570 SHA1Fingerprint CertPublicKeyHash(CERTCertificate* cert) { | 573 HashValue CertPublicKeyHashSHA1(CERTCertificate* cert) { |
| 571 SHA1Fingerprint hash; | 574 HashValue hash(HASH_VALUE_SHA1); |
| 572 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, hash.data, | 575 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, hash.data(), |
| 576 cert->derPublicKey.data, cert->derPublicKey.len); |
| 577 DCHECK_EQ(SECSuccess, rv); |
| 578 return hash; |
| 579 } |
| 580 |
| 581 HashValue CertPublicKeyHashSHA256(CERTCertificate* cert) { |
| 582 HashValue hash(HASH_VALUE_SHA256); |
| 583 SECStatus rv = HASH_HashBuf(HASH_AlgSHA256, hash.data(), |
| 573 cert->derPublicKey.data, cert->derPublicKey.len); | 584 cert->derPublicKey.data, cert->derPublicKey.len); |
| 574 DCHECK_EQ(rv, SECSuccess); | 585 DCHECK_EQ(rv, SECSuccess); |
| 575 return hash; | 586 return hash; |
| 576 } | 587 } |
| 577 | 588 |
| 578 void AppendPublicKeyHashes(CERTCertList* cert_list, | 589 void AppendPublicKeyHashes(CERTCertList* cert_list, |
| 579 CERTCertificate* root_cert, | 590 CERTCertificate* root_cert, |
| 580 std::vector<SHA1Fingerprint>* hashes) { | 591 HashValueVector* hashes) { |
| 581 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); | 592 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); |
| 582 !CERT_LIST_END(node, cert_list); | 593 !CERT_LIST_END(node, cert_list); |
| 583 node = CERT_LIST_NEXT(node)) { | 594 node = CERT_LIST_NEXT(node)) { |
| 584 hashes->push_back(CertPublicKeyHash(node->cert)); | 595 hashes->push_back(CertPublicKeyHashSHA1(node->cert)); |
| 596 hashes->push_back(CertPublicKeyHashSHA256(node->cert)); |
| 585 } | 597 } |
| 586 if (root_cert) | 598 if (root_cert) { |
| 587 hashes->push_back(CertPublicKeyHash(root_cert)); | 599 hashes->push_back(CertPublicKeyHashSHA1(root_cert)); |
| 600 hashes->push_back(CertPublicKeyHashSHA256(root_cert)); |
| 601 } |
| 588 } | 602 } |
| 589 | 603 |
| 590 // Returns true if |cert_handle| contains a policy OID that is an EV policy | 604 // Returns true if |cert_handle| contains a policy OID that is an EV policy |
| 591 // OID according to |metadata|, storing the resulting policy OID in | 605 // OID according to |metadata|, storing the resulting policy OID in |
| 592 // |*ev_policy_oid|. A true return is not sufficient to establish that a | 606 // |*ev_policy_oid|. A true return is not sufficient to establish that a |
| 593 // certificate is EV, but a false return is sufficient to establish the | 607 // certificate is EV, but a false return is sufficient to establish the |
| 594 // certificate cannot be EV. | 608 // certificate cannot be EV. |
| 595 bool IsEVCandidate(EVRootCAMetadata* metadata, | 609 bool IsEVCandidate(EVRootCAMetadata* metadata, |
| 596 CERTCertificate* cert_handle, | 610 CERTCertificate* cert_handle, |
| 597 SECOidTag* ev_policy_oid) { | 611 SECOidTag* ev_policy_oid) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 // the old path, might have been revoked. | 679 // the old path, might have been revoked. |
| 666 if (crl_set) { | 680 if (crl_set) { |
| 667 CRLSetResult crl_set_result = CheckRevocationWithCRLSet( | 681 CRLSetResult crl_set_result = CheckRevocationWithCRLSet( |
| 668 cvout[cvout_cert_list_index].value.pointer.chain, | 682 cvout[cvout_cert_list_index].value.pointer.chain, |
| 669 cvout[cvout_trust_anchor_index].value.pointer.cert, | 683 cvout[cvout_trust_anchor_index].value.pointer.cert, |
| 670 crl_set); | 684 crl_set); |
| 671 if (crl_set_result == kCRLSetRevoked) | 685 if (crl_set_result == kCRLSetRevoked) |
| 672 return false; | 686 return false; |
| 673 } | 687 } |
| 674 | 688 |
| 675 SHA1Fingerprint fingerprint = | 689 SHA1HashValue fingerprint = |
| 676 X509Certificate::CalculateFingerprint(root_ca); | 690 X509Certificate::CalculateFingerprint(root_ca); |
| 677 return metadata->HasEVPolicyOID(fingerprint, ev_policy_oid); | 691 return metadata->HasEVPolicyOID(fingerprint, ev_policy_oid); |
| 678 } | 692 } |
| 679 | 693 |
| 680 } // namespace | 694 } // namespace |
| 681 | 695 |
| 682 CertVerifyProcNSS::CertVerifyProcNSS() {} | 696 CertVerifyProcNSS::CertVerifyProcNSS() {} |
| 683 | 697 |
| 684 CertVerifyProcNSS::~CertVerifyProcNSS() {} | 698 CertVerifyProcNSS::~CertVerifyProcNSS() {} |
| 685 | 699 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 | 788 |
| 775 if ((flags & CertVerifier::VERIFY_EV_CERT) && is_ev_candidate && | 789 if ((flags & CertVerifier::VERIFY_EV_CERT) && is_ev_candidate && |
| 776 VerifyEV(cert_handle, flags, crl_set, metadata, ev_policy_oid)) { | 790 VerifyEV(cert_handle, flags, crl_set, metadata, ev_policy_oid)) { |
| 777 verify_result->cert_status |= CERT_STATUS_IS_EV; | 791 verify_result->cert_status |= CERT_STATUS_IS_EV; |
| 778 } | 792 } |
| 779 | 793 |
| 780 return OK; | 794 return OK; |
| 781 } | 795 } |
| 782 | 796 |
| 783 } // namespace net | 797 } // namespace net |
| OLD | NEW |