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

Side by Side Diff: remoting/jingle_glue/xmpp_signal_strategy.cc

Issue 10378110: Verify that xmpp_login specified in the config matches auth token. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "remoting/jingle_glue/xmpp_signal_strategy.h" 5 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
6 6
7 #include "base/bind.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h"
8 #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" 10 #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h"
9 #include "remoting/jingle_glue/jingle_thread.h" 11 #include "remoting/jingle_glue/jingle_thread.h"
10 #include "remoting/jingle_glue/xmpp_socket_adapter.h" 12 #include "remoting/jingle_glue/xmpp_socket_adapter.h"
11 #include "third_party/libjingle/source/talk/base/asyncsocket.h" 13 #include "third_party/libjingle/source/talk/base/asyncsocket.h"
12 #include "third_party/libjingle/source/talk/xmpp/prexmppauth.h" 14 #include "third_party/libjingle/source/talk/xmpp/prexmppauth.h"
13 #include "third_party/libjingle/source/talk/xmpp/saslcookiemechanism.h" 15 #include "third_party/libjingle/source/talk/xmpp/saslcookiemechanism.h"
14 16
15 namespace { 17 namespace {
16 18
17 const char kDefaultResourceName[] = "chromoting"; 19 const char kDefaultResourceName[] = "chromoting";
18 20
19 // Use 58 seconds keep-alive interval, in case routers terminate 21 // Use 58 seconds keep-alive interval, in case routers terminate
20 // connections that are idle for more than a minute. 22 // connections that are idle for more than a minute.
21 const int kKeepAliveIntervalSeconds = 50; 23 const int kKeepAliveIntervalSeconds = 50;
22 24
25 void DisconnectXmppClient(buzz::XmppClient* client) {
26 client->Disconnect();
27 }
28
23 } // namespace 29 } // namespace
24 30
25 namespace remoting { 31 namespace remoting {
26 32
27 XmppSignalStrategy::XmppSignalStrategy(JingleThread* jingle_thread, 33 XmppSignalStrategy::XmppSignalStrategy(JingleThread* jingle_thread,
28 const std::string& username, 34 const std::string& username,
29 const std::string& auth_token, 35 const std::string& auth_token,
30 const std::string& auth_token_service) 36 const std::string& auth_token_service)
31 : thread_(jingle_thread), 37 : thread_(jingle_thread),
32 username_(username), 38 username_(username),
33 auth_token_(auth_token), 39 auth_token_(auth_token),
34 auth_token_service_(auth_token_service), 40 auth_token_service_(auth_token_service),
35 resource_name_(kDefaultResourceName), 41 resource_name_(kDefaultResourceName),
36 xmpp_client_(NULL), 42 xmpp_client_(NULL),
37 state_(DISCONNECTED) { 43 state_(DISCONNECTED),
44 error_(NO_ERROR) {
38 } 45 }
39 46
40 XmppSignalStrategy::~XmppSignalStrategy() { 47 XmppSignalStrategy::~XmppSignalStrategy() {
41 DCHECK_EQ(listeners_.size(), 0U);
42 Disconnect(); 48 Disconnect();
43 } 49 }
44 50
45 void XmppSignalStrategy::Connect() { 51 void XmppSignalStrategy::Connect() {
46 DCHECK(CalledOnValidThread()); 52 DCHECK(CalledOnValidThread());
47 53
48 // Disconnect first if we are currently connected. 54 // Disconnect first if we are currently connected.
49 Disconnect(); 55 Disconnect();
50 56
51 buzz::XmppClientSettings settings; 57 buzz::XmppClientSettings settings;
(...skipping 30 matching lines...) Expand all
82 // in response to Disconnect() call above. 88 // in response to Disconnect() call above.
83 DCHECK(xmpp_client_ == NULL); 89 DCHECK(xmpp_client_ == NULL);
84 } 90 }
85 } 91 }
86 92
87 SignalStrategy::State XmppSignalStrategy::GetState() const { 93 SignalStrategy::State XmppSignalStrategy::GetState() const {
88 DCHECK(CalledOnValidThread()); 94 DCHECK(CalledOnValidThread());
89 return state_; 95 return state_;
90 } 96 }
91 97
98 SignalStrategy::Error XmppSignalStrategy::GetError() const {
99 DCHECK(CalledOnValidThread());
100 return error_;
101 }
102
92 std::string XmppSignalStrategy::GetLocalJid() const { 103 std::string XmppSignalStrategy::GetLocalJid() const {
93 DCHECK(CalledOnValidThread()); 104 DCHECK(CalledOnValidThread());
94 return xmpp_client_->jid().Str(); 105 return xmpp_client_->jid().Str();
95 } 106 }
96 107
97 void XmppSignalStrategy::AddListener(Listener* listener) { 108 void XmppSignalStrategy::AddListener(Listener* listener) {
98 DCHECK(CalledOnValidThread()); 109 DCHECK(CalledOnValidThread());
99 listeners_.AddObserver(listener); 110 listeners_.AddObserver(listener);
100 } 111 }
101 112
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 158 }
148 159
149 void XmppSignalStrategy::SetResourceName(const std::string &resource_name) { 160 void XmppSignalStrategy::SetResourceName(const std::string &resource_name) {
150 DCHECK(CalledOnValidThread()); 161 DCHECK(CalledOnValidThread());
151 resource_name_ = resource_name; 162 resource_name_ = resource_name;
152 } 163 }
153 164
154 void XmppSignalStrategy::OnConnectionStateChanged( 165 void XmppSignalStrategy::OnConnectionStateChanged(
155 buzz::XmppEngine::State state) { 166 buzz::XmppEngine::State state) {
156 DCHECK(CalledOnValidThread()); 167 DCHECK(CalledOnValidThread());
168
157 if (state == buzz::XmppEngine::STATE_OPEN) { 169 if (state == buzz::XmppEngine::STATE_OPEN) {
170 // Verify that the JID that we've received doesn't match the
simonmorris 2012/05/11 19:57:25 "doesn't match" -> "matches".
Sergey Ulanov 2012/05/11 20:48:05 Done.
171 // username that we have. That probably means that the OAuth token
simonmorris 2012/05/11 19:57:25 "That probably means" -> "If it doesn't, then... w
Sergey Ulanov 2012/05/11 20:48:05 Done.
172 // was issued for a different account, so we treat is a an auth
173 // error.
174 if (!StartsWithASCII(GetLocalJid(), username_, false)) {
simonmorris 2012/05/11 19:57:25 Other cases may be worth considering. I'll follow
175 LOG(ERROR) << "Received JID that is different from the expected value.";
176 error_ = AUTHENTICATION_FAILED;
177 xmpp_client_->SignalStateChange.disconnect(this);
178 MessageLoop::current()->PostTask(
179 FROM_HERE, base::Bind(&DisconnectXmppClient, xmpp_client_));
180 xmpp_client_ = NULL;
181 SetState(DISCONNECTED);
182 return;
183 }
184
158 keep_alive_timer_.Start( 185 keep_alive_timer_.Start(
159 FROM_HERE, base::TimeDelta::FromSeconds(kKeepAliveIntervalSeconds), 186 FROM_HERE, base::TimeDelta::FromSeconds(kKeepAliveIntervalSeconds),
160 this, &XmppSignalStrategy::SendKeepAlive); 187 this, &XmppSignalStrategy::SendKeepAlive);
161 SetState(CONNECTED); 188 SetState(CONNECTED);
162 } else if (state == buzz::XmppEngine::STATE_CLOSED) { 189 } else if (state == buzz::XmppEngine::STATE_CLOSED) {
163 // Make sure we dump errors to the log. 190 // Make sure we dump errors to the log.
164 int subcode; 191 int subcode;
165 buzz::XmppEngine::Error error = xmpp_client_->GetError(&subcode); 192 buzz::XmppEngine::Error error = xmpp_client_->GetError(&subcode);
166 LOG(INFO) << "XMPP connection was closed: error=" << error 193 LOG(INFO) << "XMPP connection was closed: error=" << error
167 << ", subcode=" << subcode; 194 << ", subcode=" << subcode;
168 195
169 keep_alive_timer_.Stop(); 196 keep_alive_timer_.Stop();
170 197
171 // Client is destroyed by the TaskRunner after the client is 198 // Client is destroyed by the TaskRunner after the client is
172 // closed. Reset the pointer so we don't try to use it later. 199 // closed. Reset the pointer so we don't try to use it later.
173 xmpp_client_ = NULL; 200 xmpp_client_ = NULL;
201
202 switch (error) {
203 case buzz::XmppEngine::ERROR_UNAUTHORIZED:
204 case buzz::XmppEngine::ERROR_AUTH:
205 case buzz::XmppEngine::ERROR_MISSING_USERNAME:
206 error_ = AUTHENTICATION_FAILED;
207 break;
208
209 default:
210 error_ = NETWORK_ERROR;
211 }
212
174 SetState(DISCONNECTED); 213 SetState(DISCONNECTED);
175 } 214 }
176 } 215 }
177 216
178 void XmppSignalStrategy::SetState(State new_state) { 217 void XmppSignalStrategy::SetState(State new_state) {
179 if (state_ != new_state) { 218 if (state_ != new_state) {
180 state_ = new_state; 219 state_ = new_state;
181 FOR_EACH_OBSERVER(Listener, listeners_, 220 FOR_EACH_OBSERVER(Listener, listeners_,
182 OnSignalStrategyStateChange(new_state)); 221 OnSignalStrategyStateChange(new_state));
183 } 222 }
(...skipping 10 matching lines...) Expand all
194 std::string mechanism = notifier::GaiaTokenPreXmppAuth::kDefaultAuthMechanism; 233 std::string mechanism = notifier::GaiaTokenPreXmppAuth::kDefaultAuthMechanism;
195 if (settings.token_service() == "oauth2") { 234 if (settings.token_service() == "oauth2") {
196 mechanism = "X-OAUTH2"; 235 mechanism = "X-OAUTH2";
197 } 236 }
198 237
199 return new notifier::GaiaTokenPreXmppAuth( 238 return new notifier::GaiaTokenPreXmppAuth(
200 jid.Str(), settings.auth_cookie(), settings.token_service(), mechanism); 239 jid.Str(), settings.auth_cookie(), settings.token_service(), mechanism);
201 } 240 }
202 241
203 } // namespace remoting 242 } // namespace remoting
OLDNEW
« remoting/jingle_glue/signal_strategy.h ('K') | « remoting/jingle_glue/xmpp_signal_strategy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698