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

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

Issue 1277093006: Enable QUIC support in chromoting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@quic_adapters
Patch Set: Created 5 years, 4 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/fake_authenticator.h ('k') | remoting/protocol/fake_session.h » ('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 (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/fake_authenticator.h" 5 #include "remoting/protocol/fake_authenticator.h"
6 6
7 #include "base/base64.h"
7 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/rand_util.h"
9 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
10 #include "net/base/io_buffer.h" 12 #include "net/base/io_buffer.h"
11 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
12 #include "remoting/base/constants.h" 14 #include "remoting/base/constants.h"
13 #include "remoting/protocol/p2p_stream_socket.h" 15 #include "remoting/protocol/p2p_stream_socket.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" 17 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
16 18
17 namespace remoting { 19 namespace remoting {
18 namespace protocol { 20 namespace protocol {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 if (did_write_bytes_) 83 if (did_write_bytes_)
82 CallDoneCallback(); 84 CallDoneCallback();
83 } 85 }
84 86
85 void FakeChannelAuthenticator::CallDoneCallback() { 87 void FakeChannelAuthenticator::CallDoneCallback() {
86 if (result_ != net::OK) 88 if (result_ != net::OK)
87 socket_.reset(); 89 socket_.reset();
88 base::ResetAndReturn(&done_callback_).Run(result_, socket_.Pass()); 90 base::ResetAndReturn(&done_callback_).Run(result_, socket_.Pass());
89 } 91 }
90 92
91 FakeAuthenticator::FakeAuthenticator( 93 FakeAuthenticator::FakeAuthenticator(Type type,
92 Type type, int round_trips, Action action, bool async) 94 int round_trips,
95 Action action,
96 bool async)
93 : type_(type), 97 : type_(type),
94 round_trips_(round_trips), 98 round_trips_(round_trips),
95 action_(action), 99 action_(action),
96 async_(async), 100 async_(async),
97 messages_(0), 101 messages_(0),
98 messages_till_started_(0) { 102 messages_till_started_(0) {
99 } 103 }
100 104
101 FakeAuthenticator::~FakeAuthenticator() { 105 FakeAuthenticator::~FakeAuthenticator() {
102 } 106 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 EXPECT_EQ(REJECTED, state()); 143 EXPECT_EQ(REJECTED, state());
140 return INVALID_CREDENTIALS; 144 return INVALID_CREDENTIALS;
141 } 145 }
142 146
143 void FakeAuthenticator::ProcessMessage(const buzz::XmlElement* message, 147 void FakeAuthenticator::ProcessMessage(const buzz::XmlElement* message,
144 const base::Closure& resume_callback) { 148 const base::Closure& resume_callback) {
145 EXPECT_EQ(WAITING_MESSAGE, state()); 149 EXPECT_EQ(WAITING_MESSAGE, state());
146 std::string id = 150 std::string id =
147 message->TextNamed(buzz::QName(kChromotingXmlNamespace, "id")); 151 message->TextNamed(buzz::QName(kChromotingXmlNamespace, "id"));
148 EXPECT_EQ(id, base::IntToString(messages_)); 152 EXPECT_EQ(id, base::IntToString(messages_));
153
154 // On the client receive the key in the last message.
155 if (type_ == CLIENT && messages_ == round_trips_ * 2 - 1) {
156 std::string key_base64 =
157 message->TextNamed(buzz::QName(kChromotingXmlNamespace, "key"));
158 EXPECT_TRUE(!key_base64.empty());
159 EXPECT_TRUE(base::Base64Decode(key_base64, &auth_key_));
160 }
161
149 ++messages_; 162 ++messages_;
150 resume_callback.Run(); 163 resume_callback.Run();
151 } 164 }
152 165
153 scoped_ptr<buzz::XmlElement> FakeAuthenticator::GetNextMessage() { 166 scoped_ptr<buzz::XmlElement> FakeAuthenticator::GetNextMessage() {
154 EXPECT_EQ(MESSAGE_READY, state()); 167 EXPECT_EQ(MESSAGE_READY, state());
155 168
156 scoped_ptr<buzz::XmlElement> result(new buzz::XmlElement( 169 scoped_ptr<buzz::XmlElement> result(new buzz::XmlElement(
157 buzz::QName(kChromotingXmlNamespace, "authentication"))); 170 buzz::QName(kChromotingXmlNamespace, "authentication")));
158 buzz::XmlElement* id = new buzz::XmlElement( 171 buzz::XmlElement* id = new buzz::XmlElement(
159 buzz::QName(kChromotingXmlNamespace, "id")); 172 buzz::QName(kChromotingXmlNamespace, "id"));
160 id->AddText(base::IntToString(messages_)); 173 id->AddText(base::IntToString(messages_));
161 result->AddElement(id); 174 result->AddElement(id);
162 175
176 // Add authentication key in the last message sent from host to client.
177 if (type_ == HOST && messages_ == round_trips_ * 2 - 1) {
178 auth_key_ = base::RandBytesAsString(16);
179 buzz::XmlElement* key = new buzz::XmlElement(
180 buzz::QName(kChromotingXmlNamespace, "key"));
181 std::string key_base64;
182 base::Base64Encode(auth_key_, &key_base64);
183 key->AddText(key_base64);
184 result->AddElement(key);
185 }
186
163 ++messages_; 187 ++messages_;
164 return result.Pass(); 188 return result.Pass();
165 } 189 }
166 190
191 const std::string& FakeAuthenticator::GetAuthKey() const {
192 EXPECT_EQ(ACCEPTED, state());
193 return auth_key_;
194 }
195
167 scoped_ptr<ChannelAuthenticator> 196 scoped_ptr<ChannelAuthenticator>
168 FakeAuthenticator::CreateChannelAuthenticator() const { 197 FakeAuthenticator::CreateChannelAuthenticator() const {
169 EXPECT_EQ(ACCEPTED, state()); 198 EXPECT_EQ(ACCEPTED, state());
170 return make_scoped_ptr( 199 return make_scoped_ptr(
171 new FakeChannelAuthenticator(action_ != REJECT_CHANNEL, async_)); 200 new FakeChannelAuthenticator(action_ != REJECT_CHANNEL, async_));
172 } 201 }
173 202
174 FakeHostAuthenticatorFactory::FakeHostAuthenticatorFactory( 203 FakeHostAuthenticatorFactory::FakeHostAuthenticatorFactory(
175 int round_trips, int messages_till_started, 204 int round_trips, int messages_till_started,
176 FakeAuthenticator::Action action, bool async) 205 FakeAuthenticator::Action action, bool async)
(...skipping 12 matching lines...) Expand all
189 FakeAuthenticator* authenticator = new FakeAuthenticator( 218 FakeAuthenticator* authenticator = new FakeAuthenticator(
190 FakeAuthenticator::HOST, round_trips_, action_, async_); 219 FakeAuthenticator::HOST, round_trips_, action_, async_);
191 authenticator->set_messages_till_started(messages_till_started_); 220 authenticator->set_messages_till_started(messages_till_started_);
192 221
193 scoped_ptr<Authenticator> result(authenticator); 222 scoped_ptr<Authenticator> result(authenticator);
194 return result.Pass(); 223 return result.Pass();
195 } 224 }
196 225
197 } // namespace protocol 226 } // namespace protocol
198 } // namespace remoting 227 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/fake_authenticator.h ('k') | remoting/protocol/fake_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698