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
3 // found in the LICENSE file.
5 #include "net/socket/ssl_client_socket.h"
7 #include "base/strings/string_util.h"
11 SSLClientSocket::SSLClientSocket()
12 : was_npn_negotiated_(false),
13 was_spdy_negotiated_(false),
14 protocol_negotiated_(kProtoUnknown
),
15 channel_id_sent_(false) {
19 NextProto
SSLClientSocket::NextProtoFromString(
20 const std::string
& proto_string
) {
21 if (proto_string
== "http1.1" || proto_string
== "http/1.1") {
23 } else if (proto_string
== "spdy/1") {
25 } else if (proto_string
== "spdy/2") {
27 } else if (proto_string
== "spdy/3") {
29 } else if (proto_string
== "spdy/3.1") {
31 } else if (proto_string
== "spdy/4a2") {
33 } else if (proto_string
== "HTTP-draft-04/2.0") {
34 return kProtoHTTP2Draft04
;
35 } else if (proto_string
== "quic/1+spdy/3") {
36 return kProtoQUIC1SPDY3
;
43 const char* SSLClientSocket::NextProtoToString(NextProto next_proto
) {
57 case kProtoHTTP2Draft04
:
58 return "HTTP-draft-04/2.0";
59 case kProtoQUIC1SPDY3
:
60 return "quic/1+spdy/3";
69 const char* SSLClientSocket::NextProtoStatusToString(
70 const SSLClientSocket::NextProtoStatus status
) {
72 case kNextProtoUnsupported
:
74 case kNextProtoNegotiated
:
76 case kNextProtoNoOverlap
:
83 std::string
SSLClientSocket::ServerProtosToString(
84 const std::string
& server_protos
) {
85 const char* protos
= server_protos
.c_str();
86 size_t protos_len
= server_protos
.length();
87 std::vector
<std::string
> server_protos_with_commas
;
88 for (size_t i
= 0; i
< protos_len
; ) {
89 const size_t len
= protos
[i
];
90 std::string
proto_str(&protos
[i
+ 1], len
);
91 server_protos_with_commas
.push_back(proto_str
);
94 return JoinString(server_protos_with_commas
, ',');
97 bool SSLClientSocket::WasNpnNegotiated() const {
98 return was_npn_negotiated_
;
101 NextProto
SSLClientSocket::GetNegotiatedProtocol() const {
102 return protocol_negotiated_
;
105 bool SSLClientSocket::IgnoreCertError(int error
, int load_flags
) {
106 if (error
== OK
|| load_flags
& LOAD_IGNORE_ALL_CERT_ERRORS
)
109 if (error
== ERR_CERT_COMMON_NAME_INVALID
&&
110 (load_flags
& LOAD_IGNORE_CERT_COMMON_NAME_INVALID
))
113 if (error
== ERR_CERT_DATE_INVALID
&&
114 (load_flags
& LOAD_IGNORE_CERT_DATE_INVALID
))
117 if (error
== ERR_CERT_AUTHORITY_INVALID
&&
118 (load_flags
& LOAD_IGNORE_CERT_AUTHORITY_INVALID
))
124 bool SSLClientSocket::set_was_npn_negotiated(bool negotiated
) {
125 return was_npn_negotiated_
= negotiated
;
128 bool SSLClientSocket::was_spdy_negotiated() const {
129 return was_spdy_negotiated_
;
132 bool SSLClientSocket::set_was_spdy_negotiated(bool negotiated
) {
133 return was_spdy_negotiated_
= negotiated
;
136 void SSLClientSocket::set_protocol_negotiated(NextProto protocol_negotiated
) {
137 protocol_negotiated_
= protocol_negotiated
;
140 bool SSLClientSocket::WasChannelIDSent() const {
141 return channel_id_sent_
;
144 void SSLClientSocket::set_channel_id_sent(bool channel_id_sent
) {
145 channel_id_sent_
= channel_id_sent
;