Index: remoting/protocol/simple_client_authenticator.cc |
diff --git a/remoting/protocol/simple_client_authenticator.cc b/remoting/protocol/simple_client_authenticator.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bca79d56db4985580e409b5e81bb569d8ed843c9 |
--- /dev/null |
+++ b/remoting/protocol/simple_client_authenticator.cc |
@@ -0,0 +1,87 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "remoting/protocol/simple_client_authenticator.h" |
+ |
+#include "base/base64.h" |
+#include "base/logging.h" |
+#include "remoting/base/constants.h" |
+#include "remoting/protocol/auth_util.h" |
+#include "remoting/protocol/simple_client_channel_authenticator.h" |
+#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
+ |
+using buzz::QName; |
+using buzz::XmlElement; |
+ |
+namespace remoting { |
+namespace protocol { |
+ |
+namespace { |
+const char kAuthenticationTag[] = "authentication"; |
+const char kAuthTokenTag[] = "auth-token"; |
+const char kCertificateTag[] = "certificate"; |
+} // namespace |
+ |
+SimpleClientAuthenticator::SimpleClientAuthenticator( |
+ const std::string& local_jid, |
+ const std::string& shared_secret) |
+ : local_jid_(local_jid), |
+ shared_secret_(shared_secret), |
+ state_(MESSAGE_READY) { |
+} |
+ |
+SimpleClientAuthenticator::~SimpleClientAuthenticator() { |
+} |
+ |
+Authenticator::State SimpleClientAuthenticator::state() const { |
+ return state_; |
+} |
+ |
+void SimpleClientAuthenticator::ProcessMessage(const XmlElement* message) { |
+ DCHECK_EQ(state_, WAITING_MESSAGE); |
+ |
+ // Parse the certificate. |
+ const XmlElement* cert_tag = |
+ message->FirstNamed(QName(kChromotingXmlNamespace, kCertificateTag)); |
+ if (cert_tag) { |
+ std::string base64_cert = cert_tag->BodyText(); |
+ if (!base::Base64Decode(base64_cert, &remote_cert_)) { |
+ LOG(ERROR) << "Failed to decode certificate received from the peer."; |
+ remote_cert_ = ""; |
Wez
2011/11/22 22:58:05
nit: Is there no .clear() or similar in std::strin
Sergey Ulanov
2011/11/23 02:02:25
Done.
|
+ } |
+ } |
+ |
+ if (remote_cert_.empty()) { |
+ state_ = REJECTED; |
+ } else { |
+ state_ = ACCEPTED; |
+ } |
+} |
+ |
+XmlElement* SimpleClientAuthenticator::GetNextMessage() { |
+ DCHECK_EQ(state_, MESSAGE_READY); |
+ |
+ XmlElement* authentication_tag = new XmlElement( |
+ QName(kChromotingXmlNamespace, kAuthenticationTag)); |
+ |
+ std::string token = |
+ protocol::GenerateSupportAuthToken(local_jid_, shared_secret_); |
+ |
+ XmlElement* auth_token_tag = new XmlElement( |
+ QName(kChromotingXmlNamespace, kAuthTokenTag)); |
+ auth_token_tag->SetBodyText(token); |
+ authentication_tag->AddElement(auth_token_tag); |
+ |
+ state_ = WAITING_MESSAGE; |
+ return authentication_tag; |
+} |
+ |
+ChannelAuthenticator* |
+SimpleClientAuthenticator::CreateChannelAuthenticator() const { |
+ DCHECK_EQ(state_, ACCEPTED); |
+ return new SimpleClientChannelAuthenticator(remote_cert_, shared_secret_); |
+}; |
+ |
+} // namespace remoting |
+} // namespace protocol |