OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/third_party_client_authenticator.h" | 5 #include "remoting/protocol/third_party_client_authenticator.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
13 #include "remoting/base/rsa_key_pair.h" | 13 #include "remoting/base/rsa_key_pair.h" |
14 #include "remoting/protocol/channel_authenticator.h" | 14 #include "remoting/protocol/channel_authenticator.h" |
15 #include "remoting/protocol/v2_authenticator.h" | 15 #include "remoting/protocol/v2_authenticator.h" |
16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
17 | 17 |
18 namespace remoting { | 18 namespace remoting { |
19 namespace protocol { | 19 namespace protocol { |
20 | 20 |
21 ThirdPartyClientAuthenticator::ThirdPartyClientAuthenticator( | 21 ThirdPartyClientAuthenticator::ThirdPartyClientAuthenticator( |
22 const std::string& host_public_key, | |
23 scoped_ptr<TokenFetcher> token_fetcher) | 22 scoped_ptr<TokenFetcher> token_fetcher) |
24 : ThirdPartyAuthenticatorBase(WAITING_MESSAGE), | 23 : ThirdPartyAuthenticatorBase(WAITING_MESSAGE), |
25 host_public_key_(host_public_key), | |
26 token_fetcher_(token_fetcher.Pass()) { | 24 token_fetcher_(token_fetcher.Pass()) { |
27 } | 25 } |
28 | 26 |
29 ThirdPartyClientAuthenticator::~ThirdPartyClientAuthenticator() { | 27 ThirdPartyClientAuthenticator::~ThirdPartyClientAuthenticator() { |
30 } | 28 } |
31 | 29 |
32 void ThirdPartyClientAuthenticator::ProcessTokenMessage( | 30 void ThirdPartyClientAuthenticator::ProcessTokenMessage( |
33 const buzz::XmlElement* message, | 31 const buzz::XmlElement* message, |
34 const base::Closure& resume_callback) { | 32 const base::Closure& resume_callback) { |
35 std::string token_url = message->TextNamed(kTokenUrlTag); | 33 std::string token_url = message->TextNamed(kTokenUrlTag); |
36 std::string token_scope = message->TextNamed(kTokenScopeTag); | 34 std::string token_scope = message->TextNamed(kTokenScopeTag); |
37 | 35 |
38 if (token_url.empty() || token_scope.empty()) { | 36 if (token_url.empty() || token_scope.empty()) { |
39 LOG(ERROR) << "Third-party authentication protocol error: " | 37 LOG(ERROR) << "Third-party authentication protocol error: " |
40 "missing token verification URL or scope."; | 38 "missing token verification URL or scope."; |
41 token_state_ = REJECTED; | 39 token_state_ = REJECTED; |
42 rejection_reason_ = PROTOCOL_ERROR; | 40 rejection_reason_ = PROTOCOL_ERROR; |
43 resume_callback.Run(); | 41 resume_callback.Run(); |
44 return; | 42 return; |
45 } | 43 } |
46 | 44 |
47 token_state_ = PROCESSING_MESSAGE; | 45 token_state_ = PROCESSING_MESSAGE; |
48 | 46 |
49 // |token_fetcher_| is owned, so Unretained() is safe here. | 47 // |token_fetcher_| is owned, so Unretained() is safe here. |
50 token_fetcher_->FetchThirdPartyToken( | 48 token_fetcher_->FetchThirdPartyToken( |
51 GURL(token_url), host_public_key_, token_scope, base::Bind( | 49 GURL(token_url), token_scope, base::Bind( |
52 &ThirdPartyClientAuthenticator::OnThirdPartyTokenFetched, | 50 &ThirdPartyClientAuthenticator::OnThirdPartyTokenFetched, |
53 base::Unretained(this), resume_callback)); | 51 base::Unretained(this), resume_callback)); |
54 } | 52 } |
55 | 53 |
56 void ThirdPartyClientAuthenticator::AddTokenElements( | 54 void ThirdPartyClientAuthenticator::AddTokenElements( |
57 buzz::XmlElement* message) { | 55 buzz::XmlElement* message) { |
58 DCHECK_EQ(token_state_, MESSAGE_READY); | 56 DCHECK_EQ(token_state_, MESSAGE_READY); |
59 DCHECK(!token_.empty()); | 57 DCHECK(!token_.empty()); |
60 | 58 |
61 buzz::XmlElement* token_tag = new buzz::XmlElement(kTokenTag); | 59 buzz::XmlElement* token_tag = new buzz::XmlElement(kTokenTag); |
(...skipping 13 matching lines...) Expand all Loading... |
75 } else { | 73 } else { |
76 token_state_ = MESSAGE_READY; | 74 token_state_ = MESSAGE_READY; |
77 underlying_ = V2Authenticator::CreateForClient( | 75 underlying_ = V2Authenticator::CreateForClient( |
78 shared_secret, MESSAGE_READY); | 76 shared_secret, MESSAGE_READY); |
79 } | 77 } |
80 resume_callback.Run(); | 78 resume_callback.Run(); |
81 } | 79 } |
82 | 80 |
83 } // namespace protocol | 81 } // namespace protocol |
84 } // namespace remoting | 82 } // namespace remoting |
OLD | NEW |