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

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 24 matching lines...) Expand all
35 " jump to state " << s; \ 35 " jump to state " << s; \
36 next_handshake_state_ = s; } while (0) 36 next_handshake_state_ = s; } while (0)
37 #else 37 #else
38 #define GotoState(s) next_handshake_state_ = s 38 #define GotoState(s) next_handshake_state_ = s
39 #endif 39 #endif
40 40
41 const size_t kMaxRecvBufferSize = 4096; 41 const size_t kMaxRecvBufferSize = 4096;
42 const int kSessionCacheTimeoutSeconds = 60 * 60; 42 const int kSessionCacheTimeoutSeconds = 60 * 60;
43 const size_t kSessionCacheMaxEntires = 1024; 43 const size_t kSessionCacheMaxEntires = 1024;
44 44
45 // If a client doesn't have a list of protocols that it supports, but
46 // the server supports NPN, choosing "http/1.1" is the best answer.
47 const char kDefaultSupportedNPNProtocol[] = "http/1.1";
48
45 // This method doesn't seemed to have made it into the OpenSSL headers. 49 // This method doesn't seemed to have made it into the OpenSSL headers.
46 unsigned long SSL_CIPHER_get_id(const SSL_CIPHER* cipher) { return cipher->id; } 50 unsigned long SSL_CIPHER_get_id(const SSL_CIPHER* cipher) { return cipher->id; }
47 51
48 // Used for encoding the |connection_status| field of an SSLInfo object. 52 // Used for encoding the |connection_status| field of an SSLInfo object.
49 int EncodeSSLConnectionStatus(int cipher_suite, 53 int EncodeSSLConnectionStatus(int cipher_suite,
50 int compression, 54 int compression,
51 int version) { 55 int version) {
52 return ((cipher_suite & SSL_CONNECTION_CIPHERSUITE_MASK) << 56 return ((cipher_suite & SSL_CONNECTION_CIPHERSUITE_MASK) <<
53 SSL_CONNECTION_CIPHERSUITE_SHIFT) | 57 SSL_CONNECTION_CIPHERSUITE_SHIFT) |
54 ((compression & SSL_CONNECTION_COMPRESSION_MASK) << 58 ((compression & SSL_CONNECTION_COMPRESSION_MASK) <<
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 // SelectNextProtoCallback is called by OpenSSL during the handshake. If the 850 // SelectNextProtoCallback is called by OpenSSL during the handshake. If the
847 // server supports NPN, selects a protocol from the list that the server 851 // 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 852 // provides. According to third_party/openssl/openssl/ssl/ssl_lib.c, the
849 // callback can assume that |in| is syntactically valid. 853 // callback can assume that |in| is syntactically valid.
850 int SSLClientSocketOpenSSL::SelectNextProtoCallback(unsigned char** out, 854 int SSLClientSocketOpenSSL::SelectNextProtoCallback(unsigned char** out,
851 unsigned char* outlen, 855 unsigned char* outlen,
852 const unsigned char* in, 856 const unsigned char* in,
853 unsigned int inlen) { 857 unsigned int inlen) {
854 #if defined(OPENSSL_NPN_NEGOTIATED) 858 #if defined(OPENSSL_NPN_NEGOTIATED)
855 if (ssl_config_.next_protos.empty()) { 859 if (ssl_config_.next_protos.empty()) {
856 *out = reinterpret_cast<uint8*>(const_cast<char*>("http/1.1")); 860 *out = reinterpret_cast<uint8*>(
857 *outlen = 8; 861 const_cast<char*>(kDefaultSupportedNPNProtocol));
wtc 2012/06/13 18:01:52 agl: it seems that these const_casts when assignin
858 npn_status_ = SSLClientSocket::kNextProtoUnsupported; 862 *outlen = arraysize(kDefaultSupportedNPNProtocol) - 1;
863 npn_status_ = kNextProtoUnsupported;
859 return SSL_TLSEXT_ERR_OK; 864 return SSL_TLSEXT_ERR_OK;
860 } 865 }
861 866
862 // Assume there's no overlap between our protocols and the server's list. 867 // Assume there's no overlap between our protocols and the server's list.
863 int status = OPENSSL_NPN_NO_OVERLAP; 868 npn_status_ = kNextProtoNoOverlap;
864 *out = const_cast<unsigned char*>(in) + 1;
865 *outlen = in[0];
866 869
867 // For each protocol in server preference order, see if we support it. 870 // For each protocol in server preference order, see if we support it.
868 for (unsigned int i = 0; i < inlen; i += in[i] + 1) { 871 for (unsigned int i = 0; i < inlen; i += in[i] + 1) {
869 for (std::vector<std::string>::const_iterator 872 for (std::vector<std::string>::const_iterator
870 j = ssl_config_.next_protos.begin(); 873 j = ssl_config_.next_protos.begin();
871 j != ssl_config_.next_protos.end(); ++j) { 874 j != ssl_config_.next_protos.end(); ++j) {
875 // We found a match.
wtc 2012/06/13 18:01:52 Nit: it's better to move this comment into the if
Johnny(Jianning) Ding 2012/06/14 04:50:13 Done. It was to address Ryan's comment, it said "t
872 if (in[i] == j->size() && 876 if (in[i] == j->size() &&
873 memcmp(&in[i + 1], j->data(), in[i]) == 0) { 877 memcmp(&in[i + 1], j->data(), in[i]) == 0) {
874 // We find a match.
875 *out = const_cast<unsigned char*>(in) + i + 1; 878 *out = const_cast<unsigned char*>(in) + i + 1;
876 *outlen = in[i]; 879 *outlen = in[i];
877 status = OPENSSL_NPN_NEGOTIATED; 880 npn_status_ = kNextProtoNegotiated;
878 break; 881 break;
879 } 882 }
880 } 883 }
881 if (status == OPENSSL_NPN_NEGOTIATED) 884 if (npn_status_ == kNextProtoNegotiated)
882 break; 885 break;
883 } 886 }
884 887
888 // If we didn't find a protocol, we select the first one from our list.
889 if (npn_status_ == kNextProtoNoOverlap) {
890 *out = reinterpret_cast<uint8*>(const_cast<char*>(
891 ssl_config_.next_protos[0].data()));
892 *outlen = ssl_config_.next_protos[0].size();
893 }
894
885 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen); 895 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen);
886 server_protos_.assign(reinterpret_cast<const char*>(in), inlen); 896 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_; 897 DVLOG(2) << "next protocol: '" << npn_proto_ << "' status: " << npn_status_;
899 #endif 898 #endif
900 return SSL_TLSEXT_ERR_OK; 899 return SSL_TLSEXT_ERR_OK;
901 } 900 }
902 901
903 int SSLClientSocketOpenSSL::DoVerifyCert(int result) { 902 int SSLClientSocketOpenSSL::DoVerifyCert(int result) {
904 DCHECK(server_cert_); 903 DCHECK(server_cert_);
905 GotoState(STATE_VERIFY_CERT_COMPLETE); 904 GotoState(STATE_VERIFY_CERT_COMPLETE);
906 905
907 CertStatus cert_status; 906 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, 1314 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv,
1316 user_write_buf_->data()); 1315 user_write_buf_->data());
1317 return rv; 1316 return rv;
1318 } 1317 }
1319 1318
1320 int err = SSL_get_error(ssl_, rv); 1319 int err = SSL_get_error(ssl_, rv);
1321 return MapOpenSSLError(err, err_tracer); 1320 return MapOpenSSLError(err, err_tracer);
1322 } 1321 }
1323 1322
1324 } // namespace net 1323 } // 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