| OLD | NEW |
| 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 "components/cryptauth/device_to_device_authenticator.h" | 5 #include "components/cryptauth/device_to_device_authenticator.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 hello_message_, std::string(Authenticator::kAuthenticationFeature))); | 147 hello_message_, std::string(Authenticator::kAuthenticationFeature))); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void DeviceToDeviceAuthenticator::OnResponderAuthTimedOut() { | 150 void DeviceToDeviceAuthenticator::OnResponderAuthTimedOut() { |
| 151 DCHECK(state_ == State::SENT_HELLO); | 151 DCHECK(state_ == State::SENT_HELLO); |
| 152 Fail("Timed out waiting for [Responder Auth]"); | 152 Fail("Timed out waiting for [Responder Auth]"); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void DeviceToDeviceAuthenticator::OnResponderAuthValidated( | 155 void DeviceToDeviceAuthenticator::OnResponderAuthValidated( |
| 156 bool validated, | 156 bool validated, |
| 157 const std::string& session_symmetric_key) { | 157 const SessionKeys& session_keys) { |
| 158 if (!validated) { | 158 if (!validated) { |
| 159 Fail("Unable to validated [Responder Auth]"); | 159 Fail("Unable to validated [Responder Auth]"); |
| 160 return; | 160 return; |
| 161 } | 161 } |
| 162 | 162 |
| 163 PA_LOG(INFO) << "Successfully validated [Responder Auth]! " | 163 PA_LOG(INFO) << "Successfully validated [Responder Auth]! " |
| 164 << "Sending [Initiator Auth]..."; | 164 << "Sending [Initiator Auth]..."; |
| 165 state_ = State::VALIDATED_RESPONDER_AUTH; | 165 state_ = State::VALIDATED_RESPONDER_AUTH; |
| 166 session_symmetric_key_ = session_symmetric_key; | 166 session_keys_ = session_keys; |
| 167 | 167 |
| 168 // Create the [Initiator Auth] message to send to the remote device. | 168 // Create the [Initiator Auth] message to send to the remote device. |
| 169 DeviceToDeviceInitiatorOperations::CreateInitiatorAuthMessage( | 169 DeviceToDeviceInitiatorOperations::CreateInitiatorAuthMessage( |
| 170 session_symmetric_key, | 170 session_keys_, connection_->remote_device().persistent_symmetric_key, |
| 171 connection_->remote_device().persistent_symmetric_key, | |
| 172 responder_auth_message_, secure_message_delegate_.get(), | 171 responder_auth_message_, secure_message_delegate_.get(), |
| 173 base::Bind(&DeviceToDeviceAuthenticator::OnInitiatorAuthCreated, | 172 base::Bind(&DeviceToDeviceAuthenticator::OnInitiatorAuthCreated, |
| 174 weak_ptr_factory_.GetWeakPtr())); | 173 weak_ptr_factory_.GetWeakPtr())); |
| 175 } | 174 } |
| 176 | 175 |
| 177 void DeviceToDeviceAuthenticator::OnInitiatorAuthCreated( | 176 void DeviceToDeviceAuthenticator::OnInitiatorAuthCreated( |
| 178 const std::string& message) { | 177 const std::string& message) { |
| 179 DCHECK(state_ == State::VALIDATED_RESPONDER_AUTH); | 178 DCHECK(state_ == State::VALIDATED_RESPONDER_AUTH); |
| 180 if (message.empty()) { | 179 if (message.empty()) { |
| 181 Fail("Failed to create [Initiator Auth]"); | 180 Fail("Failed to create [Initiator Auth]"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 197 PA_LOG(WARNING) << "Authentication failed: " << error_message; | 196 PA_LOG(WARNING) << "Authentication failed: " << error_message; |
| 198 state_ = State::AUTHENTICATION_FAILURE; | 197 state_ = State::AUTHENTICATION_FAILURE; |
| 199 weak_ptr_factory_.InvalidateWeakPtrs(); | 198 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 200 connection_->RemoveObserver(this); | 199 connection_->RemoveObserver(this); |
| 201 timer_.reset(); | 200 timer_.reset(); |
| 202 callback_.Run(result, nullptr); | 201 callback_.Run(result, nullptr); |
| 203 } | 202 } |
| 204 | 203 |
| 205 void DeviceToDeviceAuthenticator::Succeed() { | 204 void DeviceToDeviceAuthenticator::Succeed() { |
| 206 DCHECK(state_ == State::SENT_INITIATOR_AUTH); | 205 DCHECK(state_ == State::SENT_INITIATOR_AUTH); |
| 207 DCHECK(!session_symmetric_key_.empty()); | 206 DCHECK(!session_keys_.initiator_encode_key().empty()); |
| 207 DCHECK(!session_keys_.responder_encode_key().empty()); |
| 208 PA_LOG(INFO) << "Authentication succeeded!"; | 208 PA_LOG(INFO) << "Authentication succeeded!"; |
| 209 | 209 |
| 210 state_ = State::AUTHENTICATION_SUCCESS; | 210 state_ = State::AUTHENTICATION_SUCCESS; |
| 211 connection_->RemoveObserver(this); | 211 connection_->RemoveObserver(this); |
| 212 callback_.Run( | 212 callback_.Run( |
| 213 Result::SUCCESS, | 213 Result::SUCCESS, |
| 214 base::MakeUnique<DeviceToDeviceSecureContext>( | 214 base::MakeUnique<DeviceToDeviceSecureContext>( |
| 215 std::move(secure_message_delegate_), session_symmetric_key_, | 215 std::move(secure_message_delegate_), session_keys_, |
| 216 responder_auth_message_, SecureContext::PROTOCOL_VERSION_THREE_ONE)); | 216 responder_auth_message_, SecureContext::PROTOCOL_VERSION_THREE_ONE)); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void DeviceToDeviceAuthenticator::OnConnectionStatusChanged( | 219 void DeviceToDeviceAuthenticator::OnConnectionStatusChanged( |
| 220 Connection* connection, | 220 Connection* connection, |
| 221 Connection::Status old_status, | 221 Connection::Status old_status, |
| 222 Connection::Status new_status) { | 222 Connection::Status new_status) { |
| 223 // We do not expect the connection to drop during authentication. | 223 // We do not expect the connection to drop during authentication. |
| 224 if (new_status == Connection::DISCONNECTED) { | 224 if (new_status == Connection::DISCONNECTED) { |
| 225 Fail("Disconnected while authentication is in progress", | 225 Fail("Disconnected while authentication is in progress", |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 Succeed(); | 262 Succeed(); |
| 263 else | 263 else |
| 264 Fail("Failed to send [Initiator Auth]"); | 264 Fail("Failed to send [Initiator Auth]"); |
| 265 } else if (!success && state_ == State::SENT_HELLO) { | 265 } else if (!success && state_ == State::SENT_HELLO) { |
| 266 DCHECK(message.payload() == hello_message_); | 266 DCHECK(message.payload() == hello_message_); |
| 267 Fail("Failed to send [Hello]"); | 267 Fail("Failed to send [Hello]"); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 } // namespace cryptauth | 271 } // namespace cryptauth |
| OLD | NEW |