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 virtual void SendMessage(const std::string
& message
) = 0;
39 virtual void StartTls() = 0;
40 virtual void OnHandshakeDone(const std::string
& jid
,
41 scoped_ptr
<XmppStreamParser
> parser
) = 0;
42 virtual void OnLoginHandlerError(SignalStrategy::Error error
) = 0;
45 virtual ~Delegate() {}
54 XmppLoginHandler(const std::string
& server
,
55 const std::string
& username
,
56 const std::string
& auth_token
,
62 void OnDataReceived(const std::string
& data
);
66 // States the handshake goes through. States are iterated from INIT to DONE
67 // sequentially, except for ERROR state which may be accepted at any point.
69 // Following messages are sent/received in each state:
71 // client -> server: Stream header
72 // client -> server: <starttls>
74 // client <- server: Stream header with list of supported features which
75 // should include starttls.
76 // WAIT_STARTTLS_RESPONSE
77 // client <- server: <proceed>
80 // client -> server: Stream header
81 // client -> server: <auth> message with the OAuth2 token.
82 // WAIT_STREAM_HEADER_AFTER_TLS
83 // client <- server: Stream header with list of supported authentication
84 // methods which is expected to include X-OAUTH2
86 // client <- server: <success> or <failure>
87 // client -> server: Stream header
88 // client -> server: <bind>
89 // client -> server: <iq><session/></iq> to start the session
90 // WAIT_STREAM_HEADER_AFTER_AUTH
91 // client <- server: Stream header with list of features that should
94 // client <- server: <bind> result with JID.
95 // WAIT_SESSION_IQ_RESULT
96 // client <- server: result for <iq><session/></iq>
101 WAIT_STARTTLS_RESPONSE
,
103 WAIT_STREAM_HEADER_AFTER_TLS
,
105 WAIT_STREAM_HEADER_AFTER_AUTH
,
107 WAIT_SESSION_IQ_RESULT
,
112 // Callbacks for XmppStreamParser.
113 void OnStanza(scoped_ptr
<buzz::XmlElement
> stanza
);
114 void OnParserError();
116 // Starts authentication handshake in WAIT_STREAM_HEADER_AFTER_TLS state.
117 void StartAuthHandshake();
119 // Helper used to send stream header.
120 void StartStream(const std::string
& first_message
);
122 // Report the |error| to the delegate and changes |state_| to ERROR,
123 void OnError(SignalStrategy::Error error
);
126 std::string username_
;
127 std::string auth_token_
;
135 scoped_ptr
<XmppStreamParser
> stream_parser_
;
137 DISALLOW_COPY_AND_ASSIGN(XmppLoginHandler
);
140 } // namespace remoting
142 #endif // REMOTING_SIGNALING_XMPP_LOGIN_HANDLER_H_