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

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: Pin -> Secret, comment clarifications. 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& secret)> SecretFetchedCallback;
25 typedef base::Callback<void(
26 const SecretFetchedCallback& secret_fetched_callback)> FetchSecretCallback;
27
28 // This class provides a meta-authenticator that allows clients and hosts that
Sergey Ulanov 2013/03/20 05:49:05 Thanks for adding these comments!
rmsousa 2013/03/20 20:17:16 Done.
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 additionally pick a method and send its first message).
34 // * Host picks a method and sends its first message (if any).
35 // (if a message for that method was sent by the client, it is processed).
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:
42 // * CreateAuthenticator may be asynchronous (i.e. require user interaction
Sergey Ulanov 2013/03/20 05:49:05 nit: CreateAuthenticator(), and similarly add () f
rmsousa 2013/03/20 20:17:16 Done.
43 // to determine initial parameters, like PIN). This happens inside
44 // ProcessMessage, so to the outside this behaves like any asynchronous
45 // message processing. Internally, CreateAuthenticator receives a callback,
46 // that will resume the authentication once the authenticator is created.
47 // Of there is already a message to be processed by the new authenticator,
48 // this callback includes a call to the underlying ProcessMessage.
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). When an
52 // authenticator is created, it is given a preferred initial state, which
53 // the authenticator may ignore.
54 // * If the new authenticator state doesn't match the preferred one,
55 // the NegotiatingAuthenticator deals with that, by sending an empty
56 // <authenticator> stanza if the method has no message to send, and
57 // ignoring such empty messages on the receiving end.
58 // * The client may optimistically pick a method on its first message (assuming
59 // it doesn't require user interaction to start). If the host doesn't
60 // support that method, it will just discard that message, and choose
61 // another method from the client's supported methods list.
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.
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.
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 FetchSecretCallback& fetch_secret_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, and stores it in
98 // |current_authenticator_|. Authenticators that can be started in either
99 // state will be created in |preferred_initial_state|.
100 // |resume_callback| is called after |current_authenticator_| is set.
101 void CreateAuthenticator(Authenticator::State preferred_initial_state,
102 const base::Closure& resume_callback);
103
104 // Calls |current_authenticator_| to process |message|, passing the supplied
105 // |resume_callback|.
106 void ProcessMessageInternal(const buzz::XmlElement* message,
107 const base::Closure& resume_callback);
108
109 // Updates |state_| to reflect the current underlying authenticator state.
110 // |resume_callback| is called after the state is updated.
56 void UpdateState(const base::Closure& resume_callback); 111 void UpdateState(const base::Closure& resume_callback);
57 112
113 // Creates a V2Authenticator in state |initial_state| with the given
114 // |shared_secret|, then runs |resume_callback|.
115 void CreateV2AuthenticatorWithSecret(
116 Authenticator::State initial_state,
117 const base::Closure& resume_callback,
118 const std::string& shared_secret);
119
58 bool is_host_side() const; 120 bool is_host_side() const;
59 121
60 // Used only for host authenticators. 122 // Used only for host authenticators.
61 std::string local_cert_; 123 std::string local_cert_;
62 scoped_refptr<RsaKeyPair> local_key_pair_; 124 scoped_refptr<RsaKeyPair> local_key_pair_;
63 std::string shared_secret_hash_; 125 std::string shared_secret_hash_;
64 126
65 // Used only for client authenticators. 127 // Used only for client authenticators.
66 std::string authentication_tag_; 128 std::string authentication_tag_;
67 std::string shared_secret_; 129 FetchSecretCallback fetch_secret_callback_;
68 130
69 // Used for both host and client authenticators. 131 // Used for both host and client authenticators.
70 std::vector<AuthenticationMethod> methods_; 132 std::vector<AuthenticationMethod> methods_;
71 AuthenticationMethod current_method_; 133 AuthenticationMethod current_method_;
72 scoped_ptr<Authenticator> current_authenticator_; 134 scoped_ptr<Authenticator> current_authenticator_;
73 State state_; 135 State state_;
74 RejectionReason rejection_reason_; 136 RejectionReason rejection_reason_;
75 137
138 base::WeakPtrFactory<NegotiatingAuthenticator> weak_factory_;
139
76 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticator); 140 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticator);
77 }; 141 };
78 142
79 } // namespace protocol 143 } // namespace protocol
80 } // namespace remoting 144 } // namespace remoting
81 145
82 #endif // REMOTING_PROTOCOL_NEGOTIATING_AUTHENTICATOR_H_ 146 #endif // REMOTING_PROTOCOL_NEGOTIATING_AUTHENTICATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698