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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64url.h" | 10 #include "base/base64url.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
15 #include "base/timer/mock_timer.h" | 15 #include "base/timer/mock_timer.h" |
16 #include "components/cryptauth/authenticator.h" | 16 #include "components/cryptauth/authenticator.h" |
17 #include "components/cryptauth/connection.h" | 17 #include "components/cryptauth/connection.h" |
18 #include "components/cryptauth/cryptauth_test_util.h" | 18 #include "components/cryptauth/cryptauth_test_util.h" |
19 #include "components/cryptauth/device_to_device_responder_operations.h" | 19 #include "components/cryptauth/device_to_device_responder_operations.h" |
20 #include "components/cryptauth/fake_secure_message_delegate.h" | 20 #include "components/cryptauth/fake_secure_message_delegate.h" |
21 #include "components/cryptauth/secure_context.h" | 21 #include "components/cryptauth/secure_context.h" |
| 22 #include "components/cryptauth/session_keys.h" |
22 #include "components/cryptauth/wire_message.h" | 23 #include "components/cryptauth/wire_message.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 namespace cryptauth { | 27 namespace cryptauth { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 // The account id of the user. | 31 // The account id of the user. |
31 const char kAccountId[] = "example@gmail.com"; | 32 const char kAccountId[] = "example@gmail.com"; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 OnAuthenticationResultProxy(Authenticator::Result::SUCCESS)); | 263 OnAuthenticationResultProxy(Authenticator::Result::SUCCESS)); |
263 std::string responder_auth_message = SimulateResponderAuth(hello_message); | 264 std::string responder_auth_message = SimulateResponderAuth(hello_message); |
264 EXPECT_TRUE(secure_context_); | 265 EXPECT_TRUE(secure_context_); |
265 | 266 |
266 // Validate the local device sends a valid [Initiator Auth] message. | 267 // Validate the local device sends a valid [Initiator Auth] message. |
267 ASSERT_EQ(1u, connection_.message_buffer().size()); | 268 ASSERT_EQ(1u, connection_.message_buffer().size()); |
268 std::string initiator_auth = connection_.message_buffer()[0]->payload(); | 269 std::string initiator_auth = connection_.message_buffer()[0]->payload(); |
269 | 270 |
270 bool initiator_auth_validated = false; | 271 bool initiator_auth_validated = false; |
271 DeviceToDeviceResponderOperations::ValidateInitiatorAuthMessage( | 272 DeviceToDeviceResponderOperations::ValidateInitiatorAuthMessage( |
272 initiator_auth, session_symmetric_key_, | 273 initiator_auth, SessionKeys(session_symmetric_key_), |
273 remote_device_.persistent_symmetric_key, responder_auth_message, | 274 remote_device_.persistent_symmetric_key, responder_auth_message, |
274 secure_message_delegate_, | 275 secure_message_delegate_, |
275 base::Bind(&SaveBooleanResult, &initiator_auth_validated)); | 276 base::Bind(&SaveBooleanResult, &initiator_auth_validated)); |
276 ASSERT_TRUE(initiator_auth_validated); | 277 ASSERT_TRUE(initiator_auth_validated); |
277 } | 278 } |
278 | 279 |
279 TEST_F(ProximityAuthDeviceToDeviceAuthenticatorTest, ResponderRejectsHello) { | 280 TEST_F(ProximityAuthDeviceToDeviceAuthenticatorTest, ResponderRejectsHello) { |
280 std::string hello_message = BeginAuthentication(); | 281 std::string hello_message = BeginAuthentication(); |
281 | 282 |
282 // If the responder could not validate the [Hello message], it essentially | 283 // If the responder could not validate the [Hello message], it essentially |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 Authenticator::kAuthenticationFeature); | 352 Authenticator::kAuthenticationFeature); |
352 connection_.SendMessage(base::MakeUnique<WireMessage>( | 353 connection_.SendMessage(base::MakeUnique<WireMessage>( |
353 base::RandBytesAsString(300u), Authenticator::kAuthenticationFeature)); | 354 base::RandBytesAsString(300u), Authenticator::kAuthenticationFeature)); |
354 connection_.OnBytesReceived(wire_message.Serialize()); | 355 connection_.OnBytesReceived(wire_message.Serialize()); |
355 connection_.SendMessage(base::MakeUnique<WireMessage>( | 356 connection_.SendMessage(base::MakeUnique<WireMessage>( |
356 base::RandBytesAsString(300u), Authenticator::kAuthenticationFeature)); | 357 base::RandBytesAsString(300u), Authenticator::kAuthenticationFeature)); |
357 connection_.OnBytesReceived(wire_message.Serialize()); | 358 connection_.OnBytesReceived(wire_message.Serialize()); |
358 } | 359 } |
359 | 360 |
360 } // namespace cryptauth | 361 } // namespace cryptauth |
OLD | NEW |