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

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

Issue 76443006: Certificate Transparency: Threading the CT verifier into the SSL client socket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removing error codes Created 7 years 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 #include "crypto/scoped_nss_types.h" 86 #include "crypto/scoped_nss_types.h"
87 #include "net/base/address_list.h" 87 #include "net/base/address_list.h"
88 #include "net/base/connection_type_histograms.h" 88 #include "net/base/connection_type_histograms.h"
89 #include "net/base/dns_util.h" 89 #include "net/base/dns_util.h"
90 #include "net/base/io_buffer.h" 90 #include "net/base/io_buffer.h"
91 #include "net/base/net_errors.h" 91 #include "net/base/net_errors.h"
92 #include "net/base/net_log.h" 92 #include "net/base/net_log.h"
93 #include "net/cert/asn1_util.h" 93 #include "net/cert/asn1_util.h"
94 #include "net/cert/cert_status_flags.h" 94 #include "net/cert/cert_status_flags.h"
95 #include "net/cert/cert_verifier.h" 95 #include "net/cert/cert_verifier.h"
96 #include "net/cert/ct_verifier.h"
96 #include "net/cert/scoped_nss_types.h" 97 #include "net/cert/scoped_nss_types.h"
97 #include "net/cert/single_request_cert_verifier.h" 98 #include "net/cert/single_request_cert_verifier.h"
98 #include "net/cert/x509_certificate_net_log_param.h" 99 #include "net/cert/x509_certificate_net_log_param.h"
99 #include "net/cert/x509_util.h" 100 #include "net/cert/x509_util.h"
100 #include "net/http/transport_security_state.h" 101 #include "net/http/transport_security_state.h"
101 #include "net/ocsp/nss_ocsp.h" 102 #include "net/ocsp/nss_ocsp.h"
102 #include "net/socket/client_socket_handle.h" 103 #include "net/socket/client_socket_handle.h"
103 #include "net/socket/nss_ssl_util.h" 104 #include "net/socket/nss_ssl_util.h"
104 #include "net/socket/ssl_error_params.h" 105 #include "net/socket/ssl_error_params.h"
105 #include "net/ssl/ssl_cert_request_info.h" 106 #include "net/ssl/ssl_cert_request_info.h"
(...skipping 2649 matching lines...) Expand 10 before | Expand all | Expand 10 after
2755 base::SequencedTaskRunner* nss_task_runner, 2756 base::SequencedTaskRunner* nss_task_runner,
2756 scoped_ptr<ClientSocketHandle> transport_socket, 2757 scoped_ptr<ClientSocketHandle> transport_socket,
2757 const HostPortPair& host_and_port, 2758 const HostPortPair& host_and_port,
2758 const SSLConfig& ssl_config, 2759 const SSLConfig& ssl_config,
2759 const SSLClientSocketContext& context) 2760 const SSLClientSocketContext& context)
2760 : nss_task_runner_(nss_task_runner), 2761 : nss_task_runner_(nss_task_runner),
2761 transport_(transport_socket.Pass()), 2762 transport_(transport_socket.Pass()),
2762 host_and_port_(host_and_port), 2763 host_and_port_(host_and_port),
2763 ssl_config_(ssl_config), 2764 ssl_config_(ssl_config),
2764 cert_verifier_(context.cert_verifier), 2765 cert_verifier_(context.cert_verifier),
2766 cert_transparency_verifier_(context.cert_transparency_verifier),
2765 server_bound_cert_service_(context.server_bound_cert_service), 2767 server_bound_cert_service_(context.server_bound_cert_service),
2766 ssl_session_cache_shard_(context.ssl_session_cache_shard), 2768 ssl_session_cache_shard_(context.ssl_session_cache_shard),
2767 completed_handshake_(false), 2769 completed_handshake_(false),
2768 next_handshake_state_(STATE_NONE), 2770 next_handshake_state_(STATE_NONE),
2769 nss_fd_(NULL), 2771 nss_fd_(NULL),
2770 net_log_(transport_->socket()->NetLog()), 2772 net_log_(transport_->socket()->NetLog()),
2771 transport_security_state_(context.transport_security_state), 2773 transport_security_state_(context.transport_security_state),
2772 valid_thread_id_(base::kInvalidThreadId) { 2774 valid_thread_id_(base::kInvalidThreadId) {
2773 EnterFunction(""); 2775 EnterFunction("");
2774 InitCore(); 2776 InitCore();
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
3318 // SSL handshake is completed. Let's verify the certificate. 3320 // SSL handshake is completed. Let's verify the certificate.
3319 GotoState(STATE_VERIFY_CERT); 3321 GotoState(STATE_VERIFY_CERT);
3320 // Done! 3322 // Done!
3321 } 3323 }
3322 set_channel_id_sent(core_->state().channel_id_sent); 3324 set_channel_id_sent(core_->state().channel_id_sent);
3323 3325
3324 LeaveFunction(result); 3326 LeaveFunction(result);
3325 return result; 3327 return result;
3326 } 3328 }
3327 3329
3328
3329 int SSLClientSocketNSS::DoVerifyCert(int result) { 3330 int SSLClientSocketNSS::DoVerifyCert(int result) {
3330 DCHECK(!core_->state().server_cert_chain.empty()); 3331 DCHECK(!core_->state().server_cert_chain.empty());
3331 DCHECK(core_->state().server_cert_chain[0]); 3332 DCHECK(core_->state().server_cert_chain[0]);
3332 3333
3333 GotoState(STATE_VERIFY_CERT_COMPLETE); 3334 GotoState(STATE_VERIFY_CERT_COMPLETE);
3334 3335
3335 // If the certificate is expected to be bad we can use the expectation as 3336 // If the certificate is expected to be bad we can use the expectation as
3336 // the cert status. 3337 // the cert status.
3337 base::StringPiece der_cert( 3338 base::StringPiece der_cert(
3338 reinterpret_cast<char*>( 3339 reinterpret_cast<char*>(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3402 // is fixed, we need to avoid using the NSS database for non-essential 3403 // is fixed, we need to avoid using the NSS database for non-essential
3403 // purposes. See https://bugzilla.mozilla.org/show_bug.cgi?id=508081 and 3404 // purposes. See https://bugzilla.mozilla.org/show_bug.cgi?id=508081 and
3404 // http://crbug.com/15630 for more info. 3405 // http://crbug.com/15630 for more info.
3405 3406
3406 // TODO(hclam): Skip logging if server cert was expected to be bad because 3407 // TODO(hclam): Skip logging if server cert was expected to be bad because
3407 // |server_cert_verify_result_| doesn't contain all the information about 3408 // |server_cert_verify_result_| doesn't contain all the information about
3408 // the cert. 3409 // the cert.
3409 if (result == OK) 3410 if (result == OK)
3410 LogConnectionTypeMetrics(); 3411 LogConnectionTypeMetrics();
3411 3412
3412 completed_handshake_ = true;
3413
3414 #if defined(OFFICIAL_BUILD) && !defined(OS_ANDROID) && !defined(OS_IOS) 3413 #if defined(OFFICIAL_BUILD) && !defined(OS_ANDROID) && !defined(OS_IOS)
3415 // Take care of any mandates for public key pinning. 3414 // Take care of any mandates for public key pinning.
3416 // 3415 //
3417 // Pinning is only enabled for official builds to make sure that others don't 3416 // Pinning is only enabled for official builds to make sure that others don't
3418 // end up with pins that cannot be easily updated. 3417 // end up with pins that cannot be easily updated.
3419 // 3418 //
3420 // TODO(agl): We might have an issue here where a request for foo.example.com 3419 // TODO(agl): We might have an issue here where a request for foo.example.com
3421 // merges into a SPDY connection to www.example.com, and gets a different 3420 // merges into a SPDY connection to www.example.com, and gets a different
3422 // certificate. 3421 // certificate.
3423 3422
(...skipping 27 matching lines...) Expand all
3451 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN; 3450 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN;
3452 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", false); 3451 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", false);
3453 TransportSecurityState::ReportUMAOnPinFailure(host); 3452 TransportSecurityState::ReportUMAOnPinFailure(host);
3454 } else { 3453 } else {
3455 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", true); 3454 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", true);
3456 } 3455 }
3457 } 3456 }
3458 } 3457 }
3459 #endif 3458 #endif
3460 3459
3460 if (result == OK) {
3461 // Only check Certificate Transparency if there were no other errors with
3462 // the connection.
3463 VerifyCT();
3464 }
3465
3466 completed_handshake_ = true;
3467
3461 // Exit DoHandshakeLoop and return the result to the caller to Connect. 3468 // Exit DoHandshakeLoop and return the result to the caller to Connect.
3462 DCHECK_EQ(STATE_NONE, next_handshake_state_); 3469 DCHECK_EQ(STATE_NONE, next_handshake_state_);
3463 return result; 3470 return result;
3464 } 3471 }
3465 3472
3473 void SSLClientSocketNSS::VerifyCT() {
3474 if (!cert_transparency_verifier_)
3475 return;
3476
3477 // Note that this is a completely synchronous operation: The CT Log Verifier
3478 // gets all the data it needs for SCT verification and does not do any
3479 // external communication.
3480 int result = cert_transparency_verifier_->Verify(
3481 server_cert_verify_result_.verified_cert,
3482 std::string(), // SCT list from OCSP response
3483 std::string(), // SCT list from TLS extension
3484 &ct_verify_result_);
3485
3486 VLOG(1) << "CT Verification complete: result " << result
3487 << " Unverified scts: " << ct_verify_result_.unverified_scts.size()
3488 << " Verified scts: " << ct_verify_result_.verified_scts.size()
3489 << " scts from unknown logs: "
3490 << ct_verify_result_.unknown_logs_scts.size();
3491
3492 if (!ct_verify_result_.unverified_scts.empty() ||
3493 !ct_verify_result_.unknown_logs_scts.empty() ||
3494 !ct_verify_result_.verified_scts.empty()) {
3495 // Saving CT state in cert_status bits, in addition to the SCTs themselves
3496 // (which will be threaded into the SSLInfo, as well as into the HTTP
3497 // cache).
3498 // This persists the CT status and simplifies UI code for figuring out
3499 // the right CT info to display.
3500 int ct_state;
wtc 2013/11/27 20:00:49 I suggest declaring this variable as a uint32 or C
Eran M. (Google) 2013/11/27 23:01:42 Done - uint32 it is.
3501 if (!ct_verify_result_.verified_scts.empty() && result == OK)
3502 ct_state = CERT_TRANSPARENCY_SCT_VALIDATED_OK;
3503 else if (!ct_verify_result_.unverified_scts.empty())
3504 ct_state = CERT_TRANSPARENCY_SCT_FAILED_VALIDATION;
3505 else {
3506 DCHECK(!ct_verify_result_.unknown_logs_scts.empty());
3507 ct_state = CERT_TRANSPARENCY_SCT_FROM_UNKNOWN_LOGS;
3508 }
wtc 2013/11/27 20:00:49 Nit: if one branch of the if statement needs curly
Eran M. (Google) 2013/11/27 23:01:42 Done.
3509 server_cert_verify_result_.cert_status |=
3510 (ct_state & CERTIFICATE_TRANSPARENCY_STATUS_MASK) <<
3511 CERTIFICATE_TRANSPARENCY_STATUS_SHIFT;
wtc 2013/11/27 20:00:49 I don't think we need "& CERTIFICATE_TRANSPARENCY_
Eran M. (Google) 2013/11/27 23:01:42 Done.
3512 }
3513
3514 return;
wtc 2013/11/27 20:00:49 Nit: the return statement is not necessary for a v
Eran M. (Google) 2013/11/27 23:01:42 Oops! Done.
3515 }
3516
3466 void SSLClientSocketNSS::LogConnectionTypeMetrics() const { 3517 void SSLClientSocketNSS::LogConnectionTypeMetrics() const {
3467 UpdateConnectionTypeHistograms(CONNECTION_SSL); 3518 UpdateConnectionTypeHistograms(CONNECTION_SSL);
3468 int ssl_version = SSLConnectionStatusToVersion( 3519 int ssl_version = SSLConnectionStatusToVersion(
3469 core_->state().ssl_connection_status); 3520 core_->state().ssl_connection_status);
3470 switch (ssl_version) { 3521 switch (ssl_version) {
3471 case SSL_CONNECTION_VERSION_SSL2: 3522 case SSL_CONNECTION_VERSION_SSL2:
3472 UpdateConnectionTypeHistograms(CONNECTION_SSL_SSL2); 3523 UpdateConnectionTypeHistograms(CONNECTION_SSL_SSL2);
3473 break; 3524 break;
3474 case SSL_CONNECTION_VERSION_SSL3: 3525 case SSL_CONNECTION_VERSION_SSL3:
3475 UpdateConnectionTypeHistograms(CONNECTION_SSL_SSL3); 3526 UpdateConnectionTypeHistograms(CONNECTION_SSL_SSL3);
(...skipping 21 matching lines...) Expand all
3497 EnsureThreadIdAssigned(); 3548 EnsureThreadIdAssigned();
3498 base::AutoLock auto_lock(lock_); 3549 base::AutoLock auto_lock(lock_);
3499 return valid_thread_id_ == base::PlatformThread::CurrentId(); 3550 return valid_thread_id_ == base::PlatformThread::CurrentId();
3500 } 3551 }
3501 3552
3502 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { 3553 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const {
3503 return server_bound_cert_service_; 3554 return server_bound_cert_service_;
3504 } 3555 }
3505 3556
3506 } // namespace net 3557 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698