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

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: Created 3 years, 10 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 return true; 106 return true;
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 const std::string& nonce)
117 : CastSocket(owner_extension_id), 118 : CastSocket(owner_extension_id),
118 owner_extension_id_(owner_extension_id), 119 owner_extension_id_(owner_extension_id),
119 channel_id_(0), 120 channel_id_(0),
120 ip_endpoint_(ip_endpoint), 121 ip_endpoint_(ip_endpoint),
121 channel_auth_(channel_auth), 122 channel_auth_(channel_auth),
122 net_log_(net_log), 123 net_log_(net_log),
123 keep_alive_(keep_alive), 124 keep_alive_(keep_alive),
124 logger_(logger), 125 logger_(logger),
125 connect_timeout_(timeout), 126 connect_timeout_(timeout),
126 connect_timeout_timer_(new base::OneShotTimer), 127 connect_timeout_timer_(new base::OneShotTimer),
127 is_canceled_(false), 128 is_canceled_(false),
128 device_capabilities_(device_capabilities), 129 device_capabilities_(device_capabilities),
129 audio_only_(false), 130 audio_only_(false),
130 connect_state_(proto::CONN_STATE_START_CONNECT), 131 connect_state_(proto::CONN_STATE_START_CONNECT),
131 error_state_(CHANNEL_ERROR_NONE), 132 error_state_(CHANNEL_ERROR_NONE),
132 ready_state_(READY_STATE_NONE), 133 ready_state_(READY_STATE_NONE),
133 auth_delegate_(nullptr) { 134 auth_delegate_(nullptr),
135 nonce_(nonce) {
134 DCHECK(net_log_); 136 DCHECK(net_log_);
135 net_log_source_.type = net::NetLogSourceType::SOCKET; 137 net_log_source_.type = net::NetLogSourceType::SOCKET;
136 net_log_source_.id = net_log_->NextID(); 138 net_log_source_.id = net_log_->NextID();
137 } 139 }
138 140
139 CastSocketImpl::~CastSocketImpl() { 141 CastSocketImpl::~CastSocketImpl() {
140 // Ensure that resources are freed but do not run pending callbacks to avoid 142 // Ensure that resources are freed but do not run pending callbacks to avoid
141 // any re-entrancy. 143 // any re-entrancy.
142 CloseInternal(); 144 CloseInternal();
143 } 145 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 logger_->LogSocketEventWithDetails( 230 logger_->LogSocketEventWithDetails(
229 channel_id_, proto::CHANNEL_POLICY_ENFORCED, std::string()); 231 channel_id_, proto::CHANNEL_POLICY_ENFORCED, std::string());
230 return false; 232 return false;
231 } 233 }
232 return true; 234 return true;
233 } 235 }
234 236
235 bool CastSocketImpl::VerifyChallengeReply() { 237 bool CastSocketImpl::VerifyChallengeReply() {
236 DCHECK(peer_cert_); 238 DCHECK(peer_cert_);
237 AuthResult result = 239 AuthResult result =
238 AuthenticateChallengeReply(*challenge_reply_, *peer_cert_); 240 AuthenticateChallengeReply(*challenge_reply_, *peer_cert_, nonce_);
239 logger_->LogSocketChallengeReplyEvent(channel_id_, result); 241 logger_->LogSocketChallengeReplyEvent(channel_id_, result);
240 if (result.success()) { 242 if (result.success()) {
241 VLOG(1) << result.error_message; 243 VLOG(1) << result.error_message;
242 if (!VerifyChannelPolicy(result)) { 244 if (!VerifyChannelPolicy(result)) {
243 return false; 245 return false;
244 } 246 }
245 } 247 }
246 return result.success(); 248 return result.success();
247 } 249 }
248 250
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 SetErrorState(CHANNEL_ERROR_AUTHENTICATION_ERROR); 445 SetErrorState(CHANNEL_ERROR_AUTHENTICATION_ERROR);
444 } 446 }
445 return result; 447 return result;
446 } 448 }
447 449
448 int CastSocketImpl::DoAuthChallengeSend() { 450 int CastSocketImpl::DoAuthChallengeSend() {
449 VLOG_WITH_CONNECTION(1) << "DoAuthChallengeSend"; 451 VLOG_WITH_CONNECTION(1) << "DoAuthChallengeSend";
450 SetConnectState(proto::CONN_STATE_AUTH_CHALLENGE_SEND_COMPLETE); 452 SetConnectState(proto::CONN_STATE_AUTH_CHALLENGE_SEND_COMPLETE);
451 453
452 CastMessage challenge_message; 454 CastMessage challenge_message;
453 CreateAuthChallengeMessage(&challenge_message); 455 CreateAuthChallengeMessage(&challenge_message, nonce_);
454 VLOG_WITH_CONNECTION(1) << "Sending challenge: " 456 VLOG_WITH_CONNECTION(1) << "Sending challenge: "
455 << CastMessageToString(challenge_message); 457 << CastMessageToString(challenge_message);
456 458
457 transport_->SendMessage( 459 transport_->SendMessage(
458 challenge_message, 460 challenge_message,
459 base::Bind(&CastSocketImpl::DoConnectLoop, base::Unretained(this))); 461 base::Bind(&CastSocketImpl::DoConnectLoop, base::Unretained(this)));
460 462
461 // Always return IO_PENDING since the result is always asynchronous. 463 // Always return IO_PENDING since the result is always asynchronous.
462 return net::ERR_IO_PENDING; 464 return net::ERR_IO_PENDING;
463 } 465 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; 617 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state;
616 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); 618 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_);
617 error_state_ = error_state; 619 error_state_ = error_state;
618 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_)); 620 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_));
619 delegate_->OnError(error_state_); 621 delegate_->OnError(error_state_);
620 } 622 }
621 } // namespace cast_channel 623 } // namespace cast_channel
622 } // namespace api 624 } // namespace api
623 } // namespace extensions 625 } // namespace extensions
624 #undef VLOG_WITH_CONNECTION 626 #undef VLOG_WITH_CONNECTION
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698