Revert 187554 "Implement IPC::ChannelFactory, a class that accep..."
[chromium-blink-merge.git] / remoting / protocol / negotiating_authenticator.h
bloba87d543e3ca98606ea4265013c0e39cff0056f50
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
3 // found in the LICENSE file.
5 #ifndef REMOTING_PROTOCOL_NEGOTIATING_AUTHENTICATOR_H_
6 #define REMOTING_PROTOCOL_NEGOTIATING_AUTHENTICATOR_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "remoting/protocol/authenticator.h"
15 #include "remoting/protocol/authentication_method.h"
17 namespace remoting {
19 class RsaKeyPair;
21 namespace protocol {
23 class NegotiatingAuthenticator : public Authenticator {
24 public:
25 virtual ~NegotiatingAuthenticator();
27 static bool IsNegotiableMessage(const buzz::XmlElement* message);
29 // Creates a client authenticator for the given methods.
30 static scoped_ptr<Authenticator> CreateForClient(
31 const std::string& authentication_tag,
32 const std::string& shared_secret,
33 const std::vector<AuthenticationMethod>& methods);
35 // Creates a host authenticator, using a fixed shared secret/PIN hash.
36 static scoped_ptr<Authenticator> CreateForHost(
37 const std::string& local_cert,
38 scoped_refptr<RsaKeyPair> key_pair,
39 const std::string& shared_secret_hash,
40 AuthenticationMethod::HashFunction hash_function);
42 // Authenticator interface.
43 virtual State state() const OVERRIDE;
44 virtual RejectionReason rejection_reason() const OVERRIDE;
45 virtual void ProcessMessage(const buzz::XmlElement* message,
46 const base::Closure& resume_callback) OVERRIDE;
47 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE;
48 virtual scoped_ptr<ChannelAuthenticator>
49 CreateChannelAuthenticator() const OVERRIDE;
51 private:
52 NegotiatingAuthenticator(Authenticator::State initial_state);
54 void AddMethod(const AuthenticationMethod& method);
55 void CreateAuthenticator(State initial_state);
56 void UpdateState(const base::Closure& resume_callback);
58 bool is_host_side() const;
60 // Used only for host authenticators.
61 std::string local_cert_;
62 scoped_refptr<RsaKeyPair> local_key_pair_;
63 std::string shared_secret_hash_;
65 // Used only for client authenticators.
66 std::string authentication_tag_;
67 std::string shared_secret_;
69 // Used for both host and client authenticators.
70 std::vector<AuthenticationMethod> methods_;
71 AuthenticationMethod current_method_;
72 scoped_ptr<Authenticator> current_authenticator_;
73 State state_;
74 RejectionReason rejection_reason_;
76 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticator);
79 } // namespace protocol
80 } // namespace remoting
82 #endif // REMOTING_PROTOCOL_NEGOTIATING_AUTHENTICATOR_H_