OLD | NEW |
---|---|
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 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
791 const unsigned char* in, | 791 const unsigned char* in, |
792 unsigned int inlen) { | 792 unsigned int inlen) { |
793 #if defined(OPENSSL_NPN_NEGOTIATED) | 793 #if defined(OPENSSL_NPN_NEGOTIATED) |
794 if (ssl_config_.next_protos.empty()) { | 794 if (ssl_config_.next_protos.empty()) { |
795 *out = reinterpret_cast<uint8*>(const_cast<char*>("http/1.1")); | 795 *out = reinterpret_cast<uint8*>(const_cast<char*>("http/1.1")); |
796 *outlen = 8; | 796 *outlen = 8; |
797 npn_status_ = SSLClientSocket::kNextProtoUnsupported; | 797 npn_status_ = SSLClientSocket::kNextProtoUnsupported; |
798 return SSL_TLSEXT_ERR_OK; | 798 return SSL_TLSEXT_ERR_OK; |
799 } | 799 } |
800 | 800 |
801 int status = SSL_select_next_proto( | 801 int status = OPENSSL_NPN_NO_OVERLAP; |
802 out, outlen, in, inlen, | 802 *out = (unsigned char *) in + 1; |
Ryan Sleevi
2011/11/06 02:39:48
BUG? Without checking the implementation of SSL_se
Jing Zhao
2011/11/07 03:42:49
Done.
| |
803 reinterpret_cast<const unsigned char*>(ssl_config_.next_protos.data()), | 803 *outlen = in[0]; |
804 ssl_config_.next_protos.size()); | 804 for (unsigned int i = 0; i < inlen; i += in[i] + 1) { |
805 for (std::vector<std::string>::const_iterator | |
806 j = ssl_config_.next_protos.begin(); | |
807 j != ssl_config_.next_protos.end(); j++) { | |
Ryan Sleevi
2011/11/06 02:39:48
nit: ++j
Jing Zhao
2011/11/07 03:42:49
Done.
| |
808 if (in[i] == j->size() && | |
809 memcmp(&in[i + 1], j->data(), in[i]) == 0) { | |
Ryan Sleevi
2011/11/06 02:39:48
I'm a little nervous, quite possibly unreasonably
Jing Zhao
2011/11/07 03:42:49
Yes, I double checked the implementation from thir
joth
2011/11/08 10:05:23
FWIW, as we have a more expressive class library t
Ryan Sleevi
2011/11/08 15:03:23
+1 to using StringPiece - it would definitely help
| |
810 *out = (unsigned char *) in + i + 1; | |
811 *outlen = in[i]; | |
812 status = OPENSSL_NPN_NEGOTIATED; | |
813 break; | |
814 } | |
815 } | |
816 if (status == OPENSSL_NPN_NEGOTIATED) | |
817 break; | |
818 } | |
805 | 819 |
806 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen); | 820 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen); |
807 switch (status) { | 821 switch (status) { |
808 case OPENSSL_NPN_UNSUPPORTED: | 822 case OPENSSL_NPN_UNSUPPORTED: |
809 npn_status_ = SSLClientSocket::kNextProtoUnsupported; | 823 npn_status_ = SSLClientSocket::kNextProtoUnsupported; |
810 break; | 824 break; |
811 case OPENSSL_NPN_NEGOTIATED: | 825 case OPENSSL_NPN_NEGOTIATED: |
812 npn_status_ = SSLClientSocket::kNextProtoNegotiated; | 826 npn_status_ = SSLClientSocket::kNextProtoNegotiated; |
813 break; | 827 break; |
814 case OPENSSL_NPN_NO_OVERLAP: | 828 case OPENSSL_NPN_NO_OVERLAP: |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1226 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, | 1240 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, |
1227 user_write_buf_->data()); | 1241 user_write_buf_->data()); |
1228 return rv; | 1242 return rv; |
1229 } | 1243 } |
1230 | 1244 |
1231 int err = SSL_get_error(ssl_, rv); | 1245 int err = SSL_get_error(ssl_, rv); |
1232 return MapOpenSSLError(err, err_tracer); | 1246 return MapOpenSSLError(err, err_tracer); |
1233 } | 1247 } |
1234 | 1248 |
1235 } // namespace net | 1249 } // namespace net |
OLD | NEW |