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

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

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

Powered by Google App Engine
This is Rietveld 408576698