Chromium Code Reviews| Index: blimp/net/engine_authentication_handler.cc |
| diff --git a/blimp/net/engine_authentication_handler.cc b/blimp/net/engine_authentication_handler.cc |
| index 798ac87936146d4e103a8ed6a5ea505a5090fb40..3aab16d678036965bf20663eed1cb21b9e73f4a9 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,24 +113,41 @@ void Authenticator::OnConnectionError(int error) { |
| void Authenticator::ProcessMessage(std::unique_ptr<BlimpMessage> message, |
| const net::CompletionCallback& callback) { |
| - if (message->type() == BlimpMessage::PROTOCOL_CONTROL && |
| - message->protocol_control().type() == |
| - ProtocolControlMessage::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->type() != BlimpMessage::PROTOCOL_CONTROL) || |
| + (message->protocol_control().type() != |
| + ProtocolControlMessage::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: " |
|
Kevin M
2016/04/22 21:12:54
Could be good to VLOG(), since this error might be
|
| + << 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 |