| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_H_ | 5 #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_H_ |
| 6 #define NET_SOCKET_SSL_CLIENT_SOCKET_H_ | 6 #define NET_SOCKET_SSL_CLIENT_SOCKET_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // A client socket that uses SSL as the transport layer. | 39 // A client socket that uses SSL as the transport layer. |
| 40 // | 40 // |
| 41 // NOTE: The SSL handshake occurs within the Connect method after a TCP | 41 // NOTE: The SSL handshake occurs within the Connect method after a TCP |
| 42 // connection is established. If a SSL error occurs during the handshake, | 42 // connection is established. If a SSL error occurs during the handshake, |
| 43 // Connect will fail. | 43 // Connect will fail. |
| 44 // | 44 // |
| 45 class SSLClientSocket : public ClientSocket { | 45 class SSLClientSocket : public ClientSocket { |
| 46 public: | 46 public: |
| 47 SSLClientSocket() : was_npn_negotiated_(false), was_spdy_negotiated_(false) { | 47 SSLClientSocket(); |
| 48 } | 48 |
| 49 // Next Protocol Negotiation (NPN) allows a TLS client and server to come to | 49 // Next Protocol Negotiation (NPN) allows a TLS client and server to come to |
| 50 // an agreement about the application level protocol to speak over a | 50 // an agreement about the application level protocol to speak over a |
| 51 // connection. | 51 // connection. |
| 52 enum NextProtoStatus { | 52 enum NextProtoStatus { |
| 53 kNextProtoUnsupported = 0, // The server doesn't support NPN. | 53 kNextProtoUnsupported = 0, // The server doesn't support NPN. |
| 54 kNextProtoNegotiated = 1, // We agreed on a protocol. | 54 kNextProtoNegotiated = 1, // We agreed on a protocol. |
| 55 kNextProtoNoOverlap = 2, // No protocols in common. We requested | 55 kNextProtoNoOverlap = 2, // No protocols in common. We requested |
| 56 // the first protocol in our list. | 56 // the first protocol in our list. |
| 57 }; | 57 }; |
| 58 | 58 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 77 | 77 |
| 78 // Get the application level protocol that we negotiated with the server. | 78 // Get the application level protocol that we negotiated with the server. |
| 79 // *proto is set to the resulting protocol (n.b. that the string may have | 79 // *proto is set to the resulting protocol (n.b. that the string may have |
| 80 // embedded NULs). | 80 // embedded NULs). |
| 81 // kNextProtoUnsupported: *proto is cleared. | 81 // kNextProtoUnsupported: *proto is cleared. |
| 82 // kNextProtoNegotiated: *proto is set to the negotiated protocol. | 82 // kNextProtoNegotiated: *proto is set to the negotiated protocol. |
| 83 // kNextProtoNoOverlap: *proto is set to the first protocol in the | 83 // kNextProtoNoOverlap: *proto is set to the first protocol in the |
| 84 // supported list. | 84 // supported list. |
| 85 virtual NextProtoStatus GetNextProto(std::string* proto) = 0; | 85 virtual NextProtoStatus GetNextProto(std::string* proto) = 0; |
| 86 | 86 |
| 87 static NextProto NextProtoFromString(const std::string& proto_string) { | 87 static NextProto NextProtoFromString(const std::string& proto_string); |
| 88 if (proto_string == "http1.1" || proto_string == "http/1.1") { | |
| 89 return kProtoHTTP11; | |
| 90 } else if (proto_string == "spdy/1") { | |
| 91 return kProtoSPDY1; | |
| 92 } else if (proto_string == "spdy/2") { | |
| 93 return kProtoSPDY2; | |
| 94 } else { | |
| 95 return kProtoUnknown; | |
| 96 } | |
| 97 } | |
| 98 | 88 |
| 99 static bool IgnoreCertError(int error, int load_flags) { | 89 static bool IgnoreCertError(int error, int load_flags); |
| 100 if (error == OK || load_flags & LOAD_IGNORE_ALL_CERT_ERRORS) | |
| 101 return true; | |
| 102 | 90 |
| 103 if (error == ERR_CERT_COMMON_NAME_INVALID && | 91 virtual bool was_npn_negotiated() const; |
| 104 (load_flags & LOAD_IGNORE_CERT_COMMON_NAME_INVALID)) | |
| 105 return true; | |
| 106 if(error == ERR_CERT_DATE_INVALID && | |
| 107 (load_flags & LOAD_IGNORE_CERT_DATE_INVALID)) | |
| 108 return true; | |
| 109 if(error == ERR_CERT_AUTHORITY_INVALID && | |
| 110 (load_flags & LOAD_IGNORE_CERT_AUTHORITY_INVALID)) | |
| 111 return true; | |
| 112 | 92 |
| 113 return false; | 93 virtual bool set_was_npn_negotiated(bool negotiated); |
| 114 } | |
| 115 | |
| 116 virtual bool was_npn_negotiated() const { | |
| 117 return was_npn_negotiated_; | |
| 118 } | |
| 119 | |
| 120 virtual bool set_was_npn_negotiated(bool negotiated) { | |
| 121 return was_npn_negotiated_ = negotiated; | |
| 122 } | |
| 123 | 94 |
| 124 virtual void UseDNSSEC(DNSSECProvider*) { } | 95 virtual void UseDNSSEC(DNSSECProvider*) { } |
| 125 | 96 |
| 126 virtual bool was_spdy_negotiated() const { | 97 virtual bool was_spdy_negotiated() const; |
| 127 return was_spdy_negotiated_; | |
| 128 } | |
| 129 | 98 |
| 130 virtual bool set_was_spdy_negotiated(bool negotiated) { | 99 virtual bool set_was_spdy_negotiated(bool negotiated); |
| 131 return was_spdy_negotiated_ = negotiated; | |
| 132 } | |
| 133 | 100 |
| 134 private: | 101 private: |
| 135 // True if NPN was responded to, independent of selecting SPDY or HTTP. | 102 // True if NPN was responded to, independent of selecting SPDY or HTTP. |
| 136 bool was_npn_negotiated_; | 103 bool was_npn_negotiated_; |
| 137 // True if NPN successfully negotiated SPDY. | 104 // True if NPN successfully negotiated SPDY. |
| 138 bool was_spdy_negotiated_; | 105 bool was_spdy_negotiated_; |
| 139 }; | 106 }; |
| 140 | 107 |
| 141 } // namespace net | 108 } // namespace net |
| 142 | 109 |
| 143 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_H_ | 110 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_H_ |
| OLD | NEW |