| 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 3408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3419 // is fixed, we need to avoid using the NSS database for non-essential | 3419 // is fixed, we need to avoid using the NSS database for non-essential |
| 3420 // purposes. See https://bugzilla.mozilla.org/show_bug.cgi?id=508081 and | 3420 // purposes. See https://bugzilla.mozilla.org/show_bug.cgi?id=508081 and |
| 3421 // http://crbug.com/15630 for more info. | 3421 // http://crbug.com/15630 for more info. |
| 3422 | 3422 |
| 3423 // TODO(hclam): Skip logging if server cert was expected to be bad because | 3423 // TODO(hclam): Skip logging if server cert was expected to be bad because |
| 3424 // |server_cert_verify_result_| doesn't contain all the information about | 3424 // |server_cert_verify_result_| doesn't contain all the information about |
| 3425 // the cert. | 3425 // the cert. |
| 3426 if (result == OK) | 3426 if (result == OK) |
| 3427 LogConnectionTypeMetrics(); | 3427 LogConnectionTypeMetrics(); |
| 3428 | 3428 |
| 3429 #if defined(OFFICIAL_BUILD) && !defined(OS_ANDROID) && !defined(OS_IOS) | 3429 bool sni_available = |
| 3430 // Take care of any mandates for public key pinning. | 3430 ssl_config_.version_max >= SSL_PROTOCOL_VERSION_TLS1 || |
| 3431 // | 3431 ssl_config_.version_fallback; |
| 3432 // Pinning is only enabled for official builds to make sure that others don't | |
| 3433 // end up with pins that cannot be easily updated. | |
| 3434 // | |
| 3435 // TODO(agl): We might have an issue here where a request for foo.example.com | |
| 3436 // merges into a SPDY connection to www.example.com, and gets a different | |
| 3437 // certificate. | |
| 3438 | |
| 3439 // Perform pin validation if, and only if, all these conditions obtain: | |
| 3440 // | |
| 3441 // * a TransportSecurityState object is available; | |
| 3442 // * the server's certificate chain is valid (or suffers from only a minor | |
| 3443 // error); | |
| 3444 // * the server's certificate chain chains up to a known root (i.e. not a | |
| 3445 // user-installed trust anchor); and | |
| 3446 // * the build is recent (very old builds should fail open so that users | |
| 3447 // have some chance to recover). | |
| 3448 // | |
| 3449 const CertStatus cert_status = server_cert_verify_result_.cert_status; | 3432 const CertStatus cert_status = server_cert_verify_result_.cert_status; |
| 3450 if (transport_security_state_ && | 3433 if (transport_security_state_ && |
| 3451 (result == OK || | 3434 (result == OK || |
| 3452 (IsCertificateError(result) && IsCertStatusMinorError(cert_status))) && | 3435 (IsCertificateError(result) && IsCertStatusMinorError(cert_status))) && |
| 3453 server_cert_verify_result_.is_issued_by_known_root && | 3436 !transport_security_state_->VerifyPinning( |
| 3454 TransportSecurityState::IsBuildTimely()) { | 3437 server_cert_verify_result_, |
| 3455 bool sni_available = | 3438 sni_available, |
| 3456 ssl_config_.version_max >= SSL_PROTOCOL_VERSION_TLS1 || | 3439 host_and_port_.host(), |
| 3457 ssl_config_.version_fallback; | 3440 &pinning_failure_log_)) { |
| 3458 const std::string& host = host_and_port_.host(); | 3441 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN; |
| 3459 | |
| 3460 if (transport_security_state_->HasPublicKeyPins(host, sni_available)) { | |
| 3461 if (!transport_security_state_->CheckPublicKeyPins( | |
| 3462 host, | |
| 3463 sni_available, | |
| 3464 server_cert_verify_result_.public_key_hashes, | |
| 3465 &pinning_failure_log_)) { | |
| 3466 LOG(ERROR) << pinning_failure_log_; | |
| 3467 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN; | |
| 3468 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", false); | |
| 3469 TransportSecurityState::ReportUMAOnPinFailure(host); | |
| 3470 } else { | |
| 3471 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", true); | |
| 3472 } | |
| 3473 } | |
| 3474 } | 3442 } |
| 3475 #endif | |
| 3476 | 3443 |
| 3477 if (result == OK) { | 3444 if (result == OK) { |
| 3478 // Only check Certificate Transparency if there were no other errors with | 3445 // Only check Certificate Transparency if there were no other errors with |
| 3479 // the connection. | 3446 // the connection. |
| 3480 VerifyCT(); | 3447 VerifyCT(); |
| 3481 | 3448 |
| 3482 // Only cache the session if the certificate verified successfully. | 3449 // Only cache the session if the certificate verified successfully. |
| 3483 core_->CacheSessionIfNecessary(); | 3450 core_->CacheSessionIfNecessary(); |
| 3484 } | 3451 } |
| 3485 | 3452 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3574 scoped_refptr<X509Certificate> | 3541 scoped_refptr<X509Certificate> |
| 3575 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { | 3542 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { |
| 3576 return core_->state().server_cert.get(); | 3543 return core_->state().server_cert.get(); |
| 3577 } | 3544 } |
| 3578 | 3545 |
| 3579 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { | 3546 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { |
| 3580 return channel_id_service_; | 3547 return channel_id_service_; |
| 3581 } | 3548 } |
| 3582 | 3549 |
| 3583 } // namespace net | 3550 } // namespace net |
| OLD | NEW |