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

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

Issue 1759313002: Implement authenticator based on SPAKE2 implementation in boringssl. (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
« no previous file with comments | « remoting/protocol/spake2_authenticator.cc ('k') | remoting/remoting.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "remoting/protocol/v2_authenticator.h" 5 #include "remoting/protocol/spake2_authenticator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "net/base/net_errors.h"
10 #include "remoting/base/rsa_key_pair.h" 9 #include "remoting/base/rsa_key_pair.h"
11 #include "remoting/protocol/authenticator_test_base.h" 10 #include "remoting/protocol/authenticator_test_base.h"
12 #include "remoting/protocol/channel_authenticator.h" 11 #include "remoting/protocol/channel_authenticator.h"
13 #include "remoting/protocol/connection_tester.h" 12 #include "remoting/protocol/connection_tester.h"
14 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" 15 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
17 16
18 using testing::_; 17 using testing::_;
19 using testing::DeleteArg; 18 using testing::DeleteArg;
20 using testing::SaveArg; 19 using testing::SaveArg;
21 20
22 namespace remoting { 21 namespace remoting {
23 namespace protocol { 22 namespace protocol {
24 23
25 namespace { 24 namespace {
26 25
27 const int kMessageSize = 100; 26 const int kMessageSize = 100;
28 const int kMessages = 1; 27 const int kMessages = 1;
29 28
29 const char kClientId[] = "alice@gmail.com/abc";
30 const char kHostId[] = "alice@gmail.com/123";
31
30 const char kTestSharedSecret[] = "1234-1234-5678"; 32 const char kTestSharedSecret[] = "1234-1234-5678";
31 const char kTestSharedSecretBad[] = "0000-0000-0001"; 33 const char kTestSharedSecretBad[] = "0000-0000-0001";
32 34
33 } // namespace 35 } // namespace
34 36
35 class V2AuthenticatorTest : public AuthenticatorTestBase { 37 class Spake2AuthenticatorTest : public AuthenticatorTestBase {
36 public: 38 public:
37 V2AuthenticatorTest() { 39 Spake2AuthenticatorTest() {}
38 } 40 ~Spake2AuthenticatorTest() override {}
39 ~V2AuthenticatorTest() override {}
40 41
41 protected: 42 protected:
42 void InitAuthenticators(const std::string& client_secret, 43 void InitAuthenticators(const std::string& client_secret,
43 const std::string& host_secret) { 44 const std::string& host_secret) {
44 host_ = V2Authenticator::CreateForHost( 45 host_ = Spake2Authenticator::CreateForHost(kHostId, kClientId, host_secret,
45 host_cert_, key_pair_, host_secret, 46 host_cert_, key_pair_,
46 Authenticator::WAITING_MESSAGE); 47 Authenticator::WAITING_MESSAGE);
47 client_ = V2Authenticator::CreateForClient( 48 client_ = Spake2Authenticator::CreateForClient(
48 client_secret, Authenticator::MESSAGE_READY); 49 kClientId, kHostId, client_secret, Authenticator::MESSAGE_READY);
49 } 50 }
50 51
51 DISALLOW_COPY_AND_ASSIGN(V2AuthenticatorTest); 52 DISALLOW_COPY_AND_ASSIGN(Spake2AuthenticatorTest);
52 }; 53 };
53 54
54 TEST_F(V2AuthenticatorTest, SuccessfulAuth) { 55 TEST_F(Spake2AuthenticatorTest, SuccessfulAuth) {
55 ASSERT_NO_FATAL_FAILURE( 56 ASSERT_NO_FATAL_FAILURE(
56 InitAuthenticators(kTestSharedSecret, kTestSharedSecret)); 57 InitAuthenticators(kTestSharedSecret, kTestSharedSecret));
57 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 58 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
58 59
59 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); 60 ASSERT_EQ(Authenticator::ACCEPTED, host_->state());
60 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); 61 ASSERT_EQ(Authenticator::ACCEPTED, client_->state());
61 62
62 client_auth_ = client_->CreateChannelAuthenticator(); 63 client_auth_ = client_->CreateChannelAuthenticator();
63 host_auth_ = host_->CreateChannelAuthenticator(); 64 host_auth_ = host_->CreateChannelAuthenticator();
64 RunChannelAuth(false); 65 RunChannelAuth(false);
65 66
66 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), 67 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
67 kMessageSize, kMessages); 68 kMessageSize, kMessages);
68 69
69 tester.Start(); 70 tester.Start();
70 message_loop_.Run(); 71 message_loop_.Run();
71 tester.CheckResults(); 72 tester.CheckResults();
72 } 73 }
73 74
74 // Verify that connection is rejected when secrets don't match. 75 // Verify that connection is rejected when secrets don't match.
75 TEST_F(V2AuthenticatorTest, InvalidSecret) { 76 TEST_F(Spake2AuthenticatorTest, InvalidSecret) {
76 ASSERT_NO_FATAL_FAILURE( 77 ASSERT_NO_FATAL_FAILURE(
77 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret)); 78 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret));
78 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 79 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
79 80
80 ASSERT_EQ(Authenticator::REJECTED, client_->state()); 81 ASSERT_EQ(Authenticator::REJECTED, client_->state());
82 ASSERT_EQ(Authenticator::INVALID_CREDENTIALS, client_->rejection_reason());
81 83
82 // Change |client_| so that we can get the last message. 84 // Change |client_| so that we can get the last message.
83 reinterpret_cast<V2Authenticator*>(client_.get())->state_ = 85 reinterpret_cast<Spake2Authenticator*>(client_.get())->state_ =
84 Authenticator::MESSAGE_READY; 86 Authenticator::MESSAGE_READY;
85 87
86 scoped_ptr<buzz::XmlElement> message(client_->GetNextMessage()); 88 scoped_ptr<buzz::XmlElement> message(client_->GetNextMessage());
87 ASSERT_TRUE(message.get()); 89 ASSERT_TRUE(message.get());
88 90
89 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state()); 91 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state());
90 host_->ProcessMessage(message.get(), base::Bind(&base::DoNothing)); 92 host_->ProcessMessage(message.get(), base::Bind(&base::DoNothing));
91 // This assumes that V2Authenticator::ProcessMessage runs synchronously. 93 // This assumes that Spake2Authenticator::ProcessMessage runs synchronously.
92 ASSERT_EQ(Authenticator::REJECTED, host_->state()); 94 ASSERT_EQ(Authenticator::REJECTED, host_->state());
93 } 95 }
94 96
95 } // namespace protocol 97 } // namespace protocol
96 } // namespace remoting 98 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/spake2_authenticator.cc ('k') | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698