| Index: blimp/net/engine_authentication_handler.cc
|
| diff --git a/blimp/net/engine_authentication_handler.cc b/blimp/net/engine_authentication_handler.cc
|
| index fe020083d54cca0debb14ad23222b94f9f331243..9d1f37659c3fd746f919fdbdb7cc6a28fba3d66f 100644
|
| --- a/blimp/net/engine_authentication_handler.cc
|
| +++ b/blimp/net/engine_authentication_handler.cc
|
| @@ -9,8 +9,10 @@
|
| #include "base/callback_helpers.h"
|
| #include "base/logging.h"
|
| #include "base/timer/timer.h"
|
| +#include "blimp/common/create_blimp_message.h"
|
| #include "blimp/common/logging.h"
|
| #include "blimp/common/proto/blimp_message.pb.h"
|
| +#include "blimp/common/version_info.h"
|
| #include "blimp/net/blimp_connection.h"
|
| #include "blimp/net/blimp_message_processor.h"
|
| #include "blimp/net/blimp_transport.h"
|
| @@ -111,23 +113,40 @@ void Authenticator::OnConnectionError(int error) {
|
|
|
| void Authenticator::ProcessMessage(std::unique_ptr<BlimpMessage> message,
|
| const net::CompletionCallback& callback) {
|
| - if (message->has_protocol_control() &&
|
| - message->protocol_control().has_start_connection()) {
|
| - bool token_match =
|
| - client_token_ ==
|
| - message->protocol_control().start_connection().client_token();
|
| - DVLOG(1) << "Authentication challenge received: "
|
| - << message->protocol_control().start_connection().client_token()
|
| - << ", and token "
|
| - << (token_match ? " matches" : " does not match");
|
| - OnConnectionAuthenticated(token_match);
|
| - } else {
|
| - DVLOG(1) << "Expected START_CONNECTION message, got " << *message
|
| - << " instead.";
|
| + base::ScopedClosureRunner run_callback(base::Bind(callback, net::OK));
|
| +
|
| + if (!message->has_protocol_control() ||
|
| + !message->protocol_control().has_start_connection()) {
|
| + DVLOG(1) << "Expected PROTOCOL_CONTROL->START_CONNECTION, got " << *message;
|
| + OnConnectionAuthenticated(false);
|
| + return;
|
| + }
|
| +
|
| + const StartConnectionMessage& start_connection =
|
| + message->protocol_control().start_connection();
|
| +
|
| + // Verify that the protocol version is supported.
|
| + if (start_connection.protocol_version() != GetProtocolVersion()) {
|
| + DVLOG(1) << "Protocol version mismatch: "
|
| + << start_connection.protocol_version() << " vs "
|
| + << GetProtocolVersion();
|
| +
|
| + // Inform the client of the mismatch before disconnecting it, so it can
|
| + // show the user an appropriate error.
|
| + connection_->GetOutgoingMessageProcessor()->ProcessMessage(
|
| + CreateEndConnectionMessage(EndConnectionMessage::PROTOCOL_MISMATCH),
|
| + net::CompletionCallback());
|
| +
|
| OnConnectionAuthenticated(false);
|
| + return;
|
| }
|
|
|
| - callback.Run(net::OK);
|
| + // Verify that the authentication token matches.
|
| + bool token_match = client_token_ == start_connection.client_token();
|
| + DVLOG(1) << "Authentication challenge received: "
|
| + << start_connection.client_token() << ", and token "
|
| + << (token_match ? " matches" : " does not match");
|
| + OnConnectionAuthenticated(token_match);
|
| }
|
|
|
| } // namespace
|
|
|