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 "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); | |
|
Wez
2013/03/22 06:17:01
nit: I think it'd be easier to read if the error c
rmsousa
2013/03/22 21:19:05
Done.
| |
| 37 if (!token_url.empty() && !token_scope.empty()) { | |
| 38 token_state_ = PROCESSING_MESSAGE; | |
|
Wez
2013/03/22 06:17:01
nit: blank line before comment
rmsousa
2013/03/22 21:19:05
Done.
| |
| 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(ERROR) << "Third-party authentication protocol error: " | |
| 48 "missing token verification URL or scope."; | |
| 49 token_state_ = REJECTED; | |
| 50 rejection_reason_ = PROTOCOL_ERROR; | |
| 51 resume_callback.Run(); | |
| 52 } | |
| 53 | |
| 54 void ThirdPartyClientAuthenticator::AddTokenElements( | |
| 55 buzz::XmlElement* message) { | |
| 56 DCHECK(token_state_ == MESSAGE_READY); | |
|
Sergey Ulanov
2013/03/22 05:58:43
DCHECK_EQ
rmsousa
2013/03/22 21:19:05
Done.
| |
| 57 DCHECK(!token_.empty()); | |
| 58 | |
| 59 buzz::XmlElement* token_tag = new buzz::XmlElement(kTokenTag); | |
| 60 token_tag->SetBodyText(token_); | |
| 61 message->AddElement(token_tag); | |
| 62 token_state_ = ACCEPTED; | |
| 63 } | |
| 64 | |
| 65 void ThirdPartyClientAuthenticator::OnThirdPartyTokenFetched( | |
| 66 const base::Closure& resume_callback, | |
| 67 const std::string& third_party_token, | |
| 68 const std::string& shared_secret) { | |
| 69 token_ = third_party_token; | |
| 70 if (!token_.empty() && !shared_secret.empty()) { | |
|
Wez
2013/03/22 06:17:01
nit: Similarly, checking token.empty() || shared_s
rmsousa
2013/03/22 21:19:05
Done.
| |
| 71 token_state_ = MESSAGE_READY; | |
| 72 underlying_ = V2Authenticator::CreateForClient( | |
| 73 shared_secret, MESSAGE_READY); | |
| 74 } else { | |
| 75 token_state_ = REJECTED; | |
| 76 rejection_reason_ = INVALID_CREDENTIALS; | |
| 77 } | |
| 78 resume_callback.Run(); | |
| 79 } | |
| 80 | |
| 81 } // namespace protocol | |
| 82 } // namespace remoting | |
| OLD | NEW |