| 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 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 bool SSLClientSocketNSS::Core::OnNetworkTaskRunner() const { | 1267 bool SSLClientSocketNSS::Core::OnNetworkTaskRunner() const { |
| 1268 return network_task_runner_->RunsTasksOnCurrentThread(); | 1268 return network_task_runner_->RunsTasksOnCurrentThread(); |
| 1269 } | 1269 } |
| 1270 | 1270 |
| 1271 // static | 1271 // static |
| 1272 SECStatus SSLClientSocketNSS::Core::OwnAuthCertHandler( | 1272 SECStatus SSLClientSocketNSS::Core::OwnAuthCertHandler( |
| 1273 void* arg, | 1273 void* arg, |
| 1274 PRFileDesc* socket, | 1274 PRFileDesc* socket, |
| 1275 PRBool checksig, | 1275 PRBool checksig, |
| 1276 PRBool is_server) { | 1276 PRBool is_server) { |
| 1277 #ifdef SSL_ENABLE_FALSE_START |
| 1277 Core* core = reinterpret_cast<Core*>(arg); | 1278 Core* core = reinterpret_cast<Core*>(arg); |
| 1278 if (!core->handshake_callback_called_) { | 1279 if (!core->handshake_callback_called_) { |
| 1279 // Only need to turn off False Start in the initial handshake. Also, it is | 1280 // Only need to turn off False Start in the initial handshake. Also, it is |
| 1280 // unsafe to call SSL_OptionSet in a renegotiation because the "first | 1281 // unsafe to call SSL_OptionSet in a renegotiation because the "first |
| 1281 // handshake" lock isn't already held, which will result in an assertion | 1282 // handshake" lock isn't already held, which will result in an assertion |
| 1282 // failure in the ssl_Get1stHandshakeLock call in SSL_OptionSet. | 1283 // failure in the ssl_Get1stHandshakeLock call in SSL_OptionSet. |
| 1283 PRBool npn; | 1284 PRBool npn; |
| 1284 SECStatus rv = SSL_HandshakeNegotiatedExtension(socket, | 1285 SECStatus rv = SSL_HandshakeNegotiatedExtension(socket, |
| 1285 ssl_next_proto_nego_xtn, | 1286 ssl_next_proto_nego_xtn, |
| 1286 &npn); | 1287 &npn); |
| 1287 if (rv != SECSuccess || !npn) { | 1288 if (rv != SECSuccess || !npn) { |
| 1288 // If the server doesn't support NPN, then we don't do False Start with | 1289 // If the server doesn't support NPN, then we don't do False Start with |
| 1289 // it. | 1290 // it. |
| 1290 SSL_OptionSet(socket, SSL_ENABLE_FALSE_START, PR_FALSE); | 1291 SSL_OptionSet(socket, SSL_ENABLE_FALSE_START, PR_FALSE); |
| 1291 } | 1292 } |
| 1292 } | 1293 } |
| 1294 #endif |
| 1293 | 1295 |
| 1294 // Tell NSS to not verify the certificate. | 1296 // Tell NSS to not verify the certificate. |
| 1295 return SECSuccess; | 1297 return SECSuccess; |
| 1296 } | 1298 } |
| 1297 | 1299 |
| 1298 #if defined(NSS_PLATFORM_CLIENT_AUTH) | 1300 #if defined(NSS_PLATFORM_CLIENT_AUTH) |
| 1299 // static | 1301 // static |
| 1300 SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler( | 1302 SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler( |
| 1301 void* arg, | 1303 void* arg, |
| 1302 PRFileDesc* socket, | 1304 PRFileDesc* socket, |
| (...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2410 nss_handshake_state_.ssl_connection_status |= | 2412 nss_handshake_state_.ssl_connection_status |= |
| 2411 (static_cast<int>(channel_info.cipherSuite) & | 2413 (static_cast<int>(channel_info.cipherSuite) & |
| 2412 SSL_CONNECTION_CIPHERSUITE_MASK) << | 2414 SSL_CONNECTION_CIPHERSUITE_MASK) << |
| 2413 SSL_CONNECTION_CIPHERSUITE_SHIFT; | 2415 SSL_CONNECTION_CIPHERSUITE_SHIFT; |
| 2414 | 2416 |
| 2415 nss_handshake_state_.ssl_connection_status |= | 2417 nss_handshake_state_.ssl_connection_status |= |
| 2416 (static_cast<int>(channel_info.compressionMethod) & | 2418 (static_cast<int>(channel_info.compressionMethod) & |
| 2417 SSL_CONNECTION_COMPRESSION_MASK) << | 2419 SSL_CONNECTION_COMPRESSION_MASK) << |
| 2418 SSL_CONNECTION_COMPRESSION_SHIFT; | 2420 SSL_CONNECTION_COMPRESSION_SHIFT; |
| 2419 | 2421 |
| 2420 // NSS 3.14.x doesn't have a version macro for TLS 1.2 (because NSS didn't | 2422 // NSS 3.12.x doesn't have version macros for TLS 1.1 and 1.2 (because NSS |
| 2421 // support it yet), so use 0x0303 directly. | 2423 // doesn't support them yet), so we use 0x0302 and 0x0303 directly. |
| 2422 int version = SSL_CONNECTION_VERSION_UNKNOWN; | 2424 int version = SSL_CONNECTION_VERSION_UNKNOWN; |
| 2423 if (channel_info.protocolVersion < SSL_LIBRARY_VERSION_3_0) { | 2425 if (channel_info.protocolVersion < SSL_LIBRARY_VERSION_3_0) { |
| 2424 // All versions less than SSL_LIBRARY_VERSION_3_0 are treated as SSL | 2426 // All versions less than SSL_LIBRARY_VERSION_3_0 are treated as SSL |
| 2425 // version 2. | 2427 // version 2. |
| 2426 version = SSL_CONNECTION_VERSION_SSL2; | 2428 version = SSL_CONNECTION_VERSION_SSL2; |
| 2427 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_0) { | 2429 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_0) { |
| 2428 version = SSL_CONNECTION_VERSION_SSL3; | 2430 version = SSL_CONNECTION_VERSION_SSL3; |
| 2429 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_1_TLS) { | 2431 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_1_TLS) { |
| 2430 version = SSL_CONNECTION_VERSION_TLS1; | 2432 version = SSL_CONNECTION_VERSION_TLS1; |
| 2431 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_TLS_1_1) { | 2433 } else if (channel_info.protocolVersion == 0x0302) { |
| 2432 version = SSL_CONNECTION_VERSION_TLS1_1; | 2434 version = SSL_CONNECTION_VERSION_TLS1_1; |
| 2433 } else if (channel_info.protocolVersion == 0x0303) { | 2435 } else if (channel_info.protocolVersion == 0x0303) { |
| 2434 version = SSL_CONNECTION_VERSION_TLS1_2; | 2436 version = SSL_CONNECTION_VERSION_TLS1_2; |
| 2435 } | 2437 } |
| 2436 nss_handshake_state_.ssl_connection_status |= | 2438 nss_handshake_state_.ssl_connection_status |= |
| 2437 (version & SSL_CONNECTION_VERSION_MASK) << | 2439 (version & SSL_CONNECTION_VERSION_MASK) << |
| 2438 SSL_CONNECTION_VERSION_SHIFT; | 2440 SSL_CONNECTION_VERSION_SHIFT; |
| 2439 } | 2441 } |
| 2440 | 2442 |
| 2443 // SSL_HandshakeNegotiatedExtension was added in NSS 3.12.6. |
| 2444 // Since SSL_MAX_EXTENSIONS was added at the same time, we can test |
| 2445 // SSL_MAX_EXTENSIONS for the presence of SSL_HandshakeNegotiatedExtension. |
| 2446 #if defined(SSL_MAX_EXTENSIONS) |
| 2441 PRBool peer_supports_renego_ext; | 2447 PRBool peer_supports_renego_ext; |
| 2442 ok = SSL_HandshakeNegotiatedExtension(nss_fd_, ssl_renegotiation_info_xtn, | 2448 ok = SSL_HandshakeNegotiatedExtension(nss_fd_, ssl_renegotiation_info_xtn, |
| 2443 &peer_supports_renego_ext); | 2449 &peer_supports_renego_ext); |
| 2444 if (ok == SECSuccess) { | 2450 if (ok == SECSuccess) { |
| 2445 if (!peer_supports_renego_ext) { | 2451 if (!peer_supports_renego_ext) { |
| 2446 nss_handshake_state_.ssl_connection_status |= | 2452 nss_handshake_state_.ssl_connection_status |= |
| 2447 SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION; | 2453 SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION; |
| 2448 // Log an informational message if the server does not support secure | 2454 // Log an informational message if the server does not support secure |
| 2449 // renegotiation (RFC 5746). | 2455 // renegotiation (RFC 5746). |
| 2450 VLOG(1) << "The server " << host_and_port_.ToString() | 2456 VLOG(1) << "The server " << host_and_port_.ToString() |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2464 // tools.ietf.org/html/draft-pettersen-tls-version-rollback-removal-00 . | 2470 // tools.ietf.org/html/draft-pettersen-tls-version-rollback-removal-00 . |
| 2465 // | 2471 // |
| 2466 // As a first step, measure how often clients perform version fallback | 2472 // As a first step, measure how often clients perform version fallback |
| 2467 // while the server advertises support secure renegotiation. | 2473 // while the server advertises support secure renegotiation. |
| 2468 if (ssl_config_.version_fallback && | 2474 if (ssl_config_.version_fallback && |
| 2469 channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_0) { | 2475 channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_0) { |
| 2470 UMA_HISTOGRAM_BOOLEAN("Net.SSLv3FallbackToRenegoPatchedServer", | 2476 UMA_HISTOGRAM_BOOLEAN("Net.SSLv3FallbackToRenegoPatchedServer", |
| 2471 peer_supports_renego_ext == PR_TRUE); | 2477 peer_supports_renego_ext == PR_TRUE); |
| 2472 } | 2478 } |
| 2473 } | 2479 } |
| 2480 #endif |
| 2474 | 2481 |
| 2475 if (ssl_config_.version_fallback) { | 2482 if (ssl_config_.version_fallback) { |
| 2476 nss_handshake_state_.ssl_connection_status |= | 2483 nss_handshake_state_.ssl_connection_status |= |
| 2477 SSL_CONNECTION_VERSION_FALLBACK; | 2484 SSL_CONNECTION_VERSION_FALLBACK; |
| 2478 } | 2485 } |
| 2479 } | 2486 } |
| 2480 | 2487 |
| 2481 void SSLClientSocketNSS::Core::UpdateNextProto() { | 2488 void SSLClientSocketNSS::Core::UpdateNextProto() { |
| 2482 uint8 buf[256]; | 2489 uint8 buf[256]; |
| 2483 SSLNextProtoState state; | 2490 SSLNextProtoState state; |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3139 } | 3146 } |
| 3140 | 3147 |
| 3141 for (std::vector<uint16>::const_iterator it = | 3148 for (std::vector<uint16>::const_iterator it = |
| 3142 ssl_config_.disabled_cipher_suites.begin(); | 3149 ssl_config_.disabled_cipher_suites.begin(); |
| 3143 it != ssl_config_.disabled_cipher_suites.end(); ++it) { | 3150 it != ssl_config_.disabled_cipher_suites.end(); ++it) { |
| 3144 // This will fail if the specified cipher is not implemented by NSS, but | 3151 // This will fail if the specified cipher is not implemented by NSS, but |
| 3145 // the failure is harmless. | 3152 // the failure is harmless. |
| 3146 SSL_CipherPrefSet(nss_fd_, *it, PR_FALSE); | 3153 SSL_CipherPrefSet(nss_fd_, *it, PR_FALSE); |
| 3147 } | 3154 } |
| 3148 | 3155 |
| 3156 #ifdef SSL_ENABLE_SESSION_TICKETS |
| 3149 // Support RFC 5077 | 3157 // Support RFC 5077 |
| 3150 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SESSION_TICKETS, PR_TRUE); | 3158 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SESSION_TICKETS, PR_TRUE); |
| 3151 if (rv != SECSuccess) { | 3159 if (rv != SECSuccess) { |
| 3152 LogFailedNSSFunction( | 3160 LogFailedNSSFunction( |
| 3153 net_log_, "SSL_OptionSet", "SSL_ENABLE_SESSION_TICKETS"); | 3161 net_log_, "SSL_OptionSet", "SSL_ENABLE_SESSION_TICKETS"); |
| 3154 } | 3162 } |
| 3163 #else |
| 3164 #error "You need to install NSS-3.12 or later to build chromium" |
| 3165 #endif |
| 3155 | 3166 |
| 3167 #ifdef SSL_ENABLE_FALSE_START |
| 3156 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_FALSE_START, | 3168 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_FALSE_START, |
| 3157 ssl_config_.false_start_enabled); | 3169 ssl_config_.false_start_enabled); |
| 3158 if (rv != SECSuccess) | 3170 if (rv != SECSuccess) |
| 3159 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_FALSE_START"); | 3171 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_FALSE_START"); |
| 3172 #endif |
| 3160 | 3173 |
| 3174 #ifdef SSL_ENABLE_RENEGOTIATION |
| 3161 // We allow servers to request renegotiation. Since we're a client, | 3175 // We allow servers to request renegotiation. Since we're a client, |
| 3162 // prohibiting this is rather a waste of time. Only servers are in a | 3176 // prohibiting this is rather a waste of time. Only servers are in a |
| 3163 // position to prevent renegotiation attacks. | 3177 // position to prevent renegotiation attacks. |
| 3164 // http://extendedsubset.com/?p=8 | 3178 // http://extendedsubset.com/?p=8 |
| 3165 | 3179 |
| 3166 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_RENEGOTIATION, | 3180 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_RENEGOTIATION, |
| 3167 SSL_RENEGOTIATE_TRANSITIONAL); | 3181 SSL_RENEGOTIATE_TRANSITIONAL); |
| 3168 if (rv != SECSuccess) { | 3182 if (rv != SECSuccess) { |
| 3169 LogFailedNSSFunction( | 3183 LogFailedNSSFunction( |
| 3170 net_log_, "SSL_OptionSet", "SSL_ENABLE_RENEGOTIATION"); | 3184 net_log_, "SSL_OptionSet", "SSL_ENABLE_RENEGOTIATION"); |
| 3171 } | 3185 } |
| 3186 #endif // SSL_ENABLE_RENEGOTIATION |
| 3172 | 3187 |
| 3188 #ifdef SSL_CBC_RANDOM_IV |
| 3173 rv = SSL_OptionSet(nss_fd_, SSL_CBC_RANDOM_IV, PR_TRUE); | 3189 rv = SSL_OptionSet(nss_fd_, SSL_CBC_RANDOM_IV, PR_TRUE); |
| 3174 if (rv != SECSuccess) | 3190 if (rv != SECSuccess) |
| 3175 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_CBC_RANDOM_IV"); | 3191 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_CBC_RANDOM_IV"); |
| 3192 #endif |
| 3176 | 3193 |
| 3177 // Added in NSS 3.15 | |
| 3178 #ifdef SSL_ENABLE_OCSP_STAPLING | 3194 #ifdef SSL_ENABLE_OCSP_STAPLING |
| 3179 if (IsOCSPStaplingSupported()) { | 3195 if (IsOCSPStaplingSupported()) { |
| 3180 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_OCSP_STAPLING, PR_TRUE); | 3196 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_OCSP_STAPLING, PR_TRUE); |
| 3181 if (rv != SECSuccess) { | 3197 if (rv != SECSuccess) { |
| 3182 LogFailedNSSFunction(net_log_, "SSL_OptionSet", | 3198 LogFailedNSSFunction(net_log_, "SSL_OptionSet", |
| 3183 "SSL_ENABLE_OCSP_STAPLING"); | 3199 "SSL_ENABLE_OCSP_STAPLING"); |
| 3184 } | 3200 } |
| 3185 } | 3201 } |
| 3186 #endif | 3202 #endif |
| 3187 | 3203 |
| 3188 // Chromium patch to libssl | |
| 3189 #ifdef SSL_ENABLE_CACHED_INFO | 3204 #ifdef SSL_ENABLE_CACHED_INFO |
| 3190 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_CACHED_INFO, | 3205 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_CACHED_INFO, |
| 3191 ssl_config_.cached_info_enabled); | 3206 ssl_config_.cached_info_enabled); |
| 3192 if (rv != SECSuccess) | 3207 if (rv != SECSuccess) |
| 3193 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_CACHED_INFO"); | 3208 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_CACHED_INFO"); |
| 3194 #endif | 3209 #endif |
| 3195 | 3210 |
| 3196 rv = SSL_OptionSet(nss_fd_, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE); | 3211 rv = SSL_OptionSet(nss_fd_, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE); |
| 3197 if (rv != SECSuccess) { | 3212 if (rv != SECSuccess) { |
| 3198 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_HANDSHAKE_AS_CLIENT"); | 3213 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_HANDSHAKE_AS_CLIENT"); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3505 EnsureThreadIdAssigned(); | 3520 EnsureThreadIdAssigned(); |
| 3506 base::AutoLock auto_lock(lock_); | 3521 base::AutoLock auto_lock(lock_); |
| 3507 return valid_thread_id_ == base::PlatformThread::CurrentId(); | 3522 return valid_thread_id_ == base::PlatformThread::CurrentId(); |
| 3508 } | 3523 } |
| 3509 | 3524 |
| 3510 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { | 3525 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { |
| 3511 return server_bound_cert_service_; | 3526 return server_bound_cert_service_; |
| 3512 } | 3527 } |
| 3513 | 3528 |
| 3514 } // namespace net | 3529 } // namespace net |
| OLD | NEW |