| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/negotiating_authenticator_base.h" | 5 #include "remoting/protocol/negotiating_authenticator_base.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "remoting/base/rsa_key_pair.h" | 14 #include "remoting/base/rsa_key_pair.h" |
| 15 #include "remoting/protocol/channel_authenticator.h" | 15 #include "remoting/protocol/channel_authenticator.h" |
| 16 #include "remoting/protocol/name_value_map.h" |
| 16 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 17 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 17 | 18 |
| 18 namespace remoting { | 19 namespace remoting { |
| 19 namespace protocol { | 20 namespace protocol { |
| 20 | 21 |
| 22 namespace { |
| 23 |
| 24 const NameMapElement<NegotiatingAuthenticatorBase::Method> |
| 25 kAuthenticationMethodStrings[] = { |
| 26 {NegotiatingAuthenticatorBase::Method::SPAKE2_SHARED_SECRET_PLAIN, |
| 27 "spake2_plain"}, |
| 28 {NegotiatingAuthenticatorBase::Method::SPAKE2_SHARED_SECRET_HMAC, |
| 29 "spake2_hmac"}, |
| 30 {NegotiatingAuthenticatorBase::Method::SPAKE2_PAIR, "spake2_pair"}, |
| 31 {NegotiatingAuthenticatorBase::Method::THIRD_PARTY, "third_party"}, |
| 32 }; |
| 33 |
| 34 } // namespace |
| 35 |
| 21 const buzz::StaticQName NegotiatingAuthenticatorBase::kMethodAttributeQName = | 36 const buzz::StaticQName NegotiatingAuthenticatorBase::kMethodAttributeQName = |
| 22 { "", "method" }; | 37 { "", "method" }; |
| 23 const buzz::StaticQName | 38 const buzz::StaticQName |
| 24 NegotiatingAuthenticatorBase::kSupportedMethodsAttributeQName = | 39 NegotiatingAuthenticatorBase::kSupportedMethodsAttributeQName = |
| 25 { "", "supported-methods" }; | 40 { "", "supported-methods" }; |
| 26 const char NegotiatingAuthenticatorBase::kSupportedMethodsSeparator = ','; | 41 const char NegotiatingAuthenticatorBase::kSupportedMethodsSeparator = ','; |
| 27 | 42 |
| 28 NegotiatingAuthenticatorBase::NegotiatingAuthenticatorBase( | 43 NegotiatingAuthenticatorBase::NegotiatingAuthenticatorBase( |
| 29 Authenticator::State initial_state) | 44 Authenticator::State initial_state) |
| 30 : state_(initial_state) {} | 45 : state_(initial_state) {} |
| 31 | 46 |
| 32 NegotiatingAuthenticatorBase::~NegotiatingAuthenticatorBase() {} | 47 NegotiatingAuthenticatorBase::~NegotiatingAuthenticatorBase() {} |
| 33 | 48 |
| 34 Authenticator::State NegotiatingAuthenticatorBase::state() const { | 49 Authenticator::State NegotiatingAuthenticatorBase::state() const { |
| 35 return state_; | 50 return state_; |
| 36 } | 51 } |
| 37 | 52 |
| 38 bool NegotiatingAuthenticatorBase::started() const { | 53 bool NegotiatingAuthenticatorBase::started() const { |
| 39 if (!current_authenticator_) { | 54 if (!current_authenticator_) { |
| 40 return false; | 55 return false; |
| 41 } | 56 } |
| 42 return current_authenticator_->started(); | 57 return current_authenticator_->started(); |
| 43 } | 58 } |
| 44 | 59 |
| 45 Authenticator::RejectionReason | 60 Authenticator::RejectionReason |
| 46 NegotiatingAuthenticatorBase::rejection_reason() const { | 61 NegotiatingAuthenticatorBase::rejection_reason() const { |
| 47 return rejection_reason_; | 62 return rejection_reason_; |
| 48 } | 63 } |
| 49 | 64 |
| 65 // static |
| 66 NegotiatingAuthenticatorBase::Method |
| 67 NegotiatingAuthenticatorBase::ParseMethodString(const std::string& value) { |
| 68 Method result; |
| 69 if (!NameToValue(kAuthenticationMethodStrings, value, &result)) |
| 70 return Method::INVALID; |
| 71 return result; |
| 72 } |
| 73 |
| 74 // static |
| 75 std::string NegotiatingAuthenticatorBase::MethodToString(Method method) { |
| 76 return ValueToName(kAuthenticationMethodStrings, method); |
| 77 } |
| 78 |
| 50 void NegotiatingAuthenticatorBase::ProcessMessageInternal( | 79 void NegotiatingAuthenticatorBase::ProcessMessageInternal( |
| 51 const buzz::XmlElement* message, | 80 const buzz::XmlElement* message, |
| 52 const base::Closure& resume_callback) { | 81 const base::Closure& resume_callback) { |
| 53 if (current_authenticator_->state() == WAITING_MESSAGE) { | 82 if (current_authenticator_->state() == WAITING_MESSAGE) { |
| 54 // If the message was not discarded and the authenticator is waiting for it, | 83 // If the message was not discarded and the authenticator is waiting for it, |
| 55 // give it to the underlying authenticator to process. | 84 // give it to the underlying authenticator to process. |
| 56 // |current_authenticator_| is owned, so Unretained() is safe here. | 85 // |current_authenticator_| is owned, so Unretained() is safe here. |
| 57 state_ = PROCESSING_MESSAGE; | 86 state_ = PROCESSING_MESSAGE; |
| 58 current_authenticator_->ProcessMessage(message, base::Bind( | 87 current_authenticator_->ProcessMessage(message, base::Bind( |
| 59 &NegotiatingAuthenticatorBase::UpdateState, | 88 &NegotiatingAuthenticatorBase::UpdateState, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 // |resume_callback| to resume the session negotiation. | 100 // |resume_callback| to resume the session negotiation. |
| 72 state_ = current_authenticator_->state(); | 101 state_ = current_authenticator_->state(); |
| 73 if (state_ == REJECTED) | 102 if (state_ == REJECTED) |
| 74 rejection_reason_ = current_authenticator_->rejection_reason(); | 103 rejection_reason_ = current_authenticator_->rejection_reason(); |
| 75 resume_callback.Run(); | 104 resume_callback.Run(); |
| 76 } | 105 } |
| 77 | 106 |
| 78 scoped_ptr<buzz::XmlElement> | 107 scoped_ptr<buzz::XmlElement> |
| 79 NegotiatingAuthenticatorBase::GetNextMessageInternal() { | 108 NegotiatingAuthenticatorBase::GetNextMessageInternal() { |
| 80 DCHECK_EQ(state(), MESSAGE_READY); | 109 DCHECK_EQ(state(), MESSAGE_READY); |
| 81 DCHECK(current_method_ != AuthenticationMethod::INVALID); | 110 DCHECK(current_method_ != Method::INVALID); |
| 82 | 111 |
| 83 scoped_ptr<buzz::XmlElement> result; | 112 scoped_ptr<buzz::XmlElement> result; |
| 84 if (current_authenticator_->state() == MESSAGE_READY) { | 113 if (current_authenticator_->state() == MESSAGE_READY) { |
| 85 result = current_authenticator_->GetNextMessage(); | 114 result = current_authenticator_->GetNextMessage(); |
| 86 } else { | 115 } else { |
| 87 result = CreateEmptyAuthenticatorMessage(); | 116 result = CreateEmptyAuthenticatorMessage(); |
| 88 } | 117 } |
| 89 state_ = current_authenticator_->state(); | 118 state_ = current_authenticator_->state(); |
| 90 DCHECK(state_ == ACCEPTED || state_ == WAITING_MESSAGE); | 119 DCHECK(state_ == ACCEPTED || state_ == WAITING_MESSAGE); |
| 91 result->AddAttr(kMethodAttributeQName, | 120 result->AddAttr(kMethodAttributeQName, MethodToString(current_method_)); |
| 92 AuthenticationMethodToString(current_method_)); | |
| 93 return result; | 121 return result; |
| 94 } | 122 } |
| 95 | 123 |
| 96 void NegotiatingAuthenticatorBase::AddMethod(AuthenticationMethod method) { | 124 void NegotiatingAuthenticatorBase::AddMethod(Method method) { |
| 97 DCHECK(method != AuthenticationMethod::INVALID); | 125 DCHECK(method != Method::INVALID); |
| 98 methods_.push_back(method); | 126 methods_.push_back(method); |
| 99 } | 127 } |
| 100 | 128 |
| 101 const std::string& NegotiatingAuthenticatorBase::GetAuthKey() const { | 129 const std::string& NegotiatingAuthenticatorBase::GetAuthKey() const { |
| 102 DCHECK_EQ(state(), ACCEPTED); | 130 DCHECK_EQ(state(), ACCEPTED); |
| 103 return current_authenticator_->GetAuthKey(); | 131 return current_authenticator_->GetAuthKey(); |
| 104 } | 132 } |
| 105 | 133 |
| 106 scoped_ptr<ChannelAuthenticator> | 134 scoped_ptr<ChannelAuthenticator> |
| 107 NegotiatingAuthenticatorBase::CreateChannelAuthenticator() const { | 135 NegotiatingAuthenticatorBase::CreateChannelAuthenticator() const { |
| 108 DCHECK_EQ(state(), ACCEPTED); | 136 DCHECK_EQ(state(), ACCEPTED); |
| 109 return current_authenticator_->CreateChannelAuthenticator(); | 137 return current_authenticator_->CreateChannelAuthenticator(); |
| 110 } | 138 } |
| 111 | 139 |
| 112 } // namespace protocol | 140 } // namespace protocol |
| 113 } // namespace remoting | 141 } // namespace remoting |
| OLD | NEW |