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/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") {
35 const char* SSLClientSocket::NextProtoToString(NextProto next_proto
) {
52 const char* SSLClientSocket::NextProtoStatusToString(
53 const SSLClientSocket::NextProtoStatus status
) {
55 case kNextProtoUnsupported
:
57 case kNextProtoNegotiated
:
59 case kNextProtoNoOverlap
:
66 std::string
SSLClientSocket::ServerProtosToString(
67 const std::string
& server_protos
) {
68 const char* protos
= server_protos
.c_str();
69 size_t protos_len
= server_protos
.length();
70 std::vector
<std::string
> server_protos_with_commas
;
71 for (size_t i
= 0; i
< protos_len
; ) {
72 const size_t len
= protos
[i
];
73 std::string
proto_str(&protos
[i
+ 1], len
);
74 server_protos_with_commas
.push_back(proto_str
);
77 return JoinString(server_protos_with_commas
, ',');
80 bool SSLClientSocket::WasNpnNegotiated() const {
81 return was_npn_negotiated_
;
84 NextProto
SSLClientSocket::GetNegotiatedProtocol() const {
85 return protocol_negotiated_
;
88 bool SSLClientSocket::IgnoreCertError(int error
, int load_flags
) {
89 if (error
== OK
|| load_flags
& LOAD_IGNORE_ALL_CERT_ERRORS
)
92 if (error
== ERR_CERT_COMMON_NAME_INVALID
&&
93 (load_flags
& LOAD_IGNORE_CERT_COMMON_NAME_INVALID
))
96 if (error
== ERR_CERT_DATE_INVALID
&&
97 (load_flags
& LOAD_IGNORE_CERT_DATE_INVALID
))
100 if (error
== ERR_CERT_AUTHORITY_INVALID
&&
101 (load_flags
& LOAD_IGNORE_CERT_AUTHORITY_INVALID
))
107 bool SSLClientSocket::set_was_npn_negotiated(bool negotiated
) {
108 return was_npn_negotiated_
= negotiated
;
111 bool SSLClientSocket::was_spdy_negotiated() const {
112 return was_spdy_negotiated_
;
115 bool SSLClientSocket::set_was_spdy_negotiated(bool negotiated
) {
116 return was_spdy_negotiated_
= negotiated
;
119 void SSLClientSocket::set_protocol_negotiated(NextProto protocol_negotiated
) {
120 protocol_negotiated_
= protocol_negotiated
;
123 bool SSLClientSocket::WasChannelIDSent() const {
124 return channel_id_sent_
;
127 void SSLClientSocket::set_channel_id_sent(bool channel_id_sent
) {
128 channel_id_sent_
= channel_id_sent
;