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/negotiating_client_authenticator.h" | 5 #include "remoting/protocol/negotiating_client_authenticator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" |
14 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
15 #include "remoting/protocol/auth_util.h" | 16 #include "remoting/protocol/auth_util.h" |
16 #include "remoting/protocol/channel_authenticator.h" | 17 #include "remoting/protocol/channel_authenticator.h" |
17 #include "remoting/protocol/pairing_client_authenticator.h" | 18 #include "remoting/protocol/pairing_client_authenticator.h" |
18 #include "remoting/protocol/spake2_authenticator.h" | 19 #include "remoting/protocol/spake2_authenticator.h" |
19 #include "remoting/protocol/v2_authenticator.h" | 20 #include "remoting/protocol/v2_authenticator.h" |
20 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 21 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
21 | 22 |
22 namespace remoting { | 23 namespace remoting { |
23 namespace protocol { | 24 namespace protocol { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 base::Closure callback = base::Bind( | 74 base::Closure callback = base::Bind( |
74 &NegotiatingAuthenticatorBase::ProcessMessageInternal, | 75 &NegotiatingAuthenticatorBase::ProcessMessageInternal, |
75 base::Unretained(this), base::Owned(new buzz::XmlElement(*message)), | 76 base::Unretained(this), base::Owned(new buzz::XmlElement(*message)), |
76 resume_callback); | 77 resume_callback); |
77 CreateAuthenticatorForCurrentMethod(WAITING_MESSAGE, callback); | 78 CreateAuthenticatorForCurrentMethod(WAITING_MESSAGE, callback); |
78 return; | 79 return; |
79 } | 80 } |
80 ProcessMessageInternal(message, resume_callback); | 81 ProcessMessageInternal(message, resume_callback); |
81 } | 82 } |
82 | 83 |
83 scoped_ptr<buzz::XmlElement> NegotiatingClientAuthenticator::GetNextMessage() { | 84 std::unique_ptr<buzz::XmlElement> |
| 85 NegotiatingClientAuthenticator::GetNextMessage() { |
84 DCHECK_EQ(state(), MESSAGE_READY); | 86 DCHECK_EQ(state(), MESSAGE_READY); |
85 | 87 |
86 // This is the first message to the host, send a list of supported methods. | 88 // This is the first message to the host, send a list of supported methods. |
87 if (current_method_ == Method::INVALID) { | 89 if (current_method_ == Method::INVALID) { |
88 // If no authentication method has been chosen, see if we can optimistically | 90 // If no authentication method has been chosen, see if we can optimistically |
89 // choose one. | 91 // choose one. |
90 scoped_ptr<buzz::XmlElement> result; | 92 std::unique_ptr<buzz::XmlElement> result; |
91 CreatePreferredAuthenticator(); | 93 CreatePreferredAuthenticator(); |
92 if (current_authenticator_) { | 94 if (current_authenticator_) { |
93 DCHECK(current_authenticator_->state() == MESSAGE_READY); | 95 DCHECK(current_authenticator_->state() == MESSAGE_READY); |
94 result = GetNextMessageInternal(); | 96 result = GetNextMessageInternal(); |
95 } else { | 97 } else { |
96 result = CreateEmptyAuthenticatorMessage(); | 98 result = CreateEmptyAuthenticatorMessage(); |
97 } | 99 } |
98 | 100 |
99 if (is_paired()) { | 101 if (is_paired()) { |
100 // If the client is paired with the host then attach pairing client_id to | 102 // If the client is paired with the host then attach pairing client_id to |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 base::Bind(&Spake2Authenticator::CreateForClient, local_id_, | 142 base::Bind(&Spake2Authenticator::CreateForClient, local_id_, |
141 remote_id_), | 143 remote_id_), |
142 config_.fetch_third_party_token_callback)); | 144 config_.fetch_third_party_token_callback)); |
143 resume_callback.Run(); | 145 resume_callback.Run(); |
144 break; | 146 break; |
145 | 147 |
146 case Method::PAIRED_SPAKE2_P224: { | 148 case Method::PAIRED_SPAKE2_P224: { |
147 PairingClientAuthenticator* pairing_authenticator = | 149 PairingClientAuthenticator* pairing_authenticator = |
148 new PairingClientAuthenticator( | 150 new PairingClientAuthenticator( |
149 config_, base::Bind(&V2Authenticator::CreateForClient)); | 151 config_, base::Bind(&V2Authenticator::CreateForClient)); |
150 current_authenticator_ = make_scoped_ptr(pairing_authenticator); | 152 current_authenticator_ = base::WrapUnique(pairing_authenticator); |
151 pairing_authenticator->Start(preferred_initial_state, resume_callback); | 153 pairing_authenticator->Start(preferred_initial_state, resume_callback); |
152 break; | 154 break; |
153 } | 155 } |
154 | 156 |
155 case Method::PAIRED_SPAKE2_CURVE25519: { | 157 case Method::PAIRED_SPAKE2_CURVE25519: { |
156 PairingClientAuthenticator* pairing_authenticator = | 158 PairingClientAuthenticator* pairing_authenticator = |
157 new PairingClientAuthenticator( | 159 new PairingClientAuthenticator( |
158 config_, base::Bind(&Spake2Authenticator::CreateForClient, | 160 config_, base::Bind(&Spake2Authenticator::CreateForClient, |
159 local_id_, remote_id_)); | 161 local_id_, remote_id_)); |
160 current_authenticator_ = make_scoped_ptr(pairing_authenticator); | 162 current_authenticator_ = base::WrapUnique(pairing_authenticator); |
161 pairing_authenticator->Start(preferred_initial_state, resume_callback); | 163 pairing_authenticator->Start(preferred_initial_state, resume_callback); |
162 break; | 164 break; |
163 } | 165 } |
164 | 166 |
165 case Method::SHARED_SECRET_SPAKE2_P224: | 167 case Method::SHARED_SECRET_SPAKE2_P224: |
166 case Method::SHARED_SECRET_SPAKE2_CURVE25519: | 168 case Method::SHARED_SECRET_SPAKE2_CURVE25519: |
167 config_.fetch_secret_callback.Run( | 169 config_.fetch_secret_callback.Run( |
168 false, | 170 false, |
169 base::Bind( | 171 base::Bind( |
170 &NegotiatingClientAuthenticator::CreateSharedSecretAuthenticator, | 172 &NegotiatingClientAuthenticator::CreateSharedSecretAuthenticator, |
171 weak_factory_.GetWeakPtr(), preferred_initial_state, | 173 weak_factory_.GetWeakPtr(), preferred_initial_state, |
172 resume_callback)); | 174 resume_callback)); |
173 break; | 175 break; |
174 } | 176 } |
175 } | 177 } |
176 | 178 |
177 void NegotiatingClientAuthenticator::CreatePreferredAuthenticator() { | 179 void NegotiatingClientAuthenticator::CreatePreferredAuthenticator() { |
178 if (is_paired() && | 180 if (is_paired() && |
179 std::find(methods_.begin(), methods_.end(), Method::PAIRED_SPAKE2_P224) != | 181 std::find(methods_.begin(), methods_.end(), Method::PAIRED_SPAKE2_P224) != |
180 methods_.end()) { | 182 methods_.end()) { |
181 PairingClientAuthenticator* pairing_authenticator = | 183 PairingClientAuthenticator* pairing_authenticator = |
182 new PairingClientAuthenticator( | 184 new PairingClientAuthenticator( |
183 config_, base::Bind(&V2Authenticator::CreateForClient)); | 185 config_, base::Bind(&V2Authenticator::CreateForClient)); |
184 current_authenticator_ = make_scoped_ptr(pairing_authenticator); | 186 current_authenticator_ = base::WrapUnique(pairing_authenticator); |
185 pairing_authenticator->StartPaired(MESSAGE_READY); | 187 pairing_authenticator->StartPaired(MESSAGE_READY); |
186 current_method_ = Method::PAIRED_SPAKE2_P224; | 188 current_method_ = Method::PAIRED_SPAKE2_P224; |
187 } | 189 } |
188 } | 190 } |
189 | 191 |
190 void NegotiatingClientAuthenticator::CreateSharedSecretAuthenticator( | 192 void NegotiatingClientAuthenticator::CreateSharedSecretAuthenticator( |
191 Authenticator::State initial_state, | 193 Authenticator::State initial_state, |
192 const base::Closure& resume_callback, | 194 const base::Closure& resume_callback, |
193 const std::string& shared_secret) { | 195 const std::string& shared_secret) { |
194 std::string shared_secret_hash = | 196 std::string shared_secret_hash = |
195 GetSharedSecretHash(config_.host_id, shared_secret); | 197 GetSharedSecretHash(config_.host_id, shared_secret); |
196 if (current_method_ == Method::SHARED_SECRET_SPAKE2_CURVE25519) { | 198 if (current_method_ == Method::SHARED_SECRET_SPAKE2_CURVE25519) { |
197 current_authenticator_ = Spake2Authenticator::CreateForClient( | 199 current_authenticator_ = Spake2Authenticator::CreateForClient( |
198 local_id_, remote_id_, shared_secret_hash, initial_state); | 200 local_id_, remote_id_, shared_secret_hash, initial_state); |
199 } else { | 201 } else { |
200 current_authenticator_ = | 202 current_authenticator_ = |
201 V2Authenticator::CreateForClient(shared_secret_hash, initial_state); | 203 V2Authenticator::CreateForClient(shared_secret_hash, initial_state); |
202 } | 204 } |
203 resume_callback.Run(); | 205 resume_callback.Run(); |
204 } | 206 } |
205 | 207 |
206 bool NegotiatingClientAuthenticator::is_paired() { | 208 bool NegotiatingClientAuthenticator::is_paired() { |
207 return !config_.pairing_client_id.empty() && !config_.pairing_secret.empty(); | 209 return !config_.pairing_client_id.empty() && !config_.pairing_secret.empty(); |
208 } | 210 } |
209 | 211 |
210 } // namespace protocol | 212 } // namespace protocol |
211 } // namespace remoting | 213 } // namespace remoting |
OLD | NEW |