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

Side by Side Diff: blimp/net/engine_authentication_handler.cc

Issue 2281783002: Changes client_token to be client_auth_token. (Closed)
Patch Set: Linting. Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "blimp/net/engine_authentication_handler.h" 5 #include "blimp/net/engine_authentication_handler.h"
6 6
7 #include <memory>
7 #include <string> 8 #include <string>
9 #include <utility>
8 10
9 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/timer/timer.h" 13 #include "base/timer/timer.h"
12 #include "blimp/common/create_blimp_message.h" 14 #include "blimp/common/create_blimp_message.h"
13 #include "blimp/common/logging.h" 15 #include "blimp/common/logging.h"
14 #include "blimp/common/proto/blimp_message.pb.h" 16 #include "blimp/common/proto/blimp_message.pb.h"
15 #include "blimp/common/protocol_version.h" 17 #include "blimp/common/protocol_version.h"
16 #include "blimp/net/blimp_connection.h" 18 #include "blimp/net/blimp_connection.h"
17 #include "blimp/net/blimp_message_processor.h" 19 #include "blimp/net/blimp_message_processor.h"
(...skipping 12 matching lines...) Expand all
30 32
31 // Authenticates one connection. It deletes itself when 33 // Authenticates one connection. It deletes itself when
32 // * the connection is authenticated and passed to |connection_handler|. 34 // * the connection is authenticated and passed to |connection_handler|.
33 // * the connection gets into an error state. 35 // * the connection gets into an error state.
34 // * the auth message does not arrive within a reasonable time. 36 // * the auth message does not arrive within a reasonable time.
35 class Authenticator : public ConnectionErrorObserver, 37 class Authenticator : public ConnectionErrorObserver,
36 public BlimpMessageProcessor { 38 public BlimpMessageProcessor {
37 public: 39 public:
38 explicit Authenticator(std::unique_ptr<BlimpConnection> connection, 40 explicit Authenticator(std::unique_ptr<BlimpConnection> connection,
39 base::WeakPtr<ConnectionHandler> connection_handler, 41 base::WeakPtr<ConnectionHandler> connection_handler,
40 const std::string& client_token); 42 const std::string& client_auth_token);
41 ~Authenticator() override; 43 ~Authenticator() override;
42 44
43 private: 45 private:
44 // Processes authentication result and deletes |this|. 46 // Processes authentication result and deletes |this|.
45 void OnConnectionAuthenticated(bool authenticated); 47 void OnConnectionAuthenticated(bool authenticated);
46 48
47 // Handles timeout waiting for auth message, and deletes |this|. 49 // Handles timeout waiting for auth message, and deletes |this|.
48 void OnAuthenticationTimeout(); 50 void OnAuthenticationTimeout();
49 51
50 // ConnectionErrorObserver implementation. 52 // ConnectionErrorObserver implementation.
51 void OnConnectionError(int error) override; 53 void OnConnectionError(int error) override;
52 54
53 // BlimpMessageProcessor implementation. 55 // BlimpMessageProcessor implementation.
54 void ProcessMessage(std::unique_ptr<BlimpMessage> message, 56 void ProcessMessage(std::unique_ptr<BlimpMessage> message,
55 const net::CompletionCallback& callback) override; 57 const net::CompletionCallback& callback) override;
56 58
57 // The connection to be authenticated. 59 // The connection to be authenticated.
58 std::unique_ptr<BlimpConnection> connection_; 60 std::unique_ptr<BlimpConnection> connection_;
59 61
60 // Handler to pass successfully authenticated connections to. 62 // Handler to pass successfully authenticated connections to.
61 base::WeakPtr<ConnectionHandler> connection_handler_; 63 base::WeakPtr<ConnectionHandler> connection_handler_;
62 64
63 // Used to authenticate incoming connection. 65 // Used to authenticate incoming connection.
64 const std::string client_token_; 66 const std::string client_auth_token_;
65 67
66 // A timer to fail authentication on timeout. 68 // A timer to fail authentication on timeout.
67 base::OneShotTimer timeout_timer_; 69 base::OneShotTimer timeout_timer_;
68 70
69 DISALLOW_COPY_AND_ASSIGN(Authenticator); 71 DISALLOW_COPY_AND_ASSIGN(Authenticator);
70 }; 72 };
71 73
72 Authenticator::Authenticator( 74 Authenticator::Authenticator(
73 std::unique_ptr<BlimpConnection> connection, 75 std::unique_ptr<BlimpConnection> connection,
74 base::WeakPtr<ConnectionHandler> connection_handler, 76 base::WeakPtr<ConnectionHandler> connection_handler,
75 const std::string& client_token) 77 const std::string& client_auth_token)
76 : connection_(std::move(connection)), 78 : connection_(std::move(connection)),
77 connection_handler_(connection_handler), 79 connection_handler_(connection_handler),
78 client_token_(client_token) { 80 client_auth_token_(client_auth_token) {
79 DVLOG(1) << "Authenticator object created."; 81 DVLOG(1) << "Authenticator object created.";
80 82
81 // Observe for errors that might occur during the authentication phase. 83 // Observe for errors that might occur during the authentication phase.
82 connection_->AddConnectionErrorObserver(this); 84 connection_->AddConnectionErrorObserver(this);
83 connection_->SetIncomingMessageProcessor(this); 85 connection_->SetIncomingMessageProcessor(this);
84 timeout_timer_.Start( 86 timeout_timer_.Start(
85 FROM_HERE, base::TimeDelta::FromSeconds(kAuthTimeoutDurationInSeconds), 87 FROM_HERE, base::TimeDelta::FromSeconds(kAuthTimeoutDurationInSeconds),
86 this, &Authenticator::OnAuthenticationTimeout); 88 this, &Authenticator::OnAuthenticationTimeout);
87 } 89 }
88 90
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // show the user an appropriate error. 137 // show the user an appropriate error.
136 connection_->GetOutgoingMessageProcessor()->ProcessMessage( 138 connection_->GetOutgoingMessageProcessor()->ProcessMessage(
137 CreateEndConnectionMessage(EndConnectionMessage::PROTOCOL_MISMATCH), 139 CreateEndConnectionMessage(EndConnectionMessage::PROTOCOL_MISMATCH),
138 net::CompletionCallback()); 140 net::CompletionCallback());
139 141
140 OnConnectionAuthenticated(false); 142 OnConnectionAuthenticated(false);
141 return; 143 return;
142 } 144 }
143 145
144 // Verify that the authentication token matches. 146 // Verify that the authentication token matches.
145 bool token_match = client_token_ == start_connection.client_token(); 147 bool token_match = client_auth_token_ == start_connection.client_auth_token();
146 DVLOG(1) << "Authentication challenge received: " 148 DVLOG(1) << "Authentication challenge received: "
147 << start_connection.client_token() << ", and token " 149 << start_connection.client_auth_token() << ", and token "
148 << (token_match ? " matches" : " does not match"); 150 << (token_match ? " matches" : " does not match");
149 OnConnectionAuthenticated(token_match); 151 OnConnectionAuthenticated(token_match);
150 } 152 }
151 153
152 } // namespace 154 } // namespace
153 155
154 EngineAuthenticationHandler::EngineAuthenticationHandler( 156 EngineAuthenticationHandler::EngineAuthenticationHandler(
155 ConnectionHandler* connection_handler, 157 ConnectionHandler* connection_handler,
156 const std::string& client_token) 158 const std::string& client_auth_token)
157 : connection_handler_weak_factory_(connection_handler), 159 : connection_handler_weak_factory_(connection_handler),
158 client_token_(client_token) { 160 client_auth_token_(client_auth_token) {
159 DCHECK(!client_token_.empty()); 161 DCHECK(!client_auth_token_.empty());
160 } 162 }
161 163
162 EngineAuthenticationHandler::~EngineAuthenticationHandler() {} 164 EngineAuthenticationHandler::~EngineAuthenticationHandler() {}
163 165
164 void EngineAuthenticationHandler::HandleConnection( 166 void EngineAuthenticationHandler::HandleConnection(
165 std::unique_ptr<BlimpConnection> connection) { 167 std::unique_ptr<BlimpConnection> connection) {
166 // Authenticator manages its own lifetime. 168 // Authenticator manages its own lifetime.
167 new Authenticator(std::move(connection), 169 new Authenticator(std::move(connection),
168 connection_handler_weak_factory_.GetWeakPtr(), 170 connection_handler_weak_factory_.GetWeakPtr(),
169 client_token_); 171 client_auth_token_);
170 } 172 }
171 173
172 } // namespace blimp 174 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/engine_authentication_handler.h ('k') | blimp/net/engine_authentication_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698