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

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

Issue 422063004: Certificate Transparency: Require SCTs for EV certificates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing review comments. Created 6 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
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 // OpenSSL binding for SSLClientSocket. The class layout and general principle 5 // OpenSSL binding for SSLClientSocket. The class layout and general principle
6 // of operation is derived from SSLClientSocketNSS. 6 // of operation is derived from SSLClientSocketNSS.
7 7
8 #include "net/socket/ssl_client_socket_openssl.h" 8 #include "net/socket/ssl_client_socket_openssl.h"
9 9
10 #include <errno.h> 10 #include <errno.h>
11 #include <openssl/bio.h> 11 #include <openssl/bio.h>
12 #include <openssl/err.h> 12 #include <openssl/err.h>
13 #include <openssl/ssl.h> 13 #include <openssl/ssl.h>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/callback_helpers.h" 16 #include "base/callback_helpers.h"
17 #include "base/environment.h" 17 #include "base/environment.h"
18 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
19 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
20 #include "base/profiler/scoped_tracker.h" 20 #include "base/profiler/scoped_tracker.h"
21 #include "base/strings/string_piece.h" 21 #include "base/strings/string_piece.h"
22 #include "base/synchronization/lock.h" 22 #include "base/synchronization/lock.h"
23 #include "crypto/ec_private_key.h" 23 #include "crypto/ec_private_key.h"
24 #include "crypto/openssl_util.h" 24 #include "crypto/openssl_util.h"
25 #include "crypto/scoped_openssl_types.h" 25 #include "crypto/scoped_openssl_types.h"
26 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
27 #include "net/cert/cert_policy_enforcer.h"
27 #include "net/cert/cert_verifier.h" 28 #include "net/cert/cert_verifier.h"
28 #include "net/cert/ct_ev_whitelist.h" 29 #include "net/cert/ct_ev_whitelist.h"
29 #include "net/cert/ct_verifier.h" 30 #include "net/cert/ct_verifier.h"
30 #include "net/cert/single_request_cert_verifier.h" 31 #include "net/cert/single_request_cert_verifier.h"
31 #include "net/cert/x509_certificate_net_log_param.h" 32 #include "net/cert/x509_certificate_net_log_param.h"
32 #include "net/cert/x509_util_openssl.h" 33 #include "net/cert/x509_util_openssl.h"
33 #include "net/http/transport_security_state.h" 34 #include "net/http/transport_security_state.h"
34 #include "net/socket/ssl_session_cache_openssl.h" 35 #include "net/socket/ssl_session_cache_openssl.h"
35 #include "net/ssl/ssl_cert_request_info.h" 36 #include "net/ssl/ssl_cert_request_info.h"
36 #include "net/ssl/ssl_connection_status_flags.h" 37 #include "net/ssl/ssl_connection_status_flags.h"
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 host_and_port_(host_and_port), 370 host_and_port_(host_and_port),
370 ssl_config_(ssl_config), 371 ssl_config_(ssl_config),
371 ssl_session_cache_shard_(context.ssl_session_cache_shard), 372 ssl_session_cache_shard_(context.ssl_session_cache_shard),
372 trying_cached_session_(false), 373 trying_cached_session_(false),
373 next_handshake_state_(STATE_NONE), 374 next_handshake_state_(STATE_NONE),
374 npn_status_(kNextProtoUnsupported), 375 npn_status_(kNextProtoUnsupported),
375 channel_id_xtn_negotiated_(false), 376 channel_id_xtn_negotiated_(false),
376 handshake_succeeded_(false), 377 handshake_succeeded_(false),
377 marked_session_as_good_(false), 378 marked_session_as_good_(false),
378 transport_security_state_(context.transport_security_state), 379 transport_security_state_(context.transport_security_state),
380 policy_enforcer_(context.cert_policy_enforcer),
379 net_log_(transport_->socket()->NetLog()), 381 net_log_(transport_->socket()->NetLog()),
380 weak_factory_(this) { 382 weak_factory_(this) {
381 } 383 }
382 384
383 SSLClientSocketOpenSSL::~SSLClientSocketOpenSSL() { 385 SSLClientSocketOpenSSL::~SSLClientSocketOpenSSL() {
384 Disconnect(); 386 Disconnect();
385 } 387 }
386 388
387 std::string SSLClientSocketOpenSSL::GetSessionCacheKey() const { 389 std::string SSLClientSocketOpenSSL::GetSessionCacheKey() const {
388 std::string result = host_and_port_.ToString(); 390 std::string result = host_and_port_.ToString();
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 (result == OK || 1135 (result == OK ||
1134 (IsCertificateError(result) && IsCertStatusMinorError(cert_status))) && 1136 (IsCertificateError(result) && IsCertStatusMinorError(cert_status))) &&
1135 !transport_security_state_->CheckPublicKeyPins( 1137 !transport_security_state_->CheckPublicKeyPins(
1136 host_and_port_.host(), 1138 host_and_port_.host(),
1137 server_cert_verify_result_.is_issued_by_known_root, 1139 server_cert_verify_result_.is_issued_by_known_root,
1138 server_cert_verify_result_.public_key_hashes, 1140 server_cert_verify_result_.public_key_hashes,
1139 &pinning_failure_log_)) { 1141 &pinning_failure_log_)) {
1140 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN; 1142 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN;
1141 } 1143 }
1142 1144
1143 scoped_refptr<ct::EVCertsWhitelist> ev_whitelist =
1144 SSLConfigService::GetEVCertsWhitelist();
1145 if (server_cert_verify_result_.cert_status & CERT_STATUS_IS_EV) {
1146 if (ev_whitelist.get() && ev_whitelist->IsValid()) {
1147 const SHA256HashValue fingerprint(
1148 X509Certificate::CalculateFingerprint256(
1149 server_cert_verify_result_.verified_cert->os_cert_handle()));
1150
1151 UMA_HISTOGRAM_BOOLEAN(
1152 "Net.SSL_EVCertificateInWhitelist",
1153 ev_whitelist->ContainsCertificateHash(
1154 std::string(reinterpret_cast<const char*>(fingerprint.data), 8)));
1155 }
1156 }
1157
1158 if (result == OK) { 1145 if (result == OK) {
1159 // Only check Certificate Transparency if there were no other errors with 1146 // Only check Certificate Transparency if there were no other errors with
1160 // the connection. 1147 // the connection.
1161 VerifyCT(); 1148 VerifyCT();
1162 1149
1163 // TODO(joth): Work out if we need to remember the intermediate CA certs 1150 // TODO(joth): Work out if we need to remember the intermediate CA certs
1164 // when the server sends them to us, and do so here. 1151 // when the server sends them to us, and do so here.
1165 SSLContext::GetInstance()->session_cache()->MarkSSLSessionAsGood(ssl_); 1152 SSLContext::GetInstance()->session_cache()->MarkSSLSessionAsGood(ssl_);
1166 marked_session_as_good_ = true; 1153 marked_session_as_good_ = true;
1167 CheckIfHandshakeFinished(); 1154 CheckIfHandshakeFinished();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 uint8_t* sct_list_raw; 1227 uint8_t* sct_list_raw;
1241 size_t sct_list_len; 1228 size_t sct_list_len;
1242 SSL_get0_signed_cert_timestamp_list(ssl_, &sct_list_raw, &sct_list_len); 1229 SSL_get0_signed_cert_timestamp_list(ssl_, &sct_list_raw, &sct_list_len);
1243 std::string sct_list; 1230 std::string sct_list;
1244 if (sct_list_len > 0) 1231 if (sct_list_len > 0)
1245 sct_list.assign(reinterpret_cast<const char*>(sct_list_raw), sct_list_len); 1232 sct_list.assign(reinterpret_cast<const char*>(sct_list_raw), sct_list_len);
1246 1233
1247 // Note that this is a completely synchronous operation: The CT Log Verifier 1234 // Note that this is a completely synchronous operation: The CT Log Verifier
1248 // gets all the data it needs for SCT verification and does not do any 1235 // gets all the data it needs for SCT verification and does not do any
1249 // external communication. 1236 // external communication.
1250 int result = cert_transparency_verifier_->Verify( 1237 cert_transparency_verifier_->Verify(
1251 server_cert_verify_result_.verified_cert.get(), 1238 server_cert_verify_result_.verified_cert.get(), ocsp_response, sct_list,
1252 ocsp_response, sct_list, &ct_verify_result_, net_log_); 1239 &ct_verify_result_, net_log_);
1253 1240
1254 VLOG(1) << "CT Verification complete: result " << result 1241 if (!policy_enforcer_) {
1255 << " Invalid scts: " << ct_verify_result_.invalid_scts.size() 1242 server_cert_verify_result_.cert_status &= ~CERT_STATUS_IS_EV;
1256 << " Verified scts: " << ct_verify_result_.verified_scts.size() 1243 } else {
1257 << " scts from unknown logs: " 1244 if (server_cert_verify_result_.cert_status & CERT_STATUS_IS_EV) {
1258 << ct_verify_result_.unknown_logs_scts.size(); 1245 scoped_refptr<ct::EVCertsWhitelist> ev_whitelist =
1246 SSLConfigService::GetEVCertsWhitelist();
1247 if (!policy_enforcer_->DoesConformToCTEVPolicy(
1248 server_cert_verify_result_.verified_cert.get(),
1249 ev_whitelist.get(), ct_verify_result_)) {
1250 // TODO(eranm): Log via the BoundNetLog, see crbug.com/437766
1251 VLOG(1) << "EV certificate for "
1252 << server_cert_verify_result_.verified_cert->subject()
1253 .GetDisplayName()
1254 << " does not conform to CT policy, removing EV status.";
1255 server_cert_verify_result_.cert_status &= ~CERT_STATUS_IS_EV;
1256 }
1257 }
1258 }
1259 } 1259 }
1260 1260
1261 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) { 1261 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) {
1262 int rv = DoHandshakeLoop(result); 1262 int rv = DoHandshakeLoop(result);
1263 if (rv != ERR_IO_PENDING) { 1263 if (rv != ERR_IO_PENDING) {
1264 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); 1264 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv);
1265 DoConnectCallback(rv); 1265 DoConnectCallback(rv);
1266 } 1266 }
1267 } 1267 }
1268 1268
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 ct::SCT_STATUS_LOG_UNKNOWN)); 1899 ct::SCT_STATUS_LOG_UNKNOWN));
1900 } 1900 }
1901 } 1901 }
1902 1902
1903 scoped_refptr<X509Certificate> 1903 scoped_refptr<X509Certificate>
1904 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { 1904 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const {
1905 return server_cert_; 1905 return server_cert_;
1906 } 1906 }
1907 1907
1908 } // namespace net 1908 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698