Chromium Code Reviews| 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 scoped_ptr<TokenFetcher> token_fetcher, | |
| 23 Authenticator::State initial_state) | |
| 24 : ThirdPartyAuthenticatorBase(initial_state), | |
|
Sergey Ulanov
2013/03/07 21:20:41
nit: indent two more spaces.
rmsousa
2013/03/20 01:30:16
Done.
| |
| 25 host_public_key_(host_public_key), | |
| 26 token_fetcher_(token_fetcher.Pass()) { | |
| 27 } | |
| 28 | |
| 29 ThirdPartyClientAuthenticator::~ThirdPartyClientAuthenticator() { | |
| 30 } | |
| 31 | |
| 32 void ThirdPartyClientAuthenticator::ProcessMessageInternal( | |
| 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 state_ = PROCESSING_MESSAGE; | |
| 39 // |token_fetcher_| is owned, so Unretained() is safe here. | |
| 40 token_fetcher_->FetchThirdPartyToken( | |
| 41 GURL(token_url), host_public_key_, token_scope, base::Bind( | |
| 42 &ThirdPartyClientAuthenticator::OnThirdPartyTokenFetched, | |
| 43 base::Unretained(this), resume_callback)); | |
| 44 return; | |
| 45 } | |
| 46 | |
| 47 LOG(WARNING) << "Missing token issue URL/verification URL/scope."; | |
|
Sergey Ulanov
2013/03/07 21:20:41
better to log it as ERROR. Also suggest rewording
rmsousa
2013/03/20 01:30:16
Done.
| |
| 48 state_ = REJECTED; | |
| 49 rejection_reason_ = PROTOCOL_ERROR; | |
| 50 resume_callback.Run(); | |
| 51 return; | |
|
Sergey Ulanov
2013/03/07 21:20:41
nit: don't need return statement here.
rmsousa
2013/03/20 01:30:16
Done.
| |
| 52 } | |
| 53 | |
| 54 void ThirdPartyClientAuthenticator::GetNextMessageInternal( | |
| 55 buzz::XmlElement* message) { | |
| 56 if (state_ == MESSAGE_READY) { | |
|
Sergey Ulanov
2013/03/07 21:20:41
this should be a DCHECK.
rmsousa
2013/03/20 01:30:16
Done.
| |
| 57 if (!token_.empty()) { | |
| 58 buzz::XmlElement* token_tag = new buzz::XmlElement(kTokenTag); | |
| 59 token_tag->SetBodyText(token_); | |
| 60 message->AddElement(token_tag); | |
| 61 state_ = ACCEPTED; | |
| 62 } else { | |
| 63 // The client doesn't really have anything to send yet, it's just | |
| 64 // waiting for the host to send the token_url. | |
| 65 state_ = WAITING_MESSAGE; | |
| 66 } | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 void ThirdPartyClientAuthenticator::OnThirdPartyTokenFetched( | |
| 71 const base::Closure& resume_callback, const std::string& third_party_token, | |
| 72 const std::string& shared_secret) { | |
| 73 token_ = third_party_token; | |
| 74 if (!token_.empty() && !shared_secret.empty()) { | |
| 75 state_ = MESSAGE_READY; | |
| 76 underlying_ = V2Authenticator::CreateForClient( | |
| 77 shared_secret, MESSAGE_READY); | |
| 78 } else { | |
| 79 state_ = REJECTED; | |
| 80 rejection_reason_ = INVALID_CREDENTIALS; | |
| 81 } | |
| 82 resume_callback.Run(); | |
| 83 } | |
| 84 | |
| 85 } // namespace protocol | |
| 86 } // namespace remoting | |
| OLD | NEW |