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 "base/base64url.h" | 5 #include "base/base64url.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" | 8 #include "components/cryptauth/fake_secure_message_delegate.h" |
9 #include "components/proximity_auth/device_to_device_initiator_operations.h" | 9 #include "components/proximity_auth/device_to_device_initiator_operations.h" |
10 #include "components/proximity_auth/device_to_device_responder_operations.h" | 10 #include "components/proximity_auth/device_to_device_responder_operations.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace proximity_auth { | 13 namespace proximity_auth { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // The initiator's session public key in base64url form. Note that this is | 17 // The initiator's session public key in base64url form. Note that this is |
18 // actually a serialized proto. | 18 // actually a serialized proto. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 local_session_public_key_); | 69 local_session_public_key_); |
70 | 70 |
71 ASSERT_TRUE( | 71 ASSERT_TRUE( |
72 base::Base64UrlDecode(kResponderSessionPublicKeyBase64, | 72 base::Base64UrlDecode(kResponderSessionPublicKeyBase64, |
73 base::Base64UrlDecodePolicy::REQUIRE_PADDING, | 73 base::Base64UrlDecodePolicy::REQUIRE_PADDING, |
74 &remote_session_public_key_)); | 74 &remote_session_public_key_)); |
75 remote_session_private_key_ = | 75 remote_session_private_key_ = |
76 secure_message_delegate_.GetPrivateKeyForPublicKey( | 76 secure_message_delegate_.GetPrivateKeyForPublicKey( |
77 remote_session_public_key_); | 77 remote_session_public_key_); |
78 | 78 |
79 // Note: FakeSecureMessageDelegate functions are synchronous. | 79 // Note: cryptauth::FakeSecureMessageDelegate functions are synchronous. |
80 secure_message_delegate_.DeriveKey( | 80 secure_message_delegate_.DeriveKey( |
81 local_session_private_key_, remote_session_public_key_, | 81 local_session_private_key_, remote_session_public_key_, |
82 base::Bind(&SaveMessageResult, &session_symmetric_key_)); | 82 base::Bind(&SaveMessageResult, &session_symmetric_key_)); |
83 | 83 |
84 persistent_symmetric_key_ = "persistent symmetric key"; | 84 persistent_symmetric_key_ = "persistent symmetric key"; |
85 } | 85 } |
86 | 86 |
87 // Creates the initator's [Hello] message. | 87 // Creates the initator's [Hello] message. |
88 std::string CreateHelloMessage() { | 88 std::string CreateHelloMessage() { |
89 std::string hello_message; | 89 std::string hello_message; |
(...skipping 26 matching lines...) Expand all Loading... |
116 const std::string& remote_auth_message) { | 116 const std::string& remote_auth_message) { |
117 std::string local_auth_message; | 117 std::string local_auth_message; |
118 DeviceToDeviceInitiatorOperations::CreateInitiatorAuthMessage( | 118 DeviceToDeviceInitiatorOperations::CreateInitiatorAuthMessage( |
119 session_symmetric_key_, persistent_symmetric_key_, remote_auth_message, | 119 session_symmetric_key_, persistent_symmetric_key_, remote_auth_message, |
120 &secure_message_delegate_, | 120 &secure_message_delegate_, |
121 base::Bind(&SaveMessageResult, &local_auth_message)); | 121 base::Bind(&SaveMessageResult, &local_auth_message)); |
122 EXPECT_FALSE(local_auth_message.empty()); | 122 EXPECT_FALSE(local_auth_message.empty()); |
123 return local_auth_message; | 123 return local_auth_message; |
124 } | 124 } |
125 | 125 |
126 FakeSecureMessageDelegate secure_message_delegate_; | 126 cryptauth::FakeSecureMessageDelegate secure_message_delegate_; |
127 | 127 |
128 std::string persistent_symmetric_key_; | 128 std::string persistent_symmetric_key_; |
129 std::string local_session_public_key_; | 129 std::string local_session_public_key_; |
130 std::string local_session_private_key_; | 130 std::string local_session_private_key_; |
131 std::string remote_session_public_key_; | 131 std::string remote_session_public_key_; |
132 std::string remote_session_private_key_; | 132 std::string remote_session_private_key_; |
133 std::string session_symmetric_key_; | 133 std::string session_symmetric_key_; |
134 | 134 |
135 DISALLOW_COPY_AND_ASSIGN(ProximityAuthDeviceToDeviceOperationsTest); | 135 DISALLOW_COPY_AND_ASSIGN(ProximityAuthDeviceToDeviceOperationsTest); |
136 }; | 136 }; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 DeviceToDeviceResponderOperations::ValidateInitiatorAuthMessage( | 260 DeviceToDeviceResponderOperations::ValidateInitiatorAuthMessage( |
261 local_auth_message, session_symmetric_key_, | 261 local_auth_message, session_symmetric_key_, |
262 "invalid persistent symmetric key", remote_auth_message, | 262 "invalid persistent symmetric key", remote_auth_message, |
263 &secure_message_delegate_, | 263 &secure_message_delegate_, |
264 base::Bind(&SaveValidationResult, &validation_success)); | 264 base::Bind(&SaveValidationResult, &validation_success)); |
265 | 265 |
266 EXPECT_FALSE(validation_success); | 266 EXPECT_FALSE(validation_success); |
267 } | 267 } |
268 | 268 |
269 } // namespace proximity_auth | 269 } // namespace proximity_auth |
OLD | NEW |