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

Side by Side Diff: remoting/protocol/negotiating_authenticator_unittest.cc

Issue 1800823002: Add Curve25519 version of pairing authenticators (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 5 #include "base/bind.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "net/base/net_errors.h" 7 #include "net/base/net_errors.h"
8 #include "remoting/base/rsa_key_pair.h" 8 #include "remoting/base/rsa_key_pair.h"
9 #include "remoting/protocol/auth_util.h" 9 #include "remoting/protocol/auth_util.h"
10 #include "remoting/protocol/authenticator_test_base.h" 10 #include "remoting/protocol/authenticator_test_base.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 const char kTestPinBad[] = "654321"; 46 const char kTestPinBad[] = "654321";
47 47
48 } // namespace 48 } // namespace
49 49
50 class NegotiatingAuthenticatorTest : public AuthenticatorTestBase { 50 class NegotiatingAuthenticatorTest : public AuthenticatorTestBase {
51 public: 51 public:
52 NegotiatingAuthenticatorTest() {} 52 NegotiatingAuthenticatorTest() {}
53 ~NegotiatingAuthenticatorTest() override {} 53 ~NegotiatingAuthenticatorTest() override {}
54 54
55 protected: 55 protected:
56 void InitAuthenticators(const std::string& client_id, 56 virtual void InitAuthenticators(const std::string& client_id,
57 const std::string& client_paired_secret, 57 const std::string& client_paired_secret,
58 const std::string& client_interactive_pin, 58 const std::string& client_interactive_pin,
59 const std::string& host_secret, 59 const std::string& host_secret,
60 bool it2me) { 60 bool it2me) {
61 if (it2me) { 61 if (it2me) {
62 host_ = NegotiatingHostAuthenticator::CreateForIt2Me( 62 host_ = NegotiatingHostAuthenticator::CreateForIt2Me(
63 kHostJid, kClientJid, host_cert_, key_pair_, host_secret); 63 kHostJid, kClientJid, host_cert_, key_pair_, host_secret);
64 } else { 64 } else {
65 std::string host_secret_hash = 65 std::string host_secret_hash =
66 GetSharedSecretHash(kTestHostId, host_secret); 66 GetSharedSecretHash(kTestHostId, host_secret);
67 host_ = NegotiatingHostAuthenticator::CreateWithPin( 67 scoped_ptr<NegotiatingHostAuthenticator> host =
68 kHostJid, kClientJid, host_cert_, key_pair_, host_secret_hash, 68 NegotiatingHostAuthenticator::CreateWithPin(
69 pairing_registry_); 69 kHostJid, kClientJid, host_cert_, key_pair_, host_secret_hash,
70 pairing_registry_);
71 host_as_negotiating_authenticator_ = host.get();
72 host_ = std::move(host);
70 } 73 }
71 74
72 protocol::ClientAuthenticationConfig client_auth_config; 75 protocol::ClientAuthenticationConfig client_auth_config;
73 client_auth_config.host_id = kTestHostId; 76 client_auth_config.host_id = kTestHostId;
74 client_auth_config.pairing_client_id = client_id; 77 client_auth_config.pairing_client_id = client_id;
75 client_auth_config.pairing_secret= client_paired_secret; 78 client_auth_config.pairing_secret = client_paired_secret;
76 bool pairing_expected = pairing_registry_.get() != nullptr; 79 bool pairing_expected = pairing_registry_.get() != nullptr;
77 client_auth_config.fetch_secret_callback = 80 client_auth_config.fetch_secret_callback =
78 base::Bind(&NegotiatingAuthenticatorTest::FetchSecret, 81 base::Bind(&NegotiatingAuthenticatorTest::FetchSecret,
79 client_interactive_pin, pairing_expected); 82 client_interactive_pin, pairing_expected);
80 client_as_negotiating_authenticator_ = new NegotiatingClientAuthenticator( 83 client_as_negotiating_authenticator_ = new NegotiatingClientAuthenticator(
81 kClientJid, kHostJid, client_auth_config); 84 kClientJid, kHostJid, client_auth_config);
82 client_.reset(client_as_negotiating_authenticator_); 85 client_.reset(client_as_negotiating_authenticator_);
83 } 86 }
84 87
88 void DisableMethodOnClient(NegotiatingAuthenticatorBase::Method method) {
89 auto* methods = &(client_as_negotiating_authenticator_->methods_);
90 auto iter = std::find(methods->begin(), methods->end(), method);
91 ASSERT_TRUE(iter != methods->end());
92 methods->erase(iter);
93 }
94
95 void DisableMethodOnHost(NegotiatingAuthenticatorBase::Method method) {
96 auto* methods = &(host_as_negotiating_authenticator_->methods_);
97 auto iter = std::find(methods->begin(), methods->end(), method);
98 ASSERT_TRUE(iter != methods->end());
99 methods->erase(iter);
100 }
101
85 void CreatePairingRegistry(bool with_paired_client) { 102 void CreatePairingRegistry(bool with_paired_client) {
86 pairing_registry_ = new SynchronousPairingRegistry( 103 pairing_registry_ = new SynchronousPairingRegistry(
87 make_scoped_ptr(new MockPairingRegistryDelegate())); 104 make_scoped_ptr(new MockPairingRegistryDelegate()));
88 if (with_paired_client) { 105 if (with_paired_client) {
89 PairingRegistry::Pairing pairing( 106 PairingRegistry::Pairing pairing(
90 base::Time(), kTestClientName, kTestClientId, kTestPairedSecret); 107 base::Time(), kTestClientName, kTestClientId, kTestPairedSecret);
91 pairing_registry_->AddPairing(pairing); 108 pairing_registry_->AddPairing(pairing);
92 } 109 }
93 } 110 }
94 111
(...skipping 10 matching lines...) Expand all
105 ASSERT_TRUE(client_->state() == Authenticator::REJECTED || 122 ASSERT_TRUE(client_->state() == Authenticator::REJECTED ||
106 host_->state() == Authenticator::REJECTED); 123 host_->state() == Authenticator::REJECTED);
107 if (client_->state() == Authenticator::REJECTED) { 124 if (client_->state() == Authenticator::REJECTED) {
108 ASSERT_EQ(client_->rejection_reason(), reason); 125 ASSERT_EQ(client_->rejection_reason(), reason);
109 } 126 }
110 if (host_->state() == Authenticator::REJECTED) { 127 if (host_->state() == Authenticator::REJECTED) {
111 ASSERT_EQ(host_->rejection_reason(), reason); 128 ASSERT_EQ(host_->rejection_reason(), reason);
112 } 129 }
113 } 130 }
114 131
115 void VerifyAccepted(NegotiatingAuthenticatorBase::Method expected_method) { 132 virtual void VerifyAccepted() {
116 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 133 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
117 134
118 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); 135 ASSERT_EQ(Authenticator::ACCEPTED, host_->state());
119 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); 136 ASSERT_EQ(Authenticator::ACCEPTED, client_->state());
120 137
121 client_auth_ = client_->CreateChannelAuthenticator(); 138 client_auth_ = client_->CreateChannelAuthenticator();
122 host_auth_ = host_->CreateChannelAuthenticator(); 139 host_auth_ = host_->CreateChannelAuthenticator();
123 RunChannelAuth(false); 140 RunChannelAuth(false);
124 141
125 EXPECT_TRUE(client_socket_.get() != nullptr); 142 EXPECT_TRUE(client_socket_.get() != nullptr);
126 EXPECT_TRUE(host_socket_.get() != nullptr); 143 EXPECT_TRUE(host_socket_.get() != nullptr);
127 144
128 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), 145 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
129 kMessageSize, kMessages); 146 kMessageSize, kMessages);
130 147
131 tester.Start(); 148 tester.Start();
132 message_loop_.Run(); 149 message_loop_.Run();
133 tester.CheckResults(); 150 tester.CheckResults();
134 EXPECT_EQ(expected_method, 151 }
135 client_as_negotiating_authenticator_->current_method_); 152
153 NegotiatingAuthenticatorBase::Method current_method() {
154 return client_as_negotiating_authenticator_->current_method_;
136 } 155 }
137 156
138 // Use a bare pointer because the storage is managed by the base class. 157 // Use a bare pointer because the storage is managed by the base class.
158 NegotiatingHostAuthenticator* host_as_negotiating_authenticator_;
139 NegotiatingClientAuthenticator* client_as_negotiating_authenticator_; 159 NegotiatingClientAuthenticator* client_as_negotiating_authenticator_;
140 160
141 private: 161 private:
142 scoped_refptr<PairingRegistry> pairing_registry_; 162 scoped_refptr<PairingRegistry> pairing_registry_;
143 163
144 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticatorTest); 164 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticatorTest);
145 }; 165 };
146 166
167 struct PairingTestParameters {
168 bool p224_on_client;
169 bool curve25519_on_client;
170 bool p224_on_host;
171 bool curve25519_on_host;
172
173 bool expect_curve25519_used;
174 };
175
176 class NegotiatingPairingAuthenticatorTest
177 : public NegotiatingAuthenticatorTest,
178 public testing::WithParamInterface<PairingTestParameters> {
179 public:
180 void InitAuthenticators(const std::string& client_id,
181 const std::string& client_paired_secret,
182 const std::string& client_interactive_pin,
183 const std::string& host_secret,
184 bool it2me) override {
185 NegotiatingAuthenticatorTest::InitAuthenticators(
186 client_id, client_paired_secret, client_interactive_pin, host_secret,
187 it2me);
188 if (!GetParam().p224_on_client) {
189 DisableMethodOnClient(
190 NegotiatingAuthenticatorBase::Method::PAIRED_SPAKE2_P224);
191 }
192 if (!GetParam().curve25519_on_client) {
193 DisableMethodOnClient(
194 NegotiatingAuthenticatorBase::Method::PAIRED_SPAKE2_CURVE25519);
195 }
196 if (!GetParam().p224_on_host) {
197 DisableMethodOnHost(
198 NegotiatingAuthenticatorBase::Method::PAIRED_SPAKE2_P224);
199 }
200 if (!GetParam().curve25519_on_host) {
201 DisableMethodOnHost(
202 NegotiatingAuthenticatorBase::Method::PAIRED_SPAKE2_CURVE25519);
203 }
204 }
205
206 void VerifyAccepted() override {
207 NegotiatingAuthenticatorTest::VerifyAccepted();
208 EXPECT_TRUE(
209 current_method() ==
210 NegotiatingAuthenticatorBase::Method::PAIRED_SPAKE2_P224 ||
211 current_method() ==
212 NegotiatingAuthenticatorBase::Method::PAIRED_SPAKE2_CURVE25519);
213 }
214 };
215
216 INSTANTIATE_TEST_CASE_P(
217 PairingParams,
218 NegotiatingPairingAuthenticatorTest,
219 testing::Values(
220 // Only P224.
221 PairingTestParameters{true, false, true, false},
222
223 // Only curve25519.
224 PairingTestParameters{false, true, false, true},
225
226 // Both P224 and curve25519.
227 PairingTestParameters{true, true, true, true},
228
229 // One end supports both, the other supports only P224 or curve25519.
230 PairingTestParameters{false, true, true, true},
231 PairingTestParameters{true, false, true, true},
232 PairingTestParameters{true, true, false, true},
233 PairingTestParameters{true, true, true, false}));
234
147 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthMe2MePin) { 235 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthMe2MePin) {
148 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret, 236 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret,
149 kTestPin, kTestPin, false)); 237 kTestPin, kTestPin, false));
150 VerifyAccepted( 238 VerifyAccepted();
151 NegotiatingAuthenticatorBase::Method::SHARED_SECRET_SPAKE2_CURVE25519); 239 EXPECT_EQ(
240 NegotiatingAuthenticatorBase::Method::SHARED_SECRET_SPAKE2_CURVE25519,
241 current_method());
152 } 242 }
153 243
154 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthIt2me) { 244 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthIt2me) {
155 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret, 245 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret,
156 kTestPin, kTestPin, true)); 246 kTestPin, kTestPin, true));
157 VerifyAccepted( 247 VerifyAccepted();
158 NegotiatingAuthenticatorBase::Method::SHARED_SECRET_PLAIN_SPAKE2_P224); 248 EXPECT_EQ(
249 NegotiatingAuthenticatorBase::Method::SHARED_SECRET_PLAIN_SPAKE2_P224,
250 current_method());
159 } 251 }
160 252
161 TEST_F(NegotiatingAuthenticatorTest, InvalidMe2MePin) { 253 TEST_F(NegotiatingAuthenticatorTest, InvalidMe2MePin) {
162 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret, 254 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret,
163 kTestPinBad, kTestPin, false)); 255 kTestPinBad, kTestPin, false));
164 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 256 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
165 257
166 VerifyRejected(Authenticator::INVALID_CREDENTIALS); 258 VerifyRejected(Authenticator::INVALID_CREDENTIALS);
167 } 259 }
168 260
169 TEST_F(NegotiatingAuthenticatorTest, InvalidIt2MeAccessCode) { 261 TEST_F(NegotiatingAuthenticatorTest, InvalidIt2MeAccessCode) {
170 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret, 262 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret,
171 kTestPin, kTestPinBad, true)); 263 kTestPin, kTestPinBad, true));
172 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 264 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
173 265
174 VerifyRejected(Authenticator::INVALID_CREDENTIALS); 266 VerifyRejected(Authenticator::INVALID_CREDENTIALS);
175 } 267 }
176 268
177 TEST_F(NegotiatingAuthenticatorTest, IncompatibleMethods) { 269 TEST_F(NegotiatingAuthenticatorTest, IncompatibleMethods) {
178 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret, 270 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret,
179 kTestPin, kTestPinBad, true)); 271 kTestPin, kTestPinBad, true));
180 std::vector<NegotiatingAuthenticatorBase::Method>* methods = 272 DisableMethodOnClient(
181 &(client_as_negotiating_authenticator_->methods_); 273 NegotiatingAuthenticatorBase::Method::SHARED_SECRET_PLAIN_SPAKE2_P224);
182 methods->erase(std::find(
183 methods->begin(), methods->end(),
184 NegotiatingAuthenticatorBase::Method::SHARED_SECRET_PLAIN_SPAKE2_P224));
185 274
186 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 275 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
187 276
188 VerifyRejected(Authenticator::PROTOCOL_ERROR); 277 VerifyRejected(Authenticator::PROTOCOL_ERROR);
189 } 278 }
190 279
191 TEST_F(NegotiatingAuthenticatorTest, PairingNotSupported) { 280 TEST_F(NegotiatingAuthenticatorTest, PairingNotSupported) {
192 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kTestClientId, kTestPairedSecret, 281 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kTestClientId, kTestPairedSecret,
193 kTestPin, kTestPin, false)); 282 kTestPin, kTestPin, false));
194 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 283 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
195 VerifyAccepted( 284 VerifyAccepted();
196 NegotiatingAuthenticatorBase::Method::SHARED_SECRET_SPAKE2_CURVE25519); 285 EXPECT_EQ(
286 NegotiatingAuthenticatorBase::Method::SHARED_SECRET_SPAKE2_CURVE25519,
287 current_method());
197 } 288 }
198 289
199 TEST_F(NegotiatingAuthenticatorTest, PairingSupportedButNotPaired) { 290 TEST_P(NegotiatingPairingAuthenticatorTest, PairingSupportedButNotPaired) {
200 CreatePairingRegistry(false); 291 CreatePairingRegistry(false);
201 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret, 292 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kNoClientId, kNoPairedSecret,
202 kTestPin, kTestPin, false)); 293 kTestPin, kTestPin, false));
203 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 294 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
204 VerifyAccepted(NegotiatingAuthenticatorBase::Method::PAIRED_SPAKE2_P224); 295 VerifyAccepted();
205 } 296 }
206 297
207 TEST_F(NegotiatingAuthenticatorTest, PairingRevokedPinOkay) { 298 TEST_P(NegotiatingPairingAuthenticatorTest, PairingRevokedPinOkay) {
208 CreatePairingRegistry(false); 299 CreatePairingRegistry(false);
209 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kTestClientId, kTestPairedSecret, 300 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kTestClientId, kTestPairedSecret,
210 kTestPin, kTestPin, false)); 301 kTestPin, kTestPin, false));
211 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 302 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
212 VerifyAccepted(NegotiatingAuthenticatorBase::Method::PAIRED_SPAKE2_P224); 303 VerifyAccepted();
213 } 304 }
214 305
215 TEST_F(NegotiatingAuthenticatorTest, PairingRevokedPinBad) { 306 TEST_P(NegotiatingPairingAuthenticatorTest, PairingRevokedPinBad) {
216 CreatePairingRegistry(false); 307 CreatePairingRegistry(false);
217 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kTestClientId, kTestPairedSecret, 308 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kTestClientId, kTestPairedSecret,
218 kTestPinBad, kTestPin, false)); 309 kTestPinBad, kTestPin, false));
219 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 310 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
220 VerifyRejected(Authenticator::INVALID_CREDENTIALS); 311 VerifyRejected(Authenticator::INVALID_CREDENTIALS);
221 } 312 }
222 313
223 TEST_F(NegotiatingAuthenticatorTest, PairingSucceeded) { 314 TEST_P(NegotiatingPairingAuthenticatorTest, PairingSucceeded) {
224 CreatePairingRegistry(true); 315 CreatePairingRegistry(true);
225 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kTestClientId, kTestPairedSecret, 316 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(kTestClientId, kTestPairedSecret,
226 kTestPinBad, kTestPin, false)); 317 kTestPinBad, kTestPin, false));
227 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 318 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
228 VerifyAccepted(NegotiatingAuthenticatorBase::Method::PAIRED_SPAKE2_P224); 319 VerifyAccepted();
229 } 320 }
230 321
231 TEST_F(NegotiatingAuthenticatorTest, 322 TEST_P(NegotiatingPairingAuthenticatorTest,
232 PairingSucceededInvalidSecretButPinOkay) { 323 PairingSucceededInvalidSecretButPinOkay) {
233 CreatePairingRegistry(true); 324 CreatePairingRegistry(true);
234 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( 325 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(
235 kTestClientId, kTestPairedSecretBad, kTestPin, kTestPin, false)); 326 kTestClientId, kTestPairedSecretBad, kTestPin, kTestPin, false));
236 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 327 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
237 VerifyAccepted(NegotiatingAuthenticatorBase::Method::PAIRED_SPAKE2_P224); 328 VerifyAccepted();
238 } 329 }
239 330
240 TEST_F(NegotiatingAuthenticatorTest, PairingFailedInvalidSecretAndPin) { 331 TEST_P(NegotiatingPairingAuthenticatorTest, PairingFailedInvalidSecretAndPin) {
241 CreatePairingRegistry(true); 332 CreatePairingRegistry(true);
242 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( 333 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(
243 kTestClientId, kTestPairedSecretBad, kTestPinBad, kTestPin, false)); 334 kTestClientId, kTestPairedSecretBad, kTestPinBad, kTestPin, false));
244 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 335 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
245 VerifyRejected(Authenticator::INVALID_CREDENTIALS); 336 VerifyRejected(Authenticator::INVALID_CREDENTIALS);
246 } 337 }
247 338
248 } // namespace protocol 339 } // namespace protocol
249 } // namespace remoting 340 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/negotiating_authenticator_base.cc ('k') | remoting/protocol/negotiating_client_authenticator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698