Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: blimp/net/engine_authentication_handler.cc

Issue 1876983002: Use Chromium BUILD to approximate Blimp protocol version, and check it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android to use GetVersionNumber() Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/net/connection_error_observer.h ('k') | blimp/net/engine_authentication_handler_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « blimp/net/connection_error_observer.h ('k') | blimp/net/engine_authentication_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698