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..1cc50b2a9c41660b0d2a90f7bc73955190459edf 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/protocol_version.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() != kProtocolVersion) { |
+ DVLOG(1) << "Protocol version mismatch: " |
+ << start_connection.protocol_version() << " vs " |
+ << kProtocolVersion; |
+ |
+ // 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 |