summaryrefslogtreecommitdiffstats
path: root/remoting/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/protocol')
-rw-r--r--remoting/protocol/negotiating_client_authenticator.cc32
-rw-r--r--remoting/protocol/negotiating_client_authenticator.h15
2 files changed, 36 insertions, 11 deletions
diff --git a/remoting/protocol/negotiating_client_authenticator.cc b/remoting/protocol/negotiating_client_authenticator.cc
index 5ab0507..af5d56b 100644
--- a/remoting/protocol/negotiating_client_authenticator.cc
+++ b/remoting/protocol/negotiating_client_authenticator.cc
@@ -62,11 +62,13 @@ void NegotiatingClientAuthenticator::ProcessMessage(
current_method_ = method;
method_set_by_host_ = true;
state_ = PROCESSING_MESSAGE;
+
// Copy the message since the authenticator may process it asynchronously.
- CreateAuthenticator(WAITING_MESSAGE, base::Bind(
+ base::Closure callback = base::Bind(
&NegotiatingAuthenticatorBase::ProcessMessageInternal,
base::Unretained(this), base::Owned(new buzz::XmlElement(*message)),
- resume_callback));
+ resume_callback);
+ CreateAuthenticatorForCurrentMethod(WAITING_MESSAGE, callback);
return;
}
ProcessMessageInternal(message, resume_callback);
@@ -76,12 +78,18 @@ scoped_ptr<buzz::XmlElement> NegotiatingClientAuthenticator::GetNextMessage() {
DCHECK_EQ(state(), MESSAGE_READY);
// This is the first message to the host, send a list of supported methods.
if (!current_method_.is_valid()) {
- // We currently send just an empty message with the supported list, but, in
- // the future, the client may optimistically pick a method and send its
- // first message, along with the supported methods. If the host doesn't
- // support that method, it is free to ignore this first message and pick a
- // different method from the supported list.
- scoped_ptr<buzz::XmlElement> result = CreateEmptyAuthenticatorMessage();
+ // If no authentication method has been chosen, see if we can optimistically
+ // choose one.
+ scoped_ptr<buzz::XmlElement> result;
+ current_authenticator_ = CreatePreferredAuthenticator();
+ if (current_authenticator_) {
+ DCHECK(current_authenticator_->state() == MESSAGE_READY);
+ result = GetNextMessageInternal();
+ } else {
+ result = CreateEmptyAuthenticatorMessage();
+ }
+
+ // Include a list of supported methods.
std::stringstream supported_methods(std::stringstream::out);
for (std::vector<AuthenticationMethod>::iterator it = methods_.begin();
it != methods_.end(); ++it) {
@@ -96,7 +104,7 @@ scoped_ptr<buzz::XmlElement> NegotiatingClientAuthenticator::GetNextMessage() {
return GetNextMessageInternal();
}
-void NegotiatingClientAuthenticator::CreateAuthenticator(
+void NegotiatingClientAuthenticator::CreateAuthenticatorForCurrentMethod(
Authenticator::State preferred_initial_state,
const base::Closure& resume_callback) {
DCHECK(current_method_.is_valid());
@@ -115,6 +123,12 @@ void NegotiatingClientAuthenticator::CreateAuthenticator(
}
}
+scoped_ptr<Authenticator>
+NegotiatingClientAuthenticator::CreatePreferredAuthenticator() {
+ NOTIMPLEMENTED();
+ return scoped_ptr<Authenticator>();
+}
+
void NegotiatingClientAuthenticator::CreateV2AuthenticatorWithSecret(
Authenticator::State initial_state,
const base::Closure& resume_callback,
diff --git a/remoting/protocol/negotiating_client_authenticator.h b/remoting/protocol/negotiating_client_authenticator.h
index d2047fe..995cf1dd 100644
--- a/remoting/protocol/negotiating_client_authenticator.h
+++ b/remoting/protocol/negotiating_client_authenticator.h
@@ -45,8 +45,19 @@ class NegotiatingClientAuthenticator : public NegotiatingAuthenticatorBase {
// |current_authenticator_|. Authenticators that can be started in either
// state will be created in |preferred_initial_state|.
// |resume_callback| is called after |current_authenticator_| is set.
- void CreateAuthenticator(Authenticator::State preferred_initial_state,
- const base::Closure& resume_callback);
+ void CreateAuthenticatorForCurrentMethod(
+ Authenticator::State preferred_initial_state,
+ const base::Closure& resume_callback);
+
+ // If possible, create a preferred authenticator ready to send an
+ // initial message optimistically to the host. The host is free to
+ // ignore the client's preferred authenticator and initial message
+ // and to instead reply with an alternative method. See the comments
+ // in negotiating_authenticator_base.h for more details.
+ //
+ // Returns the preferred authenticator if possible, or NULL otherwise.
+ scoped_ptr<Authenticator> CreatePreferredAuthenticator();
+
// Creates a V2Authenticator in state |initial_state| with the given
// |shared_secret|, then runs |resume_callback|.