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

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 void SendAuthChallenge();
121 // Verifies whether the challenge reply received from the peer is valid:
122 // 1. Signature in the reply is valid.
123 // 2. Certificate is rooted to a trusted CA.
124 virtual bool VerifyChallengeReply();
119 125
120 private: 126 private:
121 friend class ApiResourceManager<CastSocket>; 127 friend class ApiResourceManager<CastSocket>;
122 static const char* service_name() { 128 static const char* service_name() {
123 return "CastSocketManager"; 129 return "CastSocketManager";
124 } 130 }
125 131
126 // Internal connection states. 132 // Internal connection states.
127 enum ConnectionState { 133 enum ConnectionState {
128 CONN_STATE_NONE, 134 CONN_STATE_NONE,
129 CONN_STATE_TCP_CONNECT, 135 CONN_STATE_TCP_CONNECT,
130 CONN_STATE_TCP_CONNECT_COMPLETE, 136 CONN_STATE_TCP_CONNECT_COMPLETE,
131 CONN_STATE_SSL_CONNECT, 137 CONN_STATE_SSL_CONNECT,
132 CONN_STATE_SSL_CONNECT_COMPLETE, 138 CONN_STATE_SSL_CONNECT_COMPLETE,
139 CONN_STATE_AUTH_CHALLENGE_SEND,
140 CONN_STATE_AUTH_CHALLENGE_SEND_COMPLETE,
141 CONN_STATE_AUTH_CHALLENGE_REPLY_COMPLETE,
133 }; 142 };
134 143
135 ///////////////////////////////////////////////////////////////////////////// 144 /////////////////////////////////////////////////////////////////////////////
136 // Following methods work together to implement the following flow: 145 // Following methods work together to implement the following flow:
137 // 1. Create a new TCP socket and connect to it 146 // 1. Create a new TCP socket and connect to it
138 // 2. Create a new SSL socket and try connecting to it 147 // 2. Create a new SSL socket and try connecting to it
139 // 3. If connection fails due to invalid cert authority, then extract the 148 // 3. If connection fails due to invalid cert authority, then extract the
140 // peer certificate from the error. 149 // peer certificate from the error.
141 // 4. Whitelist the peer certificate and try #1 and #2 again. 150 // 4. Whitelist the peer certificate and try #1 and #2 again.
151 // 5. If SSL socket is connected successfully, and if protocol is casts://
152 // then issue an auth challenge request.
153 // 6. Validate the auth challenge response.
142 154
143 // Main method that performs connection state transitions. 155 // Main method that performs connection state transitions.
144 int DoConnectLoop(int result); 156 int DoConnectLoop(int result);
145 // Each of the below Do* method is executed in the corresponding 157 // Each of the below Do* method is executed in the corresponding
146 // connection state. For e.g. when connection state is TCP_CONNECT 158 // connection state. For e.g. when connection state is TCP_CONNECT
147 // DoTcpConnect is called, and so on. 159 // DoTcpConnect is called, and so on.
148 int DoTcpConnect(); 160 int DoTcpConnect();
149 int DoTcpConnectComplete(int result); 161 int DoTcpConnectComplete(int result);
150 int DoSslConnect(); 162 int DoSslConnect();
151 int DoSslConnectComplete(int result); 163 int DoSslConnectComplete(int result);
152 int DoSslConnectRetry(); 164 int DoAuthChallengeSend();
165 int DoAuthChallengeSendComplete(int result);
166 int DoAuthChallengeReplyComplete(int result);
153 ///////////////////////////////////////////////////////////////////////////// 167 /////////////////////////////////////////////////////////////////////////////
154 168
155 // Callback method for callbacks from underlying sockets. 169 // Callback method for callbacks from underlying sockets.
156 void OnConnectComplete(int result); 170 void OnConnectComplete(int result);
157 171
172 // Callback method when a challenge request is sent or a reply is received.
173 void OnChallengeEvent(int result);
174
158 // Runs the external connection callback and resets it. 175 // Runs the external connection callback and resets it.
159 void DoConnectCallback(int result); 176 void DoConnectCallback(int result);
160 177
161 // Verifies that the URL is a valid cast:// or casts:// URL and sets url_ to 178 // Verifies that the URL is a valid cast:// or casts:// URL and sets url_ to
162 // the result. 179 // the result.
163 bool ParseChannelUrl(const GURL& url); 180 bool ParseChannelUrl(const GURL& url);
164 181
182 // Verify that |certificate| is rooted to a trusted CA and that |signature|
183 // matches |data|.
184 bool VerifyCredentials(const std::string& certificate,
185 const std::string& signature,
186 const std::string& data);
187
188 // Sends the given |message| and invokes the given callback when done.
189 void SendMessageInternal(const CastMessage& message,
190 const net::CompletionCallback& callback);
191
165 // Writes data to the socket from the WriteRequest at the head of the queue. 192 // Writes data to the socket from the WriteRequest at the head of the queue.
166 // Calls OnWriteData() on completion. 193 // Calls OnWriteData() on completion.
167 void WriteData(); 194 void WriteData();
168 void OnWriteData(int result); 195 void OnWriteData(int result);
169 196
170 // Reads data from the socket into one of the read buffers. Calls 197 // Reads data from the socket into one of the read buffers. Calls
171 // OnReadData() on completion. 198 // OnReadData() on completion.
172 void ReadData(); 199 void ReadData();
173 void OnReadData(int result); 200 void OnReadData(int result);
174 201
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 ConnectionState next_state_; 254 ConnectionState next_state_;
228 // Owned ptr to the underlying TCP socket. 255 // Owned ptr to the underlying TCP socket.
229 scoped_ptr<net::TCPClientSocket> tcp_socket_; 256 scoped_ptr<net::TCPClientSocket> tcp_socket_;
230 // Owned ptr to the underlying SSL socket. 257 // Owned ptr to the underlying SSL socket.
231 scoped_ptr<net::SSLClientSocket> socket_; 258 scoped_ptr<net::SSLClientSocket> socket_;
232 // Certificate of the peer. This field may be empty if the peer 259 // Certificate of the peer. This field may be empty if the peer
233 // certificate is not yet fetched. 260 // certificate is not yet fetched.
234 std::string peer_cert_; 261 std::string peer_cert_;
235 scoped_ptr<net::CertVerifier> cert_verifier_; 262 scoped_ptr<net::CertVerifier> cert_verifier_;
236 scoped_ptr<net::TransportSecurityState> transport_security_state_; 263 scoped_ptr<net::TransportSecurityState> transport_security_state_;
264 // Reply received from the receiver to a challenge request.
265 scoped_ptr<CastMessage> challenge_reply_;
237 266
238 // Callback invoked when the socket is connected. 267 // Callback invoked when the socket is connected.
239 net::CompletionCallback connect_callback_; 268 net::CompletionCallback connect_callback_;
240 269
241 // Message header struct. If fields are added, be sure to update 270 // Message header struct. If fields are added, be sure to update
242 // kMessageHeaderSize in the .cc. 271 // kMessageHeaderSize in the .cc.
243 struct MessageHeader { 272 struct MessageHeader {
244 MessageHeader(); 273 MessageHeader();
245 // Sets the message size. 274 // Sets the message size.
246 void SetMessageSize(size_t message_size); 275 void SetMessageSize(size_t message_size);
(...skipping 27 matching lines...) Expand all
274 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestRead); 303 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestRead);
275 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadMany); 304 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadMany);
276 DISALLOW_COPY_AND_ASSIGN(CastSocket); 305 DISALLOW_COPY_AND_ASSIGN(CastSocket);
277 }; 306 };
278 307
279 } // namespace cast_channel 308 } // namespace cast_channel
280 } // namespace api 309 } // namespace api
281 } // namespace extensions 310 } // namespace extensions
282 311
283 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ 312 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698