| 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 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_OCSP_STAPLING, |
| 2878 (IsOCSPStaplingSupported() || | 2814 (cert_verifier_->SupportsOCSPStapling() || |
| 2879 ssl_config_.signed_cert_timestamps_enabled)); | 2815 ssl_config_.signed_cert_timestamps_enabled)); |
| 2880 if (rv != SECSuccess) { | 2816 if (rv != SECSuccess) { |
| 2881 LogFailedNSSFunction(net_log_, "SSL_OptionSet", | 2817 LogFailedNSSFunction(net_log_, "SSL_OptionSet", |
| 2882 "SSL_ENABLE_OCSP_STAPLING"); | 2818 "SSL_ENABLE_OCSP_STAPLING"); |
| 2883 } | 2819 } |
| 2884 #endif | 2820 #endif |
| 2885 | 2821 |
| 2886 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SIGNED_CERT_TIMESTAMPS, | 2822 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SIGNED_CERT_TIMESTAMPS, |
| 2887 ssl_config_.signed_cert_timestamps_enabled); | 2823 ssl_config_.signed_cert_timestamps_enabled); |
| 2888 if (rv != SECSuccess) { | 2824 if (rv != SECSuccess) { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3097 if (ssl_config_.rev_checking_enabled) | 3033 if (ssl_config_.rev_checking_enabled) |
| 3098 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED; | 3034 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED; |
| 3099 if (ssl_config_.verify_ev_cert) | 3035 if (ssl_config_.verify_ev_cert) |
| 3100 flags |= CertVerifier::VERIFY_EV_CERT; | 3036 flags |= CertVerifier::VERIFY_EV_CERT; |
| 3101 if (ssl_config_.cert_io_enabled) | 3037 if (ssl_config_.cert_io_enabled) |
| 3102 flags |= CertVerifier::VERIFY_CERT_IO_ENABLED; | 3038 flags |= CertVerifier::VERIFY_CERT_IO_ENABLED; |
| 3103 if (ssl_config_.rev_checking_required_local_anchors) | 3039 if (ssl_config_.rev_checking_required_local_anchors) |
| 3104 flags |= CertVerifier::VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS; | 3040 flags |= CertVerifier::VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS; |
| 3105 verifier_.reset(new SingleRequestCertVerifier(cert_verifier_)); | 3041 verifier_.reset(new SingleRequestCertVerifier(cert_verifier_)); |
| 3106 return verifier_->Verify( | 3042 return verifier_->Verify( |
| 3107 core_->state().server_cert.get(), | 3043 core_->state().server_cert.get(), host_and_port_.host(), |
| 3108 host_and_port_.host(), | 3044 core_->state().stapled_ocsp_response, flags, |
| 3109 flags, | 3045 SSLConfigService::GetCRLSet().get(), &server_cert_verify_result_, |
| 3110 SSLConfigService::GetCRLSet().get(), | |
| 3111 &server_cert_verify_result_, | |
| 3112 base::Bind(&SSLClientSocketNSS::OnHandshakeIOComplete, | 3046 base::Bind(&SSLClientSocketNSS::OnHandshakeIOComplete, |
| 3113 base::Unretained(this)), | 3047 base::Unretained(this)), |
| 3114 net_log_); | 3048 net_log_); |
| 3115 } | 3049 } |
| 3116 | 3050 |
| 3117 // Derived from AuthCertificateCallback() in | 3051 // Derived from AuthCertificateCallback() in |
| 3118 // mozilla/source/security/manager/ssl/src/nsNSSCallbacks.cpp. | 3052 // mozilla/source/security/manager/ssl/src/nsNSSCallbacks.cpp. |
| 3119 int SSLClientSocketNSS::DoVerifyCertComplete(int result) { | 3053 int SSLClientSocketNSS::DoVerifyCertComplete(int result) { |
| 3120 verifier_.reset(); | 3054 verifier_.reset(); |
| 3121 | 3055 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3238 scoped_refptr<X509Certificate> | 3172 scoped_refptr<X509Certificate> |
| 3239 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { | 3173 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { |
| 3240 return core_->state().server_cert.get(); | 3174 return core_->state().server_cert.get(); |
| 3241 } | 3175 } |
| 3242 | 3176 |
| 3243 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { | 3177 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { |
| 3244 return channel_id_service_; | 3178 return channel_id_service_; |
| 3245 } | 3179 } |
| 3246 | 3180 |
| 3247 } // namespace net | 3181 } // namespace net |
| OLD | NEW |