Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: chrome/browser/extensions/api/cast_channel/cast_socket.h

Issue 35443002: Update CastSocket connection flow to check for receiver credentials. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 10
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 protected: 110 protected:
111 // Creates an instance of TCPClientSocket. 111 // Creates an instance of TCPClientSocket.
112 virtual scoped_ptr<net::TCPClientSocket> CreateTcpSocket(); 112 virtual scoped_ptr<net::TCPClientSocket> CreateTcpSocket();
113 // Creates an instance of SSLClientSocket. 113 // Creates an instance of SSLClientSocket.
114 virtual scoped_ptr<net::SSLClientSocket> CreateSslSocket(); 114 virtual scoped_ptr<net::SSLClientSocket> CreateSslSocket();
115 // Extracts peer certificate from SSLClientSocket instance when the socket 115 // Extracts peer certificate from SSLClientSocket instance when the socket
116 // is in cert error state. 116 // is in cert error state.
117 // Returns whether certificate is successfully extracted. 117 // Returns whether certificate is successfully extracted.
118 virtual bool ExtractPeerCert(std::string* cert); 118 virtual bool ExtractPeerCert(std::string* cert);
119 // Sends a challenge request to the receiver.
120 virtual int SendAuthChallenge();
121 // Reads auth challenge reply from the receiver.
122 virtual int ReadAuthChallengeReply();
123 // Verifies whether the challenge reply received from the peer is valid:
124 // 1. Signature in the reply is valid.
125 // 2. Certificate is rooted to a trusted CA.
126 virtual bool VerifyChallengeReply();
119 127
120 private: 128 private:
121 friend class ApiResourceManager<CastSocket>; 129 friend class ApiResourceManager<CastSocket>;
130 friend class CastSocketTest;
131
122 static const char* service_name() { 132 static const char* service_name() {
123 return "CastSocketManager"; 133 return "CastSocketManager";
124 } 134 }
125 135
126 // Internal connection states. 136 // Internal connection states.
127 enum ConnectionState { 137 enum ConnectionState {
128 CONN_STATE_NONE, 138 CONN_STATE_NONE,
129 CONN_STATE_TCP_CONNECT, 139 CONN_STATE_TCP_CONNECT,
130 CONN_STATE_TCP_CONNECT_COMPLETE, 140 CONN_STATE_TCP_CONNECT_COMPLETE,
131 CONN_STATE_SSL_CONNECT, 141 CONN_STATE_SSL_CONNECT,
132 CONN_STATE_SSL_CONNECT_COMPLETE, 142 CONN_STATE_SSL_CONNECT_COMPLETE,
143 CONN_STATE_AUTH_CHALLENGE_SEND,
144 CONN_STATE_AUTH_CHALLENGE_SEND_COMPLETE,
145 CONN_STATE_AUTH_CHALLENGE_REPLY_COMPLETE,
133 }; 146 };
134 147
135 ///////////////////////////////////////////////////////////////////////////// 148 /////////////////////////////////////////////////////////////////////////////
136 // Following methods work together to implement the following flow: 149 // Following methods work together to implement the following flow:
137 // 1. Create a new TCP socket and connect to it 150 // 1. Create a new TCP socket and connect to it
138 // 2. Create a new SSL socket and try connecting to it 151 // 2. Create a new SSL socket and try connecting to it
139 // 3. If connection fails due to invalid cert authority, then extract the 152 // 3. If connection fails due to invalid cert authority, then extract the
140 // peer certificate from the error. 153 // peer certificate from the error.
141 // 4. Whitelist the peer certificate and try #1 and #2 again. 154 // 4. Whitelist the peer certificate and try #1 and #2 again.
155 // 5. If SSL socket is connected successfully, and if protocol is casts://
156 // then issue an auth challenge request.
157 // 6. Validate the auth challenge response.
142 158
143 // Main method that performs connection state transitions. 159 // Main method that performs connection state transitions.
144 int DoConnectLoop(int result); 160 int DoConnectLoop(int result);
145 // Each of the below Do* method is executed in the corresponding 161 // Each of the below Do* method is executed in the corresponding
146 // connection state. For e.g. when connection state is TCP_CONNECT 162 // connection state. For e.g. when connection state is TCP_CONNECT
147 // DoTcpConnect is called, and so on. 163 // DoTcpConnect is called, and so on.
148 int DoTcpConnect(); 164 int DoTcpConnect();
149 int DoTcpConnectComplete(int result); 165 int DoTcpConnectComplete(int result);
150 int DoSslConnect(); 166 int DoSslConnect();
151 int DoSslConnectComplete(int result); 167 int DoSslConnectComplete(int result);
152 int DoSslConnectRetry(); 168 int DoAuthChallengeSend();
169 int DoAuthChallengeSendComplete(int result);
170 int DoAuthChallengeReplyComplete(int result);
153 ///////////////////////////////////////////////////////////////////////////// 171 /////////////////////////////////////////////////////////////////////////////
154 172
155 // Callback method for callbacks from underlying sockets. 173 // Callback method for callbacks from underlying sockets.
156 void OnConnectComplete(int result); 174 void OnConnectComplete(int result);
157 175
176 // Callback method when a challenge request is sent or a reply is received.
177 void OnChallengeEvent(int result);
178
158 // Runs the external connection callback and resets it. 179 // Runs the external connection callback and resets it.
159 void DoConnectCallback(int result); 180 void DoConnectCallback(int result);
160 181
161 // Verifies that the URL is a valid cast:// or casts:// URL and sets url_ to 182 // Verifies that the URL is a valid cast:// or casts:// URL and sets url_ to
162 // the result. 183 // the result.
163 bool ParseChannelUrl(const GURL& url); 184 bool ParseChannelUrl(const GURL& url);
164 185
186 // Sends the given |message| and invokes the given callback when done.
187 int SendMessageInternal(const CastMessage& message,
188 const net::CompletionCallback& callback);
189
165 // Writes data to the socket from the WriteRequest at the head of the queue. 190 // Writes data to the socket from the WriteRequest at the head of the queue.
166 // Calls OnWriteData() on completion. 191 // Calls OnWriteData() on completion.
167 void WriteData(); 192 int WriteData();
168 void OnWriteData(int result); 193 void OnWriteData(int result);
169 194
170 // Reads data from the socket into one of the read buffers. Calls 195 // Reads data from the socket into one of the read buffers. Calls
171 // OnReadData() on completion. 196 // OnReadData() on completion.
172 void ReadData(); 197 int ReadData();
173 void OnReadData(int result); 198 void OnReadData(int result);
174 199
175 // Processes the contents of header_read_buffer_ and returns true on success. 200 // Processes the contents of header_read_buffer_ and returns true on success.
176 bool ProcessHeader(); 201 bool ProcessHeader();
177 // Processes the contents of body_read_buffer_ and returns true on success. 202 // Processes the contents of body_read_buffer_ and returns true on success.
178 bool ProcessBody(); 203 bool ProcessBody();
179 // Parses the message held in body_read_buffer_ and notifies |delegate_| if a 204 // Parses the message held in body_read_buffer_ and notifies |delegate_| if a
180 // message was extracted from the buffer. Returns true on success. 205 // message was extracted from the buffer. Returns true on success.
181 bool ParseMessageFromBody(); 206 bool ParseMessageFromBody();
182 207
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 ConnectionState next_state_; 252 ConnectionState next_state_;
228 // Owned ptr to the underlying TCP socket. 253 // Owned ptr to the underlying TCP socket.
229 scoped_ptr<net::TCPClientSocket> tcp_socket_; 254 scoped_ptr<net::TCPClientSocket> tcp_socket_;
230 // Owned ptr to the underlying SSL socket. 255 // Owned ptr to the underlying SSL socket.
231 scoped_ptr<net::SSLClientSocket> socket_; 256 scoped_ptr<net::SSLClientSocket> socket_;
232 // Certificate of the peer. This field may be empty if the peer 257 // Certificate of the peer. This field may be empty if the peer
233 // certificate is not yet fetched. 258 // certificate is not yet fetched.
234 std::string peer_cert_; 259 std::string peer_cert_;
235 scoped_ptr<net::CertVerifier> cert_verifier_; 260 scoped_ptr<net::CertVerifier> cert_verifier_;
236 scoped_ptr<net::TransportSecurityState> transport_security_state_; 261 scoped_ptr<net::TransportSecurityState> transport_security_state_;
262 // Reply received from the receiver to a challenge request.
263 scoped_ptr<CastMessage> challenge_reply_;
237 264
238 // Callback invoked when the socket is connected. 265 // Callback invoked when the socket is connected.
239 net::CompletionCallback connect_callback_; 266 net::CompletionCallback connect_callback_;
240 267
241 // Message header struct. If fields are added, be sure to update 268 // Message header struct. If fields are added, be sure to update
242 // kMessageHeaderSize in the .cc. 269 // kMessageHeaderSize in the .cc.
243 struct MessageHeader { 270 struct MessageHeader {
244 MessageHeader(); 271 MessageHeader();
245 // Sets the message size. 272 // Sets the message size.
246 void SetMessageSize(size_t message_size); 273 void SetMessageSize(size_t message_size);
(...skipping 27 matching lines...) Expand all
274 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestRead); 301 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestRead);
275 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadMany); 302 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadMany);
276 DISALLOW_COPY_AND_ASSIGN(CastSocket); 303 DISALLOW_COPY_AND_ASSIGN(CastSocket);
277 }; 304 };
278 305
279 } // namespace cast_channel 306 } // namespace cast_channel
280 } // namespace api 307 } // namespace api
281 } // namespace extensions 308 } // namespace extensions
282 309
283 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ 310 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698