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 // 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 Loading... |
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 Loading... |
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 Loading... |
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 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2870 | 2806 |
2871 rv = SSL_OptionSet(nss_fd_, SSL_CBC_RANDOM_IV, PR_TRUE); | 2807 rv = SSL_OptionSet(nss_fd_, SSL_CBC_RANDOM_IV, PR_TRUE); |
2872 if (rv != SECSuccess) | 2808 if (rv != SECSuccess) |
2873 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_CBC_RANDOM_IV"); | 2809 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_CBC_RANDOM_IV"); |
2874 | 2810 |
2875 // Added in NSS 3.15 | 2811 // Added in NSS 3.15 |
2876 #ifdef SSL_ENABLE_OCSP_STAPLING | 2812 #ifdef SSL_ENABLE_OCSP_STAPLING |
2877 // Request OCSP stapling even on platforms that don't support it, in | 2813 // Request OCSP stapling even on platforms that don't support it, in |
2878 // order to extract Certificate Transparency information. | 2814 // order to extract Certificate Transparency information. |
2879 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_OCSP_STAPLING, | 2815 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_OCSP_STAPLING, |
2880 (IsOCSPStaplingSupported() || | 2816 cert_verifier_->SupportsOCSPStapling() || |
2881 ssl_config_.signed_cert_timestamps_enabled)); | 2817 ssl_config_.signed_cert_timestamps_enabled); |
2882 if (rv != SECSuccess) { | 2818 if (rv != SECSuccess) { |
2883 LogFailedNSSFunction(net_log_, "SSL_OptionSet", | 2819 LogFailedNSSFunction(net_log_, "SSL_OptionSet", |
2884 "SSL_ENABLE_OCSP_STAPLING"); | 2820 "SSL_ENABLE_OCSP_STAPLING"); |
2885 } | 2821 } |
2886 #endif | 2822 #endif |
2887 | 2823 |
2888 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SIGNED_CERT_TIMESTAMPS, | 2824 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SIGNED_CERT_TIMESTAMPS, |
2889 ssl_config_.signed_cert_timestamps_enabled); | 2825 ssl_config_.signed_cert_timestamps_enabled); |
2890 if (rv != SECSuccess) { | 2826 if (rv != SECSuccess) { |
2891 LogFailedNSSFunction(net_log_, "SSL_OptionSet", | 2827 LogFailedNSSFunction(net_log_, "SSL_OptionSet", |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3099 if (ssl_config_.rev_checking_enabled) | 3035 if (ssl_config_.rev_checking_enabled) |
3100 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED; | 3036 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED; |
3101 if (ssl_config_.verify_ev_cert) | 3037 if (ssl_config_.verify_ev_cert) |
3102 flags |= CertVerifier::VERIFY_EV_CERT; | 3038 flags |= CertVerifier::VERIFY_EV_CERT; |
3103 if (ssl_config_.cert_io_enabled) | 3039 if (ssl_config_.cert_io_enabled) |
3104 flags |= CertVerifier::VERIFY_CERT_IO_ENABLED; | 3040 flags |= CertVerifier::VERIFY_CERT_IO_ENABLED; |
3105 if (ssl_config_.rev_checking_required_local_anchors) | 3041 if (ssl_config_.rev_checking_required_local_anchors) |
3106 flags |= CertVerifier::VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS; | 3042 flags |= CertVerifier::VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS; |
3107 verifier_.reset(new SingleRequestCertVerifier(cert_verifier_)); | 3043 verifier_.reset(new SingleRequestCertVerifier(cert_verifier_)); |
3108 return verifier_->Verify( | 3044 return verifier_->Verify( |
3109 core_->state().server_cert.get(), | 3045 core_->state().server_cert.get(), host_and_port_.host(), |
3110 host_and_port_.host(), | 3046 core_->state().stapled_ocsp_response, flags, |
3111 flags, | 3047 SSLConfigService::GetCRLSet().get(), &server_cert_verify_result_, |
3112 SSLConfigService::GetCRLSet().get(), | |
3113 &server_cert_verify_result_, | |
3114 base::Bind(&SSLClientSocketNSS::OnHandshakeIOComplete, | 3048 base::Bind(&SSLClientSocketNSS::OnHandshakeIOComplete, |
3115 base::Unretained(this)), | 3049 base::Unretained(this)), |
3116 net_log_); | 3050 net_log_); |
3117 } | 3051 } |
3118 | 3052 |
3119 // Derived from AuthCertificateCallback() in | 3053 // Derived from AuthCertificateCallback() in |
3120 // mozilla/source/security/manager/ssl/src/nsNSSCallbacks.cpp. | 3054 // mozilla/source/security/manager/ssl/src/nsNSSCallbacks.cpp. |
3121 int SSLClientSocketNSS::DoVerifyCertComplete(int result) { | 3055 int SSLClientSocketNSS::DoVerifyCertComplete(int result) { |
3122 verifier_.reset(); | 3056 verifier_.reset(); |
3123 | 3057 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3240 scoped_refptr<X509Certificate> | 3174 scoped_refptr<X509Certificate> |
3241 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { | 3175 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { |
3242 return core_->state().server_cert.get(); | 3176 return core_->state().server_cert.get(); |
3243 } | 3177 } |
3244 | 3178 |
3245 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { | 3179 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { |
3246 return channel_id_service_; | 3180 return channel_id_service_; |
3247 } | 3181 } |
3248 | 3182 |
3249 } // namespace net | 3183 } // namespace net |
OLD | NEW |