OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 if (!ssl_host_info_.get()) | 473 if (!ssl_host_info_.get()) |
474 return; | 474 return; |
475 | 475 |
476 SECStatus rv; | 476 SECStatus rv; |
477 SSLSnapStartResult snap_start_type; | 477 SSLSnapStartResult snap_start_type; |
478 rv = SSL_GetSnapStartResult(nss_fd_, &snap_start_type); | 478 rv = SSL_GetSnapStartResult(nss_fd_, &snap_start_type); |
479 if (rv != SECSuccess) { | 479 if (rv != SECSuccess) { |
480 NOTREACHED(); | 480 NOTREACHED(); |
481 return; | 481 return; |
482 } | 482 } |
| 483 net_log_.AddEvent(NetLog::TYPE_SSL_SNAP_START, |
| 484 new NetLogIntegerParameter("type", snap_start_type)); |
483 LOG(ERROR) << "Snap Start: " << snap_start_type << " " << hostname_; | 485 LOG(ERROR) << "Snap Start: " << snap_start_type << " " << hostname_; |
484 if (snap_start_type == SSL_SNAP_START_FULL || | 486 if (snap_start_type == SSL_SNAP_START_FULL || |
485 snap_start_type == SSL_SNAP_START_RESUME) { | 487 snap_start_type == SSL_SNAP_START_RESUME) { |
486 // If we did a successful Snap Start then our information was correct and | 488 // If we did a successful Snap Start then our information was correct and |
487 // there's no point saving it again. | 489 // there's no point saving it again. |
488 return; | 490 return; |
489 } | 491 } |
490 | 492 |
491 const unsigned char* hello_data; | 493 const unsigned char* hello_data; |
492 unsigned hello_data_len; | 494 unsigned hello_data_len; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 ssl_config_.false_start_enabled && | 738 ssl_config_.false_start_enabled && |
737 !SSLConfigService::IsKnownFalseStartIncompatibleServer(hostname_)); | 739 !SSLConfigService::IsKnownFalseStartIncompatibleServer(hostname_)); |
738 if (rv != SECSuccess) | 740 if (rv != SECSuccess) |
739 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_FALSE_START"); | 741 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_FALSE_START"); |
740 #endif | 742 #endif |
741 | 743 |
742 #ifdef SSL_ENABLE_SNAP_START | 744 #ifdef SSL_ENABLE_SNAP_START |
743 // TODO(agl): check that SSL_ENABLE_SNAP_START actually does something in the | 745 // TODO(agl): check that SSL_ENABLE_SNAP_START actually does something in the |
744 // current NSS code. | 746 // current NSS code. |
745 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SNAP_START, | 747 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SNAP_START, |
746 SSLConfigService::snap_start_enabled()); | 748 ssl_config_.snap_start_enabled); |
747 if (rv != SECSuccess) | 749 if (rv != SECSuccess) |
748 VLOG(1) << "SSL_ENABLE_SNAP_START failed. Old system nss?"; | 750 VLOG(1) << "SSL_ENABLE_SNAP_START failed. Old system nss?"; |
749 #endif | 751 #endif |
750 | 752 |
751 #ifdef SSL_ENABLE_RENEGOTIATION | 753 #ifdef SSL_ENABLE_RENEGOTIATION |
752 // Deliberately disable this check for now: http://crbug.com/55410 | 754 // Deliberately disable this check for now: http://crbug.com/55410 |
753 if (false && | 755 if (false && |
754 SSLConfigService::IsKnownStrictTLSServer(hostname_) && | 756 SSLConfigService::IsKnownStrictTLSServer(hostname_) && |
755 !ssl_config_.mitm_proxies_allowed) { | 757 !ssl_config_.mitm_proxies_allowed) { |
756 rv = SSL_OptionSet(nss_fd_, SSL_REQUIRE_SAFE_NEGOTIATION, PR_TRUE); | 758 rv = SSL_OptionSet(nss_fd_, SSL_REQUIRE_SAFE_NEGOTIATION, PR_TRUE); |
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1842 | 1844 |
1843 that->handshake_callback_called_ = true; | 1845 that->handshake_callback_called_ = true; |
1844 | 1846 |
1845 that->UpdateServerCert(); | 1847 that->UpdateServerCert(); |
1846 that->UpdateConnectionStatus(); | 1848 that->UpdateConnectionStatus(); |
1847 } | 1849 } |
1848 | 1850 |
1849 int SSLClientSocketNSS::DoSnapStartLoadInfo() { | 1851 int SSLClientSocketNSS::DoSnapStartLoadInfo() { |
1850 EnterFunction(""); | 1852 EnterFunction(""); |
1851 int rv = ssl_host_info_->WaitForDataReady(&handshake_io_callback_); | 1853 int rv = ssl_host_info_->WaitForDataReady(&handshake_io_callback_); |
| 1854 GotoState(STATE_HANDSHAKE); |
1852 | 1855 |
1853 if (rv == OK) { | 1856 if (rv == OK) { |
1854 if (LoadSnapStartInfo()) { | 1857 if (ssl_host_info_->WaitForCertVerification(NULL) == OK) { |
1855 pseudo_connected_ = true; | 1858 if (LoadSnapStartInfo()) { |
1856 GotoState(STATE_SNAP_START_WAIT_FOR_WRITE); | 1859 pseudo_connected_ = true; |
1857 if (user_connect_callback_) | 1860 GotoState(STATE_SNAP_START_WAIT_FOR_WRITE); |
1858 DoConnectCallback(OK); | 1861 if (user_connect_callback_) |
1859 } else { | 1862 DoConnectCallback(OK); |
1860 GotoState(STATE_HANDSHAKE); | 1863 } |
| 1864 } else if (!ssl_host_info_->state().server_hello.empty()) { |
| 1865 // A non-empty ServerHello suggests that we would have tried a Snap Start |
| 1866 // connection. |
| 1867 base::TimeTicks now = base::TimeTicks::Now(); |
| 1868 const base::TimeDelta duration = |
| 1869 now - ssl_host_info_->verification_start_time(); |
| 1870 UMA_HISTOGRAM_TIMES("Net.SSLSnapStartNeededVerificationInMs", duration); |
| 1871 VLOG(1) << "Cannot snap start because verification isn't ready. " |
| 1872 << "Wanted verification after " |
| 1873 << duration.InMilliseconds() << "ms"; |
1861 } | 1874 } |
1862 } else { | 1875 } else { |
1863 DCHECK_EQ(ERR_IO_PENDING, rv); | 1876 DCHECK_EQ(ERR_IO_PENDING, rv); |
1864 GotoState(STATE_SNAP_START_LOAD_INFO); | |
1865 } | 1877 } |
1866 | 1878 |
1867 LeaveFunction(""); | 1879 LeaveFunction(""); |
1868 return rv; | 1880 return rv; |
1869 } | 1881 } |
1870 | 1882 |
1871 int SSLClientSocketNSS::DoSnapStartWaitForWrite() { | 1883 int SSLClientSocketNSS::DoSnapStartWaitForWrite() { |
1872 EnterFunction(""); | 1884 EnterFunction(""); |
1873 // In this state, we're waiting for the first Write call so that we can merge | 1885 // In this state, we're waiting for the first Write call so that we can merge |
1874 // it into the Snap Start handshake. | 1886 // it into the Snap Start handshake. |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2217 DCHECK(server_cert_); | 2229 DCHECK(server_cert_); |
2218 | 2230 |
2219 GotoState(STATE_VERIFY_CERT_COMPLETE); | 2231 GotoState(STATE_VERIFY_CERT_COMPLETE); |
2220 | 2232 |
2221 if (ssl_host_info_.get() && !ssl_host_info_->state().certs.empty() && | 2233 if (ssl_host_info_.get() && !ssl_host_info_->state().certs.empty() && |
2222 predicted_cert_chain_correct_) { | 2234 predicted_cert_chain_correct_) { |
2223 // If the SSLHostInfo had a prediction for the certificate chain of this | 2235 // If the SSLHostInfo had a prediction for the certificate chain of this |
2224 // server then it will have optimistically started a verification of that | 2236 // server then it will have optimistically started a verification of that |
2225 // chain. So, if the prediction was correct, we should wait for that | 2237 // chain. So, if the prediction was correct, we should wait for that |
2226 // verification to finish rather than start our own. | 2238 // verification to finish rather than start our own. |
| 2239 net_log_.AddEvent(NetLog::TYPE_SSL_VERIFICATION_MERGED, NULL); |
| 2240 UMA_HISTOGRAM_ENUMERATION("Net.SSLVerificationMerged", 1 /* true */, 2); |
| 2241 base::TimeTicks now = base::TimeTicks::Now(); |
| 2242 UMA_HISTOGRAM_TIMES("Net.SSLVerificationMergedMsSaved", |
| 2243 now - ssl_host_info_->verification_start_time()); |
2227 server_cert_verify_result_ = &ssl_host_info_->cert_verify_result(); | 2244 server_cert_verify_result_ = &ssl_host_info_->cert_verify_result(); |
2228 return ssl_host_info_->WaitForCertVerification(&handshake_io_callback_); | 2245 return ssl_host_info_->WaitForCertVerification(&handshake_io_callback_); |
| 2246 } else { |
| 2247 UMA_HISTOGRAM_ENUMERATION("Net.SSLVerificationMerged", 0 /* false */, 2); |
2229 } | 2248 } |
2230 | 2249 |
2231 int flags = 0; | 2250 int flags = 0; |
2232 if (ssl_config_.rev_checking_enabled) | 2251 if (ssl_config_.rev_checking_enabled) |
2233 flags |= X509Certificate::VERIFY_REV_CHECKING_ENABLED; | 2252 flags |= X509Certificate::VERIFY_REV_CHECKING_ENABLED; |
2234 if (ssl_config_.verify_ev_cert) | 2253 if (ssl_config_.verify_ev_cert) |
2235 flags |= X509Certificate::VERIFY_EV_CERT; | 2254 flags |= X509Certificate::VERIFY_EV_CERT; |
2236 verifier_.reset(new CertVerifier); | 2255 verifier_.reset(new CertVerifier); |
2237 server_cert_verify_result_ = &local_server_cert_verify_result_; | 2256 server_cert_verify_result_ = &local_server_cert_verify_result_; |
2238 return verifier_->Verify(server_cert_, hostname_, flags, | 2257 return verifier_->Verify(server_cert_, hostname_, flags, |
2239 &local_server_cert_verify_result_, | 2258 &local_server_cert_verify_result_, |
2240 &handshake_io_callback_); | 2259 &handshake_io_callback_); |
2241 } | 2260 } |
2242 | 2261 |
2243 // Derived from AuthCertificateCallback() in | 2262 // Derived from AuthCertificateCallback() in |
2244 // mozilla/source/security/manager/ssl/src/nsNSSCallbacks.cpp. | 2263 // mozilla/source/security/manager/ssl/src/nsNSSCallbacks.cpp. |
2245 int SSLClientSocketNSS::DoVerifyCertComplete(int result) { | 2264 int SSLClientSocketNSS::DoVerifyCertComplete(int result) { |
2246 verifier_.reset(); | 2265 verifier_.reset(); |
2247 | 2266 |
2248 // Using Snap Start disables certificate verification for now. | |
2249 if (SSLConfigService::snap_start_enabled()) | |
2250 result = OK; | |
2251 | |
2252 // We used to remember the intermediate CA certs in the NSS database | 2267 // We used to remember the intermediate CA certs in the NSS database |
2253 // persistently. However, NSS opens a connection to the SQLite database | 2268 // persistently. However, NSS opens a connection to the SQLite database |
2254 // during NSS initialization and doesn't close the connection until NSS | 2269 // during NSS initialization and doesn't close the connection until NSS |
2255 // shuts down. If the file system where the database resides is gone, | 2270 // shuts down. If the file system where the database resides is gone, |
2256 // the database connection goes bad. What's worse, the connection won't | 2271 // the database connection goes bad. What's worse, the connection won't |
2257 // recover when the file system comes back. Until this NSS or SQLite bug | 2272 // recover when the file system comes back. Until this NSS or SQLite bug |
2258 // is fixed, we need to avoid using the NSS database for non-essential | 2273 // is fixed, we need to avoid using the NSS database for non-essential |
2259 // purposes. See https://bugzilla.mozilla.org/show_bug.cgi?id=508081 and | 2274 // purposes. See https://bugzilla.mozilla.org/show_bug.cgi?id=508081 and |
2260 // http://crbug.com/15630 for more info. | 2275 // http://crbug.com/15630 for more info. |
2261 | 2276 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2389 case SSL_CONNECTION_VERSION_TLS1_1: | 2404 case SSL_CONNECTION_VERSION_TLS1_1: |
2390 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_1); | 2405 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_1); |
2391 break; | 2406 break; |
2392 case SSL_CONNECTION_VERSION_TLS1_2: | 2407 case SSL_CONNECTION_VERSION_TLS1_2: |
2393 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_2); | 2408 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_2); |
2394 break; | 2409 break; |
2395 }; | 2410 }; |
2396 } | 2411 } |
2397 | 2412 |
2398 } // namespace net | 2413 } // namespace net |
OLD | NEW |