| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 #include <secerr.h> | 56 #include <secerr.h> |
| 57 #include <sechash.h> | 57 #include <sechash.h> |
| 58 #include <ssl.h> | 58 #include <ssl.h> |
| 59 #include <sslerr.h> | 59 #include <sslerr.h> |
| 60 #include <sslproto.h> | 60 #include <sslproto.h> |
| 61 | 61 |
| 62 #include <limits> | 62 #include <limits> |
| 63 | 63 |
| 64 #include "base/compiler_specific.h" | 64 #include "base/compiler_specific.h" |
| 65 #include "base/metrics/histogram.h" | 65 #include "base/metrics/histogram.h" |
| 66 #include "base/lazy_instance.h" | |
| 67 #include "base/logging.h" | 66 #include "base/logging.h" |
| 68 #include "base/nss_util.h" | 67 #include "base/nss_util.h" |
| 69 #include "base/string_number_conversions.h" | 68 #include "base/string_number_conversions.h" |
| 70 #include "base/string_util.h" | 69 #include "base/string_util.h" |
| 71 #include "base/stringprintf.h" | 70 #include "base/stringprintf.h" |
| 72 #include "base/thread_restrictions.h" | 71 #include "base/thread_restrictions.h" |
| 73 #include "base/values.h" | 72 #include "base/values.h" |
| 74 #include "net/base/address_list.h" | 73 #include "net/base/address_list.h" |
| 75 #include "net/base/cert_status_flags.h" | 74 #include "net/base/cert_status_flags.h" |
| 76 #include "net/base/cert_verifier.h" | 75 #include "net/base/cert_verifier.h" |
| 77 #include "net/base/connection_type_histograms.h" | 76 #include "net/base/connection_type_histograms.h" |
| 78 #include "net/base/dns_util.h" | 77 #include "net/base/dns_util.h" |
| 79 #include "net/base/dnsrr_resolver.h" | 78 #include "net/base/dnsrr_resolver.h" |
| 80 #include "net/base/dnssec_chain_verifier.h" | 79 #include "net/base/dnssec_chain_verifier.h" |
| 81 #include "net/base/io_buffer.h" | 80 #include "net/base/io_buffer.h" |
| 82 #include "net/base/net_errors.h" | 81 #include "net/base/net_errors.h" |
| 83 #include "net/base/net_log.h" | 82 #include "net/base/net_log.h" |
| 84 #include "net/base/ssl_cert_request_info.h" | 83 #include "net/base/ssl_cert_request_info.h" |
| 85 #include "net/base/ssl_connection_status_flags.h" | 84 #include "net/base/ssl_connection_status_flags.h" |
| 86 #include "net/base/ssl_info.h" | 85 #include "net/base/ssl_info.h" |
| 87 #include "net/base/sys_addrinfo.h" | 86 #include "net/base/sys_addrinfo.h" |
| 88 #include "net/ocsp/nss_ocsp.h" | 87 #include "net/ocsp/nss_ocsp.h" |
| 89 #include "net/socket/client_socket_handle.h" | 88 #include "net/socket/client_socket_handle.h" |
| 90 #include "net/socket/dns_cert_provenance_checker.h" | 89 #include "net/socket/dns_cert_provenance_checker.h" |
| 90 #include "net/socket/nss_ssl_util.h" |
| 91 #include "net/socket/ssl_error_params.h" | 91 #include "net/socket/ssl_error_params.h" |
| 92 #include "net/socket/ssl_host_info.h" | 92 #include "net/socket/ssl_host_info.h" |
| 93 | 93 |
| 94 #if defined(USE_SYSTEM_SSL) | 94 #if defined(USE_SYSTEM_SSL) |
| 95 #include <dlfcn.h> | 95 #include <dlfcn.h> |
| 96 #endif | 96 #endif |
| 97 #if defined(OS_WIN) | 97 #if defined(OS_WIN) |
| 98 #include <windows.h> | 98 #include <windows.h> |
| 99 #include <wincrypt.h> | 99 #include <wincrypt.h> |
| 100 #elif defined(OS_MACOSX) | 100 #elif defined(OS_MACOSX) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 VLOG(1) << (void *)this << " " << __FUNCTION__ << " jump to state " << s;\ | 132 VLOG(1) << (void *)this << " " << __FUNCTION__ << " jump to state " << s;\ |
| 133 next_handshake_state_ = s;\ | 133 next_handshake_state_ = s;\ |
| 134 } while (0) | 134 } while (0) |
| 135 #define LogData(s, len)\ | 135 #define LogData(s, len)\ |
| 136 VLOG(1) << (void *)this << " " << __FUNCTION__\ | 136 VLOG(1) << (void *)this << " " << __FUNCTION__\ |
| 137 << " data [" << std::string(s, len) << "]" | 137 << " data [" << std::string(s, len) << "]" |
| 138 #endif | 138 #endif |
| 139 | 139 |
| 140 namespace { | 140 namespace { |
| 141 | 141 |
| 142 class NSSSSLInitSingleton { | |
| 143 public: | |
| 144 NSSSSLInitSingleton() { | |
| 145 base::EnsureNSSInit(); | |
| 146 | |
| 147 NSS_SetDomesticPolicy(); | |
| 148 | |
| 149 #if defined(USE_SYSTEM_SSL) | |
| 150 // Use late binding to avoid scary but benign warning | |
| 151 // "Symbol `SSL_ImplementedCiphers' has different size in shared object, | |
| 152 // consider re-linking" | |
| 153 // TODO(wtc): Use the new SSL_GetImplementedCiphers and | |
| 154 // SSL_GetNumImplementedCiphers functions when we require NSS 3.12.6. | |
| 155 // See https://bugzilla.mozilla.org/show_bug.cgi?id=496993. | |
| 156 const PRUint16* pSSL_ImplementedCiphers = static_cast<const PRUint16*>( | |
| 157 dlsym(RTLD_DEFAULT, "SSL_ImplementedCiphers")); | |
| 158 if (pSSL_ImplementedCiphers == NULL) { | |
| 159 NOTREACHED() << "Can't get list of supported ciphers"; | |
| 160 return; | |
| 161 } | |
| 162 #else | |
| 163 #define pSSL_ImplementedCiphers SSL_ImplementedCiphers | |
| 164 #endif | |
| 165 | |
| 166 // Explicitly enable exactly those ciphers with keys of at least 80 bits | |
| 167 for (int i = 0; i < SSL_NumImplementedCiphers; i++) { | |
| 168 SSLCipherSuiteInfo info; | |
| 169 if (SSL_GetCipherSuiteInfo(pSSL_ImplementedCiphers[i], &info, | |
| 170 sizeof(info)) == SECSuccess) { | |
| 171 SSL_CipherPrefSetDefault(pSSL_ImplementedCiphers[i], | |
| 172 (info.effectiveKeyBits >= 80)); | |
| 173 } | |
| 174 } | |
| 175 | |
| 176 // Enable SSL. | |
| 177 SSL_OptionSetDefault(SSL_SECURITY, PR_TRUE); | |
| 178 | |
| 179 // All other SSL options are set per-session by SSLClientSocket. | |
| 180 } | |
| 181 | |
| 182 ~NSSSSLInitSingleton() { | |
| 183 // Have to clear the cache, or NSS_Shutdown fails with SEC_ERROR_BUSY. | |
| 184 SSL_ClearSessionCache(); | |
| 185 } | |
| 186 }; | |
| 187 | |
| 188 static base::LazyInstance<NSSSSLInitSingleton> g_nss_ssl_init_singleton( | |
| 189 base::LINKER_INITIALIZED); | |
| 190 | |
| 191 // Initialize the NSS SSL library if it isn't already initialized. This must | |
| 192 // be called before any other NSS SSL functions. This function is | |
| 193 // thread-safe, and the NSS SSL library will only ever be initialized once. | |
| 194 // The NSS SSL library will be properly shut down on program exit. | |
| 195 void EnsureNSSSSLInit() { | |
| 196 // Initializing SSL causes us to do blocking IO. | |
| 197 // Temporarily allow it until we fix | |
| 198 // http://code.google.com/p/chromium/issues/detail?id=59847 | |
| 199 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 200 | |
| 201 g_nss_ssl_init_singleton.Get(); | |
| 202 } | |
| 203 | |
| 204 // The default error mapping function. | |
| 205 // Maps an NSPR error code to a network error code. | |
| 206 int MapNSPRError(PRErrorCode err) { | |
| 207 // TODO(port): fill this out as we learn what's important | |
| 208 switch (err) { | |
| 209 case PR_WOULD_BLOCK_ERROR: | |
| 210 return ERR_IO_PENDING; | |
| 211 case PR_ADDRESS_NOT_SUPPORTED_ERROR: // For connect. | |
| 212 case PR_NO_ACCESS_RIGHTS_ERROR: | |
| 213 return ERR_ACCESS_DENIED; | |
| 214 case PR_IO_TIMEOUT_ERROR: | |
| 215 return ERR_TIMED_OUT; | |
| 216 case PR_CONNECT_RESET_ERROR: | |
| 217 return ERR_CONNECTION_RESET; | |
| 218 case PR_CONNECT_ABORTED_ERROR: | |
| 219 return ERR_CONNECTION_ABORTED; | |
| 220 case PR_CONNECT_REFUSED_ERROR: | |
| 221 return ERR_CONNECTION_REFUSED; | |
| 222 case PR_HOST_UNREACHABLE_ERROR: | |
| 223 case PR_NETWORK_UNREACHABLE_ERROR: | |
| 224 return ERR_ADDRESS_UNREACHABLE; | |
| 225 case PR_ADDRESS_NOT_AVAILABLE_ERROR: | |
| 226 return ERR_ADDRESS_INVALID; | |
| 227 case PR_INVALID_ARGUMENT_ERROR: | |
| 228 return ERR_INVALID_ARGUMENT; | |
| 229 case PR_END_OF_FILE_ERROR: | |
| 230 return ERR_CONNECTION_CLOSED; | |
| 231 case PR_NOT_IMPLEMENTED_ERROR: | |
| 232 return ERR_NOT_IMPLEMENTED; | |
| 233 | |
| 234 case SEC_ERROR_INVALID_ARGS: | |
| 235 return ERR_INVALID_ARGUMENT; | |
| 236 | |
| 237 case SSL_ERROR_SSL_DISABLED: | |
| 238 return ERR_NO_SSL_VERSIONS_ENABLED; | |
| 239 case SSL_ERROR_NO_CYPHER_OVERLAP: | |
| 240 case SSL_ERROR_UNSUPPORTED_VERSION: | |
| 241 return ERR_SSL_VERSION_OR_CIPHER_MISMATCH; | |
| 242 case SSL_ERROR_HANDSHAKE_FAILURE_ALERT: | |
| 243 case SSL_ERROR_HANDSHAKE_UNEXPECTED_ALERT: | |
| 244 case SSL_ERROR_ILLEGAL_PARAMETER_ALERT: | |
| 245 return ERR_SSL_PROTOCOL_ERROR; | |
| 246 case SSL_ERROR_DECOMPRESSION_FAILURE_ALERT: | |
| 247 return ERR_SSL_DECOMPRESSION_FAILURE_ALERT; | |
| 248 case SSL_ERROR_BAD_MAC_ALERT: | |
| 249 return ERR_SSL_BAD_RECORD_MAC_ALERT; | |
| 250 case SSL_ERROR_UNSAFE_NEGOTIATION: | |
| 251 return ERR_SSL_UNSAFE_NEGOTIATION; | |
| 252 case SSL_ERROR_WEAK_SERVER_KEY: | |
| 253 return ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY; | |
| 254 | |
| 255 default: { | |
| 256 if (IS_SSL_ERROR(err)) { | |
| 257 LOG(WARNING) << "Unknown SSL error " << err << | |
| 258 " mapped to net::ERR_SSL_PROTOCOL_ERROR"; | |
| 259 return ERR_SSL_PROTOCOL_ERROR; | |
| 260 } | |
| 261 LOG(WARNING) << "Unknown error " << err << | |
| 262 " mapped to net::ERR_FAILED"; | |
| 263 return ERR_FAILED; | |
| 264 } | |
| 265 } | |
| 266 } | |
| 267 | |
| 268 // Context-sensitive error mapping functions. | |
| 269 | |
| 270 int MapHandshakeError(PRErrorCode err) { | |
| 271 switch (err) { | |
| 272 // If the server closed on us, it is a protocol error. | |
| 273 // Some TLS-intolerant servers do this when we request TLS. | |
| 274 case PR_END_OF_FILE_ERROR: | |
| 275 // The handshake may fail because some signature (for example, the | |
| 276 // signature in the ServerKeyExchange message for an ephemeral | |
| 277 // Diffie-Hellman cipher suite) is invalid. | |
| 278 case SEC_ERROR_BAD_SIGNATURE: | |
| 279 return ERR_SSL_PROTOCOL_ERROR; | |
| 280 default: | |
| 281 return MapNSPRError(err); | |
| 282 } | |
| 283 } | |
| 284 | |
| 285 // Extra parameters to attach to the NetLog when we receive an error in response | |
| 286 // to a call to an NSS function. Used instead of SSLErrorParams with | |
| 287 // events of type TYPE_SSL_NSS_ERROR. Automatically looks up last PR error. | |
| 288 class SSLFailedNSSFunctionParams : public NetLog::EventParameters { | |
| 289 public: | |
| 290 // |param| is ignored if it has a length of 0. | |
| 291 SSLFailedNSSFunctionParams(const std::string& function, | |
| 292 const std::string& param) | |
| 293 : function_(function), param_(param), ssl_lib_error_(PR_GetError()) { | |
| 294 } | |
| 295 | |
| 296 virtual Value* ToValue() const { | |
| 297 DictionaryValue* dict = new DictionaryValue(); | |
| 298 dict->SetString("function", function_); | |
| 299 if (!param_.empty()) | |
| 300 dict->SetString("param", param_); | |
| 301 dict->SetInteger("ssl_lib_error", ssl_lib_error_); | |
| 302 return dict; | |
| 303 } | |
| 304 | |
| 305 private: | |
| 306 const std::string function_; | |
| 307 const std::string param_; | |
| 308 const PRErrorCode ssl_lib_error_; | |
| 309 }; | |
| 310 | |
| 311 void LogFailedNSSFunction(const BoundNetLog& net_log, | |
| 312 const char* function, | |
| 313 const char* param) { | |
| 314 net_log.AddEvent( | |
| 315 NetLog::TYPE_SSL_NSS_ERROR, | |
| 316 make_scoped_refptr(new SSLFailedNSSFunctionParams(function, param))); | |
| 317 } | |
| 318 | |
| 319 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
| 320 | 143 |
| 321 // This callback is intended to be used with CertFindChainInStore. In addition | 144 // This callback is intended to be used with CertFindChainInStore. In addition |
| 322 // to filtering by extended/enhanced key usage, we do not show expired | 145 // to filtering by extended/enhanced key usage, we do not show expired |
| 323 // certificates and require digital signature usage in the key usage | 146 // certificates and require digital signature usage in the key usage |
| 324 // extension. | 147 // extension. |
| 325 // | 148 // |
| 326 // This matches our behavior on Mac OS X and that of NSS. It also matches the | 149 // This matches our behavior on Mac OS X and that of NSS. It also matches the |
| 327 // default behavior of IE8. See http://support.microsoft.com/kb/890326 and | 150 // default behavior of IE8. See http://support.microsoft.com/kb/890326 and |
| 328 // http://blogs.msdn.com/b/askie/archive/2009/06/09/my-expired-client-certificat
es-no-longer-display-when-connecting-to-my-web-server-using-ie8.aspx | 151 // http://blogs.msdn.com/b/askie/archive/2009/06/09/my-expired-client-certificat
es-no-longer-display-when-connecting-to-my-web-server-using-ie8.aspx |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 // Support RFC 5077 | 552 // Support RFC 5077 |
| 730 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SESSION_TICKETS, PR_TRUE); | 553 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SESSION_TICKETS, PR_TRUE); |
| 731 if (rv != SECSuccess) { | 554 if (rv != SECSuccess) { |
| 732 LogFailedNSSFunction( | 555 LogFailedNSSFunction( |
| 733 net_log_, "SSL_OptionSet", "SSL_ENABLE_SESSION_TICKETS"); | 556 net_log_, "SSL_OptionSet", "SSL_ENABLE_SESSION_TICKETS"); |
| 734 } | 557 } |
| 735 #else | 558 #else |
| 736 #error "You need to install NSS-3.12 or later to build chromium" | 559 #error "You need to install NSS-3.12 or later to build chromium" |
| 737 #endif | 560 #endif |
| 738 | 561 |
| 562 rv = SSL_OptionSet(nss_fd_, SSL_NO_CACHE, |
| 563 ssl_config_.session_resume_disabled); |
| 564 if (rv != SECSuccess) { |
| 565 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_NO_CACHE"); |
| 566 return ERR_UNEXPECTED; |
| 567 } |
| 568 |
| 739 #ifdef SSL_ENABLE_DEFLATE | 569 #ifdef SSL_ENABLE_DEFLATE |
| 740 // Some web servers have been found to break if TLS is used *or* if DEFLATE | 570 // Some web servers have been found to break if TLS is used *or* if DEFLATE |
| 741 // is advertised. Thus, if TLS is disabled (probably because we are doing | 571 // is advertised. Thus, if TLS is disabled (probably because we are doing |
| 742 // SSLv3 fallback), we disable DEFLATE also. | 572 // SSLv3 fallback), we disable DEFLATE also. |
| 743 // See http://crbug.com/31628 | 573 // See http://crbug.com/31628 |
| 744 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_DEFLATE, ssl_config_.tls1_enabled); | 574 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_DEFLATE, ssl_config_.tls1_enabled); |
| 745 if (rv != SECSuccess) | 575 if (rv != SECSuccess) |
| 746 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_DEFLATE"); | 576 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_DEFLATE"); |
| 747 #endif | 577 #endif |
| 748 | 578 |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 LeaveFunction(""); | 1186 LeaveFunction(""); |
| 1357 return; | 1187 return; |
| 1358 } | 1188 } |
| 1359 | 1189 |
| 1360 int rv = DoReadLoop(result); | 1190 int rv = DoReadLoop(result); |
| 1361 if (rv != ERR_IO_PENDING) | 1191 if (rv != ERR_IO_PENDING) |
| 1362 DoReadCallback(rv); | 1192 DoReadCallback(rv); |
| 1363 LeaveFunction(""); | 1193 LeaveFunction(""); |
| 1364 } | 1194 } |
| 1365 | 1195 |
| 1366 // Map a Chromium net error code to an NSS error code. | |
| 1367 // See _MD_unix_map_default_error in the NSS source | |
| 1368 // tree for inspiration. | |
| 1369 static PRErrorCode MapErrorToNSS(int result) { | |
| 1370 if (result >=0) | |
| 1371 return result; | |
| 1372 | |
| 1373 switch (result) { | |
| 1374 case ERR_IO_PENDING: | |
| 1375 return PR_WOULD_BLOCK_ERROR; | |
| 1376 case ERR_ACCESS_DENIED: | |
| 1377 case ERR_NETWORK_ACCESS_DENIED: | |
| 1378 // For connect, this could be mapped to PR_ADDRESS_NOT_SUPPORTED_ERROR. | |
| 1379 return PR_NO_ACCESS_RIGHTS_ERROR; | |
| 1380 case ERR_NOT_IMPLEMENTED: | |
| 1381 return PR_NOT_IMPLEMENTED_ERROR; | |
| 1382 case ERR_INTERNET_DISCONNECTED: // Equivalent to ENETDOWN. | |
| 1383 return PR_NETWORK_UNREACHABLE_ERROR; // Best approximation. | |
| 1384 case ERR_CONNECTION_TIMED_OUT: | |
| 1385 case ERR_TIMED_OUT: | |
| 1386 return PR_IO_TIMEOUT_ERROR; | |
| 1387 case ERR_CONNECTION_RESET: | |
| 1388 return PR_CONNECT_RESET_ERROR; | |
| 1389 case ERR_CONNECTION_ABORTED: | |
| 1390 return PR_CONNECT_ABORTED_ERROR; | |
| 1391 case ERR_CONNECTION_REFUSED: | |
| 1392 return PR_CONNECT_REFUSED_ERROR; | |
| 1393 case ERR_ADDRESS_UNREACHABLE: | |
| 1394 return PR_HOST_UNREACHABLE_ERROR; // Also PR_NETWORK_UNREACHABLE_ERROR. | |
| 1395 case ERR_ADDRESS_INVALID: | |
| 1396 return PR_ADDRESS_NOT_AVAILABLE_ERROR; | |
| 1397 case ERR_NAME_NOT_RESOLVED: | |
| 1398 return PR_DIRECTORY_LOOKUP_ERROR; | |
| 1399 default: | |
| 1400 LOG(WARNING) << "MapErrorToNSS " << result | |
| 1401 << " mapped to PR_UNKNOWN_ERROR"; | |
| 1402 return PR_UNKNOWN_ERROR; | |
| 1403 } | |
| 1404 } | |
| 1405 | |
| 1406 // Do network I/O between the given buffer and the given socket. | 1196 // Do network I/O between the given buffer and the given socket. |
| 1407 // Return true if some I/O performed, false otherwise (error or ERR_IO_PENDING) | 1197 // Return true if some I/O performed, false otherwise (error or ERR_IO_PENDING) |
| 1408 bool SSLClientSocketNSS::DoTransportIO() { | 1198 bool SSLClientSocketNSS::DoTransportIO() { |
| 1409 EnterFunction(""); | 1199 EnterFunction(""); |
| 1410 bool network_moved = false; | 1200 bool network_moved = false; |
| 1411 if (nss_bufs_ != NULL) { | 1201 if (nss_bufs_ != NULL) { |
| 1412 int nsent = BufferSend(); | 1202 int nsent = BufferSend(); |
| 1413 int nreceived = BufferRecv(); | 1203 int nreceived = BufferRecv(); |
| 1414 network_moved = (nsent > 0 || nreceived >= 0); | 1204 network_moved = (nsent > 0 || nreceived >= 0); |
| 1415 } | 1205 } |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2184 } else { | 1974 } else { |
| 2185 // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=562434 - | 1975 // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=562434 - |
| 2186 // SSL_ForceHandshake returned SECSuccess prematurely. | 1976 // SSL_ForceHandshake returned SECSuccess prematurely. |
| 2187 rv = SECFailure; | 1977 rv = SECFailure; |
| 2188 net_error = ERR_SSL_PROTOCOL_ERROR; | 1978 net_error = ERR_SSL_PROTOCOL_ERROR; |
| 2189 net_log_.AddEvent(NetLog::TYPE_SSL_HANDSHAKE_ERROR, | 1979 net_log_.AddEvent(NetLog::TYPE_SSL_HANDSHAKE_ERROR, |
| 2190 make_scoped_refptr(new SSLErrorParams(net_error, 0))); | 1980 make_scoped_refptr(new SSLErrorParams(net_error, 0))); |
| 2191 } | 1981 } |
| 2192 } else { | 1982 } else { |
| 2193 PRErrorCode prerr = PR_GetError(); | 1983 PRErrorCode prerr = PR_GetError(); |
| 2194 net_error = MapHandshakeError(prerr); | 1984 net_error = MapNSSHandshakeError(prerr); |
| 2195 | 1985 |
| 2196 // If not done, stay in this state | 1986 // If not done, stay in this state |
| 2197 if (net_error == ERR_IO_PENDING) { | 1987 if (net_error == ERR_IO_PENDING) { |
| 2198 GotoState(STATE_HANDSHAKE); | 1988 GotoState(STATE_HANDSHAKE); |
| 2199 } else { | 1989 } else { |
| 2200 LOG(ERROR) << "handshake failed; NSS error code " << prerr | 1990 LOG(ERROR) << "handshake failed; NSS error code " << prerr |
| 2201 << ", net_error " << net_error; | 1991 << ", net_error " << net_error; |
| 2202 net_log_.AddEvent( | 1992 net_log_.AddEvent( |
| 2203 NetLog::TYPE_SSL_HANDSHAKE_ERROR, | 1993 NetLog::TYPE_SSL_HANDSHAKE_ERROR, |
| 2204 make_scoped_refptr(new SSLErrorParams(net_error, prerr))); | 1994 make_scoped_refptr(new SSLErrorParams(net_error, prerr))); |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2573 LogData(user_read_buf_->data(), rv); | 2363 LogData(user_read_buf_->data(), rv); |
| 2574 LeaveFunction(""); | 2364 LeaveFunction(""); |
| 2575 return rv; | 2365 return rv; |
| 2576 } | 2366 } |
| 2577 PRErrorCode prerr = PR_GetError(); | 2367 PRErrorCode prerr = PR_GetError(); |
| 2578 if (prerr == PR_WOULD_BLOCK_ERROR) { | 2368 if (prerr == PR_WOULD_BLOCK_ERROR) { |
| 2579 LeaveFunction(""); | 2369 LeaveFunction(""); |
| 2580 return ERR_IO_PENDING; | 2370 return ERR_IO_PENDING; |
| 2581 } | 2371 } |
| 2582 LeaveFunction(""); | 2372 LeaveFunction(""); |
| 2583 rv = MapNSPRError(prerr); | 2373 rv = MapNSSError(prerr); |
| 2584 net_log_.AddEvent(NetLog::TYPE_SSL_READ_ERROR, | 2374 net_log_.AddEvent(NetLog::TYPE_SSL_READ_ERROR, |
| 2585 make_scoped_refptr(new SSLErrorParams(rv, prerr))); | 2375 make_scoped_refptr(new SSLErrorParams(rv, prerr))); |
| 2586 return rv; | 2376 return rv; |
| 2587 } | 2377 } |
| 2588 | 2378 |
| 2589 int SSLClientSocketNSS::DoPayloadWrite() { | 2379 int SSLClientSocketNSS::DoPayloadWrite() { |
| 2590 EnterFunction(user_write_buf_len_); | 2380 EnterFunction(user_write_buf_len_); |
| 2591 DCHECK(user_write_buf_); | 2381 DCHECK(user_write_buf_); |
| 2592 int rv = PR_Write(nss_fd_, user_write_buf_->data(), user_write_buf_len_); | 2382 int rv = PR_Write(nss_fd_, user_write_buf_->data(), user_write_buf_len_); |
| 2593 if (rv >= 0) { | 2383 if (rv >= 0) { |
| 2594 LogData(user_write_buf_->data(), rv); | 2384 LogData(user_write_buf_->data(), rv); |
| 2595 LeaveFunction(""); | 2385 LeaveFunction(""); |
| 2596 return rv; | 2386 return rv; |
| 2597 } | 2387 } |
| 2598 PRErrorCode prerr = PR_GetError(); | 2388 PRErrorCode prerr = PR_GetError(); |
| 2599 if (prerr == PR_WOULD_BLOCK_ERROR) { | 2389 if (prerr == PR_WOULD_BLOCK_ERROR) { |
| 2600 LeaveFunction(""); | 2390 LeaveFunction(""); |
| 2601 return ERR_IO_PENDING; | 2391 return ERR_IO_PENDING; |
| 2602 } | 2392 } |
| 2603 LeaveFunction(""); | 2393 LeaveFunction(""); |
| 2604 rv = MapNSPRError(prerr); | 2394 rv = MapNSSError(prerr); |
| 2605 net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR, | 2395 net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR, |
| 2606 make_scoped_refptr(new SSLErrorParams(rv, prerr))); | 2396 make_scoped_refptr(new SSLErrorParams(rv, prerr))); |
| 2607 return rv; | 2397 return rv; |
| 2608 } | 2398 } |
| 2609 | 2399 |
| 2610 void SSLClientSocketNSS::LogConnectionTypeMetrics() const { | 2400 void SSLClientSocketNSS::LogConnectionTypeMetrics() const { |
| 2611 UpdateConnectionTypeHistograms(CONNECTION_SSL); | 2401 UpdateConnectionTypeHistograms(CONNECTION_SSL); |
| 2612 if (server_cert_verify_result_->has_md5) | 2402 if (server_cert_verify_result_->has_md5) |
| 2613 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD5); | 2403 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD5); |
| 2614 if (server_cert_verify_result_->has_md2) | 2404 if (server_cert_verify_result_->has_md2) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2633 case SSL_CONNECTION_VERSION_TLS1_1: | 2423 case SSL_CONNECTION_VERSION_TLS1_1: |
| 2634 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_1); | 2424 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_1); |
| 2635 break; | 2425 break; |
| 2636 case SSL_CONNECTION_VERSION_TLS1_2: | 2426 case SSL_CONNECTION_VERSION_TLS1_2: |
| 2637 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_2); | 2427 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_2); |
| 2638 break; | 2428 break; |
| 2639 }; | 2429 }; |
| 2640 } | 2430 } |
| 2641 | 2431 |
| 2642 } // namespace net | 2432 } // namespace net |
| OLD | NEW |