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

Side by Side Diff: net/socket/ssl_client_socket_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 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived 5 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived
6 // from AuthCertificateCallback() in 6 // from AuthCertificateCallback() in
7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. 7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp.
8 8
9 /* ***** BEGIN LICENSE BLOCK ***** 9 /* ***** BEGIN LICENSE BLOCK *****
10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 #include <algorithm> 63 #include <algorithm>
64 #include <limits> 64 #include <limits>
65 #include <map> 65 #include <map>
66 66
67 #include "base/bind.h" 67 #include "base/bind.h"
68 #include "base/bind_helpers.h" 68 #include "base/bind_helpers.h"
69 #include "base/callback_helpers.h" 69 #include "base/callback_helpers.h"
70 #include "base/compiler_specific.h" 70 #include "base/compiler_specific.h"
71 #include "base/logging.h" 71 #include "base/logging.h"
72 #include "base/memory/singleton.h"
73 #include "base/metrics/histogram.h" 72 #include "base/metrics/histogram.h"
74 #include "base/single_thread_task_runner.h" 73 #include "base/single_thread_task_runner.h"
75 #include "base/stl_util.h" 74 #include "base/stl_util.h"
76 #include "base/strings/string_number_conversions.h" 75 #include "base/strings/string_number_conversions.h"
77 #include "base/strings/string_util.h" 76 #include "base/strings/string_util.h"
78 #include "base/strings/stringprintf.h" 77 #include "base/strings/stringprintf.h"
79 #include "base/thread_task_runner_handle.h" 78 #include "base/thread_task_runner_handle.h"
80 #include "base/threading/thread_restrictions.h" 79 #include "base/threading/thread_restrictions.h"
81 #include "base/values.h" 80 #include "base/values.h"
82 #include "crypto/ec_private_key.h" 81 #include "crypto/ec_private_key.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // entire SSL record. 151 // entire SSL record.
153 const int kRecvBufferSize = 17 * 1024; 152 const int kRecvBufferSize = 17 * 1024;
154 const int kSendBufferSize = 17 * 1024; 153 const int kSendBufferSize = 17 * 1024;
155 154
156 // Used by SSLClientSocketNSS::Core to indicate there is no read result 155 // Used by SSLClientSocketNSS::Core to indicate there is no read result
157 // obtained by a previous operation waiting to be returned to the caller. 156 // obtained by a previous operation waiting to be returned to the caller.
158 // This constant can be any non-negative/non-zero value (eg: it does not 157 // This constant can be any non-negative/non-zero value (eg: it does not
159 // overlap with any value of the net::Error range, including net::OK). 158 // overlap with any value of the net::Error range, including net::OK).
160 const int kNoPendingReadResult = 1; 159 const int kNoPendingReadResult = 1;
161 160
162 #if defined(USE_NSS_CERTS)
163 typedef SECStatus
164 (*CacheOCSPResponseFromSideChannelFunction)(
165 CERTCertDBHandle *handle, CERTCertificate *cert, PRTime time,
166 SECItem *encodedResponse, void *pwArg);
167
168 // On Linux, we dynamically link against the system version of libnss3.so. In
169 // order to continue working on systems without up-to-date versions of NSS we
170 // lookup CERT_CacheOCSPResponseFromSideChannel with dlsym.
171
172 // RuntimeLibNSSFunctionPointers is a singleton which caches the results of any
173 // runtime symbol resolution that we need.
174 class RuntimeLibNSSFunctionPointers {
175 public:
176 CacheOCSPResponseFromSideChannelFunction
177 GetCacheOCSPResponseFromSideChannelFunction() {
178 return cache_ocsp_response_from_side_channel_;
179 }
180
181 static RuntimeLibNSSFunctionPointers* GetInstance() {
182 return Singleton<RuntimeLibNSSFunctionPointers>::get();
183 }
184
185 private:
186 friend struct DefaultSingletonTraits<RuntimeLibNSSFunctionPointers>;
187
188 RuntimeLibNSSFunctionPointers() {
189 cache_ocsp_response_from_side_channel_ =
190 (CacheOCSPResponseFromSideChannelFunction)
191 dlsym(RTLD_DEFAULT, "CERT_CacheOCSPResponseFromSideChannel");
192 }
193
194 CacheOCSPResponseFromSideChannelFunction
195 cache_ocsp_response_from_side_channel_;
196 };
197
198 CacheOCSPResponseFromSideChannelFunction
199 GetCacheOCSPResponseFromSideChannelFunction() {
200 return RuntimeLibNSSFunctionPointers::GetInstance()
201 ->GetCacheOCSPResponseFromSideChannelFunction();
202 }
203
204 bool IsOCSPStaplingSupported() {
205 return GetCacheOCSPResponseFromSideChannelFunction() != NULL;
206 }
207 #else
208 bool IsOCSPStaplingSupported() {
209 return false;
210 }
211 #endif
212
213 // Helper functions to make it possible to log events from within the 161 // Helper functions to make it possible to log events from within the
214 // SSLClientSocketNSS::Core. 162 // SSLClientSocketNSS::Core.
215 void AddLogEvent(const base::WeakPtr<BoundNetLog>& net_log, 163 void AddLogEvent(const base::WeakPtr<BoundNetLog>& net_log,
216 NetLog::EventType event_type) { 164 NetLog::EventType event_type) {
217 if (!net_log) 165 if (!net_log)
218 return; 166 return;
219 net_log->AddEvent(event_type); 167 net_log->AddEvent(event_type);
220 } 168 }
221 169
222 // Helper function to make it possible to log events from within the 170 // Helper function to make it possible to log events from within the
(...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 SSL_PeerStapledOCSPResponses(nss_fd_); 2010 SSL_PeerStapledOCSPResponses(nss_fd_);
2063 bool ocsp_responses_present = ocsp_responses && ocsp_responses->len; 2011 bool ocsp_responses_present = ocsp_responses && ocsp_responses->len;
2064 if (ocsp_requested) 2012 if (ocsp_requested)
2065 UMA_HISTOGRAM_BOOLEAN("Net.OCSPResponseStapled", ocsp_responses_present); 2013 UMA_HISTOGRAM_BOOLEAN("Net.OCSPResponseStapled", ocsp_responses_present);
2066 if (!ocsp_responses_present) 2014 if (!ocsp_responses_present)
2067 return; 2015 return;
2068 2016
2069 nss_handshake_state_.stapled_ocsp_response = std::string( 2017 nss_handshake_state_.stapled_ocsp_response = std::string(
2070 reinterpret_cast<char*>(ocsp_responses->items[0].data), 2018 reinterpret_cast<char*>(ocsp_responses->items[0].data),
2071 ocsp_responses->items[0].len); 2019 ocsp_responses->items[0].len);
2072
2073 if (IsOCSPStaplingSupported()) {
2074 #if defined(USE_NSS_CERTS)
2075 CacheOCSPResponseFromSideChannelFunction cache_ocsp_response =
2076 GetCacheOCSPResponseFromSideChannelFunction();
2077
2078 cache_ocsp_response(
2079 CERT_GetDefaultCertDB(),
2080 nss_handshake_state_.server_cert_chain[0], PR_Now(),
2081 &ocsp_responses->items[0], NULL);
2082 #endif
2083 }
2084 } 2020 }
2085 2021
2086 void SSLClientSocketNSS::Core::UpdateConnectionStatus() { 2022 void SSLClientSocketNSS::Core::UpdateConnectionStatus() {
2087 // Note: This function may be called multiple times for a single connection 2023 // Note: This function may be called multiple times for a single connection
2088 // if renegotiations occur. 2024 // if renegotiations occur.
2089 nss_handshake_state_.ssl_connection_status = 0; 2025 nss_handshake_state_.ssl_connection_status = 0;
2090 2026
2091 SSLChannelInfo channel_info; 2027 SSLChannelInfo channel_info;
2092 SECStatus ok = SSL_GetChannelInfo(nss_fd_, 2028 SECStatus ok = SSL_GetChannelInfo(nss_fd_,
2093 &channel_info, sizeof(channel_info)); 2029 &channel_info, sizeof(channel_info));
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
2867 } 2803 }
2868 2804
2869 rv = SSL_OptionSet(nss_fd_, SSL_CBC_RANDOM_IV, PR_TRUE); 2805 rv = SSL_OptionSet(nss_fd_, SSL_CBC_RANDOM_IV, PR_TRUE);
2870 if (rv != SECSuccess) 2806 if (rv != SECSuccess)
2871 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_CBC_RANDOM_IV"); 2807 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_CBC_RANDOM_IV");
2872 2808
2873 // Added in NSS 3.15 2809 // Added in NSS 3.15
2874 #ifdef SSL_ENABLE_OCSP_STAPLING 2810 #ifdef SSL_ENABLE_OCSP_STAPLING
2875 // Request OCSP stapling even on platforms that don't support it, in 2811 // Request OCSP stapling even on platforms that don't support it, in
2876 // order to extract Certificate Transparency information. 2812 // order to extract Certificate Transparency information.
2877 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_OCSP_STAPLING, 2813 bool supports_ocsp_stapling =
2878 (IsOCSPStaplingSupported() || 2814 cert_verifier_ && cert_verifier_->SupportsOCSPStapling();
2879 ssl_config_.signed_cert_timestamps_enabled)); 2815 rv = SSL_OptionSet(
2816 nss_fd_, SSL_ENABLE_OCSP_STAPLING,
2817 supports_ocsp_stapling || ssl_config_.signed_cert_timestamps_enabled);
2880 if (rv != SECSuccess) { 2818 if (rv != SECSuccess) {
2881 LogFailedNSSFunction(net_log_, "SSL_OptionSet", 2819 LogFailedNSSFunction(net_log_, "SSL_OptionSet",
2882 "SSL_ENABLE_OCSP_STAPLING"); 2820 "SSL_ENABLE_OCSP_STAPLING");
2883 } 2821 }
2884 #endif 2822 #endif
2885 2823
2886 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SIGNED_CERT_TIMESTAMPS, 2824 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SIGNED_CERT_TIMESTAMPS,
2887 ssl_config_.signed_cert_timestamps_enabled); 2825 ssl_config_.signed_cert_timestamps_enabled);
2888 if (rv != SECSuccess) { 2826 if (rv != SECSuccess) {
2889 LogFailedNSSFunction(net_log_, "SSL_OptionSet", 2827 LogFailedNSSFunction(net_log_, "SSL_OptionSet",
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
3103 if (ssl_config_.rev_checking_enabled) 3041 if (ssl_config_.rev_checking_enabled)
3104 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED; 3042 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED;
3105 if (ssl_config_.verify_ev_cert) 3043 if (ssl_config_.verify_ev_cert)
3106 flags |= CertVerifier::VERIFY_EV_CERT; 3044 flags |= CertVerifier::VERIFY_EV_CERT;
3107 if (ssl_config_.cert_io_enabled) 3045 if (ssl_config_.cert_io_enabled)
3108 flags |= CertVerifier::VERIFY_CERT_IO_ENABLED; 3046 flags |= CertVerifier::VERIFY_CERT_IO_ENABLED;
3109 if (ssl_config_.rev_checking_required_local_anchors) 3047 if (ssl_config_.rev_checking_required_local_anchors)
3110 flags |= CertVerifier::VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS; 3048 flags |= CertVerifier::VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS;
3111 verifier_.reset(new SingleRequestCertVerifier(cert_verifier_)); 3049 verifier_.reset(new SingleRequestCertVerifier(cert_verifier_));
3112 return verifier_->Verify( 3050 return verifier_->Verify(
3113 core_->state().server_cert.get(), 3051 core_->state().server_cert.get(), host_and_port_.host(),
3114 host_and_port_.host(), 3052 core_->state().stapled_ocsp_response, flags,
3115 flags, 3053 SSLConfigService::GetCRLSet().get(), &server_cert_verify_result_,
3116 SSLConfigService::GetCRLSet().get(),
3117 &server_cert_verify_result_,
3118 base::Bind(&SSLClientSocketNSS::OnHandshakeIOComplete, 3054 base::Bind(&SSLClientSocketNSS::OnHandshakeIOComplete,
3119 base::Unretained(this)), 3055 base::Unretained(this)),
3120 net_log_); 3056 net_log_);
3121 } 3057 }
3122 3058
3123 // Derived from AuthCertificateCallback() in 3059 // Derived from AuthCertificateCallback() in
3124 // mozilla/source/security/manager/ssl/src/nsNSSCallbacks.cpp. 3060 // mozilla/source/security/manager/ssl/src/nsNSSCallbacks.cpp.
3125 int SSLClientSocketNSS::DoVerifyCertComplete(int result) { 3061 int SSLClientSocketNSS::DoVerifyCertComplete(int result) {
3126 verifier_.reset(); 3062 verifier_.reset();
3127 3063
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
3244 scoped_refptr<X509Certificate> 3180 scoped_refptr<X509Certificate>
3245 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { 3181 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const {
3246 return core_->state().server_cert.get(); 3182 return core_->state().server_cert.get();
3247 } 3183 }
3248 3184
3249 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { 3185 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const {
3250 return channel_id_service_; 3186 return channel_id_service_;
3251 } 3187 }
3252 3188
3253 } // namespace net 3189 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698