| 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, client_secret, NULL, methods); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void VerifyRejected(Authenticator::RejectionReason reason) { | 65 void VerifyRejected(Authenticator::RejectionReason reason) { |
| 66 ASSERT_TRUE((client_->state() == Authenticator::REJECTED && | 66 ASSERT_TRUE((client_->state() == Authenticator::REJECTED && |
| 67 (client_->rejection_reason() == reason)) || | 67 (client_->rejection_reason() == reason)) || |
| 68 (host_->state() == Authenticator::REJECTED && | 68 (host_->state() == Authenticator::REJECTED && |
| 69 (host_->rejection_reason() == reason))); | 69 (host_->rejection_reason() == reason))); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void VerifyAccepted() { |
| 73 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
| 74 |
| 75 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); |
| 76 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); |
| 77 |
| 78 client_auth_ = client_->CreateChannelAuthenticator(); |
| 79 host_auth_ = host_->CreateChannelAuthenticator(); |
| 80 RunChannelAuth(false); |
| 81 |
| 82 EXPECT_TRUE(client_socket_.get() != NULL); |
| 83 EXPECT_TRUE(host_socket_.get() != NULL); |
| 84 |
| 85 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
| 86 kMessageSize, kMessages); |
| 87 |
| 88 tester.Start(); |
| 89 message_loop_.Run(); |
| 90 tester.CheckResults(); |
| 91 } |
| 92 |
| 93 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticatorTest); | 94 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticatorTest); |
| 73 }; | 95 }; |
| 74 | 96 |
| 75 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthHmac) { | 97 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthHmac) { |
| 76 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 98 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
| 77 kTestSharedSecret, kTestSharedSecret, | 99 kTestSharedSecret, kTestSharedSecret, |
| 78 AuthenticationMethod::HMAC_SHA256, false)); | 100 AuthenticationMethod::HMAC_SHA256, false)); |
| 79 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 101 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 } | 102 } |
| 98 | 103 |
| 99 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthPlain) { | 104 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthPlain) { |
| 100 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 105 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
| 101 kTestSharedSecret, kTestSharedSecret, | 106 kTestSharedSecret, kTestSharedSecret, |
| 102 AuthenticationMethod::NONE, false)); | 107 AuthenticationMethod::NONE, false)); |
| 103 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 108 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 } | 109 } |
| 122 | 110 |
| 123 TEST_F(NegotiatingAuthenticatorTest, InvalidSecretHmac) { | 111 TEST_F(NegotiatingAuthenticatorTest, InvalidSecretHmac) { |
| 124 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 112 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
| 125 kTestSharedSecret, kTestSharedSecretBad, | 113 kTestSharedSecret, kTestSharedSecretBad, |
| 126 AuthenticationMethod::HMAC_SHA256, false)); | 114 AuthenticationMethod::HMAC_SHA256, false)); |
| 127 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 115 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
| 128 | 116 |
| 129 VerifyRejected(Authenticator::INVALID_CREDENTIALS); | 117 VerifyRejected(Authenticator::INVALID_CREDENTIALS); |
| 130 } | 118 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 142 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( | 130 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( |
| 143 kTestSharedSecret, kTestSharedSecretBad, | 131 kTestSharedSecret, kTestSharedSecretBad, |
| 144 AuthenticationMethod::NONE, true)); | 132 AuthenticationMethod::NONE, true)); |
| 145 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 133 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
| 146 | 134 |
| 147 VerifyRejected(Authenticator::PROTOCOL_ERROR); | 135 VerifyRejected(Authenticator::PROTOCOL_ERROR); |
| 148 } | 136 } |
| 149 | 137 |
| 150 } // namespace protocol | 138 } // namespace protocol |
| 151 } // namespace remoting | 139 } // namespace remoting |
| OLD | NEW |