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

Side by Side Diff: remoting/protocol/negotiating_authenticator.h

Issue 12518027: Protocol / client plugin changes to support interactively asking for a PIN (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Changed Pin-related objects to callbacks Created 7 years, 9 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
OLDNEW
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 #ifndef REMOTING_PROTOCOL_NEGOTIATING_AUTHENTICATOR_H_ 5 #ifndef REMOTING_PROTOCOL_NEGOTIATING_AUTHENTICATOR_H_
6 #define REMOTING_PROTOCOL_NEGOTIATING_AUTHENTICATOR_H_ 6 #define REMOTING_PROTOCOL_NEGOTIATING_AUTHENTICATOR_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
14 #include "remoting/protocol/authenticator.h" 15 #include "remoting/protocol/authenticator.h"
15 #include "remoting/protocol/authentication_method.h" 16 #include "remoting/protocol/authentication_method.h"
16 17
17 namespace remoting { 18 namespace remoting {
18 19
19 class RsaKeyPair; 20 class RsaKeyPair;
20 21
21 namespace protocol { 22 namespace protocol {
22 23
24 typedef base::Callback<void(const std::string& pin)> PinFetchedCallback;
Wez 2013/03/20 01:36:31 nit: SecretFetchedCallback - PIN is specific to Me
rmsousa 2013/03/20 04:54:54 Done.
25 typedef base::Callback<void(const PinFetchedCallback& pin_fetched_callback)>
26 FetchPinCallback;
Wez 2013/03/20 01:36:31 nit: Ditto here.
rmsousa 2013/03/20 04:54:54 Done.
27
28 // This class provides a meta-authenticator that allows clients and hosts that
29 // support multiple authentication methods to negotiate a method to use.
30 //
31 // The typical flow is:
32 // * Client sends a message to host with its supported methods.
33 // (clients may also pick a method and send its first message here).
Wez 2013/03/20 01:36:31 nit: also -> additionally
rmsousa 2013/03/20 04:54:54 Done.
34 // * Host picks a method and sends its first message (if any).
35 // (if a supported method/message was sent by a client, it is processed).
Wez 2013/03/20 01:36:31 nit: second "a" -> "the"
rmsousa 2013/03/20 04:54:54 Done.
rmsousa 2013/03/20 04:54:54 Done.
36 // * Client creates the authenticator selected by the host. If the method
37 // starts with a message from the host, it is processed.
38 // * Client and host exchange messages until the authentication is ACCEPTED or
39 // REJECTED.
40 //
41 // The details:
Wez 2013/03/20 01:36:31 This entire block is rather verbose. It looks like
rmsousa 2013/03/20 04:54:54 These only describe the 3rd and 4th bulletpoint.
42 // * The underlying message processing may be asynchronous (i.e. require user
43 // interaction based on the message contents), so it receives a callback to
44 // resume processing when done.
Wez 2013/03/20 01:36:31 This seems to be an inherent property of the Authe
rmsousa 2013/03/20 04:54:54 This text is describing the authentication negotia
45 // * Creating an authenticator may also be asynchronous (i.e. require user
46 // interaction to determine initial parameters, like PIN), so it also
47 // receives a callback. If the authenticator has received a message to
Wez 2013/03/20 01:36:31 What receives a callback? The Create*() function?
rmsousa 2013/03/20 04:54:54 CreateAuthenticator.
48 // process, the message processing code must also be on that callback.
Wez 2013/03/20 01:36:31 Not sure what "... must also be on that callback"
rmsousa 2013/03/20 04:54:54 If the authenticator is creating an authenticator
49 // * Some authentication methods may have a specific starting direction (e.g.
50 // host always sends the first message), while others are versatile (e.g.
51 // SPAKE, where either side can send the first message). So when an
52 // authenticator is created, it is given a "preferred" (context-dependent)
53 // initial state, but it may ignore it, and the negotiating authenticator
Wez 2013/03/20 01:36:31 nit: "but it may ignore it" -> "which the authenti
rmsousa 2013/03/20 04:54:54 Done.
54 // must deal with that, by sending a blank message if the method has none
55 // to send, and ignoring such blank message on the receiving end. This
Wez 2013/03/20 01:36:31 What does it mean to send a "blank message"? You m
rmsousa 2013/03/20 04:54:54 An <authenticator> stanza is part of the protocol,
56 // relies on the assumption that each method must either be versatile on
57 // both ends, or name an explicit direction to start.
Wez 2013/03/20 01:36:31 This sentence is confusing and I don't think you n
rmsousa 2013/03/20 04:54:54 Not quite... The V2 authentication is a good examp
58 // * The client may pick a method on its first message (assuming it doesn't
59 // require user interaction to start), and the host may not support that
60 // method, in which case it must discard that message and create an
61 // authenticator for a mutually supported method.
62 // * The host never sends its own supported methods back to the client, so once
63 // the host picks a method from the client's list, it's final.
Wez 2013/03/20 01:36:31 Why do we not return to the handshake and let the
rmsousa 2013/03/20 04:54:54 I'm not sure what you mean here. This is just desc
64 // * Any change in this class must maintain compatibility between any version
65 // mix of webapp, client plugin and host, for both Me2Me and IT2Me.
Wez 2013/03/20 01:36:31 This is a good point, although it's not "any" vers
rmsousa 2013/03/20 04:54:54 What do you mean currently-supported protocols? Th
23 class NegotiatingAuthenticator : public Authenticator { 66 class NegotiatingAuthenticator : public Authenticator {
24 public: 67 public:
25 virtual ~NegotiatingAuthenticator(); 68 virtual ~NegotiatingAuthenticator();
26 69
27 static bool IsNegotiableMessage(const buzz::XmlElement* message);
28
29 // Creates a client authenticator for the given methods. 70 // Creates a client authenticator for the given methods.
30 static scoped_ptr<Authenticator> CreateForClient( 71 static scoped_ptr<Authenticator> CreateForClient(
31 const std::string& authentication_tag, 72 const std::string& authentication_tag,
32 const std::string& shared_secret, 73 const FetchPinCallback& fetch_pin_callback,
33 const std::vector<AuthenticationMethod>& methods); 74 const std::vector<AuthenticationMethod>& methods);
34 75
35 // Creates a host authenticator, using a fixed shared secret/PIN hash. 76 // Creates a host authenticator, using a fixed shared secret/PIN hash.
36 static scoped_ptr<Authenticator> CreateForHost( 77 static scoped_ptr<Authenticator> CreateForHost(
37 const std::string& local_cert, 78 const std::string& local_cert,
38 scoped_refptr<RsaKeyPair> key_pair, 79 scoped_refptr<RsaKeyPair> key_pair,
39 const std::string& shared_secret_hash, 80 const std::string& shared_secret_hash,
40 AuthenticationMethod::HashFunction hash_function); 81 AuthenticationMethod::HashFunction hash_function);
41 82
42 // Authenticator interface. 83 // Authenticator interface.
43 virtual State state() const OVERRIDE; 84 virtual State state() const OVERRIDE;
44 virtual RejectionReason rejection_reason() const OVERRIDE; 85 virtual RejectionReason rejection_reason() const OVERRIDE;
45 virtual void ProcessMessage(const buzz::XmlElement* message, 86 virtual void ProcessMessage(const buzz::XmlElement* message,
46 const base::Closure& resume_callback) OVERRIDE; 87 const base::Closure& resume_callback) OVERRIDE;
47 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE; 88 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE;
48 virtual scoped_ptr<ChannelAuthenticator> 89 virtual scoped_ptr<ChannelAuthenticator>
49 CreateChannelAuthenticator() const OVERRIDE; 90 CreateChannelAuthenticator() const OVERRIDE;
50 91
51 private: 92 private:
52 NegotiatingAuthenticator(Authenticator::State initial_state); 93 explicit NegotiatingAuthenticator(Authenticator::State initial_state);
53 94
54 void AddMethod(const AuthenticationMethod& method); 95 void AddMethod(const AuthenticationMethod& method);
55 void CreateAuthenticator(State initial_state); 96
97 // (Asynchronously) creates an authenticator. Authenticators that can be
98 // started in either state will be created in |preferred_initial_state|.
99 // |resume_callback| is called when the authenticator is ready.
Wez 2013/03/20 01:36:31 Where does the Authenticator end up? |current_aut
rmsousa 2013/03/20 04:54:54 Done.
100 void CreateAuthenticator(Authenticator::State preferred_initial_state,
101 const base::Closure& resume_callback);
102
103 // Processes a message in the current authenticator. |message| and
Wez 2013/03/20 01:36:31 nit: Suggest "Calls |current_authenticator_| to pr
rmsousa 2013/03/20 04:54:54 Done.
104 // |resume_callback| are passed to the underlying ProcessMessage call.
105 void ProcessMessageInternal(const buzz::XmlElement* message,
106 const base::Closure& resume_callback);
107
108 // Updates |state_| to reflect the current underlying authenticator state.
Wez 2013/03/20 01:36:31 Why does this need a |resume_callback|? What is it
rmsousa 2013/03/20 04:54:54 Yes, it's updating the negotiating_authenticator's
56 void UpdateState(const base::Closure& resume_callback); 109 void UpdateState(const base::Closure& resume_callback);
57 110
111 // Creates a V2Authenticator in state |initial_state| with the given
112 // |shared_secret|, then runs |resume_callback|.
113 void OnPinFetched(
Wez 2013/03/20 01:36:31 Why is this called OnPinFetched if it actually cre
rmsousa 2013/03/20 04:54:54 Done.
114 Authenticator::State initial_state,
115 const base::Closure& resume_callback,
116 const std::string& shared_secret);
117
58 bool is_host_side() const; 118 bool is_host_side() const;
59 119
60 // Used only for host authenticators. 120 // Used only for host authenticators.
61 std::string local_cert_; 121 std::string local_cert_;
62 scoped_refptr<RsaKeyPair> local_key_pair_; 122 scoped_refptr<RsaKeyPair> local_key_pair_;
63 std::string shared_secret_hash_; 123 std::string shared_secret_hash_;
64 124
65 // Used only for client authenticators. 125 // Used only for client authenticators.
66 std::string authentication_tag_; 126 std::string authentication_tag_;
67 std::string shared_secret_; 127 FetchPinCallback fetch_pin_callback_;
68 128
69 // Used for both host and client authenticators. 129 // Used for both host and client authenticators.
70 std::vector<AuthenticationMethod> methods_; 130 std::vector<AuthenticationMethod> methods_;
71 AuthenticationMethod current_method_; 131 AuthenticationMethod current_method_;
72 scoped_ptr<Authenticator> current_authenticator_; 132 scoped_ptr<Authenticator> current_authenticator_;
73 State state_; 133 State state_;
74 RejectionReason rejection_reason_; 134 RejectionReason rejection_reason_;
75 135
136 base::WeakPtrFactory<NegotiatingAuthenticator> weak_factory_;
137
76 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticator); 138 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticator);
77 }; 139 };
78 140
79 } // namespace protocol 141 } // namespace protocol
80 } // namespace remoting 142 } // namespace remoting
81 143
82 #endif // REMOTING_PROTOCOL_NEGOTIATING_AUTHENTICATOR_H_ 144 #endif // REMOTING_PROTOCOL_NEGOTIATING_AUTHENTICATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698