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

Side by Side Diff: extensions/browser/api/cast_channel/cast_socket.cc

Issue 2709523008: [Cast Channel] Add support for nonce challenge to Cast channel authentication. (Closed)
Patch Set: Addresses comments Created 3 years, 9 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/cast_channel/cast_socket.h" 5 #include "extensions/browser/api/cast_channel/cast_socket.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 107 }
108 108
109 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, 109 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id,
110 const net::IPEndPoint& ip_endpoint, 110 const net::IPEndPoint& ip_endpoint,
111 ChannelAuthType channel_auth, 111 ChannelAuthType channel_auth,
112 net::NetLog* net_log, 112 net::NetLog* net_log,
113 const base::TimeDelta& timeout, 113 const base::TimeDelta& timeout,
114 bool keep_alive, 114 bool keep_alive,
115 const scoped_refptr<Logger>& logger, 115 const scoped_refptr<Logger>& logger,
116 uint64_t device_capabilities) 116 uint64_t device_capabilities)
117 : CastSocketImpl(owner_extension_id,
118 ip_endpoint,
119 channel_auth,
120 net_log,
121 timeout,
122 keep_alive,
123 logger,
124 device_capabilities,
125 GetChallengeContext()) {}
126
127 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id,
128 const net::IPEndPoint& ip_endpoint,
129 ChannelAuthType channel_auth,
130 net::NetLog* net_log,
131 const base::TimeDelta& timeout,
132 bool keep_alive,
133 const scoped_refptr<Logger>& logger,
134 uint64_t device_capabilities,
135 std::unique_ptr<AuthContext> auth_context)
117 : CastSocket(owner_extension_id), 136 : CastSocket(owner_extension_id),
118 owner_extension_id_(owner_extension_id), 137 owner_extension_id_(owner_extension_id),
119 channel_id_(0), 138 channel_id_(0),
120 ip_endpoint_(ip_endpoint), 139 ip_endpoint_(ip_endpoint),
121 channel_auth_(channel_auth), 140 channel_auth_(channel_auth),
122 net_log_(net_log), 141 net_log_(net_log),
123 keep_alive_(keep_alive), 142 keep_alive_(keep_alive),
124 logger_(logger), 143 logger_(logger),
144 auth_context_(std::move(auth_context)),
125 connect_timeout_(timeout), 145 connect_timeout_(timeout),
126 connect_timeout_timer_(new base::OneShotTimer), 146 connect_timeout_timer_(new base::OneShotTimer),
127 is_canceled_(false), 147 is_canceled_(false),
128 device_capabilities_(device_capabilities), 148 device_capabilities_(device_capabilities),
129 audio_only_(false), 149 audio_only_(false),
130 connect_state_(proto::CONN_STATE_START_CONNECT), 150 connect_state_(proto::CONN_STATE_START_CONNECT),
131 error_state_(CHANNEL_ERROR_NONE), 151 error_state_(CHANNEL_ERROR_NONE),
132 ready_state_(READY_STATE_NONE), 152 ready_state_(READY_STATE_NONE),
133 auth_delegate_(nullptr) { 153 auth_delegate_(nullptr) {
134 DCHECK(net_log_); 154 DCHECK(net_log_);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 << "Audio only channel policy enforced for video out capable device"; 247 << "Audio only channel policy enforced for video out capable device";
228 logger_->LogSocketEventWithDetails( 248 logger_->LogSocketEventWithDetails(
229 channel_id_, proto::CHANNEL_POLICY_ENFORCED, std::string()); 249 channel_id_, proto::CHANNEL_POLICY_ENFORCED, std::string());
230 return false; 250 return false;
231 } 251 }
232 return true; 252 return true;
233 } 253 }
234 254
235 bool CastSocketImpl::VerifyChallengeReply() { 255 bool CastSocketImpl::VerifyChallengeReply() {
236 DCHECK(peer_cert_); 256 DCHECK(peer_cert_);
237 AuthResult result = 257 AuthResult result = AuthenticateChallengeReply(*challenge_reply_, *peer_cert_,
238 AuthenticateChallengeReply(*challenge_reply_, *peer_cert_); 258 auth_context_.get());
239 logger_->LogSocketChallengeReplyEvent(channel_id_, result); 259 logger_->LogSocketChallengeReplyEvent(channel_id_, result);
240 if (result.success()) { 260 if (result.success()) {
241 VLOG(1) << result.error_message; 261 VLOG(1) << result.error_message;
242 if (!VerifyChannelPolicy(result)) { 262 if (!VerifyChannelPolicy(result)) {
243 return false; 263 return false;
244 } 264 }
245 } 265 }
246 return result.success(); 266 return result.success();
247 } 267 }
248 268
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 SetErrorState(CHANNEL_ERROR_AUTHENTICATION_ERROR); 463 SetErrorState(CHANNEL_ERROR_AUTHENTICATION_ERROR);
444 } 464 }
445 return result; 465 return result;
446 } 466 }
447 467
448 int CastSocketImpl::DoAuthChallengeSend() { 468 int CastSocketImpl::DoAuthChallengeSend() {
449 VLOG_WITH_CONNECTION(1) << "DoAuthChallengeSend"; 469 VLOG_WITH_CONNECTION(1) << "DoAuthChallengeSend";
450 SetConnectState(proto::CONN_STATE_AUTH_CHALLENGE_SEND_COMPLETE); 470 SetConnectState(proto::CONN_STATE_AUTH_CHALLENGE_SEND_COMPLETE);
451 471
452 CastMessage challenge_message; 472 CastMessage challenge_message;
453 CreateAuthChallengeMessage(&challenge_message); 473 CreateAuthChallengeMessage(&challenge_message, auth_context_.get());
454 VLOG_WITH_CONNECTION(1) << "Sending challenge: " 474 VLOG_WITH_CONNECTION(1) << "Sending challenge: "
455 << CastMessageToString(challenge_message); 475 << CastMessageToString(challenge_message);
456 476
457 transport_->SendMessage( 477 transport_->SendMessage(
458 challenge_message, 478 challenge_message,
459 base::Bind(&CastSocketImpl::DoConnectLoop, base::Unretained(this))); 479 base::Bind(&CastSocketImpl::DoConnectLoop, base::Unretained(this)));
460 480
461 // Always return IO_PENDING since the result is always asynchronous. 481 // Always return IO_PENDING since the result is always asynchronous.
462 return net::ERR_IO_PENDING; 482 return net::ERR_IO_PENDING;
463 } 483 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 } 631 }
612 } 632 }
613 633
614 void CastSocketImpl::SetErrorState(ChannelError error_state) { 634 void CastSocketImpl::SetErrorState(ChannelError error_state) {
615 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; 635 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state;
616 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); 636 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_);
617 error_state_ = error_state; 637 error_state_ = error_state;
618 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_)); 638 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_));
619 delegate_->OnError(error_state_); 639 delegate_->OnError(error_state_);
620 } 640 }
641
621 } // namespace cast_channel 642 } // namespace cast_channel
622 } // namespace api 643 } // namespace api
623 } // namespace extensions 644 } // namespace extensions
624 #undef VLOG_WITH_CONNECTION 645 #undef VLOG_WITH_CONNECTION
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698