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 #include "net/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
11 SSLClientSocket::SSLClientSocket() | 11 SSLClientSocket::SSLClientSocket() |
12 : was_npn_negotiated_(false), | 12 : was_npn_negotiated_(false), |
13 was_spdy_negotiated_(false), | 13 was_spdy_negotiated_(false), |
14 protocol_negotiated_(kProtoUnknown), | 14 protocol_negotiated_(kProtoUnknown), |
15 domain_bound_cert_type_(CLIENT_CERT_INVALID_TYPE) { | 15 domain_bound_cert_type_(CLIENT_CERT_INVALID_TYPE) { |
16 } | 16 } |
17 | 17 |
| 18 // static |
18 NextProto SSLClientSocket::NextProtoFromString( | 19 NextProto SSLClientSocket::NextProtoFromString( |
19 const std::string& proto_string) { | 20 const std::string& proto_string) { |
20 if (proto_string == "http1.1" || proto_string == "http/1.1") { | 21 if (proto_string == "http1.1" || proto_string == "http/1.1") { |
21 return kProtoHTTP11; | 22 return kProtoHTTP11; |
22 } else if (proto_string == "spdy/1") { | 23 } else if (proto_string == "spdy/1") { |
23 return kProtoSPDY1; | 24 return kProtoSPDY1; |
24 } else if (proto_string == "spdy/2") { | 25 } else if (proto_string == "spdy/2") { |
25 return kProtoSPDY2; | 26 return kProtoSPDY2; |
26 } else if (proto_string == "spdy/2.1") { | 27 } else if (proto_string == "spdy/2.1") { |
27 return kProtoSPDY21; | 28 return kProtoSPDY21; |
28 } else if (proto_string == "spdy/3") { | 29 } else if (proto_string == "spdy/3") { |
29 return kProtoSPDY3; | 30 return kProtoSPDY3; |
30 } else { | 31 } else { |
31 return kProtoUnknown; | 32 return kProtoUnknown; |
32 } | 33 } |
33 } | 34 } |
34 | 35 |
| 36 // static |
35 const char* SSLClientSocket::NextProtoToString(NextProto next_proto) { | 37 const char* SSLClientSocket::NextProtoToString(NextProto next_proto) { |
36 switch (next_proto) { | 38 switch (next_proto) { |
37 case kProtoHTTP11: | 39 case kProtoHTTP11: |
38 return "http/1.1"; | 40 return "http/1.1"; |
39 case kProtoSPDY1: | 41 case kProtoSPDY1: |
40 return "spdy/1"; | 42 return "spdy/1"; |
41 case kProtoSPDY2: | 43 case kProtoSPDY2: |
42 return "spdy/2"; | 44 return "spdy/2"; |
43 case kProtoSPDY21: | 45 case kProtoSPDY21: |
44 return "spdy/2.1"; | 46 return "spdy/2.1"; |
(...skipping 27 matching lines...) Expand all Loading... |
72 std::vector<std::string> server_protos_with_commas; | 74 std::vector<std::string> server_protos_with_commas; |
73 for (size_t i = 0; i < protos_len; ) { | 75 for (size_t i = 0; i < protos_len; ) { |
74 const size_t len = protos[i]; | 76 const size_t len = protos[i]; |
75 std::string proto_str(&protos[i + 1], len); | 77 std::string proto_str(&protos[i + 1], len); |
76 server_protos_with_commas.push_back(proto_str); | 78 server_protos_with_commas.push_back(proto_str); |
77 i += len + 1; | 79 i += len + 1; |
78 } | 80 } |
79 return JoinString(server_protos_with_commas, ','); | 81 return JoinString(server_protos_with_commas, ','); |
80 } | 82 } |
81 | 83 |
| 84 NextProto SSLClientSocket::GetNegotiatedProtocol() const { |
| 85 return protocol_negotiated_; |
| 86 } |
| 87 |
82 bool SSLClientSocket::IgnoreCertError(int error, int load_flags) { | 88 bool SSLClientSocket::IgnoreCertError(int error, int load_flags) { |
83 if (error == OK || load_flags & LOAD_IGNORE_ALL_CERT_ERRORS) | 89 if (error == OK || load_flags & LOAD_IGNORE_ALL_CERT_ERRORS) |
84 return true; | 90 return true; |
85 | 91 |
86 if (error == ERR_CERT_COMMON_NAME_INVALID && | 92 if (error == ERR_CERT_COMMON_NAME_INVALID && |
87 (load_flags & LOAD_IGNORE_CERT_COMMON_NAME_INVALID)) | 93 (load_flags & LOAD_IGNORE_CERT_COMMON_NAME_INVALID)) |
88 return true; | 94 return true; |
89 | 95 |
90 if (error == ERR_CERT_DATE_INVALID && | 96 if (error == ERR_CERT_DATE_INVALID && |
91 (load_flags & LOAD_IGNORE_CERT_DATE_INVALID)) | 97 (load_flags & LOAD_IGNORE_CERT_DATE_INVALID)) |
(...skipping 15 matching lines...) Expand all Loading... |
107 } | 113 } |
108 | 114 |
109 bool SSLClientSocket::was_spdy_negotiated() const { | 115 bool SSLClientSocket::was_spdy_negotiated() const { |
110 return was_spdy_negotiated_; | 116 return was_spdy_negotiated_; |
111 } | 117 } |
112 | 118 |
113 bool SSLClientSocket::set_was_spdy_negotiated(bool negotiated) { | 119 bool SSLClientSocket::set_was_spdy_negotiated(bool negotiated) { |
114 return was_spdy_negotiated_ = negotiated; | 120 return was_spdy_negotiated_ = negotiated; |
115 } | 121 } |
116 | 122 |
117 NextProto SSLClientSocket::protocol_negotiated() const { | |
118 return protocol_negotiated_; | |
119 } | |
120 | |
121 void SSLClientSocket::set_protocol_negotiated(NextProto protocol_negotiated) { | 123 void SSLClientSocket::set_protocol_negotiated(NextProto protocol_negotiated) { |
122 protocol_negotiated_ = protocol_negotiated; | 124 protocol_negotiated_ = protocol_negotiated; |
123 } | 125 } |
124 | 126 |
125 bool SSLClientSocket::WasDomainBoundCertSent() const { | 127 bool SSLClientSocket::WasDomainBoundCertSent() const { |
126 return domain_bound_cert_type_ != CLIENT_CERT_INVALID_TYPE; | 128 return domain_bound_cert_type_ != CLIENT_CERT_INVALID_TYPE; |
127 } | 129 } |
128 | 130 |
129 SSLClientCertType SSLClientSocket::domain_bound_cert_type() const { | 131 SSLClientCertType SSLClientSocket::domain_bound_cert_type() const { |
130 return domain_bound_cert_type_; | 132 return domain_bound_cert_type_; |
131 } | 133 } |
132 | 134 |
133 SSLClientCertType SSLClientSocket::set_domain_bound_cert_type( | 135 SSLClientCertType SSLClientSocket::set_domain_bound_cert_type( |
134 SSLClientCertType type) { | 136 SSLClientCertType type) { |
135 return domain_bound_cert_type_ = type; | 137 return domain_bound_cert_type_ = type; |
136 } | 138 } |
137 | 139 |
138 } // namespace net | 140 } // namespace net |
OLD | NEW |