Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: net/socket/ssl_client_socket_nss.cc

Issue 433123003: Centralize the logic for checking public key pins (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments from sleevi Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_->CheckPublicKeyPins(
3454 TransportSecurityState::IsBuildTimely()) { 3437 host_and_port_.host(),
3455 bool sni_available = 3438 sni_available,
3456 ssl_config_.version_max >= SSL_PROTOCOL_VERSION_TLS1 || 3439 server_cert_verify_result_.is_issued_by_known_root,
3457 ssl_config_.version_fallback; 3440 server_cert_verify_result_.public_key_hashes,
3458 const std::string& host = host_and_port_.host(); 3441 &pinning_failure_log_)) {
3459 3442 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN;
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 } 3443 }
3475 #endif
3476 3444
3477 if (result == OK) { 3445 if (result == OK) {
3478 // Only check Certificate Transparency if there were no other errors with 3446 // Only check Certificate Transparency if there were no other errors with
3479 // the connection. 3447 // the connection.
3480 VerifyCT(); 3448 VerifyCT();
3481 3449
3482 // Only cache the session if the certificate verified successfully. 3450 // Only cache the session if the certificate verified successfully.
3483 core_->CacheSessionIfNecessary(); 3451 core_->CacheSessionIfNecessary();
3484 } 3452 }
3485 3453
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
3574 scoped_refptr<X509Certificate> 3542 scoped_refptr<X509Certificate>
3575 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { 3543 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const {
3576 return core_->state().server_cert.get(); 3544 return core_->state().server_cert.get();
3577 } 3545 }
3578 3546
3579 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { 3547 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const {
3580 return channel_id_service_; 3548 return channel_id_service_;
3581 } 3549 }
3582 3550
3583 } // namespace net 3551 } // namespace net
OLDNEW
« net/quic/crypto/proof_verifier_chromium.cc ('K') | « net/quic/crypto/proof_verifier_chromium.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698