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

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

Issue 1081913003: Route OCSP stapling through CertVerifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@boringnss
Patch Set: split remoting fix out separately Created 5 years, 8 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
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/cert/cert_verify_proc_nss.h" 5 #include "net/cert/cert_verify_proc_nss.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include <cert.h> 10 #include <cert.h>
(...skipping 15 matching lines...) Expand all
26 #include "net/cert/crl_set.h" 26 #include "net/cert/crl_set.h"
27 #include "net/cert/ev_root_ca_metadata.h" 27 #include "net/cert/ev_root_ca_metadata.h"
28 #include "net/cert/x509_certificate.h" 28 #include "net/cert/x509_certificate.h"
29 #include "net/cert/x509_util_nss.h" 29 #include "net/cert/x509_util_nss.h"
30 30
31 #if defined(OS_IOS) 31 #if defined(OS_IOS)
32 #include <CommonCrypto/CommonDigest.h> 32 #include <CommonCrypto/CommonDigest.h>
33 #include "net/cert/x509_util_ios.h" 33 #include "net/cert/x509_util_ios.h"
34 #endif // defined(OS_IOS) 34 #endif // defined(OS_IOS)
35 35
36 #if defined(USE_NSS_CERTS)
37 #include <dlfcn.h>
38 #endif
39
36 namespace net { 40 namespace net {
37 41
38 namespace { 42 namespace {
39 43
40 typedef scoped_ptr< 44 typedef scoped_ptr<
41 CERTCertificatePolicies, 45 CERTCertificatePolicies,
42 crypto::NSSDestroyer<CERTCertificatePolicies, 46 crypto::NSSDestroyer<CERTCertificatePolicies,
43 CERT_DestroyCertificatePoliciesExtension> > 47 CERT_DestroyCertificatePoliciesExtension> >
44 ScopedCERTCertificatePolicies; 48 ScopedCERTCertificatePolicies;
45 49
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 #else 753 #else
750 CERTCertificate* cert = list[i]->os_cert_handle(); 754 CERTCertificate* cert = list[i]->os_cert_handle();
751 #endif 755 #endif
752 CERT_AddCertToListTail(result, CERT_DupCertificate(cert)); 756 CERT_AddCertToListTail(result, CERT_DupCertificate(cert));
753 } 757 }
754 return result; 758 return result;
755 } 759 }
756 760
757 } // namespace 761 } // namespace
758 762
759 CertVerifyProcNSS::CertVerifyProcNSS() {} 763 CertVerifyProcNSS::CertVerifyProcNSS() {
764 #if defined(USE_NSS_CERTS)
765 cache_ocsp_response_from_side_channel_ =
Ryan Sleevi 2015/04/23 01:41:23 In order to const, you have to move to a more chal
davidben 2015/04/23 20:41:47 Done.
766 (CacheOCSPResponseFromSideChannelFunction)dlsym(
767 RTLD_DEFAULT, "CERT_CacheOCSPResponseFromSideChannel");
768 #endif
769 }
760 770
761 CertVerifyProcNSS::~CertVerifyProcNSS() {} 771 CertVerifyProcNSS::~CertVerifyProcNSS() {}
762 772
763 bool CertVerifyProcNSS::SupportsAdditionalTrustAnchors() const { 773 bool CertVerifyProcNSS::SupportsAdditionalTrustAnchors() const {
764 return true; 774 return true;
765 } 775 }
766 776
777 bool CertVerifyProcNSS::SupportsOCSPStapling() const {
778 #if defined(USE_NSS_CERTS)
779 return cache_ocsp_response_from_side_channel_ != nullptr;
Ryan Sleevi 2015/04/23 01:41:23 Drop the explicit "!= nullptr"; this follows the i
davidben 2015/04/23 20:41:47 Done.
780 #else
781 // TODO(davidben): Support OCSP stapling on iOS.
782 return false;
783 #endif
784 }
785
767 int CertVerifyProcNSS::VerifyInternalImpl( 786 int CertVerifyProcNSS::VerifyInternalImpl(
768 X509Certificate* cert, 787 X509Certificate* cert,
769 const std::string& hostname, 788 const std::string& hostname,
789 const std::string& ocsp_response,
770 int flags, 790 int flags,
771 CRLSet* crl_set, 791 CRLSet* crl_set,
772 const CertificateList& additional_trust_anchors, 792 const CertificateList& additional_trust_anchors,
773 CERTChainVerifyCallback* chain_verify_callback, 793 CERTChainVerifyCallback* chain_verify_callback,
774 CertVerifyResult* verify_result) { 794 CertVerifyResult* verify_result) {
775 #if defined(OS_IOS) 795 #if defined(OS_IOS)
776 // For iOS, the entire chain must be loaded into NSS's in-memory certificate 796 // For iOS, the entire chain must be loaded into NSS's in-memory certificate
777 // store. 797 // store.
778 x509_util_ios::NSSCertChain scoped_chain(cert); 798 x509_util_ios::NSSCertChain scoped_chain(cert);
779 CERTCertificate* cert_handle = scoped_chain.cert_handle(); 799 CERTCertificate* cert_handle = scoped_chain.cert_handle();
780 #else 800 #else
781 CERTCertificate* cert_handle = cert->os_cert_handle(); 801 CERTCertificate* cert_handle = cert->os_cert_handle();
782 #endif // defined(OS_IOS) 802 #endif // defined(OS_IOS)
783 803
804 #if defined(USE_NSS_CERTS)
805 if (!ocsp_response.empty() &&
806 cache_ocsp_response_from_side_channel_ != nullptr) {
Ryan Sleevi 2015/04/23 01:41:23 ditto bool conversion. Drop the != nullptr
davidben 2015/04/23 20:41:47 Done.
807 // Note: NSS uses a global hash table, so this call will affect any
Ryan Sleevi 2015/04/23 01:41:23 s/a global/a thread-safe global/
davidben 2015/04/23 20:41:47 Done.
808 // concurrent verification operations on |cert| or copies of the same
809 // certificate. This is an unavoidable limitation of NSS's OCSP API.
810 SECItem ocsp_response_item;
811 ocsp_response_item.data = reinterpret_cast<unsigned char*>(
812 const_cast<char*>(ocsp_response.data()));
813 ocsp_response_item.len = ocsp_response.size();
814 cache_ocsp_response_from_side_channel_(CERT_GetDefaultCertDB(), cert_handle,
815 PR_Now(), &ocsp_response_item, NULL);
816 }
817 #endif // defined(USE_NSS_CERTS)
818
784 if (!cert->VerifyNameMatch(hostname, 819 if (!cert->VerifyNameMatch(hostname,
785 &verify_result->common_name_fallback_used)) { 820 &verify_result->common_name_fallback_used)) {
786 verify_result->cert_status |= CERT_STATUS_COMMON_NAME_INVALID; 821 verify_result->cert_status |= CERT_STATUS_COMMON_NAME_INVALID;
787 } 822 }
788 823
789 // Make sure that the cert is valid now. 824 // Make sure that the cert is valid now.
790 SECCertTimeValidity validity = CERT_CheckCertValidTimes( 825 SECCertTimeValidity validity = CERT_CheckCertValidTimes(
791 cert_handle, PR_Now(), PR_TRUE); 826 cert_handle, PR_Now(), PR_TRUE);
792 if (validity != secCertTimeValid) 827 if (validity != secCertTimeValid)
793 verify_result->cert_status |= CERT_STATUS_DATE_INVALID; 828 verify_result->cert_status |= CERT_STATUS_DATE_INVALID;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 verify_result->cert_status |= CERT_STATUS_IS_EV; 956 verify_result->cert_status |= CERT_STATUS_IS_EV;
922 } 957 }
923 } 958 }
924 959
925 return OK; 960 return OK;
926 } 961 }
927 962
928 int CertVerifyProcNSS::VerifyInternal( 963 int CertVerifyProcNSS::VerifyInternal(
929 X509Certificate* cert, 964 X509Certificate* cert,
930 const std::string& hostname, 965 const std::string& hostname,
966 const std::string& ocsp_response,
931 int flags, 967 int flags,
932 CRLSet* crl_set, 968 CRLSet* crl_set,
933 const CertificateList& additional_trust_anchors, 969 const CertificateList& additional_trust_anchors,
934 CertVerifyResult* verify_result) { 970 CertVerifyResult* verify_result) {
935 return VerifyInternalImpl(cert, 971 return VerifyInternalImpl(cert, hostname, ocsp_response, flags, crl_set,
936 hostname,
937 flags,
938 crl_set,
939 additional_trust_anchors, 972 additional_trust_anchors,
940 NULL, // chain_verify_callback 973 NULL, // chain_verify_callback
941 verify_result); 974 verify_result);
942 } 975 }
943 976
944 } // namespace net 977 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698