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

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

Issue 2337253004: Update Token Binding code to the latest drafts (Closed)
Patch Set: Add call to CBS_len() Created 4 years, 3 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
« no previous file with comments | « net/socket/ssl_client_socket_impl.h ('k') | net/spdy/spdy_http_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "net/socket/ssl_client_socket_impl.h" 5 #include "net/socket/ssl_client_socket_impl.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <openssl/bio.h> 8 #include <openssl/bio.h>
9 #include <openssl/bytestring.h> 9 #include <openssl/bytestring.h>
10 #include <openssl/err.h> 10 #include <openssl/err.h>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const int kNoPendingResult = 1; 71 const int kNoPendingResult = 1;
72 72
73 // Default size of the internal BoringSSL buffers. 73 // Default size of the internal BoringSSL buffers.
74 const int kDefaultOpenSSLBufferSize = 17 * 1024; 74 const int kDefaultOpenSSLBufferSize = 17 * 1024;
75 75
76 // TLS extension number use for Token Binding. 76 // TLS extension number use for Token Binding.
77 const unsigned int kTbExtNum = 24; 77 const unsigned int kTbExtNum = 24;
78 78
79 // Token Binding ProtocolVersions supported. 79 // Token Binding ProtocolVersions supported.
80 const uint8_t kTbProtocolVersionMajor = 0; 80 const uint8_t kTbProtocolVersionMajor = 0;
81 const uint8_t kTbProtocolVersionMinor = 8; 81 const uint8_t kTbProtocolVersionMinor = 10;
82 const uint8_t kTbMinProtocolVersionMajor = 0; 82 const uint8_t kTbMinProtocolVersionMajor = 0;
83 const uint8_t kTbMinProtocolVersionMinor = 6; 83 const uint8_t kTbMinProtocolVersionMinor = 10;
84 84
85 bool EVP_MDToPrivateKeyHash(const EVP_MD* md, SSLPrivateKey::Hash* hash) { 85 bool EVP_MDToPrivateKeyHash(const EVP_MD* md, SSLPrivateKey::Hash* hash) {
86 switch (EVP_MD_type(md)) { 86 switch (EVP_MD_type(md)) {
87 case NID_md5_sha1: 87 case NID_md5_sha1:
88 *hash = SSLPrivateKey::Hash::MD5_SHA1; 88 *hash = SSLPrivateKey::Hash::MD5_SHA1;
89 return true; 89 return true;
90 case NID_sha1: 90 case NID_sha1:
91 *hash = SSLPrivateKey::Hash::SHA1; 91 *hash = SSLPrivateKey::Hash::SHA1;
92 return true; 92 return true;
93 case NID_sha256: 93 case NID_sha256:
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 transport_read_error_(OK), 480 transport_read_error_(OK),
481 transport_write_error_(OK), 481 transport_write_error_(OK),
482 server_cert_chain_(new PeerCertificateChain(NULL)), 482 server_cert_chain_(new PeerCertificateChain(NULL)),
483 completed_connect_(false), 483 completed_connect_(false),
484 was_ever_used_(false), 484 was_ever_used_(false),
485 cert_verifier_(context.cert_verifier), 485 cert_verifier_(context.cert_verifier),
486 cert_transparency_verifier_(context.cert_transparency_verifier), 486 cert_transparency_verifier_(context.cert_transparency_verifier),
487 channel_id_service_(context.channel_id_service), 487 channel_id_service_(context.channel_id_service),
488 tb_was_negotiated_(false), 488 tb_was_negotiated_(false),
489 tb_negotiated_param_(TB_PARAM_ECDSAP256), 489 tb_negotiated_param_(TB_PARAM_ECDSAP256),
490 tb_signed_ekm_map_(10), 490 tb_signature_map_(10),
491 ssl_(NULL), 491 ssl_(NULL),
492 transport_bio_(NULL), 492 transport_bio_(NULL),
493 transport_(std::move(transport_socket)), 493 transport_(std::move(transport_socket)),
494 host_and_port_(host_and_port), 494 host_and_port_(host_and_port),
495 ssl_config_(ssl_config), 495 ssl_config_(ssl_config),
496 ssl_session_cache_shard_(context.ssl_session_cache_shard), 496 ssl_session_cache_shard_(context.ssl_session_cache_shard),
497 next_handshake_state_(STATE_NONE), 497 next_handshake_state_(STATE_NONE),
498 disconnected_(false), 498 disconnected_(false),
499 negotiated_protocol_(kProtoUnknown), 499 negotiated_protocol_(kProtoUnknown),
500 channel_id_sent_(false), 500 channel_id_sent_(false),
(...skipping 26 matching lines...) Expand all
527 SSLCertRequestInfo* cert_request_info) { 527 SSLCertRequestInfo* cert_request_info) {
528 cert_request_info->host_and_port = host_and_port_; 528 cert_request_info->host_and_port = host_and_port_;
529 cert_request_info->cert_authorities = cert_authorities_; 529 cert_request_info->cert_authorities = cert_authorities_;
530 cert_request_info->cert_key_types = cert_key_types_; 530 cert_request_info->cert_key_types = cert_key_types_;
531 } 531 }
532 532
533 ChannelIDService* SSLClientSocketImpl::GetChannelIDService() const { 533 ChannelIDService* SSLClientSocketImpl::GetChannelIDService() const {
534 return channel_id_service_; 534 return channel_id_service_;
535 } 535 }
536 536
537 Error SSLClientSocketImpl::GetSignedEKMForTokenBinding( 537 Error SSLClientSocketImpl::GetTokenBindingSignature(crypto::ECPrivateKey* key,
538 crypto::ECPrivateKey* key, 538 TokenBindingType tb_type,
539 std::vector<uint8_t>* out) { 539 std::vector<uint8_t>* out) {
540 // The same key will be used across multiple requests to sign the same value, 540 // The same key will be used across multiple requests to sign the same value,
541 // so the signature is cached. 541 // so the signature is cached.
542 std::string raw_public_key; 542 std::string raw_public_key;
543 if (!key->ExportRawPublicKey(&raw_public_key)) 543 if (!key->ExportRawPublicKey(&raw_public_key))
544 return ERR_FAILED; 544 return ERR_FAILED;
545 SignedEkmMap::iterator it = tb_signed_ekm_map_.Get(raw_public_key); 545 auto it = tb_signature_map_.Get(std::make_pair(tb_type, raw_public_key));
546 if (it != tb_signed_ekm_map_.end()) { 546 if (it != tb_signature_map_.end()) {
547 *out = it->second; 547 *out = it->second;
548 return OK; 548 return OK;
549 } 549 }
550 550
551 uint8_t tb_ekm_buf[32]; 551 uint8_t tb_ekm_buf[32];
552 static const char kTokenBindingExporterLabel[] = "EXPORTER-Token-Binding"; 552 static const char kTokenBindingExporterLabel[] = "EXPORTER-Token-Binding";
553 if (!SSL_export_keying_material(ssl_, tb_ekm_buf, sizeof(tb_ekm_buf), 553 if (!SSL_export_keying_material(ssl_, tb_ekm_buf, sizeof(tb_ekm_buf),
554 kTokenBindingExporterLabel, 554 kTokenBindingExporterLabel,
555 strlen(kTokenBindingExporterLabel), nullptr, 555 strlen(kTokenBindingExporterLabel), nullptr,
556 0, false /* no context */)) { 556 0, false /* no context */)) {
557 return ERR_FAILED; 557 return ERR_FAILED;
558 } 558 }
559 559
560 if (!SignTokenBindingEkm( 560 if (!CreateTokenBindingSignature(
561 base::StringPiece(reinterpret_cast<char*>(tb_ekm_buf), 561 base::StringPiece(reinterpret_cast<char*>(tb_ekm_buf),
562 sizeof(tb_ekm_buf)), 562 sizeof(tb_ekm_buf)),
563 key, out)) 563 tb_type, key, out))
564 return ERR_FAILED; 564 return ERR_FAILED;
565 565
566 tb_signed_ekm_map_.Put(raw_public_key, *out); 566 tb_signature_map_.Put(std::make_pair(tb_type, raw_public_key), *out);
567 return OK; 567 return OK;
568 } 568 }
569 569
570 crypto::ECPrivateKey* SSLClientSocketImpl::GetChannelIDKey() const { 570 crypto::ECPrivateKey* SSLClientSocketImpl::GetChannelIDKey() const {
571 return channel_id_key_.get(); 571 return channel_id_key_.get();
572 } 572 }
573 573
574 int SSLClientSocketImpl::ExportKeyingMaterial(const base::StringPiece& label, 574 int SSLClientSocketImpl::ExportKeyingMaterial(const base::StringPiece& label,
575 bool has_context, 575 bool has_context,
576 const base::StringPiece& context, 576 const base::StringPiece& context,
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 // afterwards. This is to aid in diagnosing connection failures because a 1167 // afterwards. This is to aid in diagnosing connection failures because a
1168 // server requires DHE ciphers. 1168 // server requires DHE ciphers.
1169 // 1169 //
1170 // TODO(davidben): A few releases after DHE's removal, remove this logic. 1170 // TODO(davidben): A few releases after DHE's removal, remove this logic.
1171 if (!ssl_config_.dhe_enabled && 1171 if (!ssl_config_.dhe_enabled &&
1172 SSL_CIPHER_is_DHE(SSL_get_current_cipher(ssl_))) { 1172 SSL_CIPHER_is_DHE(SSL_get_current_cipher(ssl_))) {
1173 return ERR_SSL_OBSOLETE_CIPHER; 1173 return ERR_SSL_OBSOLETE_CIPHER;
1174 } 1174 }
1175 1175
1176 // Check that if token binding was negotiated, then extended master secret 1176 // Check that if token binding was negotiated, then extended master secret
1177 // must also be negotiated. 1177 // and renegotiation indication must also be negotiated.
1178 if (tb_was_negotiated_ && !SSL_get_extms_support(ssl_)) 1178 if (tb_was_negotiated_ &&
1179 !(SSL_get_extms_support(ssl_) &&
1180 SSL_get_secure_renegotiation_support(ssl_))) {
1179 return ERR_SSL_PROTOCOL_ERROR; 1181 return ERR_SSL_PROTOCOL_ERROR;
1182 }
1180 1183
1181 const uint8_t* alpn_proto = NULL; 1184 const uint8_t* alpn_proto = NULL;
1182 unsigned alpn_len = 0; 1185 unsigned alpn_len = 0;
1183 SSL_get0_alpn_selected(ssl_, &alpn_proto, &alpn_len); 1186 SSL_get0_alpn_selected(ssl_, &alpn_proto, &alpn_len);
1184 if (alpn_len > 0) { 1187 if (alpn_len > 0) {
1185 base::StringPiece proto(reinterpret_cast<const char*>(alpn_proto), 1188 base::StringPiece proto(reinterpret_cast<const char*>(alpn_proto),
1186 alpn_len); 1189 alpn_len);
1187 negotiated_protocol_ = NextProtoFromString(proto); 1190 negotiated_protocol_ = NextProtoFromString(proto);
1188 } 1191 }
1189 1192
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 } 2283 }
2281 UMA_HISTOGRAM_ENUMERATION("DomainBoundCerts.Support", supported, 2284 UMA_HISTOGRAM_ENUMERATION("DomainBoundCerts.Support", supported,
2282 CHANNEL_ID_USAGE_MAX); 2285 CHANNEL_ID_USAGE_MAX);
2283 } 2286 }
2284 2287
2285 bool SSLClientSocketImpl::IsChannelIDEnabled() const { 2288 bool SSLClientSocketImpl::IsChannelIDEnabled() const {
2286 return ssl_config_.channel_id_enabled && channel_id_service_; 2289 return ssl_config_.channel_id_enabled && channel_id_service_;
2287 } 2290 }
2288 2291
2289 } // namespace net 2292 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_impl.h ('k') | net/spdy/spdy_http_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698