OLD | NEW |
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" |
15 #include "chrome/common/net/notifier/communicator/login_failure.h" | 16 #include "chrome/common/net/notifier/communicator/login_failure.h" |
16 #include "chrome/common/net/notifier/communicator/login_settings.h" | 17 #include "chrome/common/net/notifier/communicator/login_settings.h" |
17 #include "chrome/common/net/notifier/communicator/product_info.h" | 18 #include "chrome/common/net/notifier/communicator/product_info.h" |
18 #include "chrome/common/net/notifier/communicator/xmpp_connection_generator.h" | 19 #include "chrome/common/net/notifier/communicator/xmpp_connection_generator.h" |
19 #include "chrome/common/net/notifier/communicator/xmpp_socket_adapter.h" | 20 #include "chrome/common/net/notifier/communicator/xmpp_socket_adapter.h" |
20 #include "talk/base/asynchttprequest.h" | 21 #include "talk/base/asynchttprequest.h" |
21 #include "talk/base/firewallsocketserver.h" | 22 #include "talk/base/firewallsocketserver.h" |
22 #include "talk/base/signalthread.h" | 23 #include "talk/base/signalthread.h" |
23 #include "talk/base/taskrunner.h" | 24 #include "talk/base/taskrunner.h" |
24 #include "talk/base/win32socketinit.h" | 25 #include "talk/base/win32socketinit.h" |
25 #include "talk/xmllite/xmlelement.h" | 26 #include "talk/xmllite/xmlelement.h" |
26 #include "talk/xmpp/prexmppauth.h" | |
27 #include "talk/xmpp/saslcookiemechanism.h" | |
28 #include "talk/xmpp/xmppclient.h" | 27 #include "talk/xmpp/xmppclient.h" |
29 #include "talk/xmpp/xmppclientsettings.h" | 28 #include "talk/xmpp/xmppclientsettings.h" |
30 #include "talk/xmpp/constants.h" | 29 #include "talk/xmpp/constants.h" |
31 | 30 |
32 namespace notifier { | 31 namespace notifier { |
33 | 32 |
34 static void GetClientErrorInformation( | 33 static void GetClientErrorInformation( |
35 buzz::XmppClient* client, | 34 buzz::XmppClient* client, |
36 buzz::XmppEngine::Error* error, | 35 buzz::XmppEngine::Error* error, |
37 int* subcode, | 36 int* subcode, |
38 buzz::XmlElement** stream_error) { | 37 buzz::XmlElement** stream_error) { |
39 DCHECK(client); | 38 DCHECK(client); |
40 DCHECK(error); | 39 DCHECK(error); |
41 DCHECK(subcode); | 40 DCHECK(subcode); |
42 DCHECK(stream_error); | 41 DCHECK(stream_error); |
43 | 42 |
44 *error = client->GetError(subcode); | 43 *error = client->GetError(subcode); |
45 | 44 |
46 *stream_error = NULL; | 45 *stream_error = NULL; |
47 if (*error == buzz::XmppEngine::ERROR_STREAM) { | 46 if (*error == buzz::XmppEngine::ERROR_STREAM) { |
48 const buzz::XmlElement* error_element = client->GetStreamError(); | 47 const buzz::XmlElement* error_element = client->GetStreamError(); |
49 if (error_element) { | 48 if (error_element) { |
50 *stream_error = new buzz::XmlElement(*error_element); | 49 *stream_error = new buzz::XmlElement(*error_element); |
51 } | 50 } |
52 } | 51 } |
53 } | 52 } |
54 | 53 |
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 | |
140 SingleLoginAttempt::SingleLoginAttempt(talk_base::TaskParent* parent, | 54 SingleLoginAttempt::SingleLoginAttempt(talk_base::TaskParent* parent, |
141 LoginSettings* login_settings, | 55 LoginSettings* login_settings, |
142 bool successful_connection) | 56 bool successful_connection) |
143 : talk_base::Task(parent), | 57 : talk_base::Task(parent), |
144 state_(buzz::XmppEngine::STATE_NONE), | 58 state_(buzz::XmppEngine::STATE_NONE), |
145 code_(buzz::XmppEngine::ERROR_NONE), | 59 code_(buzz::XmppEngine::ERROR_NONE), |
146 subcode_(0), | 60 subcode_(0), |
147 need_authentication_(false), | 61 need_authentication_(false), |
148 certificate_expired_(false), | 62 certificate_expired_(false), |
149 cookie_refreshed_(false), | 63 cookie_refreshed_(false), |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 DCHECK(connection_generator_.get()); | 508 DCHECK(connection_generator_.get()); |
595 if (!connection_generator_.get()) { | 509 if (!connection_generator_.get()) { |
596 return; | 510 return; |
597 } | 511 } |
598 | 512 |
599 // Iterate to the next possible connection (still trying to connect). | 513 // Iterate to the next possible connection (still trying to connect). |
600 UseNextConnection(); | 514 UseNextConnection(); |
601 } | 515 } |
602 | 516 |
603 } // namespace notifier | 517 } // namespace notifier |
OLD | NEW |