diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 21:52:27 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 21:52:27 +0000 |
commit | b28f19d7901a742c41987c707168f9f71dc3ea0e (patch) | |
tree | f0b8d142fa83c8b161ffac4f1b472e38c7811af5 /net/socket/ssl_client_socket_nss.cc | |
parent | e1b19760199e7a1004684840c1641f934029f27a (diff) | |
download | chromium_src-b28f19d7901a742c41987c707168f9f71dc3ea0e.zip chromium_src-b28f19d7901a742c41987c707168f9f71dc3ea0e.tar.gz chromium_src-b28f19d7901a742c41987c707168f9f71dc3ea0e.tar.bz2 |
Add GetNextProtocol method to SSLClientSocket.
http://codereview.chromium.org/484005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34288 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/ssl_client_socket_nss.cc')
-rw-r--r-- | net/socket/ssl_client_socket_nss.cc | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/net/socket/ssl_client_socket_nss.cc b/net/socket/ssl_client_socket_nss.cc index cc3200c..4968823 100644 --- a/net/socket/ssl_client_socket_nss.cc +++ b/net/socket/ssl_client_socket_nss.cc @@ -529,37 +529,6 @@ void SSLClientSocketNSS::GetSSLInfo(SSLInfo* ssl_info) { DCHECK(server_cert_ != NULL); ssl_info->cert = server_cert_; -#ifdef SSL_NEXT_PROTO_NEGOTIATED - unsigned char npn_buf[255]; - unsigned npn_len; - int npn_status; - SECStatus rv = SSL_GetNextProto(nss_fd_, &npn_status, npn_buf, &npn_len, - sizeof(npn_buf)); - if (rv != SECSuccess) { - npn_status = SSL_NEXT_PROTO_NO_SUPPORT; - } - - if (npn_status == SSL_NEXT_PROTO_NO_SUPPORT) { - ssl_info->next_proto_status = SSLInfo::kNextProtoUnsupported; - ssl_info->next_proto.clear(); - } else { - ssl_info->next_proto = - std::string(reinterpret_cast<const char *>(npn_buf), npn_len); - switch (npn_status) { - case SSL_NEXT_PROTO_NEGOTIATED: - ssl_info->next_proto_status = SSLInfo::kNextProtoNegotiated; - break; - case SSL_NEXT_PROTO_NO_OVERLAP: - ssl_info->next_proto_status = SSLInfo::kNextProtoNoOverlap; - break; - default: - LOG(ERROR) << "Unknown npn_status: " << npn_status; - ssl_info->next_proto_status = SSLInfo::kNextProtoNoOverlap; - break; - } - } -#endif - LeaveFunction(""); } @@ -571,6 +540,45 @@ void SSLClientSocketNSS::GetSSLCertRequestInfo( LeaveFunction(cert_request_info->client_certs.size()); } +SSLClientSocket::NextProtoStatus +SSLClientSocketNSS::GetNextProtocol(std::string* proto) { +#if !defined(SSL_NEXT_PROTO_NEGOTIATED) + // No NPN support in the libssl that we are building with. + proto->clear(); + return kNextProtoUnsupported; +#else + unsigned char buf[256]; + int state; + unsigned len; + SECStatus rv = SSL_GetNextProto(nss_fd_, &state, buf, &len, sizeof(buf)); + if (rv != SECSuccess) { + NOTREACHED() << "Error return from SSL_GetNextProto: " << rv; + proto->clear(); + return kNextProtoUnsupported; + } + if (len == sizeof(buf)) { + // Based on the wire protocol, it should be impossible for the protocol + // string to be > 255 bytes long. + NOTREACHED() << "NPN protocol name truncated"; + } + switch(state) { + case SSL_NEXT_PROTO_NO_SUPPORT: + proto->clear(); + return kNextProtoUnsupported; + case SSL_NEXT_PROTO_NEGOTIATED: + *proto = std::string(reinterpret_cast<char*>(buf), len); + return kNextProtoNegotiated; + case SSL_NEXT_PROTO_NO_OVERLAP: + *proto = std::string(reinterpret_cast<char*>(buf), len); + return kNextProtoNoOverlap; + default: + NOTREACHED() << "Unknown status from SSL_GetNextProto: " << state; + proto->clear(); + return kNextProtoUnsupported; + } +#endif +} + void SSLClientSocketNSS::DoReadCallback(int rv) { EnterFunction(rv); DCHECK(rv != ERR_IO_PENDING); |