OLD | NEW |
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 <errno.h> | 10 #include <errno.h> |
(...skipping 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 *outlen = arraysize(kDefaultSupportedNPNProtocol) - 1; | 1775 *outlen = arraysize(kDefaultSupportedNPNProtocol) - 1; |
1776 npn_status_ = kNextProtoUnsupported; | 1776 npn_status_ = kNextProtoUnsupported; |
1777 return SSL_TLSEXT_ERR_OK; | 1777 return SSL_TLSEXT_ERR_OK; |
1778 } | 1778 } |
1779 | 1779 |
1780 // Assume there's no overlap between our protocols and the server's list. | 1780 // Assume there's no overlap between our protocols and the server's list. |
1781 npn_status_ = kNextProtoNoOverlap; | 1781 npn_status_ = kNextProtoNoOverlap; |
1782 | 1782 |
1783 // For each protocol in server preference order, see if we support it. | 1783 // For each protocol in server preference order, see if we support it. |
1784 for (unsigned int i = 0; i < inlen; i += in[i] + 1) { | 1784 for (unsigned int i = 0; i < inlen; i += in[i] + 1) { |
1785 for (std::vector<std::string>::const_iterator | 1785 for (NextProto next_proto : ssl_config_.next_protos) { |
1786 j = ssl_config_.next_protos.begin(); | 1786 const std::string proto = NextProtoToString(next_proto); |
1787 j != ssl_config_.next_protos.end(); ++j) { | 1787 if (in[i] == proto.size() && |
1788 if (in[i] == j->size() && | 1788 memcmp(&in[i + 1], proto.data(), in[i]) == 0) { |
1789 memcmp(&in[i + 1], j->data(), in[i]) == 0) { | |
1790 // We found a match. | 1789 // We found a match. |
1791 *out = const_cast<unsigned char*>(in) + i + 1; | 1790 *out = const_cast<unsigned char*>(in) + i + 1; |
1792 *outlen = in[i]; | 1791 *outlen = in[i]; |
1793 npn_status_ = kNextProtoNegotiated; | 1792 npn_status_ = kNextProtoNegotiated; |
1794 break; | 1793 break; |
1795 } | 1794 } |
1796 } | 1795 } |
1797 if (npn_status_ == kNextProtoNegotiated) | 1796 if (npn_status_ == kNextProtoNegotiated) |
1798 break; | 1797 break; |
1799 } | 1798 } |
1800 | 1799 |
1801 // If we didn't find a protocol, we select the first one from our list. | 1800 // If we didn't find a protocol, we select the first one from our list. |
1802 if (npn_status_ == kNextProtoNoOverlap) { | 1801 if (npn_status_ == kNextProtoNoOverlap) { |
1803 *out = reinterpret_cast<uint8*>(const_cast<char*>( | 1802 const std::string proto = NextProtoToString(ssl_config_.next_protos[0]); |
1804 ssl_config_.next_protos[0].data())); | 1803 *out = reinterpret_cast<uint8*>(const_cast<char*>(proto.data())); |
1805 *outlen = ssl_config_.next_protos[0].size(); | 1804 *outlen = proto.size(); |
1806 } | 1805 } |
1807 | 1806 |
1808 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen); | 1807 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen); |
1809 DVLOG(2) << "next protocol: '" << npn_proto_ << "' status: " << npn_status_; | 1808 DVLOG(2) << "next protocol: '" << npn_proto_ << "' status: " << npn_status_; |
1810 set_negotiation_extension(kExtensionNPN); | 1809 set_negotiation_extension(kExtensionNPN); |
1811 return SSL_TLSEXT_ERR_OK; | 1810 return SSL_TLSEXT_ERR_OK; |
1812 } | 1811 } |
1813 | 1812 |
1814 long SSLClientSocketOpenSSL::MaybeReplayTransportError( | 1813 long SSLClientSocketOpenSSL::MaybeReplayTransportError( |
1815 BIO *bio, | 1814 BIO *bio, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 ct::SCT_STATUS_LOG_UNKNOWN)); | 1902 ct::SCT_STATUS_LOG_UNKNOWN)); |
1904 } | 1903 } |
1905 } | 1904 } |
1906 | 1905 |
1907 scoped_refptr<X509Certificate> | 1906 scoped_refptr<X509Certificate> |
1908 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { | 1907 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { |
1909 return server_cert_; | 1908 return server_cert_; |
1910 } | 1909 } |
1911 | 1910 |
1912 } // namespace net | 1911 } // namespace net |
OLD | NEW |