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

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

Issue 8647001: Add implementation for current IT2Me auth. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/protocol/simple_client_authenticator.h"
6
7 #include "base/base64.h"
8 #include "base/logging.h"
9 #include "remoting/base/constants.h"
10 #include "remoting/protocol/auth_util.h"
11 #include "remoting/protocol/simple_client_channel_authenticator.h"
12 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
13
14 using buzz::QName;
15 using buzz::XmlElement;
16
17 namespace remoting {
18 namespace protocol {
19
20 namespace {
21 const char kAuthenticationTag[] = "authentication";
22 const char kAuthTokenTag[] = "auth-token";
23 const char kCertificateTag[] = "certificate";
24 } // namespace
25
26 SimpleClientAuthenticator::SimpleClientAuthenticator(
27 const std::string& local_jid,
28 const std::string& shared_secret)
29 : local_jid_(local_jid),
30 shared_secret_(shared_secret),
31 state_(MESSAGE_READY) {
32 }
33
34 SimpleClientAuthenticator::~SimpleClientAuthenticator() {
35 }
36
37 Authenticator::State SimpleClientAuthenticator::state() const {
38 return state_;
39 }
40
41 void SimpleClientAuthenticator::ProcessMessage(const XmlElement* message) {
42 DCHECK_EQ(state_, WAITING_MESSAGE);
43
44 // Parse the certificate.
45 const XmlElement* cert_tag =
46 message->FirstNamed(QName(kChromotingXmlNamespace, kCertificateTag));
47 if (cert_tag) {
48 std::string base64_cert = cert_tag->BodyText();
49 if (!base::Base64Decode(base64_cert, &remote_cert_)) {
50 LOG(ERROR) << "Failed to decode certificate received from the peer.";
51 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.
52 }
53 }
54
55 if (remote_cert_.empty()) {
56 state_ = REJECTED;
57 } else {
58 state_ = ACCEPTED;
59 }
60 }
61
62 XmlElement* SimpleClientAuthenticator::GetNextMessage() {
63 DCHECK_EQ(state_, MESSAGE_READY);
64
65 XmlElement* authentication_tag = new XmlElement(
66 QName(kChromotingXmlNamespace, kAuthenticationTag));
67
68 std::string token =
69 protocol::GenerateSupportAuthToken(local_jid_, shared_secret_);
70
71 XmlElement* auth_token_tag = new XmlElement(
72 QName(kChromotingXmlNamespace, kAuthTokenTag));
73 auth_token_tag->SetBodyText(token);
74 authentication_tag->AddElement(auth_token_tag);
75
76 state_ = WAITING_MESSAGE;
77 return authentication_tag;
78 }
79
80 ChannelAuthenticator*
81 SimpleClientAuthenticator::CreateChannelAuthenticator() const {
82 DCHECK_EQ(state_, ACCEPTED);
83 return new SimpleClientChannelAuthenticator(remote_cert_, shared_secret_);
84 };
85
86 } // namespace remoting
87 } // namespace protocol
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698