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/proximity_auth/device_to_device_authenticator.h" | 5 #include "components/proximity_auth/device_to_device_authenticator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/timer/mock_timer.h" | 10 #include "base/timer/mock_timer.h" |
11 #include "components/proximity_auth/connection.h" | 11 #include "components/proximity_auth/connection.h" |
12 #include "components/proximity_auth/cryptauth/base64url.h" | 12 #include "components/proximity_auth/cryptauth/base64url.h" |
13 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" | 13 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" |
14 #include "components/proximity_auth/device_to_device_responder_operations.h" | 14 #include "components/proximity_auth/device_to_device_responder_operations.h" |
| 15 #include "components/proximity_auth/proximity_auth_test_util.h" |
15 #include "components/proximity_auth/secure_context.h" | 16 #include "components/proximity_auth/secure_context.h" |
16 #include "components/proximity_auth/wire_message.h" | 17 #include "components/proximity_auth/wire_message.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace proximity_auth { | 21 namespace proximity_auth { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // The account id of the user. | 25 // The account id of the user. |
25 const char kAccountId[] = "example@gmail.com"; | 26 const char kAccountId[] = "example@gmail.com"; |
26 | 27 |
27 // Attributes of the connected remote device. | |
28 const char kRemoteDeviceName[] = "iPhone 6"; | |
29 const char kRemoteDevicePublicKey[] = "remote public key"; | |
30 const char kRemoteDeviceBluetoothAddress[] = "AA:BB:CC:DD:EE:FF"; | |
31 const char kRemoteDevicePersistentSymmetricKey[] = "PSK"; | |
32 | |
33 // The initiator's session public key in base64url form. Note that this is | 28 // The initiator's session public key in base64url form. Note that this is |
34 // actually a serialized proto. | 29 // actually a serialized proto. |
35 const char kInitiatorSessionPublicKeyBase64[] = | 30 const char kInitiatorSessionPublicKeyBase64[] = |
36 "CAESRQogOlH8DgPMQu7eAt-b6yoTXcazG8mAl6SPC5Ds-LTULIcSIQDZDMqsoYRO4tNMej1FB" | 31 "CAESRQogOlH8DgPMQu7eAt-b6yoTXcazG8mAl6SPC5Ds-LTULIcSIQDZDMqsoYRO4tNMej1FB" |
37 "El1sTiTiVDqrcGq-CkYCzDThw=="; | 32 "El1sTiTiVDqrcGq-CkYCzDThw=="; |
38 | 33 |
39 // The initiator's session public key in base64url form. Note that this is | 34 // The initiator's session public key in base64url form. Note that this is |
40 // actually a serialized proto. | 35 // actually a serialized proto. |
41 const char kResponderSessionPublicKeyBase64[] = | 36 const char kResponderSessionPublicKeyBase64[] = |
42 "CAESRgohAN9QYU5HySO14Gi9PDIClacBnC0C8wqPwXsNHUNG_vXlEiEAggzU80ZOd9DWuCBdp" | 37 "CAESRgohAN9QYU5HySO14Gi9PDIClacBnC0C8wqPwXsNHUNG_vXlEiEAggzU80ZOd9DWuCBdp" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 base::MockTimer* timer_; | 126 base::MockTimer* timer_; |
132 | 127 |
133 DISALLOW_COPY_AND_ASSIGN(DeviceToDeviceAuthenticatorForTest); | 128 DISALLOW_COPY_AND_ASSIGN(DeviceToDeviceAuthenticatorForTest); |
134 }; | 129 }; |
135 | 130 |
136 } // namespace | 131 } // namespace |
137 | 132 |
138 class ProximityAuthDeviceToDeviceAuthenticatorTest : public testing::Test { | 133 class ProximityAuthDeviceToDeviceAuthenticatorTest : public testing::Test { |
139 public: | 134 public: |
140 ProximityAuthDeviceToDeviceAuthenticatorTest() | 135 ProximityAuthDeviceToDeviceAuthenticatorTest() |
141 : remote_device_(kRemoteDeviceName, | 136 : remote_device_(CreateClassicRemoteDeviceForTest()), |
142 kRemoteDevicePublicKey, | |
143 kRemoteDeviceBluetoothAddress, | |
144 kRemoteDevicePersistentSymmetricKey), | |
145 connection_(remote_device_), | 137 connection_(remote_device_), |
146 secure_message_delegate_(new FakeSecureMessageDelegate), | 138 secure_message_delegate_(new FakeSecureMessageDelegate), |
147 authenticator_(&connection_, | 139 authenticator_(&connection_, |
148 make_scoped_ptr(secure_message_delegate_)) {} | 140 make_scoped_ptr(secure_message_delegate_)) {} |
149 ~ProximityAuthDeviceToDeviceAuthenticatorTest() override {} | 141 ~ProximityAuthDeviceToDeviceAuthenticatorTest() override {} |
150 | 142 |
151 void SetUp() override { | 143 void SetUp() override { |
152 // Set up the session asymmetric keys for both the local and remote devices. | 144 // Set up the session asymmetric keys for both the local and remote devices. |
153 Base64UrlDecode(kInitiatorSessionPublicKeyBase64, | 145 Base64UrlDecode(kInitiatorSessionPublicKeyBase64, |
154 &local_session_public_key_); | 146 &local_session_public_key_); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 EXPECT_TRUE(validated); | 182 EXPECT_TRUE(validated); |
191 EXPECT_EQ(local_session_public_key_, local_session_public_key); | 183 EXPECT_EQ(local_session_public_key_, local_session_public_key); |
192 | 184 |
193 return hello_message; | 185 return hello_message; |
194 } | 186 } |
195 | 187 |
196 // Simulate receiving a valid [Responder Auth] message from the remote device. | 188 // Simulate receiving a valid [Responder Auth] message from the remote device. |
197 std::string SimulateResponderAuth(const std::string& hello_message) { | 189 std::string SimulateResponderAuth(const std::string& hello_message) { |
198 std::string remote_device_private_key = | 190 std::string remote_device_private_key = |
199 secure_message_delegate_->GetPrivateKeyForPublicKey( | 191 secure_message_delegate_->GetPrivateKeyForPublicKey( |
200 kRemoteDevicePublicKey); | 192 kTestRemoteDevicePublicKey); |
201 | 193 |
202 std::string responder_auth_message; | 194 std::string responder_auth_message; |
203 DeviceToDeviceResponderOperations::CreateResponderAuthMessage( | 195 DeviceToDeviceResponderOperations::CreateResponderAuthMessage( |
204 hello_message, remote_session_public_key_, remote_session_private_key_, | 196 hello_message, remote_session_public_key_, remote_session_private_key_, |
205 remote_device_private_key, remote_device_.persistent_symmetric_key, | 197 remote_device_private_key, remote_device_.persistent_symmetric_key, |
206 secure_message_delegate_, | 198 secure_message_delegate_, |
207 base::Bind(&SaveStringResult, &responder_auth_message)); | 199 base::Bind(&SaveStringResult, &responder_auth_message)); |
208 EXPECT_FALSE(responder_auth_message.empty()); | 200 EXPECT_FALSE(responder_auth_message.empty()); |
209 | 201 |
210 WireMessage wire_message(responder_auth_message); | 202 WireMessage wire_message(responder_auth_message); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 WireMessage wire_message(base::RandBytesAsString(300u)); | 334 WireMessage wire_message(base::RandBytesAsString(300u)); |
343 connection_.SendMessage( | 335 connection_.SendMessage( |
344 make_scoped_ptr(new WireMessage(base::RandBytesAsString(300u)))); | 336 make_scoped_ptr(new WireMessage(base::RandBytesAsString(300u)))); |
345 connection_.OnBytesReceived(wire_message.Serialize()); | 337 connection_.OnBytesReceived(wire_message.Serialize()); |
346 connection_.SendMessage( | 338 connection_.SendMessage( |
347 make_scoped_ptr(new WireMessage(base::RandBytesAsString(300u)))); | 339 make_scoped_ptr(new WireMessage(base::RandBytesAsString(300u)))); |
348 connection_.OnBytesReceived(wire_message.Serialize()); | 340 connection_.OnBytesReceived(wire_message.Serialize()); |
349 } | 341 } |
350 | 342 |
351 } // namespace proximity_auth | 343 } // namespace proximity_auth |
OLD | NEW |