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

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

Issue 12326090: Third Party authentication protocol. (Closed) Base URL: http://git.chromium.org/chromium/src.git@host_key_pair
Patch Set: REviewer comments Created 7 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2013 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/third_party_client_authenticator.h"
6
7 #include "base/base64.h"
8 #include "base/bind.h"
9 #include "base/callback.h"
10 #include "base/logging.h"
11 #include "googleurl/src/gurl.h"
12 #include "remoting/base/constants.h"
13 #include "remoting/base/rsa_key_pair.h"
14 #include "remoting/protocol/channel_authenticator.h"
15 #include "remoting/protocol/v2_authenticator.h"
16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
17
18 namespace remoting {
19 namespace protocol {
20
21 ThirdPartyClientAuthenticator::ThirdPartyClientAuthenticator(
22 const std::string& host_public_key,
23 scoped_ptr<TokenFetcher> token_fetcher)
24 : ThirdPartyAuthenticatorBase(WAITING_MESSAGE),
25 host_public_key_(host_public_key),
26 token_fetcher_(token_fetcher.Pass()) {
27 }
28
29 ThirdPartyClientAuthenticator::~ThirdPartyClientAuthenticator() {
30 }
31
32 void ThirdPartyClientAuthenticator::ProcessTokenMessage(
33 const buzz::XmlElement* message,
34 const base::Closure& resume_callback) {
35 std::string token_url = message->TextNamed(kTokenUrlTag);
36 std::string token_scope = message->TextNamed(kTokenScopeTag);
37
38 if (token_url.empty() || token_scope.empty()) {
39 LOG(ERROR) << "Third-party authentication protocol error: "
40 "missing token verification URL or scope.";
41 token_state_ = REJECTED;
42 rejection_reason_ = PROTOCOL_ERROR;
43 resume_callback.Run();
44 return;
45 }
46
47 token_state_ = PROCESSING_MESSAGE;
48
49 // |token_fetcher_| is owned, so Unretained() is safe here.
50 token_fetcher_->FetchThirdPartyToken(
51 GURL(token_url), host_public_key_, token_scope, base::Bind(
52 &ThirdPartyClientAuthenticator::OnThirdPartyTokenFetched,
53 base::Unretained(this), resume_callback));
54 }
55
56 void ThirdPartyClientAuthenticator::AddTokenElements(
57 buzz::XmlElement* message) {
58 DCHECK_EQ(token_state_, MESSAGE_READY);
59 DCHECK(!token_.empty());
60
61 buzz::XmlElement* token_tag = new buzz::XmlElement(kTokenTag);
62 token_tag->SetBodyText(token_);
63 message->AddElement(token_tag);
64 token_state_ = ACCEPTED;
65 }
66
67 void ThirdPartyClientAuthenticator::OnThirdPartyTokenFetched(
68 const base::Closure& resume_callback,
69 const std::string& third_party_token,
70 const std::string& shared_secret) {
71 token_ = third_party_token;
72 if (token_.empty() || shared_secret.empty()) {
73 token_state_ = REJECTED;
74 rejection_reason_ = INVALID_CREDENTIALS;
75 } else {
76 token_state_ = MESSAGE_READY;
77 underlying_ = V2Authenticator::CreateForClient(
78 shared_secret, MESSAGE_READY);
79 }
80 resume_callback.Run();
81 }
82
83 } // namespace protocol
84 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/third_party_client_authenticator.h ('k') | remoting/protocol/third_party_host_authenticator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698