OLD | NEW |
---|---|
(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 "remoting/base/constants.h" | |
12 #include "remoting/base/rsa_key_pair.h" | |
13 #include "remoting/protocol/channel_authenticator.h" | |
14 #include "remoting/protocol/v2_authenticator.h" | |
15 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | |
16 | |
17 namespace remoting { | |
18 namespace protocol { | |
19 | |
20 ThirdPartyClientAuthenticator::ThirdPartyClientAuthenticator( | |
21 const std::string& host_public_key, | |
22 const FetchTokenCallback& fetch_token_callback) | |
23 : ThirdPartyAuthenticatorBase(WAITING_MESSAGE), | |
24 host_public_key_(host_public_key), | |
25 fetch_token_callback_(fetch_token_callback), | |
26 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
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 if (!token_url.empty() && !token_scope.empty()) { | |
38 token_state_ = PROCESSING_MESSAGE; | |
39 fetch_token_callback_.Run( | |
40 GURL(token_url), host_public_key_, token_scope, base::Bind( | |
41 &ThirdPartyClientAuthenticator::OnThirdPartyTokenFetched, | |
42 weak_factory_.GetWeakPtr(), resume_callback)); | |
43 return; | |
44 } | |
45 | |
46 LOG(ERROR) << "Third-party authentication protocol error: " | |
47 "missing token verification URL or scope."; | |
48 token_state_ = REJECTED; | |
49 rejection_reason_ = PROTOCOL_ERROR; | |
50 resume_callback.Run(); | |
51 } | |
52 | |
53 void ThirdPartyClientAuthenticator::AddTokenElements( | |
54 buzz::XmlElement* message) { | |
55 DCHECK(token_state_ == MESSAGE_READY); | |
56 DCHECK(!token_.empty()); | |
57 | |
58 buzz::XmlElement* token_tag = new buzz::XmlElement(kTokenTag); | |
59 token_tag->SetBodyText(token_); | |
60 message->AddElement(token_tag); | |
61 token_state_ = ACCEPTED; | |
62 } | |
63 | |
64 void ThirdPartyClientAuthenticator::OnThirdPartyTokenFetched( | |
65 const base::Closure& resume_callback, const std::string& third_party_token, | |
Sergey Ulanov
2013/03/20 07:24:12
nit: one argument per line please
rmsousa
2013/03/21 01:23:25
Done.
| |
66 const std::string& shared_secret) { | |
67 token_ = third_party_token; | |
68 if (!token_.empty() && !shared_secret.empty()) { | |
69 token_state_ = MESSAGE_READY; | |
70 underlying_ = V2Authenticator::CreateForClient( | |
71 shared_secret, MESSAGE_READY); | |
72 } else { | |
73 token_state_ = REJECTED; | |
74 rejection_reason_ = INVALID_CREDENTIALS; | |
75 } | |
76 resume_callback.Run(); | |
77 } | |
78 | |
79 } // namespace protocol | |
80 } // namespace remoting | |
OLD | NEW |