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

Side by Side Diff: chrome/common/net/notifier/communicator/single_login_attempt.cc

Issue 2724010: Revert 49298 - Broke compile - Token-based authentication for chromoting.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "chrome/common/net/notifier/communicator/single_login_attempt.h" 9 #include "chrome/common/net/notifier/communicator/single_login_attempt.h"
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "chrome/common/net/notifier/communicator/connection_options.h" 12 #include "chrome/common/net/notifier/communicator/connection_options.h"
13 #include "chrome/common/net/notifier/communicator/connection_settings.h" 13 #include "chrome/common/net/notifier/communicator/connection_settings.h"
14 #include "chrome/common/net/notifier/communicator/const_communicator.h" 14 #include "chrome/common/net/notifier/communicator/const_communicator.h"
15 #include "chrome/common/net/notifier/communicator/gaia_token_pre_xmpp_auth.h"
16 #include "chrome/common/net/notifier/communicator/login_failure.h" 15 #include "chrome/common/net/notifier/communicator/login_failure.h"
17 #include "chrome/common/net/notifier/communicator/login_settings.h" 16 #include "chrome/common/net/notifier/communicator/login_settings.h"
18 #include "chrome/common/net/notifier/communicator/product_info.h" 17 #include "chrome/common/net/notifier/communicator/product_info.h"
19 #include "chrome/common/net/notifier/communicator/xmpp_connection_generator.h" 18 #include "chrome/common/net/notifier/communicator/xmpp_connection_generator.h"
20 #include "chrome/common/net/notifier/communicator/xmpp_socket_adapter.h" 19 #include "chrome/common/net/notifier/communicator/xmpp_socket_adapter.h"
21 #include "talk/base/asynchttprequest.h" 20 #include "talk/base/asynchttprequest.h"
22 #include "talk/base/firewallsocketserver.h" 21 #include "talk/base/firewallsocketserver.h"
23 #include "talk/base/signalthread.h" 22 #include "talk/base/signalthread.h"
24 #include "talk/base/taskrunner.h" 23 #include "talk/base/taskrunner.h"
25 #include "talk/base/win32socketinit.h" 24 #include "talk/base/win32socketinit.h"
26 #include "talk/xmllite/xmlelement.h" 25 #include "talk/xmllite/xmlelement.h"
26 #include "talk/xmpp/prexmppauth.h"
27 #include "talk/xmpp/saslcookiemechanism.h"
27 #include "talk/xmpp/xmppclient.h" 28 #include "talk/xmpp/xmppclient.h"
28 #include "talk/xmpp/xmppclientsettings.h" 29 #include "talk/xmpp/xmppclientsettings.h"
29 #include "talk/xmpp/constants.h" 30 #include "talk/xmpp/constants.h"
30 31
31 namespace notifier { 32 namespace notifier {
32 33
33 static void GetClientErrorInformation( 34 static void GetClientErrorInformation(
34 buzz::XmppClient* client, 35 buzz::XmppClient* client,
35 buzz::XmppEngine::Error* error, 36 buzz::XmppEngine::Error* error,
36 int* subcode, 37 int* subcode,
37 buzz::XmlElement** stream_error) { 38 buzz::XmlElement** stream_error) {
38 DCHECK(client); 39 DCHECK(client);
39 DCHECK(error); 40 DCHECK(error);
40 DCHECK(subcode); 41 DCHECK(subcode);
41 DCHECK(stream_error); 42 DCHECK(stream_error);
42 43
43 *error = client->GetError(subcode); 44 *error = client->GetError(subcode);
44 45
45 *stream_error = NULL; 46 *stream_error = NULL;
46 if (*error == buzz::XmppEngine::ERROR_STREAM) { 47 if (*error == buzz::XmppEngine::ERROR_STREAM) {
47 const buzz::XmlElement* error_element = client->GetStreamError(); 48 const buzz::XmlElement* error_element = client->GetStreamError();
48 if (error_element) { 49 if (error_element) {
49 *stream_error = new buzz::XmlElement(*error_element); 50 *stream_error = new buzz::XmlElement(*error_element);
50 } 51 }
51 } 52 }
52 } 53 }
53 54
55 namespace {
56
57 const char kGaiaAuthMechanism[] = "X-GOOGLE-TOKEN";
58
59 // This class looks for the X-GOOGLE-TOKEN auth mechanism and uses
60 // that instead of the default auth mechanism (PLAIN).
61 class GaiaTokenPreXmppAuth : public buzz::PreXmppAuth {
62 public:
63 GaiaTokenPreXmppAuth(
64 const std::string& username,
65 const std::string& token,
66 const std::string& token_service)
67 : username_(username),
68 token_(token),
69 token_service_(token_service) {}
70
71 virtual ~GaiaTokenPreXmppAuth() {}
72
73 // buzz::PreXmppAuth (-buzz::SaslHandler) implementation. We stub
74 // all the methods out as we don't actually do any authentication at
75 // this point.
76
77 virtual void StartPreXmppAuth(
78 const buzz::Jid& jid,
79 const talk_base::SocketAddress& server,
80 const talk_base::CryptString& pass,
81 const std::string& auth_cookie) {
82 SignalAuthDone();
83 }
84
85 virtual bool IsAuthDone() const { return true; }
86
87 virtual bool IsAuthorized() const { return true; }
88
89 virtual bool HadError() const { return false; }
90
91 virtual int GetError() const { return 0; }
92
93 virtual buzz::CaptchaChallenge GetCaptchaChallenge() const {
94 return buzz::CaptchaChallenge();
95 }
96
97 virtual std::string GetAuthCookie() const { return std::string(); }
98
99 // buzz::SaslHandler implementation.
100
101 virtual std::string ChooseBestSaslMechanism(
102 const std::vector<std::string> & mechanisms, bool encrypted) {
103 return (std::find(mechanisms.begin(),
104 mechanisms.end(), kGaiaAuthMechanism) !=
105 mechanisms.end()) ? kGaiaAuthMechanism : "";
106 }
107
108 virtual buzz::SaslMechanism* CreateSaslMechanism(
109 const std::string& mechanism) {
110 return
111 (mechanism == kGaiaAuthMechanism) ?
112 new buzz::SaslCookieMechanism(
113 kGaiaAuthMechanism, username_, token_, token_service_)
114 : NULL;
115 }
116
117 // TODO(akalin): remove this code.
118 virtual bool GetTlsServerInfo(const talk_base::SocketAddress& server,
119 std::string* tls_server_hostname,
120 std::string* tls_server_domain) const {
121 std::string server_ip = server.IPAsString();
122 if ((server_ip == buzz::STR_TALK_GOOGLE_COM) ||
123 (server_ip == buzz::STR_TALKX_L_GOOGLE_COM)) {
124 // For Gaia auth, the talk.google.com server expects you to use
125 // "gmail.com" in the stream, and expects the domain certificate
126 // to be "gmail.com" as well.
127 *tls_server_hostname = buzz::STR_GMAIL_COM;
128 *tls_server_domain = buzz::STR_GMAIL_COM;
129 return true;
130 }
131 return false;
132 }
133
134 private:
135 std::string username_, token_, token_service_;
136 };
137
138 } // namespace
139
54 SingleLoginAttempt::SingleLoginAttempt(talk_base::TaskParent* parent, 140 SingleLoginAttempt::SingleLoginAttempt(talk_base::TaskParent* parent,
55 LoginSettings* login_settings, 141 LoginSettings* login_settings,
56 bool successful_connection) 142 bool successful_connection)
57 : talk_base::Task(parent), 143 : talk_base::Task(parent),
58 state_(buzz::XmppEngine::STATE_NONE), 144 state_(buzz::XmppEngine::STATE_NONE),
59 code_(buzz::XmppEngine::ERROR_NONE), 145 code_(buzz::XmppEngine::ERROR_NONE),
60 subcode_(0), 146 subcode_(0),
61 need_authentication_(false), 147 need_authentication_(false),
62 certificate_expired_(false), 148 certificate_expired_(false),
63 cookie_refreshed_(false), 149 cookie_refreshed_(false),
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 DCHECK(connection_generator_.get()); 594 DCHECK(connection_generator_.get());
509 if (!connection_generator_.get()) { 595 if (!connection_generator_.get()) {
510 return; 596 return;
511 } 597 }
512 598
513 // Iterate to the next possible connection (still trying to connect). 599 // Iterate to the next possible connection (still trying to connect).
514 UseNextConnection(); 600 UseNextConnection();
515 } 601 }
516 602
517 } // namespace notifier 603 } // namespace notifier
OLDNEW
« no previous file with comments | « chrome/common/net/notifier/communicator/gaia_token_pre_xmpp_auth.cc ('k') | remoting/base/constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698