Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: net/base/cert_verify_proc_nss.cc

Issue 10826257: Implement SHA-256 fingerprint support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 od.offset = SEC_OID_UNKNOWN; 562 od.offset = SEC_OID_UNKNOWN;
560 // NSS doesn't allow us to pass an empty description, so I use a hardcoded, 563 // NSS doesn't allow us to pass an empty description, so I use a hardcoded,
561 // default description here. The description doesn't need to be unique for 564 // default description here. The description doesn't need to be unique for
562 // each OID. 565 // each OID.
563 od.desc = "a certificate policy"; 566 od.desc = "a certificate policy";
564 od.mechanism = CKM_INVALID_MECHANISM; 567 od.mechanism = CKM_INVALID_MECHANISM;
565 od.supportedExtension = INVALID_CERT_EXTENSION; 568 od.supportedExtension = INVALID_CERT_EXTENSION;
566 return SECOID_AddEntry(&od); 569 return SECOID_AddEntry(&od);
567 } 570 }
568 571
569 SHA1Fingerprint CertPublicKeyHash(CERTCertificate* cert) { 572 HashValue CertPublicKeyHashSHA1(CERTCertificate* cert) {
570 SHA1Fingerprint hash; 573 HashValue hash(HASH_VALUE_SHA1);
571 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, hash.data, 574 SECStatus rv = HASH_HashBuf(HASH_AlgSHA1, hash.data(),
575 cert->derPublicKey.data, cert->derPublicKey.len);
576 DCHECK_EQ(rv, SECSuccess);
577 return hash;
578 }
579
580 HashValue CertPublicKeyHashSHA256(CERTCertificate* cert) {
581 HashValue hash(HASH_VALUE_SHA256);
582 SECStatus rv = HASH_HashBuf(HASH_AlgSHA256, hash.data(),
572 cert->derPublicKey.data, cert->derPublicKey.len); 583 cert->derPublicKey.data, cert->derPublicKey.len);
573 DCHECK_EQ(rv, SECSuccess); 584 DCHECK_EQ(rv, SECSuccess);
574 return hash; 585 return hash;
575 } 586 }
576 587
577 void AppendPublicKeyHashes(CERTCertList* cert_list, 588 void AppendPublicKeyHashes(CERTCertList* cert_list,
578 CERTCertificate* root_cert, 589 CERTCertificate* root_cert,
579 std::vector<SHA1Fingerprint>* hashes) { 590 HashValueVector* hashes) {
580 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); 591 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list);
581 !CERT_LIST_END(node, cert_list); 592 !CERT_LIST_END(node, cert_list);
582 node = CERT_LIST_NEXT(node)) { 593 node = CERT_LIST_NEXT(node)) {
583 hashes->push_back(CertPublicKeyHash(node->cert)); 594 hashes->push_back(CertPublicKeyHashSHA1(node->cert));
595 hashes->push_back(CertPublicKeyHashSHA256(node->cert));
584 } 596 }
585 if (root_cert) 597 if (root_cert) {
586 hashes->push_back(CertPublicKeyHash(root_cert)); 598 hashes->push_back(CertPublicKeyHashSHA1(root_cert));
599 hashes->push_back(CertPublicKeyHashSHA256(root_cert));
600 }
587 } 601 }
588 602
589 // Returns true if |cert_handle| contains a policy OID that is an EV policy 603 // Returns true if |cert_handle| contains a policy OID that is an EV policy
590 // OID according to |metadata|, storing the resulting policy OID in 604 // OID according to |metadata|, storing the resulting policy OID in
591 // |*ev_policy_oid|. A true return is not sufficient to establish that a 605 // |*ev_policy_oid|. A true return is not sufficient to establish that a
592 // certificate is EV, but a false return is sufficient to establish the 606 // certificate is EV, but a false return is sufficient to establish the
593 // certificate cannot be EV. 607 // certificate cannot be EV.
594 bool IsEVCandidate(EVRootCAMetadata* metadata, 608 bool IsEVCandidate(EVRootCAMetadata* metadata,
595 CERTCertificate* cert_handle, 609 CERTCertificate* cert_handle,
596 SECOidTag* ev_policy_oid) { 610 SECOidTag* ev_policy_oid) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 // the old path, might have been revoked. 678 // the old path, might have been revoked.
665 if (crl_set) { 679 if (crl_set) {
666 CRLSetResult crl_set_result = CheckRevocationWithCRLSet( 680 CRLSetResult crl_set_result = CheckRevocationWithCRLSet(
667 cvout[cvout_cert_list_index].value.pointer.chain, 681 cvout[cvout_cert_list_index].value.pointer.chain,
668 cvout[cvout_trust_anchor_index].value.pointer.cert, 682 cvout[cvout_trust_anchor_index].value.pointer.cert,
669 crl_set); 683 crl_set);
670 if (crl_set_result == kCRLSetRevoked) 684 if (crl_set_result == kCRLSetRevoked)
671 return false; 685 return false;
672 } 686 }
673 687
674 SHA1Fingerprint fingerprint = 688 SHA1HashValue fingerprint =
675 X509Certificate::CalculateFingerprint(root_ca); 689 X509Certificate::CalculateFingerprint(root_ca);
676 return metadata->HasEVPolicyOID(fingerprint, ev_policy_oid); 690 return metadata->HasEVPolicyOID(fingerprint, ev_policy_oid);
677 } 691 }
678 692
679 } // namespace 693 } // namespace
680 694
681 CertVerifyProcNSS::CertVerifyProcNSS() {} 695 CertVerifyProcNSS::CertVerifyProcNSS() {}
682 696
683 CertVerifyProcNSS::~CertVerifyProcNSS() {} 697 CertVerifyProcNSS::~CertVerifyProcNSS() {}
684 698
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 787
774 if ((flags & X509Certificate::VERIFY_EV_CERT) && is_ev_candidate && 788 if ((flags & X509Certificate::VERIFY_EV_CERT) && is_ev_candidate &&
775 VerifyEV(cert_handle, flags, crl_set, metadata, ev_policy_oid)) { 789 VerifyEV(cert_handle, flags, crl_set, metadata, ev_policy_oid)) {
776 verify_result->cert_status |= CERT_STATUS_IS_EV; 790 verify_result->cert_status |= CERT_STATUS_IS_EV;
777 } 791 }
778 792
779 return OK; 793 return OK;
780 } 794 }
781 795
782 } // namespace net 796 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698