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

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

Issue 8429034: Upstream: Build net_unittests for Android. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: update crypto.gyp Created 9 years, 1 month 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 | « net/net.gyp ('k') | net/spdy/spdy_protocol_test.cc » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 << ", SSL error code " << ssl_error 779 << ", SSL error code " << ssl_error
780 << ", net_error " << net_error; 780 << ", net_error " << net_error;
781 net_log_.AddEvent( 781 net_log_.AddEvent(
782 NetLog::TYPE_SSL_HANDSHAKE_ERROR, 782 NetLog::TYPE_SSL_HANDSHAKE_ERROR,
783 make_scoped_refptr(new SSLErrorParams(net_error, ssl_error))); 783 make_scoped_refptr(new SSLErrorParams(net_error, ssl_error)));
784 } 784 }
785 } 785 }
786 return net_error; 786 return net_error;
787 } 787 }
788 788
789 // SelectNextProtoCallback is called by OpenSSL during the handshake. If the
790 // server supports NPN, selects a protocol from the list that the server
791 // provides. According to third_party/openssl/openssl/ssl/ssl_lib.c, the
792 // callback can assume that |in| is syntactically valid.
789 int SSLClientSocketOpenSSL::SelectNextProtoCallback(unsigned char** out, 793 int SSLClientSocketOpenSSL::SelectNextProtoCallback(unsigned char** out,
790 unsigned char* outlen, 794 unsigned char* outlen,
791 const unsigned char* in, 795 const unsigned char* in,
792 unsigned int inlen) { 796 unsigned int inlen) {
793 #if defined(OPENSSL_NPN_NEGOTIATED) 797 #if defined(OPENSSL_NPN_NEGOTIATED)
794 if (ssl_config_.next_protos.empty()) { 798 if (ssl_config_.next_protos.empty()) {
795 *out = reinterpret_cast<uint8*>(const_cast<char*>("http/1.1")); 799 *out = reinterpret_cast<uint8*>(const_cast<char*>("http/1.1"));
796 *outlen = 8; 800 *outlen = 8;
797 npn_status_ = SSLClientSocket::kNextProtoUnsupported; 801 npn_status_ = SSLClientSocket::kNextProtoUnsupported;
798 return SSL_TLSEXT_ERR_OK; 802 return SSL_TLSEXT_ERR_OK;
799 } 803 }
800 804
801 int status = SSL_select_next_proto( 805 // Assume there's no overlap between our protocols and the server's list.
802 out, outlen, in, inlen, 806 int status = OPENSSL_NPN_NO_OVERLAP;
803 reinterpret_cast<const unsigned char*>(ssl_config_.next_protos.data()), 807 *out = const_cast<unsigned char*>(in) + 1;
804 ssl_config_.next_protos.size()); 808 *outlen = in[0];
809
810 // For each protocol in server preference order, see if we support it.
811 for (unsigned int i = 0; i < inlen; i += in[i] + 1) {
812 for (std::vector<std::string>::const_iterator
813 j = ssl_config_.next_protos.begin();
mmenke 2011/11/17 16:16:08 nit: Could you indent just this line 4 more space
814 j != ssl_config_.next_protos.end(); ++j) {
815 if (in[i] == j->size() &&
816 memcmp(&in[i + 1], j->data(), in[i]) == 0) {
817 // We find a match.
818 *out = const_cast<unsigned char*>(in) + i + 1;
819 *outlen = in[i];
820 status = OPENSSL_NPN_NEGOTIATED;
821 break;
822 }
823 }
824 if (status == OPENSSL_NPN_NEGOTIATED)
825 break;
826 }
805 827
806 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen); 828 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen);
807 switch (status) { 829 switch (status) {
808 case OPENSSL_NPN_UNSUPPORTED:
809 npn_status_ = SSLClientSocket::kNextProtoUnsupported;
810 break;
811 case OPENSSL_NPN_NEGOTIATED: 830 case OPENSSL_NPN_NEGOTIATED:
812 npn_status_ = SSLClientSocket::kNextProtoNegotiated; 831 npn_status_ = SSLClientSocket::kNextProtoNegotiated;
813 break; 832 break;
814 case OPENSSL_NPN_NO_OVERLAP: 833 case OPENSSL_NPN_NO_OVERLAP:
815 npn_status_ = SSLClientSocket::kNextProtoNoOverlap; 834 npn_status_ = SSLClientSocket::kNextProtoNoOverlap;
816 break; 835 break;
817 default: 836 default:
818 NOTREACHED() << status; 837 NOTREACHED() << status;
819 break; 838 break;
820 } 839 }
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, 1245 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv,
1227 user_write_buf_->data()); 1246 user_write_buf_->data());
1228 return rv; 1247 return rv;
1229 } 1248 }
1230 1249
1231 int err = SSL_get_error(ssl_, rv); 1250 int err = SSL_get_error(ssl_, rv);
1232 return MapOpenSSLError(err, err_tracer); 1251 return MapOpenSSLError(err, err_tracer);
1233 } 1252 }
1234 1253
1235 } // namespace net 1254 } // namespace net
OLDNEW
« no previous file with comments | « net/net.gyp ('k') | net/spdy/spdy_protocol_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698