1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef REMOTING_SIGNALING_XMPP_LOGIN_HANDLER_H_
6 #define REMOTING_SIGNALING_XMPP_LOGIN_HANDLER_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "remoting/signaling/signal_strategy.h"
13 // Undefine SendMessage and ERROR defined in Windows headers.
24 class XmppStreamParser
;
26 // XmppLoginHandler handles authentication handshake for XmppSignalStrategy. It
27 // receives incoming data using onDataReceived(), calls Delegate::SendMessage()
28 // to send outgoing messages and calls Delegate::OnHandshakeDone() after
29 // authentication is finished successfully or Delegate::OnError() on error.
31 // See RFC3920 for description of XMPP and authentication handshake.
32 class XmppLoginHandler
{
38 // All Delegate methods are allowed to destroy XmppLoginHandler.
39 virtual void SendMessage(const std::string
& message
) = 0;
40 virtual void StartTls() = 0;
41 virtual void OnHandshakeDone(const std::string
& jid
,
42 scoped_ptr
<XmppStreamParser
> parser
) = 0;
43 virtual void OnLoginHandlerError(SignalStrategy::Error error
) = 0;
46 virtual ~Delegate() {}
55 XmppLoginHandler(const std::string
& server
,
56 const std::string
& username
,
57 const std::string
& auth_token
,
63 void OnDataReceived(const std::string
& data
);
67 // States the handshake goes through. States are iterated from INIT to DONE
68 // sequentially, except for ERROR state which may be accepted at any point.
70 // Following messages are sent/received in each state:
72 // client -> server: Stream header
73 // client -> server: <starttls>
75 // client <- server: Stream header with list of supported features which
76 // should include starttls.
77 // WAIT_STARTTLS_RESPONSE
78 // client <- server: <proceed>
81 // client -> server: Stream header
82 // client -> server: <auth> message with the OAuth2 token.
83 // WAIT_STREAM_HEADER_AFTER_TLS
84 // client <- server: Stream header with list of supported authentication
85 // methods which is expected to include X-OAUTH2
87 // client <- server: <success> or <failure>
88 // client -> server: Stream header
89 // client -> server: <bind>
90 // client -> server: <iq><session/></iq> to start the session
91 // WAIT_STREAM_HEADER_AFTER_AUTH
92 // client <- server: Stream header with list of features that should
95 // client <- server: <bind> result with JID.
96 // WAIT_SESSION_IQ_RESULT
97 // client <- server: result for <iq><session/></iq>
102 WAIT_STARTTLS_RESPONSE
,
104 WAIT_STREAM_HEADER_AFTER_TLS
,
106 WAIT_STREAM_HEADER_AFTER_AUTH
,
108 WAIT_SESSION_IQ_RESULT
,
113 // Callbacks for XmppStreamParser.
114 void OnStanza(scoped_ptr
<buzz::XmlElement
> stanza
);
115 void OnParserError();
117 // Starts authentication handshake in WAIT_STREAM_HEADER_AFTER_TLS state.
118 void StartAuthHandshake();
120 // Helper used to send stream header.
121 void StartStream(const std::string
& first_message
);
123 // Report the |error| to the delegate and changes |state_| to ERROR,
124 void OnError(SignalStrategy::Error error
);
127 std::string username_
;
128 std::string auth_token_
;
136 scoped_ptr
<XmppStreamParser
> stream_parser_
;
138 DISALLOW_COPY_AND_ASSIGN(XmppLoginHandler
);
141 } // namespace remoting
143 #endif // REMOTING_SIGNALING_XMPP_LOGIN_HANDLER_H_