| OLD | NEW |
| 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 "remoting/protocol/negotiating_authenticator.h" | 5 #include "remoting/protocol/negotiating_authenticator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "remoting/base/rsa_key_pair.h" | 9 #include "remoting/base/rsa_key_pair.h" |
| 10 #include "remoting/protocol/authenticator_test_base.h" | 10 #include "remoting/protocol/authenticator_test_base.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 host_cert_, key_pair_, host_secret_hash, hash_function); | 52 host_cert_, key_pair_, host_secret_hash, hash_function); |
| 53 | 53 |
| 54 std::vector<AuthenticationMethod> methods; | 54 std::vector<AuthenticationMethod> methods; |
| 55 methods.push_back(AuthenticationMethod::Spake2( | 55 methods.push_back(AuthenticationMethod::Spake2( |
| 56 AuthenticationMethod::HMAC_SHA256)); | 56 AuthenticationMethod::HMAC_SHA256)); |
| 57 if (!client_hmac_only) { | 57 if (!client_hmac_only) { |
| 58 methods.push_back(AuthenticationMethod::Spake2( | 58 methods.push_back(AuthenticationMethod::Spake2( |
| 59 AuthenticationMethod::NONE)); | 59 AuthenticationMethod::NONE)); |
| 60 } | 60 } |
| 61 client_ = NegotiatingAuthenticator::CreateForClient( | 61 client_ = NegotiatingAuthenticator::CreateForClient( |
| 62 kTestHostId, client_secret, methods); | 62 kTestHostId, base::Bind(&NegotiatingAuthenticatorTest::FetchSecret, |
| 63 client_secret), methods); |
| 63 } | 64 } |
| 64 | 65 |
| 66 static void FetchSecret( |
| 67 const std::string& client_secret, |
| 68 const protocol::SecretFetchedCallback& secret_fetched_callback) { |
| 69 secret_fetched_callback.Run(client_secret); |
| 70 } |
| 65 void VerifyRejected(Authenticator::RejectionReason reason) { | 71 void VerifyRejected(Authenticator::RejectionReason reason) { |
| 66 ASSERT_TRUE((client_->state() == Authenticator::REJECTED && | 72 ASSERT_TRUE((client_->state() == Authenticator::REJECTED && |
| 67 (client_->rejection_reason() == reason)) || | 73 (client_->rejection_reason() == reason)) || |
| 68 (host_->state() == Authenticator::REJECTED && | 74 (host_->state() == Authenticator::REJECTED && |
| 69 (host_->rejection_reason() == reason))); | 75 (host_->rejection_reason() == reason))); |
| 70 } | 76 } |
| 71 | 77 |
| 78 void VerifyAccepted() { |
| 79 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
| 80 |
| 81 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); |
| 82 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); |
| 83 |
| 84 client_auth_ = client_->CreateChannelAuthenticator(); |
| 85 host_auth_ = host_->CreateChannelAuthenticator(); |
| 86 RunChannelAuth(false); |
| 87 |
| 88 EXPECT_TRUE(client_socket_.get() != NULL); |
| 89 EXPECT_TRUE(host_socket_.get() != NULL); |
| 90 |
| 91 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
| 92 kMessageSize, kMessages); |
| 93 |
| 94 tester.Start(); |
| 95 message_loop_.Run(); |
| 96 tester.CheckResults(); |
| 97 } |
| 98 |
| 99 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticatorTest); | 100 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticatorTest); |
| 73 }; | 101 }; |
| 74 | 102 |
| 75 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthHmac) { | 103 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthHmac) { |
| 76 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 104 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
| 77 kTestSharedSecret, kTestSharedSecret, | 105 kTestSharedSecret, kTestSharedSecret, |
| 78 AuthenticationMethod::HMAC_SHA256, false)); | 106 AuthenticationMethod::HMAC_SHA256, false)); |
| 79 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 107 VerifyAccepted(); |
| 80 | |
| 81 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); | |
| 82 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); | |
| 83 | |
| 84 client_auth_ = client_->CreateChannelAuthenticator(); | |
| 85 host_auth_ = host_->CreateChannelAuthenticator(); | |
| 86 RunChannelAuth(false); | |
| 87 | |
| 88 EXPECT_TRUE(client_socket_.get() != NULL); | |
| 89 EXPECT_TRUE(host_socket_.get() != NULL); | |
| 90 | |
| 91 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | |
| 92 kMessageSize, kMessages); | |
| 93 | |
| 94 tester.Start(); | |
| 95 message_loop_.Run(); | |
| 96 tester.CheckResults(); | |
| 97 } | 108 } |
| 98 | 109 |
| 99 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthPlain) { | 110 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthPlain) { |
| 100 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 111 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
| 101 kTestSharedSecret, kTestSharedSecret, | 112 kTestSharedSecret, kTestSharedSecret, |
| 102 AuthenticationMethod::NONE, false)); | 113 AuthenticationMethod::NONE, false)); |
| 103 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 114 VerifyAccepted(); |
| 104 | |
| 105 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); | |
| 106 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); | |
| 107 | |
| 108 client_auth_ = client_->CreateChannelAuthenticator(); | |
| 109 host_auth_ = host_->CreateChannelAuthenticator(); | |
| 110 RunChannelAuth(false); | |
| 111 | |
| 112 EXPECT_TRUE(client_socket_.get() != NULL); | |
| 113 EXPECT_TRUE(host_socket_.get() != NULL); | |
| 114 | |
| 115 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | |
| 116 kMessageSize, kMessages); | |
| 117 | |
| 118 tester.Start(); | |
| 119 message_loop_.Run(); | |
| 120 tester.CheckResults(); | |
| 121 } | 115 } |
| 122 | 116 |
| 123 TEST_F(NegotiatingAuthenticatorTest, InvalidSecretHmac) { | 117 TEST_F(NegotiatingAuthenticatorTest, InvalidSecretHmac) { |
| 124 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 118 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
| 125 kTestSharedSecret, kTestSharedSecretBad, | 119 kTestSharedSecret, kTestSharedSecretBad, |
| 126 AuthenticationMethod::HMAC_SHA256, false)); | 120 AuthenticationMethod::HMAC_SHA256, false)); |
| 127 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 121 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
| 128 | 122 |
| 129 VerifyRejected(Authenticator::INVALID_CREDENTIALS); | 123 VerifyRejected(Authenticator::INVALID_CREDENTIALS); |
| 130 } | 124 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 142 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 136 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
| 143 kTestSharedSecret, kTestSharedSecretBad, | 137 kTestSharedSecret, kTestSharedSecretBad, |
| 144 AuthenticationMethod::NONE, true)); | 138 AuthenticationMethod::NONE, true)); |
| 145 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 139 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
| 146 | 140 |
| 147 VerifyRejected(Authenticator::PROTOCOL_ERROR); | 141 VerifyRejected(Authenticator::PROTOCOL_ERROR); |
| 148 } | 142 } |
| 149 | 143 |
| 150 } // namespace protocol | 144 } // namespace protocol |
| 151 } // namespace remoting | 145 } // namespace remoting |
| OLD | NEW |