Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: remoting/protocol/pairing_client_authenticator.cc

Issue 14793021: PairingAuthenticator implementation and plumbing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer comments. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/pairing_client_authenticator.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "remoting/base/constants.h"
10 #include "remoting/base/rsa_key_pair.h"
11 #include "remoting/protocol/authentication_method.h"
12 #include "remoting/protocol/channel_authenticator.h"
13 #include "remoting/protocol/v2_authenticator.h"
14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
15
16 namespace remoting {
17 namespace protocol {
18
19 PairingClientAuthenticator::PairingClientAuthenticator(
20 const std::string& client_id,
21 const std::string& paired_secret,
22 const FetchSecretCallback& fetch_pin_callback,
23 const std::string& authentication_tag)
24 : sent_client_id_(false),
25 client_id_(client_id),
26 paired_secret_(paired_secret),
27 fetch_pin_callback_(fetch_pin_callback),
28 authentication_tag_(authentication_tag),
29 weak_factory_(this) {
30 v2_authenticator_ = V2Authenticator::CreateForClient(
31 paired_secret_, MESSAGE_READY);
32 using_paired_secret_ = true;
33 }
34
35 void PairingClientAuthenticator::CreateV2AuthenticatorWithPIN(
36 State initial_state,
37 const SetAuthenticatorCallback& set_authenticator_callback) {
38 SecretFetchedCallback callback = base::Bind(
39 &PairingClientAuthenticator::OnPinFetched,
40 weak_factory_.GetWeakPtr(), initial_state, set_authenticator_callback);
41 fetch_pin_callback_.Run(callback);
42 }
43
44 void PairingClientAuthenticator::AddPairingElements(buzz::XmlElement* message) {
45 // If the client id and secret have not yet been sent, do so now. Note that
46 // in this case the V2Authenticator is being used optimistically to send the
47 // first message of the SPAKE exchange since we don't yet know whether or not
48 // the host will accept the client id or request that we fall back to the PIN.
49 if (!sent_client_id_) {
50 buzz::XmlElement* pairing_tag = new buzz::XmlElement(kPairingInfoTag);
51 pairing_tag->AddAttr(kClientIdAttribute, client_id_);
52 message->AddElement(pairing_tag);
53 sent_client_id_ = true;
54 }
55 }
56
57 void PairingClientAuthenticator::OnPinFetched(
58 State initial_state,
59 const SetAuthenticatorCallback& callback,
60 const std::string& pin) {
61 callback.Run(V2Authenticator::CreateForClient(
62 AuthenticationMethod::ApplyHashFunction(
63 AuthenticationMethod::HMAC_SHA256,
64 authentication_tag_, pin),
65 initial_state));
66 }
67
68 } // namespace protocol
69 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698