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 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 bool SSLClientSocketNSS::Core::OnNetworkTaskRunner() const { | 1255 bool SSLClientSocketNSS::Core::OnNetworkTaskRunner() const { |
1256 return network_task_runner_->RunsTasksOnCurrentThread(); | 1256 return network_task_runner_->RunsTasksOnCurrentThread(); |
1257 } | 1257 } |
1258 | 1258 |
1259 // static | 1259 // static |
1260 SECStatus SSLClientSocketNSS::Core::OwnAuthCertHandler( | 1260 SECStatus SSLClientSocketNSS::Core::OwnAuthCertHandler( |
1261 void* arg, | 1261 void* arg, |
1262 PRFileDesc* socket, | 1262 PRFileDesc* socket, |
1263 PRBool checksig, | 1263 PRBool checksig, |
1264 PRBool is_server) { | 1264 PRBool is_server) { |
1265 #ifdef SSL_ENABLE_FALSE_START | |
1266 Core* core = reinterpret_cast<Core*>(arg); | 1265 Core* core = reinterpret_cast<Core*>(arg); |
1267 if (!core->handshake_callback_called_) { | 1266 if (!core->handshake_callback_called_) { |
1268 // Only need to turn off False Start in the initial handshake. Also, it is | 1267 // Only need to turn off False Start in the initial handshake. Also, it is |
1269 // unsafe to call SSL_OptionSet in a renegotiation because the "first | 1268 // unsafe to call SSL_OptionSet in a renegotiation because the "first |
1270 // handshake" lock isn't already held, which will result in an assertion | 1269 // handshake" lock isn't already held, which will result in an assertion |
1271 // failure in the ssl_Get1stHandshakeLock call in SSL_OptionSet. | 1270 // failure in the ssl_Get1stHandshakeLock call in SSL_OptionSet. |
1272 PRBool npn; | 1271 PRBool npn; |
1273 SECStatus rv = SSL_HandshakeNegotiatedExtension(socket, | 1272 SECStatus rv = SSL_HandshakeNegotiatedExtension(socket, |
1274 ssl_next_proto_nego_xtn, | 1273 ssl_next_proto_nego_xtn, |
1275 &npn); | 1274 &npn); |
1276 if (rv != SECSuccess || !npn) { | 1275 if (rv != SECSuccess || !npn) { |
1277 // If the server doesn't support NPN, then we don't do False Start with | 1276 // If the server doesn't support NPN, then we don't do False Start with |
1278 // it. | 1277 // it. |
1279 SSL_OptionSet(socket, SSL_ENABLE_FALSE_START, PR_FALSE); | 1278 SSL_OptionSet(socket, SSL_ENABLE_FALSE_START, PR_FALSE); |
1280 } | 1279 } |
1281 } | 1280 } |
1282 #endif | |
1283 | 1281 |
1284 // Tell NSS to not verify the certificate. | 1282 // Tell NSS to not verify the certificate. |
1285 return SECSuccess; | 1283 return SECSuccess; |
1286 } | 1284 } |
1287 | 1285 |
1288 #if defined(NSS_PLATFORM_CLIENT_AUTH) | 1286 #if defined(NSS_PLATFORM_CLIENT_AUTH) |
1289 // static | 1287 // static |
1290 SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler( | 1288 SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler( |
1291 void* arg, | 1289 void* arg, |
1292 PRFileDesc* socket, | 1290 PRFileDesc* socket, |
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2466 nss_handshake_state_.ssl_connection_status |= | 2464 nss_handshake_state_.ssl_connection_status |= |
2467 (static_cast<int>(channel_info.cipherSuite) & | 2465 (static_cast<int>(channel_info.cipherSuite) & |
2468 SSL_CONNECTION_CIPHERSUITE_MASK) << | 2466 SSL_CONNECTION_CIPHERSUITE_MASK) << |
2469 SSL_CONNECTION_CIPHERSUITE_SHIFT; | 2467 SSL_CONNECTION_CIPHERSUITE_SHIFT; |
2470 | 2468 |
2471 nss_handshake_state_.ssl_connection_status |= | 2469 nss_handshake_state_.ssl_connection_status |= |
2472 (static_cast<int>(channel_info.compressionMethod) & | 2470 (static_cast<int>(channel_info.compressionMethod) & |
2473 SSL_CONNECTION_COMPRESSION_MASK) << | 2471 SSL_CONNECTION_COMPRESSION_MASK) << |
2474 SSL_CONNECTION_COMPRESSION_SHIFT; | 2472 SSL_CONNECTION_COMPRESSION_SHIFT; |
2475 | 2473 |
2476 // NSS 3.12.x doesn't have version macros for TLS 1.1 and 1.2 (because NSS | 2474 // NSS 3.14.x doesn't have a version macro for TLS 1.2 (because NSS didn't |
2477 // doesn't support them yet), so we use 0x0302 and 0x0303 directly. | 2475 // support it yet), so use 0x0303 directly. |
2478 int version = SSL_CONNECTION_VERSION_UNKNOWN; | 2476 int version = SSL_CONNECTION_VERSION_UNKNOWN; |
2479 if (channel_info.protocolVersion < SSL_LIBRARY_VERSION_3_0) { | 2477 if (channel_info.protocolVersion < SSL_LIBRARY_VERSION_3_0) { |
2480 // All versions less than SSL_LIBRARY_VERSION_3_0 are treated as SSL | 2478 // All versions less than SSL_LIBRARY_VERSION_3_0 are treated as SSL |
2481 // version 2. | 2479 // version 2. |
2482 version = SSL_CONNECTION_VERSION_SSL2; | 2480 version = SSL_CONNECTION_VERSION_SSL2; |
2483 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_0) { | 2481 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_0) { |
2484 version = SSL_CONNECTION_VERSION_SSL3; | 2482 version = SSL_CONNECTION_VERSION_SSL3; |
2485 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_1_TLS) { | 2483 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_1_TLS) { |
2486 version = SSL_CONNECTION_VERSION_TLS1; | 2484 version = SSL_CONNECTION_VERSION_TLS1; |
2487 } else if (channel_info.protocolVersion == 0x0302) { | 2485 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_TLS_1_1) { |
2488 version = SSL_CONNECTION_VERSION_TLS1_1; | 2486 version = SSL_CONNECTION_VERSION_TLS1_1; |
2489 } else if (channel_info.protocolVersion == 0x0303) { | 2487 } else if (channel_info.protocolVersion == 0x0303) { |
2490 version = SSL_CONNECTION_VERSION_TLS1_2; | 2488 version = SSL_CONNECTION_VERSION_TLS1_2; |
2491 } | 2489 } |
2492 nss_handshake_state_.ssl_connection_status |= | 2490 nss_handshake_state_.ssl_connection_status |= |
2493 (version & SSL_CONNECTION_VERSION_MASK) << | 2491 (version & SSL_CONNECTION_VERSION_MASK) << |
2494 SSL_CONNECTION_VERSION_SHIFT; | 2492 SSL_CONNECTION_VERSION_SHIFT; |
2495 } | 2493 } |
2496 | 2494 |
2497 // SSL_HandshakeNegotiatedExtension was added in NSS 3.12.6. | |
2498 // Since SSL_MAX_EXTENSIONS was added at the same time, we can test | |
2499 // SSL_MAX_EXTENSIONS for the presence of SSL_HandshakeNegotiatedExtension. | |
2500 #if defined(SSL_MAX_EXTENSIONS) | |
2501 PRBool peer_supports_renego_ext; | 2495 PRBool peer_supports_renego_ext; |
2502 ok = SSL_HandshakeNegotiatedExtension(nss_fd_, ssl_renegotiation_info_xtn, | 2496 ok = SSL_HandshakeNegotiatedExtension(nss_fd_, ssl_renegotiation_info_xtn, |
2503 &peer_supports_renego_ext); | 2497 &peer_supports_renego_ext); |
2504 if (ok == SECSuccess) { | 2498 if (ok == SECSuccess) { |
2505 if (!peer_supports_renego_ext) { | 2499 if (!peer_supports_renego_ext) { |
2506 nss_handshake_state_.ssl_connection_status |= | 2500 nss_handshake_state_.ssl_connection_status |= |
2507 SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION; | 2501 SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION; |
2508 // Log an informational message if the server does not support secure | 2502 // Log an informational message if the server does not support secure |
2509 // renegotiation (RFC 5746). | 2503 // renegotiation (RFC 5746). |
2510 VLOG(1) << "The server " << host_and_port_.ToString() | 2504 VLOG(1) << "The server " << host_and_port_.ToString() |
(...skipping 13 matching lines...) Expand all Loading... |
2524 // tools.ietf.org/html/draft-pettersen-tls-version-rollback-removal-00 . | 2518 // tools.ietf.org/html/draft-pettersen-tls-version-rollback-removal-00 . |
2525 // | 2519 // |
2526 // As a first step, measure how often clients perform version fallback | 2520 // As a first step, measure how often clients perform version fallback |
2527 // while the server advertises support secure renegotiation. | 2521 // while the server advertises support secure renegotiation. |
2528 if (ssl_config_.version_fallback && | 2522 if (ssl_config_.version_fallback && |
2529 channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_0) { | 2523 channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_0) { |
2530 UMA_HISTOGRAM_BOOLEAN("Net.SSLv3FallbackToRenegoPatchedServer", | 2524 UMA_HISTOGRAM_BOOLEAN("Net.SSLv3FallbackToRenegoPatchedServer", |
2531 peer_supports_renego_ext == PR_TRUE); | 2525 peer_supports_renego_ext == PR_TRUE); |
2532 } | 2526 } |
2533 } | 2527 } |
2534 #endif | |
2535 | 2528 |
2536 if (ssl_config_.version_fallback) { | 2529 if (ssl_config_.version_fallback) { |
2537 nss_handshake_state_.ssl_connection_status |= | 2530 nss_handshake_state_.ssl_connection_status |= |
2538 SSL_CONNECTION_VERSION_FALLBACK; | 2531 SSL_CONNECTION_VERSION_FALLBACK; |
2539 } | 2532 } |
2540 } | 2533 } |
2541 | 2534 |
2542 void SSLClientSocketNSS::Core::RecordChannelIDSupport() { | 2535 void SSLClientSocketNSS::Core::RecordChannelIDSupport() { |
2543 DCHECK(OnNSSTaskRunner()); | 2536 DCHECK(OnNSSTaskRunner()); |
2544 if (nss_handshake_state_.resumed_handshake) | 2537 if (nss_handshake_state_.resumed_handshake) |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3173 } | 3166 } |
3174 | 3167 |
3175 for (std::vector<uint16>::const_iterator it = | 3168 for (std::vector<uint16>::const_iterator it = |
3176 ssl_config_.disabled_cipher_suites.begin(); | 3169 ssl_config_.disabled_cipher_suites.begin(); |
3177 it != ssl_config_.disabled_cipher_suites.end(); ++it) { | 3170 it != ssl_config_.disabled_cipher_suites.end(); ++it) { |
3178 // This will fail if the specified cipher is not implemented by NSS, but | 3171 // This will fail if the specified cipher is not implemented by NSS, but |
3179 // the failure is harmless. | 3172 // the failure is harmless. |
3180 SSL_CipherPrefSet(nss_fd_, *it, PR_FALSE); | 3173 SSL_CipherPrefSet(nss_fd_, *it, PR_FALSE); |
3181 } | 3174 } |
3182 | 3175 |
3183 #ifdef SSL_ENABLE_SESSION_TICKETS | |
3184 // Support RFC 5077 | 3176 // Support RFC 5077 |
3185 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SESSION_TICKETS, PR_TRUE); | 3177 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_SESSION_TICKETS, PR_TRUE); |
3186 if (rv != SECSuccess) { | 3178 if (rv != SECSuccess) { |
3187 LogFailedNSSFunction( | 3179 LogFailedNSSFunction( |
3188 net_log_, "SSL_OptionSet", "SSL_ENABLE_SESSION_TICKETS"); | 3180 net_log_, "SSL_OptionSet", "SSL_ENABLE_SESSION_TICKETS"); |
3189 } | 3181 } |
3190 #else | |
3191 #error "You need to install NSS-3.12 or later to build chromium" | |
3192 #endif | |
3193 | 3182 |
3194 #ifdef SSL_ENABLE_FALSE_START | |
3195 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_FALSE_START, | 3183 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_FALSE_START, |
3196 ssl_config_.false_start_enabled); | 3184 ssl_config_.false_start_enabled); |
3197 if (rv != SECSuccess) | 3185 if (rv != SECSuccess) |
3198 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_FALSE_START"); | 3186 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_FALSE_START"); |
3199 #endif | |
3200 | 3187 |
3201 #ifdef SSL_ENABLE_RENEGOTIATION | |
3202 // We allow servers to request renegotiation. Since we're a client, | 3188 // We allow servers to request renegotiation. Since we're a client, |
3203 // prohibiting this is rather a waste of time. Only servers are in a | 3189 // prohibiting this is rather a waste of time. Only servers are in a |
3204 // position to prevent renegotiation attacks. | 3190 // position to prevent renegotiation attacks. |
3205 // http://extendedsubset.com/?p=8 | 3191 // http://extendedsubset.com/?p=8 |
3206 | 3192 |
3207 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_RENEGOTIATION, | 3193 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_RENEGOTIATION, |
3208 SSL_RENEGOTIATE_TRANSITIONAL); | 3194 SSL_RENEGOTIATE_TRANSITIONAL); |
3209 if (rv != SECSuccess) { | 3195 if (rv != SECSuccess) { |
3210 LogFailedNSSFunction( | 3196 LogFailedNSSFunction( |
3211 net_log_, "SSL_OptionSet", "SSL_ENABLE_RENEGOTIATION"); | 3197 net_log_, "SSL_OptionSet", "SSL_ENABLE_RENEGOTIATION"); |
3212 } | 3198 } |
3213 #endif // SSL_ENABLE_RENEGOTIATION | |
3214 | 3199 |
3215 #ifdef SSL_CBC_RANDOM_IV | |
3216 rv = SSL_OptionSet(nss_fd_, SSL_CBC_RANDOM_IV, PR_TRUE); | 3200 rv = SSL_OptionSet(nss_fd_, SSL_CBC_RANDOM_IV, PR_TRUE); |
3217 if (rv != SECSuccess) | 3201 if (rv != SECSuccess) |
3218 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_CBC_RANDOM_IV"); | 3202 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_CBC_RANDOM_IV"); |
3219 #endif | |
3220 | 3203 |
| 3204 // Added in NSS 3.15 |
3221 #ifdef SSL_ENABLE_OCSP_STAPLING | 3205 #ifdef SSL_ENABLE_OCSP_STAPLING |
3222 if (IsOCSPStaplingSupported()) { | 3206 if (IsOCSPStaplingSupported()) { |
3223 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_OCSP_STAPLING, PR_TRUE); | 3207 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_OCSP_STAPLING, PR_TRUE); |
3224 if (rv != SECSuccess) { | 3208 if (rv != SECSuccess) { |
3225 LogFailedNSSFunction(net_log_, "SSL_OptionSet", | 3209 LogFailedNSSFunction(net_log_, "SSL_OptionSet", |
3226 "SSL_ENABLE_OCSP_STAPLING"); | 3210 "SSL_ENABLE_OCSP_STAPLING"); |
3227 } | 3211 } |
3228 } | 3212 } |
3229 #endif | 3213 #endif |
3230 | 3214 |
| 3215 // Chromium patch to libssl |
3231 #ifdef SSL_ENABLE_CACHED_INFO | 3216 #ifdef SSL_ENABLE_CACHED_INFO |
3232 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_CACHED_INFO, | 3217 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_CACHED_INFO, |
3233 ssl_config_.cached_info_enabled); | 3218 ssl_config_.cached_info_enabled); |
3234 if (rv != SECSuccess) | 3219 if (rv != SECSuccess) |
3235 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_CACHED_INFO"); | 3220 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_CACHED_INFO"); |
3236 #endif | 3221 #endif |
3237 | 3222 |
3238 rv = SSL_OptionSet(nss_fd_, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE); | 3223 rv = SSL_OptionSet(nss_fd_, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE); |
3239 if (rv != SECSuccess) { | 3224 if (rv != SECSuccess) { |
3240 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_HANDSHAKE_AS_CLIENT"); | 3225 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_HANDSHAKE_AS_CLIENT"); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3547 EnsureThreadIdAssigned(); | 3532 EnsureThreadIdAssigned(); |
3548 base::AutoLock auto_lock(lock_); | 3533 base::AutoLock auto_lock(lock_); |
3549 return valid_thread_id_ == base::PlatformThread::CurrentId(); | 3534 return valid_thread_id_ == base::PlatformThread::CurrentId(); |
3550 } | 3535 } |
3551 | 3536 |
3552 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { | 3537 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { |
3553 return server_bound_cert_service_; | 3538 return server_bound_cert_service_; |
3554 } | 3539 } |
3555 | 3540 |
3556 } // namespace net | 3541 } // namespace net |
OLD | NEW |