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

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

Issue 10532061: Select the first protocol from the next protocol list of SSLConfig if If we didn't find a protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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
« no previous file with comments | « no previous file | no next file » | 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 // 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 <openssl/ssl.h> 10 #include <openssl/ssl.h>
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 SSL_CTX_sess_set_new_cb(ssl_ctx_.get(), NewSessionCallbackStatic); 331 SSL_CTX_sess_set_new_cb(ssl_ctx_.get(), NewSessionCallbackStatic);
332 SSL_CTX_sess_set_remove_cb(ssl_ctx_.get(), RemoveSessionCallbackStatic); 332 SSL_CTX_sess_set_remove_cb(ssl_ctx_.get(), RemoveSessionCallbackStatic);
333 SSL_CTX_set_timeout(ssl_ctx_.get(), kSessionCacheTimeoutSeconds); 333 SSL_CTX_set_timeout(ssl_ctx_.get(), kSessionCacheTimeoutSeconds);
334 SSL_CTX_sess_set_cache_size(ssl_ctx_.get(), kSessionCacheMaxEntires); 334 SSL_CTX_sess_set_cache_size(ssl_ctx_.get(), kSessionCacheMaxEntires);
335 SSL_CTX_set_client_cert_cb(ssl_ctx_.get(), ClientCertCallback); 335 SSL_CTX_set_client_cert_cb(ssl_ctx_.get(), ClientCertCallback);
336 #if defined(OPENSSL_NPN_NEGOTIATED) 336 #if defined(OPENSSL_NPN_NEGOTIATED)
337 // TODO(kristianm): Only select this if ssl_config_.next_proto is not empty. 337 // TODO(kristianm): Only select this if ssl_config_.next_proto is not empty.
338 // It would be better if the callback were not a global setting, 338 // It would be better if the callback were not a global setting,
339 // but that is an OpenSSL issue. 339 // but that is an OpenSSL issue.
340 SSL_CTX_set_next_proto_select_cb(ssl_ctx_.get(), SelectNextProtoCallback, 340 SSL_CTX_set_next_proto_select_cb(ssl_ctx_.get(), SelectNextProtoCallback,
341 NULL); 341 NULL);
wtc 2012/06/08 21:33:35 Hmm... this must be the issue that rsleevi pointed
Johnny(Jianning) Ding 2012/06/11 13:27:19 @kristianm, according to your comment, seems there
agl 2012/06/11 16:02:02 Well, I simply didn't add the option to switch the
342 #endif 342 #endif
343 } 343 }
344 344
345 static int NewSessionCallbackStatic(SSL* ssl, SSL_SESSION* session) { 345 static int NewSessionCallbackStatic(SSL* ssl, SSL_SESSION* session) {
346 return GetInstance()->NewSessionCallback(ssl, session); 346 return GetInstance()->NewSessionCallback(ssl, session);
347 } 347 }
348 348
349 int NewSessionCallback(SSL* ssl, SSL_SESSION* session) { 349 int NewSessionCallback(SSL* ssl, SSL_SESSION* session) {
350 SSLClientSocketOpenSSL* socket = GetClientSocketFromSSL(ssl); 350 SSLClientSocketOpenSSL* socket = GetClientSocketFromSSL(ssl);
351 session_cache_.OnSessionAdded(socket->host_and_port(), 351 session_cache_.OnSessionAdded(socket->host_and_port(),
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 845
846 // SelectNextProtoCallback is called by OpenSSL during the handshake. If the 846 // SelectNextProtoCallback is called by OpenSSL during the handshake. If the
847 // server supports NPN, selects a protocol from the list that the server 847 // server supports NPN, selects a protocol from the list that the server
848 // provides. According to third_party/openssl/openssl/ssl/ssl_lib.c, the 848 // provides. According to third_party/openssl/openssl/ssl/ssl_lib.c, the
849 // callback can assume that |in| is syntactically valid. 849 // callback can assume that |in| is syntactically valid.
850 int SSLClientSocketOpenSSL::SelectNextProtoCallback(unsigned char** out, 850 int SSLClientSocketOpenSSL::SelectNextProtoCallback(unsigned char** out,
851 unsigned char* outlen, 851 unsigned char* outlen,
852 const unsigned char* in, 852 const unsigned char* in,
853 unsigned int inlen) { 853 unsigned int inlen) {
854 #if defined(OPENSSL_NPN_NEGOTIATED) 854 #if defined(OPENSSL_NPN_NEGOTIATED)
855 // It's expected that a client will have a list of protocols that it
agl 2012/06/08 14:23:14 I don't think that this comment is very clear. May
Johnny(Jianning) Ding 2012/06/11 13:27:19 That comment is copied from https://technotes.goog
agl 2012/06/11 16:02:02 The first half is, but it doesn't make sense in th
wtc 2012/06/12 17:50:30 jnd: I suggest simply removing this comment. You
Johnny(Jianning) Ding 2012/06/13 09:31:20 Thanks for all your comments. Seems we should keep
856 // supports. If not, which means NPN is not supported.
855 if (ssl_config_.next_protos.empty()) { 857 if (ssl_config_.next_protos.empty()) {
856 *out = reinterpret_cast<uint8*>(const_cast<char*>("http/1.1")); 858 *out = reinterpret_cast<uint8*>(const_cast<char*>("http/1.1"));
857 *outlen = 8; 859 *outlen = 8;
Ryan Sleevi 2012/06/08 18:16:29 nit: I think I preferred Joth's suggestion (use a
Johnny(Jianning) Ding 2012/06/11 13:27:19 Will change in next upload.
858 npn_status_ = SSLClientSocket::kNextProtoUnsupported; 860 npn_status_ = kNextProtoUnsupported;
agl 2012/06/08 14:23:14 This should be NoOverlap, not Unsupported. If we h
Ryan Sleevi 2012/06/08 18:16:29 agl: This does change the behaviour then between t
859 return SSL_TLSEXT_ERR_OK; 861 return SSL_TLSEXT_ERR_OK;
860 } 862 }
861 863
862 // Assume there's no overlap between our protocols and the server's list. 864 // Assume there's no overlap between our protocols and the server's list.
863 int status = OPENSSL_NPN_NO_OVERLAP; 865 npn_status_ = kNextProtoNoOverlap;
864 *out = const_cast<unsigned char*>(in) + 1;
865 *outlen = in[0];
866 866
867 // For each protocol in server preference order, see if we support it. 867 // For each protocol in server preference order, see if we support it.
868 for (unsigned int i = 0; i < inlen; i += in[i] + 1) { 868 for (unsigned int i = 0; i < inlen; i += in[i] + 1) {
869 for (std::vector<std::string>::const_iterator 869 for (std::vector<std::string>::const_iterator
870 j = ssl_config_.next_protos.begin(); 870 j = ssl_config_.next_protos.begin();
871 j != ssl_config_.next_protos.end(); ++j) { 871 j != ssl_config_.next_protos.end(); ++j) {
872 if (in[i] == j->size() && 872 if (in[i] == j->size() &&
873 memcmp(&in[i + 1], j->data(), in[i]) == 0) { 873 memcmp(&in[i + 1], j->data(), in[i]) == 0) {
874 // We find a match. 874 // We find a match.
875 *out = const_cast<unsigned char*>(in) + i + 1; 875 *out = const_cast<unsigned char*>(in) + i + 1;
876 *outlen = in[i]; 876 *outlen = in[i];
877 status = OPENSSL_NPN_NEGOTIATED; 877 npn_status_ = kNextProtoNegotiated;
Ryan Sleevi 2012/06/08 18:16:29 nit: find -> found, since this comment appears aft
Johnny(Jianning) Ding 2012/06/11 13:27:19 will change in next upload. On 2012/06/08 18:16:2
878 break; 878 break;
879 } 879 }
880 } 880 }
881 if (status == OPENSSL_NPN_NEGOTIATED) 881 if (npn_status_ == kNextProtoNegotiated)
882 break; 882 break;
883 } 883 }
884 884
885 // If we didn't find a protocol, we select the first one from our list.
886 if (npn_status_ == kNextProtoNoOverlap) {
887 *out = reinterpret_cast<uint8*>(const_cast<char*>(
888 ssl_config_.next_protos[0].data()));
889 *outlen = ssl_config_.next_protos[0].size();
890 }
891
885 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen); 892 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen);
886 server_protos_.assign(reinterpret_cast<const char*>(in), inlen); 893 server_protos_.assign(reinterpret_cast<const char*>(in), inlen);
887 switch (status) {
888 case OPENSSL_NPN_NEGOTIATED:
889 npn_status_ = SSLClientSocket::kNextProtoNegotiated;
890 break;
891 case OPENSSL_NPN_NO_OVERLAP:
892 npn_status_ = SSLClientSocket::kNextProtoNoOverlap;
893 break;
894 default:
895 NOTREACHED() << status;
896 break;
897 }
898 DVLOG(2) << "next protocol: '" << npn_proto_ << "' status: " << npn_status_; 894 DVLOG(2) << "next protocol: '" << npn_proto_ << "' status: " << npn_status_;
899 #endif 895 #endif
900 return SSL_TLSEXT_ERR_OK; 896 return SSL_TLSEXT_ERR_OK;
901 } 897 }
902 898
903 int SSLClientSocketOpenSSL::DoVerifyCert(int result) { 899 int SSLClientSocketOpenSSL::DoVerifyCert(int result) {
904 DCHECK(server_cert_); 900 DCHECK(server_cert_);
905 GotoState(STATE_VERIFY_CERT_COMPLETE); 901 GotoState(STATE_VERIFY_CERT_COMPLETE);
906 902
907 CertStatus cert_status; 903 CertStatus cert_status;
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, 1311 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv,
1316 user_write_buf_->data()); 1312 user_write_buf_->data());
1317 return rv; 1313 return rv;
1318 } 1314 }
1319 1315
1320 int err = SSL_get_error(ssl_, rv); 1316 int err = SSL_get_error(ssl_, rv);
1321 return MapOpenSSLError(err, err_tracer); 1317 return MapOpenSSLError(err, err_tracer);
1322 } 1318 }
1323 1319
1324 } // namespace net 1320 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698